mirror of
https://github.com/TotalFreedomMC/TF-ProjectKorra.git
synced 2025-02-11 11:40:40 +00:00
Ported the new configuration system to some of the base code, and improved elements of the Preset system
This commit is contained in:
parent
fd1710ce61
commit
444eba5d36
9 changed files with 112 additions and 89 deletions
|
@ -3,8 +3,6 @@ package com.projectkorra.projectkorra;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import co.aikar.timings.lib.MCTiming;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
@ -12,6 +10,9 @@ import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.projectkorra.projectkorra.ability.CoreAbility;
|
import com.projectkorra.projectkorra.ability.CoreAbility;
|
||||||
import com.projectkorra.projectkorra.ability.ElementalAbility;
|
import com.projectkorra.projectkorra.ability.ElementalAbility;
|
||||||
|
import com.projectkorra.projectkorra.configuration.better.ConfigManager;
|
||||||
|
import com.projectkorra.projectkorra.configuration.better.configs.properties.FirePropertiesConfig;
|
||||||
|
import com.projectkorra.projectkorra.configuration.better.configs.properties.WaterPropertiesConfig;
|
||||||
import com.projectkorra.projectkorra.earthbending.metal.MetalClips;
|
import com.projectkorra.projectkorra.earthbending.metal.MetalClips;
|
||||||
import com.projectkorra.projectkorra.object.HorizontalVelocityTracker;
|
import com.projectkorra.projectkorra.object.HorizontalVelocityTracker;
|
||||||
import com.projectkorra.projectkorra.util.ActionBar;
|
import com.projectkorra.projectkorra.util.ActionBar;
|
||||||
|
@ -20,6 +21,8 @@ import com.projectkorra.projectkorra.util.TempArmor;
|
||||||
import com.projectkorra.projectkorra.util.TempPotionEffect;
|
import com.projectkorra.projectkorra.util.TempPotionEffect;
|
||||||
import com.projectkorra.projectkorra.waterbending.blood.Bloodbending;
|
import com.projectkorra.projectkorra.waterbending.blood.Bloodbending;
|
||||||
|
|
||||||
|
import co.aikar.timings.lib.MCTiming;
|
||||||
|
|
||||||
public class BendingManager implements Runnable {
|
public class BendingManager implements Runnable {
|
||||||
|
|
||||||
private static BendingManager instance;
|
private static BendingManager instance;
|
||||||
|
@ -150,19 +153,19 @@ public class BendingManager implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getSunriseMessage() {
|
public static String getSunriseMessage() {
|
||||||
return ChatColor.translateAlternateColorCodes('&', ConfigManager.languageConfig.get().getString("Extras.Fire.DayMessage"));
|
return ChatColor.translateAlternateColorCodes('&', ConfigManager.getConfig(FirePropertiesConfig.class).DayMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getSunsetMessage() {
|
public static String getSunsetMessage() {
|
||||||
return ChatColor.translateAlternateColorCodes('&', ConfigManager.languageConfig.get().getString("Extras.Fire.NightMessage"));
|
return ChatColor.translateAlternateColorCodes('&', ConfigManager.getConfig(FirePropertiesConfig.class).NightMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getMoonriseMessage() {
|
public static String getMoonriseMessage() {
|
||||||
return ChatColor.translateAlternateColorCodes('&', ConfigManager.languageConfig.get().getString("Extras.Water.NightMessage"));
|
return ChatColor.translateAlternateColorCodes('&', ConfigManager.getConfig(WaterPropertiesConfig.class).NightMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getMoonsetMessage() {
|
public static String getMoonsetMessage() {
|
||||||
return ChatColor.translateAlternateColorCodes('&', ConfigManager.languageConfig.get().getString("Extras.Water.DayMessage"));
|
return ChatColor.translateAlternateColorCodes('&', ConfigManager.getConfig(WaterPropertiesConfig.class).DayMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,15 +9,14 @@ import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.projectkorra.projectkorra.Element.SubElement;
|
import com.projectkorra.projectkorra.Element.SubElement;
|
||||||
|
@ -28,6 +27,8 @@ import com.projectkorra.projectkorra.ability.CoreAbility;
|
||||||
import com.projectkorra.projectkorra.ability.util.PassiveManager;
|
import com.projectkorra.projectkorra.ability.util.PassiveManager;
|
||||||
import com.projectkorra.projectkorra.avatar.AvatarState;
|
import com.projectkorra.projectkorra.avatar.AvatarState;
|
||||||
import com.projectkorra.projectkorra.command.Commands;
|
import com.projectkorra.projectkorra.command.Commands;
|
||||||
|
import com.projectkorra.projectkorra.configuration.better.ConfigManager;
|
||||||
|
import com.projectkorra.projectkorra.configuration.better.configs.properties.GeneralPropertiesConfig;
|
||||||
import com.projectkorra.projectkorra.earthbending.metal.MetalClips;
|
import com.projectkorra.projectkorra.earthbending.metal.MetalClips;
|
||||||
import com.projectkorra.projectkorra.event.PlayerCooldownChangeEvent;
|
import com.projectkorra.projectkorra.event.PlayerCooldownChangeEvent;
|
||||||
import com.projectkorra.projectkorra.event.PlayerCooldownChangeEvent.Result;
|
import com.projectkorra.projectkorra.event.PlayerCooldownChangeEvent.Result;
|
||||||
|
@ -245,7 +246,6 @@ public class BendingPlayer {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<String> disabledWorlds = getConfig().getStringList("Properties.DisabledWorlds");
|
|
||||||
final Location playerLoc = this.player.getLocation();
|
final Location playerLoc = this.player.getLocation();
|
||||||
|
|
||||||
if (!this.player.isOnline() || this.player.isDead()) {
|
if (!this.player.isOnline() || this.player.isDead()) {
|
||||||
|
@ -258,7 +258,7 @@ public class BendingPlayer {
|
||||||
return false;
|
return false;
|
||||||
} else if (!ignoreBinds && (!ability.getName().equals(this.getBoundAbilityName()))) {
|
} else if (!ignoreBinds && (!ability.getName().equals(this.getBoundAbilityName()))) {
|
||||||
return false;
|
return false;
|
||||||
} else if (disabledWorlds != null && disabledWorlds.contains(this.player.getWorld().getName())) {
|
} else if (Stream.of(ConfigManager.getConfig(GeneralPropertiesConfig.class).DisabledWorlds).anyMatch(this.player.getWorld().getName()::equalsIgnoreCase)) {
|
||||||
return false;
|
return false;
|
||||||
} else if (Commands.isToggledForAll || !this.isToggled() || !this.isElementToggled(ability.getElement())) {
|
} else if (Commands.isToggledForAll || !this.isToggled() || !this.isElementToggled(ability.getElement())) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -267,7 +267,7 @@ public class BendingPlayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ignoreCooldowns && this.cooldowns.containsKey(this.name)) {
|
if (!ignoreCooldowns && this.cooldowns.containsKey(this.name)) {
|
||||||
if (this.cooldowns.get(this.name).getCooldown() + getConfig().getLong("Properties.GlobalCooldown") >= System.currentTimeMillis()) {
|
if (this.cooldowns.get(this.name).getCooldown() + ConfigManager.getConfig(GeneralPropertiesConfig.class).GlobalCooldown >= System.currentTimeMillis()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,11 +300,10 @@ public class BendingPlayer {
|
||||||
return false; // If the passive is disabled.
|
return false; // If the passive is disabled.
|
||||||
}
|
}
|
||||||
final Element element = ability.getElement();
|
final Element element = ability.getElement();
|
||||||
if (Commands.isToggledForAll && ConfigManager.defaultConfig.get().getBoolean("Properties.TogglePassivesWithAllBending")) {
|
if (Commands.isToggledForAll && ConfigManager.getConfig(GeneralPropertiesConfig.class).TogglePassivesWithAllBending) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<String> disabledWorlds = getConfig().getStringList("Properties.DisabledWorlds");
|
|
||||||
|
|
||||||
if (element == null || this.player == null) {
|
if (element == null || this.player == null) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -312,7 +311,7 @@ public class BendingPlayer {
|
||||||
return false;
|
return false;
|
||||||
} else if (!this.hasElement(element)) {
|
} else if (!this.hasElement(element)) {
|
||||||
return false;
|
return false;
|
||||||
} else if (disabledWorlds != null && disabledWorlds.contains(this.player.getWorld().getName())) {
|
} else if (Stream.of(ConfigManager.getConfig(GeneralPropertiesConfig.class).DisabledWorlds).anyMatch(this.player.getWorld().getName()::equalsIgnoreCase)) {
|
||||||
return false;
|
return false;
|
||||||
} else if (this.player.getGameMode() == GameMode.SPECTATOR) {
|
} else if (this.player.getGameMode() == GameMode.SPECTATOR) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1198,22 +1198,10 @@ public class PKListener implements Listener {
|
||||||
GeneralMethods.removeUnusableAbilities(player.getName());
|
GeneralMethods.removeUnusableAbilities(player.getName());
|
||||||
}, 5);
|
}, 5);
|
||||||
|
|
||||||
if (ConfigManager.languageConfig.get().getBoolean("Chat.Branding.JoinMessage.Enabled")) {
|
|
||||||
Bukkit.getScheduler().runTaskLater(ProjectKorra.plugin, (Runnable) () -> {
|
Bukkit.getScheduler().runTaskLater(ProjectKorra.plugin, (Runnable) () -> {
|
||||||
ChatColor color = ChatColor.valueOf(ConfigManager.languageConfig.get().getString("Chat.Branding.Color").toUpperCase());
|
player.sendMessage(ChatColor.GOLD + "This server is running ProjectKorra version " + ProjectKorra.plugin.getDescription().getVersion() + " for bending! Find out more at http://www.projectkorra.com!");
|
||||||
color = color == null ? ChatColor.GOLD : color;
|
|
||||||
final String topBorder = ConfigManager.languageConfig.get().getString("Chat.Branding.Borders.TopBorder");
|
|
||||||
final String bottomBorder = ConfigManager.languageConfig.get().getString("Chat.Branding.Borders.BottomBorder");
|
|
||||||
if (!topBorder.isEmpty()) {
|
|
||||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', topBorder));
|
|
||||||
}
|
|
||||||
player.sendMessage(color + "This server is running ProjectKorra version " + ProjectKorra.plugin.getDescription().getVersion() + " for bending! Find out more at http://www.projectkorra.com!");
|
|
||||||
if (!bottomBorder.isEmpty()) {
|
|
||||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', bottomBorder));
|
|
||||||
}
|
|
||||||
}, 20 * 4);
|
}, 20 * 4);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerChangeWorld(final PlayerChangedWorldEvent event) {
|
public void onPlayerChangeWorld(final PlayerChangedWorldEvent event) {
|
||||||
|
@ -1567,7 +1555,7 @@ public class PKListener implements Listener {
|
||||||
final int slot = event.getNewSlot() + 1;
|
final int slot = event.getNewSlot() + 1;
|
||||||
GeneralMethods.displayMovePreview(player, slot);
|
GeneralMethods.displayMovePreview(player, slot);
|
||||||
|
|
||||||
if (!ConfigManager.defaultConfig.get().getBoolean("Properties.BendingPreview")) {
|
if (!ConfigManager.getConfig(GeneralPropertiesConfig.class).BendingPreview) {
|
||||||
final WaterArms waterArms = CoreAbility.getAbility(player, WaterArms.class);
|
final WaterArms waterArms = CoreAbility.getAbility(player, WaterArms.class);
|
||||||
if (waterArms != null) {
|
if (waterArms != null) {
|
||||||
waterArms.displayBoundMsg(event.getNewSlot() + 1);
|
waterArms.displayBoundMsg(event.getNewSlot() + 1);
|
||||||
|
|
|
@ -220,7 +220,12 @@ public class PresetCommand extends PKCommand {
|
||||||
if (bPlayer == null) {
|
if (bPlayer == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final HashMap<Integer, String> abilities = (HashMap<Integer, String>) bPlayer.getAbilities().clone();
|
String[] abilities = new String[9];
|
||||||
|
for (int slot = 0; slot < 9; slot++) {
|
||||||
|
if (bPlayer.getAbilities().containsKey(slot + 1)) {
|
||||||
|
abilities[slot] = bPlayer.getAbilities().get(slot + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final Preset preset = new Preset(player.getUniqueId(), name, abilities);
|
final Preset preset = new Preset(player.getUniqueId(), name, abilities);
|
||||||
preset.save(player);
|
preset.save(player);
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class ConfigManager {
|
||||||
CONFIG_CACHE.put(clazz, defaultConfig);
|
CONFIG_CACHE.put(clazz, defaultConfig);
|
||||||
|
|
||||||
File file = new File(JavaPlugin.getPlugin(ProjectKorra.class).getDataFolder(), "config");
|
File file = new File(JavaPlugin.getPlugin(ProjectKorra.class).getDataFolder(), "config");
|
||||||
file.mkdir();
|
file.mkdirs();
|
||||||
|
|
||||||
for (String parent : defaultConfig.getParents()) {
|
for (String parent : defaultConfig.getParents()) {
|
||||||
file = new File(file, parent);
|
file = new File(file, parent);
|
||||||
|
|
|
@ -11,6 +11,9 @@ public class FirePropertiesConfig implements Config {
|
||||||
public final long RevertTicks = 0;
|
public final long RevertTicks = 0;
|
||||||
public final double DayFactor = 0;
|
public final double DayFactor = 0;
|
||||||
|
|
||||||
|
public final String DayMessage = "";
|
||||||
|
public final String NightMessage = "";
|
||||||
|
|
||||||
public final ParticleEffect Particles = ParticleEffect.FLAME;
|
public final ParticleEffect Particles = ParticleEffect.FLAME;
|
||||||
|
|
||||||
public final boolean PlaySound = true;
|
public final boolean PlaySound = true;
|
||||||
|
|
|
@ -26,6 +26,8 @@ public class GeneralPropertiesConfig implements Config {
|
||||||
|
|
||||||
public final long GlobalCooldown = 0;
|
public final long GlobalCooldown = 0;
|
||||||
|
|
||||||
|
public final boolean TogglePassivesWithAllBending = true;
|
||||||
|
|
||||||
public final int MaxPresets = 0;
|
public final int MaxPresets = 0;
|
||||||
|
|
||||||
public final boolean ImportEnabled = false;
|
public final boolean ImportEnabled = false;
|
||||||
|
@ -40,6 +42,8 @@ public class GeneralPropertiesConfig implements Config {
|
||||||
|
|
||||||
public final boolean ApplyHorizontalCollisionBarrierBlockDamage = true;
|
public final boolean ApplyHorizontalCollisionBarrierBlockDamage = true;
|
||||||
|
|
||||||
|
public final String[] DisabledWorlds = {};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "General";
|
return "General";
|
||||||
|
|
|
@ -11,6 +11,9 @@ public class WaterPropertiesConfig implements Config {
|
||||||
|
|
||||||
public final double NightFactor = 0;
|
public final double NightFactor = 0;
|
||||||
|
|
||||||
|
public final String DayMessage = "";
|
||||||
|
public final String NightMessage = "";
|
||||||
|
|
||||||
public final boolean PlaySound = true;
|
public final boolean PlaySound = true;
|
||||||
public final Sound SoundType = Sound.BLOCK_WATER_AMBIENT;
|
public final Sound SoundType = Sound.BLOCK_WATER_AMBIENT;
|
||||||
public final float SoundVolume = 0;
|
public final float SoundVolume = 0;
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
package com.projectkorra.projectkorra.object;
|
package com.projectkorra.projectkorra.object;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
@ -10,31 +14,28 @@ import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
import com.projectkorra.projectkorra.BendingPlayer;
|
import com.projectkorra.projectkorra.BendingPlayer;
|
||||||
import com.projectkorra.projectkorra.ProjectKorra;
|
import com.projectkorra.projectkorra.ProjectKorra;
|
||||||
import com.projectkorra.projectkorra.ability.CoreAbility;
|
import com.projectkorra.projectkorra.ability.CoreAbility;
|
||||||
import com.projectkorra.projectkorra.configuration.ConfigManager;
|
|
||||||
import com.projectkorra.projectkorra.storage.DBConnection;
|
import com.projectkorra.projectkorra.storage.DBConnection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A savable association of abilities and hotbar slots, stored per player.
|
* A persistent association of abilities and hotbar slots, stored per player.
|
||||||
*
|
|
||||||
* @author kingbirdy
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
public class Preset {
|
public class Preset {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ConcurrentHashMap that stores a list of every Player's {@link Preset
|
* ConcurrentHashMap that stores a list of every Player's {@link Preset
|
||||||
* presets}, keyed to their UUID
|
* presets}, keyed to their UUID
|
||||||
*/
|
*/
|
||||||
public static Map<UUID, List<Preset>> presets = new ConcurrentHashMap<UUID, List<Preset>>();
|
public static Map<UUID, List<Preset>> presets = new ConcurrentHashMap<>();
|
||||||
public static FileConfiguration config = ConfigManager.presetConfig.get();
|
public static Map<String, ExternalPreset> externalPresets = new HashMap<>();
|
||||||
public static HashMap<String, ArrayList<String>> externalPresets = new HashMap<String, ArrayList<String>>();
|
|
||||||
static String loadQuery = "SELECT * FROM pk_presets WHERE uuid = ?";
|
static String loadQuery = "SELECT * FROM pk_presets WHERE uuid = ?";
|
||||||
static String loadNameQuery = "SELECT * FROM pk_presets WHERE uuid = ? AND name = ?";
|
static String loadNameQuery = "SELECT * FROM pk_presets WHERE uuid = ? AND name = ?";
|
||||||
static String deleteQuery = "DELETE FROM pk_presets WHERE uuid = ? AND name = ?";
|
static String deleteQuery = "DELETE FROM pk_presets WHERE uuid = ? AND name = ?";
|
||||||
|
@ -42,9 +43,9 @@ public class Preset {
|
||||||
static String updateQuery1 = "UPDATE pk_presets SET slot";
|
static String updateQuery1 = "UPDATE pk_presets SET slot";
|
||||||
static String updateQuery2 = " = ? WHERE uuid = ? AND name = ?";
|
static String updateQuery2 = " = ? WHERE uuid = ? AND name = ?";
|
||||||
|
|
||||||
private final UUID uuid;
|
private final transient UUID uuid;
|
||||||
private final HashMap<Integer, String> abilities;
|
private final transient String[] abilities;
|
||||||
private final String name;
|
private final transient String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@link Preset}
|
* Creates a new {@link Preset}
|
||||||
|
@ -54,7 +55,7 @@ public class Preset {
|
||||||
* @param abilities A HashMap of the abilities to be saved in the Preset,
|
* @param abilities A HashMap of the abilities to be saved in the Preset,
|
||||||
* keyed to the slot they're bound to
|
* keyed to the slot they're bound to
|
||||||
*/
|
*/
|
||||||
public Preset(final UUID uuid, final String name, final HashMap<Integer, String> abilities) {
|
public Preset(final UUID uuid, final String name, final String[] abilities) {
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.abilities = abilities;
|
this.abilities = abilities;
|
||||||
|
@ -64,6 +65,32 @@ public class Preset {
|
||||||
presets.get(uuid).add(this);
|
presets.get(uuid).add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final class ExternalPreset extends Preset {
|
||||||
|
|
||||||
|
private final String Name = null;
|
||||||
|
private final String[] Abilities = null;
|
||||||
|
|
||||||
|
public ExternalPreset() {
|
||||||
|
super(null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getAbilities() {
|
||||||
|
return Abilities;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(final Player player) {}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unload a Player's Presets from those stored in memory.
|
* Unload a Player's Presets from those stored in memory.
|
||||||
*
|
*
|
||||||
|
@ -94,14 +121,11 @@ public class Preset {
|
||||||
if (rs.next()) { // Presets exist.
|
if (rs.next()) { // Presets exist.
|
||||||
int i = 0;
|
int i = 0;
|
||||||
do {
|
do {
|
||||||
final HashMap<Integer, String> moves = new HashMap<Integer, String>();
|
String[] abilities = new String[9];
|
||||||
for (int total = 1; total <= 9; total++) {
|
for (int slot = 0; slot < 9; slot++) {
|
||||||
final String slot = rs.getString("slot" + total);
|
abilities[slot] = rs.getString("slot" + (slot + 1));
|
||||||
if (slot != null) {
|
|
||||||
moves.put(total, slot);
|
|
||||||
}
|
}
|
||||||
}
|
new Preset(uuid, rs.getString("name"), abilities);
|
||||||
new Preset(uuid, rs.getString("name"), moves);
|
|
||||||
i++;
|
i++;
|
||||||
} while (rs.next());
|
} while (rs.next());
|
||||||
ProjectKorra.log.info("Loaded " + i + " presets for " + player.getName());
|
ProjectKorra.log.info("Loaded " + i + " presets for " + player.getName());
|
||||||
|
@ -136,16 +160,19 @@ public class Preset {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final HashMap<Integer, String> abilities = new HashMap<>(preset.abilities);
|
String[] abilities = preset.getAbilities();
|
||||||
boolean boundAll = true;
|
boolean boundAll = true;
|
||||||
for (int i = 1; i <= 9; i++) {
|
HashMap<Integer, String> bindings = new HashMap<>();
|
||||||
final CoreAbility coreAbil = CoreAbility.getAbility(abilities.get(i));
|
for (int i = 0; i < abilities.length; i++) {
|
||||||
|
final CoreAbility coreAbil = CoreAbility.getAbility(abilities[i]);
|
||||||
if (coreAbil != null && !bPlayer.canBind(coreAbil)) {
|
if (coreAbil != null && !bPlayer.canBind(coreAbil)) {
|
||||||
abilities.remove(i);
|
abilities[i] = null;
|
||||||
boundAll = false;
|
boundAll = false;
|
||||||
|
} else {
|
||||||
|
bindings.put(i + 1, abilities[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bPlayer.setAbilities(abilities);
|
bPlayer.setAbilities(bindings);
|
||||||
return boundAll;
|
return boundAll;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,15 +216,20 @@ public class Preset {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void loadExternalPresets() {
|
public static void loadExternalPresets() {
|
||||||
final HashMap<String, ArrayList<String>> presets = new HashMap<String, ArrayList<String>>();
|
Gson gson = new Gson();
|
||||||
for (final String name : config.getKeys(false)) {
|
File directory = new File(JavaPlugin.getPlugin(ProjectKorra.class).getDataFolder(), "presets");
|
||||||
if (!presets.containsKey(name)) {
|
if (directory.exists() && directory.isDirectory()) {
|
||||||
if (!config.getStringList(name).isEmpty() && config.getStringList(name).size() <= 9) {
|
for (File f : directory.listFiles((parent, name) -> name.endsWith(".json"))) {
|
||||||
presets.put(name.toLowerCase(), (ArrayList<String>) config.getStringList(name));
|
try (BufferedReader reader = Files.newBufferedReader(f.toPath())) {
|
||||||
|
ExternalPreset preset = gson.fromJson(reader, ExternalPreset.class);
|
||||||
|
externalPresets.put(preset.getName().toLowerCase(), preset);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
directory.mkdirs();
|
||||||
}
|
}
|
||||||
externalPresets = presets;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean externalPresetExists(final String name) {
|
public static boolean externalPresetExists(final String name) {
|
||||||
|
@ -214,10 +246,10 @@ public class Preset {
|
||||||
*
|
*
|
||||||
* @param player The Player who's Preset should be gotten
|
* @param player The Player who's Preset should be gotten
|
||||||
* @param name The name of the Preset who's contents should be gotten
|
* @param name The name of the Preset who's contents should be gotten
|
||||||
* @return HashMap of ability names keyed to hotbar slots, if the Preset
|
* @return String array of ability names indexed by hotbar slots, if the Preset
|
||||||
* exists, or null otherwise
|
* exists, or null otherwise
|
||||||
*/
|
*/
|
||||||
public static HashMap<Integer, String> getPresetContents(final Player player, final String name) {
|
public static String[] getPresetContents(final Player player, final String name) {
|
||||||
if (!presets.containsKey(player.getUniqueId())) {
|
if (!presets.containsKey(player.getUniqueId())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -230,33 +262,13 @@ public class Preset {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean bindExternalPreset(final Player player, final String name) {
|
public static boolean bindExternalPreset(final Player player, final String name) {
|
||||||
boolean boundAll = true;
|
|
||||||
int slot = 0;
|
|
||||||
final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
|
final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
|
||||||
if (bPlayer == null) {
|
if (bPlayer == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final HashMap<Integer, String> abilities = new HashMap<Integer, String>();
|
|
||||||
|
|
||||||
if (externalPresetExists(name.toLowerCase())) {
|
if (externalPresetExists(name.toLowerCase())) {
|
||||||
for (final String ability : externalPresets.get(name.toLowerCase())) {
|
return bindPreset(player, externalPresets.get(name.toLowerCase()));
|
||||||
slot++;
|
|
||||||
final CoreAbility coreAbil = CoreAbility.getAbility(ability);
|
|
||||||
if (coreAbil != null) {
|
|
||||||
abilities.put(slot, coreAbil.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 1; i <= 9; i++) {
|
|
||||||
final CoreAbility coreAbil = CoreAbility.getAbility(abilities.get(i));
|
|
||||||
if (coreAbil != null && !bPlayer.canBind(coreAbil)) {
|
|
||||||
abilities.remove(i);
|
|
||||||
boundAll = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bPlayer.setAbilities(abilities);
|
|
||||||
return boundAll;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -285,6 +297,10 @@ public class Preset {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String[] getAbilities() {
|
||||||
|
return this.abilities;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the Preset to the database.
|
* Saves the Preset to the database.
|
||||||
*/
|
*/
|
||||||
|
@ -303,15 +319,17 @@ public class Preset {
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
for (final Integer i : this.abilities.keySet()) {
|
for (int i = 0; i < abilities.length; i++) {
|
||||||
|
final String ability = abilities[i];
|
||||||
|
final int slot = i + 1;
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
PreparedStatement ps;
|
PreparedStatement ps;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
this.ps = DBConnection.sql.getConnection().prepareStatement(updateQuery1 + i + updateQuery2);
|
this.ps = DBConnection.sql.getConnection().prepareStatement(updateQuery1 + slot + updateQuery2);
|
||||||
this.ps.setString(1, Preset.this.abilities.get(i));
|
this.ps.setString(1, ability);
|
||||||
this.ps.setString(2, Preset.this.uuid.toString());
|
this.ps.setString(2, Preset.this.uuid.toString());
|
||||||
this.ps.setString(3, Preset.this.name);
|
this.ps.setString(3, Preset.this.name);
|
||||||
this.ps.execute();
|
this.ps.execute();
|
||||||
|
|
Loading…
Reference in a new issue