diff --git a/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminInfoCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminInfoCommand.java index 98eb59b7d..f335769cc 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminInfoCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminInfoCommand.java @@ -35,10 +35,8 @@ public class AdminInfoCommand extends CompositeCommand { } // If there are no args, then the player wants info on the island at this location if (args.isEmpty()) { - if (!getIslands().getIslandAt(user.getLocation()).map(i -> new IslandInfo(i).showInfo(user)).orElse(false)) { - user.sendMessage("commands.admin.info.no-island"); - return false; - } + getIslands().getIslandAt(user.getLocation()).ifPresentOrElse(i -> new IslandInfo(i).showAdminInfo(user), () -> + user.sendMessage("commands.admin.info.no-island")); return true; } // Get target player @@ -50,7 +48,7 @@ public class AdminInfoCommand extends CompositeCommand { // Show info for this player Island island = getIslands().getIsland(getWorld(), targetUUID); if (island != null) { - new IslandInfo(island).showInfo(user); + new IslandInfo(island).showAdminInfo(user); if (!getIslands().getQuarantinedIslandByUser(getWorld(), targetUUID).isEmpty()) { user.sendMessage("commands.admin.info.islands-in-trash"); } diff --git a/src/main/java/world/bentobox/bentobox/util/IslandInfo.java b/src/main/java/world/bentobox/bentobox/util/IslandInfo.java index 90f9bd074..99886efd0 100644 --- a/src/main/java/world/bentobox/bentobox/util/IslandInfo.java +++ b/src/main/java/world/bentobox/bentobox/util/IslandInfo.java @@ -29,7 +29,7 @@ public class IslandInfo { /** * @param plugin - * @param island + * @param island Island to show info */ public IslandInfo(Island island) { this.plugin = BentoBox.getInstance(); @@ -39,11 +39,10 @@ public class IslandInfo { } /** - * Shows info of this island to this user. - * @param user the User who is requesting it - * @return always true + * Shows admin info of this island + * @param user user asking */ - public boolean showInfo(User user) { + public void showAdminInfo(User user) { user.sendMessage("commands.admin.info.title"); user.sendMessage("commands.admin.info.island-uuid", "[uuid]", island.getUniqueId()); if (owner == null) { @@ -87,6 +86,38 @@ public class IslandInfo { if (island.getPurgeProtected()) { user.sendMessage("commands.admin.info.purge-protected"); } + } + + + /** + * Shows info of this island to this user. + * @param user the User who is requesting it + * @return always true + */ + public boolean showInfo(User user) { + user.sendMessage("commands.admin.info.title"); + if (owner == null) { + user.sendMessage("commands.admin.info.unowned"); + } else { + user.sendMessage("commands.admin.info.owner", "[owner]", plugin.getPlayers().getName(owner)); + user.sendMessage("commands.admin.info.deaths", "[number]", String.valueOf(plugin.getPlayers().getDeaths(world, owner))); + String resets = String.valueOf(plugin.getPlayers().getResets(world, owner)); + String total = plugin.getIWM().getResetLimit(world) < 0 ? "Unlimited" : String.valueOf(plugin.getIWM().getResetLimit(world)); + user.sendMessage("commands.admin.info.resets-left", "[number]", resets, "[total]", total); + // Show team members + showMembers(user); + } + Vector location = island.getProtectionCenter().toVector(); + user.sendMessage("commands.admin.info.island-center", TextVariables.XYZ, Util.xyz(location)); + user.sendMessage("commands.admin.info.protection-range", "[range]", String.valueOf(island.getProtectionRange())); + user.sendMessage("commands.admin.info.protection-coords", "[xz1]", Util.xyz(new Vector(island.getMinProtectedX(), 0, island.getMinProtectedZ())), "[xz2]", Util.xyz(new Vector(island.getMaxProtectedX(), 0, island.getMaxProtectedZ()))); + if (island.isSpawn()) { + user.sendMessage("commands.admin.info.is-spawn"); + } + if (!island.getBanned().isEmpty()) { + user.sendMessage("commands.admin.info.banned-players"); + island.getBanned().forEach(u -> user.sendMessage("commands.admin.info.banned-format", TextVariables.NAME, plugin.getPlayers().getName(u))); + } return true; } diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminInfoCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminInfoCommandTest.java index 97ebd4eaf..4cf7dad10 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminInfoCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminInfoCommandTest.java @@ -185,7 +185,7 @@ public class AdminInfoCommandTest { @Test public void testExecuteUserStringListOfStringNoArgsNoIsland() { when(im.getIslandAt(any())).thenReturn(Optional.empty()); - assertFalse(iic.execute(user, "", Collections.emptyList())); + assertTrue(iic.execute(user, "", Collections.emptyList())); verify(user).sendMessage("commands.admin.info.no-island"); } diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandInfoCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandInfoCommandTest.java index 739bbea47..db650ebb5 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandInfoCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandInfoCommandTest.java @@ -196,18 +196,13 @@ public class IslandInfoCommandTest { public void testExecuteUserStringListOfStringNoArgsSuccess() { assertTrue(iic.execute(user, "", Collections.emptyList())); verify(user).sendMessage("commands.admin.info.title"); - verify(user).sendMessage(eq("commands.admin.info.island-uuid"), eq("[uuid]"), any()); - verify(user).sendMessage(eq("commands.admin.info.owner"), eq("[owner]"), eq(null), eq("[uuid]"), any()); - verify(user).sendMessage(eq("commands.admin.info.last-login"), eq("[date]"), any()); + verify(user).sendMessage(eq("commands.admin.info.owner"), eq("[owner]"), eq(null)); verify(user).sendMessage("commands.admin.info.deaths", "[number]", "0"); verify(user).sendMessage("commands.admin.info.resets-left", "[number]", "0", "[total]", "0"); verify(user).sendMessage("commands.admin.info.team-members-title"); verify(user).sendMessage("commands.admin.info.team-owner-format", "[name]", null, "[rank]", "ranks.owner"); - verify(user).sendMessage("commands.admin.info.island-protection-center", "[xyz]", "0,0,0"); verify(user).sendMessage("commands.admin.info.island-center", "[xyz]", "0,0,0"); - verify(user).sendMessage("commands.admin.info.island-coords", "[xz1]", "0,0,0", "[xz2]", "0,0,0"); verify(user).sendMessage("commands.admin.info.protection-range", "[range]", "100"); - verify(user).sendMessage("commands.admin.info.max-protection-range", "[range]", "100"); verify(user).sendMessage("commands.admin.info.protection-coords", "[xz1]", "0,0,0", "[xz2]", "0,0,0"); } @@ -218,20 +213,14 @@ public class IslandInfoCommandTest { public void testExecuteUserStringListOfStringArgsSuccess() { assertTrue(iic.execute(user, "", Collections.singletonList("tastybento"))); verify(user).sendMessage("commands.admin.info.title"); - verify(user).sendMessage(eq("commands.admin.info.island-uuid"), eq("[uuid]"), any()); - verify(user).sendMessage(eq("commands.admin.info.owner"), eq("[owner]"), eq(null), eq("[uuid]"), any()); - verify(user).sendMessage(eq("commands.admin.info.last-login"), eq("[date]"), any()); + verify(user).sendMessage(eq("commands.admin.info.owner"), eq("[owner]"), eq(null)); verify(user).sendMessage("commands.admin.info.deaths", "[number]", "0"); verify(user).sendMessage("commands.admin.info.resets-left", "[number]", "0", "[total]", "0"); verify(user).sendMessage("commands.admin.info.team-members-title"); verify(user).sendMessage("commands.admin.info.team-owner-format", "[name]", null, "[rank]", "ranks.owner"); - verify(user).sendMessage("commands.admin.info.island-protection-center", "[xyz]", "0,0,0"); verify(user).sendMessage("commands.admin.info.island-center", "[xyz]", "0,0,0"); - verify(user).sendMessage("commands.admin.info.island-coords", "[xz1]", "0,0,0", "[xz2]", "0,0,0"); verify(user).sendMessage("commands.admin.info.protection-range", "[range]", "100"); - verify(user).sendMessage("commands.admin.info.max-protection-range", "[range]", "100"); verify(user).sendMessage("commands.admin.info.protection-coords", "[xz1]", "0,0,0", "[xz2]", "0,0,0"); - } /**