Skip to content

Commit

Permalink
Improved success messages for admin commands and fixed failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Poslovitch committed Jun 30, 2019
1 parent 6ecc021 commit 64d89f9
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ public boolean execute(User user, String label, List<String> args) {

private void deletePlayer(User user, UUID targetUUID) {
// Delete player and island
user.sendMessage("commands.admin.delete.deleted-island", "[xyz]", Util.xyz(getIslands().getIsland(getWorld(), targetUUID).getCenter().toVector()));

// Get the target's island
Island oldIsland = getIslands().getIsland(getWorld(), targetUUID);
if (oldIsland != null) {
Expand All @@ -89,7 +87,7 @@ private void deletePlayer(User user, UUID targetUUID) {
getIslands().deleteIsland(oldIsland, true, targetUUID);
}
getPlayers().clearHomeLocations(getWorld(), targetUUID);
user.sendMessage("general.success");
user.sendMessage("commands.admin.delete.deleted-island", "[xyz]", Util.xyz(getIslands().getIsland(getWorld(), targetUUID).getCenter().toVector()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public boolean execute(User user, String label, List<String> args) {
} else {
this.askConfirmation(user, () -> {
getIslands().deleteQuarantinedIslandByUser(getWorld(), targetUUID);
user.sendMessage("general.success");
user.sendMessage("commands.admin.emptytrash.success");
});
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public boolean execute(User user, String label, List<String> args) {
getIslands().setOwner(user, targetUUID, i);
getWorld().getBlockAt(i.getCenter()).setType(Material.BEDROCK);
user.sendMessage("commands.admin.register.registered-island", "[xyz]", Util.xyz(i.getCenter().toVector()));
user.sendMessage("general.success");
IslandBaseEvent event = IslandEvent.builder()
.island(i)
.location(i.getCenter())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public boolean execute(User user, String label, List<String> args) {
// Everything's fine, we can set the island as spawn :)
askConfirmation(user, () -> {
getIslands().resetAllFlags(getWorld());
user.sendMessage("general.success");
user.sendMessage("commands.admin.resetflags.success");
});
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ private void setSpawn(User user, Island i) {
}
getIslands().setSpawn(i);
i.setSpawnPoint(World.Environment.NORMAL, user.getLocation());
user.sendMessage("general.success");

user.sendMessage("commands.admin.setspawn.success");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public boolean execute(User user, String label, List<String> args) {
}
this.askConfirmation(user, () -> {
if (getIslands().switchIsland(getWorld(), targetUUID, islands.get(n -1))) {
user.sendMessage("general.success");
user.sendMessage("commands.admin.switchto.success");
} else {
user.sendMessage("commands.admin.switchto.cannot-switch");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public boolean execute(User user, String label, List<String> args) {
private void unregisterPlayer(User user, UUID targetUUID) {
// Unregister island
Island oldIsland = getIslands().getIsland(getWorld(), targetUUID);
user.sendMessage("commands.admin.unregister.unregistered-island", "[xyz]", Util.xyz(oldIsland.getCenter().toVector()));
IslandBaseEvent event = IslandEvent.builder()
.island(oldIsland)
.location(oldIsland.getCenter())
Expand All @@ -77,7 +76,7 @@ private void unregisterPlayer(User user, UUID targetUUID) {
getIslands().removePlayer(getWorld(), m);
getPlayers().clearHomeLocations(getWorld(), m);
});
user.sendMessage("general.success");
user.sendMessage("commands.admin.unregister.unregistered-island", "[xyz]", Util.xyz(oldIsland.getCenter().toVector()));
}

@Override
Expand Down
12 changes: 8 additions & 4 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ commands:
parameters: "<player> <number>"
description: "switch player's island to the numbered one in trash"
out-of-range: "&cNumber must be between 1 and [number]. Use &l[label] trash [player] &r&cto see island numbers"
cannot-switch: "&cSwitch failed. See console log for error."
cannot-switch: "&cSwitch failed. See console log for error."
success: "&Successfully switched the player's island to the specified one."
trash:
no-unowned-in-trash: "&cNo unowned islands in trash"
no-islands-in-trash: "&cPlayer has no islands in trash"
Expand All @@ -164,12 +165,13 @@ commands:
emptytrash:
parameters: "[player]"
description: "Clear trash for player, or all unowned islands in trash"
success: "&aTrash successfully emptied."
version:
description: "display BentoBox and addons versions"
setrange:
parameters: "<player> <range>"
description: "set the range of player's island"
range-updated: "Island range updated to [number]"
range-updated: "&aIsland range updated to &b[number]&a."
reload:
description: "reload"
tp:
Expand All @@ -186,10 +188,11 @@ commands:
unknown-rank: "&cUnknown rank!"
rank-set: "&aRank set from [from] to [to]."
setspawn:
description: "set an Island as spawn for this world"
description: "set an island as spawn for this world"
already-spawn: "&cThis island is already a spawn!"
no-island-here: "&cThere is no island here."
confirmation: "&cAre you sure you want to set this Island as the spawn for this world?"
confirmation: "&cAre you sure you want to set this island as the spawn for this world?"
success: "&aSuccessfully set this island as the spawn for this world."
blueprint:
parameters: "<load/copy/paste/pos1/pos2/save>"
description: "manipulate blueprints"
Expand Down Expand Up @@ -279,6 +282,7 @@ commands:
&aRight click to decrement
resetflags:
description: "Reset all islands to default flag settings in config.yml"
success: "&aSuccessfully reset all islands' flags to the default settings."
world:
description: "Manage world settings"
delete:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ private Player setUpTarget() {
public void testExecuteUserStringListOfStringHasIsland() {
testCanExecute();
assertTrue(iec.execute(user, "", Collections.singletonList("tasty")));
Mockito.verify(user).sendMessage("commands.island.expel.success");
Mockito.verify(user).sendMessage("commands.island.expel.success", TextVariables.NAME, "target");
Mockito.verify(im).homeTeleport(Mockito.any(), Mockito.any());
}

Expand All @@ -381,7 +381,7 @@ public void testExecuteUserStringListOfStringNoIslandSendToSpawn() {
testCanExecute();
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(false);
assertTrue(iec.execute(user, "", Collections.singletonList("tasty")));
Mockito.verify(user).sendMessage("commands.island.expel.success");
Mockito.verify(user).sendMessage("commands.island.expel.success", TextVariables.NAME, "target");
Mockito.verify(im).spawnTeleport(Mockito.any(), Mockito.any());
}

Expand All @@ -401,7 +401,7 @@ public void testExecuteUserStringListOfStringCreateIsland() {
testCanExecute();
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(false);
assertTrue(iec.execute(user, "", Collections.singletonList("tasty")));
Mockito.verify(user).sendMessage("commands.island.expel.success");
Mockito.verify(user).sendMessage("commands.island.expel.success", TextVariables.NAME, "target");
Mockito.verify(addon).logWarning(Mockito.eq("Expel: target had no island, so one was created"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.Settings;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.CommandsManager;
Expand Down Expand Up @@ -298,9 +299,7 @@ public void testExecuteSuccess() {
// Execute
when(im.getIsland(any(), Mockito.any(UUID.class))).thenReturn(island);
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
verify(user).sendMessage(eq("general.success"));
verify(user).sendMessage("commands.island.team.coop.success", TextVariables.NAME, null);
verify(island).setRank(target, RanksManager.COOP_RANK);
}


}

0 comments on commit 64d89f9

Please sign in to comment.