From 8ba0ebd1702ba3befc9cf484d5a28b6509e6b6f7 Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Sat, 27 Apr 2019 21:03:40 +0200 Subject: [PATCH] Added better success feedback messages for IslandBanCommand and IslandUnbanCommand #630 --- .../api/commands/island/IslandBanCommand.java | 16 +++---- .../commands/island/IslandUnbanCommand.java | 12 +++--- src/main/resources/locales/en-US.yml | 8 ++-- .../commands/island/IslandBanCommandTest.java | 43 +++++++++---------- .../island/IslandUnbanCommandTest.java | 37 ++++++++-------- 5 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/IslandBanCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/IslandBanCommand.java index 30e7c2bdd..5dcda3289 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/IslandBanCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/IslandBanCommand.java @@ -1,14 +1,9 @@ package world.bentobox.bentobox.api.commands.island; -import java.util.List; -import java.util.Optional; -import java.util.UUID; -import java.util.stream.Collectors; - import org.bukkit.Bukkit; import org.bukkit.Sound; import org.bukkit.entity.Player; - +import org.eclipse.jdt.annotation.NonNull; import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.events.IslandBaseEvent; import world.bentobox.bentobox.api.events.island.IslandEvent; @@ -17,6 +12,11 @@ import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.util.Util; +import java.util.List; +import java.util.Optional; +import java.util.UUID; +import java.util.stream.Collectors; + public class IslandBanCommand extends CompositeCommand { public IslandBanCommand(CompositeCommand islandCommand) { @@ -82,7 +82,7 @@ public class IslandBanCommand extends CompositeCommand { return ban(user, target); } - private boolean ban(User issuer, User target) { + private boolean ban(@NonNull User issuer, User target) { Island island = getIslands().getIsland(getWorld(), issuer.getUniqueId()); // Check if player can ban any more players @@ -98,7 +98,7 @@ public class IslandBanCommand extends CompositeCommand { // Event is not cancelled if (!banEvent.isCancelled() && island.ban(issuer.getUniqueId(), target.getUniqueId())) { - issuer.sendMessage("general.success"); + issuer.sendMessage("commands.island.ban.player-banned", TextVariables.NAME, target.getName()); target.sendMessage("commands.island.ban.owner-banned-you", TextVariables.NAME, issuer.getName()); // If the player is online, has an island and on the banned island, move them home immediately if (target.isOnline() && getIslands().hasIsland(getWorld(), target.getUniqueId()) && island.onIsland(target.getLocation())) { diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/IslandUnbanCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/IslandUnbanCommand.java index af2f1a332..72ff1f86f 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/IslandUnbanCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/IslandUnbanCommand.java @@ -1,10 +1,5 @@ package world.bentobox.bentobox.api.commands.island; -import java.util.List; -import java.util.Optional; -import java.util.UUID; -import java.util.stream.Collectors; - import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.events.IslandBaseEvent; import world.bentobox.bentobox.api.events.island.IslandEvent; @@ -13,6 +8,11 @@ import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.util.Util; +import java.util.List; +import java.util.Optional; +import java.util.UUID; +import java.util.stream.Collectors; + public class IslandUnbanCommand extends CompositeCommand { public IslandUnbanCommand(CompositeCommand islandCommand) { @@ -79,7 +79,7 @@ public class IslandUnbanCommand extends CompositeCommand { // Event is not cancelled if (!unbanEvent.isCancelled() && island.unban(issuer.getUniqueId(), target.getUniqueId())) { - issuer.sendMessage("general.success"); + issuer.sendMessage("commands.island.unban.player-unbanned", TextVariables.NAME, target.getName()); target.sendMessage("commands.island.unban.you-are-unbanned", TextVariables.NAME, issuer.getName()); // Set cooldown if (getSettings().getBanCooldown() > 0 && getParent() != null) { diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index eff8ecac7..8252e1ef9 100644 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -417,18 +417,20 @@ commands: cannot-ban: "&cThat player cannot be banned." cannot-ban-member: "&cKick the team member first, then ban." cannot-ban-more-players: "&cYou reached the ban limit, you cannot ban any more players from your island." - player-already-banned: "&cPlayer is already banned" + player-already-banned: "&cPlayer is already banned." + player-banned: "&b[name]&c is now banned from your island." owner-banned-you: "&b[name]&c banned you from their island!" you-are-banned: "&bYou are banned from this island!" unban: description: "unban a player from your island" parameters: "" cannot-unban-yourself: "&cYou cannot unban yourself!" - player-not-banned: "&cPlayer is not banned" + player-not-banned: "&cPlayer is not banned." + player-unbanned: "&b[name]&a is now unbanned from your island." you-are-unbanned: "&b[name]&a unbanned you from their island!" banlist: description: "list banned players" - noone: "&aNo one is banned on this island" + noone: "&aNo one is banned on this island." the-following: "&bThe following players are banned:" names: "&c[line]" you-can-ban: "&bYou can ban up to &e[number] &bmore players." diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandBanCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandBanCommandTest.java index 68b96fc1d..5526623fc 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandBanCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandBanCommandTest.java @@ -1,23 +1,5 @@ package world.bentobox.bentobox.api.commands.island; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; -import java.util.stream.Collectors; - import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.entity.Player; @@ -32,7 +14,6 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; - import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.api.commands.CompositeCommand; @@ -45,6 +26,24 @@ import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.PlayersManager; import world.bentobox.bentobox.managers.RanksManager; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; +import java.util.stream.Collectors; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** * @author tastybento * @@ -250,7 +249,7 @@ public class IslandBanCommandTest { when(island.ban(Mockito.any(), Mockito.any())).thenReturn(true); assertTrue(ibc.execute(user, ibc.getLabel(), Collections.singletonList("bill"))); - Mockito.verify(user).sendMessage("general.success"); + Mockito.verify(user).sendMessage("commands.island.ban.player-banned", TextVariables.NAME, targetUser.getName()); Mockito.verify(targetUser).sendMessage("commands.island.ban.owner-banned-you", TextVariables.NAME, user.getName()); } @@ -272,7 +271,7 @@ public class IslandBanCommandTest { when(island.ban(Mockito.any(), Mockito.any())).thenReturn(true); assertTrue(ibc.execute(user, ibc.getLabel(), Collections.singletonList("bill"))); - Mockito.verify(user).sendMessage("general.success"); + Mockito.verify(user).sendMessage("commands.island.ban.player-banned", TextVariables.NAME, targetUser.getName()); Mockito.verify(targetUser).sendMessage("commands.island.ban.owner-banned-you", TextVariables.NAME, user.getName()); } @@ -293,7 +292,7 @@ public class IslandBanCommandTest { when(island.ban(Mockito.any(), Mockito.any())).thenReturn(false); assertFalse(ibc.execute(user, ibc.getLabel(), Collections.singletonList("bill"))); - Mockito.verify(user, Mockito.never()).sendMessage("general.success"); + Mockito.verify(user, Mockito.never()).sendMessage("commands.island.ban.player-banned", TextVariables.NAME, targetUser.getName()); Mockito.verify(targetUser, Mockito.never()).sendMessage("commands.island.ban.owner-banned-you", "[owner]", user.getName()); } diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandUnbanCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandUnbanCommandTest.java index 3fd0d3781..aa0a63bbe 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandUnbanCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandUnbanCommandTest.java @@ -1,21 +1,5 @@ package world.bentobox.bentobox.api.commands.island; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; - import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.entity.Player; @@ -29,7 +13,6 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; - import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.api.commands.CompositeCommand; @@ -42,6 +25,22 @@ import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.PlayersManager; import world.bentobox.bentobox.managers.RanksManager; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** * @author tastybento * @@ -218,7 +217,7 @@ public class IslandUnbanCommandTest { when(island.unban(Mockito.any(), Mockito.any())).thenReturn(true); assertTrue(iubc.execute(user, iubc.getLabel(), Collections.singletonList("bill"))); - Mockito.verify(user).sendMessage("general.success"); + Mockito.verify(user).sendMessage("commands.island.unban.player-unbanned", TextVariables.NAME, targetUser.getName()); Mockito.verify(targetUser).sendMessage("commands.island.unban.you-are-unbanned", TextVariables.NAME, user.getName()); } @@ -242,7 +241,7 @@ public class IslandUnbanCommandTest { when(island.unban(Mockito.any(), Mockito.any())).thenReturn(false); assertFalse(iubc.execute(user, iubc.getLabel(), Collections.singletonList("bill"))); - Mockito.verify(user, Mockito.never()).sendMessage("general.success"); + Mockito.verify(user, Mockito.never()).sendMessage("commands.island.unban.player-unbanned", TextVariables.NAME, targetUser.getName()); Mockito.verify(targetUser, Mockito.never()).sendMessage("commands.island.unban.you-are-unbanned", "[owner]", user.getName()); }