mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-21 16:47:39 +01:00
WIP - clear reset all command
This commit is contained in:
parent
342387cf09
commit
541ee35256
@ -438,6 +438,10 @@ public class Settings implements DataObject, WorldSettings {
|
|||||||
private boolean closePanelOnClickOutside = true;
|
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";
|
private String uniqueId = "config";
|
||||||
|
|
||||||
// Getters and setters
|
// Getters and setters
|
||||||
@ -680,6 +684,7 @@ public class Settings implements DataObject, WorldSettings {
|
|||||||
/**
|
/**
|
||||||
* @return the resetLimit
|
* @return the resetLimit
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public int getResetLimit() {
|
public int getResetLimit() {
|
||||||
return resetLimit;
|
return resetLimit;
|
||||||
}
|
}
|
||||||
@ -1479,6 +1484,20 @@ public class Settings implements DataObject, WorldSettings {
|
|||||||
public void setGeoLimitSettings(List<String> geoLimitSettings) {
|
public void setGeoLimitSettings(List<String> geoLimitSettings) {
|
||||||
this.geoLimitSettings = 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -235,4 +235,20 @@ public interface WorldSettings {
|
|||||||
* @return list of entity types that should not exit the island limits
|
* @return list of entity types that should not exit the island limits
|
||||||
*/
|
*/
|
||||||
List<String> getGeoLimitSettings();
|
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);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@ import java.util.List;
|
|||||||
import us.tastybento.bskyblock.api.commands.CompositeCommand;
|
import us.tastybento.bskyblock.api.commands.CompositeCommand;
|
||||||
import us.tastybento.bskyblock.api.localization.TextVariables;
|
import us.tastybento.bskyblock.api.localization.TextVariables;
|
||||||
import us.tastybento.bskyblock.api.user.User;
|
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.AdminGetRankCommand;
|
||||||
import us.tastybento.bskyblock.commands.admin.AdminInfoCommand;
|
import us.tastybento.bskyblock.commands.admin.AdminInfoCommand;
|
||||||
import us.tastybento.bskyblock.commands.admin.AdminRegisterCommand;
|
import us.tastybento.bskyblock.commands.admin.AdminRegisterCommand;
|
||||||
@ -54,6 +56,9 @@ public class AdminCommand extends CompositeCommand {
|
|||||||
new AdminUnregisterCommand(this);
|
new AdminUnregisterCommand(this);
|
||||||
// Range
|
// Range
|
||||||
new AdminRangeCommand(this);
|
new AdminRangeCommand(this);
|
||||||
|
// Resets
|
||||||
|
new AdminClearResetCommand(this);
|
||||||
|
new AdminClearResetAllCommand(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
@ -51,13 +51,14 @@ public class IslandResetCommand extends CompositeCommand {
|
|||||||
user.sendMessage("commands.island.reset.must-remove-members");
|
user.sendMessage("commands.island.reset.must-remove-members");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getSettings().getResetLimit() >= 0 ) {
|
if (getIWM().getResetLimit(getWorld()) >= 0 ) {
|
||||||
if (getPlayers().getResetsLeft(user.getUniqueId()) == 0) {
|
int resetsLeft = getIWM().getResetLimit(getWorld()) - getPlayers().getResets(getWorld(), user.getUniqueId());
|
||||||
|
if (resetsLeft <= 0) {
|
||||||
user.sendMessage("commands.island.reset.none-left");
|
user.sendMessage("commands.island.reset.none-left");
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
// Notify how many resets are left
|
// 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
|
// Request confirmation
|
||||||
@ -88,6 +89,8 @@ public class IslandResetCommand extends CompositeCommand {
|
|||||||
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
|
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
|
||||||
// TODO: needs Vault
|
// TODO: needs Vault
|
||||||
}
|
}
|
||||||
|
// Add a reset
|
||||||
|
getPlayers().addReset(getWorld(), user.getUniqueId());
|
||||||
// Create new island and then delete the old one
|
// Create new island and then delete the old one
|
||||||
try {
|
try {
|
||||||
NewIsland.builder()
|
NewIsland.builder()
|
||||||
|
@ -600,7 +600,7 @@ public class Island implements DataObject {
|
|||||||
user.sendMessage("commands.admin.info.last-login","[date]", d.toString());
|
user.sendMessage("commands.admin.info.last-login","[date]", d.toString());
|
||||||
|
|
||||||
user.sendMessage("commands.admin.info.deaths", "[number]", String.valueOf(plugin.getPlayers().getDeaths(owner)));
|
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());
|
String total = plugin.getSettings().getResetLimit() < 0 ? "Unlimited" : String.valueOf(plugin.getSettings().getResetLimit());
|
||||||
user.sendMessage("commands.admin.info.resets-left", "[number]", resets, "[total]", total);
|
user.sendMessage("commands.admin.info.resets-left", "[number]", resets, "[total]", total);
|
||||||
// Show team members
|
// Show team members
|
||||||
|
@ -30,7 +30,7 @@ public class Players implements DataObject {
|
|||||||
@Expose
|
@Expose
|
||||||
private String playerName;
|
private String playerName;
|
||||||
@Expose
|
@Expose
|
||||||
private int resetsLeft;
|
private Map<String, Integer> resets = new HashMap<>();
|
||||||
@Expose
|
@Expose
|
||||||
private String locale = "";
|
private String locale = "";
|
||||||
@Expose
|
@Expose
|
||||||
@ -52,7 +52,6 @@ public class Players implements DataObject {
|
|||||||
public Players(BSkyBlock plugin, UUID uniqueId) {
|
public Players(BSkyBlock plugin, UUID uniqueId) {
|
||||||
this.uniqueId = uniqueId.toString();
|
this.uniqueId = uniqueId.toString();
|
||||||
homeLocations = new HashMap<>();
|
homeLocations = new HashMap<>();
|
||||||
resetsLeft = plugin.getSettings().getResetLimit();
|
|
||||||
locale = "";
|
locale = "";
|
||||||
kickedList = new HashMap<>();
|
kickedList = new HashMap<>();
|
||||||
// Try to get player's name
|
// 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
|
* @return the resetsLeft
|
||||||
*/
|
*/
|
||||||
public int getResetsLeft() {
|
public int getResets(World world) {
|
||||||
return resetsLeft;
|
resets.putIfAbsent(world.getName(), 0);
|
||||||
|
return resets.get(world.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param resetsLeft
|
* @return the resets
|
||||||
* the resetsLeft to set
|
|
||||||
*/
|
*/
|
||||||
public void setResetsLeft(int resetsLeft) {
|
public Map<String, Integer> getResets() {
|
||||||
this.resetsLeft = resetsLeft;
|
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;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,11 +39,10 @@ public class JoinLeaveListener implements Listener {
|
|||||||
if (plugin.getPlayers().isKnown(playerUUID)) {
|
if (plugin.getPlayers().isKnown(playerUUID)) {
|
||||||
// Load player
|
// Load player
|
||||||
players.addPlayer(playerUUID);
|
players.addPlayer(playerUUID);
|
||||||
|
// Reset island resets if required
|
||||||
// Reset resets if the admin changes it to or from unlimited
|
plugin.getIWM().getOverWorlds().stream()
|
||||||
if (plugin.getSettings().getResetLimit() < players.getResetsLeft(playerUUID) || (plugin.getSettings().getResetLimit() >= 0 && players.getResetsLeft(playerUUID) < 0)) {
|
.filter(w -> event.getPlayer().getLastPlayed() < plugin.getIWM().getResetEpoch(w))
|
||||||
players.setResetsLeft(playerUUID, plugin.getSettings().getResetLimit());
|
.forEach(w -> players.setResets(w, playerUUID, 0));
|
||||||
}
|
|
||||||
// Set the player's name (it may have changed), but only if it isn't empty
|
// Set the player's name (it may have changed), but only if it isn't empty
|
||||||
if (!user.getName().isEmpty()) {
|
if (!user.getName().isEmpty()) {
|
||||||
players.setPlayerName(user);
|
players.setPlayerName(user);
|
||||||
|
@ -734,4 +734,30 @@ public class IslandWorldManager {
|
|||||||
public List<String> getGeoLimitSettings(World world) {
|
public List<String> getGeoLimitSettings(World world) {
|
||||||
return worldSettings.get(Util.getWorld(world)).getGeoLimitSettings();
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ public class PlayersManager {
|
|||||||
}
|
}
|
||||||
// Try cache
|
// Try cache
|
||||||
return playerCache.containsKey(uniqueID) || handler.objectExists(uniqueID.toString());
|
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());
|
addPlayer(user.getUniqueId());
|
||||||
playerCache.get(user.getUniqueId()).setHomeLocation(location,number);
|
playerCache.get(user.getUniqueId()).setHomeLocation(location,number);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the home location for the player
|
* Sets the home location for the player
|
||||||
* @param playerUUID - the player's UUID
|
* @param playerUUID - the player's UUID
|
||||||
@ -202,7 +202,7 @@ public class PlayersManager {
|
|||||||
addPlayer(user.getUniqueId());
|
addPlayer(user.getUniqueId());
|
||||||
return playerCache.get(user.getUniqueId()).getHomeLocation(world, number);
|
return playerCache.get(user.getUniqueId()).getHomeLocation(world, number);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the home location, or null if none
|
* Returns the home location, or null if none
|
||||||
* @param world - world
|
* @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
|
* @param playerUUID - the player's UUID
|
||||||
* @return number of resets
|
* @return number of resets
|
||||||
*/
|
*/
|
||||||
public int getResetsLeft(UUID playerUUID) {
|
public int getResets(World world, UUID playerUUID) {
|
||||||
addPlayer(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 playerUUID - the player's UUID
|
||||||
* @param resets - number of resets
|
* @param resets - number of resets
|
||||||
*/
|
*/
|
||||||
public void setResetsLeft(UUID playerUUID, int resets) {
|
public void setResets(World world, UUID playerUUID, int resets) {
|
||||||
addPlayer(playerUUID);
|
addPlayer(playerUUID);
|
||||||
playerCache.get(playerUUID).setResetsLeft(resets);
|
playerCache.get(playerUUID).setResets(world, resets);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -437,4 +439,11 @@ public class PlayersManager {
|
|||||||
return User.getInstance(uuid);
|
return User.getInstance(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void addReset(World world, UUID playerUUID) {
|
||||||
|
addPlayer(playerUUID);
|
||||||
|
playerCache.get(playerUUID).addReset(world);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.commands.island;
|
package us.tastybento.bskyblock.commands.island;
|
||||||
|
|
||||||
@ -14,6 +14,7 @@ import java.util.HashMap;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
@ -51,6 +52,8 @@ public class IslandResetCommandTest {
|
|||||||
private Settings s;
|
private Settings s;
|
||||||
private IslandsManager im;
|
private IslandsManager im;
|
||||||
private PlayersManager pm;
|
private PlayersManager pm;
|
||||||
|
private World world;
|
||||||
|
private IslandWorldManager iwm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws java.lang.Exception
|
* @throws java.lang.Exception
|
||||||
@ -60,17 +63,17 @@ public class IslandResetCommandTest {
|
|||||||
// Set up plugin
|
// Set up plugin
|
||||||
BSkyBlock plugin = mock(BSkyBlock.class);
|
BSkyBlock plugin = mock(BSkyBlock.class);
|
||||||
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||||
|
|
||||||
// Command manager
|
// Command manager
|
||||||
CommandsManager cm = mock(CommandsManager.class);
|
CommandsManager cm = mock(CommandsManager.class);
|
||||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
s = mock(Settings.class);
|
s = mock(Settings.class);
|
||||||
when(s.getResetWait()).thenReturn(0L);
|
when(s.getResetWait()).thenReturn(0L);
|
||||||
when(s.getResetLimit()).thenReturn(3);
|
when(s.getResetLimit()).thenReturn(3);
|
||||||
when(plugin.getSettings()).thenReturn(s);
|
when(plugin.getSettings()).thenReturn(s);
|
||||||
|
|
||||||
// Player
|
// Player
|
||||||
Player p = mock(Player.class);
|
Player p = mock(Player.class);
|
||||||
// User, sometime use Mockito.withSettings().verboseLogging()
|
// User, sometime use Mockito.withSettings().verboseLogging()
|
||||||
@ -79,18 +82,21 @@ public class IslandResetCommandTest {
|
|||||||
uuid = UUID.randomUUID();
|
uuid = UUID.randomUUID();
|
||||||
when(user.getUniqueId()).thenReturn(uuid);
|
when(user.getUniqueId()).thenReturn(uuid);
|
||||||
when(user.getPlayer()).thenReturn(p);
|
when(user.getPlayer()).thenReturn(p);
|
||||||
|
|
||||||
// Parent command has no aliases
|
// Parent command has no aliases
|
||||||
ic = mock(IslandCommand.class);
|
ic = mock(IslandCommand.class);
|
||||||
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||||
when(ic.getTopLabel()).thenReturn("island");
|
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)
|
// No island for player to begin with (set it later in the tests)
|
||||||
im = mock(IslandsManager.class);
|
im = mock(IslandsManager.class);
|
||||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
||||||
when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
||||||
when(plugin.getIslands()).thenReturn(im);
|
when(plugin.getIslands()).thenReturn(im);
|
||||||
|
|
||||||
|
|
||||||
// Has team
|
// Has team
|
||||||
pm = mock(PlayersManager.class);
|
pm = mock(PlayersManager.class);
|
||||||
@ -104,19 +110,20 @@ public class IslandResetCommandTest {
|
|||||||
|
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getScheduler()).thenReturn(sch);
|
when(Bukkit.getScheduler()).thenReturn(sch);
|
||||||
|
|
||||||
|
|
||||||
// IWM friendly name
|
// IWM friendly name
|
||||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
iwm = mock(IslandWorldManager.class);
|
||||||
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
||||||
when(plugin.getIWM()).thenReturn(iwm);
|
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)}.
|
* 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
|
@Test
|
||||||
public void testNoIsland() throws IOException {
|
public void testNoIsland() throws IOException {
|
||||||
@ -126,7 +133,7 @@ public class IslandResetCommandTest {
|
|||||||
assertFalse(irc.execute(user, irc.getLabel(), new ArrayList<>()));
|
assertFalse(irc.execute(user, irc.getLabel(), new ArrayList<>()));
|
||||||
Mockito.verify(user).sendMessage("general.errors.no-island");
|
Mockito.verify(user).sendMessage("general.errors.no-island");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotLeader() throws IOException {
|
public void testNotLeader() throws IOException {
|
||||||
IslandResetCommand irc = new IslandResetCommand(ic);
|
IslandResetCommand irc = new IslandResetCommand(ic);
|
||||||
@ -135,7 +142,7 @@ public class IslandResetCommandTest {
|
|||||||
assertFalse(irc.execute(user, irc.getLabel(), new ArrayList<>()));
|
assertFalse(irc.execute(user, irc.getLabel(), new ArrayList<>()));
|
||||||
Mockito.verify(user).sendMessage("general.errors.not-leader");
|
Mockito.verify(user).sendMessage("general.errors.not-leader");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHasTeam() throws IOException {
|
public void testHasTeam() throws IOException {
|
||||||
IslandResetCommand irc = new IslandResetCommand(ic);
|
IslandResetCommand irc = new IslandResetCommand(ic);
|
||||||
@ -146,7 +153,7 @@ public class IslandResetCommandTest {
|
|||||||
assertFalse(irc.execute(user, irc.getLabel(), new ArrayList<>()));
|
assertFalse(irc.execute(user, irc.getLabel(), new ArrayList<>()));
|
||||||
Mockito.verify(user).sendMessage("commands.island.reset.must-remove-members");
|
Mockito.verify(user).sendMessage("commands.island.reset.must-remove-members");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoResetsLeft() throws IOException {
|
public void testNoResetsLeft() throws IOException {
|
||||||
IslandResetCommand irc = new IslandResetCommand(ic);
|
IslandResetCommand irc = new IslandResetCommand(ic);
|
||||||
@ -156,14 +163,14 @@ public class IslandResetCommandTest {
|
|||||||
when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||||
// Now has no team
|
// Now has no team
|
||||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
||||||
|
|
||||||
// Block based on no resets left
|
// 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<>()));
|
assertFalse(irc.execute(user, irc.getLabel(), new ArrayList<>()));
|
||||||
Mockito.verify(user).sendMessage("commands.island.reset.none-left");
|
Mockito.verify(user).sendMessage("commands.island.reset.none-left");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoConfirmationRequired() throws IOException {
|
public void testNoConfirmationRequired() throws IOException {
|
||||||
IslandResetCommand irc = new IslandResetCommand(ic);
|
IslandResetCommand irc = new IslandResetCommand(ic);
|
||||||
@ -174,14 +181,14 @@ public class IslandResetCommandTest {
|
|||||||
// Now has no team
|
// Now has no team
|
||||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
||||||
// Give the user some resets
|
// 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
|
// Set so no confirmation required
|
||||||
when(s.isResetConfirmation()).thenReturn(false);
|
when(s.isResetConfirmation()).thenReturn(false);
|
||||||
|
|
||||||
// Old island mock
|
// Old island mock
|
||||||
Island oldIsland = mock(Island.class);
|
Island oldIsland = mock(Island.class);
|
||||||
when(im.getIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(oldIsland);
|
when(im.getIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(oldIsland);
|
||||||
|
|
||||||
// Mock up NewIsland builder
|
// Mock up NewIsland builder
|
||||||
NewIsland.Builder builder = mock(NewIsland.Builder.class);
|
NewIsland.Builder builder = mock(NewIsland.Builder.class);
|
||||||
when(builder.player(Mockito.any())).thenReturn(builder);
|
when(builder.player(Mockito.any())).thenReturn(builder);
|
||||||
@ -195,9 +202,9 @@ public class IslandResetCommandTest {
|
|||||||
assertTrue(irc.execute(user, irc.getLabel(), new ArrayList<>()));
|
assertTrue(irc.execute(user, irc.getLabel(), new ArrayList<>()));
|
||||||
// Verify that build new island was called and the number of resets left shown
|
// Verify that build new island was called and the number of resets left shown
|
||||||
Mockito.verify(builder).build();
|
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
|
@Test
|
||||||
public void testUnlimitedResets() throws IOException {
|
public void testUnlimitedResets() throws IOException {
|
||||||
IslandResetCommand irc = new IslandResetCommand(ic);
|
IslandResetCommand irc = new IslandResetCommand(ic);
|
||||||
@ -208,14 +215,14 @@ public class IslandResetCommandTest {
|
|||||||
// Now has no team
|
// Now has no team
|
||||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
||||||
// Give the user some resets
|
// 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
|
// Set so no confirmation required
|
||||||
when(s.isResetConfirmation()).thenReturn(false);
|
when(s.isResetConfirmation()).thenReturn(false);
|
||||||
|
|
||||||
// Old island mock
|
// Old island mock
|
||||||
Island oldIsland = mock(Island.class);
|
Island oldIsland = mock(Island.class);
|
||||||
when(im.getIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(oldIsland);
|
when(im.getIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(oldIsland);
|
||||||
|
|
||||||
// Mock up NewIsland builder
|
// Mock up NewIsland builder
|
||||||
NewIsland.Builder builder = mock(NewIsland.Builder.class);
|
NewIsland.Builder builder = mock(NewIsland.Builder.class);
|
||||||
when(builder.player(Mockito.any())).thenReturn(builder);
|
when(builder.player(Mockito.any())).thenReturn(builder);
|
||||||
@ -225,16 +232,16 @@ public class IslandResetCommandTest {
|
|||||||
PowerMockito.mockStatic(NewIsland.class);
|
PowerMockito.mockStatic(NewIsland.class);
|
||||||
when(NewIsland.builder()).thenReturn(builder);
|
when(NewIsland.builder()).thenReturn(builder);
|
||||||
// Test with unlimited resets
|
// Test with unlimited resets
|
||||||
when(s.getResetLimit()).thenReturn(-1);
|
when(iwm.getResetLimit(Mockito.any())).thenReturn(-1);
|
||||||
|
|
||||||
// Reset
|
// Reset
|
||||||
assertTrue(irc.execute(user, irc.getLabel(), new ArrayList<>()));
|
assertTrue(irc.execute(user, irc.getLabel(), new ArrayList<>()));
|
||||||
// Verify that build new island was called and the number of resets left shown
|
// Verify that build new island was called and the number of resets left shown
|
||||||
Mockito.verify(builder).build();
|
Mockito.verify(builder).build();
|
||||||
// This should not be shown
|
// 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
|
@Test
|
||||||
public void testConfirmationRequired() throws IOException {
|
public void testConfirmationRequired() throws IOException {
|
||||||
IslandResetCommand irc = new IslandResetCommand(ic);
|
IslandResetCommand irc = new IslandResetCommand(ic);
|
||||||
@ -245,14 +252,14 @@ public class IslandResetCommandTest {
|
|||||||
// Now has no team
|
// Now has no team
|
||||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
||||||
// Give the user some resets
|
// 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
|
// Set so no confirmation required
|
||||||
when(s.isResetConfirmation()).thenReturn(false);
|
when(s.isResetConfirmation()).thenReturn(false);
|
||||||
|
|
||||||
// Old island mock
|
// Old island mock
|
||||||
Island oldIsland = mock(Island.class);
|
Island oldIsland = mock(Island.class);
|
||||||
when(im.getIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(oldIsland);
|
when(im.getIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(oldIsland);
|
||||||
|
|
||||||
// Mock up NewIsland builder
|
// Mock up NewIsland builder
|
||||||
NewIsland.Builder builder = mock(NewIsland.Builder.class);
|
NewIsland.Builder builder = mock(NewIsland.Builder.class);
|
||||||
when(builder.player(Mockito.any())).thenReturn(builder);
|
when(builder.player(Mockito.any())).thenReturn(builder);
|
||||||
@ -270,12 +277,12 @@ public class IslandResetCommandTest {
|
|||||||
assertTrue(irc.execute(user, irc.getLabel(), new ArrayList<>()));
|
assertTrue(irc.execute(user, irc.getLabel(), new ArrayList<>()));
|
||||||
// Check for message
|
// Check for message
|
||||||
Mockito.verify(user).sendMessage("general.confirm", "[seconds]", String.valueOf(s.getConfirmationTime()));
|
Mockito.verify(user).sendMessage("general.confirm", "[seconds]", String.valueOf(s.getConfirmationTime()));
|
||||||
|
|
||||||
// Send command again to confirm
|
// Send command again to confirm
|
||||||
assertTrue(irc.execute(user, irc.getLabel(), new ArrayList<>()));
|
assertTrue(irc.execute(user, irc.getLabel(), new ArrayList<>()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNewIslandError() throws IOException {
|
public void testNewIslandError() throws IOException {
|
||||||
IslandResetCommand irc = new IslandResetCommand(ic);
|
IslandResetCommand irc = new IslandResetCommand(ic);
|
||||||
@ -286,14 +293,14 @@ public class IslandResetCommandTest {
|
|||||||
// Now has no team
|
// Now has no team
|
||||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
||||||
// Give the user some resets
|
// 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
|
// Set so no confirmation required
|
||||||
when(s.isResetConfirmation()).thenReturn(false);
|
when(s.isResetConfirmation()).thenReturn(false);
|
||||||
|
|
||||||
// Old island mock
|
// Old island mock
|
||||||
Island oldIsland = mock(Island.class);
|
Island oldIsland = mock(Island.class);
|
||||||
when(im.getIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(oldIsland);
|
when(im.getIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(oldIsland);
|
||||||
|
|
||||||
// Mock up NewIsland builder
|
// Mock up NewIsland builder
|
||||||
NewIsland.Builder builder = mock(NewIsland.Builder.class);
|
NewIsland.Builder builder = mock(NewIsland.Builder.class);
|
||||||
when(builder.player(Mockito.any())).thenReturn(builder);
|
when(builder.player(Mockito.any())).thenReturn(builder);
|
||||||
@ -305,11 +312,11 @@ public class IslandResetCommandTest {
|
|||||||
|
|
||||||
// Require no confirmation
|
// Require no confirmation
|
||||||
when(s.isResetConfirmation()).thenReturn(false);
|
when(s.isResetConfirmation()).thenReturn(false);
|
||||||
|
|
||||||
// Reset
|
// Reset
|
||||||
assertFalse(irc.execute(user, irc.getLabel(), new ArrayList<>()));
|
assertFalse(irc.execute(user, irc.getLabel(), new ArrayList<>()));
|
||||||
Mockito.verify(user).sendMessage("commands.island.create.unable-create-island");
|
Mockito.verify(user).sendMessage("commands.island.create.unable-create-island");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ public class MySQLDatabaseHandlerTest {
|
|||||||
players.setLocale("sdfsd");
|
players.setLocale("sdfsd");
|
||||||
players.setPlayerName("name");
|
players.setPlayerName("name");
|
||||||
players.setPlayerUUID(UUID.randomUUID());
|
players.setPlayerUUID(UUID.randomUUID());
|
||||||
players.setResetsLeft(3);
|
players.setResets(world, 3);
|
||||||
|
|
||||||
|
|
||||||
MySQLDatabaseHandler<Players> h = new MySQLDatabaseHandler<>(plugin, Players.class, dbConn);
|
MySQLDatabaseHandler<Players> h = new MySQLDatabaseHandler<>(plugin, Players.class, dbConn);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.managers;
|
package us.tastybento.bskyblock.managers;
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ public class PlayersManagerTest {
|
|||||||
// Set up plugin
|
// Set up plugin
|
||||||
plugin = mock(BSkyBlock.class);
|
plugin = mock(BSkyBlock.class);
|
||||||
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||||
|
|
||||||
// island world mgr
|
// island world mgr
|
||||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||||
world = mock(World.class);
|
world = mock(World.class);
|
||||||
@ -80,11 +80,11 @@ public class PlayersManagerTest {
|
|||||||
when(iwm.getBSBNetherWorld()).thenReturn(nether);
|
when(iwm.getBSBNetherWorld()).thenReturn(nether);
|
||||||
when(iwm.inWorld(any())).thenReturn(true);
|
when(iwm.inWorld(any())).thenReturn(true);
|
||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
Settings s = mock(Settings.class);
|
Settings s = mock(Settings.class);
|
||||||
when(plugin.getSettings()).thenReturn(s);
|
when(plugin.getSettings()).thenReturn(s);
|
||||||
|
|
||||||
// Set up spawn
|
// Set up spawn
|
||||||
Location netherSpawn = mock(Location.class);
|
Location netherSpawn = mock(Location.class);
|
||||||
when(netherSpawn.toVector()).thenReturn(new Vector(0,0,0));
|
when(netherSpawn.toVector()).thenReturn(new Vector(0,0,0));
|
||||||
@ -106,7 +106,7 @@ public class PlayersManagerTest {
|
|||||||
when(user.getName()).thenReturn("tastybento");
|
when(user.getName()).thenReturn("tastybento");
|
||||||
User.setPlugin(plugin);
|
User.setPlugin(plugin);
|
||||||
|
|
||||||
// Player has island to begin with
|
// Player has island to begin with
|
||||||
IslandsManager im = mock(IslandsManager.class);
|
IslandsManager im = mock(IslandsManager.class);
|
||||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||||
when(im.isOwner(Mockito.any(), Mockito.any())).thenReturn(true);
|
when(im.isOwner(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||||
@ -123,10 +123,10 @@ public class PlayersManagerTest {
|
|||||||
LocalesManager lm = mock(LocalesManager.class);
|
LocalesManager lm = mock(LocalesManager.class);
|
||||||
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
|
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
|
||||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||||
|
|
||||||
// Normally in world
|
// Normally in world
|
||||||
Util.setPlugin(plugin);
|
Util.setPlugin(plugin);
|
||||||
|
|
||||||
// Mock database
|
// Mock database
|
||||||
db = mock(BSBDatabase.class);
|
db = mock(BSBDatabase.class);
|
||||||
PowerMockito.whenNew(BSBDatabase.class).withAnyArguments().thenReturn(db);
|
PowerMockito.whenNew(BSBDatabase.class).withAnyArguments().thenReturn(db);
|
||||||
@ -239,7 +239,7 @@ public class PlayersManagerTest {
|
|||||||
|
|
||||||
pm.addPlayer(uuid);
|
pm.addPlayer(uuid);
|
||||||
pm.addPlayer(notUUID);
|
pm.addPlayer(notUUID);
|
||||||
|
|
||||||
pm.removeAllPlayers();
|
pm.removeAllPlayers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,7 +324,7 @@ public class PlayersManagerTest {
|
|||||||
public void testGetUUID() {
|
public void testGetUUID() {
|
||||||
PlayersManager pm = new PlayersManager(plugin);
|
PlayersManager pm = new PlayersManager(plugin);
|
||||||
assertEquals(uuid,pm.getUUID(uuid.toString()));
|
assertEquals(uuid,pm.getUUID(uuid.toString()));
|
||||||
|
|
||||||
OfflinePlayer olp = mock(OfflinePlayer.class);
|
OfflinePlayer olp = mock(OfflinePlayer.class);
|
||||||
when(olp.getUniqueId()).thenReturn(uuid);
|
when(olp.getUniqueId()).thenReturn(uuid);
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
@ -339,13 +339,13 @@ public class PlayersManagerTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Names answer(InvocationOnMock invocation) throws Throwable {
|
public Names answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
assertEquals(uuid, pm.getUUID("tastybento"));
|
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
|
@Test
|
||||||
public void testGetSetResetsLeft() {
|
public void testGetSetResetsLeft() {
|
||||||
@ -381,9 +381,9 @@ public class PlayersManagerTest {
|
|||||||
|
|
||||||
// Add a player
|
// Add a player
|
||||||
pm.addPlayer(uuid);
|
pm.addPlayer(uuid);
|
||||||
assertEquals(0, pm.getResetsLeft(uuid));
|
assertEquals(0, pm.getResets(world, uuid));
|
||||||
pm.setResetsLeft(uuid, 20);
|
pm.setResets(world, uuid, 20);
|
||||||
assertEquals(20, pm.getResetsLeft(uuid));
|
assertEquals(20, pm.getResets(world, uuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user