mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-28 13:45:14 +01:00
Made /is reset use the command cooldown API + switched "wait" settings to int
Aaaand had to update some tests. Lots of tests.
This commit is contained in:
parent
bfff61e6a1
commit
e11f173ca3
@ -135,20 +135,20 @@ public class Settings implements DataObject {
|
||||
private boolean kickConfirmation = true;
|
||||
|
||||
@ConfigEntry(path = "island.require-confirmation.kick-wait")
|
||||
private long kickWait = 10L;
|
||||
private int kickWait = 10;
|
||||
|
||||
@ConfigEntry(path = "island.require-confirmation.leave")
|
||||
private boolean leaveConfirmation = true;
|
||||
|
||||
@ConfigEntry(path = "island.require-confirmation.leave-wait")
|
||||
private long leaveWait = 10L;
|
||||
private int leaveWait = 10;
|
||||
|
||||
@ConfigEntry(path = "island.require-confirmation.reset")
|
||||
private boolean resetConfirmation = true;
|
||||
|
||||
@ConfigComment("How long a player must wait before they can reset their island again in seconds")
|
||||
@ConfigEntry(path = "island.reset-wait")
|
||||
private long resetWait = 300;
|
||||
private int resetWait = 300;
|
||||
|
||||
@ConfigComment("These set the minimum and maximum size of a name.")
|
||||
@ConfigEntry(path = "island.name.min-length")
|
||||
@ -475,7 +475,7 @@ public class Settings implements DataObject {
|
||||
/**
|
||||
* @return the kickWait
|
||||
*/
|
||||
public long getKickWait() {
|
||||
public int getKickWait() {
|
||||
return kickWait;
|
||||
}
|
||||
|
||||
@ -489,7 +489,7 @@ public class Settings implements DataObject {
|
||||
/**
|
||||
* @return the leaveWait
|
||||
*/
|
||||
public long getLeaveWait() {
|
||||
public int getLeaveWait() {
|
||||
return leaveWait;
|
||||
}
|
||||
|
||||
@ -503,7 +503,7 @@ public class Settings implements DataObject {
|
||||
/**
|
||||
* @param kickWait the kickWait to set
|
||||
*/
|
||||
public void setKickWait(long kickWait) {
|
||||
public void setKickWait(int kickWait) {
|
||||
this.kickWait = kickWait;
|
||||
}
|
||||
|
||||
@ -517,21 +517,21 @@ public class Settings implements DataObject {
|
||||
/**
|
||||
* @param leaveWait the leaveWait to set
|
||||
*/
|
||||
public void setLeaveWait(long leaveWait) {
|
||||
public void setLeaveWait(int leaveWait) {
|
||||
this.leaveWait = leaveWait;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the resetWait
|
||||
*/
|
||||
public long getResetWait() {
|
||||
public int getResetWait() {
|
||||
return resetWait;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resetWait the resetWait to set
|
||||
*/
|
||||
public void setResetWait(long resetWait) {
|
||||
public void setResetWait(int resetWait) {
|
||||
this.resetWait = resetWait;
|
||||
}
|
||||
|
||||
|
@ -19,15 +19,12 @@ import world.bentobox.bentobox.managers.island.NewIsland;
|
||||
|
||||
public class IslandResetCommand extends ConfirmableCommand {
|
||||
|
||||
private Map<UUID, Long> cooldown;
|
||||
|
||||
public IslandResetCommand(CompositeCommand islandCommand) {
|
||||
super(islandCommand, "reset", "restart");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
cooldown = new HashMap<>();
|
||||
setPermission("island.create");
|
||||
setOnlyPlayer(true);
|
||||
setDescription("commands.island.reset.description");
|
||||
@ -36,10 +33,10 @@ public class IslandResetCommand extends ConfirmableCommand {
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
// Check cooldown
|
||||
if (getSettings().getResetWait() > 0 && onRestartWaitTime(user) > 0 && !user.isOp()) {
|
||||
user.sendMessage("general.errors.you-must-wait", TextVariables.NUMBER, String.valueOf(onRestartWaitTime(user)));
|
||||
if (getSettings().getResetWait() > 0 && checkCooldown(user, null)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!getIslands().hasIsland(getWorld(), user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return false;
|
||||
@ -104,18 +101,7 @@ public class IslandResetCommand extends ConfirmableCommand {
|
||||
user.sendMessage("commands.island.create.unable-create-island");
|
||||
return false;
|
||||
}
|
||||
setCooldown(user);
|
||||
setCooldown(user.getUniqueId(), null, getSettings().getResetWait());
|
||||
return true;
|
||||
}
|
||||
|
||||
private int onRestartWaitTime(User user) {
|
||||
if (!cooldown.containsKey(user.getUniqueId())) {
|
||||
return 0;
|
||||
}
|
||||
return (int) (System.currentTimeMillis() - cooldown.get(user.getUniqueId()) / 1000);
|
||||
}
|
||||
|
||||
private void setCooldown(User user) {
|
||||
cooldown.put(user.getUniqueId(), System.currentTimeMillis() + (getIWM().getResetLimit(getWorld()) * 1000L));
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,6 @@ public class DefaultHelpCommandTest {
|
||||
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
|
@ -54,7 +54,7 @@ public class AdminClearResetsAllCommandTest {
|
||||
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getResetWait()).thenReturn(0);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
|
@ -64,7 +64,6 @@ public class AdminClearResetsCommandTest {
|
||||
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
|
@ -66,7 +66,7 @@ public class AdminDeleteCommandTest {
|
||||
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getResetWait()).thenReturn(0);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
|
@ -66,11 +66,6 @@ public class AdminInfoCommandTest {
|
||||
CommandsManager cm = mock(CommandsManager.class);
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
|
@ -65,11 +65,6 @@ public class AdminRegisterCommandTest {
|
||||
CommandsManager cm = mock(CommandsManager.class);
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
|
@ -63,11 +63,6 @@ public class AdminUnregisterCommandTest {
|
||||
CommandsManager cm = mock(CommandsManager.class);
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
|
@ -53,11 +53,6 @@ public class AdminRangeCommandTest {
|
||||
CommandsManager cm = mock(CommandsManager.class);
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
|
@ -58,11 +58,6 @@ public class AdminRangeDisplayCommandTest {
|
||||
CommandsManager cm = mock(CommandsManager.class);
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
|
@ -66,11 +66,6 @@ public class AdminRangeResetCommandTest {
|
||||
CommandsManager cm = mock(CommandsManager.class);
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
|
@ -66,11 +66,6 @@ public class AdminRangeSetCommandTest {
|
||||
CommandsManager cm = mock(CommandsManager.class);
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
|
@ -63,11 +63,6 @@ public class AdminTeamAddCommandTest {
|
||||
CommandsManager cm = mock(CommandsManager.class);
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
|
@ -64,11 +64,6 @@ public class AdminTeamDisbandCommandTest {
|
||||
CommandsManager cm = mock(CommandsManager.class);
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
|
@ -66,11 +66,6 @@ public class AdminTeamKickCommandTest {
|
||||
CommandsManager cm = mock(CommandsManager.class);
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
|
@ -64,11 +64,6 @@ public class AdminTeamMakeLeaderCommandTest {
|
||||
CommandsManager cm = mock(CommandsManager.class);
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
|
@ -76,7 +76,6 @@ public class IslandBanCommandTest {
|
||||
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getRankCommand(Mockito.anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
|
@ -69,8 +69,6 @@ public class IslandBanlistCommandTest {
|
||||
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
|
@ -66,8 +66,6 @@ public class IslandGoCommandTest {
|
||||
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
|
@ -70,8 +70,7 @@ public class IslandResetCommandTest {
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
|
||||
when(s.getResetWait()).thenReturn(0);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
|
@ -73,7 +73,6 @@ public class IslandUnbanCommandTest {
|
||||
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getRankCommand(Mockito.anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
@ -69,7 +69,6 @@ public class IslandTeamCoopCommandTest {
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getRankCommand(Mockito.anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
@ -68,9 +68,7 @@ public class IslandTeamInviteCommandTest {
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getRankCommand(Mockito.anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
|
@ -74,8 +74,6 @@ public class IslandTeamKickCommandTest {
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
|
@ -66,8 +66,7 @@ public class IslandTeamLeaveCommandTest {
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
|
||||
when(s.getResetWait()).thenReturn(0);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
@ -150,7 +149,7 @@ public class IslandTeamLeaveCommandTest {
|
||||
public void testExecuteWithConfirmation() {
|
||||
when(s.isLeaveConfirmation()).thenReturn(true);
|
||||
// 3 second timeout
|
||||
when(s.getLeaveWait()).thenReturn(3L);
|
||||
when(s.getLeaveWait()).thenReturn(3);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
||||
when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
||||
// Add a team leader - null
|
||||
|
@ -69,7 +69,6 @@ public class IslandTeamTrustCommandTest {
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getRankCommand(Mockito.anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
@ -69,7 +69,6 @@ public class IslandTeamUncoopCommandTest {
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getRankCommand(Mockito.anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
@ -69,7 +69,6 @@ public class IslandTeamUntrustCommandTest {
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getRankCommand(Mockito.anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
@ -77,7 +77,6 @@ public class CycleClickTest {
|
||||
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
|
@ -85,8 +85,6 @@ public class LockAndBanListenerTest {
|
||||
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
|
@ -96,8 +96,6 @@ public class IslandsManagerTest {
|
||||
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
|
Loading…
Reference in New Issue
Block a user