Skip to content

Commit

Permalink
Added setwarp and removewarp commands to enable courses.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jul 16, 2023
1 parent 9ab5ff0 commit dbd978c
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/main/java/world/bentobox/parkour/Parkour.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.entity.SpawnCategory;
import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
import org.bukkit.entity.SpawnCategory;
import org.bukkit.event.Listener;
import org.bukkit.generator.ChunkGenerator;
import org.eclipse.jdt.annotation.Nullable;
Expand All @@ -15,6 +15,8 @@
import world.bentobox.bentobox.api.configuration.Config;
import world.bentobox.bentobox.api.configuration.WorldSettings;
import world.bentobox.parkour.commands.CoursesCommand;
import world.bentobox.parkour.commands.RemoveWarpCommand;
import world.bentobox.parkour.commands.SetWarpCommand;
import world.bentobox.parkour.commands.TopCommand;
import world.bentobox.parkour.generators.ChunkGeneratorWorld;
import world.bentobox.parkour.gui.RankingsUI;
Expand Down Expand Up @@ -57,6 +59,8 @@ public void setup()
super.setup();
new TopCommand(getAddon(), this);
new CoursesCommand(getAddon(), this);
new SetWarpCommand(getAddon(), this);
new RemoveWarpCommand(getAddon(), this);
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package world.bentobox.parkour.commands;

import java.util.List;

import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.parkour.Parkour;
import world.bentobox.parkour.ParkourManager;

public class RemoveWarpCommand extends CompositeCommand {

public RemoveWarpCommand(Parkour addon, CompositeCommand parent) {
super(parent, "removewarp");
}

@Override
public void setup() {
this.setPermission("parkour.removewarp");
setOnlyPlayer(true);
setDescription("parkour.commands.parkour.removewarp.description");
}

@Override
public boolean canExecute(User user, String label, List<String> args) {
Island island = getIslands().getIsland(getWorld(), user);
ParkourManager pm = ((Parkour)getAddon()).getPm();
if (pm.getWarpSpot(island).isEmpty()) {
user.sendMessage("parkour.errors.no-warp");
return false;
}
return true;
}

@Override
public boolean execute(User user, String label, List<String> args) {
ParkourManager pm = ((Parkour)getAddon()).getPm();
Island island = getIslands().getIsland(getWorld(), user);
user.sendMessage("parkour.warp.removed");
pm.setWarpSpot(island, null);
return true;
}

}
49 changes: 49 additions & 0 deletions src/main/java/world/bentobox/parkour/commands/SetWarpCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package world.bentobox.parkour.commands;

import java.util.List;

import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.parkour.Parkour;
import world.bentobox.parkour.ParkourManager;

public class SetWarpCommand extends CompositeCommand {



public SetWarpCommand(Parkour addon, CompositeCommand parent) {
super(parent, "setwarp");
}

@Override
public void setup() {
this.setPermission("parkour.setwarp");
setOnlyPlayer(true);
setDescription("parkour.commands.parkour.setwarp.description");
}

@Override
public boolean canExecute(User user, String label, List<String> args) {
if (!getIslands().userIsOnIsland(getWorld(), user)) {
user.sendMessage("parkour.errors.not-on-island");
return false;
}
return true;
}

@Override
public boolean execute(User user, String label, List<String> args) {
ParkourManager pm = ((Parkour)getAddon()).getPm();
Island island = getIslands().getIsland(getWorld(), user);
if (pm.getWarpSpot(island).isEmpty()) {
user.sendMessage("parkour.warp.set");
} else {
user.sendMessage("parkour.warp.replaced");
}
pm.setWarpSpot(island, user.getLocation());

return true;
}

}
3 changes: 3 additions & 0 deletions src/main/java/world/bentobox/parkour/gui/CoursesTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;

import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.Tab;
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
Expand Down Expand Up @@ -81,8 +82,10 @@ public String getName() {
.sorted()
.filter(hs -> Objects.nonNull(hs.getWarpSpot()))
.forEach(hs -> {
BentoBox.getInstance().logDebug("course found");
UUID owner = addon.getIslands().getIslandById(hs.getUniqueId()).map(Island::getOwner).orElse(null);
if (owner != null) {
BentoBox.getInstance().logDebug("Adding head for " + owner);
heads.add(getHead(hs, owner));
}
});
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/world/bentobox/parkour/objects/ParkourData.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
*/
@Table(name = "Parkour")
public class ParkourData implements DataObject, Comparable<Integer> {
public class ParkourData implements DataObject, Comparable<ParkourData> {

/**
* uniqueId is the island's UUID
Expand Down Expand Up @@ -84,10 +84,6 @@ public void setUniqueId(String uniqueId) {
this.uniqueId = uniqueId;
}

@Override
public int compareTo(Integer o) {
return Integer.compare(runCount, o);
}

/**
* @return the start
Expand Down Expand Up @@ -131,5 +127,9 @@ public void setWarpSpot(Location warpSpot) {
this.warpSpot = warpSpot;
}

@Override
public int compareTo(ParkourData o) {
return Integer.compare(this.runCount, o.getRunCount());
}

}
5 changes: 5 additions & 0 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ parkour:
did-not-beat-previous-time: "&b You didn't beat your previous time!"
errors:
not-on-island: "&c You must be on an island to do that"
no-warp: "&c This course is already private"
warp:
set: "&d Warp spot set! Players can now see your course!"
replaced: "&e Warp spot set! Old spot deactivated!"
Expand All @@ -53,6 +54,10 @@ parkour:
not-owner: '&c You are not the owner of your team!'
commands:
parkour:
setwarp:
description: sets the warp spot and makes your course public
removewarp:
description: removes the warp spot and makes your course private
help:
description: Start a parkour course or teleport to your course
go:
Expand Down

0 comments on commit dbd978c

Please sign in to comment.