diff --git a/src/main/java/world/bentobox/level/Level.java b/src/main/java/world/bentobox/level/Level.java index 8b6e32c..50103b7 100644 --- a/src/main/java/world/bentobox/level/Level.java +++ b/src/main/java/world/bentobox/level/Level.java @@ -6,10 +6,10 @@ import java.util.UUID; import org.bukkit.World; -import world.bentobox.level.commands.AdminLevel; -import world.bentobox.level.commands.AdminTop; -import world.bentobox.level.commands.IslandLevel; -import world.bentobox.level.commands.IslandTop; +import world.bentobox.level.commands.admin.AdminLevelCommand; +import world.bentobox.level.commands.admin.AdminTopCommand; +import world.bentobox.level.commands.island.IslandLevelCommand; +import world.bentobox.level.commands.island.IslandTopCommand; import world.bentobox.level.config.Settings; import world.bentobox.level.objects.LevelsData; import world.bentobox.level.listeners.JoinLeaveListener; @@ -20,9 +20,8 @@ import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.database.Database; import world.bentobox.bentobox.database.objects.Island; - /** - * Addon to BSkyBlock that enables island level scoring and top ten functionality + * Addon to BSkyBlock/AcidIsland that enables island level scoring and top ten functionality * @author tastybento * */ @@ -119,22 +118,22 @@ public class Level extends Addon { this.getPlugin().getAddonsManager().getAddonByName("AcidIsland").ifPresent(a -> { CompositeCommand acidIslandCmd = getPlugin().getCommandsManager().getCommand(getConfig().getString("acidisland.user-command","ai")); if (acidIslandCmd != null) { - new IslandLevel(this, acidIslandCmd); - new IslandTop(this, acidIslandCmd); + new IslandLevelCommand(this, acidIslandCmd); + new IslandTopCommand(this, acidIslandCmd); CompositeCommand acidCmd = getPlugin().getCommandsManager().getCommand(getConfig().getString("acidisland.admin-command","acid")); - new AdminLevel(this, acidCmd); - new AdminTop(this, acidCmd); + new AdminLevelCommand(this, acidCmd); + new AdminTopCommand(this, acidCmd); } }); // BSkyBlock hook in this.getPlugin().getAddonsManager().getAddonByName("BSkyBlock").ifPresent(a -> { CompositeCommand bsbIslandCmd = getPlugin().getCommandsManager().getCommand(getConfig().getString("bskyblock.user-command","island")); if (bsbIslandCmd != null) { - new IslandLevel(this, bsbIslandCmd); - new IslandTop(this, bsbIslandCmd); + new IslandLevelCommand(this, bsbIslandCmd); + new IslandTopCommand(this, bsbIslandCmd); CompositeCommand bsbAdminCmd = getPlugin().getCommandsManager().getCommand(getConfig().getString("bskyblock.admin-command","bsbadmin")); - new AdminLevel(this, bsbAdminCmd); - new AdminTop(this, bsbAdminCmd); + new AdminLevelCommand(this, bsbAdminCmd); + new AdminTopCommand(this, bsbAdminCmd); } }); diff --git a/src/main/java/world/bentobox/level/commands/AdminLevel.java b/src/main/java/world/bentobox/level/commands/AdminLevel.java index 77239fe..c4b252e 100644 --- a/src/main/java/world/bentobox/level/commands/AdminLevel.java +++ b/src/main/java/world/bentobox/level/commands/AdminLevel.java @@ -7,6 +7,10 @@ import world.bentobox.level.Level; import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.user.User; +/** + * @deprecated Renamed and moved to {@link world.bentobox.level.commands.admin.AdminLevelCommand}. + */ +@Deprecated public class AdminLevel extends CompositeCommand { private final Level levelPlugin; diff --git a/src/main/java/world/bentobox/level/commands/AdminTop.java b/src/main/java/world/bentobox/level/commands/AdminTop.java index 0a60006..3a39b4a 100644 --- a/src/main/java/world/bentobox/level/commands/AdminTop.java +++ b/src/main/java/world/bentobox/level/commands/AdminTop.java @@ -11,6 +11,10 @@ import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.database.objects.Island; +/** + * @deprecated Renamed and moved to {@link world.bentobox.level.commands.admin.AdminTopCommand}. + */ +@Deprecated public class AdminTop extends CompositeCommand { private final Level levelPlugin; diff --git a/src/main/java/world/bentobox/level/commands/IslandLevel.java b/src/main/java/world/bentobox/level/commands/IslandLevel.java index 2effe67..8ca414c 100644 --- a/src/main/java/world/bentobox/level/commands/IslandLevel.java +++ b/src/main/java/world/bentobox/level/commands/IslandLevel.java @@ -7,6 +7,10 @@ import world.bentobox.level.Level; import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.user.User; +/** + * @deprecated Renamed and moved to {@link world.bentobox.level.commands.island.IslandLevelCommand}. + */ +@Deprecated public class IslandLevel extends CompositeCommand { private final Level levelPlugin; diff --git a/src/main/java/world/bentobox/level/commands/IslandTop.java b/src/main/java/world/bentobox/level/commands/IslandTop.java index 0e960f9..eba1397 100644 --- a/src/main/java/world/bentobox/level/commands/IslandTop.java +++ b/src/main/java/world/bentobox/level/commands/IslandTop.java @@ -6,6 +6,10 @@ import world.bentobox.level.Level; import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.user.User; +/** + * @deprecated Renamed and moved to {@link world.bentobox.level.commands.island.IslandTopCommand}. + */ +@Deprecated public class IslandTop extends CompositeCommand { private final Level plugin; diff --git a/src/main/java/world/bentobox/level/commands/admin/AdminLevelCommand.java b/src/main/java/world/bentobox/level/commands/admin/AdminLevelCommand.java new file mode 100644 index 0000000..f0fcee2 --- /dev/null +++ b/src/main/java/world/bentobox/level/commands/admin/AdminLevelCommand.java @@ -0,0 +1,45 @@ +package world.bentobox.level.commands.admin; + +import world.bentobox.bentobox.api.commands.CompositeCommand; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.level.Level; + +import java.util.List; +import java.util.UUID; + +public class AdminLevelCommand extends CompositeCommand { + + private final Level levelPlugin; + + public AdminLevelCommand(Level levelPlugin, CompositeCommand parent) { + super(parent, "level"); + this.levelPlugin = levelPlugin; + } + + @Override + public void setup() { + this.setPermission("admin.level"); + this.setOnlyPlayer(false); + this.setParametersHelp("admin.level.parameters"); + this.setDescription("admin.level.description"); + } + + @Override + public boolean execute(User user, String label, List args) { + if (args.size() == 1) { + // Asking for another player's level? + // Convert name to a UUID + final UUID playerUUID = getPlugin().getPlayers().getUUID(args.get(0)); + if (playerUUID == null) { + user.sendMessage("general.errors.unknown-player"); + return true; + } else { + levelPlugin.calculateIslandLevel(getWorld(), user, playerUUID); + } + return true; + } else { + showHelp(this, user); + return false; + } + } +} diff --git a/src/main/java/world/bentobox/level/commands/admin/AdminTopCommand.java b/src/main/java/world/bentobox/level/commands/admin/AdminTopCommand.java new file mode 100644 index 0000000..1a40cbe --- /dev/null +++ b/src/main/java/world/bentobox/level/commands/admin/AdminTopCommand.java @@ -0,0 +1,67 @@ +package world.bentobox.level.commands.admin; + +import org.bukkit.World; +import world.bentobox.bentobox.api.commands.CompositeCommand; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.bentobox.database.objects.Island; +import world.bentobox.level.Level; + +import java.util.List; +import java.util.Map; +import java.util.UUID; + +public class AdminTopCommand extends CompositeCommand { + + private final Level levelPlugin; + + public AdminTopCommand(Level levelPlugin, CompositeCommand parent) { + super(parent, "top", "topten"); + this.levelPlugin = levelPlugin; + } + + @Override + public void setup() { + this.setPermission("admin.top"); + this.setOnlyPlayer(false); + this.setDescription("admin.top.description"); + } + + @Override + public boolean execute(User user, String label, List args) { + // Get world + World world; + if (args.isEmpty()) { + if (getPlugin().getIWM().getOverWorlds().size() == 1) { + world = getPlugin().getIWM().getOverWorlds().get(0); + } else { + showHelp(this, user); + return false; + } + } else { + if (getPlugin().getIWM().isOverWorld(args.get(0))) { + world = getPlugin().getIWM().getIslandWorld(args.get(0)); + } else { + user.sendMessage("commands.admin.top.unknown-world"); + return false; + } + + } + int rank = 0; + for (Map.Entry topTen : levelPlugin.getTopTen().getTopTenList(world).getTopTen().entrySet()) { + Island island = getPlugin().getIslands().getIsland(world, topTen.getKey()); + if (island != null) { + rank++; + String item = user.getTranslation("admin.topten", + "[rank]", + "[name]", + "[level]", + String.valueOf(rank), + this.getPlugin().getPlayers().getUser(island.getOwner()).getName(), + String.valueOf(topTen.getValue())); + user.sendRawMessage(item); + } + } + + return true; + } +} diff --git a/src/main/java/world/bentobox/level/commands/island/IslandLevelCommand.java b/src/main/java/world/bentobox/level/commands/island/IslandLevelCommand.java new file mode 100644 index 0000000..84cfb3a --- /dev/null +++ b/src/main/java/world/bentobox/level/commands/island/IslandLevelCommand.java @@ -0,0 +1,50 @@ +package world.bentobox.level.commands.island; + +import world.bentobox.bentobox.api.commands.CompositeCommand; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.level.Level; + +import java.util.List; +import java.util.UUID; + +public class IslandLevelCommand extends CompositeCommand { + + private final Level levelPlugin; + + public IslandLevelCommand(Level levelPlugin, CompositeCommand parent) { + super(parent, "level"); + this.levelPlugin = levelPlugin; + } + + @Override + public void setup() { + this.setPermission("island.level"); + this.setParametersHelp("island.level.parameters"); + this.setDescription("island.level.description"); + this.setOnlyPlayer(true); + } + + @Override + public boolean execute(User user, String label, List args) { + if (!args.isEmpty()) { + // Asking for another player's level? + // Convert name to a UUID + final UUID playerUUID = getPlugin().getPlayers().getUUID(args.get(0)); + if (playerUUID == null) { + user.sendMessage("general.errors.unknown-player"); + return true; + } else if (user.getUniqueId().equals(playerUUID) ) { + // Self level request + levelPlugin.calculateIslandLevel(getWorld(), user, user.getUniqueId()); + } else { + user.sendMessage("island.level.island-level-is", "[level]", String.valueOf(levelPlugin.getIslandLevel(getWorld(), playerUUID))); + return true; + } + } else { + // Self level request + levelPlugin.calculateIslandLevel(getWorld(), user, user.getUniqueId()); + } + return false; + } + +} diff --git a/src/main/java/world/bentobox/level/commands/island/IslandTopCommand.java b/src/main/java/world/bentobox/level/commands/island/IslandTopCommand.java new file mode 100644 index 0000000..1f8db3d --- /dev/null +++ b/src/main/java/world/bentobox/level/commands/island/IslandTopCommand.java @@ -0,0 +1,30 @@ +package world.bentobox.level.commands.island; + +import world.bentobox.bentobox.api.commands.CompositeCommand; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.level.Level; + +import java.util.List; + +public class IslandTopCommand extends CompositeCommand { + + private final Level plugin; + + public IslandTopCommand(Level plugin, CompositeCommand parent) { + super(parent, "top", "topten"); + this.plugin = plugin; + } + + @Override + public void setup() { + setPermission("island.top"); + setDescription("island.top.description"); + setOnlyPlayer(true); + } + + @Override + public boolean execute(User user, String label, List list) { + plugin.getTopTen().getGUI(getWorld(), user, getPermissionPrefix()); + return true; + } +}