Removed deprecated classes

This commit is contained in:
Florian CUNY 2019-01-03 16:51:57 +01:00
parent bde91b7784
commit 2e2c7c69de
6 changed files with 1 additions and 530 deletions

View File

@ -1,64 +0,0 @@
package world.bentobox.bentobox.api.commands.admin;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
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.util.Util;
/**
* @deprecated Renamed and moved to {@link world.bentobox.bentobox.api.commands.admin.resets.AdminResetsResetCommand}.
*/
@Deprecated
public class AdminClearresetsCommand extends CompositeCommand {
public AdminClearresetsCommand(CompositeCommand parent) {
super(parent, "clearresets");
}
@Override
public void setup() {
setPermission("admin.clearreset");
setParametersHelp("commands.admin.clearresets.parameters");
setDescription("commands.admin.clearresets.description");
}
@Override
public boolean execute(User user, String label, List<String> args) {
// If args are not right, show help
if (args.size() != 1) {
showHelp(this, user);
return false;
}
// Get target
UUID targetUUID = getPlayers().getUUID(args.get(0));
if (targetUUID == null) {
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
return false;
}
if (!getIslands().hasIsland(getWorld(), targetUUID)) {
user.sendMessage("general.errors.player-has-no-island");
return false;
}
// Clear resets
user.sendMessage("commands.admin.clearresets.cleared");
getPlayers().setResets(getWorld(), targetUUID, 0);
user.sendMessage("general.success");
return true;
}
@Override
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
if (args.isEmpty()) {
// Don't show every player on the server. Require at least the first letter
return Optional.empty();
}
List<String> options = new ArrayList<>(Util.getOnlinePlayerList(user));
return Optional.of(Util.tabLimit(options, lastArg));
}
}

View File

@ -1,45 +0,0 @@
package world.bentobox.bentobox.api.commands.admin;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.user.User;
/**
* @deprecated Unlike {@link AdminClearresetsCommand}, this command will be removed.
* We will be working on an alternative which will use {@link world.bentobox.bentobox.api.commands.admin.resets.AdminResetsResetCommand} instead.
*/
@Deprecated
public class AdminClearresetsallCommand extends ConfirmableCommand {
public AdminClearresetsallCommand(CompositeCommand parent) {
super(parent, "clearresetsall");
}
@Override
public void setup() {
setPermission("admin.clearresetsall");
setDescription("commands.admin.clearresetsall.description");
}
@Override
public boolean execute(User user, String label, List<String> args) {
if (!args.isEmpty()) {
showHelp(this, user);
return false;
}
this.askConfirmation(user, () -> {
// Set the reset epoch to now
getIWM().setResetEpoch(getWorld());
// Reset all current players
Bukkit.getOnlinePlayers().stream().map(Player::getUniqueId).filter(getPlayers()::isKnown).forEach(u -> getPlayers().setResets(getWorld(), u, 0));
user.sendMessage("general.success");
});
return true;
}
}

View File

