Skip to content

Commit

Permalink
Slimmer trimmer island info for players.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Sep 4, 2021
1 parent 547c266 commit 0f7ca6a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ public boolean execute(User user, String label, List<String> args) {
}
// 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
Expand All @@ -50,7 +48,7 @@ public boolean execute(User user, String label, List<String> args) {
// 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");
}
Expand Down
41 changes: 36 additions & 5 deletions src/main/java/world/bentobox/bentobox/util/IslandInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -39,11 +39,10 @@ public IslandInfo(Island island) {
}

/**
* 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) {
Expand Down Expand Up @@ -87,6 +86,38 @@ public boolean showInfo(User user) {
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public void testExecuteUserStringListOfStringNoArgsConsole() {
@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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,13 @@ public void testExecuteUserStringListOfStringNoArgsNoIsland() {
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");
}

Expand All @@ -218,20 +213,14 @@ public void testExecuteUserStringListOfStringNoArgsSuccess() {
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");

}

/**
Expand Down

0 comments on commit 0f7ca6a

Please sign in to comment.