mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-28 13:45:14 +01:00
Performed code cleanup using Intellij.
This commit is contained in:
parent
bcc0028671
commit
d94477034a
@ -419,7 +419,7 @@ public class Metrics {
|
||||
protected JSONObject getChartData() {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
HashMap<String, Integer> map = getValues(new HashMap<String, Integer>());
|
||||
HashMap<String, Integer> map = getValues(new HashMap<>());
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
@ -503,7 +503,7 @@ public class Metrics {
|
||||
protected JSONObject getChartData() {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
HashMap<String, Integer> map = getValues(new HashMap<String, Integer>());
|
||||
HashMap<String, Integer> map = getValues(new HashMap<>());
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
@ -553,7 +553,7 @@ public class Metrics {
|
||||
protected JSONObject getChartData() {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
HashMap<String, Integer> map = getValues(new HashMap<String, Integer>());
|
||||
HashMap<String, Integer> map = getValues(new HashMap<>());
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
@ -596,7 +596,7 @@ public class Metrics {
|
||||
protected JSONObject getChartData() {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
HashMap<String, int[]> map = getValues(new HashMap<String, int[]>());
|
||||
HashMap<String, int[]> map = getValues(new HashMap<>());
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
@ -686,7 +686,7 @@ public class Metrics {
|
||||
protected JSONObject getChartData() {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
HashMap<Country, Integer> map = getValues(new HashMap<Country, Integer>());
|
||||
HashMap<Country, Integer> map = getValues(new HashMap<>());
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
|
@ -46,7 +46,7 @@ public abstract class Addon implements AddonInterface {
|
||||
*/
|
||||
public FileConfiguration getConfig() {
|
||||
if (config == null) {
|
||||
config = loadYamlFile(ADDON_CONFIG_FILENAME);
|
||||
config = loadYamlFile();
|
||||
}
|
||||
return config;
|
||||
}
|
||||
@ -93,13 +93,12 @@ public abstract class Addon implements AddonInterface {
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a YAML file
|
||||
* Load YAML config file
|
||||
*
|
||||
* @param file
|
||||
* @return Yaml File configuration
|
||||
*/
|
||||
private FileConfiguration loadYamlFile(String file) {
|
||||
File yamlFile = new File(dataFolder, file);
|
||||
private FileConfiguration loadYamlFile() {
|
||||
File yamlFile = new File(dataFolder, ADDON_CONFIG_FILENAME);
|
||||
|
||||
YamlConfiguration yamlConfig = null;
|
||||
if (yamlFile.exists()) {
|
||||
@ -107,7 +106,7 @@ public abstract class Addon implements AddonInterface {
|
||||
yamlConfig = new YamlConfiguration();
|
||||
yamlConfig.load(yamlFile);
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().severe("Could not load YAML file: " + file + " " + e.getMessage());
|
||||
Bukkit.getLogger().severe(() -> "Could not load config.yml: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
return yamlConfig;
|
||||
@ -139,7 +138,7 @@ public abstract class Addon implements AddonInterface {
|
||||
*/
|
||||
public void saveDefaultConfig() {
|
||||
saveResource(ADDON_CONFIG_FILENAME, false);
|
||||
config = loadYamlFile(ADDON_CONFIG_FILENAME);
|
||||
config = loadYamlFile();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,7 +41,7 @@ public class AddonClassLoader extends URLClassLoader {
|
||||
|
||||
loader = addonsManager;
|
||||
|
||||
Class<?> javaClass = null;
|
||||
Class<?> javaClass;
|
||||
try {
|
||||
String mainClass = data.getString("main");
|
||||
javaClass = Class.forName(mainClass, true, this);
|
||||
@ -94,7 +94,7 @@ public class AddonClassLoader extends URLClassLoader {
|
||||
* @see java.net.URLClassLoader#findClass(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> findClass(String name) throws ClassNotFoundException {
|
||||
protected Class<?> findClass(String name) {
|
||||
return findClass(name, true);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package us.tastybento.bskyblock.api.commands;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@ -81,9 +81,7 @@ public class DefaultHelpCommand extends CompositeCommand {
|
||||
if (!subCommand.getLabel().equals(HELP)) {
|
||||
// Every command should have help because every command has a default help
|
||||
Optional<CompositeCommand> sub = subCommand.getSubCommand(HELP);
|
||||
if (sub.isPresent()) {
|
||||
sub.get().execute(user, Arrays.asList(String.valueOf(newDepth)));
|
||||
}
|
||||
sub.ifPresent(compositeCommand -> compositeCommand.execute(user, Collections.singletonList(String.valueOf(newDepth))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.api.configuration;
|
||||
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
@ -12,10 +9,6 @@ import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target({ FIELD, METHOD })
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public @interface ConfigComment {
|
||||
|
||||
String value();
|
||||
|
@ -2,7 +2,6 @@ package us.tastybento.bskyblock.api.configuration;
|
||||
|
||||
import java.beans.IntrospectionException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import us.tastybento.bskyblock.database.AbstractDatabaseHandler;
|
||||
import us.tastybento.bskyblock.database.BSBDbSetup;
|
||||
@ -20,14 +19,14 @@ public interface ISettings<T> {
|
||||
|
||||
// ----------------Saver-------------------
|
||||
@SuppressWarnings("unchecked")
|
||||
default void saveSettings() throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException, IntrospectionException, SQLException {
|
||||
default void saveSettings() throws IllegalAccessException, InvocationTargetException, IntrospectionException {
|
||||
// Get the handler
|
||||
ConfigHandler<T> settingsHandler = (ConfigHandler<T>) new FlatFileDatabase().getConfig(getInstance().getClass());
|
||||
// Load every field in the config class
|
||||
settingsHandler.saveSettings(getInstance());
|
||||
}
|
||||
|
||||
default void saveBackup() throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException, IntrospectionException, SQLException {
|
||||
default void saveBackup() throws IllegalAccessException, InvocationTargetException, IntrospectionException {
|
||||
// Save backup
|
||||
@SuppressWarnings("unchecked")
|
||||
AbstractDatabaseHandler<T> backupHandler = (AbstractDatabaseHandler<T>) new FlatFileDatabase().getHandler(getInstance().getClass());
|
||||
@ -36,7 +35,7 @@ public interface ISettings<T> {
|
||||
|
||||
// --------------- Loader ------------------
|
||||
@SuppressWarnings("unchecked")
|
||||
default T loadSettings() throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException, SQLException {
|
||||
default T loadSettings() throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException {
|
||||
// See if this settings object already exists in the database
|
||||
AbstractDatabaseHandler<T> dbhandler = (AbstractDatabaseHandler<T>) BSBDbSetup.getDatabase().getHandler(getClass());
|
||||
T dbConfig = null;
|
||||
|
@ -14,116 +14,116 @@ public interface WorldSettings {
|
||||
/**
|
||||
* @return the friendly name of the world. Used in player commands
|
||||
*/
|
||||
public String getFriendlyName();
|
||||
String getFriendlyName();
|
||||
|
||||
/**
|
||||
* @return the entityLimits
|
||||
*/
|
||||
public Map<EntityType, Integer> getEntityLimits();
|
||||
Map<EntityType, Integer> getEntityLimits();
|
||||
|
||||
/**
|
||||
* @return the islandDistance
|
||||
*/
|
||||
public int getIslandDistance();
|
||||
int getIslandDistance();
|
||||
|
||||
/**
|
||||
* @return the islandHeight
|
||||
*/
|
||||
public int getIslandHeight();
|
||||
int getIslandHeight();
|
||||
|
||||
/**
|
||||
* @return the islandProtectionRange
|
||||
*/
|
||||
public int getIslandProtectionRange();
|
||||
int getIslandProtectionRange();
|
||||
|
||||
/**
|
||||
* @return the islandStartX
|
||||
*/
|
||||
public int getIslandStartX();
|
||||
int getIslandStartX();
|
||||
|
||||
/**
|
||||
* @return the islandStartZ
|
||||
*/
|
||||
public int getIslandStartZ();
|
||||
int getIslandStartZ();
|
||||
|
||||
/**
|
||||
* @return the islandXOffset
|
||||
*/
|
||||
public int getIslandXOffset();
|
||||
int getIslandXOffset();
|
||||
|
||||
/**
|
||||
* @return the islandZOffset
|
||||
*/
|
||||
public int getIslandZOffset();
|
||||
int getIslandZOffset();
|
||||
|
||||
/**
|
||||
* @return the maxIslands
|
||||
*/
|
||||
public int getMaxIslands();
|
||||
int getMaxIslands();
|
||||
|
||||
/**
|
||||
* @return the netherSpawnRadius
|
||||
*/
|
||||
public int getNetherSpawnRadius();
|
||||
int getNetherSpawnRadius();
|
||||
|
||||
/**
|
||||
* @return the seaHeight
|
||||
*/
|
||||
public int getSeaHeight();
|
||||
int getSeaHeight();
|
||||
|
||||
/**
|
||||
* @return the tileEntityLimits
|
||||
*/
|
||||
public Map<String, Integer> getTileEntityLimits();
|
||||
Map<String, Integer> getTileEntityLimits();
|
||||
|
||||
/**
|
||||
* @return the worldName
|
||||
*/
|
||||
public String getWorldName();
|
||||
String getWorldName();
|
||||
|
||||
/**
|
||||
* @return the endGenerate
|
||||
*/
|
||||
public boolean isEndGenerate();
|
||||
boolean isEndGenerate();
|
||||
|
||||
/**
|
||||
* @return the endIslands
|
||||
*/
|
||||
public boolean isEndIslands();
|
||||
boolean isEndIslands();
|
||||
|
||||
/**
|
||||
* @return the netherGenerate
|
||||
*/
|
||||
public boolean isNetherGenerate();
|
||||
boolean isNetherGenerate();
|
||||
|
||||
/**
|
||||
* @return the netherIslands
|
||||
*/
|
||||
public boolean isNetherIslands();
|
||||
boolean isNetherIslands();
|
||||
|
||||
/**
|
||||
* @return the netherTrees
|
||||
*/
|
||||
public boolean isNetherTrees();
|
||||
boolean isNetherTrees();
|
||||
|
||||
/**
|
||||
* @return the dragonSpawn
|
||||
*/
|
||||
public boolean isDragonSpawn();
|
||||
boolean isDragonSpawn();
|
||||
|
||||
/**
|
||||
* @return the max team size for this world
|
||||
*/
|
||||
public int getMaxTeamSize();
|
||||
int getMaxTeamSize();
|
||||
|
||||
/**
|
||||
* @return the max homes
|
||||
*/
|
||||
public int getMaxHomes();
|
||||
int getMaxHomes();
|
||||
|
||||
/**
|
||||
* @return the permission prefix
|
||||
*/
|
||||
public String getPermissionPrefix();
|
||||
String getPermissionPrefix();
|
||||
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ public class IslandBaseEvent extends PremadeEvent implements Cancellable {
|
||||
* @return the owner of the island
|
||||
*/
|
||||
public UUID getOwner() {
|
||||
return getOwner();
|
||||
return island.getOwner();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -81,7 +81,7 @@ public class FlagBuilder {
|
||||
|
||||
/**
|
||||
* Adds a listener for clicks on this flag when it is a panel item. Default is
|
||||
* {@link us.tastybento.bskyblock.listeners.flags.UpDownClick.UpDownClick}
|
||||
* {@link us.tastybento.bskyblock.listeners.flags.UpDownClick}
|
||||
* @param onClickListener - the listener for clicks. Must use the ClickOn interface
|
||||
* @return FlagBuilder
|
||||
*/
|
||||
|
@ -2,6 +2,7 @@ package us.tastybento.bskyblock.api.panels.builders;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
@ -30,12 +31,11 @@ public class PanelItemBuilder {
|
||||
|
||||
/**
|
||||
* Set icon to player's head
|
||||
* @param playerUUID - player's UUID
|
||||
* @param playerName - player's name
|
||||
* @return PanelItemBuilder
|
||||
*/
|
||||
public PanelItemBuilder icon(String playerName) {
|
||||
ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
|
||||
this.icon = item;
|
||||
this.icon = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
|
||||
this.name = playerName;
|
||||
this.playerHead = true;
|
||||
return this;
|
||||
@ -77,9 +77,7 @@ public class PanelItemBuilder {
|
||||
* @return PanelItemBuilder
|
||||
*/
|
||||
public PanelItemBuilder description(String description) {
|
||||
for (String line : description.split("\n")) {
|
||||
this.description.add(line);
|
||||
}
|
||||
Collections.addAll(this.description, description.split("\n"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ public class Notifier {
|
||||
.build(
|
||||
new CacheLoader<User, Notification>() {
|
||||
@Override
|
||||
public Notification load(User user) throws Exception {
|
||||
public Notification load(User user) {
|
||||
return new Notification(null, 0);
|
||||
}
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ public class User {
|
||||
|
||||
/**
|
||||
* Used for testing
|
||||
* @param plugin
|
||||
* @param p - BSkyBlock plugin
|
||||
*/
|
||||
public static void setPlugin(BSkyBlock p) {
|
||||
plugin = p;
|
||||
@ -359,12 +359,7 @@ public class User {
|
||||
}
|
||||
User other = (User) obj;
|
||||
if (playerUUID == null) {
|
||||
if (other.playerUUID != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!playerUUID.equals(other.playerUUID)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return other.playerUUID == null;
|
||||
} else return playerUUID.equals(other.playerUUID);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.commands.admin;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.commands.admin;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -1,9 +1,7 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.commands.admin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
@ -58,7 +56,7 @@ public class AdminSetRankCommand extends CompositeCommand {
|
||||
RanksManager rm = getPlugin().getRanksManager();
|
||||
int rankValue = rm.getRanks().entrySet().stream()
|
||||
.filter(r -> user.getTranslation(r.getKey()).equalsIgnoreCase(args.get(1))).findFirst()
|
||||
.map(r -> r.getValue()).orElse(-999);
|
||||
.map(Map.Entry::getValue).orElse(-999);
|
||||
if (rankValue < RanksManager.BANNED_RANK) {
|
||||
user.sendMessage("commands.admin.setrank.unknown-rank");
|
||||
return false;
|
||||
|
@ -63,13 +63,12 @@ public class AdminTeleportCommand extends CompositeCommand {
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
List<String> options = new ArrayList<>();
|
||||
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();
|
||||
}
|
||||
options.addAll(Util.getOnlinePlayerList(user));
|
||||
List<String> options = new ArrayList<>(Util.getOnlinePlayerList(user));
|
||||
return Optional.of(Util.tabLimit(options, lastArg));
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.commands.island;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.commands.island;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.commands.island;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -42,7 +42,7 @@ public class IslandSethomeCommand extends CompositeCommand {
|
||||
int maxHomes = Util.getPermValue(user.getPlayer(), "island.maxhomes", getSettings().getMaxHomes());
|
||||
if (maxHomes > 1) {
|
||||
// Check the number given is a number
|
||||
int number = 0;
|
||||
int number;
|
||||
try {
|
||||
number = Integer.valueOf(args.get(0));
|
||||
if (number < 1 || number > maxHomes) {
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.commands.island;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -130,13 +130,12 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
List<String> options = new ArrayList<>();
|
||||
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();
|
||||
}
|
||||
options.addAll(Util.getOnlinePlayerList(user));
|
||||
List<String> options = new ArrayList<>(Util.getOnlinePlayerList(user));
|
||||
return Optional.of(Util.tabLimit(options, lastArg));
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ public interface DatabaseConnecter {
|
||||
|
||||
/**
|
||||
* Save the Yaml Config
|
||||
* @param yamlFile - the YAML config
|
||||
* @param yamlConfig - the YAML config
|
||||
* @param tableName - analogous to a table in a database
|
||||
* @param fileName - the name of the record. Must be unique.
|
||||
* @param commentMap - map of comments, may be empty
|
||||
|
@ -16,6 +16,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -94,7 +95,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
// Nothing there...
|
||||
tableFolder.mkdirs();
|
||||
}
|
||||
for (File file: tableFolder.listFiles(ymlFilter)) {
|
||||
for (File file: Objects.requireNonNull(tableFolder.listFiles(ymlFilter))) {
|
||||
String fileName = file.getName();
|
||||
if (storeAt != null) {
|
||||
fileName = storeAt.filename();
|
||||
@ -248,100 +249,99 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
}
|
||||
|
||||
// Run through all the fields in the class that is being stored. EVERY field must have a get and set method
|
||||
fields:
|
||||
for (Field field : dataObject.getDeclaredFields()) {
|
||||
for (Field field : dataObject.getDeclaredFields()) {
|
||||
|
||||
// Get the property descriptor for this field
|
||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(field.getName(), dataObject);
|
||||
// Get the read method, i.e., getXXXX();
|
||||
Method method = propertyDescriptor.getReadMethod();
|
||||
// Invoke the read method to get the value. We have no idea what type of value it is.
|
||||
Object value = method.invoke(instance);
|
||||
String storageLocation = field.getName();
|
||||
// Check if there is an annotation on the field
|
||||
ConfigEntry configEntry = field.getAnnotation(ConfigEntry.class);
|
||||
// If there is a config path annotation then do something
|
||||
if (configEntry != null) {
|
||||
if (!configEntry.specificTo().equals(GameType.BOTH) && !configEntry.specificTo().equals(Constants.GAMETYPE)) {
|
||||
continue fields;
|
||||
}
|
||||
if (!configEntry.path().isEmpty()) {
|
||||
storageLocation = configEntry.path();
|
||||
}
|
||||
// TODO: add in game-specific saving
|
||||
// Get the property descriptor for this field
|
||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(field.getName(), dataObject);
|
||||
// Get the read method, i.e., getXXXX();
|
||||
Method method = propertyDescriptor.getReadMethod();
|
||||
// Invoke the read method to get the value. We have no idea what type of value it is.
|
||||
Object value = method.invoke(instance);
|
||||
String storageLocation = field.getName();
|
||||
// Check if there is an annotation on the field
|
||||
ConfigEntry configEntry = field.getAnnotation(ConfigEntry.class);
|
||||
// If there is a config path annotation then do something
|
||||
if (configEntry != null) {
|
||||
if (!configEntry.specificTo().equals(GameType.BOTH) && !configEntry.specificTo().equals(Constants.GAMETYPE)) {
|
||||
continue;
|
||||
}
|
||||
if (!configEntry.path().isEmpty()) {
|
||||
storageLocation = configEntry.path();
|
||||
}
|
||||
// TODO: add in game-specific saving
|
||||
|
||||
}
|
||||
|
||||
// Comments
|
||||
ConfigComment comment = field.getAnnotation(ConfigComment.class);
|
||||
if (comment != null) {
|
||||
// Create a random placeholder string
|
||||
String random = "comment-" + UUID.randomUUID().toString();
|
||||
// Store placeholder
|
||||
config.set(random, " ");
|
||||
// Create comment
|
||||
yamlComments.put(random, "# " + comment.value());
|
||||
}
|
||||
}
|
||||
|
||||
// Adapter
|
||||
Adapter adapterNotation = field.getAnnotation(Adapter.class);
|
||||
if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) {
|
||||
// A conversion adapter has been defined
|
||||
try {
|
||||
config.set(storageLocation, ((AdapterInterface<?,?>)adapterNotation.value().newInstance()).serialize(value));
|
||||
} catch (InstantiationException e) {
|
||||
plugin.logError("Could not instatiate adapter " + adapterNotation.value().getName() + " " + e.getMessage());
|
||||
}
|
||||
// We are done here
|
||||
continue fields;
|
||||
// Comments
|
||||
ConfigComment comment = field.getAnnotation(ConfigComment.class);
|
||||
if (comment != null) {
|
||||
// Create a random placeholder string
|
||||
String random = "comment-" + UUID.randomUUID().toString();
|
||||
// Store placeholder
|
||||
config.set(random, " ");
|
||||
// Create comment
|
||||
yamlComments.put(random, "# " + comment.value());
|
||||
}
|
||||
|
||||
// Adapter
|
||||
Adapter adapterNotation = field.getAnnotation(Adapter.class);
|
||||
if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) {
|
||||
// A conversion adapter has been defined
|
||||
try {
|
||||
config.set(storageLocation, ((AdapterInterface<?,?>)adapterNotation.value().newInstance()).serialize(value));
|
||||
} catch (InstantiationException e) {
|
||||
plugin.logError("Could not instatiate adapter " + adapterNotation.value().getName() + " " + e.getMessage());
|
||||
}
|
||||
|
||||
// Depending on the vale type, it'll need serializing differently
|
||||
// Check if this field is the mandatory UniqueId field. This is used to identify this instantiation of the class
|
||||
if (method.getName().equals("getUniqueId")) {
|
||||
// If the object does not have a unique name assigned to it already, one is created at random
|
||||
String id = (String)value;
|
||||
if (value == null || id.isEmpty()) {
|
||||
id = databaseConnecter.getUniqueId(dataObject.getSimpleName());
|
||||
// Set it in the class so that it will be used next time
|
||||
propertyDescriptor.getWriteMethod().invoke(instance, id);
|
||||
}
|
||||
// Save the name for when the file is saved
|
||||
if (filename.isEmpty()) {
|
||||
filename = id;
|
||||
}
|
||||
// We are done here
|
||||
continue;
|
||||
}
|
||||
|
||||
// Depending on the vale type, it'll need serializing differently
|
||||
// Check if this field is the mandatory UniqueId field. This is used to identify this instantiation of the class
|
||||
if (method.getName().equals("getUniqueId")) {
|
||||
// If the object does not have a unique name assigned to it already, one is created at random
|
||||
String id = (String)value;
|
||||
if (value == null || id.isEmpty()) {
|
||||
id = databaseConnecter.getUniqueId(dataObject.getSimpleName());
|
||||
// Set it in the class so that it will be used next time
|
||||
propertyDescriptor.getWriteMethod().invoke(instance, id);
|
||||
}
|
||||
// Collections need special serialization
|
||||
if (Map.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
|
||||
// Maps need to have keys serialized
|
||||
if (value != null) {
|
||||
Map<Object, Object> result = new HashMap<>();
|
||||
for (Entry<Object, Object> object : ((Map<Object,Object>)value).entrySet()) {
|
||||
// Serialize all key and values
|
||||
result.put(serialize(object.getKey()), serialize(object.getValue()));
|
||||
}
|
||||
// Save the list in the config file
|
||||
config.set(storageLocation, result);
|
||||
}
|
||||
} else if (Set.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
|
||||
// Sets need to be serialized as string lists
|
||||
if (value != null) {
|
||||
List<Object> list = new ArrayList<>();
|
||||
for (Object object : (Set<Object>)value) {
|
||||
list.add(serialize(object));
|
||||
}
|
||||
// Save the list in the config file
|
||||
config.set(storageLocation, list);
|
||||
}
|
||||
} else {
|
||||
// For all other data that doesn't need special serialization
|
||||
config.set(storageLocation, serialize(value));
|
||||
// Save the name for when the file is saved
|
||||
if (filename.isEmpty()) {
|
||||
filename = id;
|
||||
}
|
||||
}
|
||||
// Collections need special serialization
|
||||
if (Map.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
|
||||
// Maps need to have keys serialized
|
||||
if (value != null) {
|
||||
Map<Object, Object> result = new HashMap<>();
|
||||
for (Entry<Object, Object> object : ((Map<Object,Object>)value).entrySet()) {
|
||||
// Serialize all key and values
|
||||
result.put(serialize(object.getKey()), serialize(object.getValue()));
|
||||
}
|
||||
// Save the list in the config file
|
||||
config.set(storageLocation, result);
|
||||
}
|
||||
} else if (Set.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
|
||||
// Sets need to be serialized as string lists
|
||||
if (value != null) {
|
||||
List<Object> list = new ArrayList<>();
|
||||
for (Object object : (Set<Object>)value) {
|
||||
list.add(serialize(object));
|
||||
}
|
||||
// Save the list in the config file
|
||||
config.set(storageLocation, list);
|
||||
}
|
||||
} else {
|
||||
// For all other data that doesn't need special serialization
|
||||
config.set(storageLocation, serialize(value));
|
||||
}
|
||||
}
|
||||
if (filename.isEmpty()) {
|
||||
throw new IllegalArgumentException("No uniqueId in class");
|
||||
}
|
||||
|
||||
|
||||
databaseConnecter.saveYamlFile(config, path, filename, yamlComments);
|
||||
}
|
||||
|
||||
@ -371,7 +371,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private Object deserialize(Object value, Class<? extends Object> clazz) {
|
||||
private Object deserialize(Object value, Class<?> clazz) {
|
||||
// If value is already null, then it can be nothing else
|
||||
if (value == null) {
|
||||
return null;
|
||||
@ -463,7 +463,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
@Override
|
||||
public void close() {
|
||||
// Not used
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ import us.tastybento.bskyblock.database.DatabaseConnectionSettingsImpl;
|
||||
public class MongoDBDatabaseConnecter implements DatabaseConnecter {
|
||||
|
||||
private MongoClient client;
|
||||
private MongoCredential credential;
|
||||
private DatabaseConnectionSettingsImpl dbSettings;
|
||||
|
||||
/**
|
||||
@ -25,11 +24,11 @@ public class MongoDBDatabaseConnecter implements DatabaseConnecter {
|
||||
*/
|
||||
public MongoDBDatabaseConnecter(DatabaseConnectionSettingsImpl dbSettings) {
|
||||
this.dbSettings = dbSettings;
|
||||
credential = MongoCredential.createCredential(dbSettings.getUsername(),
|
||||
MongoCredential credential = MongoCredential.createCredential(dbSettings.getUsername(),
|
||||
dbSettings.getDatabaseName(),
|
||||
dbSettings.getPassword().toCharArray());
|
||||
MongoClientOptions options = MongoClientOptions.builder().sslEnabled(false).build();
|
||||
client = new MongoClient(new ServerAddress(dbSettings.getHost(), dbSettings.getPort()),credential,options);
|
||||
client = new MongoClient(new ServerAddress(dbSettings.getHost(), dbSettings.getPort()), credential,options);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -12,7 +12,6 @@ import org.bukkit.potion.PotionEffectType;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import com.mongodb.client.MongoCursor;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import com.mongodb.client.model.FindOneAndReplaceOptions;
|
||||
import com.mongodb.client.model.IndexOptions;
|
||||
@ -43,10 +42,6 @@ public class MongoDBDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
private static final String UNIQUEID = "uniqueId";
|
||||
private static final String MONGO_ID = "_id";
|
||||
|
||||
/**
|
||||
* Connection to the database
|
||||
*/
|
||||
private MongoDatabase database = null;
|
||||
private MongoCollection<Document> collection;
|
||||
private DatabaseConnecter dbConnecter;
|
||||
|
||||
@ -63,7 +58,10 @@ public class MongoDBDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
super(plugin, type, dbConnecter);
|
||||
this.bskyblock = plugin;
|
||||
this.dbConnecter = dbConnecter;
|
||||
database = (MongoDatabase)dbConnecter.createConnection();
|
||||
/*
|
||||
Connection to the database
|
||||
*/
|
||||
MongoDatabase database = (MongoDatabase) dbConnecter.createConnection();
|
||||
collection = database.getCollection(dataObject.getCanonicalName());
|
||||
IndexOptions indexOptions = new IndexOptions().unique(true);
|
||||
collection.createIndex(Indexes.text(UNIQUEID), indexOptions);
|
||||
@ -90,10 +88,9 @@ public class MongoDBDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
public List<T> loadObjects() {
|
||||
List<T> list = new ArrayList<>();
|
||||
Gson gson = getGSON();
|
||||
MongoCursor<Document> it = collection.find(new Document()).iterator();
|
||||
while (it.hasNext()) {
|
||||
for (Document document : collection.find(new Document())) {
|
||||
// The deprecated serialize option does not have a viable alternative without involving a huge amount of custom code
|
||||
String json = JSON.serialize(it.next());
|
||||
String json = JSON.serialize(document);
|
||||
json = json.replaceFirst(MONGO_ID, UNIQUEID);
|
||||
list.add(gson.fromJson(json, dataObject));
|
||||
}
|
||||
@ -155,7 +152,7 @@ public class MongoDBDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
*/
|
||||
@Override
|
||||
public boolean objectExists(String key) {
|
||||
return collection.find(new Document(MONGO_ID, key)).first() != null ? true : false;
|
||||
return collection.find(new Document(MONGO_ID, key)).first() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,7 +39,7 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
/**
|
||||
* Connection to the database
|
||||
*/
|
||||
private Connection connection = null;
|
||||
private Connection connection;
|
||||
|
||||
private BSkyBlock bskyblock;
|
||||
|
||||
@ -62,12 +62,11 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
* Creates the table in the database if it doesn't exist already
|
||||
*/
|
||||
private void createSchema() {
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append("CREATE TABLE IF NOT EXISTS `");
|
||||
sql.append(dataObject.getCanonicalName());
|
||||
sql.append("` (json JSON, uniqueId VARCHAR(255) GENERATED ALWAYS AS (json->\"$.uniqueId\"), UNIQUE INDEX i (uniqueId) )");
|
||||
String sql = "CREATE TABLE IF NOT EXISTS `" +
|
||||
dataObject.getCanonicalName() +
|
||||
"` (json JSON, uniqueId VARCHAR(255) GENERATED ALWAYS AS (json->\"$.uniqueId\"), UNIQUE INDEX i (uniqueId) )";
|
||||
// Prepare and execute the database statements
|
||||
try (PreparedStatement pstmt = connection.prepareStatement(sql.toString())) {
|
||||
try (PreparedStatement pstmt = connection.prepareStatement(sql)) {
|
||||
pstmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
plugin.logError("Problem trying to create schema for data object " + dataObject.getCanonicalName() + " " + e.getMessage());
|
||||
@ -114,15 +113,14 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
|
||||
@Override
|
||||
public T loadObject(String uniqueId) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("SELECT `json` FROM `");
|
||||
sb.append(dataObject.getCanonicalName());
|
||||
sb.append("` WHERE uniqueId = ? LIMIT 1");
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sb.toString())) {
|
||||
String sb = "SELECT `json` FROM `" +
|
||||
dataObject.getCanonicalName() +
|
||||
"` WHERE uniqueId = ? LIMIT 1";
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sb)) {
|
||||
// UniqueId needs to be placed in quotes
|
||||
preparedStatement.setString(1, "\"" + uniqueId + "\"");
|
||||
try (ResultSet resultSet = preparedStatement.executeQuery()) {
|
||||
while (resultSet.next()) {
|
||||
if (resultSet.next()) {
|
||||
// If there is a result, we only want/need the first one
|
||||
Gson gson = getGSON();
|
||||
return gson.fromJson(resultSet.getString("json"), dataObject);
|
||||
@ -140,14 +138,13 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
plugin.logError("This class is not a DataObject: " + instance.getClass().getName());
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String sb = "INSERT INTO " +
|
||||
"`" +
|
||||
dataObject.getCanonicalName() +
|
||||
"` (json) VALUES (?) ON DUPLICATE KEY UPDATE json = ?";
|
||||
// Replace into is used so that any data in the table will be replaced with updated data
|
||||
sb.append("INSERT INTO ");
|
||||
sb.append("`");
|
||||
// The table name is the canonical name, so that add-ons can be sure of a unique table in the database
|
||||
sb.append(dataObject.getCanonicalName());
|
||||
sb.append("` (json) VALUES (?) ON DUPLICATE KEY UPDATE json = ?");
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sb.toString())) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sb)) {
|
||||
Gson gson = getGSON();
|
||||
String toStore = gson.toJson(instance);
|
||||
preparedStatement.setString(1, toStore);
|
||||
@ -164,11 +161,10 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
plugin.logError("This class is not a DataObject: " + instance.getClass().getName());
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("DELETE FROM `");
|
||||
sb.append(dataObject.getCanonicalName());
|
||||
sb.append("` WHERE uniqueId = ?");
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sb.toString())) {
|
||||
String sb = "DELETE FROM `" +
|
||||
dataObject.getCanonicalName() +
|
||||
"` WHERE uniqueId = ?";
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sb)) {
|
||||
Method getUniqueId = dataObject.getMethod("getUniqueId");
|
||||
String uniqueId = (String) getUniqueId.invoke(instance);
|
||||
preparedStatement.setString(1, uniqueId);
|
||||
@ -184,12 +180,11 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
@Override
|
||||
public boolean objectExists(String key) {
|
||||
// Create the query to see if this key exists
|
||||
StringBuilder query = new StringBuilder();
|
||||
query.append("SELECT IF ( EXISTS( SELECT * FROM `");
|
||||
query.append(dataObject.getCanonicalName());
|
||||
query.append("` WHERE `uniqueId` = ?), 1, 0)");
|
||||
String query = "SELECT IF ( EXISTS( SELECT * FROM `" +
|
||||
dataObject.getCanonicalName() +
|
||||
"` WHERE `uniqueId` = ?), 1, 0)";
|
||||
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(query.toString())) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
|
||||
preparedStatement.setString(1, key);
|
||||
try (ResultSet resultSet = preparedStatement.executeQuery()) {
|
||||
if (resultSet.next()) {
|
||||
|
@ -383,10 +383,7 @@ public class Island implements DataObject {
|
||||
}
|
||||
|
||||
public boolean inIslandSpace(Location location) {
|
||||
if (Util.sameWorld(world, location.getWorld())) {
|
||||
return inIslandSpace(location.getBlockX(), location.getBlockZ());
|
||||
}
|
||||
return false;
|
||||
return Util.sameWorld(world, location.getWorld()) && inIslandSpace(location.getBlockX(), location.getBlockZ());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -441,11 +438,7 @@ public class Island implements DataObject {
|
||||
* @return true if it is, false if not
|
||||
*/
|
||||
public boolean onIsland(Location target) {
|
||||
if (Util.sameWorld(world, target.getWorld())) {
|
||||
return target.getBlockX() >= minProtectedX && target.getBlockX() < (minProtectedX + protectionRange * 2)
|
||||
&& target.getBlockZ() >= minProtectedZ && target.getBlockZ() < (minProtectedZ + protectionRange * 2);
|
||||
}
|
||||
return false;
|
||||
return Util.sameWorld(world, target.getWorld()) && target.getBlockX() >= minProtectedX && target.getBlockX() < (minProtectedX + protectionRange * 2) && target.getBlockZ() >= minProtectedZ && target.getBlockZ() < (minProtectedZ + protectionRange * 2);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -459,7 +452,7 @@ public class Island implements DataObject {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a player from the team member map. Do not call this directly. Use {@link us.tastybento.bskyblock.managers.IslandsManager#removePlayer(UUID)}
|
||||
* Removes a player from the team member map. Do not call this directly. Use {@link us.tastybento.bskyblock.managers.IslandsManager#removePlayer(World, UUID)}
|
||||
* @param playerUUID
|
||||
*/
|
||||
public void removeMember(UUID playerUUID) {
|
||||
@ -675,7 +668,7 @@ public class Island implements DataObject {
|
||||
user.sendMessage("commands.admin.info.island-coords", "[xz1]", Util.xyz(from), "[xz2]", Util.xyz(to));
|
||||
user.sendMessage("commands.admin.info.protection-range", "[range]", String.valueOf(range));
|
||||
Vector pfrom = center.toVector().subtract(new Vector(protectionRange, 0, protectionRange)).setY(0);
|
||||
Vector pto = center.toVector().add(new Vector(protectionRange-1, 0, protectionRange-1)).setY(center.getWorld().getMaxHeight());;
|
||||
Vector pto = center.toVector().add(new Vector(protectionRange-1, 0, protectionRange-1)).setY(center.getWorld().getMaxHeight());
|
||||
user.sendMessage("commands.admin.info.protection-coords", "[xz1]", Util.xyz(pfrom), "[xz2]", Util.xyz(pto));
|
||||
if (spawn) {
|
||||
user.sendMessage("commands.admin.info.is-spawn");
|
||||
|
@ -80,7 +80,7 @@ public class Players implements DataObject {
|
||||
public Location getHomeLocation(World world, int number) {
|
||||
return homeLocations.entrySet().stream()
|
||||
.filter(en -> Util.sameWorld(en.getKey().getWorld(), world) && en.getValue() == number)
|
||||
.map(en -> en.getKey())
|
||||
.map(Map.Entry::getKey)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
@ -301,9 +301,7 @@ public class Clipboard {
|
||||
Bukkit.getLogger().info("Banner");
|
||||
Banner banner = (Banner)bs;
|
||||
s.set("baseColor", banner.getBaseColor().toString());
|
||||
banner.getPatterns().forEach(p -> {
|
||||
s.set("pattern." + p.getPattern().toString(), p.getColor().toString());
|
||||
});
|
||||
banner.getPatterns().forEach(p -> s.set("pattern." + p.getPattern().toString(), p.getColor().toString()));
|
||||
}
|
||||
if (bs instanceof InventoryHolder) {
|
||||
Bukkit.getLogger().info("Inventory holder");
|
||||
@ -357,7 +355,7 @@ public class Clipboard {
|
||||
|
||||
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(unzipFilePath.toAbsolutePath().toString()))) {
|
||||
byte[] bytesIn = new byte[1024];
|
||||
int read = 0;
|
||||
int read;
|
||||
while ((read = zipInputStream.read(bytesIn)) != -1) {
|
||||
bos.write(bytesIn, 0, read);
|
||||
}
|
||||
|
@ -80,25 +80,29 @@ public class IslandBuilder {
|
||||
|
||||
public void build() {
|
||||
// Switch on island type
|
||||
if (type == IslandType.ISLAND) {
|
||||
world = island.getWorld();
|
||||
if (Constants.GAMETYPE == GameType.ACIDISLAND) {
|
||||
generateAcidIslandBlocks();
|
||||
} else {
|
||||
generateIslandBlocks();
|
||||
}
|
||||
} else if (type == IslandType.NETHER) {
|
||||
world = Bukkit.getWorld(island.getWorld().getName() + "_nether");
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
generateNetherBlocks();
|
||||
} else if (type == IslandType.END) {
|
||||
world = Bukkit.getWorld(island.getWorld().getName() + "_the_end");
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
generateEndBlocks();
|
||||
switch (type) {
|
||||
case ISLAND:
|
||||
world = island.getWorld();
|
||||
if (Constants.GAMETYPE == GameType.ACIDISLAND) {
|
||||
generateAcidIslandBlocks();
|
||||
} else {
|
||||
generateIslandBlocks();
|
||||
}
|
||||
break;
|
||||
case NETHER:
|
||||
world = Bukkit.getWorld(island.getWorld().getName() + "_nether");
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
generateNetherBlocks();
|
||||
break;
|
||||
case END:
|
||||
world = Bukkit.getWorld(island.getWorld().getName() + "_the_end");
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
generateEndBlocks();
|
||||
break;
|
||||
}
|
||||
// Do other stuff
|
||||
}
|
||||
@ -221,7 +225,7 @@ public class IslandBuilder {
|
||||
int islandHeight = island.getCenter().getBlockY();
|
||||
|
||||
World world = island.getCenter().getWorld();
|
||||
int y = 0;
|
||||
int y;
|
||||
// Add some grass
|
||||
for (y = islandHeight + 4; y < islandHeight + 5; y++) {
|
||||
for (int x_space = x - 3; x_space <= x + 3; x_space++) {
|
||||
@ -302,7 +306,7 @@ public class IslandBuilder {
|
||||
int z = island.getCenter().getBlockZ();
|
||||
int islandHeight = island.getCenter().getBlockY();
|
||||
|
||||
int y = 0;
|
||||
int y;
|
||||
for (y = islandHeight + 4; y < islandHeight + 5; y++) {
|
||||
for (int x_space = x - 3; x_space <= x + 3; x_space++) {
|
||||
for (int z_space = z - 3; z_space <= z + 3; z_space++) {
|
||||
@ -374,7 +378,7 @@ public class IslandBuilder {
|
||||
int z = island.getCenter().getBlockZ();
|
||||
int islandHeight = island.getCenter().getBlockY();
|
||||
|
||||
int y = 0;
|
||||
int y;
|
||||
// Add some grass
|
||||
for (y = islandHeight + 4; y < islandHeight + 5; y++) {
|
||||
for (int x_space = x - 3; x_space <= x + 3; x_space++) {
|
||||
|
@ -1,12 +1,9 @@
|
||||
package us.tastybento.bskyblock.listeners;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -43,11 +40,11 @@ public class NetherPortals implements Listener {
|
||||
* @param location - the location
|
||||
* @return true if in the spawn area, false if not
|
||||
*/
|
||||
private boolean awayFromSpawn(Location location) {
|
||||
private boolean atSpawn(Location location) {
|
||||
Vector p = location.toVector().multiply(new Vector(1, 0, 1));
|
||||
Vector spawn = location.getWorld().getSpawnLocation().toVector().multiply(new Vector(1, 0, 1));
|
||||
int radiusSquared = plugin.getIWM().getNetherSpawnRadius(location.getWorld()) ^ 2;
|
||||
return (spawn.distanceSquared(p) < radiusSquared) ? false : true;
|
||||
return (spawn.distanceSquared(p) < radiusSquared);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,8 +60,8 @@ public class NetherPortals implements Listener {
|
||||
return true;
|
||||
}
|
||||
// Player is in an island world and in a nether or end
|
||||
return (player.getWorld().getEnvironment().equals(Environment.NETHER) && plugin.getIWM().isNetherIslands(player.getWorld()))
|
||||
|| (player.getWorld().getEnvironment().equals(Environment.THE_END) && plugin.getIWM().isEndIslands(player.getWorld())) ? true: false;
|
||||
return (player.getWorld().getEnvironment().equals(Environment.NETHER) && plugin.getIWM().isNetherIslands(player.getWorld()))
|
||||
|| (player.getWorld().getEnvironment().equals(Environment.THE_END) && plugin.getIWM().isEndIslands(player.getWorld()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,7 +74,7 @@ public class NetherPortals implements Listener {
|
||||
if (noAction(e.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
if (!awayFromSpawn(e.getBlock().getLocation())) {
|
||||
if (atSpawn(e.getBlock().getLocation())) {
|
||||
User.getInstance(e.getPlayer()).sendMessage(ERROR_NO_PERMISSION);
|
||||
e.setCancelled(true);
|
||||
}
|
||||
@ -92,7 +89,7 @@ public class NetherPortals implements Listener {
|
||||
if (noAction(e.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
if (!awayFromSpawn(e.getBlockClicked().getLocation())) {
|
||||
if (atSpawn(e.getBlockClicked().getLocation())) {
|
||||
User.getInstance(e.getPlayer()).sendMessage(ERROR_NO_PERMISSION);
|
||||
e.setCancelled(true);
|
||||
}
|
||||
@ -126,7 +123,6 @@ public class NetherPortals implements Listener {
|
||||
.location(e.getFrom().toVector().toLocation(endWorld))
|
||||
.build();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -161,13 +157,7 @@ public class NetherPortals implements Listener {
|
||||
if (expl == null) {
|
||||
return false;
|
||||
}
|
||||
Iterator<Block> it = e.blockList().iterator();
|
||||
while (it.hasNext()) {
|
||||
Block b = it.next();
|
||||
if (!awayFromSpawn(b.getLocation())) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
e.blockList().removeIf(b -> atSpawn(b.getLocation()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -222,7 +212,7 @@ public class NetherPortals implements Listener {
|
||||
if (noAction(e.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
if (!awayFromSpawn(e.getBlock().getLocation())) {
|
||||
if (atSpawn(e.getBlock().getLocation())) {
|
||||
User.getInstance(e.getPlayer()).sendMessage(ERROR_NO_PERMISSION);
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.listeners;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.listeners.flags;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.listeners.flags;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
@ -67,7 +67,7 @@ public class BreakBlocksListener extends AbstractFlagListener {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {}
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
switch (e.getClickedBlock().getType()) {
|
||||
case CAKE_BLOCK:
|
||||
@ -101,7 +101,6 @@ public class BreakBlocksListener extends AbstractFlagListener {
|
||||
e.setCancelled(true);
|
||||
user.sendMessage("protection.protected");
|
||||
}
|
||||
return;
|
||||
});
|
||||
|
||||
// The player is in the world, but not on an island, so general world settings apply
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.listeners.flags;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.listeners.flags;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.listeners.flags;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.listeners.flags;
|
||||
|
||||
import org.bukkit.entity.Animals;
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.listeners.flags;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.listeners.flags;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.listeners.flags;
|
||||
|
||||
import org.bukkit.block.Beacon;
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.listeners.flags;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.listeners.flags;
|
||||
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.listeners.flags;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -40,7 +37,6 @@ public class LockAndBanListener implements Listener {
|
||||
|
||||
/**
|
||||
* Enforces island bans and locks
|
||||
* @param plugin
|
||||
*/
|
||||
public LockAndBanListener() {
|
||||
this.im = BSkyBlock.getInstance().getIslands();
|
||||
@ -49,7 +45,7 @@ public class LockAndBanListener implements Listener {
|
||||
// Teleport check
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerTeleport(PlayerTeleportEvent e) {
|
||||
e.setCancelled(checkAndNotify(e.getPlayer(), e.getTo()).equals(CheckResult.OPEN) ? false : true);
|
||||
e.setCancelled(!checkAndNotify(e.getPlayer(), e.getTo()).equals(CheckResult.OPEN));
|
||||
}
|
||||
|
||||
// Movement check
|
||||
@ -59,7 +55,7 @@ public class LockAndBanListener implements Listener {
|
||||
if (e.getFrom().getBlockX() - e.getTo().getBlockX() == 0 && e.getFrom().getBlockZ() - e.getTo().getBlockZ() == 0) {
|
||||
return;
|
||||
}
|
||||
if (checkAndNotify(e.getPlayer(), e.getTo()).equals(CheckResult.OPEN) ? false : true) {
|
||||
if (!checkAndNotify(e.getPlayer(), e.getTo()).equals(CheckResult.OPEN)) {
|
||||
e.setCancelled(true);
|
||||
e.getFrom().getWorld().playSound(e.getFrom(), Sound.BLOCK_ANVIL_HIT, 1F, 1F);
|
||||
e.getPlayer().setVelocity(new Vector(0,0,0));
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.listeners.flags;
|
||||
|
||||
import java.util.Optional;
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.listeners.flags;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.listeners.flags;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.listeners.flags;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.listeners.flags;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.listeners.flags;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.listeners.flags;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
|
@ -51,7 +51,6 @@ public class InventorySave {
|
||||
player.getInventory().setContents(inv.getInventory());
|
||||
player.getInventory().setArmorContents(inv.getArmor());
|
||||
inventories.remove(player.getUniqueId());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,19 +10,18 @@ import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.InvalidDescriptionException;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.addons.Addon;
|
||||
import us.tastybento.bskyblock.api.addons.AddonClassLoader;
|
||||
import us.tastybento.bskyblock.api.addons.exception.InvalidAddonFormatException;
|
||||
import us.tastybento.bskyblock.api.addons.exception.InvalidAddonInheritException;
|
||||
import us.tastybento.bskyblock.api.events.addon.AddonEvent;
|
||||
|
||||
/**
|
||||
@ -52,7 +51,7 @@ public class AddonsManager {
|
||||
if (!f.exists()) {
|
||||
f.mkdirs();
|
||||
}
|
||||
Arrays.stream(f.listFiles()).filter(x -> !x.isDirectory() && x.getName().endsWith(".jar")).forEach(t -> {
|
||||
Arrays.stream(Objects.requireNonNull(f.listFiles())).filter(x -> !x.isDirectory() && x.getName().endsWith(".jar")).forEach(t -> {
|
||||
plugin.log("Loading " + t.getName());
|
||||
try {
|
||||
loadAddon(t);
|
||||
@ -82,12 +81,12 @@ public class AddonsManager {
|
||||
* @return Optional addon object
|
||||
*/
|
||||
public Optional<Addon> getAddonByName(String name){
|
||||
return Optional.ofNullable(addons.stream().filter(a -> a.getDescription().getName().contains(name)).findFirst().orElse(null));
|
||||
return addons.stream().filter(a -> a.getDescription().getName().contains(name)).findFirst();
|
||||
}
|
||||
|
||||
private void loadAddon(File f) throws InvalidAddonFormatException, InvalidAddonInheritException, InvalidDescriptionException {
|
||||
private void loadAddon(File f) {
|
||||
try {
|
||||
Addon addon = null;
|
||||
Addon addon;
|
||||
// Check that this is a jar
|
||||
if (!f.getName().endsWith(".jar")) {
|
||||
throw new IOException("Filename must end in .jar. Name is '" + f.getName() + "'");
|
||||
@ -174,7 +173,7 @@ public class AddonsManager {
|
||||
* @return Class - the class
|
||||
*/
|
||||
public Class<?> getClassByName(final String name) {
|
||||
return classes.getOrDefault(name, loader.stream().map(l -> l.findClass(name, false)).filter(c -> c != null).findFirst().orElse(null));
|
||||
return classes.getOrDefault(name, loader.stream().map(l -> l.findClass(name, false)).filter(Objects::nonNull).findFirst().orElse(null));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -207,17 +206,11 @@ public class AddonsManager {
|
||||
public List<String> listJarYamlFiles(JarFile jar, String folderPath) {
|
||||
List<String> result = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Loop through all the entries.
|
||||
*/
|
||||
Enumeration<JarEntry> entries = jar.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
JarEntry entry = entries.nextElement();
|
||||
String path = entry.getName();
|
||||
|
||||
/**
|
||||
* Not in the folder.
|
||||
*/
|
||||
if (!path.startsWith(folderPath)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -327,7 +327,7 @@ public class IslandWorldManager {
|
||||
*/
|
||||
public boolean isNether(World world) {
|
||||
World w = Util.getWorld(world);
|
||||
return (worldSettings.containsKey(w) && worldSettings.get(w).isNetherGenerate()) ? true : false;
|
||||
return worldSettings.containsKey(w) && worldSettings.get(w).isNetherGenerate();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -337,7 +337,7 @@ public class IslandWorldManager {
|
||||
*/
|
||||
public boolean isIslandNether(World world) {
|
||||
World w = Util.getWorld(world);
|
||||
return (worldSettings.containsKey(w) && worldSettings.get(w).isNetherGenerate() && worldSettings.get(w).isNetherIslands()) ? true : false;
|
||||
return worldSettings.containsKey(w) && worldSettings.get(w).isNetherGenerate() && worldSettings.get(w).isNetherIslands();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -347,7 +347,7 @@ public class IslandWorldManager {
|
||||
*/
|
||||
public boolean isEnd(World world) {
|
||||
World w = Util.getWorld(world);
|
||||
return (worldSettings.containsKey(w) && worldSettings.get(w).isEndGenerate()) ? true : false;
|
||||
return worldSettings.containsKey(w) && worldSettings.get(w).isEndGenerate();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -357,7 +357,7 @@ public class IslandWorldManager {
|
||||
*/
|
||||
public boolean isIslandEnd(World world) {
|
||||
World w = Util.getWorld(world);
|
||||
return (worldSettings.containsKey(w) && worldSettings.get(w).isEndGenerate() && worldSettings.get(w).isEndIslands()) ? true : false;
|
||||
return worldSettings.containsKey(w) && worldSettings.get(w).isEndGenerate() && worldSettings.get(w).isEndIslands();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -385,7 +385,7 @@ public class IslandWorldManager {
|
||||
*/
|
||||
public boolean isNetherTrees(World world) {
|
||||
World w = Util.getWorld(world);
|
||||
return (worldSettings.containsKey(w) && worldSettings.get(w).isNetherTrees()) ? true : false;
|
||||
return worldSettings.containsKey(w) && worldSettings.get(w).isNetherTrees();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -395,7 +395,7 @@ public class IslandWorldManager {
|
||||
*/
|
||||
public boolean isDragonSpawn(World world) {
|
||||
World w = Util.getWorld(world);
|
||||
return (worldSettings.containsKey(w) && !worldSettings.get(w).isDragonSpawn()) ? false : true;
|
||||
return !worldSettings.containsKey(w) || worldSettings.get(w).isDragonSpawn();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,7 +63,7 @@ public class IslandsManager {
|
||||
// Ground must be solid
|
||||
if (!ground.getType().isSolid()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Cannot be submerged
|
||||
if (space1.isLiquid() && space2.isLiquid()) {
|
||||
return false;
|
||||
@ -88,7 +88,7 @@ public class IslandsManager {
|
||||
MaterialData md = ground.getState().getData();
|
||||
if (md instanceof SimpleAttachableMaterialData) {
|
||||
if (md instanceof TrapDoor) {
|
||||
TrapDoor trapDoor = (TrapDoor)md;
|
||||
TrapDoor trapDoor = (TrapDoor) md;
|
||||
if (trapDoor.isOpen()) {
|
||||
return false;
|
||||
}
|
||||
@ -105,14 +105,7 @@ public class IslandsManager {
|
||||
// check
|
||||
// a few other items
|
||||
// isSolid thinks that PLATEs and SIGNS are solid, but they are not
|
||||
if (space1.getType().isSolid() && !space1.getType().equals(Material.SIGN_POST) && !space1.getType().equals(Material.WALL_SIGN)) {
|
||||
return false;
|
||||
}
|
||||
if (space2.getType().isSolid()&& !space2.getType().equals(Material.SIGN_POST) && !space2.getType().equals(Material.WALL_SIGN)) {
|
||||
return false;
|
||||
}
|
||||
// Safe
|
||||
return true;
|
||||
return (!space1.getType().isSolid() || space1.getType().equals(Material.SIGN_POST) || space1.getType().equals(Material.WALL_SIGN)) && (!space2.getType().isSolid() || space2.getType().equals(Material.SIGN_POST) || space2.getType().equals(Material.WALL_SIGN));
|
||||
}
|
||||
|
||||
private BSkyBlock plugin;
|
||||
@ -369,13 +362,11 @@ public class IslandsManager {
|
||||
// To cover slabs, stairs and other half blocks, try one block above
|
||||
Location lPlusOne = l.clone();
|
||||
lPlusOne.add(new Vector(0, 1, 0));
|
||||
if (lPlusOne != null) {
|
||||
if (isSafeLocation(lPlusOne)) {
|
||||
// Adjust the home location accordingly
|
||||
plugin.getPlayers().setHomeLocation(user, lPlusOne, number);
|
||||
return lPlusOne;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Home location either isn't safe, or does not exist so try the island
|
||||
// location
|
||||
@ -451,7 +442,7 @@ public class IslandsManager {
|
||||
/**
|
||||
* Provides UUID of this player's team leader or null if it does not exist
|
||||
* @param world - world to check
|
||||
* @param playerUUID - the player's UUID
|
||||
* @param leaderUUID - the leader's UUID
|
||||
* @return UUID of leader or null if player has no island
|
||||
*/
|
||||
public UUID getTeamLeader(World world, UUID leaderUUID) {
|
||||
@ -530,7 +521,6 @@ public class IslandsManager {
|
||||
if (player.getGameMode().equals(GameMode.SPECTATOR)) {
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -540,10 +530,7 @@ public class IslandsManager {
|
||||
* @return true if they are, false if they are not, or spawn does not exist
|
||||
*/
|
||||
public boolean isAtSpawn(Location playerLoc) {
|
||||
if (!spawn.containsKey(playerLoc.getWorld())) {
|
||||
return false;
|
||||
}
|
||||
return spawn.get(playerLoc.getWorld()).onIsland(playerLoc);
|
||||
return spawn.containsKey(playerLoc.getWorld()) && spawn.get(playerLoc.getWorld()).onIsland(playerLoc);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -611,7 +598,7 @@ public class IslandsManager {
|
||||
* @return true if the player is the owner of their island, i.e., owner or team leader
|
||||
*/
|
||||
public boolean isOwner(World world, UUID uniqueId) {
|
||||
return hasIsland(world, uniqueId) ? getIsland(world, uniqueId).getOwner().equals(uniqueId) : false;
|
||||
return hasIsland(world, uniqueId) && getIsland(world, uniqueId).getOwner().equals(uniqueId);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -747,14 +734,13 @@ public class IslandsManager {
|
||||
* @param playerUUID - the player's UUID
|
||||
* @return true if successful, false if not
|
||||
*/
|
||||
public boolean setJoinTeam(Island teamIsland, UUID playerUUID) {
|
||||
public void setJoinTeam(Island teamIsland, UUID playerUUID) {
|
||||
// Add player to new island
|
||||
teamIsland.addMember(playerUUID);
|
||||
islandCache.addPlayer(playerUUID, teamIsland);
|
||||
// Save the database
|
||||
save(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setLast(Location last) {
|
||||
|
@ -7,6 +7,7 @@ import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
@ -82,7 +83,7 @@ public class LocalesManager {
|
||||
}
|
||||
|
||||
// Store all the locales available
|
||||
for (File language : localeDir.listFiles(ymlFilter)) {
|
||||
for (File language : Objects.requireNonNull(localeDir.listFiles(ymlFilter))) {
|
||||
Locale localeObject = Locale.forLanguageTag(language.getName().substring(0, language.getName().length() - 4));
|
||||
if (languages.containsKey(localeObject)) {
|
||||
// Merge into current language
|
||||
|
@ -99,7 +99,7 @@ public class PlayersManager {
|
||||
return;
|
||||
}
|
||||
if (!playerCache.containsKey(playerUUID)) {
|
||||
Players player = null;
|
||||
Players player;
|
||||
// If the player is in the database, load it, otherwise create a new player
|
||||
if (handler.objectExists(playerUUID.toString())) {
|
||||
player = handler.loadObject(playerUUID.toString());
|
||||
@ -107,7 +107,6 @@ public class PlayersManager {
|
||||
player = new Players(plugin, playerUUID);
|
||||
}
|
||||
playerCache.put(playerUUID, player);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,12 +144,8 @@ public class PlayersManager {
|
||||
return false;
|
||||
}
|
||||
// Try cache
|
||||
if (playerCache.containsKey(uniqueID)) {
|
||||
return true;
|
||||
} else {
|
||||
// Get from the database - do not add to cache yet
|
||||
return handler.objectExists(uniqueID.toString());
|
||||
}
|
||||
return playerCache.containsKey(uniqueID) || handler.objectExists(uniqueID.toString());
|
||||
// Get from the database - do not add to cache yet
|
||||
}
|
||||
|
||||
/**
|
||||
@ -253,7 +248,7 @@ public class PlayersManager {
|
||||
if (string.length() == 36 && string.contains("-")) {
|
||||
try {
|
||||
return UUID.fromString(string);
|
||||
} catch (Exception e) {}
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
// Look in the name cache, then the data base and finally Bukkit blocking request
|
||||
return playerCache.values().stream()
|
||||
|
@ -90,16 +90,13 @@ public class RanksManager {
|
||||
* @return true if removed
|
||||
*/
|
||||
public boolean removeRank(String reference) {
|
||||
if (reference.equalsIgnoreCase(OWNER_RANK_REF)
|
||||
|| reference.equalsIgnoreCase(MEMBER_RANK_REF)
|
||||
|| reference.equalsIgnoreCase(VISITOR_RANK_REF)
|
||||
|| reference.equalsIgnoreCase(BANNED_RANK_REF)
|
||||
|| reference.equalsIgnoreCase(ADMIN_RANK_REF)
|
||||
|| reference.equalsIgnoreCase(MOD_RANK_REF)) {
|
||||
return false;
|
||||
}
|
||||
return !reference.equalsIgnoreCase(OWNER_RANK_REF)
|
||||
&& !reference.equalsIgnoreCase(MEMBER_RANK_REF)
|
||||
&& !reference.equalsIgnoreCase(VISITOR_RANK_REF)
|
||||
&& !reference.equalsIgnoreCase(BANNED_RANK_REF)
|
||||
&& !reference.equalsIgnoreCase(ADMIN_RANK_REF)
|
||||
&& !reference.equalsIgnoreCase(MOD_RANK_REF) && (ranks.remove(reference) != null);
|
||||
|
||||
return ranks.remove(reference) == null ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,9 +4,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -80,13 +78,7 @@ public class IslandCache {
|
||||
if (!islandsByLocation.remove(island.getCenter(), island) || !islandsByUUID.containsKey(island.getWorld())) {
|
||||
return false;
|
||||
}
|
||||
Iterator<Entry<UUID, Island>> it = islandsByUUID.get(island.getWorld()).entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<UUID, Island> en = it.next();
|
||||
if (en.getValue().equals(island)) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
islandsByUUID.get(island.getWorld()).entrySet().removeIf(en -> en.getValue().equals(island));
|
||||
// Remove from grid
|
||||
grids.putIfAbsent(island.getWorld(), new IslandGrid());
|
||||
return grids.get(island.getWorld()).removeFromGrid(island);
|
||||
@ -165,16 +157,14 @@ public class IslandCache {
|
||||
public boolean hasIsland(World world, UUID uuid) {
|
||||
islandsByUUID.putIfAbsent(Util.getWorld(world), new HashMap<>());
|
||||
Island island = islandsByUUID.get(Util.getWorld(world)).get(uuid);
|
||||
if (island != null) {
|
||||
return island.getOwner().equals(uuid);
|
||||
}
|
||||
return false;
|
||||
return island != null && island.getOwner().equals(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a player from the cache. If the player has an island, the island owner is removed and membership cleared.
|
||||
* The island is removed from the islandsByUUID map, but kept in the location map.
|
||||
* @param playerUUID - player's UUID
|
||||
* @param world - world
|
||||
* @param uuid - player's UUID
|
||||
*/
|
||||
public void removePlayer(World world, UUID uuid) {
|
||||
islandsByUUID.putIfAbsent(Util.getWorld(world), new HashMap<>());
|
||||
|
@ -190,28 +190,27 @@ public class NewIsland {
|
||||
int x = lastIsland.getBlockX();
|
||||
int z = lastIsland.getBlockZ();
|
||||
int d = plugin.getIWM().getIslandDistance(lastIsland.getWorld()) * 2;
|
||||
Location nextPos = lastIsland;
|
||||
if (x < z) {
|
||||
if (-1 * x < z) {
|
||||
nextPos.setX(nextPos.getX() + d);
|
||||
return nextPos;
|
||||
lastIsland.setX(lastIsland.getX() + d);
|
||||
return lastIsland;
|
||||
}
|
||||
nextPos.setZ(nextPos.getZ() + d);
|
||||
return nextPos;
|
||||
lastIsland.setZ(lastIsland.getZ() + d);
|
||||
return lastIsland;
|
||||
}
|
||||
if (x > z) {
|
||||
if (-1 * x >= z) {
|
||||
nextPos.setX(nextPos.getX() - d);
|
||||
return nextPos;
|
||||
lastIsland.setX(lastIsland.getX() - d);
|
||||
return lastIsland;
|
||||
}
|
||||
nextPos.setZ(nextPos.getZ() - d);
|
||||
return nextPos;
|
||||
lastIsland.setZ(lastIsland.getZ() - d);
|
||||
return lastIsland;
|
||||
}
|
||||
if (x <= 0) {
|
||||
nextPos.setZ(nextPos.getZ() + d);
|
||||
return nextPos;
|
||||
lastIsland.setZ(lastIsland.getZ() + d);
|
||||
return lastIsland;
|
||||
}
|
||||
nextPos.setZ(nextPos.getZ() - d);
|
||||
return nextPos;
|
||||
lastIsland.setZ(lastIsland.getZ() - d);
|
||||
return lastIsland;
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
@ -40,14 +41,11 @@ public class FileLister{
|
||||
File localeDir = new File(plugin.getDataFolder(), folderPath);
|
||||
if (localeDir.exists()) {
|
||||
FilenameFilter ymlFilter = (File dir, String name) -> name.toLowerCase().endsWith(".yml");
|
||||
return Arrays.asList(localeDir.list(ymlFilter));
|
||||
return Arrays.asList(Objects.requireNonNull(localeDir.list(ymlFilter)));
|
||||
} else if (checkJar) {
|
||||
// Else look in the JAR
|
||||
File jarfile;
|
||||
|
||||
/**
|
||||
* Get the jar file from the plugin.
|
||||
*/
|
||||
try {
|
||||
Method method = JavaPlugin.class.getDeclaredMethod("getFile");
|
||||
method.setAccessible(true);
|
||||
@ -59,17 +57,11 @@ public class FileLister{
|
||||
|
||||
JarFile jar = new JarFile(jarfile);
|
||||
|
||||
/**
|
||||
* Loop through all the entries.
|
||||
*/
|
||||
Enumeration<JarEntry> entries = jar.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
JarEntry entry = entries.nextElement();
|
||||
String path = entry.getName();
|
||||
|
||||
/**
|
||||
* Not in the folder.
|
||||
*/
|
||||
if (!path.startsWith(folderPath)) {
|
||||
continue;
|
||||
}
|
||||
@ -89,9 +81,6 @@ public class FileLister{
|
||||
// Look in the JAR
|
||||
File jarfile;
|
||||
|
||||
/**
|
||||
* Get the jar file from the plugin.
|
||||
*/
|
||||
try {
|
||||
Method method = JavaPlugin.class.getDeclaredMethod("getFile");
|
||||
method.setAccessible(true);
|
||||
@ -103,17 +92,11 @@ public class FileLister{
|
||||
|
||||
JarFile jar = new JarFile(jarfile);
|
||||
|
||||
/**
|
||||
* Loop through all the entries.
|
||||
*/
|
||||
Enumeration<JarEntry> entries = jar.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
JarEntry entry = entries.nextElement();
|
||||
String path = entry.getName();
|
||||
|
||||
/**
|
||||
* Not in the folder.
|
||||
*/
|
||||
if (!path.startsWith(folderPath)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ import us.tastybento.bskyblock.api.panels.PanelItem;
|
||||
|
||||
public class HeadGetter {
|
||||
private static Map<String,ItemStack> cachedHeads = new HashMap<>();
|
||||
private static Map<String, PanelItem> names = new HashMap<>();
|
||||
private static final Map<String, PanelItem> names = new HashMap<>();
|
||||
private BSkyBlock plugin;
|
||||
private static Map<String,Set<HeadRequester>> headRequesters = new HashMap<>();
|
||||
|
||||
|
@ -7,5 +7,5 @@ public interface HeadRequester {
|
||||
/**
|
||||
* @param item - panel item
|
||||
*/
|
||||
public void setHead(PanelItem item);
|
||||
void setHead(PanelItem item);
|
||||
}
|
||||
|
@ -53,13 +53,8 @@ public class Pair<X, Z> {
|
||||
return false;
|
||||
}
|
||||
if (z == null) {
|
||||
if (other.z != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!z.equals(other.z)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return other.z == null;
|
||||
} else return z.equals(other.z);
|
||||
}
|
||||
|
||||
}
|
@ -125,22 +125,22 @@ public class Util {
|
||||
* Credits to mikenon on GitHub!
|
||||
*/
|
||||
public static String prettifyText(String ugly) {
|
||||
String fin = "";
|
||||
StringBuilder fin = new StringBuilder();
|
||||
ugly = ugly.toLowerCase();
|
||||
if (ugly.contains("_")) {
|
||||
String[] splt = ugly.split("_");
|
||||
int i = 0;
|
||||
for (String s : splt) {
|
||||
i += 1;
|
||||
fin += Character.toUpperCase(s.charAt(0)) + s.substring(1);
|
||||
fin.append(Character.toUpperCase(s.charAt(0))).append(s.substring(1));
|
||||
if (i < splt.length) {
|
||||
fin += " ";
|
||||
fin.append(" ");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fin += Character.toUpperCase(ugly.charAt(0)) + ugly.substring(1);
|
||||
fin.append(Character.toUpperCase(ugly.charAt(0))).append(ugly.substring(1));
|
||||
}
|
||||
return fin;
|
||||
return fin.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,11 +52,11 @@ public class YmlCommentParser {
|
||||
Matcher commentM = COMMENT_PATTERN.matcher(line);
|
||||
Matcher sectionM = SECTION_PATTERN.matcher(line);
|
||||
if (commentM.matches()) {
|
||||
comments.append(commentM.group("comment") + "\n");
|
||||
comments.append(commentM.group("comment")).append("\n");
|
||||
} else if (sectionM.matches()) {
|
||||
String comment = sectionM.group("comment");
|
||||
if (comment != null && !comment.trim().isEmpty()) {
|
||||
comments.append(comment + "\n");
|
||||
comments.append(comment).append("\n");
|
||||
}
|
||||
String name = sectionM.group("name").trim();
|
||||
String value = sectionM.group("value");
|
||||
@ -158,9 +158,9 @@ public class YmlCommentParser {
|
||||
String path = getPath(baseKey, name);
|
||||
String comment = getComment(path);
|
||||
if (comment != null) {
|
||||
sb.append((lineNum > 1 ? "\n" : "") + comment
|
||||
sb.append(lineNum > 1 ? "\n" : "").append(comment
|
||||
.replaceAll("^#", Matcher.quoteReplacement(indent + "#"))
|
||||
.replaceAll("\n#", Matcher.quoteReplacement("\n" + indent + "#")));
|
||||
.replaceAll("\n#", Matcher.quoteReplacement("\n" + indent + "#")));
|
||||
}
|
||||
if (value != null && !value.trim().isEmpty()) {
|
||||
// Scalar with value
|
||||
@ -173,7 +173,7 @@ public class YmlCommentParser {
|
||||
}
|
||||
}
|
||||
lineNum++;
|
||||
sb.append(line + "\n");
|
||||
sb.append(line).append("\n");
|
||||
}
|
||||
return sb.toString().replaceAll("\r\n", "\n").replaceAll("\n\r", "\n").replaceAll("\n", "\r\n");
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public class SafeSpotTeleport {
|
||||
private static final int MAX_CHUNKS = 200;
|
||||
private static final long SPEED = 1;
|
||||
private static final int MAX_RADIUS = 200;
|
||||
private boolean checking = true;
|
||||
private boolean checking;
|
||||
private BukkitTask task;
|
||||
|
||||
// Parameters
|
||||
|
@ -13,6 +13,7 @@ import static org.mockito.Mockito.when;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@ -168,7 +169,7 @@ public class TestBSkyBlock {
|
||||
|
||||
Settings settings = mock(Settings.class);
|
||||
Mockito.when(plugin.getSettings()).thenReturn(settings);
|
||||
Mockito.when(settings.getFakePlayers()).thenReturn(new HashSet<String>());
|
||||
Mockito.when(settings.getFakePlayers()).thenReturn(new HashSet<>());
|
||||
|
||||
}
|
||||
|
||||
@ -215,11 +216,11 @@ public class TestBSkyBlock {
|
||||
args[0] = "d";
|
||||
assertNotSame(Arrays.asList("help", "sub1","sub2"), testCommand.tabComplete(player, "test", args));
|
||||
args[0] = "sub1";
|
||||
assertEquals(Arrays.asList(), testCommand.tabComplete(player, "test", args));
|
||||
assertEquals(Collections.emptyList(), testCommand.tabComplete(player, "test", args));
|
||||
String[] args2 = {"sub2",""};
|
||||
assertEquals(Arrays.asList("subsub", "help"), testCommand.tabComplete(player, "test", args2));
|
||||
args2[1] = "s";
|
||||
assertEquals(Arrays.asList("subsub"), testCommand.tabComplete(player, "test", args2));
|
||||
assertEquals(Collections.singletonList("subsub"), testCommand.tabComplete(player, "test", args2));
|
||||
String[] args3 = {"sub2","subsub", ""};
|
||||
assertEquals(Arrays.asList("subsubsub", "help"), testCommand.tabComplete(player, "test", args3));
|
||||
// Test for overridden tabcomplete
|
||||
@ -343,9 +344,8 @@ public class TestBSkyBlock {
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
List<String> options = new ArrayList<>();
|
||||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
|
||||
options.addAll(Arrays.asList("Florian", "Ben", "Bill", "Ted"));
|
||||
List<String> options = new ArrayList<>(Arrays.asList("Florian", "Ben", "Bill", "Ted"));
|
||||
return Optional.of(Util.tabLimit(options, lastArg));
|
||||
}
|
||||
}
|
||||
|
@ -42,13 +42,12 @@ public class AddonTest {
|
||||
@Mock
|
||||
static BSkyBlock plugin;
|
||||
static JavaPlugin javaPlugin;
|
||||
private static World world;
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
Server server = mock(Server.class);
|
||||
world = mock(World.class);
|
||||
World world = mock(World.class);
|
||||
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||
when(server.getWorld("world")).thenReturn(world);
|
||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||
|
@ -35,14 +35,7 @@ import us.tastybento.bskyblock.managers.PlayersManager;
|
||||
@PrepareForTest({Bukkit.class, BSkyBlock.class, CommandEvent.class})
|
||||
public class DefaultHelpCommandTest {
|
||||
|
||||
private BSkyBlock plugin;
|
||||
private IslandCommand ic;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private Settings s;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private Player player;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
@ -50,7 +43,7 @@ public class DefaultHelpCommandTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
plugin = mock(BSkyBlock.class);
|
||||
BSkyBlock plugin = mock(BSkyBlock.class);
|
||||
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||
|
||||
// Command manager
|
||||
@ -58,17 +51,17 @@ public class DefaultHelpCommandTest {
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getResetLimit()).thenReturn(3);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
player = mock(Player.class);
|
||||
Player player = mock(Player.class);
|
||||
// Sometimes use: Mockito.withSettings().verboseLogging()
|
||||
user = mock(User.class);
|
||||
when(user.isOp()).thenReturn(false);
|
||||
uuid = UUID.randomUUID();
|
||||
UUID uuid = UUID.randomUUID();
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.getPlayer()).thenReturn(player);
|
||||
User.setPlugin(plugin);
|
||||
@ -76,11 +69,11 @@ public class DefaultHelpCommandTest {
|
||||
User.getInstance(player);
|
||||
|
||||
// Parent command has no aliases
|
||||
ic = mock(IslandCommand.class);
|
||||
IslandCommand ic = mock(IslandCommand.class);
|
||||
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
|
||||
// No island for player to begin with (set it later in the tests)
|
||||
im = mock(IslandsManager.class);
|
||||
IslandsManager im = mock(IslandsManager.class);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
||||
when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
||||
// Has team
|
||||
@ -88,7 +81,7 @@ public class DefaultHelpCommandTest {
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
|
||||
pm = mock(PlayersManager.class);
|
||||
PlayersManager pm = mock(PlayersManager.class);
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
// Server & Scheduler
|
||||
|
@ -43,13 +43,12 @@ import us.tastybento.bskyblock.managers.PlayersManager;
|
||||
@RunWith(PowerMockRunner.class)
|
||||
public class UserTest {
|
||||
|
||||
private static World world;
|
||||
private static Player player;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
Server server = mock(Server.class);
|
||||
world = mock(World.class);
|
||||
World world = mock(World.class);
|
||||
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||
when(server.getWorld("world")).thenReturn(world);
|
||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||
|
@ -42,12 +42,11 @@ public class AdminCommandTest {
|
||||
|
||||
@Mock
|
||||
static BSkyBlock plugin;
|
||||
private static World world;
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
Server server = mock(Server.class);
|
||||
world = mock(World.class);
|
||||
World world = mock(World.class);
|
||||
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||
when(server.getWorld("world")).thenReturn(world);
|
||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||
|
@ -49,7 +49,6 @@ public class AdminInfoCommandTest {
|
||||
private AdminCommand ac;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private Settings s;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
@ -68,7 +67,7 @@ public class AdminInfoCommandTest {
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getResetLimit()).thenReturn(3);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
@ -46,11 +46,9 @@ import us.tastybento.bskyblock.managers.PlayersManager;
|
||||
@PrepareForTest({Bukkit.class, BSkyBlock.class, User.class })
|
||||
public class AdminRegisterCommandTest {
|
||||
|
||||
private BSkyBlock plugin;
|
||||
private AdminCommand ac;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private Settings s;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
@ -61,7 +59,7 @@ public class AdminRegisterCommandTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
plugin = mock(BSkyBlock.class);
|
||||
BSkyBlock plugin = mock(BSkyBlock.class);
|
||||
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||
|
||||
// Command manager
|
||||
@ -69,7 +67,7 @@ public class AdminRegisterCommandTest {
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getResetLimit()).thenReturn(3);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
@ -45,11 +45,8 @@ import us.tastybento.bskyblock.managers.PlayersManager;
|
||||
@PrepareForTest({Bukkit.class, BSkyBlock.class, User.class })
|
||||
public class AdminUnregisterCommandTest {
|
||||
|
||||
private BSkyBlock plugin;
|
||||
private AdminCommand ac;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private Settings s;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
@ -60,7 +57,7 @@ public class AdminUnregisterCommandTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
plugin = mock(BSkyBlock.class);
|
||||
BSkyBlock plugin = mock(BSkyBlock.class);
|
||||
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||
|
||||
// Command manager
|
||||
@ -68,7 +65,7 @@ public class AdminUnregisterCommandTest {
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getResetLimit()).thenReturn(3);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
@ -78,7 +75,7 @@ public class AdminUnregisterCommandTest {
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
user = mock(User.class);
|
||||
when(user.isOp()).thenReturn(false);
|
||||
uuid = UUID.randomUUID();
|
||||
UUID uuid = UUID.randomUUID();
|
||||
notUUID = UUID.randomUUID();
|
||||
while(notUUID.equals(uuid)) {
|
||||
notUUID = UUID.randomUUID();
|
||||
|
@ -47,7 +47,6 @@ public class AdminTeamAddCommandTest {
|
||||
private AdminCommand ac;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private Settings s;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
@ -66,7 +65,7 @@ public class AdminTeamAddCommandTest {
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getResetLimit()).thenReturn(3);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
@ -44,11 +44,9 @@ import us.tastybento.bskyblock.managers.PlayersManager;
|
||||
@PrepareForTest({Bukkit.class, BSkyBlock.class, User.class })
|
||||
public class AdminTeamDisbandCommandTest {
|
||||
|
||||
private BSkyBlock plugin;
|
||||
private AdminCommand ac;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private Settings s;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
@ -59,7 +57,7 @@ public class AdminTeamDisbandCommandTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
plugin = mock(BSkyBlock.class);
|
||||
BSkyBlock plugin = mock(BSkyBlock.class);
|
||||
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||
|
||||
// Command manager
|
||||
@ -67,7 +65,7 @@ public class AdminTeamDisbandCommandTest {
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getResetLimit()).thenReturn(3);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
@ -50,7 +50,6 @@ public class AdminTeamKickCommandTest {
|
||||
private AdminCommand ac;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private Settings s;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
@ -69,7 +68,7 @@ public class AdminTeamKickCommandTest {
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getResetLimit()).thenReturn(3);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
@ -44,11 +44,9 @@ import us.tastybento.bskyblock.managers.PlayersManager;
|
||||
@PrepareForTest({Bukkit.class, BSkyBlock.class, User.class })
|
||||
public class AdminTeamMakeLeaderCommandTest {
|
||||
|
||||
private BSkyBlock plugin;
|
||||
private AdminCommand ac;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private Settings s;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
@ -59,7 +57,7 @@ public class AdminTeamMakeLeaderCommandTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
plugin = mock(BSkyBlock.class);
|
||||
BSkyBlock plugin = mock(BSkyBlock.class);
|
||||
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||
|
||||
// Command manager
|
||||
@ -67,7 +65,7 @@ public class AdminTeamMakeLeaderCommandTest {
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getResetLimit()).thenReturn(3);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
@ -52,11 +52,9 @@ import us.tastybento.bskyblock.managers.PlayersManager;
|
||||
@PrepareForTest({Bukkit.class, BSkyBlock.class, User.class })
|
||||
public class IslandBanCommandTest {
|
||||
|
||||
private BSkyBlock plugin;
|
||||
private IslandCommand ic;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private Settings s;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private Island island;
|
||||
@ -67,7 +65,7 @@ public class IslandBanCommandTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
plugin = mock(BSkyBlock.class);
|
||||
BSkyBlock plugin = mock(BSkyBlock.class);
|
||||
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||
|
||||
// Command manager
|
||||
@ -75,7 +73,7 @@ public class IslandBanCommandTest {
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getResetLimit()).thenReturn(3);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
@ -350,7 +348,7 @@ public class IslandBanCommandTest {
|
||||
@Override
|
||||
public Boolean answer(InvocationOnMock invocation) throws Throwable {
|
||||
Player p = invocation.getArgumentAt(0, Player.class);
|
||||
return p.getName().equals("ian") ? false : true;
|
||||
return !p.getName().equals("ian");
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -48,11 +48,9 @@ import us.tastybento.bskyblock.managers.PlayersManager;
|
||||
@PrepareForTest({Bukkit.class, BSkyBlock.class, User.class })
|
||||
public class IslandBanlistCommandTest {
|
||||
|
||||
private BSkyBlock plugin;
|
||||
private IslandCommand ic;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private Settings s;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private Island island;
|
||||
@ -63,7 +61,7 @@ public class IslandBanlistCommandTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
plugin = mock(BSkyBlock.class);
|
||||
BSkyBlock plugin = mock(BSkyBlock.class);
|
||||
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||
|
||||
// Command manager
|
||||
@ -71,7 +69,7 @@ public class IslandBanlistCommandTest {
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getResetLimit()).thenReturn(3);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
@ -45,7 +45,6 @@ import us.tastybento.bskyblock.managers.island.NewIsland;
|
||||
@PrepareForTest({Bukkit.class, BSkyBlock.class, NewIsland.class })
|
||||
public class IslandResetCommandTest {
|
||||
|
||||
private BSkyBlock plugin;
|
||||
private IslandCommand ic;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
@ -59,7 +58,7 @@ public class IslandResetCommandTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
plugin = mock(BSkyBlock.class);
|
||||
BSkyBlock plugin = mock(BSkyBlock.class);
|
||||
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||
|
||||
// Command manager
|
||||
|
@ -48,11 +48,9 @@ import us.tastybento.bskyblock.managers.PlayersManager;
|
||||
@PrepareForTest({Bukkit.class, BSkyBlock.class, User.class })
|
||||
public class IslandUnbanCommandTest {
|
||||
|
||||
private BSkyBlock plugin;
|
||||
private IslandCommand ic;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private Settings s;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private Island island;
|
||||
@ -63,7 +61,7 @@ public class IslandUnbanCommandTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
plugin = mock(BSkyBlock.class);
|
||||
BSkyBlock plugin = mock(BSkyBlock.class);
|
||||
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||
|
||||
// Command manager
|
||||
@ -71,7 +69,7 @@ public class IslandUnbanCommandTest {
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getResetLimit()).thenReturn(3);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
@ -42,11 +42,9 @@ import us.tastybento.bskyblock.managers.PlayersManager;
|
||||
@PrepareForTest({Bukkit.class, BSkyBlock.class, User.class })
|
||||
public class IslandTeamInviteCommandTest {
|
||||
|
||||
private BSkyBlock plugin;
|
||||
private IslandCommand ic;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private Settings s;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
@ -57,7 +55,7 @@ public class IslandTeamInviteCommandTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
plugin = mock(BSkyBlock.class);
|
||||
BSkyBlock plugin = mock(BSkyBlock.class);
|
||||
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||
|
||||
// Command manager
|
||||
@ -65,7 +63,7 @@ public class IslandTeamInviteCommandTest {
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getResetLimit()).thenReturn(3);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
@ -45,7 +45,6 @@ import us.tastybento.bskyblock.managers.PlayersManager;
|
||||
@PrepareForTest({Bukkit.class, BSkyBlock.class, User.class })
|
||||
public class IslandTeamKickCommandTest {
|
||||
|
||||
private BSkyBlock plugin;
|
||||
private IslandCommand ic;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
@ -60,7 +59,7 @@ public class IslandTeamKickCommandTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
plugin = mock(BSkyBlock.class);
|
||||
BSkyBlock plugin = mock(BSkyBlock.class);
|
||||
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||
|
||||
// Command manager
|
||||
|
@ -40,13 +40,11 @@ import us.tastybento.bskyblock.managers.PlayersManager;
|
||||
@PrepareForTest({Bukkit.class, BSkyBlock.class, User.class })
|
||||
public class IslandTeamLeaveCommandTest {
|
||||
|
||||
private BSkyBlock plugin;
|
||||
private IslandCommand ic;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private Settings s;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
@ -54,7 +52,7 @@ public class IslandTeamLeaveCommandTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
plugin = mock(BSkyBlock.class);
|
||||
BSkyBlock plugin = mock(BSkyBlock.class);
|
||||
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||
|
||||
// Command manager
|
||||
@ -88,7 +86,7 @@ public class IslandTeamLeaveCommandTest {
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
PlayersManager pm = mock(PlayersManager.class);
|
||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
|
@ -61,13 +61,8 @@ import us.tastybento.bskyblock.util.Util;
|
||||
public class NetherPortalsTest {
|
||||
|
||||
private BSkyBlock plugin;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private Settings s;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
private BukkitScheduler sch;
|
||||
private IslandWorldManager iwm;
|
||||
private World world;
|
||||
private World nether;
|
||||
@ -102,7 +97,7 @@ public class NetherPortalsTest {
|
||||
when(Util.getWorld(Mockito.any())).thenReturn(world);
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
Settings s = mock(Settings.class);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Set up spawn
|
||||
@ -113,10 +108,10 @@ public class NetherPortalsTest {
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
user = mock(User.class);
|
||||
User user = mock(User.class);
|
||||
when(user.isOp()).thenReturn(false);
|
||||
uuid = UUID.randomUUID();
|
||||
notUUID = UUID.randomUUID();
|
||||
UUID uuid = UUID.randomUUID();
|
||||
UUID notUUID = UUID.randomUUID();
|
||||
while(notUUID.equals(uuid)) {
|
||||
notUUID = UUID.randomUUID();
|
||||
}
|
||||
@ -135,7 +130,7 @@ public class NetherPortalsTest {
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
// Server & Scheduler
|
||||
sch = mock(BukkitScheduler.class);
|
||||
BukkitScheduler sch = mock(BukkitScheduler.class);
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
when(Bukkit.getScheduler()).thenReturn(sch);
|
||||
|
||||
|
@ -58,10 +58,6 @@ public class FireListenerTest {
|
||||
|
||||
private static Location location;
|
||||
private static BSkyBlock plugin;
|
||||
private static FlagsManager flagsManager;
|
||||
private static Zombie zombie;
|
||||
private static Slime slime;
|
||||
private static Cow cow;
|
||||
private static IslandWorldManager iwm;
|
||||
|
||||
@BeforeClass
|
||||
@ -95,7 +91,7 @@ public class FireListenerTest {
|
||||
when(location.getBlockZ()).thenReturn(0);
|
||||
PowerMockito.mockStatic(Flags.class);
|
||||
|
||||
flagsManager = new FlagsManager(plugin);
|
||||
FlagsManager flagsManager = new FlagsManager(plugin);
|
||||
when(plugin.getFlagsManager()).thenReturn(flagsManager);
|
||||
|
||||
|
||||
@ -112,11 +108,11 @@ public class FireListenerTest {
|
||||
when(Util.getWorld(Mockito.any())).thenReturn(world);
|
||||
|
||||
// Monsters and animals
|
||||
zombie = mock(Zombie.class);
|
||||
Zombie zombie = mock(Zombie.class);
|
||||
when(zombie.getLocation()).thenReturn(location);
|
||||
slime = mock(Slime.class);
|
||||
Slime slime = mock(Slime.class);
|
||||
when(slime.getLocation()).thenReturn(location);
|
||||
cow = mock(Cow.class);
|
||||
Cow cow = mock(Cow.class);
|
||||
when(cow.getLocation()).thenReturn(location);
|
||||
|
||||
// Fake players
|
||||
|
@ -52,16 +52,12 @@ public class LockAndBanListenerTest {
|
||||
private static final Integer X = 600;
|
||||
private static final Integer Y = 120;
|
||||
private static final Integer Z = 10000;
|
||||
private BSkyBlock plugin;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private Settings s;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private Island island;
|
||||
private World world;
|
||||
private LockAndBanListener listener;
|
||||
private Location loc;
|
||||
private Location outside;
|
||||
private Location inside;
|
||||
private Notifier notifier;
|
||||
@ -75,14 +71,14 @@ public class LockAndBanListenerTest {
|
||||
public void setUp() throws Exception {
|
||||
|
||||
// Set up plugin
|
||||
plugin = mock(BSkyBlock.class);
|
||||
BSkyBlock plugin = mock(BSkyBlock.class);
|
||||
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||
|
||||
// World
|
||||
world = mock(World.class);
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getResetLimit()).thenReturn(3);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
@ -105,7 +101,7 @@ public class LockAndBanListenerTest {
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
PlayersManager pm = mock(PlayersManager.class);
|
||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
@ -127,7 +123,7 @@ public class LockAndBanListenerTest {
|
||||
island = mock(Island.class);
|
||||
when(island.getBanned()).thenReturn(new HashSet<>());
|
||||
when(island.isBanned(Mockito.any())).thenReturn(false);
|
||||
loc = mock(Location.class);
|
||||
Location loc = mock(Location.class);
|
||||
when(loc.getWorld()).thenReturn(world);
|
||||
when(loc.getBlockX()).thenReturn(X);
|
||||
when(loc.getBlockY()).thenReturn(Y);
|
||||
@ -551,7 +547,7 @@ public class LockAndBanListenerTest {
|
||||
|
||||
@Override
|
||||
public Boolean answer(InvocationOnMock invocation) throws Throwable {
|
||||
return invocation.getArgumentAt(0, User.class).getUniqueId().equals(uuid2) ? true : false;
|
||||
return invocation.getArgumentAt(0, User.class).getUniqueId().equals(uuid2);
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -46,7 +46,6 @@ public class MobSpawnListenerTest {
|
||||
|
||||
private static Location location;
|
||||
private static BSkyBlock plugin;
|
||||
private static FlagsManager flagsManager;
|
||||
private static Zombie zombie;
|
||||
private static Slime slime;
|
||||
private static Cow cow;
|
||||
@ -87,7 +86,7 @@ public class MobSpawnListenerTest {
|
||||
when(location.getBlockZ()).thenReturn(0);
|
||||
PowerMockito.mockStatic(Flags.class);
|
||||
|
||||
flagsManager = new FlagsManager(plugin);
|
||||
FlagsManager flagsManager = new FlagsManager(plugin);
|
||||
when(plugin.getFlagsManager()).thenReturn(flagsManager);
|
||||
|
||||
// Monsters and animals
|
||||
|
@ -53,19 +53,9 @@ public class UpDownClickTest {
|
||||
private BSkyBlock plugin;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private Settings s;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private Island island;
|
||||
private World world;
|
||||
private Location loc;
|
||||
private Location outside;
|
||||
private Location inside;
|
||||
private Notifier notifier;
|
||||
private Location inside2;
|
||||
private BukkitScheduler sch;
|
||||
private Flag flag;
|
||||
private PanelItem panelItem;
|
||||
private Panel panel;
|
||||
private Inventory inv;
|
||||
|
||||
@ -80,10 +70,10 @@ public class UpDownClickTest {
|
||||
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||
|
||||
// World
|
||||
world = mock(World.class);
|
||||
World world = mock(World.class);
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
Settings s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getResetLimit()).thenReturn(3);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
@ -107,12 +97,12 @@ public class UpDownClickTest {
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
PlayersManager pm = mock(PlayersManager.class);
|
||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
// Server & Scheduler
|
||||
sch = mock(BukkitScheduler.class);
|
||||
BukkitScheduler sch = mock(BukkitScheduler.class);
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
when(Bukkit.getScheduler()).thenReturn(sch);
|
||||
|
||||
@ -122,14 +112,14 @@ public class UpDownClickTest {
|
||||
when(lm.get(any(), any())).thenReturn("mock translation");
|
||||
|
||||
// Notifier
|
||||
notifier = mock(Notifier.class);
|
||||
Notifier notifier = mock(Notifier.class);
|
||||
when(plugin.getNotifier()).thenReturn(notifier);
|
||||
|
||||
// Island Banned list initialization
|
||||
island = mock(Island.class);
|
||||
when(island.getBanned()).thenReturn(new HashSet<>());
|
||||
when(island.isBanned(Mockito.any())).thenReturn(false);
|
||||
loc = mock(Location.class);
|
||||
Location loc = mock(Location.class);
|
||||
when(loc.getWorld()).thenReturn(world);
|
||||
when(loc.getBlockX()).thenReturn(X);
|
||||
when(loc.getBlockY()).thenReturn(Y);
|
||||
@ -144,19 +134,19 @@ public class UpDownClickTest {
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
||||
|
||||
// Common from to's
|
||||
outside = mock(Location.class);
|
||||
Location outside = mock(Location.class);
|
||||
when(outside.getWorld()).thenReturn(world);
|
||||
when(outside.getBlockX()).thenReturn(X + PROTECTION_RANGE + 1);
|
||||
when(outside.getBlockY()).thenReturn(Y);
|
||||
when(outside.getBlockZ()).thenReturn(Z);
|
||||
|
||||
inside = mock(Location.class);
|
||||
Location inside = mock(Location.class);
|
||||
when(inside.getWorld()).thenReturn(world);
|
||||
when(inside.getBlockX()).thenReturn(X + PROTECTION_RANGE - 1);
|
||||
when(inside.getBlockY()).thenReturn(Y);
|
||||
when(inside.getBlockZ()).thenReturn(Z);
|
||||
|
||||
inside2 = mock(Location.class);
|
||||
Location inside2 = mock(Location.class);
|
||||
when(inside.getWorld()).thenReturn(world);
|
||||
when(inside.getBlockX()).thenReturn(X + PROTECTION_RANGE - 2);
|
||||
when(inside.getBlockY()).thenReturn(Y);
|
||||
@ -167,7 +157,7 @@ public class UpDownClickTest {
|
||||
when(im.getProtectedIslandAt(Mockito.eq(inside2))).thenReturn(opIsland);
|
||||
when(im.getProtectedIslandAt(Mockito.eq(outside))).thenReturn(Optional.empty());
|
||||
|
||||
panelItem = mock(PanelItem.class);
|
||||
PanelItem panelItem = mock(PanelItem.class);
|
||||
flag = mock(Flag.class);
|
||||
when(flag.toPanelItem(Mockito.any(), Mockito.any())).thenReturn(panelItem);
|
||||
when(panelItem.getItem()).thenReturn(mock(ItemStack.class));
|
||||
|
@ -60,12 +60,8 @@ import us.tastybento.bskyblock.util.Util;
|
||||
public class FlyingMobEventsTest {
|
||||
|
||||
private BSkyBlock plugin;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private Settings s;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
private BukkitScheduler sch;
|
||||
private IslandWorldManager iwm;
|
||||
|
||||
@ -79,16 +75,16 @@ public class FlyingMobEventsTest {
|
||||
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
Settings s = mock(Settings.class);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
user = mock(User.class);
|
||||
User user = mock(User.class);
|
||||
when(user.isOp()).thenReturn(false);
|
||||
uuid = UUID.randomUUID();
|
||||
notUUID = UUID.randomUUID();
|
||||
UUID uuid = UUID.randomUUID();
|
||||
UUID notUUID = UUID.randomUUID();
|
||||
while(notUUID.equals(uuid)) {
|
||||
notUUID = UUID.randomUUID();
|
||||
}
|
||||
|
@ -52,11 +52,7 @@ public class PlayersManagerTest {
|
||||
private BSkyBlock plugin;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private Settings s;
|
||||
private IslandsManager im;
|
||||
private UUID notUUID;
|
||||
private BukkitScheduler sch;
|
||||
private IslandWorldManager iwm;
|
||||
private World world;
|
||||
private World nether;
|
||||
private World end;
|
||||
@ -72,7 +68,7 @@ public class PlayersManagerTest {
|
||||
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||
|
||||
// island world mgr
|
||||
iwm = mock(IslandWorldManager.class);
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
world = mock(World.class);
|
||||
when(world.getName()).thenReturn("world");
|
||||
nether = mock(World.class);
|
||||
@ -86,7 +82,7 @@ public class PlayersManagerTest {
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
Settings s = mock(Settings.class);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Set up spawn
|
||||
@ -111,7 +107,7 @@ public class PlayersManagerTest {
|
||||
User.setPlugin(plugin);
|
||||
|
||||
// Player has island to begin with
|
||||
im = mock(IslandsManager.class);
|
||||
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);
|
||||
when(im.getTeamLeader(Mockito.any(), Mockito.any())).thenReturn(uuid);
|
||||
@ -119,7 +115,7 @@ public class PlayersManagerTest {
|
||||
|
||||
|
||||
// Server & Scheduler
|
||||
sch = mock(BukkitScheduler.class);
|
||||
BukkitScheduler sch = mock(BukkitScheduler.class);
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
when(Bukkit.getScheduler()).thenReturn(sch);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user