@ -1,135 +0,0 @@
package world.bentobox.bentobox.api.flags;
import org.bukkit.Material;
import org.bukkit.event.Listener;
import world.bentobox.bentobox.api.flags.Flag.Type;
import world.bentobox.bentobox.api.flags.clicklisteners.CycleClick;
import world.bentobox.bentobox.api.flags.clicklisteners.IslandToggleClick;
import world.bentobox.bentobox.api.flags.clicklisteners.WorldToggleClick;
import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.managers.RanksManager;
/**
* @deprecated Replaced by {@link Flag.Builder}.
*/
@Deprecated
public class FlagBuilder {
private String id;
private Material icon;
private Listener listener;
private boolean setting;
private Type type = Type.PROTECTION;
private int defaultRank = RanksManager.MEMBER_RANK;
private PanelItem.ClickHandler onClick;
private boolean subPanel = false;
public FlagBuilder id(String string) {
id = string;
return this;
}
/**
* The material that will become the icon for this flag
* @param icon - material
*/
public FlagBuilder icon(Material icon) {
this.icon = icon;
return this;
}
/**
* @param listener - the Bukkit listener that will be registered to handle this flag
*/
public FlagBuilder listener(Listener listener) {
this.listener = listener;
return this;
}
public Flag build() {
// If no onClick has been set, then apply default ones
if (onClick == null) {
switch (type){
case PROTECTION:
onClick = new CycleClick(id);
break;
case SETTING:
onClick = new IslandToggleClick(id);
break;
case WORLD_SETTING:
onClick = new WorldToggleClick(id);
break;
default:
onClick = new CycleClick(id);
break;
}
}
Flag f = new Flag(id, icon, listener, type, defaultRank, onClick, subPanel);
f.setDefaultSetting(setting);
return f;
}
/**
* Sets the default setting for this flag in the world
* @param setting - true or false
* @return FlagBuilder
*/
public FlagBuilder allowedByDefault(boolean setting) {
this.setting = setting;
return this;
}
/**
* Set the type of this flag
* @param type {@link Type}
* @return FlagBuilder
*/
public FlagBuilder type(Type type) {
this.type = type;
return this;
}
/**
* Set the id of this flag to the name of this enum value
* @param flag - flag
* @return FlagBuilder
*/
public FlagBuilder id(Enum<?> flag) {
id = flag.name();
return this;
}
/**
* Set a default rank for this flag. If not set, the value of RanksManager.MEMBER_RANK will be used
* @param rank - rank value
* @return FlagBuilder
*/
public FlagBuilder defaultRank(int rank) {
this.defaultRank = rank;
return this;
}
/**
* Adds a listener for clicks on this flag when it is a panel item. Default is
* {@link world.bentobox.bentobox.api.flags.clicklisteners.CycleClick}
* @param onClickListener - the listener for clicks. Must use the ClickOn interface
* @return FlagBuilder
*/
public FlagBuilder onClick(PanelItem.ClickHandler onClickListener) {
this.onClick = onClickListener;
return this;
}
/**
* Marks this flag as "using a sub-panel"
* @param subPanel - whether the flag will use a sub-panel or not
* @return FlagBuilder
*/
public FlagBuilder subPanel(boolean subPanel) {
this.subPanel = subPanel;
return this;
}
}

View File

@ -27,7 +27,7 @@ public class CommandsManager {
if (command.getAddon() != null) {
commandPrefix = command.getAddon().getDescription().getName().toLowerCase(Locale.ENGLISH);
}
commandMap.register(commandPrefix, command);
}
catch(Exception exception){

View File

@ -1,165 +0,0 @@
/**
*
*/
package world.bentobox.bentobox.api.commands.admin;
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.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitScheduler;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
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;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.managers.CommandsManager;
import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.LocalesManager;
import world.bentobox.bentobox.managers.PlayersManager;
/**
* @author ben
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
public class AdminClearresetsCommandTest {
private CompositeCommand ac;
private User user;
private IslandsManager im;
private PlayersManager pm;
private UUID notUUID;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
// Set up plugin
BentoBox plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
// Command manager
CommandsManager cm = mock(CommandsManager.class);
when(plugin.getCommandsManager()).thenReturn(cm);
// Settings
Settings s = mock(Settings.class);
when(plugin.getSettings()).thenReturn(s);
// Player
Player p = mock(Player.class);
// Sometimes use Mockito.withSettings().verboseLogging()
user = mock(User.class);
when(user.isOp()).thenReturn(false);
UUID uuid = UUID.randomUUID();
notUUID = UUID.randomUUID();
while(notUUID.equals(uuid)) {
notUUID = UUID.randomUUID();
}
when(user.getUniqueId()).thenReturn(uuid);
when(user.getPlayer()).thenReturn(p);
when(user.getName()).thenReturn("tastybento");
User.setPlugin(plugin);
// Parent command has no aliases
ac = mock(CompositeCommand.class);
when(ac.getSubCommandAliases()).thenReturn(new HashMap<>());
// Island World Manager
IslandWorldManager iwm = mock(IslandWorldManager.class);
when(plugin.getIWM()).thenReturn(iwm);
// Player has island to begin with
im = mock(IslandsManager.class);
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
when(im.isOwner(Mockito.any(),Mockito.any())).thenReturn(true);
when(im.getOwner(Mockito.any(),Mockito.any())).thenReturn(uuid);
when(plugin.getIslands()).thenReturn(im);
// Has team
pm = mock(PlayersManager.class);
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
when(plugin.getPlayers()).thenReturn(pm);
// Server & Scheduler
BukkitScheduler sch = mock(BukkitScheduler.class);
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getScheduler()).thenReturn(sch);
// Locales
LocalesManager lm = mock(LocalesManager.class);
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
when(plugin.getLocalesManager()).thenReturn(lm);
}
/**
* Test method for .
*/
@Test
public void testExecuteNoTarget() {
AdminClearresetsCommand itl = new AdminClearresetsCommand(ac);
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>()));
// Show help
Mockito.verify(user).sendMessage(Mockito.eq("commands.help.header"), Mockito.eq("[label]"), Mockito.any());
}
/**
* Test method for .
*/
@Test
public void testExecuteUnknownPlayer() {
AdminClearresetsCommand itl = new AdminClearresetsCommand(ac);
String[] name = {"tastybento"};
when(pm.getUUID(Mockito.any())).thenReturn(null);
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
Mockito.verify(user).sendMessage("general.errors.unknown-player", "[name]", name[0]);
}
/**
* Test method for .
*/
@Test
public void testExecutePlayerNoIsland() {
AdminClearresetsCommand itl = new AdminClearresetsCommand(ac);
String[] name = {"tastybento"};
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.player-has-no-island"));
}
@Test
public void testExecuteSuccess() {
String[] name = {"tastybento"};
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
AdminClearresetsCommand itl = new AdminClearresetsCommand(ac);
assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
// Add other verifications
Mockito.verify(user).sendMessage("commands.admin.clearresets.cleared");
Mockito.verify(user).sendMessage(Mockito.eq("general.success"));
}
}

