diff --git a/src/me/aleksilassila/islands/commands/IslandCommands.java b/src/me/aleksilassila/islands/commands/IslandCommands.java index ac3f4d3..83d0df3 100644 --- a/src/me/aleksilassila/islands/commands/IslandCommands.java +++ b/src/me/aleksilassila/islands/commands/IslandCommands.java @@ -2,6 +2,7 @@ import me.aleksilassila.islands.Islands; import me.aleksilassila.islands.Main; +import me.aleksilassila.islands.utils.Messages; import me.aleksilassila.islands.utils.Permissions; import me.aleksilassila.islands.generation.IslandGrid; import me.aleksilassila.islands.utils.ChatUtils; @@ -143,7 +144,13 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } } - String homeId = args.length == 0 ? "1" : args[0]; + int homeId; + + try { + homeId = args.length == 0 ? 1 : Integer.parseInt(args[0]); + } catch (NumberFormatException e) { + homeId = 1; + } Location location = grid.getIslandSpawn(grid.getHomeIsland(player.getUniqueId(), homeId)); @@ -180,34 +187,4 @@ private int teleportCooldown(Player player) { return 0; } - - static class Messages extends ChatUtils { - static class error { - public static final String ISLAND_NOT_FOUND = error("404 - Home not found."); - public static final String NO_PERMISSION = error("You don't have permission to use this command."); - public static final String HOME_NOT_FOUND = error("404 - Home not found :("); - - public static String COOLDOWN(int remainingTime) { - return error("You took damage recently. You have to wait for " + remainingTime + "s before teleporting."); - } - } - - static class success { - - - public static String HOMES_FOUND(int amount) { - return success("Found " + amount + " home(s)."); - } - } - - static class info { - public static final String ON_SURFACE = info("You can only use this command on surface."); - public static final String IN_OVERWORLD = info("You can only use this command in overworld."); - } - - static class help { - public static final String VISIT = info("Usage: /visit name"); - public static final String HOME = error("Usage: /home "); - } - } } \ No newline at end of file diff --git a/src/me/aleksilassila/islands/commands/subcommands/unnameSubcommand.java b/src/me/aleksilassila/islands/commands/subcommands/unnameSubcommand.java index 2a1ea89..18055fa 100644 --- a/src/me/aleksilassila/islands/commands/subcommands/unnameSubcommand.java +++ b/src/me/aleksilassila/islands/commands/subcommands/unnameSubcommand.java @@ -42,6 +42,12 @@ public void onCommand(Player player, String[] args, boolean confirmed) { return; } + if (plugin.getIslandsConfig().getInt("islands." + islandId + ".home") <= 0 + || plugin.getIslandsConfig().getString("islands." + islandId + ".UUID") == null) { + player.sendMessage(Messages.error.ISLAND_NO_OWNER); + return; + } + if (plugin.getIslandsConfig().getString("islands." + islandId + ".UUID").equals(player.getUniqueId().toString()) || Permissions.checkPermission(player, Permissions.bypass.unname)) { grid.unnameIsland(islandId); diff --git a/src/me/aleksilassila/islands/generation/IslandGeneration.java b/src/me/aleksilassila/islands/generation/IslandGeneration.java index 2e55997..9801c88 100644 --- a/src/me/aleksilassila/islands/generation/IslandGeneration.java +++ b/src/me/aleksilassila/islands/generation/IslandGeneration.java @@ -3,6 +3,7 @@ import com.sun.istack.internal.Nullable; import me.aleksilassila.islands.Islands; import me.aleksilassila.islands.utils.ChatUtils; +import me.aleksilassila.islands.utils.Messages; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -41,7 +42,7 @@ public void addToQueue(CopyTask task) { popFromQueue(task.player.getUniqueId().toString()); queue.add(task); - task.player.sendMessage(Messages.Info.QUEUE_STATUS(queue.size())); + task.player.sendMessage(Messages.info.QUEUE_STATUS(queue.size())); } @Nullable @@ -114,16 +115,16 @@ public void run() { } if (clearingIndex >= islands.grid.islandSpacing * islands.grid.islandSpacing) { - player.sendMessage(Messages.Success.CLEARING_DONE); + player.sendMessage(Messages.success.CLEARING_DONE); clearingArea = false; break; } else if (clearingIndex == islands.grid.islandSpacing * islands.grid.islandSpacing / 4) { - player.sendMessage(Messages.Info.CLEARING_STATUS(25)); + player.sendMessage(Messages.info.CLEARING_STATUS(25)); } else if (clearingIndex == islands.grid.islandSpacing * islands.grid.islandSpacing / 2) { - player.sendMessage(Messages.Info.CLEARING_STATUS(50)); + player.sendMessage(Messages.info.CLEARING_STATUS(50)); } else if (clearingIndex == islands.grid.islandSpacing * islands.grid.islandSpacing / 4 * 3) { - player.sendMessage(Messages.Info.CLEARING_STATUS(75)); + player.sendMessage(Messages.info.CLEARING_STATUS(75)); } clearingIndex++; @@ -159,23 +160,23 @@ public void run() { // Update lighting islands.plugin.islandsWorld.getChunkAt(targetX + islandSize / 2, targetZ + islandSize / 2); - player.sendMessage(Messages.Success.GENERATION_DONE); + player.sendMessage(Messages.success.GENERATION_DONE); queue.remove(this); if (queue.size() > 0) { CopyTask nextTask = queue.get(0); nextTask.runTaskTimer(islands.plugin, 0, buildDelay); - nextTask.player.sendMessage(Messages.Info.GENERATION_STARTED(nextTask.islandSize * nextTask.islandSize / 20.0)); + nextTask.player.sendMessage(Messages.info.GENERATION_STARTED(nextTask.islandSize * nextTask.islandSize / 20.0)); } this.cancel(); break loop; } else if (index == islandSize * islandSize / 4) { - player.sendMessage(Messages.Info.GENERATION_STATUS(25)); + player.sendMessage(Messages.info.GENERATION_STATUS(25)); } else if (index == islandSize * islandSize / 2) { - player.sendMessage(Messages.Info.GENERATION_STATUS(50)); + player.sendMessage(Messages.info.GENERATION_STATUS(50)); } else if (index == islandSize * islandSize / 4 * 3) { - player.sendMessage(Messages.Info.GENERATION_STATUS(75)); + player.sendMessage(Messages.info.GENERATION_STATUS(75)); } index++; @@ -242,30 +243,4 @@ public boolean isBlockInIslandCircle(int relativeX, int relativeZ, int islandSiz return (Math.pow(relativeX - islandSize / 2.0, 2) + Math.pow(relativeZ - islandSize / 2.0, 2)) <= Math.pow(islandSize / 2.0, 2); } - - static class Messages extends ChatUtils { - static class Success { - - public static final String GENERATION_DONE = success("Island generation completed."); - public static final String CLEARING_DONE = success("Island clearing done."); - } - - static class Info { - public static String GENERATION_STARTED(double time) { - return info("Your generation event has been started. It will take approximately " + (int) time + " seconds."); - } - - public static String QUEUE_STATUS(int queueSize) { - return info("Your event has been added to the queue. There are " + (queueSize - 1) + " event(s) before yours."); - } - - public static String GENERATION_STATUS(int status) { - return info("Your generation event is " + status + "% completed."); - } - - public static String CLEARING_STATUS(int status) { - return info("Clearing event " + status + "% completed."); - } - } - } } diff --git a/src/me/aleksilassila/islands/generation/IslandGrid.java b/src/me/aleksilassila/islands/generation/IslandGrid.java index e5d45aa..5d47a72 100644 --- a/src/me/aleksilassila/islands/generation/IslandGrid.java +++ b/src/me/aleksilassila/islands/generation/IslandGrid.java @@ -31,9 +31,9 @@ private FileConfiguration getIslandsConfig() { } public void unnameIsland(String islandId) { - String homeId = islands.plugin.getIslandsConfig().getString("islands." + islandId + ".home"); + int homeId = islands.plugin.getIslandsConfig().getInt("islands." + islandId + ".home"); - getIslandsConfig().set("islands." + islandId + ".name", homeId); + getIslandsConfig().set("islands." + islandId + ".name", String.valueOf(homeId)); getIslandsConfig().set("islands." + islandId + ".public", 0); islands.plugin.saveIslandsConfig(); @@ -111,11 +111,11 @@ public String getPublicIsland(String name) { } @Nullable - public String getHomeIsland(UUID uuid, String homeId) { + public String getHomeIsland(UUID uuid, int homeId) { List allIslands = getAllIslandIds(uuid); for (String islandId : allIslands) { - if (getIslandsConfig().getString("islands." + islandId + ".home").equals(homeId)) { + if (getIslandsConfig().getInt("islands." + islandId + ".home") == homeId) { return islandId; } } @@ -165,7 +165,7 @@ private String addIslandToConfig(int xIndex, int zIndex, int islandSize, UUID uu int realY = getIslandY(xIndex, zIndex); int realZ = zIndex * islandSpacing + islandSpacing / 2 - islandSize / 2; - String home = getNewHomeId(uuid); + int home = getNewHomeId(uuid); String islandId = xIndex + "x" + zIndex; @@ -212,7 +212,7 @@ public String createIsland(UUID uuid, int islandSize) { } } - return addIslandToConfig(x, z, islandSize, uuid, getNewHomeId(uuid)); + return addIslandToConfig(x, z, islandSize, uuid, String.valueOf(getNewHomeId(uuid))); } } @@ -291,19 +291,19 @@ public void setSpawnPoint(String islandId, int x, int y) { getIslandsConfig().set("islands." + islandId + ".spawnPoint.y", y); } - public String getNewHomeId(UUID uuid) { + public int getNewHomeId(UUID uuid) { List ids = getAllIslandIds(uuid); - List homeIds = new ArrayList<>(); + List homeIds = new ArrayList<>(); for (String islandId : ids) { - String homeNumber = getIslandsConfig().getString("islands." + islandId + ".home"); + int homeNumber = getIslandsConfig().getInt("islands." + islandId + ".home"); homeIds.add(homeNumber); } - String home = String.valueOf(getNumberOfIslands(uuid) + 1); + int home = getNumberOfIslands(uuid) + 1; for (int i = 1; i <= getNumberOfIslands(uuid) + 1; i++) { - if (!homeIds.contains(String.valueOf(i))) home = String.valueOf(i); + if (!homeIds.contains(i)) home = i; } return home; diff --git a/src/me/aleksilassila/islands/utils/Messages.java b/src/me/aleksilassila/islands/utils/Messages.java index 82c54d3..17aa183 100644 --- a/src/me/aleksilassila/islands/utils/Messages.java +++ b/src/me/aleksilassila/islands/utils/Messages.java @@ -18,8 +18,15 @@ public static class error { public static final String NOT_ON_ISLAND = error("You have to be on an island."); public static final String NOT_OWNED = error("You don't own this island."); public static final String PLAYER_NOT_FOUND = error("Player not found."); - public static String NO_BIOME_FOUND = error("Biome not found."); - public static String NO_LOCATIONS_FOR_BIOME = error("No available locations for specified biome."); + public static final String ISLAND_NO_OWNER = error("To make an island private, it must have an owner."); + public static final String NO_BIOME_FOUND = error("Biome not found."); + public static final String NO_LOCATIONS_FOR_BIOME = error("No available locations for specified biome."); + public static final String ISLAND_NOT_FOUND = error("404 - Home not found."); + public static final String HOME_NOT_FOUND = error("404 - Home not found :("); + + public static String COOLDOWN(int remainingTime) { + return error("You took damage recently. You have to wait for " + remainingTime + "s before teleporting."); + } } public static class success { @@ -31,6 +38,8 @@ public static class success { public static final String TRUSTED = success("Player trusted!"); public static final String SPAWNPOINT_CHANGED = success("Island spawn point changed."); public static final String OWNER_REMOVED = success("Island owner removed."); + public static final String GENERATION_DONE = success("Island generation completed."); + public static final String CLEARING_DONE = success("Island clearing done."); public static String OWNER_CHANGED(String name) { return success("Island owner switched to " + name + "."); @@ -43,10 +52,16 @@ public static String NAME_CHANGED(String name) { public static String ISLAND_RECEIVED(String playerName, String islandName) { return success("You are now the owner of " + playerName + "'s island " + islandName + "."); } + + public static String HOMES_FOUND(int amount) { + return success("Found " + amount + " home(s)."); + } } public static class info { public static final String CONFIRM = info("Are you sure? Repeat the command to confirm."); + public static final String ON_SURFACE = info("You can only use this command on surface."); + public static final String IN_OVERWORLD = info("You can only use this command in overworld."); public static String TRUSTED_INFO(int numberOfPlayers) { return info("You have trusted " + numberOfPlayers + " player(s)."); @@ -55,17 +70,35 @@ public static String TRUSTED_INFO(int numberOfPlayers) { public static String TRUSTED_PLAYER(String displayName) { return ChatColor.GRAY + " - " + displayName; } + + public static String GENERATION_STARTED(double time) { + return info("Your generation event has been started. It will take approximately " + (int) time + " seconds."); + } + + public static String QUEUE_STATUS(int queueSize) { + return info("Your event has been added to the queue. There are " + (queueSize - 1) + " event(s) before yours."); + } + + public static String GENERATION_STATUS(int status) { + return info("Your generation event is " + status + "% completed."); + } + + public static String CLEARING_STATUS(int status) { + return info("Clearing event " + status + "% completed."); + } } public static class help { public static final String UNTRUST = info("/untrust (You have to be on target island)"); public static final String TRUST = info("/trust (You have to be on target island)"); public static final String SETSPAWN = info("/island setspawn"); - public static String CREATE = ChatColor.GRAY + "/island create ()"; - public static String REGENERATE = ChatColor.GRAY + "/island regenerate () (You have to be on target island)"; - public static String NAME = ChatColor.GRAY + "/island name (You have to be on target island)"; - public static String UNNAME = ChatColor.GRAY + "/island unname (You have to be on target island)"; - public static String GIVE = ChatColor.GRAY + "/island give (You have to be on target island)"; - public static String DELETE = ChatColor.GRAY + "/island delete (You have to be on target island)"; + public static final String CREATE = ChatColor.GRAY + "/island create ()"; + public static final String REGENERATE = ChatColor.GRAY + "/island regenerate () (You have to be on target island)"; + public static final String NAME = ChatColor.GRAY + "/island name (You have to be on target island)"; + public static final String UNNAME = ChatColor.GRAY + "/island unname (You have to be on target island)"; + public static final String GIVE = ChatColor.GRAY + "/island give (You have to be on target island)"; + public static final String DELETE = ChatColor.GRAY + "/island delete (You have to be on target island)"; + public static final String VISIT = info("Usage: /visit name"); + public static final String HOME = error("Usage: /home "); } } \ No newline at end of file diff --git a/src/plugin.yml b/src/plugin.yml index e2347be..acd476c 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,5 +1,5 @@ name: Islands -version: 1.2.0 +version: 1.2.2 author: Aleksi Lassila main: me.aleksilassila.islands.Main api-version: 1.16 @@ -7,7 +7,7 @@ softdepend: [Vault] commands: island: description: Island managment - usage: / biome + usage: / aliases: [is] visit: description: Visit islands