WIP - clear reset all command

This commit is contained in:
tastybento 2018-07-25 07:04:40 -07:00
parent 342387cf09
commit 541ee35256
14 changed files with 303 additions and 84 deletions

View File

@ -438,6 +438,10 @@ public class Settings implements DataObject, WorldSettings {
private boolean closePanelOnClickOutside = true;
//---------------------------------------------------------------------------------------/
@ConfigComment("These settings should not be edited")
@ConfigEntry(path = "do-not-edit-these-settings.reset-epoch")
private long resetEpoch = 0;
private String uniqueId = "config";
// Getters and setters
@ -680,6 +684,7 @@ public class Settings implements DataObject, WorldSettings {
/**
* @return the resetLimit
*/
@Override
public int getResetLimit() {
return resetLimit;
}
@ -1479,6 +1484,20 @@ public class Settings implements DataObject, WorldSettings {
public void setGeoLimitSettings(List<String> geoLimitSettings) {
this.geoLimitSettings = geoLimitSettings;
}
/**
* @return the resetEpoch
*/
@Override
public long getResetEpoch() {
return resetEpoch;
}
/**
* @param resetEpoch the resetEpoch to set
*/
@Override
public void setResetEpoch(long resetEpoch) {
this.resetEpoch = resetEpoch;
}
}

View File

@ -235,4 +235,20 @@ public interface WorldSettings {
* @return list of entity types that should not exit the island limits
*/
List<String> getGeoLimitSettings();
/**
* @return reset limit for world
*/
int getResetLimit();
/**
* Get the island reset time stamp. Any player who last logged in before this time will have resets zeroed
*/
long getResetEpoch();
/**
* Set the island reset time stamp. Any player who last logged in before this time will have resets zeroed
*/
void setResetEpoch(long timestamp);
}

View File

@ -5,6 +5,8 @@ import java.util.List;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.localization.TextVariables;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.commands.admin.AdminClearResetAllCommand;
import us.tastybento.bskyblock.commands.admin.AdminClearResetCommand;
import us.tastybento.bskyblock.commands.admin.AdminGetRankCommand;
import us.tastybento.bskyblock.commands.admin.AdminInfoCommand;
import us.tastybento.bskyblock.commands.admin.AdminRegisterCommand;
@ -54,6 +56,9 @@ public class AdminCommand extends CompositeCommand {
new AdminUnregisterCommand(this);
// Range
new AdminRangeCommand(this);
// Resets
new AdminClearResetCommand(this);
new AdminClearResetAllCommand(this);
}
@Override

View File

@ -0,0 +1,52 @@
package us.tastybento.bskyblock.commands.admin;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.util.Util;
public class AdminClearResetAllCommand extends CompositeCommand {
public AdminClearResetAllCommand(CompositeCommand parent) {
super(parent, "clearresetall");
}
@Override
public void setup() {
setPermission("admin.clearresetall");
setParameters("commands.admin.clearreset.parameters");
setDescription("commands.admin.clearreset.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;
}
// 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;
}
@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

@ -0,0 +1,59 @@
package us.tastybento.bskyblock.commands.admin;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.util.Util;
public class AdminClearResetCommand extends CompositeCommand {
public AdminClearResetCommand(CompositeCommand parent) {
super(parent, "clearreset");
}
@Override
public void setup() {
setPermission("admin.clearreset");
setParameters("commands.admin.clearreset.parameters");
setDescription("commands.admin.clearreset.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");
return false;
}
if (!getIslands().hasIsland(getWorld(), targetUUID)) {
user.sendMessage("general.errors.player-has-no-island");
return false;
}
// Clear resets
user.sendMessage("commands.admin.clearreset.cleared");
getPlayers().setResets(getWorld(), user.getUniqueId(), 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

@ -51,13 +51,14 @@ public class IslandResetCommand extends CompositeCommand {
user.sendMessage("commands.island.reset.must-remove-members");
return false;
}
if (getSettings().getResetLimit() >= 0 ) {
if (getPlayers().getResetsLeft(user.getUniqueId()) == 0) {
if (getIWM().getResetLimit(getWorld()) >= 0 ) {
int resetsLeft = getIWM().getResetLimit(getWorld()) - getPlayers().getResets(getWorld(), user.getUniqueId());
if (resetsLeft <= 0) {
user.sendMessage("commands.island.reset.none-left");
return false;
} else {
// Notify how many resets are left
user.sendMessage("commands.island.reset.resets-left", TextVariables.NUMBER, String.valueOf(getPlayers().getResetsLeft(user.getUniqueId())));
user.sendMessage("commands.island.reset.resets-left", TextVariables.NUMBER, String.valueOf(resetsLeft));
}
}
// Request confirmation
@ -88,6 +89,8 @@ public class IslandResetCommand extends CompositeCommand {
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
// TODO: needs Vault
}
// Add a reset
getPlayers().addReset(getWorld(), user.getUniqueId());
// Create new island and then delete the old one
try {
NewIsland.builder()

View File

@ -600,7 +600,7 @@ public class Island implements DataObject {
user.sendMessage("commands.admin.info.last-login","[date]", d.toString());
user.sendMessage("commands.admin.info.deaths", "[number]", String.valueOf(plugin.getPlayers().getDeaths(owner)));
String resets = String.valueOf(plugin.getPlayers().getResetsLeft(owner));
String resets = String.valueOf(plugin.getPlayers().getResets(world, owner));
String total = plugin.getSettings().getResetLimit() < 0 ? "Unlimited" : String.valueOf(plugin.getSettings().getResetLimit());
user.sendMessage("commands.admin.info.resets-left", "[number]", resets, "[total]", total);
// Show team members

View File

@ -30,7 +30,7 @@ public class Players implements DataObject {
@Expose
private String playerName;
@Expose
private int resetsLeft;
private Map<String, Integer> resets = new HashMap<>();
@Expose
private String locale = "";
@Expose
@ -52,7 +52,6 @@ public class Players implements DataObject {
public Players(BSkyBlock plugin, UUID uniqueId) {
this.uniqueId = uniqueId.toString();
homeLocations = new HashMap<>();
resetsLeft = plugin.getSettings().getResetLimit();
locale = "";
kickedList = new HashMap<>();
// Try to get player's name
@ -142,18 +141,35 @@ public class Players implements DataObject {
}
/**
* Get number of resets done in this world
* @param world - world
* @return the resetsLeft
*/
public int getResetsLeft() {
return resetsLeft;
public int getResets(World world) {
resets.putIfAbsent(world.getName(), 0);
return resets.get(world.getName());
}
/**
* @param resetsLeft
* the resetsLeft to set
* @return the resets
*/
public void setResetsLeft(int resetsLeft) {
this.resetsLeft = resetsLeft;
public Map<String, Integer> getResets() {
return resets;
}
/**
* @param resets the resets to set
*/
public void setResets(Map<String, Integer> resets) {
this.resets = resets;
}
/**
* @param resets
* the resets to set
*/
public void setResets(World world, int resets) {
this.resets.put(world.getName(), resets);
}
/**
@ -281,4 +297,12 @@ public class Players implements DataObject {
this.uniqueId = uniqueId;
}
/**
* Increments the reset counter for player in world
* @param world - world
*/
public void addReset(World world) {
resets.merge(world.getName(), 1, Integer::sum);
}
}

View File

@ -39,11 +39,10 @@ public class JoinLeaveListener implements Listener {
if (plugin.getPlayers().isKnown(playerUUID)) {
// Load player
players.addPlayer(playerUUID);
// Reset resets if the admin changes it to or from unlimited
if (plugin.getSettings().getResetLimit() < players.getResetsLeft(playerUUID) || (plugin.getSettings().getResetLimit() >= 0 && players.getResetsLeft(playerUUID) < 0)) {
players.setResetsLeft(playerUUID, plugin.getSettings().getResetLimit());
}
// Reset island resets if required
plugin.getIWM().getOverWorlds().stream()
.filter(w -> event.getPlayer().getLastPlayed() < plugin.getIWM().getResetEpoch(w))
.forEach(w -> players.setResets(w, playerUUID, 0));
// Set the player's name (it may have changed), but only if it isn't empty
if (!user.getName().isEmpty()) {
players.setPlayerName(user);

View File

@ -734,4 +734,30 @@ public class IslandWorldManager {
public List<String> getGeoLimitSettings(World world) {
return worldSettings.get(Util.getWorld(world)).getGeoLimitSettings();
}
/**
* Get the reset limit for this world
* @param world - world
* @return number of resets allowed. -1 = unlimited
*/
public int getResetLimit(World world) {
return worlds.containsKey(Util.getWorld(world)) ? worldSettings.get(Util.getWorld(world)).getResetLimit() : -1;
}
/**
* Gets the time stamp for when all player resets were zeroed
* @param world
*/
public long getResetEpoch(World world) {
return worldSettings.get(Util.getWorld(world)).getResetEpoch();
}
/**
* Sets the time stamp for when all player resets were zeroed
* @param world
*/
public void setResetEpoch(World world) {
worldSettings.get(Util.getWorld(world)).setResetEpoch(System.currentTimeMillis());
}
}

View File

@ -145,7 +145,7 @@ public class PlayersManager {
}
// Try cache
return playerCache.containsKey(uniqueID) || handler.objectExists(uniqueID.toString());
// Get from the database - do not add to cache yet
// Get from the database - do not add to cache yet
}
/**
@ -158,7 +158,7 @@ public class PlayersManager {
addPlayer(user.getUniqueId());
playerCache.get(user.getUniqueId()).setHomeLocation(location,number);
}
/**
* Sets the home location for the player
* @param playerUUID - the player's UUID
@ -202,7 +202,7 @@ public class PlayersManager {
addPlayer(user.getUniqueId());
return playerCache.get(user.getUniqueId()).getHomeLocation(world, number);
}
/**
* Returns the home location, or null if none
* @param world - world
@ -286,25 +286,27 @@ public class PlayersManager {
}
/**
* Gets how many island resets the player has left
* Gets how many island resets the player has done
* @param world
*
* @param playerUUID - the player's UUID
* @return number of resets
*/
public int getResetsLeft(UUID playerUUID) {
public int getResets(World world, UUID playerUUID) {
addPlayer(playerUUID);
return playerCache.get(playerUUID).getResetsLeft();
return playerCache.get(playerUUID).getResets(world);
}
/**
* Sets how many resets the player has left
* Sets how many resets the player has performed
*
* @param world - world
* @param playerUUID - the player's UUID
* @param resets - number of resets
*/
public void setResetsLeft(UUID playerUUID, int resets) {
public void setResets(World world, UUID playerUUID, int resets) {
addPlayer(playerUUID);
playerCache.get(playerUUID).setResetsLeft(resets);
playerCache.get(playerUUID).setResets(world, resets);
}
/**
@ -437,4 +439,11 @@ public class PlayersManager {
return User.getInstance(uuid);
}
public void addReset(World world, UUID playerUUID) {
addPlayer(playerUUID);
playerCache.get(playerUUID).addReset(world);
}
}

View File

@ -1,5 +1,5 @@
/**
*
*
*/
package us.tastybento.bskyblock.commands.island;
@ -14,6 +14,7 @@ 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.bukkit.scheduler.BukkitTask;
@ -51,6 +52,8 @@ public class IslandResetCommandTest {
private Settings s;
private IslandsManager im;
private PlayersManager pm;
private World world;
private IslandWorldManager iwm;
/**
* @throws java.lang.Exception
@ -60,17 +63,17 @@ public class IslandResetCommandTest {
// 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
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);
// User, sometime use Mockito.withSettings().verboseLogging()
@ -79,18 +82,21 @@ public class IslandResetCommandTest {
uuid = UUID.randomUUID();
when(user.getUniqueId()).thenReturn(uuid);
when(user.getPlayer()).thenReturn(p);
// Parent command has no aliases
ic = mock(IslandCommand.class);
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
when(ic.getTopLabel()).thenReturn("island");
// World
world = mock(World.class);
when(ic.getWorld()).thenReturn(world);
// No island for player to begin with (set it later in the tests)
im = mock(IslandsManager.class);
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
when(plugin.getIslands()).thenReturn(im);
// Has team
pm = mock(PlayersManager.class);
@ -104,19 +110,20 @@ public class IslandResetCommandTest {
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getScheduler()).thenReturn(sch);
// IWM friendly name
IslandWorldManager iwm = mock(IslandWorldManager.class);
iwm = mock(IslandWorldManager.class);
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
when(plugin.getIWM()).thenReturn(iwm);
when(iwm.getResetLimit(Mockito.any())).thenReturn(3);
}
/**
* Test method for {@link us.tastybento.bskyblock.commands.island.IslandResetCommand#execute(us.tastybento.bskyblock.api.user.User, java.util.List)}.
* @throws IOException
* @throws IOException
*/
@Test
public void testNoIsland() throws IOException {
@ -126,7 +133,7 @@ public class IslandResetCommandTest {
assertFalse(irc.execute(user, irc.getLabel(), new ArrayList<>()));
Mockito.verify(user).sendMessage("general.errors.no-island");
}
@Test
public void testNotLeader() throws IOException {
IslandResetCommand irc = new IslandResetCommand(ic);
@ -135,7 +142,7 @@ public class IslandResetCommandTest {
assertFalse(irc.execute(user, irc.getLabel(), new ArrayList<>()));
Mockito.verify(user).sendMessage("general.errors.not-leader");
}
@Test
public void testHasTeam() throws IOException {
IslandResetCommand irc = new IslandResetCommand(ic);
@ -146,7 +153,7 @@ public class IslandResetCommandTest {
assertFalse(irc.execute(user, irc.getLabel(), new ArrayList<>()));
Mockito.verify(user).sendMessage("commands.island.reset.must-remove-members");
}
@Test
public void testNoResetsLeft() throws IOException {
IslandResetCommand irc = new IslandResetCommand(ic);
@ -156,14 +163,14 @@ public class IslandResetCommandTest {
when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
// Now has no team
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
// Block based on no resets left
when(pm.getResetsLeft(Mockito.eq(uuid))).thenReturn(0);
when(pm.getResets(Mockito.eq(world),Mockito.eq(uuid))).thenReturn(3);
assertFalse(irc.execute(user, irc.getLabel(), new ArrayList<>()));
Mockito.verify(user).sendMessage("commands.island.reset.none-left");
}
@Test
public void testNoConfirmationRequired() throws IOException {
IslandResetCommand irc = new IslandResetCommand(ic);
@ -174,14 +181,14 @@ public class IslandResetCommandTest {
// Now has no team
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
// Give the user some resets
when(pm.getResetsLeft(Mockito.eq(uuid))).thenReturn(1);
when(pm.getResets(Mockito.eq(world), Mockito.eq(uuid))).thenReturn(1);
// Set so no confirmation required
when(s.isResetConfirmation()).thenReturn(false);
// Old island mock
Island oldIsland = mock(Island.class);
when(im.getIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(oldIsland);
// Mock up NewIsland builder
NewIsland.Builder builder = mock(NewIsland.Builder.class);
when(builder.player(Mockito.any())).thenReturn(builder);
@ -195,9 +202,9 @@ public class IslandResetCommandTest {
assertTrue(irc.execute(user, irc.getLabel(), new ArrayList<>()));
// Verify that build new island was called and the number of resets left shown
Mockito.verify(builder).build();
Mockito.verify(user).sendMessage("commands.island.reset.resets-left", "[number]", "1");
Mockito.verify(user).sendMessage("commands.island.reset.resets-left", "[number]", "2");
}
@Test
public void testUnlimitedResets() throws IOException {
IslandResetCommand irc = new IslandResetCommand(ic);
@ -208,14 +215,14 @@ public class IslandResetCommandTest {
// Now has no team
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
// Give the user some resets
when(pm.getResetsLeft(Mockito.eq(uuid))).thenReturn(1);
when(pm.getResets(Mockito.eq(world), Mockito.eq(uuid))).thenReturn(1);
// Set so no confirmation required
when(s.isResetConfirmation()).thenReturn(false);
// Old island mock
Island oldIsland = mock(Island.class);
when(im.getIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(oldIsland);
// Mock up NewIsland builder
NewIsland.Builder builder = mock(NewIsland.Builder.class);
when(builder.player(Mockito.any())).thenReturn(builder);
@ -225,16 +232,16 @@ public class IslandResetCommandTest {
PowerMockito.mockStatic(NewIsland.class);
when(NewIsland.builder()).thenReturn(builder);
// Test with unlimited resets
when(s.getResetLimit()).thenReturn(-1);
when(iwm.getResetLimit(Mockito.any())).thenReturn(-1);
// Reset
assertTrue(irc.execute(user, irc.getLabel(), new ArrayList<>()));
// Verify that build new island was called and the number of resets left shown
Mockito.verify(builder).build();
// This should not be shown
Mockito.verify(user, Mockito.never()).sendMessage("commands.island.reset.resets-left", "[number]", "1");
Mockito.verify(user, Mockito.never()).sendMessage("commands.island.reset.resets-left", "[number]", "1");
}
@Test
public void testConfirmationRequired() throws IOException {
IslandResetCommand irc = new IslandResetCommand(ic);
@ -245,14 +252,14 @@ public class IslandResetCommandTest {
// Now has no team
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
// Give the user some resets
when(pm.getResetsLeft(Mockito.eq(uuid))).thenReturn(1);
when(pm.getResets(Mockito.eq(world), Mockito.eq(uuid))).thenReturn(1);
// Set so no confirmation required
when(s.isResetConfirmation()).thenReturn(false);
// Old island mock
Island oldIsland = mock(Island.class);
when(im.getIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(oldIsland);
// Mock up NewIsland builder
NewIsland.Builder builder = mock(NewIsland.Builder.class);
when(builder.player(Mockito.any())).thenReturn(builder);
@ -270,12 +277,12 @@ public class IslandResetCommandTest {
assertTrue(irc.execute(user, irc.getLabel(), new ArrayList<>()));
// Check for message
Mockito.verify(user).sendMessage("general.confirm", "[seconds]", String.valueOf(s.getConfirmationTime()));
// Send command again to confirm
assertTrue(irc.execute(user, irc.getLabel(), new ArrayList<>()));
}
@Test
public void testNewIslandError() throws IOException {
IslandResetCommand irc = new IslandResetCommand(ic);
@ -286,14 +293,14 @@ public class IslandResetCommandTest {
// Now has no team
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
// Give the user some resets
when(pm.getResetsLeft(Mockito.eq(uuid))).thenReturn(1);
when(pm.getResets(Mockito.eq(world), Mockito.eq(uuid))).thenReturn(1);
// Set so no confirmation required
when(s.isResetConfirmation()).thenReturn(false);
// Old island mock
Island oldIsland = mock(Island.class);
when(im.getIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(oldIsland);
// Mock up NewIsland builder
NewIsland.Builder builder = mock(NewIsland.Builder.class);
when(builder.player(Mockito.any())).thenReturn(builder);
@ -305,11 +312,11 @@ public class IslandResetCommandTest {
// Require no confirmation
when(s.isResetConfirmation()).thenReturn(false);
// Reset
assertFalse(irc.execute(user, irc.getLabel(), new ArrayList<>()));
Mockito.verify(user).sendMessage("commands.island.create.unable-create-island");
}
}

View File

@ -120,7 +120,7 @@ public class MySQLDatabaseHandlerTest {
players.setLocale("sdfsd");
players.setPlayerName("name");
players.setPlayerUUID(UUID.randomUUID());
players.setResetsLeft(3);
players.setResets(world, 3);
MySQLDatabaseHandler<Players> h = new MySQLDatabaseHandler<>(plugin, Players.class, dbConn);

View File

@ -1,5 +1,5 @@
/**
*
*
*/
package us.tastybento.bskyblock.managers;
@ -66,7 +66,7 @@ public class PlayersManagerTest {
// Set up plugin
plugin = mock(BSkyBlock.class);
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
// island world mgr
IslandWorldManager iwm = mock(IslandWorldManager.class);
world = mock(World.class);
@ -80,11 +80,11 @@ public class PlayersManagerTest {
when(iwm.getBSBNetherWorld()).thenReturn(nether);
when(iwm.inWorld(any())).thenReturn(true);
when(plugin.getIWM()).thenReturn(iwm);
// Settings
Settings s = mock(Settings.class);
when(plugin.getSettings()).thenReturn(s);
// Set up spawn
Location netherSpawn = mock(Location.class);
when(netherSpawn.toVector()).thenReturn(new Vector(0,0,0));
@ -106,7 +106,7 @@ public class PlayersManagerTest {
when(user.getName()).thenReturn("tastybento");
User.setPlugin(plugin);
// Player has island to begin with
// Player has island to begin with
IslandsManager im = mock(IslandsManager.class);
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
when(im.isOwner(Mockito.any(), Mockito.any())).thenReturn(true);
@ -123,10 +123,10 @@ public class PlayersManagerTest {
LocalesManager lm = mock(LocalesManager.class);
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
when(plugin.getLocalesManager()).thenReturn(lm);
// Normally in world
Util.setPlugin(plugin);
// Mock database
db = mock(BSBDatabase.class);
PowerMockito.whenNew(BSBDatabase.class).withAnyArguments().thenReturn(db);
@ -239,7 +239,7 @@ public class PlayersManagerTest {
pm.addPlayer(uuid);
pm.addPlayer(notUUID);
pm.removeAllPlayers();
}
@ -324,7 +324,7 @@ public class PlayersManagerTest {
public void testGetUUID() {
PlayersManager pm = new PlayersManager(plugin);
assertEquals(uuid,pm.getUUID(uuid.toString()));
OfflinePlayer olp = mock(OfflinePlayer.class);
when(olp.getUniqueId()).thenReturn(uuid);
PowerMockito.mockStatic(Bukkit.class);
@ -339,13 +339,13 @@ public class PlayersManagerTest {
@Override
public Names answer(InvocationOnMock invocation) throws Throwable {
return name;
}
});
assertEquals(uuid, pm.getUUID("tastybento"));
}
/**
@ -368,7 +368,7 @@ public class PlayersManagerTest {
}
/**
* Test method for {@link us.tastybento.bskyblock.managers.PlayersManager#getResetsLeft(java.util.UUID)}.
* Test method for {@link us.tastybento.bskyblock.managers.PlayersManager#getResets(java.util.UUID)}.
*/
@Test
public void testGetSetResetsLeft() {
@ -381,9 +381,9 @@ public class PlayersManagerTest {
// Add a player
pm.addPlayer(uuid);
assertEquals(0, pm.getResetsLeft(uuid));
pm.setResetsLeft(uuid, 20);
assertEquals(20, pm.getResetsLeft(uuid));
assertEquals(0, pm.getResets(world, uuid));
pm.setResets(world, uuid, 20);
assertEquals(20, pm.getResets(world, uuid));
}
/**