View File

@ -1,120 +0,0 @@
package world.bentobox.bentobox.api.commands.admin;
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.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitScheduler;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
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;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.managers.CommandsManager;
import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.LocalesManager;
import world.bentobox.bentobox.managers.PlayersManager;
@RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
public class AdminClearresetsallCommandTest {
private CompositeCommand ac;
private User user;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
// Set up plugin
BentoBox plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
// Command manager
CommandsManager cm = mock(CommandsManager.class);
when(plugin.getCommandsManager()).thenReturn(cm);
// Settings
Settings s = mock(Settings.class);
when(s.getResetCooldown()).thenReturn(0);
when(plugin.getSettings()).thenReturn(s);
// Player
Player p = mock(Player.class);
// Sometimes use Mockito.withSettings().verboseLogging()
user = mock(User.class);
when(user.isOp()).thenReturn(false);
UUID uuid = UUID.randomUUID();
UUID notUUID = UUID.randomUUID();
while(notUUID.equals(uuid)) {
notUUID = UUID.randomUUID();
}
when(user.getUniqueId()).thenReturn(uuid);
when(user.getPlayer()).thenReturn(p);
when(user.getName()).thenReturn("tastybento");
User.setPlugin(plugin);
// Parent command has no aliases
ac = mock(CompositeCommand.class);
when(ac.getSubCommandAliases()).thenReturn(new HashMap<>());
// Island World Manager
IslandWorldManager iwm = mock(IslandWorldManager.class);
when(plugin.getIWM()).thenReturn(iwm);
// Player has island to begin with
IslandsManager im = mock(IslandsManager.class);
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
when(im.isOwner(Mockito.any(),Mockito.any())).thenReturn(true);
when(im.getOwner(Mockito.any(),Mockito.any())).thenReturn(uuid);
when(plugin.getIslands()).thenReturn(im);
// Has team
PlayersManager pm = mock(PlayersManager.class);
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
when(plugin.getPlayers()).thenReturn(pm);
// Server & Scheduler
BukkitScheduler sch = mock(BukkitScheduler.class);
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getScheduler()).thenReturn(sch);
// Locales
LocalesManager lm = mock(LocalesManager.class);
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
when(plugin.getLocalesManager()).thenReturn(lm);
}
/**
* Test method for .
*/
@SuppressWarnings("deprecation")
@Test
public void testExecuteCheckConfirm() {
AdminClearresetsallCommand itl = new AdminClearresetsallCommand(ac);
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>(Arrays.asList("tastybento", "bobby"))));
assertTrue(itl.execute(user, itl.getLabel(), new ArrayList<>()));
Mockito.verify(user).sendMessage(Mockito.eq("commands.confirmation.confirm"), Mockito.eq("[seconds]"), Mockito.any());
}
}