From 92af75e6028b2e10ddaa61deed4686c98620e549 Mon Sep 17 00:00:00 2001 From: Tastybento Date: Sat, 6 Jan 2018 15:23:01 -0800 Subject: [PATCH] Converted to using the Settings loaded by the database handler. Removed a lot of static references. Constants have their own class. --- .../us/tastybento/bskyblock/BSkyBlock.java | 156 ++- .../us/tastybento/bskyblock/Constants.java | 38 + .../us/tastybento/bskyblock/EnumAdapter.java | 25 - .../us/tastybento/bskyblock/Settings.java | 1075 ++++++++++++++-- .../us/tastybento/bskyblock/Settings2.java | 1115 ----------------- .../api/commands/CompositeCommand.java | 108 +- .../bskyblock/api/commands/User.java | 3 +- .../api/configuration/ISettings.java | 8 +- .../api/events/command/CommandEvent.java | 1 + .../api/events/purge/PurgeStartEvent.java | 1 + .../tastybento/bskyblock/api/flags/Flag.java | 7 +- .../bskyblock/api/flags/FlagBuilder.java | 7 +- .../bskyblock/api/localization/BSBLocale.java | 3 - .../bskyblock/commands/AdminCommand.java | 6 +- .../bskyblock/commands/IslandCommand.java | 6 +- .../commands/admin/AdminReloadCommand.java | 2 - .../commands/admin/AdminVersionCommand.java | 4 +- .../island/CustomIslandMultiHomeHelp.java | 4 +- .../commands/island/IslandCreateCommand.java | 6 +- .../commands/island/IslandGoCommand.java | 6 +- .../commands/island/IslandResetCommand.java | 6 +- .../island/IslandResetnameCommand.java | 4 +- .../commands/island/IslandSethomeCommand.java | 6 +- .../commands/island/IslandSetnameCommand.java | 14 +- .../teams/AbstractIslandTeamCommand.java | 3 +- .../island/teams/IslandTeamCommand.java | 14 +- .../teams/IslandTeamInviteAcceptCommand.java | 8 +- .../island/teams/IslandTeamInviteCommand.java | 14 +- .../teams/IslandTeamInviteRejectCommand.java | 4 +- .../island/teams/IslandTeamLeaveCommand.java | 4 +- .../teams/IslandTeamPromoteCommand.java | 4 +- .../teams/IslandTeamSetownerCommand.java | 12 +- .../bskyblock/config/ConfigLoader.java | 69 - .../bskyblock/config/PluginConfig.java | 128 -- .../bskyblock/database/BSBDatabase.java | 10 +- .../DatabaseConnectionSettingsImpl.java | 10 - .../database/flatfile/FlatFileDatabase.java | 5 +- .../flatfile/FlatFileDatabaseHandler.java | 5 +- .../database/managers/PlayersManager.java | 8 +- .../database/managers/island/IslandCache.java | 3 +- .../managers/island/IslandsManager.java | 31 +- .../database/managers/island/NewIsland.java | 51 +- .../database/mysql/MySQLDatabase.java | 13 +- .../database/objects/DataObject.java | 12 +- .../bskyblock/database/objects/Island.java | 14 +- .../bskyblock/database/objects/Players.java | 19 +- .../generators/ChunkGeneratorWorld.java | 19 +- .../bskyblock/generators/IslandWorld.java | 64 +- .../island/builders/IslandBuilder.java | 16 +- .../listeners/JoinLeaveListener.java | 10 +- .../bskyblock/managers/FlagsManager.java | 11 +- .../bskyblock/managers/LocalesManager.java | 44 +- .../bskyblock/util/DeleteIslandChunks.java | 10 +- .../us/tastybento/bskyblock/util/Util.java | 33 +- src/test/java/bskyblock/TestBSkyBlock.java | 10 +- 55 files changed, 1447 insertions(+), 1822 deletions(-) create mode 100644 src/main/java/us/tastybento/bskyblock/Constants.java delete mode 100644 src/main/java/us/tastybento/bskyblock/EnumAdapter.java delete mode 100644 src/main/java/us/tastybento/bskyblock/Settings2.java delete mode 100644 src/main/java/us/tastybento/bskyblock/config/ConfigLoader.java delete mode 100644 src/main/java/us/tastybento/bskyblock/config/PluginConfig.java diff --git a/src/main/java/us/tastybento/bskyblock/BSkyBlock.java b/src/main/java/us/tastybento/bskyblock/BSkyBlock.java index 34f4096da..57e02e73a 100755 --- a/src/main/java/us/tastybento/bskyblock/BSkyBlock.java +++ b/src/main/java/us/tastybento/bskyblock/BSkyBlock.java @@ -7,7 +7,6 @@ import org.bukkit.plugin.java.JavaPlugin; import us.tastybento.bskyblock.commands.AdminCommand; import us.tastybento.bskyblock.commands.IslandCommand; -import us.tastybento.bskyblock.config.PluginConfig; import us.tastybento.bskyblock.database.BSBDatabase; import us.tastybento.bskyblock.database.managers.PlayersManager; import us.tastybento.bskyblock.database.managers.island.IslandsManager; @@ -40,79 +39,82 @@ public class BSkyBlock extends JavaPlugin { private LocalesManager localesManager; private AddonsManager addonsManager; private FlagsManager flagsManager; + private IslandWorld islandWorldManager; + + // Settings + Settings settings; + @Override public void onEnable(){ plugin = this; // Load config - EXPERIMENTAL - Settings2 config = new Settings2(); + settings = new Settings(); try { //config.saveConfig(); // works, but will wipe out comments - config = config.loadConfig(); - getLogger().info("DEBUG: island distance = " + config.getIslandDistance()); + settings = settings.loadSettings(); + getLogger().info("DEBUG: island distance = " + settings.getIslandDistance()); } catch (Exception e) { e.printStackTrace(); } - - // Load configuration and locales. If there are no errors, load the plugin. - if(PluginConfig.loadPluginConfig(this)){ - - playersManager = new PlayersManager(this); - islandsManager = new IslandsManager(this); - // Load metrics - metrics = new Metrics(plugin); - registerCustomCharts(); + playersManager = new PlayersManager(this); + islandsManager = new IslandsManager(this); - // Set up commands - commandsManager = new CommandsManager(); - new IslandCommand(); - new AdminCommand(); + // Load metrics + metrics = new Metrics(plugin); + registerCustomCharts(); - // These items have to be loaded when the server has done 1 tick. - // Note Worlds are not loaded this early, so any Locations or World reference will be null - // at this point. Therefore, the 1 tick scheduler is required. - getServer().getScheduler().runTask(this, new Runnable() { + // Set up commands + commandsManager = new CommandsManager(); + new IslandCommand(); + new AdminCommand(); - @Override - public void run() { - // Create the world if it does not exist - new IslandWorld(plugin); - - getServer().getScheduler().runTask(plugin, new Runnable() { + // These items have to be loaded when the server has done 1 tick. + // Note Worlds are not loaded this early, so any Locations or World reference will be null + // at this point. Therefore, the 1 tick scheduler is required. + getServer().getScheduler().runTask(this, new Runnable() { - @Override - public void run() { - // Load islands from database - islandsManager.load(); + @Override + public void run() { + // Create the world if it does not exist + islandWorldManager = new IslandWorld(plugin); - // TODO: load these from config.yml - Settings.chestItems = new ItemStack[] { - new ItemStack(Material.LAVA_BUCKET,1), - new ItemStack(Material.ICE,2), - new ItemStack(Material.MELON_SEEDS,1), - new ItemStack(Material.BONE,2), - new ItemStack(Material.COBBLESTONE,5), - new ItemStack(Material.SAPLING,2) - }; + getServer().getScheduler().runTask(plugin, new Runnable() { - Settings.defaultLanguage = "en-US"; - localesManager = new LocalesManager(plugin); - //TODO localesManager.registerLocales(plugin); + @Override + public void run() { + // Load islands from database + islandsManager.load(); - // Register Listeners - registerListeners(); + // TODO: load these from config.yml + getSettings().setChestItems(new ItemStack[] { + new ItemStack(Material.LAVA_BUCKET,1), + new ItemStack(Material.ICE,2), + new ItemStack(Material.MELON_SEEDS,1), + new ItemStack(Material.BONE,2), + new ItemStack(Material.COBBLESTONE,5), + new ItemStack(Material.SAPLING,2) + }); - // Load Flags - flagsManager = new FlagsManager(); + //getSettings().setDefaultLanguage("en-US"); + plugin.getLogger().info("DEBUG: ************************** Loading Locales **************************"); + localesManager = new LocalesManager(plugin); + //TODO localesManager.registerLocales(plugin); - // Load addons - addonsManager = new AddonsManager(plugin); - addonsManager.enableAddons(); + // Register Listeners + registerListeners(); - /* - *DEBUG CODE + // Load Flags + flagsManager = new FlagsManager(); + + // Load addons + addonsManager = new AddonsManager(plugin); + addonsManager.enableAddons(); + + /* + *DEBUG CODE Island loadedIsland = islandsManager.getIsland(owner); getLogger().info("Island name = " + loadedIsland.getName()); getLogger().info("Island locked = " + loadedIsland.getLocked()); @@ -121,24 +123,25 @@ public class BSkyBlock extends JavaPlugin { for (Entry flag: loadedIsland.getFlags().entrySet()) { getLogger().info("Flag " + flag.getKey().name() + " = " + flag.getValue()); } - */ - // Save islands & players data asynchronously every X minutes - Settings.databaseBackupPeriod = 10 * 60 * 20; - plugin.getServer().getScheduler().runTaskTimer(plugin, new Runnable() { + */ + // Save islands & players data asynchronously every X minutes + getSettings().setDatabaseBackupPeriod(10 * 60 * 20); + plugin.getServer().getScheduler().runTaskTimer(plugin, new Runnable() { - @Override - public void run() { - playersManager.save(true); - islandsManager.save(true); - } - }, Settings.databaseBackupPeriod, Settings.databaseBackupPeriod); - } - }); - } - }); - } + @Override + public void run() { + playersManager.save(true); + islandsManager.save(true); + } + }, getSettings().getDatabaseBackupPeriod(), getSettings().getDatabaseBackupPeriod()); + } + }); + } + }); } + + private void registerListeners() { PluginManager manager = getServer().getPluginManager(); // Player join events @@ -177,7 +180,7 @@ public class BSkyBlock extends JavaPlugin { @Override public String getValue() { - return Settings.defaultLanguage; + return getSettings().getDefaultLanguage(); } }); @@ -185,7 +188,7 @@ public class BSkyBlock extends JavaPlugin { @Override public String getValue() { - return BSBDatabase.getDatabase().toString(); + return BSBDatabase.getDatabase(plugin).toString(); } }); } @@ -238,4 +241,19 @@ public class BSkyBlock extends JavaPlugin { return flagsManager; } + /** + * @return the settings + */ + public Settings getSettings() { + return settings; + } + + + /** + * @return the Island World Manager + */ + public IslandWorld getIslandWorldManager() { + return islandWorldManager; + } + } diff --git a/src/main/java/us/tastybento/bskyblock/Constants.java b/src/main/java/us/tastybento/bskyblock/Constants.java new file mode 100644 index 000000000..4d98c9e6a --- /dev/null +++ b/src/main/java/us/tastybento/bskyblock/Constants.java @@ -0,0 +1,38 @@ +package us.tastybento.bskyblock; + +import us.tastybento.bskyblock.api.configuration.ConfigEntry.GameType; + +/** + * All the plugin settings are here + * @author Tastybento + */ +public class Constants { + // ----------------- Constants ----------------- + + /* + public final static GameType GAMETYPE = GameType.ACIDISLAND; + // The spawn command (Essentials spawn for example) + public final static String SPAWNCOMMAND = "spawn"; + // Permission prefix + public final static String PERMPREFIX = "acidisland."; + // The island command + public final static String ISLANDCOMMAND = "ai"; + // The challenge command + public static final String CHALLENGECOMMAND = "aic"; + // Admin command + public static final String ADMINCOMMAND = "acid"; + */ + public final static GameType GAMETYPE = GameType.BSKYBLOCK; + // Permission prefix + public final static String PERMPREFIX = "bskyblock."; + // The island command + public final static String ISLANDCOMMAND = "island"; + // The challenge command + public static final String CHALLENGECOMMAND = "bsc"; + // The spawn command (Essentials spawn for example) + public final static String SPAWNCOMMAND = "spawn"; + // Admin command + public static final String ADMINCOMMAND = "bsadmin"; + + +} \ No newline at end of file diff --git a/src/main/java/us/tastybento/bskyblock/EnumAdapter.java b/src/main/java/us/tastybento/bskyblock/EnumAdapter.java deleted file mode 100644 index 5b31c39be..000000000 --- a/src/main/java/us/tastybento/bskyblock/EnumAdapter.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * - */ -package us.tastybento.bskyblock; - -import org.bukkit.Bukkit; - -/** - * @author ben - * Takes in inputs and turns them into an enum - */ -public class EnumAdapter { - - /** - * Takes in inputs and turns them into an enum of type - * @param input - * @param type - * @return - */ - public Object adapt(Object input, Object type) { - Bukkit.getLogger().info("Ran the EnumAdapter: input is " + input + " and type = " + type); - return Enum.valueOf((Class)type, (String)input); - } - -} diff --git a/src/main/java/us/tastybento/bskyblock/Settings.java b/src/main/java/us/tastybento/bskyblock/Settings.java index e01644712..3483068c9 100644 --- a/src/main/java/us/tastybento/bskyblock/Settings.java +++ b/src/main/java/us/tastybento/bskyblock/Settings.java @@ -12,199 +12,176 @@ import org.bukkit.potion.PotionEffectType; import us.tastybento.bskyblock.api.configuration.ConfigEntry; import us.tastybento.bskyblock.api.configuration.ConfigEntry.GameType; import us.tastybento.bskyblock.api.configuration.ISettings; +import us.tastybento.bskyblock.api.configuration.PotionEffectListAdpater; import us.tastybento.bskyblock.api.flags.Flag; +import us.tastybento.bskyblock.config.StoreAt; import us.tastybento.bskyblock.database.BSBDatabase.DatabaseType; /** * All the plugin settings are here * @author Tastybento */ -public class Settings implements ISettings { - // ----------------- Constants ----------------- - - /* - public final static GameType GAMETYPE = GameType.ACIDISLAND; - // The spawn command (Essentials spawn for example) - public final static String SPAWNCOMMAND = "spawn"; - // Permission prefix - public final static String PERMPREFIX = "acidisland."; - // The island command - public final static String ISLANDCOMMAND = "ai"; - // The challenge command - public static final String CHALLENGECOMMAND = "aic"; - // Admin command - public static final String ADMINCOMMAND = "acid"; - */ - public final static GameType GAMETYPE = GameType.BSKYBLOCK; - // Permission prefix - public final static String PERMPREFIX = "bskyblock."; - // The island command - public final static String ISLANDCOMMAND = "island"; - // The challenge command - public static final String CHALLENGECOMMAND = "bsc"; - // The spawn command (Essentials spawn for example) - public final static String SPAWNCOMMAND = "spawn"; - // Admin command - public static final String ADMINCOMMAND = "bsadmin"; - +@StoreAt(filename="config.yml") // Explicitly call out what name this should have. +public class Settings implements ISettings { + // --------------------------------------------- /* GENERAL */ @ConfigEntry(path = "general.check-updates") - public static boolean checkUpdates = true; + private boolean checkUpdates = true; @ConfigEntry(path = "general.default-language") - public static String defaultLanguage = "en-US"; + private String defaultLanguage = "en-US"; @ConfigEntry(path = "general.use-economy") - public static boolean useEconomy = true; + private boolean useEconomy = true; // Purge @ConfigEntry(path = "general.purge.max-island-level") - public static int purgeMaxIslandLevel = 50; + private int purgeMaxIslandLevel = 50; @ConfigEntry(path = "general.purge.remove-user-data") - public static boolean purgeRemoveUserData = false; + private boolean purgeRemoveUserData = false; // Database - @ConfigEntry(path = "general.database.type", adapter = EnumAdapter.class) - public static DatabaseType databaseType = DatabaseType.FLATFILE; + @ConfigEntry(path = "general.database.type") + private DatabaseType databaseType = DatabaseType.FLATFILE; @ConfigEntry(path = "general.database.host") - public static String dbHost = "localhost"; + private String dbHost = "localhost"; @ConfigEntry(path = "general.database.port") - public static int dbPort = 3306; + private int dbPort = 3306; @ConfigEntry(path = "general.database.name") - public static String dbName = "BSkyBlock"; + private String dbName = "BSkyBlock"; @ConfigEntry(path = "general.database.username") - public static String dbUsername = "username"; + private String dbUsername = "username"; @ConfigEntry(path = "general.database.password") - public static String dbPassword = "password"; + private String dbPassword = "password"; @ConfigEntry(path = "general.database.backup-period") - public static int databaseBackupPeriod = 5; + private int databaseBackupPeriod = 5; //TODO change allowAutoActivator to the fakePlayers introduced in ASB 3.0.8 @ConfigEntry(path = "general.allow-FTB-auto-activators") - public static boolean allowAutoActivator = false; + private boolean allowAutoActivator = false; @ConfigEntry(path = "general.allow-obsidian-scooping") - public static boolean allowObsidianScooping = true; + private boolean allowObsidianScooping = true; // --------------------------------------------- /* WORLD */ @ConfigEntry(path = "world.world-name", needsReset = true) - public static String worldName = "BSkyBlock"; + private String worldName = "BSkyBlock"; @ConfigEntry(path = "world.distance-between-islands", needsReset = true) - public static int islandDistance = 200; + private int islandDistance = 200; @ConfigEntry(path = "world.protection-range", overrideOnChange = true) - public static int islandProtectionRange = 100; + private int islandProtectionRange = 100; @ConfigEntry(path = "world.start-x", needsReset = true) - public static int islandStartX = 0; + private int islandStartX = 0; @ConfigEntry(path = "world.start-z", needsReset = true) - public static int islandStartZ = 0; + private int islandStartZ = 0; - public static int islandXOffset; - public static int islandZOffset; + private int islandXOffset; + private int islandZOffset; @ConfigEntry(path = "world.sea-height", specificTo = GameType.ACIDISLAND) - public static int seaHeight = 100; + private int seaHeight = 100; @ConfigEntry(path = "world.island-height") - public static int islandHeight = 100; + private int islandHeight = 100; @ConfigEntry(path = "world.max-islands") - public static int maxIslands = -1; + private int maxIslands = -1; // Nether @ConfigEntry(path = "world.nether.generate") - public static boolean netherGenerate = true; + private boolean netherGenerate = true; @ConfigEntry(path = "world.nether.islands", needsReset = true) - public static boolean netherIslands = true; + private boolean netherIslands = true; @ConfigEntry(path = "world.nether.trees") - public static boolean netherTrees = true; + private boolean netherTrees = true; @ConfigEntry(path = "world.nether.roof") - public static boolean netherRoof = true; + private boolean netherRoof = true; @ConfigEntry(path = "world.nether.spawn-radius") - public static int netherSpawnRadius = 32; + private int netherSpawnRadius = 32; // End @ConfigEntry(path = "world.end.generate") - public static boolean endGenerate = true; + private boolean endGenerate = true; @ConfigEntry(path = "world.end.islands", needsReset = true) - public static boolean endIslands = true; + private boolean endIslands = true; // Entities - public static HashMap entityLimits; - public static HashMap tileEntityLimits; + private HashMap entityLimits; + private HashMap tileEntityLimits; // --------------------------------------------- /* ISLAND */ - public static int maxTeamSize; - public static int maxHomes; - public static int nameMinLength; - public static int nameMaxLength; - public static int inviteWait; + private int maxTeamSize; + private int maxHomes; + private int nameMinLength; + private int nameMaxLength; + private int inviteWait; // Reset - public static int resetLimit; - public static int resetWait; - public static boolean leaversLoseReset; - public static boolean kickedKeepInventory; + private int resetLimit; + private int resetWait; + private boolean leaversLoseReset; + private boolean kickedKeepInventory; // Remove mobs - public static boolean removeMobsOnLogin; - public static boolean removeMobsOnIsland; - public static List removeMobsWhitelist; + private boolean removeMobsOnLogin; + private boolean removeMobsOnIsland; + private List removeMobsWhitelist; - public static boolean makeIslandIfNone; - public static boolean immediateTeleportOnIsland; - public static boolean respawnOnIsland; + private boolean makeIslandIfNone; + private boolean immediateTeleportOnIsland; + private boolean respawnOnIsland; // Deaths @ConfigEntry(path = "island.deaths.max") - public static int deathsMax = 10; + private int deathsMax = 10; @ConfigEntry(path = "island.deaths.sum-team") - public static boolean deathsSumTeam = false; + private boolean deathsSumTeam = false; // --------------------------------------------- /* PROTECTION */ @ConfigEntry(path = "protection.allow-piston-push") - public static boolean allowPistonPush = false; + private boolean allowPistonPush = false; @ConfigEntry(path = "protection.restrict-flying-mobs") - public static boolean restrictFlyingMobs = true; + private boolean restrictFlyingMobs = true; - public static int togglePvPCooldown; + private int togglePvPCooldown; - public static HashMap defaultFlags; + private HashMap defaultFlags; //TODO transform these options below into flags - public static boolean allowEndermanGriefing; - public static boolean endermanDeathDrop; - public static boolean allowTNTDamage; - public static boolean allowChestDamage; - public static boolean allowCreeperDamage; - public static boolean allowCreeperGriefing; - public static boolean allowMobDamageToItemFrames; + private boolean allowEndermanGriefing; + private boolean endermanDeathDrop; + private boolean allowTNTDamage; + private boolean allowChestDamage; + private boolean allowCreeperDamage; + private boolean allowCreeperGriefing; + private boolean allowMobDamageToItemFrames; //TODO flags @@ -217,31 +194,923 @@ public class Settings implements ISettings { */ @ConfigEntry(path = "acid.damage-op", specificTo = GameType.ACIDISLAND) - public static boolean acidDamageOp = false; + private boolean acidDamageOp = false; @ConfigEntry(path = "acid.damage-chickens", specificTo = GameType.ACIDISLAND) - public static boolean acidDamageChickens = false; + private boolean acidDamageChickens = false; @ConfigEntry(path = "acid.options.item-destroy-time", specificTo = GameType.ACIDISLAND) - public static int acidDestroyItemTime = 0; + private int acidDestroyItemTime = 0; // Damage @ConfigEntry(path = "acid.damage.acid.player", specificTo = GameType.ACIDISLAND) - public static int acidDamage = 10; + private int acidDamage = 10; @ConfigEntry(path = "acid.damage.rain", specificTo = GameType.ACIDISLAND) - public static int acidRainDamage = 1; + private int acidRainDamage = 1; - @ConfigEntry(path = "acid.damage.effects", specificTo = GameType.ACIDISLAND) - public static List acidEffects = new ArrayList<>(Arrays.asList(PotionEffectType.CONFUSION, PotionEffectType.SLOW)); + @ConfigEntry(path = "acid.damage.effects", specificTo = GameType.ACIDISLAND, adapter = PotionEffectListAdpater.class) + private List acidEffects = new ArrayList<>(Arrays.asList(PotionEffectType.CONFUSION, PotionEffectType.SLOW)); /* SCHEMATICS */ - public static List companionNames; - public static ItemStack[] chestItems; - public static EntityType companionType; + private List companionNames; + private ItemStack[] chestItems; + private EntityType companionType; - public static boolean useOwnGenerator; + private boolean useOwnGenerator; + + private HashMap limitedBlocks; + private boolean teamJoinDeathReset; + + private String uniqueId; + + /** + * @return the uniqueId + */ + public String getUniqueId() { + return uniqueId; + } + /** + * @param uniqueId the uniqueId to set + */ + public void setUniqueId(String uniqueId) { + this.uniqueId = uniqueId; + } + /** + * @return the checkUpdates + */ + public boolean isCheckUpdates() { + return checkUpdates; + } + /** + * @param checkUpdates the checkUpdates to set + */ + public void setCheckUpdates(boolean checkUpdates) { + this.checkUpdates = checkUpdates; + } + /** + * @return the defaultLanguage + */ + public String getDefaultLanguage() { + return defaultLanguage; + } + /** + * @param defaultLanguage the defaultLanguage to set + */ + public void setDefaultLanguage(String defaultLanguage) { + this.defaultLanguage = defaultLanguage; + } + /** + * @return the useEconomy + */ + public boolean isUseEconomy() { + return useEconomy; + } + /** + * @param useEconomy the useEconomy to set + */ + public void setUseEconomy(boolean useEconomy) { + this.useEconomy = useEconomy; + } + /** + * @return the purgeMaxIslandLevel + */ + public int getPurgeMaxIslandLevel() { + return purgeMaxIslandLevel; + } + /** + * @param purgeMaxIslandLevel the purgeMaxIslandLevel to set + */ + public void setPurgeMaxIslandLevel(int purgeMaxIslandLevel) { + this.purgeMaxIslandLevel = purgeMaxIslandLevel; + } + /** + * @return the purgeRemoveUserData + */ + public boolean isPurgeRemoveUserData() { + return purgeRemoveUserData; + } + /** + * @param purgeRemoveUserData the purgeRemoveUserData to set + */ + public void setPurgeRemoveUserData(boolean purgeRemoveUserData) { + this.purgeRemoveUserData = purgeRemoveUserData; + } + /** + * @return the databaseType + */ + public DatabaseType getDatabaseType() { + return databaseType; + } + /** + * @param databaseType the databaseType to set + */ + public void setDatabaseType(DatabaseType databaseType) { + this.databaseType = databaseType; + } + /** + * @return the dbHost + */ + public String getDbHost() { + return dbHost; + } + /** + * @param dbHost the dbHost to set + */ + public void setDbHost(String dbHost) { + this.dbHost = dbHost; + } + /** + * @return the dbPort + */ + public int getDbPort() { + return dbPort; + } + /** + * @param dbPort the dbPort to set + */ + public void setDbPort(int dbPort) { + this.dbPort = dbPort; + } + /** + * @return the dbName + */ + public String getDbName() { + return dbName; + } + /** + * @param dbName the dbName to set + */ + public void setDbName(String dbName) { + this.dbName = dbName; + } + /** + * @return the dbUsername + */ + public String getDbUsername() { + return dbUsername; + } + /** + * @param dbUsername the dbUsername to set + */ + public void setDbUsername(String dbUsername) { + this.dbUsername = dbUsername; + } + /** + * @return the dbPassword + */ + public String getDbPassword() { + return dbPassword; + } + /** + * @param dbPassword the dbPassword to set + */ + public void setDbPassword(String dbPassword) { + this.dbPassword = dbPassword; + } + /** + * @return the databaseBackupPeriod + */ + public int getDatabaseBackupPeriod() { + return databaseBackupPeriod; + } + /** + * @param databaseBackupPeriod the databaseBackupPeriod to set + */ + public void setDatabaseBackupPeriod(int databaseBackupPeriod) { + this.databaseBackupPeriod = databaseBackupPeriod; + } + /** + * @return the allowAutoActivator + */ + public boolean isAllowAutoActivator() { + return allowAutoActivator; + } + /** + * @param allowAutoActivator the allowAutoActivator to set + */ + public void setAllowAutoActivator(boolean allowAutoActivator) { + this.allowAutoActivator = allowAutoActivator; + } + /** + * @return the allowObsidianScooping + */ + public boolean isAllowObsidianScooping() { + return allowObsidianScooping; + } + /** + * @param allowObsidianScooping the allowObsidianScooping to set + */ + public void setAllowObsidianScooping(boolean allowObsidianScooping) { + this.allowObsidianScooping = allowObsidianScooping; + } + /** + * @return the worldName + */ + public String getWorldName() { + return worldName; + } + /** + * @param worldName the worldName to set + */ + public void setWorldName(String worldName) { + this.worldName = worldName; + } + /** + * @return the islandDistance + */ + public int getIslandDistance() { + return islandDistance; + } + /** + * @param islandDistance the islandDistance to set + */ + public void setIslandDistance(int islandDistance) { + this.islandDistance = islandDistance; + } + /** + * @return the islandProtectionRange + */ + public int getIslandProtectionRange() { + return islandProtectionRange; + } + /** + * @param islandProtectionRange the islandProtectionRange to set + */ + public void setIslandProtectionRange(int islandProtectionRange) { + this.islandProtectionRange = islandProtectionRange; + } + /** + * @return the islandStartX + */ + public int getIslandStartX() { + return islandStartX; + } + /** + * @param islandStartX the islandStartX to set + */ + public void setIslandStartX(int islandStartX) { + this.islandStartX = islandStartX; + } + /** + * @return the islandStartZ + */ + public int getIslandStartZ() { + return islandStartZ; + } + /** + * @param islandStartZ the islandStartZ to set + */ + public void setIslandStartZ(int islandStartZ) { + this.islandStartZ = islandStartZ; + } + /** + * @return the islandXOffset + */ + public int getIslandXOffset() { + return islandXOffset; + } + /** + * @param islandXOffset the islandXOffset to set + */ + public void setIslandXOffset(int islandXOffset) { + this.islandXOffset = islandXOffset; + } + /** + * @return the islandZOffset + */ + public int getIslandZOffset() { + return islandZOffset; + } + /** + * @param islandZOffset the islandZOffset to set + */ + public void setIslandZOffset(int islandZOffset) { + this.islandZOffset = islandZOffset; + } + /** + * @return the seaHeight + */ + public int getSeaHeight() { + return seaHeight; + } + /** + * @param seaHeight the seaHeight to set + */ + public void setSeaHeight(int seaHeight) { + this.seaHeight = seaHeight; + } + /** + * @return the islandHeight + */ + public int getIslandHeight() { + return islandHeight; + } + /** + * @param islandHeight the islandHeight to set + */ + public void setIslandHeight(int islandHeight) { + this.islandHeight = islandHeight; + } + /** + * @return the maxIslands + */ + public int getMaxIslands() { + return maxIslands; + } + /** + * @param maxIslands the maxIslands to set + */ + public void setMaxIslands(int maxIslands) { + this.maxIslands = maxIslands; + } + /** + * @return the netherGenerate + */ + public boolean isNetherGenerate() { + return netherGenerate; + } + /** + * @param netherGenerate the netherGenerate to set + */ + public void setNetherGenerate(boolean netherGenerate) { + this.netherGenerate = netherGenerate; + } + /** + * @return the netherIslands + */ + public boolean isNetherIslands() { + return netherIslands; + } + /** + * @param netherIslands the netherIslands to set + */ + public void setNetherIslands(boolean netherIslands) { + this.netherIslands = netherIslands; + } + /** + * @return the netherTrees + */ + public boolean isNetherTrees() { + return netherTrees; + } + /** + * @param netherTrees the netherTrees to set + */ + public void setNetherTrees(boolean netherTrees) { + this.netherTrees = netherTrees; + } + /** + * @return the netherRoof + */ + public boolean isNetherRoof() { + return netherRoof; + } + /** + * @param netherRoof the netherRoof to set + */ + public void setNetherRoof(boolean netherRoof) { + this.netherRoof = netherRoof; + } + /** + * @return the netherSpawnRadius + */ + public int getNetherSpawnRadius() { + return netherSpawnRadius; + } + /** + * @param netherSpawnRadius the netherSpawnRadius to set + */ + public void setNetherSpawnRadius(int netherSpawnRadius) { + this.netherSpawnRadius = netherSpawnRadius; + } + /** + * @return the endGenerate + */ + public boolean isEndGenerate() { + return endGenerate; + } + /** + * @param endGenerate the endGenerate to set + */ + public void setEndGenerate(boolean endGenerate) { + this.endGenerate = endGenerate; + } + /** + * @return the endIslands + */ + public boolean isEndIslands() { + return endIslands; + } + /** + * @param endIslands the endIslands to set + */ + public void setEndIslands(boolean endIslands) { + this.endIslands = endIslands; + } + /** + * @return the entityLimits + */ + public HashMap getEntityLimits() { + return entityLimits; + } + /** + * @param entityLimits the entityLimits to set + */ + public void setEntityLimits(HashMap entityLimits) { + this.entityLimits = entityLimits; + } + /** + * @return the tileEntityLimits + */ + public HashMap getTileEntityLimits() { + return tileEntityLimits; + } + /** + * @param tileEntityLimits the tileEntityLimits to set + */ + public void setTileEntityLimits(HashMap tileEntityLimits) { + this.tileEntityLimits = tileEntityLimits; + } + /** + * @return the maxTeamSize + */ + public int getMaxTeamSize() { + return maxTeamSize; + } + /** + * @param maxTeamSize the maxTeamSize to set + */ + public void setMaxTeamSize(int maxTeamSize) { + this.maxTeamSize = maxTeamSize; + } + /** + * @return the maxHomes + */ + public int getMaxHomes() { + return maxHomes; + } + /** + * @param maxHomes the maxHomes to set + */ + public void setMaxHomes(int maxHomes) { + this.maxHomes = maxHomes; + } + /** + * @return the nameMinLength + */ + public int getNameMinLength() { + return nameMinLength; + } + /** + * @param nameMinLength the nameMinLength to set + */ + public void setNameMinLength(int nameMinLength) { + this.nameMinLength = nameMinLength; + } + /** + * @return the nameMaxLength + */ + public int getNameMaxLength() { + return nameMaxLength; + } + /** + * @param nameMaxLength the nameMaxLength to set + */ + public void setNameMaxLength(int nameMaxLength) { + this.nameMaxLength = nameMaxLength; + } + /** + * @return the inviteWait + */ + public int getInviteWait() { + return inviteWait; + } + /** + * @param inviteWait the inviteWait to set + */ + public void setInviteWait(int inviteWait) { + this.inviteWait = inviteWait; + } + /** + * @return the resetLimit + */ + public int getResetLimit() { + return resetLimit; + } + /** + * @param resetLimit the resetLimit to set + */ + public void setResetLimit(int resetLimit) { + this.resetLimit = resetLimit; + } + /** + * @return the resetWait + */ + public int getResetWait() { + return resetWait; + } + /** + * @param resetWait the resetWait to set + */ + public void setResetWait(int resetWait) { + this.resetWait = resetWait; + } + /** + * @return the leaversLoseReset + */ + public boolean isLeaversLoseReset() { + return leaversLoseReset; + } + /** + * @param leaversLoseReset the leaversLoseReset to set + */ + public void setLeaversLoseReset(boolean leaversLoseReset) { + this.leaversLoseReset = leaversLoseReset; + } + /** + * @return the kickedKeepInventory + */ + public boolean isKickedKeepInventory() { + return kickedKeepInventory; + } + /** + * @param kickedKeepInventory the kickedKeepInventory to set + */ + public void setKickedKeepInventory(boolean kickedKeepInventory) { + this.kickedKeepInventory = kickedKeepInventory; + } + /** + * @return the removeMobsOnLogin + */ + public boolean isRemoveMobsOnLogin() { + return removeMobsOnLogin; + } + /** + * @param removeMobsOnLogin the removeMobsOnLogin to set + */ + public void setRemoveMobsOnLogin(boolean removeMobsOnLogin) { + this.removeMobsOnLogin = removeMobsOnLogin; + } + /** + * @return the removeMobsOnIsland + */ + public boolean isRemoveMobsOnIsland() { + return removeMobsOnIsland; + } + /** + * @param removeMobsOnIsland the removeMobsOnIsland to set + */ + public void setRemoveMobsOnIsland(boolean removeMobsOnIsland) { + this.removeMobsOnIsland = removeMobsOnIsland; + } + /** + * @return the removeMobsWhitelist + */ + public List getRemoveMobsWhitelist() { + return removeMobsWhitelist; + } + /** + * @param removeMobsWhitelist the removeMobsWhitelist to set + */ + public void setRemoveMobsWhitelist(List removeMobsWhitelist) { + this.removeMobsWhitelist = removeMobsWhitelist; + } + /** + * @return the makeIslandIfNone + */ + public boolean isMakeIslandIfNone() { + return makeIslandIfNone; + } + /** + * @param makeIslandIfNone the makeIslandIfNone to set + */ + public void setMakeIslandIfNone(boolean makeIslandIfNone) { + this.makeIslandIfNone = makeIslandIfNone; + } + /** + * @return the immediateTeleportOnIsland + */ + public boolean isImmediateTeleportOnIsland() { + return immediateTeleportOnIsland; + } + /** + * @param immediateTeleportOnIsland the immediateTeleportOnIsland to set + */ + public void setImmediateTeleportOnIsland(boolean immediateTeleportOnIsland) { + this.immediateTeleportOnIsland = immediateTeleportOnIsland; + } + /** + * @return the respawnOnIsland + */ + public boolean isRespawnOnIsland() { + return respawnOnIsland; + } + /** + * @param respawnOnIsland the respawnOnIsland to set + */ + public void setRespawnOnIsland(boolean respawnOnIsland) { + this.respawnOnIsland = respawnOnIsland; + } + /** + * @return the deathsMax + */ + public int getDeathsMax() { + return deathsMax; + } + /** + * @param deathsMax the deathsMax to set + */ + public void setDeathsMax(int deathsMax) { + this.deathsMax = deathsMax; + } + /** + * @return the deathsSumTeam + */ + public boolean isDeathsSumTeam() { + return deathsSumTeam; + } + /** + * @param deathsSumTeam the deathsSumTeam to set + */ + public void setDeathsSumTeam(boolean deathsSumTeam) { + this.deathsSumTeam = deathsSumTeam; + } + /** + * @return the allowPistonPush + */ + public boolean isAllowPistonPush() { + return allowPistonPush; + } + /** + * @param allowPistonPush the allowPistonPush to set + */ + public void setAllowPistonPush(boolean allowPistonPush) { + this.allowPistonPush = allowPistonPush; + } + /** + * @return the restrictFlyingMobs + */ + public boolean isRestrictFlyingMobs() { + return restrictFlyingMobs; + } + /** + * @param restrictFlyingMobs the restrictFlyingMobs to set + */ + public void setRestrictFlyingMobs(boolean restrictFlyingMobs) { + this.restrictFlyingMobs = restrictFlyingMobs; + } + /** + * @return the togglePvPCooldown + */ + public int getTogglePvPCooldown() { + return togglePvPCooldown; + } + /** + * @param togglePvPCooldown the togglePvPCooldown to set + */ + public void setTogglePvPCooldown(int togglePvPCooldown) { + this.togglePvPCooldown = togglePvPCooldown; + } + /** + * @return the defaultFlags + */ + public HashMap getDefaultFlags() { + return defaultFlags; + } + /** + * @param defaultFlags the defaultFlags to set + */ + public void setDefaultFlags(HashMap defaultFlags) { + this.defaultFlags = defaultFlags; + } + /** + * @return the allowEndermanGriefing + */ + public boolean isAllowEndermanGriefing() { + return allowEndermanGriefing; + } + /** + * @param allowEndermanGriefing the allowEndermanGriefing to set + */ + public void setAllowEndermanGriefing(boolean allowEndermanGriefing) { + this.allowEndermanGriefing = allowEndermanGriefing; + } + /** + * @return the endermanDeathDrop + */ + public boolean isEndermanDeathDrop() { + return endermanDeathDrop; + } + /** + * @param endermanDeathDrop the endermanDeathDrop to set + */ + public void setEndermanDeathDrop(boolean endermanDeathDrop) { + this.endermanDeathDrop = endermanDeathDrop; + } + /** + * @return the allowTNTDamage + */ + public boolean isAllowTNTDamage() { + return allowTNTDamage; + } + /** + * @param allowTNTDamage the allowTNTDamage to set + */ + public void setAllowTNTDamage(boolean allowTNTDamage) { + this.allowTNTDamage = allowTNTDamage; + } + /** + * @return the allowChestDamage + */ + public boolean isAllowChestDamage() { + return allowChestDamage; + } + /** + * @param allowChestDamage the allowChestDamage to set + */ + public void setAllowChestDamage(boolean allowChestDamage) { + this.allowChestDamage = allowChestDamage; + } + /** + * @return the allowCreeperDamage + */ + public boolean isAllowCreeperDamage() { + return allowCreeperDamage; + } + /** + * @param allowCreeperDamage the allowCreeperDamage to set + */ + public void setAllowCreeperDamage(boolean allowCreeperDamage) { + this.allowCreeperDamage = allowCreeperDamage; + } + /** + * @return the allowCreeperGriefing + */ + public boolean isAllowCreeperGriefing() { + return allowCreeperGriefing; + } + /** + * @param allowCreeperGriefing the allowCreeperGriefing to set + */ + public void setAllowCreeperGriefing(boolean allowCreeperGriefing) { + this.allowCreeperGriefing = allowCreeperGriefing; + } + /** + * @return the allowMobDamageToItemFrames + */ + public boolean isAllowMobDamageToItemFrames() { + return allowMobDamageToItemFrames; + } + /** + * @param allowMobDamageToItemFrames the allowMobDamageToItemFrames to set + */ + public void setAllowMobDamageToItemFrames(boolean allowMobDamageToItemFrames) { + this.allowMobDamageToItemFrames = allowMobDamageToItemFrames; + } + /** + * @return the acidDamageOp + */ + public boolean isAcidDamageOp() { + return acidDamageOp; + } + /** + * @param acidDamageOp the acidDamageOp to set + */ + public void setAcidDamageOp(boolean acidDamageOp) { + this.acidDamageOp = acidDamageOp; + } + /** + * @return the acidDamageChickens + */ + public boolean isAcidDamageChickens() { + return acidDamageChickens; + } + /** + * @param acidDamageChickens the acidDamageChickens to set + */ + public void setAcidDamageChickens(boolean acidDamageChickens) { + this.acidDamageChickens = acidDamageChickens; + } + /** + * @return the acidDestroyItemTime + */ + public int getAcidDestroyItemTime() { + return acidDestroyItemTime; + } + /** + * @param acidDestroyItemTime the acidDestroyItemTime to set + */ + public void setAcidDestroyItemTime(int acidDestroyItemTime) { + this.acidDestroyItemTime = acidDestroyItemTime; + } + /** + * @return the acidDamage + */ + public int getAcidDamage() { + return acidDamage; + } + /** + * @param acidDamage the acidDamage to set + */ + public void setAcidDamage(int acidDamage) { + this.acidDamage = acidDamage; + } + /** + * @return the acidRainDamage + */ + public int getAcidRainDamage() { + return acidRainDamage; + } + /** + * @param acidRainDamage the acidRainDamage to set + */ + public void setAcidRainDamage(int acidRainDamage) { + this.acidRainDamage = acidRainDamage; + } + /** + * @return the acidEffects + */ + public List getAcidEffects() { + return acidEffects; + } + /** + * @param acidEffects the acidEffects to set + */ + public void setAcidEffects(List acidEffects) { + this.acidEffects = acidEffects; + } + /** + * @return the companionNames + */ + public List getCompanionNames() { + return companionNames; + } + /** + * @param companionNames the companionNames to set + */ + public void setCompanionNames(List companionNames) { + this.companionNames = companionNames; + } + /** + * @return the chestItems + */ + public ItemStack[] getChestItems() { + return chestItems; + } + /** + * @param chestItems the chestItems to set + */ + public void setChestItems(ItemStack[] chestItems) { + this.chestItems = chestItems; + } + /** + * @return the companionType + */ + public EntityType getCompanionType() { + return companionType; + } + /** + * @param companionType the companionType to set + */ + public void setCompanionType(EntityType companionType) { + this.companionType = companionType; + } + /** + * @return the useOwnGenerator + */ + public boolean isUseOwnGenerator() { + return useOwnGenerator; + } + /** + * @param useOwnGenerator the useOwnGenerator to set + */ + public void setUseOwnGenerator(boolean useOwnGenerator) { + this.useOwnGenerator = useOwnGenerator; + } + /** + * @return the limitedBlocks + */ + public HashMap getLimitedBlocks() { + return limitedBlocks; + } + /** + * @param limitedBlocks the limitedBlocks to set + */ + public void setLimitedBlocks(HashMap limitedBlocks) { + this.limitedBlocks = limitedBlocks; + } + /** + * @return the teamJoinDeathReset + */ + public boolean isTeamJoinDeathReset() { + return teamJoinDeathReset; + } + /** + * @param teamJoinDeathReset the teamJoinDeathReset to set + */ + public void setTeamJoinDeathReset(boolean teamJoinDeathReset) { + this.teamJoinDeathReset = teamJoinDeathReset; + } - public static HashMap limitedBlocks; - public static boolean teamJoinDeathReset; } \ No newline at end of file diff --git a/src/main/java/us/tastybento/bskyblock/Settings2.java b/src/main/java/us/tastybento/bskyblock/Settings2.java deleted file mode 100644 index 0d2b4978e..000000000 --- a/src/main/java/us/tastybento/bskyblock/Settings2.java +++ /dev/null @@ -1,1115 +0,0 @@ -package us.tastybento.bskyblock; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; - -import org.bukkit.entity.EntityType; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffectType; - -import us.tastybento.bskyblock.api.configuration.ConfigEntry; -import us.tastybento.bskyblock.api.configuration.ConfigEntry.GameType; -import us.tastybento.bskyblock.api.configuration.ISettings; -import us.tastybento.bskyblock.api.flags.Flag; -import us.tastybento.bskyblock.config.StoreAt; -import us.tastybento.bskyblock.database.BSBDatabase.DatabaseType; - -/** - * All the plugin settings are here - * @author Tastybento - */ -@StoreAt(filename="config.yml") // Explicitly call out what name this should have. -public class Settings2 implements ISettings { - - // --------------------------------------------- - - /* GENERAL */ - - @ConfigEntry(path = "general.check-updates") - private boolean checkUpdates = true; - - @ConfigEntry(path = "general.default-language") - private String defaultLanguage = "en-US"; - - @ConfigEntry(path = "general.use-economy") - private boolean useEconomy = true; - - // Purge - @ConfigEntry(path = "general.purge.max-island-level") - private int purgeMaxIslandLevel = 50; - - @ConfigEntry(path = "general.purge.remove-user-data") - private boolean purgeRemoveUserData = false; - - // Database - @ConfigEntry(path = "general.database.type") - private DatabaseType databaseType = DatabaseType.FLATFILE; - - @ConfigEntry(path = "general.database.host") - private String dbHost = "localhost"; - - @ConfigEntry(path = "general.database.port") - private int dbPort = 3306; - - @ConfigEntry(path = "general.database.name") - private String dbName = "BSkyBlock"; - - @ConfigEntry(path = "general.database.username") - private String dbUsername = "username"; - - @ConfigEntry(path = "general.database.password") - private String dbPassword = "password"; - - @ConfigEntry(path = "general.database.backup-period") - private int databaseBackupPeriod = 5; - - //TODO change allowAutoActivator to the fakePlayers introduced in ASB 3.0.8 - @ConfigEntry(path = "general.allow-FTB-auto-activators") - private boolean allowAutoActivator = false; - - @ConfigEntry(path = "general.allow-obsidian-scooping") - private boolean allowObsidianScooping = true; - - // --------------------------------------------- - - /* WORLD */ - @ConfigEntry(path = "world.world-name", needsReset = true) - private String worldName = "BSkyBlock"; - - @ConfigEntry(path = "world.distance-between-islands", needsReset = true) - private int islandDistance = 200; - - @ConfigEntry(path = "world.protection-range", overrideOnChange = true) - private int islandProtectionRange = 100; - - @ConfigEntry(path = "world.start-x", needsReset = true) - private int islandStartX = 0; - - @ConfigEntry(path = "world.start-z", needsReset = true) - private int islandStartZ = 0; - - private int islandXOffset; - private int islandZOffset; - - @ConfigEntry(path = "world.sea-height", specificTo = GameType.ACIDISLAND) - private int seaHeight = 100; - - @ConfigEntry(path = "world.island-height") - private int islandHeight = 100; - - @ConfigEntry(path = "world.max-islands") - private int maxIslands = -1; - - // Nether - @ConfigEntry(path = "world.nether.generate") - private boolean netherGenerate = true; - - @ConfigEntry(path = "world.nether.islands", needsReset = true) - private boolean netherIslands = true; - - @ConfigEntry(path = "world.nether.trees") - private boolean netherTrees = true; - - @ConfigEntry(path = "world.nether.roof") - private boolean netherRoof = true; - - @ConfigEntry(path = "world.nether.spawn-radius") - private int netherSpawnRadius = 32; - - // End - @ConfigEntry(path = "world.end.generate") - private boolean endGenerate = true; - - @ConfigEntry(path = "world.end.islands", needsReset = true) - private boolean endIslands = true; - - // Entities - private HashMap entityLimits; - private HashMap tileEntityLimits; - - // --------------------------------------------- - - /* ISLAND */ - private int maxTeamSize; - private int maxHomes; - private int nameMinLength; - private int nameMaxLength; - private int inviteWait; - - // Reset - private int resetLimit; - private int resetWait; - private boolean leaversLoseReset; - private boolean kickedKeepInventory; - - // Remove mobs - private boolean removeMobsOnLogin; - private boolean removeMobsOnIsland; - private List removeMobsWhitelist; - - private boolean makeIslandIfNone; - private boolean immediateTeleportOnIsland; - private boolean respawnOnIsland; - - // Deaths - @ConfigEntry(path = "island.deaths.max") - private int deathsMax = 10; - - @ConfigEntry(path = "island.deaths.sum-team") - private boolean deathsSumTeam = false; - - // --------------------------------------------- - - /* PROTECTION */ - @ConfigEntry(path = "protection.allow-piston-push") - private boolean allowPistonPush = false; - - @ConfigEntry(path = "protection.restrict-flying-mobs") - private boolean restrictFlyingMobs = true; - - private int togglePvPCooldown; - - private HashMap defaultFlags; - - //TODO transform these options below into flags - private boolean allowEndermanGriefing; - private boolean endermanDeathDrop; - private boolean allowTNTDamage; - private boolean allowChestDamage; - private boolean allowCreeperDamage; - private boolean allowCreeperGriefing; - private boolean allowMobDamageToItemFrames; - - //TODO flags - - // --------------------------------------------- - - /* ACID */ - - /* - * This settings category only exists if the GameType is ACIDISLAND. - */ - - @ConfigEntry(path = "acid.damage-op", specificTo = GameType.ACIDISLAND) - private boolean acidDamageOp = false; - - @ConfigEntry(path = "acid.damage-chickens", specificTo = GameType.ACIDISLAND) - private boolean acidDamageChickens = false; - - @ConfigEntry(path = "acid.options.item-destroy-time", specificTo = GameType.ACIDISLAND) - private int acidDestroyItemTime = 0; - - // Damage - @ConfigEntry(path = "acid.damage.acid.player", specificTo = GameType.ACIDISLAND) - private int acidDamage = 10; - - @ConfigEntry(path = "acid.damage.rain", specificTo = GameType.ACIDISLAND) - private int acidRainDamage = 1; - - @ConfigEntry(path = "acid.damage.effects", specificTo = GameType.ACIDISLAND) - private List acidEffects = new ArrayList<>(Arrays.asList(PotionEffectType.CONFUSION, PotionEffectType.SLOW)); - - /* SCHEMATICS */ - private List companionNames; - private ItemStack[] chestItems; - private EntityType companionType; - - private boolean useOwnGenerator; - - private HashMap limitedBlocks; - private boolean teamJoinDeathReset; - - private String uniqueId; - - /** - * @return the uniqueId - */ - public String getUniqueId() { - return uniqueId; - } - /** - * @param uniqueId the uniqueId to set - */ - public void setUniqueId(String uniqueId) { - this.uniqueId = uniqueId; - } - /** - * @return the checkUpdates - */ - public boolean isCheckUpdates() { - return checkUpdates; - } - /** - * @param checkUpdates the checkUpdates to set - */ - public void setCheckUpdates(boolean checkUpdates) { - this.checkUpdates = checkUpdates; - } - /** - * @return the defaultLanguage - */ - public String getDefaultLanguage() { - return defaultLanguage; - } - /** - * @param defaultLanguage the defaultLanguage to set - */ - public void setDefaultLanguage(String defaultLanguage) { - this.defaultLanguage = defaultLanguage; - } - /** - * @return the useEconomy - */ - public boolean isUseEconomy() { - return useEconomy; - } - /** - * @param useEconomy the useEconomy to set - */ - public void setUseEconomy(boolean useEconomy) { - this.useEconomy = useEconomy; - } - /** - * @return the purgeMaxIslandLevel - */ - public int getPurgeMaxIslandLevel() { - return purgeMaxIslandLevel; - } - /** - * @param purgeMaxIslandLevel the purgeMaxIslandLevel to set - */ - public void setPurgeMaxIslandLevel(int purgeMaxIslandLevel) { - this.purgeMaxIslandLevel = purgeMaxIslandLevel; - } - /** - * @return the purgeRemoveUserData - */ - public boolean isPurgeRemoveUserData() { - return purgeRemoveUserData; - } - /** - * @param purgeRemoveUserData the purgeRemoveUserData to set - */ - public void setPurgeRemoveUserData(boolean purgeRemoveUserData) { - this.purgeRemoveUserData = purgeRemoveUserData; - } - /** - * @return the databaseType - */ - public DatabaseType getDatabaseType() { - return databaseType; - } - /** - * @param databaseType the databaseType to set - */ - public void setDatabaseType(DatabaseType databaseType) { - this.databaseType = databaseType; - } - /** - * @return the dbHost - */ - public String getDbHost() { - return dbHost; - } - /** - * @param dbHost the dbHost to set - */ - public void setDbHost(String dbHost) { - this.dbHost = dbHost; - } - /** - * @return the dbPort - */ - public int getDbPort() { - return dbPort; - } - /** - * @param dbPort the dbPort to set - */ - public void setDbPort(int dbPort) { - this.dbPort = dbPort; - } - /** - * @return the dbName - */ - public String getDbName() { - return dbName; - } - /** - * @param dbName the dbName to set - */ - public void setDbName(String dbName) { - this.dbName = dbName; - } - /** - * @return the dbUsername - */ - public String getDbUsername() { - return dbUsername; - } - /** - * @param dbUsername the dbUsername to set - */ - public void setDbUsername(String dbUsername) { - this.dbUsername = dbUsername; - } - /** - * @return the dbPassword - */ - public String getDbPassword() { - return dbPassword; - } - /** - * @param dbPassword the dbPassword to set - */ - public void setDbPassword(String dbPassword) { - this.dbPassword = dbPassword; - } - /** - * @return the databaseBackupPeriod - */ - public int getDatabaseBackupPeriod() { - return databaseBackupPeriod; - } - /** - * @param databaseBackupPeriod the databaseBackupPeriod to set - */ - public void setDatabaseBackupPeriod(int databaseBackupPeriod) { - this.databaseBackupPeriod = databaseBackupPeriod; - } - /** - * @return the allowAutoActivator - */ - public boolean isAllowAutoActivator() { - return allowAutoActivator; - } - /** - * @param allowAutoActivator the allowAutoActivator to set - */ - public void setAllowAutoActivator(boolean allowAutoActivator) { - this.allowAutoActivator = allowAutoActivator; - } - /** - * @return the allowObsidianScooping - */ - public boolean isAllowObsidianScooping() { - return allowObsidianScooping; - } - /** - * @param allowObsidianScooping the allowObsidianScooping to set - */ - public void setAllowObsidianScooping(boolean allowObsidianScooping) { - this.allowObsidianScooping = allowObsidianScooping; - } - /** - * @return the worldName - */ - public String getWorldName() { - return worldName; - } - /** - * @param worldName the worldName to set - */ - public void setWorldName(String worldName) { - this.worldName = worldName; - } - /** - * @return the islandDistance - */ - public int getIslandDistance() { - return islandDistance; - } - /** - * @param islandDistance the islandDistance to set - */ - public void setIslandDistance(int islandDistance) { - this.islandDistance = islandDistance; - } - /** - * @return the islandProtectionRange - */ - public int getIslandProtectionRange() { - return islandProtectionRange; - } - /** - * @param islandProtectionRange the islandProtectionRange to set - */ - public void setIslandProtectionRange(int islandProtectionRange) { - this.islandProtectionRange = islandProtectionRange; - } - /** - * @return the islandStartX - */ - public int getIslandStartX() { - return islandStartX; - } - /** - * @param islandStartX the islandStartX to set - */ - public void setIslandStartX(int islandStartX) { - this.islandStartX = islandStartX; - } - /** - * @return the islandStartZ - */ - public int getIslandStartZ() { - return islandStartZ; - } - /** - * @param islandStartZ the islandStartZ to set - */ - public void setIslandStartZ(int islandStartZ) { - this.islandStartZ = islandStartZ; - } - /** - * @return the islandXOffset - */ - public int getIslandXOffset() { - return islandXOffset; - } - /** - * @param islandXOffset the islandXOffset to set - */ - public void setIslandXOffset(int islandXOffset) { - this.islandXOffset = islandXOffset; - } - /** - * @return the islandZOffset - */ - public int getIslandZOffset() { - return islandZOffset; - } - /** - * @param islandZOffset the islandZOffset to set - */ - public void setIslandZOffset(int islandZOffset) { - this.islandZOffset = islandZOffset; - } - /** - * @return the seaHeight - */ - public int getSeaHeight() { - return seaHeight; - } - /** - * @param seaHeight the seaHeight to set - */ - public void setSeaHeight(int seaHeight) { - this.seaHeight = seaHeight; - } - /** - * @return the islandHeight - */ - public int getIslandHeight() { - return islandHeight; - } - /** - * @param islandHeight the islandHeight to set - */ - public void setIslandHeight(int islandHeight) { - this.islandHeight = islandHeight; - } - /** - * @return the maxIslands - */ - public int getMaxIslands() { - return maxIslands; - } - /** - * @param maxIslands the maxIslands to set - */ - public void setMaxIslands(int maxIslands) { - this.maxIslands = maxIslands; - } - /** - * @return the netherGenerate - */ - public boolean isNetherGenerate() { - return netherGenerate; - } - /** - * @param netherGenerate the netherGenerate to set - */ - public void setNetherGenerate(boolean netherGenerate) { - this.netherGenerate = netherGenerate; - } - /** - * @return the netherIslands - */ - public boolean isNetherIslands() { - return netherIslands; - } - /** - * @param netherIslands the netherIslands to set - */ - public void setNetherIslands(boolean netherIslands) { - this.netherIslands = netherIslands; - } - /** - * @return the netherTrees - */ - public boolean isNetherTrees() { - return netherTrees; - } - /** - * @param netherTrees the netherTrees to set - */ - public void setNetherTrees(boolean netherTrees) { - this.netherTrees = netherTrees; - } - /** - * @return the netherRoof - */ - public boolean isNetherRoof() { - return netherRoof; - } - /** - * @param netherRoof the netherRoof to set - */ - public void setNetherRoof(boolean netherRoof) { - this.netherRoof = netherRoof; - } - /** - * @return the netherSpawnRadius - */ - public int getNetherSpawnRadius() { - return netherSpawnRadius; - } - /** - * @param netherSpawnRadius the netherSpawnRadius to set - */ - public void setNetherSpawnRadius(int netherSpawnRadius) { - this.netherSpawnRadius = netherSpawnRadius; - } - /** - * @return the endGenerate - */ - public boolean isEndGenerate() { - return endGenerate; - } - /** - * @param endGenerate the endGenerate to set - */ - public void setEndGenerate(boolean endGenerate) { - this.endGenerate = endGenerate; - } - /** - * @return the endIslands - */ - public boolean isEndIslands() { - return endIslands; - } - /** - * @param endIslands the endIslands to set - */ - public void setEndIslands(boolean endIslands) { - this.endIslands = endIslands; - } - /** - * @return the entityLimits - */ - public HashMap getEntityLimits() { - return entityLimits; - } - /** - * @param entityLimits the entityLimits to set - */ - public void setEntityLimits(HashMap entityLimits) { - this.entityLimits = entityLimits; - } - /** - * @return the tileEntityLimits - */ - public HashMap getTileEntityLimits() { - return tileEntityLimits; - } - /** - * @param tileEntityLimits the tileEntityLimits to set - */ - public void setTileEntityLimits(HashMap tileEntityLimits) { - this.tileEntityLimits = tileEntityLimits; - } - /** - * @return the maxTeamSize - */ - public int getMaxTeamSize() { - return maxTeamSize; - } - /** - * @param maxTeamSize the maxTeamSize to set - */ - public void setMaxTeamSize(int maxTeamSize) { - this.maxTeamSize = maxTeamSize; - } - /** - * @return the maxHomes - */ - public int getMaxHomes() { - return maxHomes; - } - /** - * @param maxHomes the maxHomes to set - */ - public void setMaxHomes(int maxHomes) { - this.maxHomes = maxHomes; - } - /** - * @return the nameMinLength - */ - public int getNameMinLength() { - return nameMinLength; - } - /** - * @param nameMinLength the nameMinLength to set - */ - public void setNameMinLength(int nameMinLength) { - this.nameMinLength = nameMinLength; - } - /** - * @return the nameMaxLength - */ - public int getNameMaxLength() { - return nameMaxLength; - } - /** - * @param nameMaxLength the nameMaxLength to set - */ - public void setNameMaxLength(int nameMaxLength) { - this.nameMaxLength = nameMaxLength; - } - /** - * @return the inviteWait - */ - public int getInviteWait() { - return inviteWait; - } - /** - * @param inviteWait the inviteWait to set - */ - public void setInviteWait(int inviteWait) { - this.inviteWait = inviteWait; - } - /** - * @return the resetLimit - */ - public int getResetLimit() { - return resetLimit; - } - /** - * @param resetLimit the resetLimit to set - */ - public void setResetLimit(int resetLimit) { - this.resetLimit = resetLimit; - } - /** - * @return the resetWait - */ - public int getResetWait() { - return resetWait; - } - /** - * @param resetWait the resetWait to set - */ - public void setResetWait(int resetWait) { - this.resetWait = resetWait; - } - /** - * @return the leaversLoseReset - */ - public boolean isLeaversLoseReset() { - return leaversLoseReset; - } - /** - * @param leaversLoseReset the leaversLoseReset to set - */ - public void setLeaversLoseReset(boolean leaversLoseReset) { - this.leaversLoseReset = leaversLoseReset; - } - /** - * @return the kickedKeepInventory - */ - public boolean isKickedKeepInventory() { - return kickedKeepInventory; - } - /** - * @param kickedKeepInventory the kickedKeepInventory to set - */ - public void setKickedKeepInventory(boolean kickedKeepInventory) { - this.kickedKeepInventory = kickedKeepInventory; - } - /** - * @return the removeMobsOnLogin - */ - public boolean isRemoveMobsOnLogin() { - return removeMobsOnLogin; - } - /** - * @param removeMobsOnLogin the removeMobsOnLogin to set - */ - public void setRemoveMobsOnLogin(boolean removeMobsOnLogin) { - this.removeMobsOnLogin = removeMobsOnLogin; - } - /** - * @return the removeMobsOnIsland - */ - public boolean isRemoveMobsOnIsland() { - return removeMobsOnIsland; - } - /** - * @param removeMobsOnIsland the removeMobsOnIsland to set - */ - public void setRemoveMobsOnIsland(boolean removeMobsOnIsland) { - this.removeMobsOnIsland = removeMobsOnIsland; - } - /** - * @return the removeMobsWhitelist - */ - public List getRemoveMobsWhitelist() { - return removeMobsWhitelist; - } - /** - * @param removeMobsWhitelist the removeMobsWhitelist to set - */ - public void setRemoveMobsWhitelist(List removeMobsWhitelist) { - this.removeMobsWhitelist = removeMobsWhitelist; - } - /** - * @return the makeIslandIfNone - */ - public boolean isMakeIslandIfNone() { - return makeIslandIfNone; - } - /** - * @param makeIslandIfNone the makeIslandIfNone to set - */ - public void setMakeIslandIfNone(boolean makeIslandIfNone) { - this.makeIslandIfNone = makeIslandIfNone; - } - /** - * @return the immediateTeleportOnIsland - */ - public boolean isImmediateTeleportOnIsland() { - return immediateTeleportOnIsland; - } - /** - * @param immediateTeleportOnIsland the immediateTeleportOnIsland to set - */ - public void setImmediateTeleportOnIsland(boolean immediateTeleportOnIsland) { - this.immediateTeleportOnIsland = immediateTeleportOnIsland; - } - /** - * @return the respawnOnIsland - */ - public boolean isRespawnOnIsland() { - return respawnOnIsland; - } - /** - * @param respawnOnIsland the respawnOnIsland to set - */ - public void setRespawnOnIsland(boolean respawnOnIsland) { - this.respawnOnIsland = respawnOnIsland; - } - /** - * @return the deathsMax - */ - public int getDeathsMax() { - return deathsMax; - } - /** - * @param deathsMax the deathsMax to set - */ - public void setDeathsMax(int deathsMax) { - this.deathsMax = deathsMax; - } - /** - * @return the deathsSumTeam - */ - public boolean isDeathsSumTeam() { - return deathsSumTeam; - } - /** - * @param deathsSumTeam the deathsSumTeam to set - */ - public void setDeathsSumTeam(boolean deathsSumTeam) { - this.deathsSumTeam = deathsSumTeam; - } - /** - * @return the allowPistonPush - */ - public boolean isAllowPistonPush() { - return allowPistonPush; - } - /** - * @param allowPistonPush the allowPistonPush to set - */ - public void setAllowPistonPush(boolean allowPistonPush) { - this.allowPistonPush = allowPistonPush; - } - /** - * @return the restrictFlyingMobs - */ - public boolean isRestrictFlyingMobs() { - return restrictFlyingMobs; - } - /** - * @param restrictFlyingMobs the restrictFlyingMobs to set - */ - public void setRestrictFlyingMobs(boolean restrictFlyingMobs) { - this.restrictFlyingMobs = restrictFlyingMobs; - } - /** - * @return the togglePvPCooldown - */ - public int getTogglePvPCooldown() { - return togglePvPCooldown; - } - /** - * @param togglePvPCooldown the togglePvPCooldown to set - */ - public void setTogglePvPCooldown(int togglePvPCooldown) { - this.togglePvPCooldown = togglePvPCooldown; - } - /** - * @return the defaultFlags - */ - public HashMap getDefaultFlags() { - return defaultFlags; - } - /** - * @param defaultFlags the defaultFlags to set - */ - public void setDefaultFlags(HashMap defaultFlags) { - this.defaultFlags = defaultFlags; - } - /** - * @return the allowEndermanGriefing - */ - public boolean isAllowEndermanGriefing() { - return allowEndermanGriefing; - } - /** - * @param allowEndermanGriefing the allowEndermanGriefing to set - */ - public void setAllowEndermanGriefing(boolean allowEndermanGriefing) { - this.allowEndermanGriefing = allowEndermanGriefing; - } - /** - * @return the endermanDeathDrop - */ - public boolean isEndermanDeathDrop() { - return endermanDeathDrop; - } - /** - * @param endermanDeathDrop the endermanDeathDrop to set - */ - public void setEndermanDeathDrop(boolean endermanDeathDrop) { - this.endermanDeathDrop = endermanDeathDrop; - } - /** - * @return the allowTNTDamage - */ - public boolean isAllowTNTDamage() { - return allowTNTDamage; - } - /** - * @param allowTNTDamage the allowTNTDamage to set - */ - public void setAllowTNTDamage(boolean allowTNTDamage) { - this.allowTNTDamage = allowTNTDamage; - } - /** - * @return the allowChestDamage - */ - public boolean isAllowChestDamage() { - return allowChestDamage; - } - /** - * @param allowChestDamage the allowChestDamage to set - */ - public void setAllowChestDamage(boolean allowChestDamage) { - this.allowChestDamage = allowChestDamage; - } - /** - * @return the allowCreeperDamage - */ - public boolean isAllowCreeperDamage() { - return allowCreeperDamage; - } - /** - * @param allowCreeperDamage the allowCreeperDamage to set - */ - public void setAllowCreeperDamage(boolean allowCreeperDamage) { - this.allowCreeperDamage = allowCreeperDamage; - } - /** - * @return the allowCreeperGriefing - */ - public boolean isAllowCreeperGriefing() { - return allowCreeperGriefing; - } - /** - * @param allowCreeperGriefing the allowCreeperGriefing to set - */ - public void setAllowCreeperGriefing(boolean allowCreeperGriefing) { - this.allowCreeperGriefing = allowCreeperGriefing; - } - /** - * @return the allowMobDamageToItemFrames - */ - public boolean isAllowMobDamageToItemFrames() { - return allowMobDamageToItemFrames; - } - /** - * @param allowMobDamageToItemFrames the allowMobDamageToItemFrames to set - */ - public void setAllowMobDamageToItemFrames(boolean allowMobDamageToItemFrames) { - this.allowMobDamageToItemFrames = allowMobDamageToItemFrames; - } - /** - * @return the acidDamageOp - */ - public boolean isAcidDamageOp() { - return acidDamageOp; - } - /** - * @param acidDamageOp the acidDamageOp to set - */ - public void setAcidDamageOp(boolean acidDamageOp) { - this.acidDamageOp = acidDamageOp; - } - /** - * @return the acidDamageChickens - */ - public boolean isAcidDamageChickens() { - return acidDamageChickens; - } - /** - * @param acidDamageChickens the acidDamageChickens to set - */ - public void setAcidDamageChickens(boolean acidDamageChickens) { - this.acidDamageChickens = acidDamageChickens; - } - /** - * @return the acidDestroyItemTime - */ - public int getAcidDestroyItemTime() { - return acidDestroyItemTime; - } - /** - * @param acidDestroyItemTime the acidDestroyItemTime to set - */ - public void setAcidDestroyItemTime(int acidDestroyItemTime) { - this.acidDestroyItemTime = acidDestroyItemTime; - } - /** - * @return the acidDamage - */ - public int getAcidDamage() { - return acidDamage; - } - /** - * @param acidDamage the acidDamage to set - */ - public void setAcidDamage(int acidDamage) { - this.acidDamage = acidDamage; - } - /** - * @return the acidRainDamage - */ - public int getAcidRainDamage() { - return acidRainDamage; - } - /** - * @param acidRainDamage the acidRainDamage to set - */ - public void setAcidRainDamage(int acidRainDamage) { - this.acidRainDamage = acidRainDamage; - } - /** - * @return the acidEffects - */ - public List getAcidEffects() { - return acidEffects; - } - /** - * @param acidEffects the acidEffects to set - */ - public void setAcidEffects(List acidEffects) { - this.acidEffects = acidEffects; - } - /** - * @return the companionNames - */ - public List getCompanionNames() { - return companionNames; - } - /** - * @param companionNames the companionNames to set - */ - public void setCompanionNames(List companionNames) { - this.companionNames = companionNames; - } - /** - * @return the chestItems - */ - public ItemStack[] getChestItems() { - return chestItems; - } - /** - * @param chestItems the chestItems to set - */ - public void setChestItems(ItemStack[] chestItems) { - this.chestItems = chestItems; - } - /** - * @return the companionType - */ - public EntityType getCompanionType() { - return companionType; - } - /** - * @param companionType the companionType to set - */ - public void setCompanionType(EntityType companionType) { - this.companionType = companionType; - } - /** - * @return the useOwnGenerator - */ - public boolean isUseOwnGenerator() { - return useOwnGenerator; - } - /** - * @param useOwnGenerator the useOwnGenerator to set - */ - public void setUseOwnGenerator(boolean useOwnGenerator) { - this.useOwnGenerator = useOwnGenerator; - } - /** - * @return the limitedBlocks - */ - public HashMap getLimitedBlocks() { - return limitedBlocks; - } - /** - * @param limitedBlocks the limitedBlocks to set - */ - public void setLimitedBlocks(HashMap limitedBlocks) { - this.limitedBlocks = limitedBlocks; - } - /** - * @return the teamJoinDeathReset - */ - public boolean isTeamJoinDeathReset() { - return teamJoinDeathReset; - } - /** - * @param teamJoinDeathReset the teamJoinDeathReset to set - */ - public void setTeamJoinDeathReset(boolean teamJoinDeathReset) { - this.teamJoinDeathReset = teamJoinDeathReset; - } - -} \ No newline at end of file diff --git a/src/main/java/us/tastybento/bskyblock/api/commands/CompositeCommand.java b/src/main/java/us/tastybento/bskyblock/api/commands/CompositeCommand.java index c92e1e90c..01eb1c0bb 100644 --- a/src/main/java/us/tastybento/bskyblock/api/commands/CompositeCommand.java +++ b/src/main/java/us/tastybento/bskyblock/api/commands/CompositeCommand.java @@ -17,6 +17,7 @@ import org.bukkit.command.PluginIdentifiableCommand; import org.bukkit.entity.Player; import us.tastybento.bskyblock.BSkyBlock; +import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.api.events.command.CommandEvent; import us.tastybento.bskyblock.database.managers.PlayersManager; import us.tastybento.bskyblock.database.managers.island.IslandsManager; @@ -59,6 +60,23 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi */ private String usage; + /** + * Used only for testing.... + */ + public CompositeCommand(BSkyBlock plugin, String label, String... string) { + super(label); + this.setAliases(new ArrayList<>(Arrays.asList(string))); + this.parent = null; + setUsage(""); + this.subCommandLevel = 0; // Top level + this.subCommands = new LinkedHashMap<>(); + this.setup(); + if (!this.getSubCommand("help").isPresent() && !label.equals("help")) + new DefaultHelpCommand(this); + + } + + /** * Sub-command constructor * @param parent - the parent composite command @@ -83,7 +101,6 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi Bukkit.getLogger().info("DEBUG: registering command " + label); } - /** * This is the top-level command constructor for commands that have no parent. * @param label - string for this command @@ -108,22 +125,6 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi } - /** - * Used only for testing.... - */ - public CompositeCommand(BSkyBlock plugin, String label, String... string) { - super(label); - this.setAliases(new ArrayList<>(Arrays.asList(string))); - this.parent = null; - setUsage(""); - this.subCommandLevel = 0; // Top level - this.subCommands = new LinkedHashMap<>(); - this.setup(); - if (!this.getSubCommand("help").isPresent() && !label.equals("help")) - new DefaultHelpCommand(this); - - } - /* * This method deals with the command execution. It traverses the tree of @@ -227,6 +228,10 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi return getPlugin().getIslands().getMembers(user.getUniqueId()); } + public String getParameters() { + return parameters; + } + /** * @return the parent command object */ @@ -246,12 +251,20 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi protected PlayersManager getPlayers() { return getPlugin().getPlayers(); } - + @Override public BSkyBlock getPlugin() { return BSkyBlock.getInstance(); } - + + /** + * @return Settings object + */ + public Settings getSettings() { + return getPlugin().getSettings(); + } + + /** * Returns the CompositeCommand object refering to this command label * @param label - command label or alias @@ -264,6 +277,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi } return Optional.empty(); } + /** * @return Map of sub commands for this command @@ -272,7 +286,6 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi return subCommands; } - /** * Convenience method to obtain the user's team leader * @param user @@ -282,41 +295,11 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi return getPlugin().getIslands().getTeamLeader(user.getUniqueId()); } - - public void setparameters(String parameters) { - this.setParameters(parameters); - } - @Override public String getUsage() { return "/" + usage; } - /** - * This creates the full linking chain of commands - */ - @Override - public Command setUsage(String usage) { - // Go up the chain - CompositeCommand parent = this.getParent(); - this.usage = this.getLabel() + " " + usage; - while (parent != null) { - this.usage = parent.getLabel() + " " + this.usage; - parent = parent.getParent(); - } - this.usage = this.usage.trim(); - return this; - } - - public String getParameters() { - return parameters; - } - - - public void setParameters(String parameters) { - this.parameters = parameters; - } - /** * Check if this command has a specific sub command * @param subCommand @@ -326,6 +309,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi return subCommands.containsKey(subCommand); } + /** * Check if this command has any sub commands * @return true if this command has subcommands @@ -368,11 +352,35 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi this.onlyPlayer = onlyPlayer; } + public void setparameters(String parameters) { + this.setParameters(parameters); + } + + public void setParameters(String parameters) { + this.parameters = parameters; + } + @Override public void setPermission(String permission) { this.permission = permission; } + /** + * This creates the full linking chain of commands + */ + @Override + public Command setUsage(String usage) { + // Go up the chain + CompositeCommand parent = this.getParent(); + this.usage = this.getLabel() + " " + usage; + while (parent != null) { + this.usage = parent.getLabel() + " " + this.usage; + parent = parent.getParent(); + } + this.usage = this.usage.trim(); + return this; + } + @Override public List tabComplete(final CommandSender sender, final String alias, final String[] args) { List options = new ArrayList<>(); diff --git a/src/main/java/us/tastybento/bskyblock/api/commands/User.java b/src/main/java/us/tastybento/bskyblock/api/commands/User.java index 983c82c32..1826e3848 100644 --- a/src/main/java/us/tastybento/bskyblock/api/commands/User.java +++ b/src/main/java/us/tastybento/bskyblock/api/commands/User.java @@ -17,7 +17,6 @@ import org.bukkit.inventory.PlayerInventory; import org.bukkit.permissions.PermissionAttachmentInfo; import us.tastybento.bskyblock.BSkyBlock; -import us.tastybento.bskyblock.Settings; /** * BSB's user object. Wraps Player. @@ -255,7 +254,7 @@ public class User { if (!plugin.getPlayers().getLocale(this.playerUUID).isEmpty()) return Locale.forLanguageTag(plugin.getPlayers().getLocale(this.playerUUID)); } - return Locale.forLanguageTag(Settings.defaultLanguage); + return Locale.forLanguageTag(plugin.getSettings().getDefaultLanguage()); } } diff --git a/src/main/java/us/tastybento/bskyblock/api/configuration/ISettings.java b/src/main/java/us/tastybento/bskyblock/api/configuration/ISettings.java index 5af66f808..feb7ad017 100644 --- a/src/main/java/us/tastybento/bskyblock/api/configuration/ISettings.java +++ b/src/main/java/us/tastybento/bskyblock/api/configuration/ISettings.java @@ -5,7 +5,7 @@ import java.lang.reflect.InvocationTargetException; import java.sql.SQLException; import us.tastybento.bskyblock.BSkyBlock; -import us.tastybento.bskyblock.Settings2; +import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.database.flatfile.FlatFileDatabase; import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler; @@ -19,7 +19,7 @@ public interface ISettings { // ----------------Saver------------------- @SuppressWarnings("unchecked") - public default void saveConfig(T instance) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, IntrospectionException, SQLException { + default void saveConfig(T instance) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, IntrospectionException, SQLException { // Get the handler AbstractDatabaseHandler configHandler = (AbstractDatabaseHandler) new FlatFileDatabase().getHandler(BSkyBlock.getInstance(), instance.getClass()); // Load every field in the config class @@ -27,9 +27,9 @@ public interface ISettings { } // --------------- Loader ------------------ @SuppressWarnings("unchecked") - public default Settings2 loadConfig() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, ClassNotFoundException, IntrospectionException, SQLException { + default Settings loadSettings() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, ClassNotFoundException, IntrospectionException, SQLException { // Get the handler - AbstractDatabaseHandler configHandler = (AbstractDatabaseHandler) new FlatFileDatabase().getHandler(BSkyBlock.getInstance(), Settings2.class); + AbstractDatabaseHandler configHandler = (AbstractDatabaseHandler) new FlatFileDatabase().getHandler(BSkyBlock.getInstance(), Settings.class); // Load every field in the config class return configHandler.loadObject("config"); } diff --git a/src/main/java/us/tastybento/bskyblock/api/events/command/CommandEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/command/CommandEvent.java index 02441343a..829119696 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/command/CommandEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/command/CommandEvent.java @@ -3,6 +3,7 @@ package us.tastybento.bskyblock.api.events.command; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.event.Cancellable; + import us.tastybento.bskyblock.api.events.PremadeEvent; /** diff --git a/src/main/java/us/tastybento/bskyblock/api/events/purge/PurgeStartEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/purge/PurgeStartEvent.java index c742766cd..3b6722530 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/purge/PurgeStartEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/purge/PurgeStartEvent.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.UUID; import org.bukkit.event.Cancellable; + import us.tastybento.bskyblock.api.events.PremadeEvent; /** diff --git a/src/main/java/us/tastybento/bskyblock/api/flags/Flag.java b/src/main/java/us/tastybento/bskyblock/api/flags/Flag.java index 3493639df..72fd39dd4 100644 --- a/src/main/java/us/tastybento/bskyblock/api/flags/Flag.java +++ b/src/main/java/us/tastybento/bskyblock/api/flags/Flag.java @@ -1,10 +1,11 @@ package us.tastybento.bskyblock.api.flags; -import org.bukkit.event.Listener; -import us.tastybento.bskyblock.api.panels.PanelItem; - import java.util.Optional; +import org.bukkit.event.Listener; + +import us.tastybento.bskyblock.api.panels.PanelItem; + public class Flag { private String id; diff --git a/src/main/java/us/tastybento/bskyblock/api/flags/FlagBuilder.java b/src/main/java/us/tastybento/bskyblock/api/flags/FlagBuilder.java index 18fdbb5b3..cc304a344 100644 --- a/src/main/java/us/tastybento/bskyblock/api/flags/FlagBuilder.java +++ b/src/main/java/us/tastybento/bskyblock/api/flags/FlagBuilder.java @@ -1,10 +1,11 @@ package us.tastybento.bskyblock.api.flags; -import org.bukkit.event.Listener; -import us.tastybento.bskyblock.api.panels.PanelItem; - import java.util.Optional; +import org.bukkit.event.Listener; + +import us.tastybento.bskyblock.api.panels.PanelItem; + public class FlagBuilder { private String id; diff --git a/src/main/java/us/tastybento/bskyblock/api/localization/BSBLocale.java b/src/main/java/us/tastybento/bskyblock/api/localization/BSBLocale.java index 3ff6565b5..f48472ff6 100644 --- a/src/main/java/us/tastybento/bskyblock/api/localization/BSBLocale.java +++ b/src/main/java/us/tastybento/bskyblock/api/localization/BSBLocale.java @@ -1,11 +1,8 @@ package us.tastybento.bskyblock.api.localization; import java.io.File; -import java.util.HashMap; import java.util.Locale; -import java.util.Map; -import org.bukkit.ChatColor; import org.bukkit.configuration.file.YamlConfiguration; /** diff --git a/src/main/java/us/tastybento/bskyblock/commands/AdminCommand.java b/src/main/java/us/tastybento/bskyblock/commands/AdminCommand.java index 45436b2a3..e4970a3ee 100755 --- a/src/main/java/us/tastybento/bskyblock/commands/AdminCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/AdminCommand.java @@ -2,7 +2,7 @@ package us.tastybento.bskyblock.commands; import java.util.List; -import us.tastybento.bskyblock.Settings; +import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.commands.admin.AdminReloadCommand; @@ -11,12 +11,12 @@ import us.tastybento.bskyblock.commands.admin.AdminVersionCommand; public class AdminCommand extends CompositeCommand { public AdminCommand() { - super(Settings.ADMINCOMMAND, "bsb"); + super(Constants.ADMINCOMMAND, "bsb"); } @Override public void setup() { - this.setPermission(Settings.PERMPREFIX + "admin.*"); + this.setPermission(Constants.PERMPREFIX + "admin.*"); this.setOnlyPlayer(false); this.setDescription("admin.help.description"); new AdminVersionCommand(this); diff --git a/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java b/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java index c96153557..45d0e19f9 100755 --- a/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java @@ -2,6 +2,7 @@ package us.tastybento.bskyblock.commands; import java.util.List; +import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.commands.island.IslandAboutCommand; @@ -12,12 +13,11 @@ import us.tastybento.bskyblock.commands.island.IslandResetnameCommand; import us.tastybento.bskyblock.commands.island.IslandSethomeCommand; import us.tastybento.bskyblock.commands.island.IslandSetnameCommand; import us.tastybento.bskyblock.commands.island.teams.IslandTeamCommand; -import us.tastybento.bskyblock.Settings; public class IslandCommand extends CompositeCommand { public IslandCommand() { - super(Settings.ISLANDCOMMAND, "is"); + super(Constants.ISLANDCOMMAND, "is"); } /* (non-Javadoc) @@ -28,7 +28,7 @@ public class IslandCommand extends CompositeCommand { this.setDescription("commands.island.help.description"); this.setOnlyPlayer(true); // Permission - this.setPermission(Settings.PERMPREFIX + "island"); + this.setPermission(Constants.PERMPREFIX + "island"); // Set up subcommands new IslandAboutCommand(this); new IslandCreateCommand(this); diff --git a/src/main/java/us/tastybento/bskyblock/commands/admin/AdminReloadCommand.java b/src/main/java/us/tastybento/bskyblock/commands/admin/AdminReloadCommand.java index 3a63aa09b..c3c9c31ad 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/admin/AdminReloadCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/admin/AdminReloadCommand.java @@ -7,7 +7,6 @@ import java.util.List; import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.User; -import us.tastybento.bskyblock.config.ConfigLoader; /** * @author ben @@ -38,7 +37,6 @@ public class AdminReloadCommand extends CompositeCommand { */ @Override public boolean execute(User user, List args) { - new ConfigLoader(); return true; } diff --git a/src/main/java/us/tastybento/bskyblock/commands/admin/AdminVersionCommand.java b/src/main/java/us/tastybento/bskyblock/commands/admin/AdminVersionCommand.java index 341415fd6..577d7eb37 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/admin/AdminVersionCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/admin/AdminVersionCommand.java @@ -2,9 +2,9 @@ package us.tastybento.bskyblock.commands.admin; import java.util.List; +import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.User; -import us.tastybento.bskyblock.Settings; public class AdminVersionCommand extends CompositeCommand { @@ -15,7 +15,7 @@ public class AdminVersionCommand extends CompositeCommand { @Override public void setup() { // Permission - this.setPermission(Settings.PERMPREFIX + "admin.version"); + this.setPermission(Constants.PERMPREFIX + "admin.version"); } @Override diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/CustomIslandMultiHomeHelp.java b/src/main/java/us/tastybento/bskyblock/commands/island/CustomIslandMultiHomeHelp.java index 92ef111d8..a7ec5f3e6 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/CustomIslandMultiHomeHelp.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/CustomIslandMultiHomeHelp.java @@ -2,9 +2,9 @@ package us.tastybento.bskyblock.commands.island; import java.util.List; +import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.User; -import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.util.Util; /** @@ -40,7 +40,7 @@ public class CustomIslandMultiHomeHelp extends CompositeCommand { String desc = getDescription().isEmpty() ? "" : user.getTranslation(getDescription()); // Player. Check perms if (user.hasPermission(getPermission())) { - int maxHomes = Util.getPermValue(user.getPlayer(), Settings.PERMPREFIX + "island.maxhomes", Settings.maxHomes); + int maxHomes = Util.getPermValue(user.getPlayer(), Constants.PERMPREFIX + "island.maxhomes", getSettings().getMaxHomes()); if (maxHomes > 1) { params = getParameters().isEmpty() ? "" : user.getTranslation(getParameters()); user.sendMessage("commands.help.syntax", "[usage]", usage, "[parameters]", params, "[description]", desc); diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/IslandCreateCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/IslandCreateCommand.java index fa311a774..9073124e5 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/IslandCreateCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/IslandCreateCommand.java @@ -6,11 +6,11 @@ package us.tastybento.bskyblock.commands.island; import java.io.IOException; import java.util.List; +import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason; import us.tastybento.bskyblock.commands.IslandCommand; -import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.database.managers.island.NewIsland; /** @@ -26,7 +26,7 @@ public class IslandCreateCommand extends CompositeCommand { @Override public void setup() { - this.setPermission(Settings.PERMPREFIX + "island.create"); + this.setPermission(Constants.PERMPREFIX + "island.create"); this.setOnlyPlayer(true); this.setDescription("commands.island.create.description"); } @@ -55,7 +55,7 @@ public class IslandCreateCommand extends CompositeCommand { */ protected void createIsland(User user) { try { - NewIsland.builder() + NewIsland.builder(getPlugin()) .player(user.getPlayer()) .reason(Reason.CREATE) .build(); diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/IslandGoCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/IslandGoCommand.java index 665df2bfe..3b9fd0549 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/IslandGoCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/IslandGoCommand.java @@ -8,10 +8,10 @@ import java.util.List; import org.apache.commons.lang.math.NumberUtils; import org.bukkit.ChatColor; +import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.commands.IslandCommand; -import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.util.Util; /** @@ -26,7 +26,7 @@ public class IslandGoCommand extends CompositeCommand { @Override public void setup() { - this.setPermission(Settings.PERMPREFIX + "island.home"); + this.setPermission(Constants.PERMPREFIX + "island.home"); this.setOnlyPlayer(true); this.setDescription("commands.island.go.description"); new CustomIslandMultiHomeHelp(this); @@ -43,7 +43,7 @@ public class IslandGoCommand extends CompositeCommand { } if (!args.isEmpty() && NumberUtils.isDigits(args.get(0))) { int homeValue = Integer.valueOf(args.get(0)); - int maxHomes = Util.getPermValue(user.getPlayer(), Settings.PERMPREFIX + "island.maxhomes", Settings.maxHomes); + int maxHomes = Util.getPermValue(user.getPlayer(), Constants.PERMPREFIX + "island.maxhomes", getSettings().getMaxHomes()); if (homeValue > 1 && homeValue <= maxHomes) { getIslands().homeTeleport(user.getPlayer(), homeValue); return true; diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/IslandResetCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/IslandResetCommand.java index c96eb39d6..242721c65 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/IslandResetCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/IslandResetCommand.java @@ -6,10 +6,10 @@ import java.util.List; import org.bukkit.GameMode; import org.bukkit.entity.Player; +import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason; -import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.database.managers.island.NewIsland; import us.tastybento.bskyblock.database.objects.Island; @@ -23,7 +23,7 @@ public class IslandResetCommand extends CompositeCommand { @Override public void setup() { - this.setPermission(Settings.PERMPREFIX + "island.create"); + this.setPermission(Constants.PERMPREFIX + "island.create"); this.setOnlyPlayer(true); this.setDescription("commands.island.reset.description"); } @@ -56,7 +56,7 @@ public class IslandResetCommand extends CompositeCommand { if (DEBUG) getPlugin().getLogger().info("DEBUG: making new island "); try { - NewIsland.builder() + NewIsland.builder(getPlugin()) .player(player) .reason(Reason.RESET) .oldIsland(oldIsland) diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/IslandResetnameCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/IslandResetnameCommand.java index b00d90dc3..077b0afd0 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/IslandResetnameCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/IslandResetnameCommand.java @@ -6,9 +6,9 @@ package us.tastybento.bskyblock.commands.island; import java.util.List; import java.util.UUID; +import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.User; -import us.tastybento.bskyblock.Settings; /** * @author tastybento @@ -22,7 +22,7 @@ public class IslandResetnameCommand extends CompositeCommand { @Override public void setup() { - this.setPermission(Settings.PERMPREFIX + "island.name"); + this.setPermission(Constants.PERMPREFIX + "island.name"); this.setOnlyPlayer(true); this.setDescription("commands.island.resetname.description"); diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/IslandSethomeCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/IslandSethomeCommand.java index 0548d2561..d79f8a597 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/IslandSethomeCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/IslandSethomeCommand.java @@ -3,9 +3,9 @@ package us.tastybento.bskyblock.commands.island; import java.util.List; import java.util.UUID; +import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.User; -import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.util.Util; public class IslandSethomeCommand extends CompositeCommand { @@ -16,7 +16,7 @@ public class IslandSethomeCommand extends CompositeCommand { @Override public void setup() { - this.setPermission(Settings.PERMPREFIX + "island.sethome"); + this.setPermission(Constants.PERMPREFIX + "island.sethome"); this.setOnlyPlayer(true); this.setDescription("commands.island.sethome.description"); new CustomIslandMultiHomeHelp(this); @@ -40,7 +40,7 @@ public class IslandSethomeCommand extends CompositeCommand { user.sendMessage("commands.island.sethome.home-set"); } else { // Dynamic home sizes with permissions - int maxHomes = Util.getPermValue(user.getPlayer(), Settings.PERMPREFIX + "island.maxhomes", Settings.maxHomes); + int maxHomes = Util.getPermValue(user.getPlayer(), Constants.PERMPREFIX + "island.maxhomes", getSettings().getMaxHomes()); if (maxHomes > 1) { // Check the number given is a number int number = 0; diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/IslandSetnameCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/IslandSetnameCommand.java index f113449d1..a58b5c9c0 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/IslandSetnameCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/IslandSetnameCommand.java @@ -10,9 +10,9 @@ import java.util.stream.Collectors; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.User; -import us.tastybento.bskyblock.Settings; /** * @author tastybento @@ -26,7 +26,7 @@ public class IslandSetnameCommand extends CompositeCommand { @Override public void setup() { - this.setPermission(Settings.PERMPREFIX + "island.name"); + this.setPermission(Constants.PERMPREFIX + "island.name"); this.setOnlyPlayer(true); this.setParameters("commands.island.setname.parameters"); this.setDescription("commands.island.setname.description"); @@ -59,17 +59,17 @@ public class IslandSetnameCommand extends CompositeCommand { String name = args.stream().collect(Collectors.joining( " " )); // Check if the name isn't too short or too long - if (name.length() < Settings.nameMinLength) { - user.sendMessage("commands.island.setname.too-short", "[length]", String.valueOf(Settings.nameMinLength)); + if (name.length() < getSettings().getNameMinLength()) { + user.sendMessage("commands.island.setname.too-short", "[length]", String.valueOf(getSettings().getNameMinLength())); return true; } - if (name.length() > Settings.nameMaxLength) { - user.sendMessage("commands.island.setname.too-long", "[length]", String.valueOf(Settings.nameMaxLength)); + if (name.length() > getSettings().getNameMaxLength()) { + user.sendMessage("commands.island.setname.too-long", "[length]", String.valueOf(getSettings().getNameMaxLength())); return true; } // Set the name - if (!player.hasPermission(Settings.PERMPREFIX + "island.name.format")) + if (!player.hasPermission(Constants.PERMPREFIX + "island.name.format")) getIslands().getIsland(player.getUniqueId()).setName(ChatColor.translateAlternateColorCodes('&', name)); else getIslands().getIsland(playerUUID).setName(name); diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/teams/AbstractIslandTeamCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/teams/AbstractIslandTeamCommand.java index 64f42c484..6de0c3972 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/teams/AbstractIslandTeamCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/teams/AbstractIslandTeamCommand.java @@ -13,7 +13,6 @@ import com.google.common.collect.HashBiMap; import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.User; -import us.tastybento.bskyblock.Settings; /** * A safe common space for team commands to share data @@ -42,6 +41,6 @@ public abstract class AbstractIslandTeamCommand extends CompositeCommand { * @param player */ protected void setResetWaitTime(final Player player) { - resetWaitTime.put(player.getUniqueId(), Calendar.getInstance().getTimeInMillis() + Settings.resetWait * 1000); + resetWaitTime.put(player.getUniqueId(), Calendar.getInstance().getTimeInMillis() + getSettings().getResetWait() * 1000); } } diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamCommand.java index 6ad749c69..bb9304553 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamCommand.java @@ -7,11 +7,11 @@ import java.util.UUID; import org.apache.commons.lang.math.NumberUtils; import org.bukkit.permissions.PermissionAttachmentInfo; +import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.events.IslandBaseEvent; import us.tastybento.bskyblock.api.events.team.TeamEvent; -import us.tastybento.bskyblock.Settings; public class IslandTeamCommand extends AbstractIslandTeamCommand { @@ -23,7 +23,7 @@ public class IslandTeamCommand extends AbstractIslandTeamCommand { @Override public void setup() { - this.setPermission(Settings.PERMPREFIX + "island.team"); + this.setPermission(Constants.PERMPREFIX + "island.team"); this.setOnlyPlayer(true); this.setDescription("commands.island.team.description"); @@ -50,15 +50,15 @@ public class IslandTeamCommand extends AbstractIslandTeamCommand { UUID teamLeaderUUID = getTeamLeader(user); Set teamMembers = getMembers(user); if (teamLeaderUUID.equals(playerUUID)) { - int maxSize = Settings.maxTeamSize; + int maxSize = getSettings().getMaxTeamSize(); for (PermissionAttachmentInfo perms : user.getEffectivePermissions()) { - if (perms.getPermission().startsWith(Settings.PERMPREFIX + "team.maxsize.")) { - if (perms.getPermission().contains(Settings.PERMPREFIX + "team.maxsize.*")) { - maxSize = Settings.maxTeamSize; + if (perms.getPermission().startsWith(Constants.PERMPREFIX + "team.maxsize.")) { + if (perms.getPermission().contains(Constants.PERMPREFIX + "team.maxsize.*")) { + maxSize = getSettings().getMaxTeamSize(); break; } else { // Get the max value should there be more than one - String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "team.maxsize."); + String[] spl = perms.getPermission().split(Constants.PERMPREFIX + "team.maxsize."); if (spl.length > 1) { if (!NumberUtils.isDigits(spl[1])) { getPlugin().getLogger().severe("Player " + user.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring..."); diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteAcceptCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteAcceptCommand.java index 9a582a2d5..cfa762a34 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteAcceptCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteAcceptCommand.java @@ -7,10 +7,10 @@ import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; +import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.events.IslandBaseEvent; import us.tastybento.bskyblock.api.events.team.TeamEvent; -import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.database.objects.Island; public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand { @@ -21,7 +21,7 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand { @Override public void setup() { - this.setPermission(Settings.PERMPREFIX + "island.team"); + this.setPermission(Constants.PERMPREFIX + "island.team"); this.setOnlyPlayer(true); this.setDescription("commands.island.team.invite.accept.description"); } @@ -88,13 +88,13 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand { // Set the cooldown setResetWaitTime(user.getPlayer()); // Reset deaths - if (Settings.teamJoinDeathReset) { + if (getSettings().isTeamJoinDeathReset()) { getPlayers().setDeaths(playerUUID, 0); } // Put player back into normal mode user.setGameMode(GameMode.SURVIVAL); - user.sendMessage("commands.island.team.invite.accept.you-joined-island", "[label]", Settings.ISLANDCOMMAND); + user.sendMessage("commands.island.team.invite.accept.you-joined-island", "[label]", Constants.ISLANDCOMMAND); User inviter = User.getInstance(inviteList.get(playerUUID)); if (inviter != null) { inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", "[name]", user.getName()); diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteCommand.java index 22303da31..b70961243 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteCommand.java @@ -11,10 +11,10 @@ import org.apache.commons.lang.math.NumberUtils; import org.bukkit.OfflinePlayer; import org.bukkit.permissions.PermissionAttachmentInfo; +import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.events.IslandBaseEvent; import us.tastybento.bskyblock.api.events.team.TeamEvent; -import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.util.Util; public class IslandTeamInviteCommand extends AbstractIslandTeamCommand { @@ -25,7 +25,7 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand { @Override public void setup() { - this.setPermission(Settings.PERMPREFIX + "island.team"); + this.setPermission(Constants.PERMPREFIX + "island.team"); this.setOnlyPlayer(true); this.setDescription("commands.island.team.invite.description"); @@ -84,16 +84,16 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand { } Set teamMembers = getMembers(user); // Check if player has space on their team - int maxSize = Settings.maxTeamSize; + int maxSize = getSettings().getMaxTeamSize(); // Dynamic team sizes with permissions for (PermissionAttachmentInfo perms : user.getEffectivePermissions()) { - if (perms.getPermission().startsWith(Settings.PERMPREFIX + "team.maxsize.")) { - if (perms.getPermission().contains(Settings.PERMPREFIX + "team.maxsize.*")) { - maxSize = Settings.maxTeamSize; + if (perms.getPermission().startsWith(Constants.PERMPREFIX + "team.maxsize.")) { + if (perms.getPermission().contains(Constants.PERMPREFIX + "team.maxsize.*")) { + maxSize = getSettings().getMaxTeamSize(); break; } else { // Get the max value should there be more than one - String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "team.maxsize."); + String[] spl = perms.getPermission().split(Constants.PERMPREFIX + "team.maxsize."); if (spl.length > 1) { if (!NumberUtils.isDigits(spl[1])) { getPlugin().getLogger().severe("Player " + user.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring..."); diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteRejectCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteRejectCommand.java index 2344baa9c..db8432783 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteRejectCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteRejectCommand.java @@ -3,10 +3,10 @@ package us.tastybento.bskyblock.commands.island.teams; import java.util.List; import java.util.UUID; +import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.events.IslandBaseEvent; import us.tastybento.bskyblock.api.events.team.TeamEvent; -import us.tastybento.bskyblock.Settings; public class IslandTeamInviteRejectCommand extends AbstractIslandTeamCommand { @@ -16,7 +16,7 @@ public class IslandTeamInviteRejectCommand extends AbstractIslandTeamCommand { @Override public void setup() { - this.setPermission(Settings.PERMPREFIX + "island.team"); + this.setPermission(Constants.PERMPREFIX + "island.team"); this.setOnlyPlayer(true); this.setDescription("commands.island.team.invite.reject.description"); } diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamLeaveCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamLeaveCommand.java index 7be840735..a8f5ddaee 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamLeaveCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamLeaveCommand.java @@ -2,8 +2,8 @@ package us.tastybento.bskyblock.commands.island.teams; import java.util.List; +import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.User; -import us.tastybento.bskyblock.Settings; public class IslandTeamLeaveCommand extends AbstractIslandTeamCommand { @@ -13,7 +13,7 @@ public class IslandTeamLeaveCommand extends AbstractIslandTeamCommand { @Override public void setup() { - this.setPermission(Settings.PERMPREFIX + "island.team"); + this.setPermission(Constants.PERMPREFIX + "island.team"); this.setOnlyPlayer(true); this.setDescription("commands.island.team.leave.description"); diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamPromoteCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamPromoteCommand.java index 0b3854496..48f29c256 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamPromoteCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamPromoteCommand.java @@ -2,8 +2,8 @@ package us.tastybento.bskyblock.commands.island.teams; import java.util.List; +import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.User; -import us.tastybento.bskyblock.Settings; public class IslandTeamPromoteCommand extends AbstractIslandTeamCommand { @@ -13,7 +13,7 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommand { @Override public void setup() { - this.setPermission(Settings.PERMPREFIX + "island.team"); + this.setPermission(Constants.PERMPREFIX + "island.team"); this.setOnlyPlayer(true); this.setParameters("commands.island.team.promote.parameters"); this.setDescription("commands.island.team.promote.description"); diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamSetownerCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamSetownerCommand.java index 55f61c85a..17ab8d8c3 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamSetownerCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamSetownerCommand.java @@ -9,10 +9,10 @@ import java.util.UUID; import org.apache.commons.lang.math.NumberUtils; import org.bukkit.permissions.PermissionAttachmentInfo; +import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.events.IslandBaseEvent; import us.tastybento.bskyblock.api.events.team.TeamEvent; -import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.util.Util; @@ -24,7 +24,7 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand { @Override public void setup() { - this.setPermission(Settings.PERMPREFIX + "island.team"); + this.setPermission(Constants.PERMPREFIX + "island.team"); this.setOnlyPlayer(true); this.setParameters("commands.island.team.setowner.parameters"); this.setDescription("commands.island.team.setowner.description"); @@ -81,7 +81,7 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand { if (target.isOnline()) { // Check if new leader has a lower range permission than the island size boolean hasARangePerm = false; - int range = Settings.islandProtectionRange; + int range = getSettings().getIslandProtectionRange(); // Check for zero protection range Island islandByOwner = getIslands().getIsland(targetUUID); if (islandByOwner.getProtectionRange() == 0) { @@ -89,12 +89,12 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand { islandByOwner.setProtectionRange(range); } for (PermissionAttachmentInfo perms : target.getEffectivePermissions()) { - if (perms.getPermission().startsWith(Settings.PERMPREFIX + "island.range.")) { - if (perms.getPermission().contains(Settings.PERMPREFIX + "island.range.*")) { + if (perms.getPermission().startsWith(Constants.PERMPREFIX + "island.range.")) { + if (perms.getPermission().contains(Constants.PERMPREFIX + "island.range.*")) { // Ignore break; } else { - String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "island.range."); + String[] spl = perms.getPermission().split(Constants.PERMPREFIX + "island.range."); if (spl.length > 1) { if (!NumberUtils.isDigits(spl[1])) { getPlugin().getLogger().severe("Player " + user.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring..."); diff --git a/src/main/java/us/tastybento/bskyblock/config/ConfigLoader.java b/src/main/java/us/tastybento/bskyblock/config/ConfigLoader.java deleted file mode 100644 index 06df137f5..000000000 --- a/src/main/java/us/tastybento/bskyblock/config/ConfigLoader.java +++ /dev/null @@ -1,69 +0,0 @@ -package us.tastybento.bskyblock.config; - -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import org.bukkit.Bukkit; - -import us.tastybento.bskyblock.BSkyBlock; -import us.tastybento.bskyblock.Settings; -import us.tastybento.bskyblock.api.configuration.ConfigEntry; -import us.tastybento.bskyblock.api.configuration.ConfigEntry.GameType; -import us.tastybento.bskyblock.api.configuration.ConfigEntry.NoAdapter; - -public class ConfigLoader { - - public ConfigLoader() { - try { - getAnnotations(Settings.class); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public void getAnnotations(Class clazz) throws IllegalArgumentException, IllegalAccessException, NoSuchMethodException, SecurityException, InvocationTargetException, InstantiationException{ - for(Field field : clazz.getDeclaredFields()){ - Class type = field.getType(); - String name = field.getName(); - ConfigEntry configEntry = field.getAnnotation(ConfigEntry.class); - - - // If there is a config annotation then do something - if (configEntry != null) { - // Get the current value - Object currentvalue = field.get(null); - // Get the setting as defined in the config file - Object configValue = BSkyBlock.getInstance().getConfig().get(configEntry.path()); - // If this setting is for use in this game - if (configEntry.specificTo().equals(GameType.BOTH) || configEntry.specificTo().equals(Settings.GAMETYPE)) { - // If there's a difference in the value. Note for non-primitives, this will be true - if (!currentvalue.equals(configValue)) { - Bukkit.getLogger().info(name + " changed value from " + currentvalue + " to " + configValue); - // If there's an adapter use it to convert from the YML object to the setting field - if (!configEntry.adapter().equals(NoAdapter.class)) { - // Create an instance of the adapter class - Object instance = configEntry.adapter().newInstance(); - // Get the adapt method - it should be there. - Method method = configEntry.adapter().getMethod("adapt", Object.class, Object.class); - if (method != null) { - // It exists, so invoke it - configValue = method.invoke(instance, configValue, type); - if (configValue != null) { - // Set the field. - field.set(null, configValue); - } - } - } else if (configValue != null){ - // No adapter - I hope this works! - field.set(null, configValue); - } - } - } else { - Bukkit.getLogger().info(name + " not applicable to this game type"); - } - } - } - } -} diff --git a/src/main/java/us/tastybento/bskyblock/config/PluginConfig.java b/src/main/java/us/tastybento/bskyblock/config/PluginConfig.java deleted file mode 100644 index be1d3e6ea..000000000 --- a/src/main/java/us/tastybento/bskyblock/config/PluginConfig.java +++ /dev/null @@ -1,128 +0,0 @@ -package us.tastybento.bskyblock.config; - -import java.util.HashMap; - -import us.tastybento.bskyblock.BSkyBlock; -import us.tastybento.bskyblock.Settings; -import us.tastybento.bskyblock.config.NotSetup.ConfigError; -import us.tastybento.bskyblock.database.BSBDatabase.DatabaseType; - -/** - * Loads the plugin configuration and the locales. - * Also provides - * - * @author Tastybento - * @author Poslovitch - */ -public class PluginConfig { - - /** - * Loads the plugin configuration and the locales. - * If there were errors, it setups the commands as "NotSetup" and generates a debug for admins to fix their configuration. - * @return true if there wasn't any error, otherwise false. - */ - public static boolean loadPluginConfig(BSkyBlock plugin) { - plugin.saveDefaultConfig(); - - // Initialize the errors list - HashMap errors = new HashMap<>(); - - //TODO config version - - // The order in this file should match the order in config.yml so that it's easy to check that everything is covered - - // ********************* General ********************* - Settings.checkUpdates = plugin.getConfig().getBoolean("general.check-updates", true); - - //loadLocales(plugin); - Settings.defaultLanguage = plugin.getConfig().getString("general.default-language", "en-US"); - //if(!plugin.getLocales().containsKey(Settings.defaultLanguage)) errors.put(ConfigError.UNKNOWN_LANGUAGE, Settings.defaultLanguage); - - Settings.useEconomy = plugin.getConfig().getBoolean("general.use-economy", true); - //Settings.useControlPanel = plugin.getConfig().getBoolean("general.use-control-panel", true); - - // Purge - Settings.purgeRemoveUserData = plugin.getConfig().getBoolean("general.purge.remove-user-data", false); - - // Database - String dbType = plugin.getConfig().getString("general.database.type","FLATFILE"); - boolean found = false; - for (DatabaseType type: DatabaseType.values()) { - if (type.name().equals(dbType.toUpperCase())) { - Settings.databaseType = type; - found = true; - break; - } - } - if (!found) { - plugin.getLogger().severe("Database type not found! Using FLATFILE"); - Settings.databaseType = DatabaseType.FLATFILE; - } - Settings.dbHost = plugin.getConfig().getString("general.database.host", "localhost"); - Settings.dbPort = plugin.getConfig().getInt("general.database.port",3306); - Settings.dbName = plugin.getConfig().getString("general.database.name", "BSkyBlock"); - Settings.dbUsername = plugin.getConfig().getString("general.database.username"); - Settings.dbPassword = plugin.getConfig().getString("general.database.password"); - - //Settings.ftbAutoActivator = plugin.getConfig().getBoolean("general.FTB-auto-activator", false); - Settings.allowObsidianScooping = plugin.getConfig().getBoolean("general.allow-obsidian-scooping", true); - - // Allow teleport - //Settings.fallingAllowTeleport = plugin.getConfig().getBoolean("general.allow-teleport.falling", true); - //Settings.fallingBlockedCommands = plugin.getConfig().getStringList("general.allow-teleport.falling-blocked-commands"); - //Settings.acidAllowTeleport = plugin.getConfig().getBoolean("general.allow-teleport.acid", true); - //Settings.acidBlockedCommands = plugin.getConfig().getStringList("general.allow-teleport.acid-blocked-commands"); - - // ********************* World ********************* - Settings.worldName = plugin.getConfig().getString("world.world-name", "BSkyBlock_world"); - //TODO check if it is the same than before - - int distance = plugin.getConfig().getInt("world.distance", 208); - Settings.islandDistance = Math.round((long)distance/16) * 16; - if(distance < 48) errors.put(ConfigError.ISLAND_DISTANCE_TOO_LOW, Settings.islandDistance); - - Settings.islandProtectionRange = plugin.getConfig().getInt("world.protection-range", 100); - if(Settings.islandProtectionRange < 0) errors.put(ConfigError.PROTECTION_RANGE_TOO_LOW, Settings.islandProtectionRange); - if(Settings.islandProtectionRange > Settings.islandDistance) errors.put(ConfigError.PROTECTION_RANGE_HIGHER_THAN_ISLAND_DISTANCE, Settings.islandProtectionRange); - - //Settings.startX = plugin.getConfig().getInt("world.start-x", 0); - //Settings.startZ = plugin.getConfig().getInt("world.start-z", 0); - Settings.islandHeight = plugin.getConfig().getInt("world.island-height", 120); - if(Settings.islandHeight < 5) errors.put(ConfigError.ISLAND_HEIGHT_TOO_LOW, Settings.islandHeight); - Settings.seaHeight = plugin.getConfig().getInt("world.sea-height", 0); - - Settings.maxIslands = plugin.getConfig().getInt("world.max-islands", 0); - - // Nether - Settings.netherGenerate = plugin.getConfig().getBoolean("world.nether.generate", true); - Settings.netherIslands = plugin.getConfig().getBoolean("world.nether.islands", true); - Settings.netherTrees = plugin.getConfig().getBoolean("world.nether.trees", true); - Settings.netherRoof = plugin.getConfig().getBoolean("world.nether.roof", true); - Settings.netherSpawnRadius = plugin.getConfig().getInt("world.nether.spawn-radius", 25); - if(!Settings.netherIslands){ - // If the nether is vanilla - if(Settings.netherSpawnRadius < 0) errors.put(ConfigError.NETHER_SPAWN_RADIUS_TOO_LOW, Settings.netherSpawnRadius); - if(Settings.netherSpawnRadius > 100) errors.put(ConfigError.NETHER_SPAWN_RADIUS_TOO_HIGH, Settings.netherSpawnRadius); - } - // TODO: add to config - Settings.endGenerate = true; - Settings.endIslands = false; - Settings.limitedBlocks = new HashMap<>(); - Settings.defaultFlags = new HashMap<>(); - - // Team - Settings.maxTeamSize = plugin.getConfig().getInt("island.max-team-size", 4); - //Settings.leaveConfirmation = plugin.getConfig().getBoolean("require-confirmation.leave", true); - //Settings.leaveConfirmWait = plugin.getConfig().getLong("require-confirmation.leave-wait", 10) * 20; - - //TODO end loading - - //TODO not setup error report - - return true; - } - - public static void loadLocales(BSkyBlock plugin){ - //TODO Imperatively load en-US locale - } -} \ No newline at end of file diff --git a/src/main/java/us/tastybento/bskyblock/database/BSBDatabase.java b/src/main/java/us/tastybento/bskyblock/database/BSBDatabase.java index 399737546..c11ca287e 100755 --- a/src/main/java/us/tastybento/bskyblock/database/BSBDatabase.java +++ b/src/main/java/us/tastybento/bskyblock/database/BSBDatabase.java @@ -1,8 +1,6 @@ package us.tastybento.bskyblock.database; -import org.bukkit.plugin.Plugin; - -import us.tastybento.bskyblock.Settings; +import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.database.flatfile.FlatFileDatabase; import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler; import us.tastybento.bskyblock.database.mysql.MySQLDatabase; @@ -14,9 +12,9 @@ public abstract class BSBDatabase { * FLATFILE and MYSQL. Default is FLATFILE * @return Database type */ - public static BSBDatabase getDatabase(){ + public static BSBDatabase getDatabase(BSkyBlock plugin){ for(DatabaseType type : DatabaseType.values()){ - if(type == Settings.databaseType) return type.database; + if(type == plugin.getSettings().getDatabaseType()) return type.database; } return DatabaseType.FLATFILE.database; } @@ -38,6 +36,6 @@ public abstract class BSBDatabase { * @param dataObjectClass * @return database handler */ - public abstract AbstractDatabaseHandler getHandler(Plugin plugin, Class dataObjectClass); + public abstract AbstractDatabaseHandler getHandler(BSkyBlock plugin, Class dataObjectClass); } \ No newline at end of file diff --git a/src/main/java/us/tastybento/bskyblock/database/DatabaseConnectionSettingsImpl.java b/src/main/java/us/tastybento/bskyblock/database/DatabaseConnectionSettingsImpl.java index 3accdf9a4..d4065f53b 100644 --- a/src/main/java/us/tastybento/bskyblock/database/DatabaseConnectionSettingsImpl.java +++ b/src/main/java/us/tastybento/bskyblock/database/DatabaseConnectionSettingsImpl.java @@ -1,7 +1,5 @@ package us.tastybento.bskyblock.database; -import us.tastybento.bskyblock.Settings; - public class DatabaseConnectionSettingsImpl { private String host; private int port; @@ -25,14 +23,6 @@ public class DatabaseConnectionSettingsImpl { this.password = password; } - public DatabaseConnectionSettingsImpl() { - this.host = Settings.dbHost; - this.port = Settings.dbPort; - this.databaseName = Settings.dbName; - this.username = Settings.dbUsername; - this.password = Settings.dbPassword; - } - /** * @return the host */ diff --git a/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabase.java b/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabase.java index c20f15112..23a61d8b0 100755 --- a/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabase.java +++ b/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabase.java @@ -1,14 +1,13 @@ package us.tastybento.bskyblock.database.flatfile; -import org.bukkit.plugin.Plugin; - +import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.database.BSBDatabase; import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler; public class FlatFileDatabase extends BSBDatabase{ @Override - public AbstractDatabaseHandler getHandler(Plugin plugin, Class type) { + public AbstractDatabaseHandler getHandler(BSkyBlock plugin, Class type) { return new FlatFileDatabaseHandler<>(plugin, type, new FlatFileDatabaseConnecter(plugin, null)); } diff --git a/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseHandler.java b/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseHandler.java index aced7a4d9..0d4189552 100644 --- a/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseHandler.java +++ b/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseHandler.java @@ -24,10 +24,9 @@ import org.bukkit.configuration.MemorySection; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.Plugin; -import us.tastybento.bskyblock.Settings; +import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.configuration.ConfigEntry; import us.tastybento.bskyblock.api.configuration.ConfigEntry.GameType; -import us.tastybento.bskyblock.api.configuration.ConfigEntry.NoAdapter; import us.tastybento.bskyblock.config.StoreAt; import us.tastybento.bskyblock.database.DatabaseConnecter; import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler; @@ -172,7 +171,7 @@ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { if (!configEntry.path().isEmpty()) { storageLocation = configEntry.path(); } - if (!configEntry.specificTo().equals(GameType.BOTH) && !configEntry.specificTo().equals(Settings.GAMETYPE)) { + if (!configEntry.specificTo().equals(GameType.BOTH) && !configEntry.specificTo().equals(Constants.GAMETYPE)) { Bukkit.getLogger().info(field.getName() + " not applicable to this game type"); continue; } diff --git a/src/main/java/us/tastybento/bskyblock/database/managers/PlayersManager.java b/src/main/java/us/tastybento/bskyblock/database/managers/PlayersManager.java index 0a4da0910..2c3fc50c5 100644 --- a/src/main/java/us/tastybento/bskyblock/database/managers/PlayersManager.java +++ b/src/main/java/us/tastybento/bskyblock/database/managers/PlayersManager.java @@ -15,7 +15,7 @@ import org.bukkit.Location; import org.bukkit.entity.Player; import us.tastybento.bskyblock.BSkyBlock; -import us.tastybento.bskyblock.Settings; +import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.database.BSBDatabase; import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Players; @@ -40,7 +40,7 @@ public class PlayersManager{ @SuppressWarnings("unchecked") public PlayersManager(BSkyBlock plugin){ this.plugin = plugin; - database = BSBDatabase.getDatabase(); + database = BSBDatabase.getDatabase(plugin); // Set up the database handler to store and retrieve Players classes handler = (AbstractDatabaseHandler) database.getHandler(plugin, Players.class); playerCache = new HashMap<>(); @@ -138,7 +138,7 @@ public class PlayersManager{ } else { if (DEBUG) plugin.getLogger().info("DEBUG: new player"); - player = new Players(playerUUID); + player = new Players(plugin, playerUUID); } playerCache.put(playerUUID, player); return player; @@ -506,7 +506,7 @@ public class PlayersManager{ addPlayer(targetUUID); // Check if the target player has a permission bypass (admin.noban) Player target = plugin.getServer().getPlayer(targetUUID); - if (target != null && target.hasPermission(Settings.PERMPREFIX + "admin.noban")) { + if (target != null && target.hasPermission(Constants.PERMPREFIX + "admin.noban")) { return false; } Island island = plugin.getIslands().getIsland(playerUUID); diff --git a/src/main/java/us/tastybento/bskyblock/database/managers/island/IslandCache.java b/src/main/java/us/tastybento/bskyblock/database/managers/island/IslandCache.java index 715bdfcbc..928a49199 100644 --- a/src/main/java/us/tastybento/bskyblock/database/managers/island/IslandCache.java +++ b/src/main/java/us/tastybento/bskyblock/database/managers/island/IslandCache.java @@ -17,7 +17,6 @@ import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import us.tastybento.bskyblock.BSkyBlock; -import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.util.Util; @@ -136,7 +135,7 @@ public class IslandCache { public Island createIsland(Location location, UUID owner){ if (DEBUG) plugin.getLogger().info("DEBUG: adding island for " + owner + " at " + location); - Island island = new Island(location, owner, Settings.islandProtectionRange); + Island island = new Island(plugin, location, owner, plugin.getSettings().getIslandProtectionRange()); islandsByLocation.put(location, island); if (owner != null) islandsByUUID.put(owner, island); diff --git a/src/main/java/us/tastybento/bskyblock/database/managers/island/IslandsManager.java b/src/main/java/us/tastybento/bskyblock/database/managers/island/IslandsManager.java index 7eff9c772..bd6890f6f 100644 --- a/src/main/java/us/tastybento/bskyblock/database/managers/island/IslandsManager.java +++ b/src/main/java/us/tastybento/bskyblock/database/managers/island/IslandsManager.java @@ -20,12 +20,11 @@ import org.bukkit.material.TrapDoor; import org.bukkit.util.Vector; import us.tastybento.bskyblock.BSkyBlock; +import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.User; -import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.database.BSBDatabase; import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler; import us.tastybento.bskyblock.database.objects.Island; -import us.tastybento.bskyblock.generators.IslandWorld; import us.tastybento.bskyblock.util.DeleteIslandChunks; import us.tastybento.bskyblock.util.SafeSpotTeleport; import us.tastybento.bskyblock.util.Util; @@ -50,7 +49,7 @@ public class IslandsManager { * - Location to be checked * @return true if safe, otherwise false */ - public static boolean isSafeLocation(final Location l) { + public boolean isSafeLocation(final Location l) { if (l == null) { return false; } @@ -76,7 +75,7 @@ public class IslandsManager { // In BSkyBlock, liquid may be unsafe if (ground.isLiquid() || space1.isLiquid() || space2.isLiquid()) { // Check if acid has no damage - if (Settings.acidDamage > 0D) { + if (plugin.getSettings().getAcidDamage() > 0D) { // Bukkit.getLogger().info("DEBUG: acid"); return false; } else if (ground.getType().equals(Material.STATIONARY_LAVA) || ground.getType().equals(Material.LAVA) @@ -141,7 +140,7 @@ public class IslandsManager { @SuppressWarnings("unchecked") public IslandsManager(BSkyBlock plugin){ this.plugin = plugin; - database = BSBDatabase.getDatabase(); + database = BSBDatabase.getDatabase(plugin); // Set up the database handler to store and retrieve Island classes handler = (AbstractDatabaseHandler) database.getHandler(plugin, Island.class); islandCache = new IslandCache(); @@ -248,7 +247,7 @@ public class IslandsManager { public Island createIsland(Location location, UUID owner){ if (DEBUG) plugin.getLogger().info("DEBUG: adding island for " + owner + " at " + location); - return islandCache.createIsland(new Island(location, owner, Settings.islandProtectionRange)); + return islandCache.createIsland(new Island(plugin, location, owner, plugin.getSettings().getIslandProtectionRange())); } /** @@ -625,7 +624,7 @@ public class IslandsManager { //player.sendBlockChange(home, Material.GLOWSTONE, (byte)0); User user = User.getInstance(player); if (number == 1) { - user.sendMessage("commands.island.go.teleport", "[label]", Settings.ISLANDCOMMAND); + user.sendMessage("commands.island.go.teleport", "[label]", Constants.ISLANDCOMMAND); } else { user.sendMessage("commands.island.go.island.go.teleported", "[number]", String.valueOf(number)); } @@ -696,7 +695,7 @@ public class IslandsManager { if (plugin.getPlayers().hasIsland(uuid) || plugin.getPlayers().inTeam(uuid)) { islandTestLocations.add(plugin.getIslands().getIslandLocation(uuid)); // If new Nether - if (Settings.netherGenerate && Settings.netherIslands && IslandWorld.getNetherWorld() != null) { + if (plugin.getSettings().isNetherGenerate() && plugin.getSettings().isNetherIslands() && plugin.getIslandWorldManager().getNetherWorld() != null) { islandTestLocations.add(netherIsland(plugin.getIslands().getIslandLocation(uuid))); } } @@ -713,7 +712,7 @@ public class IslandsManager { // Must be in the same world as the locations being checked // Note that getWorld can return null if a world has been deleted on the server if (islandTestLocation != null && islandTestLocation.getWorld() != null && islandTestLocation.getWorld().equals(loc.getWorld())) { - int protectionRange = Settings.islandProtectionRange; + int protectionRange = plugin.getSettings().getIslandProtectionRange(); if (getIslandAt(islandTestLocation) != null) { // Get the protection range for this location if possible Island island = getProtectedIslandAt(islandTestLocation); @@ -781,10 +780,10 @@ public class IslandsManager { // Run through all the locations for (Location islandTestLocation : islandTestLocations) { if (loc.getWorld().equals(islandTestLocation.getWorld())) { - if (loc.getX() >= islandTestLocation.getX() - Settings.islandProtectionRange - && loc.getX() < islandTestLocation.getX() + Settings.islandProtectionRange - && loc.getZ() >= islandTestLocation.getZ() - Settings.islandProtectionRange - && loc.getZ() < islandTestLocation.getZ() + Settings.islandProtectionRange) { + if (loc.getX() >= islandTestLocation.getX() - plugin.getSettings().getIslandProtectionRange() + && loc.getX() < islandTestLocation.getX() + plugin.getSettings().getIslandProtectionRange() + && loc.getZ() >= islandTestLocation.getZ() - plugin.getSettings().getIslandProtectionRange() + && loc.getZ() < islandTestLocation.getZ() + plugin.getSettings().getIslandProtectionRange()) { return true; } } @@ -807,7 +806,7 @@ public class IslandsManager { */ private Location netherIsland(Location islandLocation) { //plugin.getLogger().info("DEBUG: netherworld = " + ASkyBlock.getNetherWorld()); - return islandLocation.toVector().toLocation(IslandWorld.getNetherWorld()); + return islandLocation.toVector().toLocation(plugin.getIslandWorldManager().getNetherWorld()); } /** @@ -870,10 +869,10 @@ public class IslandsManager { Island spawn = getSpawn(); if (spawn != null) { // go to island spawn - player.teleport(IslandWorld.getIslandWorld().getSpawnLocation()); + player.teleport(plugin.getIslandWorldManager().getIslandWorld().getSpawnLocation()); //plugin.getLogger().warning("During island deletion player " + player.getName() + " sent to spawn."); } else { - if (!player.performCommand(Settings.SPAWNCOMMAND)) { + if (!player.performCommand(Constants.SPAWNCOMMAND)) { plugin.getLogger().warning( "During island deletion player " + player.getName() + " could not be sent to spawn so was dropped, sorry."); } diff --git a/src/main/java/us/tastybento/bskyblock/database/managers/island/NewIsland.java b/src/main/java/us/tastybento/bskyblock/database/managers/island/NewIsland.java index 8abe9eb9c..f80997618 100644 --- a/src/main/java/us/tastybento/bskyblock/database/managers/island/NewIsland.java +++ b/src/main/java/us/tastybento/bskyblock/database/managers/island/NewIsland.java @@ -10,9 +10,7 @@ import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.api.events.IslandBaseEvent; import us.tastybento.bskyblock.api.events.island.IslandEvent; import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason; -import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.database.objects.Island; -import us.tastybento.bskyblock.generators.IslandWorld; import us.tastybento.bskyblock.island.builders.IslandBuilder; import us.tastybento.bskyblock.island.builders.IslandBuilder.IslandType; @@ -23,13 +21,14 @@ import us.tastybento.bskyblock.island.builders.IslandBuilder.IslandType; */ public class NewIsland { private static final boolean DEBUG = false; - private final BSkyBlock plugin = BSkyBlock.getInstance(); + private BSkyBlock plugin; private Island island; private final Player player; private final Reason reason; - private NewIsland(Island oldIsland, Player player, Reason reason) { + private NewIsland(BSkyBlock plugin, Island oldIsland, Player player, Reason reason) { super(); + this.plugin = plugin; this.player = player; this.reason = reason; newIsland(); @@ -48,10 +47,11 @@ public class NewIsland { /** * Start building a new island + * @param plugin * @return New island builder object */ - public static Builder builder() { - return new Builder(); + public static Builder builder(BSkyBlock plugin) { + return new Builder(plugin); } /** @@ -63,6 +63,12 @@ public class NewIsland { private Island oldIsland; private Player player; private Reason reason; + private BSkyBlock plugin; + + public Builder(BSkyBlock plugin) { + this.plugin = plugin; + } + public Builder oldIsland(Island oldIsland) { this.oldIsland = oldIsland; @@ -82,7 +88,7 @@ public class NewIsland { public Island build() throws IOException { if (player != null) { - NewIsland newIsland = new NewIsland(oldIsland, player, reason); + NewIsland newIsland = new NewIsland(plugin, oldIsland, player, reason); return newIsland.getIsland(); } throw new IOException("Insufficient parameters. Must have a schematic and a player"); @@ -132,22 +138,22 @@ public class NewIsland { plugin.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { // Create island - new IslandBuilder(island) + new IslandBuilder(plugin, island) .setPlayer(player) - .setChestItems(Settings.chestItems) + .setChestItems(plugin.getSettings().getChestItems()) .setType(IslandType.ISLAND) .build(); - if (Settings.netherGenerate && Settings.netherIslands && IslandWorld.getNetherWorld() != null) { - new IslandBuilder(island) + if (plugin.getSettings().isNetherGenerate() && plugin.getSettings().isNetherIslands() && plugin.getIslandWorldManager().getNetherWorld() != null) { + new IslandBuilder(plugin,island) .setPlayer(player) - .setChestItems(Settings.chestItems) + .setChestItems(plugin.getSettings().getChestItems()) .setType(IslandType.NETHER) .build(); } - if (Settings.endGenerate && Settings.endIslands && IslandWorld.getEndWorld() != null) { - new IslandBuilder(island) + if (plugin.getSettings().isEndGenerate() && plugin.getSettings().isEndIslands() && plugin.getIslandWorldManager().getEndWorld() != null) { + new IslandBuilder(plugin,island) .setPlayer(player) - .setChestItems(Settings.chestItems) + .setChestItems(plugin.getSettings().getChestItems()) .setType(IslandType.END) .build(); } @@ -188,7 +194,8 @@ public class NewIsland { // Find the next free spot if (last == null) { - last = new Location(IslandWorld.getIslandWorld(), Settings.islandXOffset + Settings.islandStartX, Settings.islandHeight, Settings.islandZOffset + Settings.islandStartZ); + last = new Location(plugin.getIslandWorldManager().getIslandWorld(), plugin.getSettings().getIslandXOffset() + plugin.getSettings().getIslandStartX(), + plugin.getSettings().getIslandHeight(), plugin.getSettings().getIslandZOffset() + plugin.getSettings().getIslandStartZ()); } Location next = last.clone(); if (DEBUG) @@ -218,25 +225,25 @@ public class NewIsland { Location nextPos = lastIsland; if (x < z) { if (-1 * x < z) { - nextPos.setX(nextPos.getX() + Settings.islandDistance*2); + nextPos.setX(nextPos.getX() + plugin.getSettings().getIslandDistance()*2); return nextPos; } - nextPos.setZ(nextPos.getZ() + Settings.islandDistance*2); + nextPos.setZ(nextPos.getZ() + plugin.getSettings().getIslandDistance()*2); return nextPos; } if (x > z) { if (-1 * x >= z) { - nextPos.setX(nextPos.getX() - Settings.islandDistance*2); + nextPos.setX(nextPos.getX() - plugin.getSettings().getIslandDistance()*2); return nextPos; } - nextPos.setZ(nextPos.getZ() - Settings.islandDistance*2); + nextPos.setZ(nextPos.getZ() - plugin.getSettings().getIslandDistance()*2); return nextPos; } if (x <= 0) { - nextPos.setZ(nextPos.getZ() + Settings.islandDistance*2); + nextPos.setZ(nextPos.getZ() + plugin.getSettings().getIslandDistance()*2); return nextPos; } - nextPos.setZ(nextPos.getZ() - Settings.islandDistance*2); + nextPos.setZ(nextPos.getZ() - plugin.getSettings().getIslandDistance()*2); return nextPos; } } diff --git a/src/main/java/us/tastybento/bskyblock/database/mysql/MySQLDatabase.java b/src/main/java/us/tastybento/bskyblock/database/mysql/MySQLDatabase.java index d126bee51..e6c66c209 100755 --- a/src/main/java/us/tastybento/bskyblock/database/mysql/MySQLDatabase.java +++ b/src/main/java/us/tastybento/bskyblock/database/mysql/MySQLDatabase.java @@ -1,7 +1,6 @@ package us.tastybento.bskyblock.database.mysql; -import org.bukkit.plugin.Plugin; - +import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.database.BSBDatabase; import us.tastybento.bskyblock.database.DatabaseConnectionSettingsImpl; import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler; @@ -9,8 +8,14 @@ import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler; public class MySQLDatabase extends BSBDatabase{ @Override - public AbstractDatabaseHandler getHandler(Plugin plugin, Class type) { - return new MySQLDatabaseHandler<>(plugin, type, new MySQLDatabaseConnecter(new DatabaseConnectionSettingsImpl())); + public AbstractDatabaseHandler getHandler(BSkyBlock plugin, Class type) { + return new MySQLDatabaseHandler<>(plugin, type, new MySQLDatabaseConnecter(new DatabaseConnectionSettingsImpl( + plugin.getSettings().getDbHost(), + plugin.getSettings().getDbPort(), + plugin.getSettings().getDbName(), + plugin.getSettings().getDbUsername(), + plugin.getSettings().getDbPassword() + ))); } } diff --git a/src/main/java/us/tastybento/bskyblock/database/objects/DataObject.java b/src/main/java/us/tastybento/bskyblock/database/objects/DataObject.java index 2d5e6db82..ff97d66fe 100644 --- a/src/main/java/us/tastybento/bskyblock/database/objects/DataObject.java +++ b/src/main/java/us/tastybento/bskyblock/database/objects/DataObject.java @@ -1,20 +1,26 @@ package us.tastybento.bskyblock.database.objects; +import us.tastybento.bskyblock.BSkyBlock; + /** * Contains fields that must be in any data object * @author tastybento * */ -public abstract class DataObject { +public interface DataObject { + + default BSkyBlock getPlugin() { + return BSkyBlock.getInstance(); + } /** * @return the uniqueId */ - public abstract String getUniqueId(); + abstract String getUniqueId(); /** * @param uniqueId the uniqueId to set */ - public abstract void setUniqueId(String uniqueId); + abstract void setUniqueId(String uniqueId); } diff --git a/src/main/java/us/tastybento/bskyblock/database/objects/Island.java b/src/main/java/us/tastybento/bskyblock/database/objects/Island.java index 0e52e2a56..1cf2c1451 100755 --- a/src/main/java/us/tastybento/bskyblock/database/objects/Island.java +++ b/src/main/java/us/tastybento/bskyblock/database/objects/Island.java @@ -13,13 +13,13 @@ import org.bukkit.World; import org.bukkit.block.BlockState; import org.bukkit.entity.Entity; +import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.api.events.IslandBaseEvent; import us.tastybento.bskyblock.api.events.island.IslandEvent; import us.tastybento.bskyblock.api.events.island.IslandEvent.IslandLockEvent; import us.tastybento.bskyblock.api.events.island.IslandEvent.IslandUnlockEvent; import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason; import us.tastybento.bskyblock.api.flags.Flag; -import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.util.Util; /** @@ -30,11 +30,10 @@ import us.tastybento.bskyblock.util.Util; * @author Tastybento * @author Poslovitch */ -public class Island extends DataObject { +public class Island implements DataObject { private String uniqueId = ""; - @Override public String getUniqueId() { // Island's have UUID's that are randomly assigned if they do not exist if (uniqueId.isEmpty()) { @@ -43,7 +42,6 @@ public class Island extends DataObject { return uniqueId; } - @Override public void setUniqueId(String uniqueId) { this.uniqueId = uniqueId; } @@ -53,7 +51,7 @@ public class Island extends DataObject { private Location center; // Island range - private int range = Settings.islandDistance; + private int range; // Coordinates of the island area private int minX; @@ -104,15 +102,15 @@ public class Island extends DataObject { private Location spawnPoint; public Island() {} - - public Island(Location location, UUID owner, int protectionRange) { + + public Island(BSkyBlock plugin, Location location, UUID owner, int protectionRange) { this.members.add(owner); this.owner = owner; this.createdDate = System.currentTimeMillis(); this.updatedDate = System.currentTimeMillis(); this.world = location.getWorld(); this.center = location; - this.range = Settings.islandDistance; + this.range = plugin.getSettings().getIslandProtectionRange(); this.minX = center.getBlockX() - range; this.minZ = center.getBlockZ() - range; this.protectionRange = protectionRange; diff --git a/src/main/java/us/tastybento/bskyblock/database/objects/Players.java b/src/main/java/us/tastybento/bskyblock/database/objects/Players.java index 770a9f7ac..119cf2462 100755 --- a/src/main/java/us/tastybento/bskyblock/database/objects/Players.java +++ b/src/main/java/us/tastybento/bskyblock/database/objects/Players.java @@ -9,14 +9,14 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; -import us.tastybento.bskyblock.Settings; +import us.tastybento.bskyblock.BSkyBlock; /** * Tracks the following info on the player * * @author tastybento */ -public class Players extends DataObject { +public class Players implements DataObject { private HashMap homeLocations; private String uniqueId; private String playerName; @@ -31,15 +31,16 @@ public class Players extends DataObject { public Players() {} /** + * @param plugin * @param uniqueId * Constructor - initializes the state variables * */ - public Players(final UUID uniqueId) { + public Players(BSkyBlock plugin, final UUID uniqueId) { this.uniqueId = uniqueId.toString(); this.homeLocations = new HashMap<>(); this.playerName = ""; - this.resetsLeft = Settings.resetLimit; + this.resetsLeft = plugin.getSettings().getResetLimit(); this.locale = ""; this.kickedList = new HashMap<>(); this.playerName = Bukkit.getServer().getOfflinePlayer(uniqueId).getName(); @@ -200,8 +201,8 @@ public class Players extends DataObject { */ public void setDeaths(int deaths) { this.deaths = deaths; - if (this.deaths > Settings.deathsMax) { - this.deaths = Settings.deathsMax; + if (this.deaths > getPlugin().getSettings().getDeathsMax()) { + this.deaths = getPlugin().getSettings().getDeathsMax(); } } @@ -210,8 +211,8 @@ public class Players extends DataObject { */ public void addDeath() { this.deaths++; - if (this.deaths > Settings.deathsMax) { - this.deaths = Settings.deathsMax; + if (this.deaths > getPlugin().getSettings().getDeathsMax()) { + this.deaths = getPlugin().getSettings().getDeathsMax(); } } @@ -233,7 +234,7 @@ public class Players extends DataObject { Calendar coolDownTime = Calendar.getInstance(); coolDownTime.setTime(kickedDate); // coolDownTime.add(Calendar.HOUR_OF_DAY, Settings.inviteWait); - coolDownTime.add(Calendar.MINUTE, Settings.inviteWait); + coolDownTime.add(Calendar.MINUTE, getPlugin().getSettings().getInviteWait()); // Add the invite cooldown period Calendar timeNow = Calendar.getInstance(); // plugin.getLogger().info("DEBUG: date now = " + timeNow); diff --git a/src/main/java/us/tastybento/bskyblock/generators/ChunkGeneratorWorld.java b/src/main/java/us/tastybento/bskyblock/generators/ChunkGeneratorWorld.java index 77031ca18..daabe31b2 100644 --- a/src/main/java/us/tastybento/bskyblock/generators/ChunkGeneratorWorld.java +++ b/src/main/java/us/tastybento/bskyblock/generators/ChunkGeneratorWorld.java @@ -11,16 +11,25 @@ import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.ChunkGenerator; import org.bukkit.util.noise.PerlinOctaveGenerator; -import us.tastybento.bskyblock.Settings; +import us.tastybento.bskyblock.BSkyBlock; /** * @author tastybento * Creates the world */ public class ChunkGeneratorWorld extends ChunkGenerator { + + BSkyBlock plugin; Random rand = new Random(); PerlinOctaveGenerator gen; - //BSkyBlock plugin = BSkyBlock.getPlugin(); + + /** + * @param plugin + */ + public ChunkGeneratorWorld(BSkyBlock plugin) { + super(); + this.plugin = plugin; + } @Override public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, ChunkGenerator.BiomeGrid biomeGrid) { @@ -28,10 +37,10 @@ public class ChunkGeneratorWorld extends ChunkGenerator { return generateNetherChunks(world, random, chunkX, chunkZ, biomeGrid); } ChunkData result = createChunkData(world); - if (Settings.seaHeight != 0) { + if (plugin.getSettings().getSeaHeight() != 0) { for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { - for (int y = 0; y < Settings.seaHeight; y++) { + for (int y = 0; y < plugin.getSettings().getSeaHeight(); y++) { result.setBlock(x, y, z, Material.STATIONARY_WATER); } } @@ -64,7 +73,7 @@ public class ChunkGeneratorWorld extends ChunkGenerator { if (!world.getEnvironment().equals(Environment.NETHER)) { return result; } - if (Settings.netherRoof) { + if (plugin.getSettings().isNetherRoof()) { // Make the roof - common across the world for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { diff --git a/src/main/java/us/tastybento/bskyblock/generators/IslandWorld.java b/src/main/java/us/tastybento/bskyblock/generators/IslandWorld.java index 55c6a5eda..35f5dfd84 100644 --- a/src/main/java/us/tastybento/bskyblock/generators/IslandWorld.java +++ b/src/main/java/us/tastybento/bskyblock/generators/IslandWorld.java @@ -6,11 +6,10 @@ import org.bukkit.WorldCreator; import org.bukkit.WorldType; import us.tastybento.bskyblock.BSkyBlock; -import us.tastybento.bskyblock.Settings; public class IslandWorld { - //private BSkyBlock plugin; + private BSkyBlock plugin; private static World islandWorld; private static World netherWorld; private static World endWorld; @@ -19,37 +18,38 @@ public class IslandWorld { * Generates the Skyblock worlds. */ public IslandWorld(BSkyBlock plugin) { - if (Settings.useOwnGenerator) { + this.plugin = plugin; + if (plugin.getSettings().isUseOwnGenerator()) { // Do nothing return; } - if (plugin.getServer().getWorld(Settings.worldName) == null) { + if (plugin.getServer().getWorld(plugin.getSettings().getWorldName()) == null) { Bukkit.getLogger().info("Creating " + plugin.getName() + "'s Island World..."); } // Create the world if it does not exist - islandWorld = WorldCreator.name(Settings.worldName).type(WorldType.FLAT).environment(World.Environment.NORMAL).generator(new ChunkGeneratorWorld()) + islandWorld = WorldCreator.name(plugin.getSettings().getWorldName()).type(WorldType.FLAT).environment(World.Environment.NORMAL).generator(new ChunkGeneratorWorld(plugin)) .createWorld(); // Make the nether if it does not exist - if (Settings.netherGenerate) { - if (plugin.getServer().getWorld(Settings.worldName + "_nether") == null) { + if (plugin.getSettings().isNetherGenerate()) { + if (plugin.getServer().getWorld(plugin.getSettings().getWorldName() + "_nether") == null) { Bukkit.getLogger().info("Creating " + plugin.getName() + "'s Nether..."); } - if (!Settings.netherIslands) { - netherWorld = WorldCreator.name(Settings.worldName + "_nether").type(WorldType.NORMAL).environment(World.Environment.NETHER).createWorld(); + if (!plugin.getSettings().isNetherIslands()) { + netherWorld = WorldCreator.name(plugin.getSettings().getWorldName() + "_nether").type(WorldType.NORMAL).environment(World.Environment.NETHER).createWorld(); } else { - netherWorld = WorldCreator.name(Settings.worldName + "_nether").type(WorldType.FLAT).generator(new ChunkGeneratorWorld()) + netherWorld = WorldCreator.name(plugin.getSettings().getWorldName() + "_nether").type(WorldType.FLAT).generator(new ChunkGeneratorWorld(plugin)) .environment(World.Environment.NETHER).createWorld(); } } // Make the end if it does not exist - if (Settings.endGenerate) { - if (plugin.getServer().getWorld(Settings.worldName + "_the_end") == null) { + if (plugin.getSettings().isEndGenerate()) { + if (plugin.getServer().getWorld(plugin.getSettings().getWorldName() + "_the_end") == null) { Bukkit.getLogger().info("Creating " + plugin.getName() + "'s End World..."); } - if (!Settings.endIslands) { - endWorld = WorldCreator.name(Settings.worldName + "_the_end").type(WorldType.NORMAL).environment(World.Environment.THE_END).createWorld(); + if (!plugin.getSettings().isEndIslands()) { + endWorld = WorldCreator.name(plugin.getSettings().getWorldName() + "_the_end").type(WorldType.NORMAL).environment(World.Environment.THE_END).createWorld(); } else { - endWorld = WorldCreator.name(Settings.worldName + "_the_end").type(WorldType.FLAT).generator(new ChunkGeneratorWorld()) + endWorld = WorldCreator.name(plugin.getSettings().getWorldName() + "_the_end").type(WorldType.FLAT).generator(new ChunkGeneratorWorld(plugin)) .environment(World.Environment.THE_END).createWorld(); } } @@ -62,22 +62,22 @@ public class IslandWorld { Bukkit.getLogger().info("Trying to register generator with Multiverse "); try { Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), - "mv import " + Settings.worldName + " normal -g " + plugin.getName()); + "mv import " + plugin.getSettings().getWorldName() + " normal -g " + plugin.getName()); if (!Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), - "mv modify set generator " + plugin.getName() + " " + Settings.worldName)) { + "mv modify set generator " + plugin.getName() + " " + plugin.getSettings().getWorldName())) { Bukkit.getLogger().severe("Multiverse is out of date! - Upgrade to latest version!"); } - if (netherWorld != null && Settings.netherGenerate && Settings.netherIslands) { + if (netherWorld != null && plugin.getSettings().isNetherGenerate() && plugin.getSettings().isNetherIslands()) { Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), - "mv import " + Settings.worldName + "_nether nether -g " + plugin.getName()); + "mv import " + plugin.getSettings().getWorldName() + "_nether nether -g " + plugin.getName()); Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), - "mv modify set generator " + plugin.getName() + " " + Settings.worldName + "_nether"); + "mv modify set generator " + plugin.getName() + " " + plugin.getSettings().getWorldName() + "_nether"); } - if (endWorld != null && Settings.endGenerate && Settings.endIslands) { + if (endWorld != null && plugin.getSettings().isEndGenerate() && plugin.getSettings().isEndIslands()) { Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), - "mv import " + Settings.worldName + "_the_end end -g " + plugin.getName()); + "mv import " + plugin.getSettings().getWorldName() + "_the_end end -g " + plugin.getName()); Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), - "mv modify set generator " + plugin.getName() + " " + Settings.worldName + "_the_end"); + "mv modify set generator " + plugin.getName() + " " + plugin.getSettings().getWorldName() + "_the_end"); } } catch (Exception e) { Bukkit.getLogger().severe("Not successfull! Disabling " + plugin.getName() + "!"); @@ -92,9 +92,9 @@ public class IslandWorld { /** * @return the islandWorld */ - public static World getIslandWorld() { - if (Settings.useOwnGenerator) { - return Bukkit.getServer().getWorld(Settings.worldName); + public World getIslandWorld() { + if (plugin.getSettings().isUseOwnGenerator()) { + return Bukkit.getServer().getWorld(plugin.getSettings().getWorldName()); } return islandWorld; } @@ -102,9 +102,9 @@ public class IslandWorld { /** * @return the netherWorld */ - public static World getNetherWorld() { - if (Settings.useOwnGenerator) { - return Bukkit.getServer().getWorld(Settings.worldName + "_nether"); + public World getNetherWorld() { + if (plugin.getSettings().isUseOwnGenerator()) { + return Bukkit.getServer().getWorld(plugin.getSettings().getWorldName() + "_nether"); } return netherWorld; } @@ -112,9 +112,9 @@ public class IslandWorld { /** * @return the endWorld */ - public static World getEndWorld() { - if (Settings.useOwnGenerator) { - return Bukkit.getServer().getWorld(Settings.worldName + "_the_end"); + public World getEndWorld() { + if (plugin.getSettings().isUseOwnGenerator()) { + return Bukkit.getServer().getWorld(plugin.getSettings().getWorldName() + "_the_end"); } return endWorld; } diff --git a/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilder.java b/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilder.java index 478e21335..ae0d6c637 100644 --- a/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilder.java +++ b/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilder.java @@ -16,11 +16,11 @@ import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.material.Chest; -import us.tastybento.bskyblock.Settings; +import us.tastybento.bskyblock.BSkyBlock; +import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.configuration.ConfigEntry.GameType; import us.tastybento.bskyblock.database.objects.Island; -import us.tastybento.bskyblock.generators.IslandWorld; /** * Fired when a team event happens. @@ -44,9 +44,11 @@ public class IslandBuilder { //private List companions = new ArrayList<>(); private UUID playerUUID; private String playerName; + private BSkyBlock plugin; - public IslandBuilder(Island island) { + public IslandBuilder(BSkyBlock plugin, Island island) { super(); + this.plugin = plugin; this.island = island; this.world = island.getWorld(); } @@ -59,13 +61,13 @@ public class IslandBuilder { this.type = type; switch(type) { case END: - this.world = IslandWorld.getEndWorld(); + this.world = plugin.getIslandWorldManager().getEndWorld(); break; case ISLAND: - this.world = IslandWorld.getIslandWorld(); + this.world = plugin.getIslandWorldManager().getIslandWorld(); break; case NETHER: - this.world = IslandWorld.getNetherWorld(); + this.world = plugin.getIslandWorldManager().getNetherWorld(); break; default: this.world = island.getWorld(); @@ -98,7 +100,7 @@ public class IslandBuilder { public void build() { // Switch on island type if (type == IslandType.ISLAND) { - if (Settings.GAMETYPE == GameType.ACIDISLAND) { + if (Constants.GAMETYPE == GameType.ACIDISLAND) { generateAcidIslandBlocks(); } else { generateIslandBlocks(); diff --git a/src/main/java/us/tastybento/bskyblock/listeners/JoinLeaveListener.java b/src/main/java/us/tastybento/bskyblock/listeners/JoinLeaveListener.java index 0c3f457a4..9d26ec79a 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/JoinLeaveListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/JoinLeaveListener.java @@ -10,8 +10,8 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import us.tastybento.bskyblock.BSkyBlock; +import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.User; -import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.database.managers.PlayersManager; import us.tastybento.bskyblock.database.objects.Island; @@ -46,8 +46,8 @@ public class JoinLeaveListener implements Listener { // Load player players.addPlayer(playerUUID); // Reset resets if the admin changes it to or from unlimited - if (Settings.resetLimit < players.getResetsLeft(playerUUID) || (Settings.resetLimit >= 0 && players.getResetsLeft(playerUUID) < 0)) { - players.setResetsLeft(playerUUID, Settings.resetLimit); + if (plugin.getSettings().getResetLimit() < players.getResetsLeft(playerUUID) || (plugin.getSettings().getResetLimit() >= 0 && players.getResetsLeft(playerUUID) < 0)) { + players.setResetsLeft(playerUUID, plugin.getSettings().getResetLimit()); } if (DEBUG) plugin.getLogger().info("DEBUG: Setting player's name"); @@ -62,7 +62,7 @@ public class JoinLeaveListener implements Listener { } else { plugin.getLogger().warning("Player that just logged in has no name! " + playerUUID.toString()); } - if (Settings.removeMobsOnLogin) { + if (plugin.getSettings().isRemoveMobsOnLogin()) { if (DEBUG) plugin.getLogger().info("DEBUG: Removing mobs"); plugin.getIslands().removeMobs(player.getLocation()); @@ -73,7 +73,7 @@ public class JoinLeaveListener implements Listener { if (currentIsland != null && (currentIsland.isLocked() || plugin.getPlayers().isBanned(currentIsland.getOwner(),player.getUniqueId()))) { if (DEBUG) plugin.getLogger().info("DEBUG: Current island is locked, or player is banned"); - if (!currentIsland.getMembers().contains(playerUUID) && !player.hasPermission(Settings.PERMPREFIX + "mod.bypassprotect")) { + if (!currentIsland.getMembers().contains(playerUUID) && !player.hasPermission(Constants.PERMPREFIX + "mod.bypassprotect")) { if (DEBUG) plugin.getLogger().info("DEBUG: No bypass - teleporting"); user.sendMessage("locked.islandlocked"); diff --git a/src/main/java/us/tastybento/bskyblock/managers/FlagsManager.java b/src/main/java/us/tastybento/bskyblock/managers/FlagsManager.java index 249488f75..1bc1cc914 100644 --- a/src/main/java/us/tastybento/bskyblock/managers/FlagsManager.java +++ b/src/main/java/us/tastybento/bskyblock/managers/FlagsManager.java @@ -1,13 +1,14 @@ package us.tastybento.bskyblock.managers; -import org.bukkit.Bukkit; -import us.tastybento.bskyblock.BSkyBlock; -import us.tastybento.bskyblock.api.flags.Flag; -import us.tastybento.bskyblock.api.panels.PanelItem; - import java.util.ArrayList; import java.util.List; +import org.bukkit.Bukkit; + +import us.tastybento.bskyblock.BSkyBlock; +import us.tastybento.bskyblock.api.flags.Flag; +import us.tastybento.bskyblock.api.panels.PanelItem; + public final class FlagsManager { private List flags = new ArrayList<>(); diff --git a/src/main/java/us/tastybento/bskyblock/managers/LocalesManager.java b/src/main/java/us/tastybento/bskyblock/managers/LocalesManager.java index 268d89cc1..10c52e361 100644 --- a/src/main/java/us/tastybento/bskyblock/managers/LocalesManager.java +++ b/src/main/java/us/tastybento/bskyblock/managers/LocalesManager.java @@ -8,7 +8,6 @@ import java.util.Locale; import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.localization.BSBLocale; -import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.util.FileLister; /** @@ -23,7 +22,7 @@ public final class LocalesManager { public LocalesManager(BSkyBlock plugin) { this.plugin = plugin; - this.loadLocales("BSB"); // Default + this.loadLocales(""); // Default } /** @@ -37,8 +36,8 @@ public final class LocalesManager { if (locale != null && locale.contains(reference)) return locale.get(reference); // Return the default - if (languages.get(Locale.forLanguageTag(Settings.defaultLanguage)).contains(reference)) { - return languages.get(Locale.forLanguageTag(Settings.defaultLanguage)).get(reference); + if (languages.get(Locale.forLanguageTag(plugin.getSettings().getDefaultLanguage())).contains(reference)) { + return languages.get(Locale.forLanguageTag(plugin.getSettings().getDefaultLanguage())).get(reference); } return null; } @@ -49,25 +48,38 @@ public final class LocalesManager { * TODO: Make more robust. The file filter is fragile. */ public void loadLocales(String parent) { + if (DEBUG) { + if (parent.isEmpty()) + plugin.getLogger().info("DEBUG: loading locale for BSkyBlock"); + else + plugin.getLogger().info("DEBUG: loading locale for " + parent); + } // Describe the filter - we only want files that are correctly named FilenameFilter ymlFilter = new FilenameFilter() { @Override public boolean accept(File dir, String name) { - //plugin.getLogger().info("DEBUG: filename = " + name + " parent = " + parent ); - if (name.startsWith(parent) && name.toLowerCase().endsWith(".yml")) { - // See if this is a valid locale - if (name.length() < 9) - return false; - //Locale localeObject = Locale.forLanguageTag(name.substring(name.length() - 9, name.length() - 4)); - - return true; + // Do BSkyBlock files + if (parent.isEmpty()) { + if (name.toLowerCase().endsWith(".yml") && name.length() == 9) { + if (DEBUG) + plugin.getLogger().info("DEBUG: bsb locale filename = " + name); + return true; + } + return false; + } else { + // Addon locales + if (name.startsWith(parent) && name.toLowerCase().endsWith(".yml")) { + if (DEBUG) + plugin.getLogger().info("DEBUG: addon locale filename = " + name); + return true; + } + return false; } - return false; } }; // Run through the files and store the locales - File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER + "/" + parent); + File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER); // If the folder does not exist, then make it and fill with the locale files from the jar // If it does exist, then new files will NOT be written! if (!localeDir.exists()) { @@ -90,9 +102,13 @@ public final class LocalesManager { if (DEBUG) plugin.getLogger().info("DEBUG: locale country found = " + localeObject.getCountry()); if (languages.containsKey(localeObject)) { + if (DEBUG) + plugin.getLogger().info("DEBUG: this locale is known"); // Merge into current language languages.get(localeObject).merge(language); } else { + if (DEBUG) + plugin.getLogger().info("DEBUG: this locale is not known - new language"); // New language languages.put(localeObject, new BSBLocale(localeObject, language)); } diff --git a/src/main/java/us/tastybento/bskyblock/util/DeleteIslandChunks.java b/src/main/java/us/tastybento/bskyblock/util/DeleteIslandChunks.java index a97bd7eec..ed7bd594b 100644 --- a/src/main/java/us/tastybento/bskyblock/util/DeleteIslandChunks.java +++ b/src/main/java/us/tastybento/bskyblock/util/DeleteIslandChunks.java @@ -6,9 +6,7 @@ import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.api.events.IslandBaseEvent; import us.tastybento.bskyblock.api.events.island.IslandEvent; import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason; -import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.database.objects.Island; -import us.tastybento.bskyblock.generators.IslandWorld; //import com.wasteofplastic.askyblock.nms.NMSAbstraction; @@ -42,12 +40,12 @@ public class DeleteIslandChunks { for (int x = minXChunk; x <= maxXChunk; x++) { for (int z = minZChunk; z<=maxZChunk; z++) { world.regenerateChunk(x, z); - if (Settings.netherIslands && Settings.netherGenerate) { - IslandWorld.getNetherWorld().regenerateChunk(x, z); + if (plugin.getSettings().isNetherGenerate() && plugin.getSettings().isNetherIslands()) { + plugin.getIslandWorldManager().getNetherWorld().regenerateChunk(x, z); } - if (Settings.endIslands && Settings.endGenerate) { - IslandWorld.getEndWorld().regenerateChunk(x, z); + if (plugin.getSettings().isEndGenerate() && plugin.getSettings().isEndIslands()) { + plugin.getIslandWorldManager().getEndWorld().regenerateChunk(x, z); } } } diff --git a/src/main/java/us/tastybento/bskyblock/util/Util.java b/src/main/java/us/tastybento/bskyblock/util/Util.java index d93f0f9c8..079ba2252 100755 --- a/src/main/java/us/tastybento/bskyblock/util/Util.java +++ b/src/main/java/us/tastybento/bskyblock/util/Util.java @@ -27,8 +27,6 @@ import org.bukkit.plugin.Plugin; import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.api.commands.User; -import us.tastybento.bskyblock.Settings; -import us.tastybento.bskyblock.generators.IslandWorld; /** * A set of utility methods @@ -37,7 +35,6 @@ import us.tastybento.bskyblock.generators.IslandWorld; * @author Poslovitch */ public class Util { - private static BSkyBlock plugin = BSkyBlock.getInstance(); private static String serverVersion = null; @@ -47,7 +44,7 @@ public class Util { */ public static String getServerVersion() { if (serverVersion == null) { - String serverPackageName = plugin.getServer().getClass().getPackage().getName(); + String serverPackageName = getPlugin().getServer().getClass().getPackage().getName(); serverVersion = serverPackageName.substring(serverPackageName.lastIndexOf('.') + 1); } return serverVersion; @@ -135,8 +132,8 @@ public class Util { @SuppressWarnings("deprecation") public static List getPlayerInHandItems(Player player) { List result = new ArrayList(2); - if (plugin.getServer().getVersion().contains("(MC: 1.7") - || plugin.getServer().getVersion().contains("(MC: 1.8")) { + if (getPlugin().getServer().getVersion().contains("(MC: 1.7") + || getPlugin().getServer().getVersion().contains("(MC: 1.8")) { if (player.getItemInHand() != null) result.add(player.getItemInHand()); return result; @@ -185,8 +182,8 @@ public class Util { */ @SuppressWarnings("deprecation") public static boolean playerIsHolding(Player player, Material type) { - if (plugin.getServer().getVersion().contains("(MC: 1.7") - || plugin.getServer().getVersion().contains("(MC: 1.8")) { + if (getPlugin().getServer().getVersion().contains("(MC: 1.7") + || getPlugin().getServer().getVersion().contains("(MC: 1.8")) { if (player.getItemInHand() != null && player.getItemInHand().getType().equals(type)) { return true; } @@ -209,13 +206,13 @@ public class Util { */ public static boolean inWorld(Location loc) { if (loc != null) { - if (loc.getWorld().equals(IslandWorld.getIslandWorld())) { + if (loc.getWorld().equals(getPlugin().getIslandWorldManager().getIslandWorld())) { return true; } - if (Settings.netherIslands && loc.getWorld().equals(IslandWorld.getNetherWorld())) { + if (getPlugin().getSettings().isNetherIslands() && loc.getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) { return true; } - if (Settings.endIslands && loc.getWorld().equals(IslandWorld.getEndWorld())) { + if (getPlugin().getSettings().isEndIslands() && loc.getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) { return true; } } @@ -320,7 +317,7 @@ public class Util { } public static void runCommand(final Player player, final String string) { - plugin.getServer().getScheduler().runTask(plugin, new Runnable() { + getPlugin().getServer().getScheduler().runTask(getPlugin(), new Runnable() { @Override public void run() { @@ -364,7 +361,7 @@ public class Util { // In ASkyBlock, liquid may be unsafe if (ground.isLiquid() || space1.isLiquid() || space2.isLiquid()) { // Check if acid has no damage - if (Settings.acidDamage > 0D) { + if (getPlugin().getSettings().getAcidDamage() > 0D) { // Bukkit.getLogger().info("DEBUG: acid"); return false; } else if (ground.getType().equals(Material.STATIONARY_LAVA) || ground.getType().equals(Material.LAVA) @@ -427,7 +424,7 @@ public class Util { String[] spl = perms.getPermission().split(perm + "."); if (spl.length > 1) { if (!NumberUtils.isDigits(spl[1])) { - plugin.getLogger().severe("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring..."); + getPlugin().getLogger().severe("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring..."); } else { permValue = Math.max(permValue, Integer.valueOf(spl[1])); @@ -443,4 +440,12 @@ public class Util { return permValue; } + /** + * @return the plugin + */ + public static BSkyBlock getPlugin() { + return BSkyBlock.getInstance(); + } + + } diff --git a/src/test/java/bskyblock/TestBSkyBlock.java b/src/test/java/bskyblock/TestBSkyBlock.java index 15d515937..907129ff1 100644 --- a/src/test/java/bskyblock/TestBSkyBlock.java +++ b/src/test/java/bskyblock/TestBSkyBlock.java @@ -26,11 +26,11 @@ import org.junit.Test; import org.mockito.Mockito; import us.tastybento.bskyblock.BSkyBlock; +import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.events.IslandBaseEvent; import us.tastybento.bskyblock.api.events.team.TeamEvent; -import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.util.Util; public class TestBSkyBlock { @@ -56,7 +56,7 @@ public class TestBSkyBlock { Mockito.when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger()); sender = mock(CommandSender.class); player = mock(Player.class); - Mockito.when(player.hasPermission(Settings.PERMPREFIX + "default.permission")).thenReturn(true); + Mockito.when(player.hasPermission(Constants.PERMPREFIX + "default.permission")).thenReturn(true); plugin = mock(BSkyBlock.class); //Mockito.when(plugin.getServer()).thenReturn(server); @@ -81,7 +81,7 @@ public class TestBSkyBlock { User user = User.getInstance(playerUUID); CompositeCommand testCommand = new TestCommand(); testCommand.setOnlyPlayer(true); - testCommand.setPermission(Settings.PERMPREFIX + "default.permission"); + testCommand.setPermission(Constants.PERMPREFIX + "default.permission"); // Test basic execution assertTrue(testCommand.execute(user, new ArrayList<>())); assertEquals("test",testCommand.getLabel()); @@ -89,7 +89,7 @@ public class TestBSkyBlock { assertEquals("t", testCommand.getAliases().get(0)); assertTrue(testCommand.isOnlyPlayer()); assertNull(testCommand.getParent()); - assertEquals(Settings.PERMPREFIX + "default.permission", testCommand.getPermission()); + assertEquals(Constants.PERMPREFIX + "default.permission", testCommand.getPermission()); // Check commands and aliases match to correct class for (Entry command : testCommand.getSubCommands().entrySet()) { assertEquals(testCommand.getSubCommand(command.getKey()), Optional.of(command.getValue())); @@ -123,7 +123,7 @@ public class TestBSkyBlock { // Test command arguments CompositeCommand argCmd = new Test3ArgsCommand(); argCmd.setOnlyPlayer(true); - argCmd.setPermission(Settings.PERMPREFIX + "default.permission"); + argCmd.setPermission(Constants.PERMPREFIX + "default.permission"); assertTrue(argCmd.execute(player, "args", new String[]{"give", "100", "ben"})); assertFalse(testCommand.execute(player, "test", new String[] {"sub2", "subsub", "subsubsub"})); assertFalse(testCommand.execute(player, "test", new String[] {"sub2", "subsub", "subsubsub", "ben"}));