diff --git a/src/com/projectkorra/projectkorra/GeneralMethods.java b/src/com/projectkorra/projectkorra/GeneralMethods.java index ebded911..27a552f3 100644 --- a/src/com/projectkorra/projectkorra/GeneralMethods.java +++ b/src/com/projectkorra/projectkorra/GeneralMethods.java @@ -99,6 +99,7 @@ import com.projectkorra.projectkorra.airbending.AirSpout; import com.projectkorra.projectkorra.airbending.AirSuction; import com.projectkorra.projectkorra.airbending.AirSwipe; import com.projectkorra.projectkorra.configuration.better.ConfigManager; +import com.projectkorra.projectkorra.configuration.better.configs.commands.BindCommandConfig; import com.projectkorra.projectkorra.configuration.better.configs.properties.ChatPropertiesConfig; import com.projectkorra.projectkorra.configuration.better.configs.properties.GeneralPropertiesConfig; import com.projectkorra.projectkorra.earthbending.EarthBlast; @@ -216,7 +217,7 @@ public class GeneralMethods { bPlayer.getAbilities().put(slot, ability); if (coreAbil != null) { - GeneralMethods.sendBrandingMessage(player, coreAbil.getElement().getColor() + ConfigManager.languageConfig.get().getString("Commands.Bind.SuccessfullyBound").replace("{ability}", ability).replace("{slot}", String.valueOf(slot))); + GeneralMethods.sendBrandingMessage(player, coreAbil.getElement().getColor() + ConfigManager.getConfig(BindCommandConfig.class).SuccessfullyBoundMessage.replace("{ability}", ability).replace("{slot}", String.valueOf(slot))); } saveAbility(bPlayer, slot, ability); } diff --git a/src/com/projectkorra/projectkorra/command/BindCommand.java b/src/com/projectkorra/projectkorra/command/BindCommand.java index 980d2284..b442e8c1 100644 --- a/src/com/projectkorra/projectkorra/command/BindCommand.java +++ b/src/com/projectkorra/projectkorra/command/BindCommand.java @@ -16,11 +16,13 @@ import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.ComboAbility; import com.projectkorra.projectkorra.ability.CoreAbility; import com.projectkorra.projectkorra.ability.PassiveAbility; -import com.projectkorra.projectkorra.configuration.ConfigManager; +import com.projectkorra.projectkorra.configuration.better.ConfigManager; +import com.projectkorra.projectkorra.configuration.better.configs.commands.BindCommandConfig; /** * Executor for /bending bind. Extends {@link PKCommand}. */ +@SuppressWarnings("rawtypes") public class BindCommand extends PKCommand { private final String abilityDoesntExist; @@ -33,16 +35,16 @@ public class BindCommand extends PKCommand { private final String unbindable; public BindCommand() { - super("bind", "/bending bind [Slot]", ConfigManager.languageConfig.get().getString("Commands.Bind.Description"), new String[] { "bind", "b" }); + super("bind", "/bending bind [Slot]", ConfigManager.getConfig(BindCommandConfig.class).Description, new String[] { "bind", "b" }); - this.abilityDoesntExist = ConfigManager.languageConfig.get().getString("Commands.Bind.AbilityDoesntExist"); - this.wrongNumber = ConfigManager.languageConfig.get().getString("Commands.Bind.WrongNumber"); - this.loadingInfo = ConfigManager.languageConfig.get().getString("Commands.Bind.LoadingInfo"); - this.toggledElementOff = ConfigManager.languageConfig.get().getString("Commands.Bind.ElementToggledOff"); - this.noElement = ConfigManager.languageConfig.get().getString("Commands.Bind.NoElement"); - this.noElementAE = ConfigManager.languageConfig.get().getString("Commands.Bind.NoElementAE"); - this.noSubElement = ConfigManager.languageConfig.get().getString("Commands.Bind.NoSubElement"); - this.unbindable = ConfigManager.languageConfig.get().getString("Commands.Bind.Unbindable"); + this.abilityDoesntExist = ConfigManager.getConfig(BindCommandConfig.class).AbilityDoesntExistMessage; + this.wrongNumber = ConfigManager.getConfig(BindCommandConfig.class).WrongNumberMessage; + this.loadingInfo = ConfigManager.getConfig(BindCommandConfig.class).LoadingInfoMessage; + this.toggledElementOff = ConfigManager.getConfig(BindCommandConfig.class).ElementToggledOffMessage; + this.noElement = ConfigManager.getConfig(BindCommandConfig.class).NoElementMessage; + this.noElementAE = ConfigManager.getConfig(BindCommandConfig.class).NoElementMessageAE; + this.noSubElement = ConfigManager.getConfig(BindCommandConfig.class).NoSubElementMessage; + this.unbindable = ConfigManager.getConfig(BindCommandConfig.class).UnbindableMessage; } @Override diff --git a/src/com/projectkorra/projectkorra/configuration/better/configs/abilities/water/WaterManipulationConfig.java b/src/com/projectkorra/projectkorra/configuration/better/configs/abilities/water/WaterManipulationConfig.java new file mode 100644 index 00000000..0c1182a3 --- /dev/null +++ b/src/com/projectkorra/projectkorra/configuration/better/configs/abilities/water/WaterManipulationConfig.java @@ -0,0 +1,21 @@ +package com.projectkorra.projectkorra.configuration.better.configs.abilities.water; + +public class WaterManipulationConfig extends SourcedWaterAbilityConfig { + + public final double SelectRange = 0; + + public WaterManipulationConfig() { + super(true, "", "", true, true); + } + + @Override + public String getName() { + return "WaterManipulation"; + } + + @Override + public String[] getParents() { + return new String[] { "Abilities", "Water" }; + } + +} \ No newline at end of file diff --git a/src/com/projectkorra/projectkorra/configuration/better/configs/commands/BindCommandConfig.java b/src/com/projectkorra/projectkorra/configuration/better/configs/commands/BindCommandConfig.java new file mode 100644 index 00000000..591dda4f --- /dev/null +++ b/src/com/projectkorra/projectkorra/configuration/better/configs/commands/BindCommandConfig.java @@ -0,0 +1,28 @@ +package com.projectkorra.projectkorra.configuration.better.configs.commands; + +import com.projectkorra.projectkorra.configuration.better.Config; + +public class BindCommandConfig implements Config { + + public final String Description = ""; + public final String SuccessfullyBoundMessage = ""; + public final String AbilityDoesntExistMessage = ""; + public final String WrongNumberMessage = ""; + public final String LoadingInfoMessage = ""; + public final String ElementToggledOffMessage = ""; + public final String NoElementMessage = ""; + public final String NoElementMessageAE = ""; + public final String NoSubElementMessage = ""; + public final String UnbindableMessage = ""; + + @Override + public String getName() { + return "Bind"; + } + + @Override + public String[] getParents() { + return new String[] { "Commands" }; + } + +} \ No newline at end of file diff --git a/src/com/projectkorra/projectkorra/configuration/better/configs/properties/EarthPropertiesConfig.java b/src/com/projectkorra/projectkorra/configuration/better/configs/properties/EarthPropertiesConfig.java index c627774a..227272bd 100644 --- a/src/com/projectkorra/projectkorra/configuration/better/configs/properties/EarthPropertiesConfig.java +++ b/src/com/projectkorra/projectkorra/configuration/better/configs/properties/EarthPropertiesConfig.java @@ -8,7 +8,13 @@ import com.projectkorra.projectkorra.configuration.better.Config; public class EarthPropertiesConfig implements Config { public final Material[] EarthBlocks = {}; + public final boolean RevertEarthbending = true; + public final long RevertCheckTime = 0; + public final boolean SafeRevert = true; + + public final boolean DynamicSourcing = true; + public final double MaxSelectRange = 0; public final boolean PlaySound = true; public final Sound SoundType = Sound.ENTITY_GHAST_SHOOT; diff --git a/src/com/projectkorra/projectkorra/configuration/better/configs/properties/GeneralPropertiesConfig.java b/src/com/projectkorra/projectkorra/configuration/better/configs/properties/GeneralPropertiesConfig.java index 4bd69e22..32c51c49 100644 --- a/src/com/projectkorra/projectkorra/configuration/better/configs/properties/GeneralPropertiesConfig.java +++ b/src/com/projectkorra/projectkorra/configuration/better/configs/properties/GeneralPropertiesConfig.java @@ -22,6 +22,13 @@ public class GeneralPropertiesConfig implements Config { public final boolean DatabaseCooldowns = true; + public final boolean UseMySQL = false; + public final String MySQL_Host = ""; + public final int MySQL_Port = 3306; + public final String MySQL_User = ""; + public final String MySQL_Password = ""; + public final String MySQL_Database = ""; + public final boolean BendingPreview = true; public final long GlobalCooldown = 0; diff --git a/src/com/projectkorra/projectkorra/configuration/better/configs/properties/WaterPropertiesConfig.java b/src/com/projectkorra/projectkorra/configuration/better/configs/properties/WaterPropertiesConfig.java index a93e8470..40d021f5 100644 --- a/src/com/projectkorra/projectkorra/configuration/better/configs/properties/WaterPropertiesConfig.java +++ b/src/com/projectkorra/projectkorra/configuration/better/configs/properties/WaterPropertiesConfig.java @@ -14,6 +14,10 @@ public class WaterPropertiesConfig implements Config { public final String DayMessage = ""; public final String NightMessage = ""; + public final boolean DynamicSourcing = true; + + public final double MaxSelectRange = 0; + public final boolean PlaySound = true; public final Sound SoundType = Sound.BLOCK_WATER_AMBIENT; public final float SoundVolume = 0; diff --git a/src/com/projectkorra/projectkorra/storage/DBConnection.java b/src/com/projectkorra/projectkorra/storage/DBConnection.java index e1f32d1a..8de4e949 100644 --- a/src/com/projectkorra/projectkorra/storage/DBConnection.java +++ b/src/com/projectkorra/projectkorra/storage/DBConnection.java @@ -5,7 +5,8 @@ import java.sql.SQLException; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ProjectKorra; -import com.projectkorra.projectkorra.configuration.ConfigManager; +import com.projectkorra.projectkorra.configuration.better.ConfigManager; +import com.projectkorra.projectkorra.configuration.better.configs.properties.GeneralPropertiesConfig; public class DBConnection { @@ -19,12 +20,13 @@ public class DBConnection { private static boolean isOpen = false; public static void init() { - DBConnection.host = ConfigManager.getConfig().getString("Storage.MySQL.host"); - DBConnection.port = ConfigManager.getConfig().getInt("Storage.MySQL.port"); - DBConnection.pass = ConfigManager.getConfig().getString("Storage.MySQL.pass"); - DBConnection.db = ConfigManager.getConfig().getString("Storage.MySQL.db"); - DBConnection.user = ConfigManager.getConfig().getString("Storage.MySQL.user"); - if (ProjectKorra.plugin.getConfig().getString("Storage.engine").equalsIgnoreCase("mysql")) { + GeneralPropertiesConfig config = ConfigManager.getConfig(GeneralPropertiesConfig.class); + DBConnection.host = config.MySQL_Host; + DBConnection.port = config.MySQL_Port; + DBConnection.pass = config.MySQL_Password; + DBConnection.db = config.MySQL_Database; + DBConnection.user = config.MySQL_User; + if (config.UseMySQL) { sql = new MySQL(ProjectKorra.log, "Establishing MySQL Connection...", host, port, user, pass, db); if (((MySQL) sql).open() == null) { ProjectKorra.log.severe("Disabling due to database error"); diff --git a/src/com/projectkorra/projectkorra/util/BlockSource.java b/src/com/projectkorra/projectkorra/util/BlockSource.java index 5a56abbb..255bfb50 100644 --- a/src/com/projectkorra/projectkorra/util/BlockSource.java +++ b/src/com/projectkorra/projectkorra/util/BlockSource.java @@ -4,7 +4,6 @@ import java.util.HashMap; import org.bukkit.Location; import org.bukkit.block.Block; -import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import com.projectkorra.projectkorra.BendingPlayer; @@ -12,7 +11,9 @@ import com.projectkorra.projectkorra.ability.CoreAbility; import com.projectkorra.projectkorra.ability.EarthAbility; import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.ability.WaterAbility; -import com.projectkorra.projectkorra.configuration.ConfigManager; +import com.projectkorra.projectkorra.configuration.better.ConfigManager; +import com.projectkorra.projectkorra.configuration.better.configs.properties.EarthPropertiesConfig; +import com.projectkorra.projectkorra.configuration.better.configs.properties.WaterPropertiesConfig; /** * BlockSource is a class that handles water and earth bending sources. When a @@ -23,21 +24,17 @@ import com.projectkorra.projectkorra.configuration.ConfigManager; * For example, Surge has two different ways to select a source, one involving * shift and another involving left clicks. */ +@SuppressWarnings("rawtypes") public class BlockSource { /** * An enum representation of the source types available for bending * abilities. - * - * @author kingbirdy */ public static enum BlockSourceType { WATER, ICE, PLANT, EARTH, METAL, LAVA, SNOW } private static HashMap>> playerSources = new HashMap>>(); - private static FileConfiguration config = ConfigManager.defaultConfig.get(); - // The player should never need to grab source blocks from farther than this. - private static double MAX_RANGE = config.getDouble("Abilities.Water.WaterManipulation.SelectRange"); /** * Updates all of the player's sources. @@ -58,7 +55,7 @@ public class BlockSource { } if (coreAbil instanceof WaterAbility) { - final Block waterBlock = WaterAbility.getWaterSourceBlock(player, MAX_RANGE, true); + final Block waterBlock = WaterAbility.getWaterSourceBlock(player, ConfigManager.getConfig(WaterPropertiesConfig.class).MaxSelectRange, true); if (waterBlock != null) { putSource(player, waterBlock, BlockSourceType.WATER, clickType); if (ElementalAbility.isPlant(waterBlock)) { @@ -72,7 +69,7 @@ public class BlockSource { } } } else if (coreAbil instanceof EarthAbility) { - final Block earthBlock = EarthAbility.getEarthSourceBlock(player, null, MAX_RANGE); + final Block earthBlock = EarthAbility.getEarthSourceBlock(player, null, ConfigManager.getConfig(EarthPropertiesConfig.class).MaxSelectRange); if (earthBlock != null) { putSource(player, earthBlock, BlockSourceType.EARTH, clickType); if (ElementalAbility.isMetal(earthBlock)) { @@ -82,7 +79,7 @@ public class BlockSource { // We need to handle lava differently, since getEarthSourceBlock doesn't account for lava. // We should only select the lava source if it is closer than the earth. - final Block lavaBlock = EarthAbility.getLavaSourceBlock(player, MAX_RANGE); + final Block lavaBlock = EarthAbility.getLavaSourceBlock(player, ConfigManager.getConfig(EarthPropertiesConfig.class).MaxSelectRange); final double earthDist = earthBlock != null ? earthBlock.getLocation().distanceSquared(player.getLocation()) : Double.MAX_VALUE; final double lavaDist = lavaBlock != null ? lavaBlock.getLocation().distanceSquared(player.getLocation()) : Double.MAX_VALUE; if (lavaBlock != null && lavaDist <= earthDist) { @@ -251,8 +248,7 @@ public class BlockSource { sourceBlock = null; } } - final boolean dynamic = ConfigManager.getConfig().getBoolean("Properties.Water.DynamicSourcing"); - if (dynamic && sourceBlock == null) { + if (ConfigManager.getConfig(WaterPropertiesConfig.class).DynamicSourcing && sourceBlock == null) { if (allowWater && sourceBlock == null) { sourceBlock = getSourceBlock(player, range, BlockSourceType.WATER, clickType); } @@ -306,8 +302,7 @@ public class BlockSource { */ public static Block getEarthSourceBlock(final Player player, final double range, final ClickType clickType, final boolean allowNearbySubstitute) { Block sourceBlock = getSourceBlock(player, range, BlockSourceType.EARTH, clickType); - final boolean dynamic = ConfigManager.getConfig().getBoolean("Properties.Earth.DynamicSourcing"); - if (dynamic && sourceBlock == null && allowNearbySubstitute) { + if (ConfigManager.getConfig(EarthPropertiesConfig.class).DynamicSourcing && sourceBlock == null && allowNearbySubstitute) { final BlockSourceInformation blockInfo = getBlockSourceInformation(player, BlockSourceType.EARTH, clickType); if (blockInfo == null) { diff --git a/src/com/projectkorra/projectkorra/util/PassiveHandler.java b/src/com/projectkorra/projectkorra/util/PassiveHandler.java index 636ec584..0bc1427d 100644 --- a/src/com/projectkorra/projectkorra/util/PassiveHandler.java +++ b/src/com/projectkorra/projectkorra/util/PassiveHandler.java @@ -2,6 +2,7 @@ package com.projectkorra.projectkorra.util; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Stream; import org.bukkit.entity.Player; @@ -11,7 +12,8 @@ import com.projectkorra.projectkorra.ability.util.PassiveManager; import com.projectkorra.projectkorra.airbending.passive.AirSaturation; import com.projectkorra.projectkorra.chiblocking.passive.ChiSaturation; import com.projectkorra.projectkorra.command.Commands; -import com.projectkorra.projectkorra.configuration.ConfigManager; +import com.projectkorra.projectkorra.configuration.better.ConfigManager; +import com.projectkorra.projectkorra.configuration.better.configs.properties.GeneralPropertiesConfig; public class PassiveHandler { private static final Map FOOD = new ConcurrentHashMap<>(); @@ -44,11 +46,11 @@ public class PassiveHandler { double air = AirSaturation.getExhaustionFactor(); double chi = ChiSaturation.getExhaustionFactor(); - if (ConfigManager.defaultConfig.get().getStringList("Properties.DisabledWorlds").contains(player.getWorld().getName())) { + if (Stream.of(ConfigManager.getConfig(GeneralPropertiesConfig.class).DisabledWorlds).anyMatch(player.getWorld().getName()::equalsIgnoreCase)) { return; } - if (Commands.isToggledForAll && ConfigManager.defaultConfig.get().getBoolean("Properties.TogglePassivesWithAllBending")) { + if (Commands.isToggledForAll && ConfigManager.getConfig(GeneralPropertiesConfig.class).TogglePassivesWithAllBending) { return; } diff --git a/src/com/projectkorra/projectkorra/util/RevertChecker.java b/src/com/projectkorra/projectkorra/util/RevertChecker.java index df122483..a571ac5c 100644 --- a/src/com/projectkorra/projectkorra/util/RevertChecker.java +++ b/src/com/projectkorra/projectkorra/util/RevertChecker.java @@ -10,21 +10,18 @@ import java.util.concurrent.Future; import org.bukkit.Server; import org.bukkit.block.Block; -import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.EarthAbility; -import com.projectkorra.projectkorra.configuration.ConfigManager; +import com.projectkorra.projectkorra.configuration.better.ConfigManager; +import com.projectkorra.projectkorra.configuration.better.configs.properties.EarthPropertiesConfig; import io.papermc.lib.PaperLib; public class RevertChecker implements Runnable { private final ProjectKorra plugin; - - private static final FileConfiguration config = ConfigManager.defaultConfig.get(); - private static final boolean safeRevert = config.getBoolean("Properties.Earth.SafeRevert"); public static Map earthRevertQueue = new ConcurrentHashMap<>(); static Map airRevertQueue = new ConcurrentHashMap<>(); @@ -70,8 +67,8 @@ public class RevertChecker implements Runnable { } this.time = System.currentTimeMillis(); - if (config.getBoolean("Properties.Earth.RevertEarthbending")) { - + EarthPropertiesConfig config = ConfigManager.getConfig(EarthPropertiesConfig.class); + if (config.RevertEarthbending) { try { this.returnFuture = this.plugin.getServer().getScheduler().callSyncMethod(this.plugin, new getOccupiedChunks(this.plugin.getServer())); final Set> chunks = this.returnFuture.get(); @@ -89,7 +86,7 @@ public class RevertChecker implements Runnable { chunkcoord.put("x", block.getX() >> 4); chunkcoord.put("z", block.getZ() >> 4); - if (this.time > (info.getTime() + config.getLong("Properties.Earth.RevertCheckTime")) && !(chunks.contains(chunkcoord) && safeRevert)) { + if (this.time > (info.getTime() + config.RevertCheckTime) && !(chunks.contains(chunkcoord) && config.SafeRevert)) { this.addToRevertQueue(block); } } @@ -108,7 +105,7 @@ public class RevertChecker implements Runnable { chunkcoord.put("x", block.getX() >> 4); chunkcoord.put("z", block.getZ() >> 4); - if (this.time > (info.getTime() + config.getLong("Properties.Earth.RevertCheckTime")) && !(chunks.contains(chunkcoord) && safeRevert)) { + if (this.time > (info.getTime() + config.RevertCheckTime) && !(chunks.contains(chunkcoord) && config.SafeRevert)) { this.addToAirRevertQueue(i); } }