Port more base systems and commands

This commit is contained in:
Alexander Meech 2019-08-13 03:34:37 -04:00
parent 444eba5d36
commit dc0c295583
11 changed files with 109 additions and 44 deletions

View file

@ -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);
}

View file

@ -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 <Ability> [Slot]", ConfigManager.languageConfig.get().getString("Commands.Bind.Description"), new String[] { "bind", "b" });
super("bind", "/bending bind <Ability> [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

View file

@ -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" };
}
}

View file

@ -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" };
}
}

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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");

View file

@ -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<Player, HashMap<BlockSourceType, HashMap<ClickType, BlockSourceInformation>>> playerSources = new HashMap<Player, HashMap<BlockSourceType, HashMap<ClickType, BlockSourceInformation>>>();
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) {

View file

@ -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<Player, Float> 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;
}

View file

@ -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<Block, Block> earthRevertQueue = new ConcurrentHashMap<>();
static Map<Integer, Integer> 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<Map<String, Integer>> 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);
}
}