mirror of
https://github.com/BentoBoxWorld/Level.git
synced 2025-01-08 16:58:23 +01:00
Added admin top remove command to remove players from top ten
https://github.com/BentoBoxWorld/Level/issues/98
This commit is contained in:
parent
d6117e69d8
commit
05437ca14a
@ -13,6 +13,7 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
|
||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
||||
@ -152,6 +153,7 @@ public class TopTen implements Listener {
|
||||
* @param world - world
|
||||
* @return top ten data object
|
||||
*/
|
||||
@NonNull
|
||||
public TopTenData getTopTenList(World world) {
|
||||
topTenList.putIfAbsent(world, new TopTenData());
|
||||
return topTenList.get(world);
|
||||
|
@ -16,6 +16,7 @@ public class AdminTopCommand extends CompositeCommand {
|
||||
public AdminTopCommand(Level levelPlugin, CompositeCommand parent) {
|
||||
super(parent, "top", "topten");
|
||||
this.levelPlugin = levelPlugin;
|
||||
new AdminTopRemoveCommand(levelPlugin, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,55 @@
|
||||
package world.bentobox.level.commands.admin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.level.Level;
|
||||
|
||||
/**
|
||||
* Removes a player from the top ten
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class AdminTopRemoveCommand extends CompositeCommand {
|
||||
|
||||
private final Level addon;
|
||||
private User target;
|
||||
|
||||
public AdminTopRemoveCommand(Level addon, CompositeCommand parent) {
|
||||
super(parent, "remove", "delete");
|
||||
this.addon = addon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
this.setPermission("admin.top.remove");
|
||||
this.setOnlyPlayer(false);
|
||||
this.setParametersHelp("admin.top.remove.parameters");
|
||||
this.setDescription("admin.top.remove.description");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see world.bentobox.bentobox.api.commands.BentoBoxCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)
|
||||
*/
|
||||
@Override
|
||||
public boolean canExecute(User user, String label, List<String> args) {
|
||||
if (args.size() != 1) {
|
||||
this.showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
target = getPlayers().getUser(args.get(0));
|
||||
if (target == null) {
|
||||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
addon.getTopTen().getTopTenList(getWorld()).remove(target.getUniqueId());
|
||||
user.sendMessage("general.success");
|
||||
return true;
|
||||
}
|
||||
}
|
@ -28,6 +28,9 @@ island:
|
||||
gui-heading: "&6[name]: &B[rank]"
|
||||
island-level: "&BLevel [level]"
|
||||
warp-to: "&AWarping to [name]'s island"
|
||||
remove:
|
||||
description: "remove player from Top Ten"
|
||||
parameters: "<player>"
|
||||
|
||||
value:
|
||||
description: "shows the value of any block"
|
||||
|
@ -0,0 +1,188 @@
|
||||
package world.bentobox.level.commands.admin;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
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.addons.GameModeAddon;
|
||||
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.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
import world.bentobox.level.Level;
|
||||
import world.bentobox.level.TopTen;
|
||||
import world.bentobox.level.objects.TopTenData;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class})
|
||||
public class AdminTopRemoveCommandTest {
|
||||
|
||||
@Mock
|
||||
private CompositeCommand ic;
|
||||
private UUID uuid;
|
||||
@Mock
|
||||
private User user;
|
||||
@Mock
|
||||
private IslandsManager im;
|
||||
@Mock
|
||||
private Island island;
|
||||
@Mock
|
||||
private Level addon;
|
||||
@Mock
|
||||
private World world;
|
||||
@Mock
|
||||
private IslandWorldManager iwm;
|
||||
@Mock
|
||||
private GameModeAddon gameModeAddon;
|
||||
@Mock
|
||||
private Player p;
|
||||
@Mock
|
||||
private LocalesManager lm;
|
||||
@Mock
|
||||
private PlayersManager pm;
|
||||
|
||||
private AdminTopRemoveCommand atrc;
|
||||
@Mock
|
||||
private TopTen tt;
|
||||
@Mock
|
||||
private TopTenData ttd;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
BentoBox plugin = mock(BentoBox.class);
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
User.setPlugin(plugin);
|
||||
// Addon
|
||||
when(ic.getAddon()).thenReturn(addon);
|
||||
when(ic.getPermissionPrefix()).thenReturn("bskyblock.");
|
||||
when(ic.getLabel()).thenReturn("island");
|
||||
when(ic.getTopLabel()).thenReturn("island");
|
||||
when(ic.getWorld()).thenReturn(world);
|
||||
when(ic.getTopLabel()).thenReturn("bsb");
|
||||
|
||||
|
||||
// IWM friendly name
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
|
||||
|
||||
// World
|
||||
when(world.toString()).thenReturn("world");
|
||||
when(world.getName()).thenReturn("BSkyBlock_world");
|
||||
|
||||
|
||||
// Player manager
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
when(pm.getUser(anyString())).thenReturn(user);
|
||||
// topTen
|
||||
when(addon.getTopTen()).thenReturn(tt);
|
||||
when(tt.getTopTenList(any())).thenReturn(ttd);
|
||||
// User
|
||||
uuid = UUID.randomUUID();
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.getTranslation(any())).thenAnswer(invocation -> invocation.getArgument(0, String.class));
|
||||
|
||||
atrc = new AdminTopRemoveCommand(addon, ic);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
User.clearUsers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.level.commands.admin.AdminTopRemoveCommand#AdminTopRemoveCommand(world.bentobox.level.Level, world.bentobox.bentobox.api.commands.CompositeCommand)}.
|
||||
*/
|
||||
@Test
|
||||
public void testAdminTopRemoveCommand() {
|
||||
assertEquals("remove", atrc.getLabel());
|
||||
assertEquals("delete", atrc.getAliases().get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.level.commands.admin.AdminTopRemoveCommand#setup()}.
|
||||
*/
|
||||
@Test
|
||||
public void testSetup() {
|
||||
assertEquals("bskyblock.admin.top.remove", atrc.getPermission());
|
||||
assertEquals("admin.top.remove.parameters", atrc.getParameters());
|
||||
assertEquals("admin.top.remove.description", atrc.getDescription());
|
||||
assertFalse(atrc.isOnlyPlayer());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.level.commands.admin.AdminTopRemoveCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testCanExecuteWrongArgs() {
|
||||
assertFalse(atrc.canExecute(user, "delete", Collections.emptyList()));
|
||||
verify(user).sendMessage(eq("commands.help.header"), eq(TextVariables.LABEL), eq("BSkyBlock"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.level.commands.admin.AdminTopRemoveCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testCanExecuteUnknown() {
|
||||
when(pm.getUser(anyString())).thenReturn(null);
|
||||
assertFalse(atrc.canExecute(user, "delete", Collections.singletonList("tastybento")));
|
||||
verify(user).sendMessage(eq("general.errors.unknown-player"), eq(TextVariables.NAME), eq("tastybento"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.level.commands.admin.AdminTopRemoveCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testCanExecuteKnown() {
|
||||
assertTrue(atrc.canExecute(user, "delete", Collections.singletonList("tastybento")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.level.commands.admin.AdminTopRemoveCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfString() {
|
||||
testCanExecuteKnown();
|
||||
assertTrue(atrc.execute(user, "delete", Collections.singletonList("tastybento")));
|
||||
verify(ttd).remove(eq(uuid));
|
||||
verify(user).sendMessage(eq("general.success"));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user