-
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added clear resets and clear reset all admin commands.
Clear reset all uses a timestamp stored in config.yml. If a player logs in and the last time they logged in was before that timestamp, then their resets are cleared. Note that as opposed to ASkyBlock, the player object stores the number of resets done for a world and not the number of resets left. This is a better design because it means that admins can change the max number of resets and every player file does not have to be adjusted. Location of commit (30,000ft above Nevada desert, just coming into Las Vegas).
- Loading branch information
1 parent
541ee35
commit 9c41ceb
Showing
7 changed files
with
356 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 0 additions & 52 deletions
52
src/main/java/us/tastybento/bskyblock/commands/admin/AdminClearResetAllCommand.java
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
src/main/java/us/tastybento/bskyblock/commands/admin/AdminClearResetsAllCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package us.tastybento.bskyblock.commands.admin; | ||
|
||
import java.util.List; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
|
||
import us.tastybento.bskyblock.api.commands.CompositeCommand; | ||
import us.tastybento.bskyblock.api.user.User; | ||
|
||
public class AdminClearResetsAllCommand extends CompositeCommand { | ||
|
||
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 are not right, show help | ||
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 false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
src/test/java/us/tastybento/bskyblock/commands/admin/AdminClearResetsAllCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package us.tastybento.bskyblock.commands.admin; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.UUID; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.World; | ||
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 us.tastybento.bskyblock.BSkyBlock; | ||
import us.tastybento.bskyblock.Settings; | ||
import us.tastybento.bskyblock.api.user.User; | ||
import us.tastybento.bskyblock.commands.AdminCommand; | ||
import us.tastybento.bskyblock.managers.CommandsManager; | ||
import us.tastybento.bskyblock.managers.IslandWorldManager; | ||
import us.tastybento.bskyblock.managers.IslandsManager; | ||
import us.tastybento.bskyblock.managers.LocalesManager; | ||
import us.tastybento.bskyblock.managers.PlayersManager; | ||
|
||
@RunWith(PowerMockRunner.class) | ||
@PrepareForTest({Bukkit.class, BSkyBlock.class, User.class }) | ||
public class AdminClearResetsAllCommandTest { | ||
|
||
private AdminCommand 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 | ||
BSkyBlock plugin = mock(BSkyBlock.class); | ||
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin); | ||
|
||
// Command manager | ||
CommandsManager cm = mock(CommandsManager.class); | ||
when(plugin.getCommandsManager()).thenReturn(cm); | ||
|
||
// Settings | ||
Settings s = mock(Settings.class); | ||
when(s.getResetWait()).thenReturn(0L); | ||
when(s.getResetLimit()).thenReturn(3); | ||
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(AdminCommand.class); | ||
when(ac.getSubCommandAliases()).thenReturn(new HashMap<>()); | ||
|
||
// Island World Manager | ||
IslandWorldManager iwm = mock(IslandWorldManager.class); | ||
World world = mock(World.class); | ||
when(iwm.getBSBIslandWorld()).thenReturn(world); | ||
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.getTeamLeader(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 {@link us.tastybento.bskyblock.commands.admin.AdminClearResetsAllCommand#execute(us.tastybento.bskyblock.api.user.User, java.util.List)}. | ||
*/ | ||
@Test | ||
public void testExecuteCheckConfirm() { | ||
AdminClearResetsAllCommand itl = new AdminClearResetsAllCommand(ac); | ||
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>())); | ||
Mockito.verify(user).sendMessage(Mockito.eq("general.confirm"), Mockito.eq("[seconds]"), Mockito.any()); | ||
} | ||
|
||
} |
Oops, something went wrong.