From 722f136e3f8729ac69bd68044c3c6d868f092e90 Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Sun, 28 Apr 2019 10:39:31 +0200 Subject: [PATCH] Added better success message to AdminTeamKickCommand #630 --- .../admin/team/AdminTeamKickCommand.java | 30 +++++++++----- src/main/resources/locales/en-US.yml | 1 + .../admin/team/AdminTeamKickCommandTest.java | 41 ++++++++++--------- 3 files changed, 41 insertions(+), 31 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamKickCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamKickCommand.java index 5990c68c5..98dfe58a3 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamKickCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamKickCommand.java @@ -1,10 +1,7 @@ package world.bentobox.bentobox.api.commands.admin.team; -import java.util.List; -import java.util.UUID; - import org.bukkit.Bukkit; - +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.team.TeamEvent; @@ -12,11 +9,17 @@ import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.database.objects.Island; +import java.util.List; +import java.util.UUID; + +/** + * Kicks the specified player from the island team. + * @author tastybento + */ public class AdminTeamKickCommand extends CompositeCommand { public AdminTeamKickCommand(CompositeCommand parent) { super(parent, "kick"); - } @Override @@ -49,18 +52,23 @@ public class AdminTeamKickCommand extends CompositeCommand { } @Override - public boolean execute(User user, String label, List args) { + public boolean execute(User user, String label, @NonNull List args) { UUID targetUUID = getPlayers().getUUID(args.get(0)); - if (targetUUID.equals(getIslands().getOwner(getWorld(), targetUUID))) { + + Island island = getIslands().getIsland(getWorld(), targetUUID); + + if (targetUUID.equals(island.getOwner())) { user.sendMessage("commands.admin.team.kick.cannot-kick-owner"); - getIslands().getIsland(getWorld(), targetUUID).showMembers(user); + island.showMembers(user); return false; } - User.getInstance(targetUUID).sendMessage("commands.admin.team.kick.admin-kicked"); + User target = User.getInstance(targetUUID); + target.sendMessage("commands.admin.team.kick.admin-kicked"); + getIslands().removePlayer(getWorld(), targetUUID); - user.sendMessage("general.success"); + user.sendMessage("commands.admin.team.kick.success", TextVariables.NAME, target.getName(), "[owner]", getPlayers().getName(island.getOwner())); + // Fire event so add-ons know - Island island = getIslands().getIsland(getWorld(), targetUUID); IslandBaseEvent event = TeamEvent.builder() .island(island) .reason(TeamEvent.Reason.KICK) diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index f58e2d7d0..57d1717a1 100644 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -74,6 +74,7 @@ commands: cannot-kick-owner: "&cYou cannot kick the owner. Kick members first." not-in-team: "&cThis player is not in a team." admin-kicked: "&cThe admin kicked you from the team." + success: "&b[name] &ahas been kicked from &b[owner]&a's island." setowner: parameters: "" description: "transfers island ownership to the player" diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamKickCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamKickCommandTest.java index 9ceccc924..c1b682ffc 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamKickCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamKickCommandTest.java @@ -1,18 +1,5 @@ package world.bentobox.bentobox.api.commands.admin.team; -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.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; -import java.util.UUID; - import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.entity.Player; @@ -26,9 +13,9 @@ 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.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; @@ -37,6 +24,20 @@ import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.LocalesManager; import world.bentobox.bentobox.managers.PlayersManager; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +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 * @@ -122,7 +123,6 @@ public class AdminTeamKickCommandTest { PluginManager pim = mock(PluginManager.class); when(server.getPluginManager()).thenReturn(pim); when(Bukkit.getServer()).thenReturn(server); - } @@ -172,7 +172,7 @@ public class AdminTeamKickCommandTest { String[] name = {"tastybento"}; when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - when(im.getOwner(Mockito.any(), Mockito.eq(notUUID))).thenReturn(notUUID); + when(is.getOwner()).thenReturn(notUUID); AdminTeamKickCommand itl = new AdminTeamKickCommand(ac); assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); @@ -188,15 +188,16 @@ public class AdminTeamKickCommandTest { when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true); Island is = mock(Island.class); when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(is); - String[] name = {"tastybento"}; + String name = "tastybento"; when(pm.getUUID(Mockito.any())).thenReturn(notUUID); + when(pm.getName(Mockito.any())).thenReturn(name); - when(im.getOwner(Mockito.any(), Mockito.eq(notUUID))).thenReturn(uuid); + when(is.getOwner()).thenReturn(uuid); AdminTeamKickCommand itl = new AdminTeamKickCommand(ac); - assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name))); + assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList(name))); Mockito.verify(im).removePlayer(Mockito.any(), Mockito.eq(notUUID)); - Mockito.verify(user).sendMessage(Mockito.eq("general.success")); + Mockito.verify(user).sendMessage(Mockito.eq("commands.admin.team.kick.success"), Mockito.eq(TextVariables.NAME), Mockito.eq(name), Mockito.eq("[owner]"), Mockito.anyString()); } }