diff --git a/src/main/java/world/bentobox/parkour/Parkour.java b/src/main/java/world/bentobox/parkour/Parkour.java index 288fec0..9a1af9c 100644 --- a/src/main/java/world/bentobox/parkour/Parkour.java +++ b/src/main/java/world/bentobox/parkour/Parkour.java @@ -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; @@ -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; @@ -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); } }; diff --git a/src/main/java/world/bentobox/parkour/commands/RemoveWarpCommand.java b/src/main/java/world/bentobox/parkour/commands/RemoveWarpCommand.java new file mode 100644 index 0000000..c461e1f --- /dev/null +++ b/src/main/java/world/bentobox/parkour/commands/RemoveWarpCommand.java @@ -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 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 args) { + ParkourManager pm = ((Parkour)getAddon()).getPm(); + Island island = getIslands().getIsland(getWorld(), user); + user.sendMessage("parkour.warp.removed"); + pm.setWarpSpot(island, null); + return true; + } + +} diff --git a/src/main/java/world/bentobox/parkour/commands/SetWarpCommand.java b/src/main/java/world/bentobox/parkour/commands/SetWarpCommand.java new file mode 100644 index 0000000..bbf194e --- /dev/null +++ b/src/main/java/world/bentobox/parkour/commands/SetWarpCommand.java @@ -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 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 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; + } + +} diff --git a/src/main/java/world/bentobox/parkour/gui/CoursesTab.java b/src/main/java/world/bentobox/parkour/gui/CoursesTab.java index eaf98ea..ef1954f 100644 --- a/src/main/java/world/bentobox/parkour/gui/CoursesTab.java +++ b/src/main/java/world/bentobox/parkour/gui/CoursesTab.java @@ -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; @@ -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)); } }); diff --git a/src/main/java/world/bentobox/parkour/objects/ParkourData.java b/src/main/java/world/bentobox/parkour/objects/ParkourData.java index c6e9e91..6e099ac 100644 --- a/src/main/java/world/bentobox/parkour/objects/ParkourData.java +++ b/src/main/java/world/bentobox/parkour/objects/ParkourData.java @@ -16,7 +16,7 @@ * */ @Table(name = "Parkour") -public class ParkourData implements DataObject, Comparable { +public class ParkourData implements DataObject, Comparable { /** * uniqueId is the island's UUID @@ -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 @@ -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()); + } } diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index b292162..55103d3 100755 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -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!" @@ -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: