From 6bad38cc189484178cddc843d078f0b65863f3e6 Mon Sep 17 00:00:00 2001 From: jack lin Date: Sun, 13 Jul 2014 02:17:26 +1200 Subject: [PATCH] Updated importer to add slot abilities --- .../ProjectKorra/Ability/StockAbilities.java | 16 ++++++- .../projectkorra/ProjectKorra/Commands.java | 31 ++++++++++-- .../projectkorra/ProjectKorra/Methods.java | 47 +++++++++---------- 3 files changed, 62 insertions(+), 32 deletions(-) diff --git a/src/com/projectkorra/ProjectKorra/Ability/StockAbilities.java b/src/com/projectkorra/ProjectKorra/Ability/StockAbilities.java index dc5b985c..c51dbda7 100644 --- a/src/com/projectkorra/ProjectKorra/Ability/StockAbilities.java +++ b/src/com/projectkorra/ProjectKorra/Ability/StockAbilities.java @@ -1,10 +1,13 @@ package com.projectkorra.ProjectKorra.Ability; +import java.util.Arrays; + public enum StockAbilities { + // Old Bending AirBlast, AirBubble, AirShield, AirSuction, AirSwipe, Tornado, AirScooter, AirSpout, AirBurst, - Catapult, RaiseEarth, EarthGrab, EarthTunnel, EarthBlast, Collapse, Tremorsense, EarthArmor, Shockwave, Extraction, + Catapult, RaiseEarth, EarthGrab, EarthTunnel, EarthBlast, Collapse, Tremorsense, EarthArmor, Shockwave, HeatControl, Blaze, FireJet, Illumination, WallOfFire, FireBlast, Lightning, FireBurst, FireShield, @@ -12,7 +15,10 @@ public enum StockAbilities { HighJump, RapidPunch, Paralyze, - AvatarState; + AvatarState, + + // Project Korra + Extraction; private enum AirbendingAbilities { AirBlast, AirBubble, AirShield, AirSuction, AirSwipe, Tornado, AirScooter, AirSpout, AirBurst; @@ -69,4 +75,10 @@ public enum StockAbilities { return false; } + + public static StockAbilities getAbility(int index) { + if (index == -1) + return null; + return (StockAbilities)Arrays.asList(values()).get(index); + } } diff --git a/src/com/projectkorra/ProjectKorra/Commands.java b/src/com/projectkorra/ProjectKorra/Commands.java index 94b3cc09..164289ad 100644 --- a/src/com/projectkorra/ProjectKorra/Commands.java +++ b/src/com/projectkorra/ProjectKorra/Commands.java @@ -17,8 +17,10 @@ import org.bukkit.command.PluginCommand; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitTask; import com.projectkorra.ProjectKorra.Ability.AbilityModuleManager; +import com.projectkorra.ProjectKorra.Ability.StockAbilities; public class Commands { @@ -48,7 +50,7 @@ public class Commands { String[] whoaliases = {"who", "w"}; String[] importaliases = {"import", "i"}; - private static int importTask; + private static BukkitTask importTask; private void init() { PluginCommand projectkorra = plugin.getCommand("projectkorra"); CommandExecutor exe; @@ -236,21 +238,35 @@ public class Commands { UUID uuid = Bukkit.getOfflinePlayer(playername).getUniqueId(); ArrayList element = new ArrayList(); List oe = bendingPlayers.getIntegerList(string + ".BendingTypes"); + HashMap abilities = new HashMap(); + List oa = bendingPlayers.getIntegerList(string + ".SlotAbilities"); + boolean permaremoved = bendingPlayers.getBoolean(string + ".Permaremoved"); + int slot = 1; + for (int i : oa) { + if (StockAbilities.getAbility(i) != null) { + abilities.put(slot, StockAbilities.getAbility(i).toString()); + slot++; + } else { + abilities.put(slot, null); + slot++; + } + } + for (int i : oe) { if (Element.getType(i) != null) { element.add(Element.getType(i)); } } - BendingPlayer bPlayer = new BendingPlayer(uuid, playername, element, new HashMap(), false); + BendingPlayer bPlayer = new BendingPlayer(uuid, playername, element, abilities, permaremoved); bPlayers.add(bPlayer); } final int total = bPlayers.size(); final CommandSender sender = s; s.sendMessage(ChatColor.GREEN + "Import of data started. Do NOT stop / reload your server."); - importTask = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { + importTask = Bukkit.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() { public void run() { int i = 0; if (i >= 10) { @@ -261,7 +277,7 @@ public class Commands { while (i < 10) { if (bPlayers.isEmpty()) { sender.sendMessage(ChatColor.GREEN + "Import complete, it may be best to reload your server."); - Bukkit.getServer().getScheduler().cancelTask(importTask); + Bukkit.getServer().getScheduler().cancelTask(importTask.getTaskId()); for (Player player: Bukkit.getOnlinePlayers()) { Methods.createBendingPlayer(player.getUniqueId(), player.getName()); } @@ -275,7 +291,12 @@ public class Commands { if (bPlayer.hasElement(Element.Fire)) elements.append("f"); if (bPlayer.hasElement(Element.Chi)) elements.append("c"); - DBConnection.sql.modifyQuery("INSERT INTO pk_players (uuid, player, element, permaremoved) VALUES ('" + bPlayer.uuid.toString() + "', '" + bPlayer.player + "', '" + elements + "', 'false')"); + HashMap abilities = bPlayer.abilities; + + DBConnection.sql.modifyQuery("INSERT INTO pk_players (uuid, player, element, permaremoved) VALUES ('" + bPlayer.uuid.toString() + "', '" + bPlayer.player + "', '" + elements + "', '" + bPlayer.isPermaRemoved() +"')"); + for (int slot = 1; slot < 10; slot++) { + DBConnection.sql.modifyQuery("UPDATE pk_players SET slot" + slot + " = '" + abilities.get(slot) + "' WHERE player = '" + bPlayer.getPlayerName() + "'"); + } // ResultSet rs2 = DBConnection.sql.readQuery("SELECT * FROM pk_players WHERE uuid = '" + bPlayer.uuid.toString() + "'"); // try { diff --git a/src/com/projectkorra/ProjectKorra/Methods.java b/src/com/projectkorra/ProjectKorra/Methods.java index 07e91ea1..35671d39 100644 --- a/src/com/projectkorra/ProjectKorra/Methods.java +++ b/src/com/projectkorra/ProjectKorra/Methods.java @@ -232,36 +232,33 @@ public class Methods { - public static void deserializeFile() { - File readFile = new File(".", "bendingPlayers.yml"); + public static void deserializeFile() { + File readFile = new File(".", "bendingPlayers.yml"); File writeFile = new File(".", "converted.yml"); if (readFile.exists()) { -// plugin.log.info("File exists"); - try - { - DataInputStream input = new DataInputStream(new FileInputStream(readFile)); - BufferedReader reader = new BufferedReader(new InputStreamReader(input)); + // plugin.log.info("File exists"); + try { + DataInputStream input = new DataInputStream(new FileInputStream(readFile)); + BufferedReader reader = new BufferedReader(new InputStreamReader(input)); - DataOutputStream output = new DataOutputStream(new FileOutputStream(writeFile)); - BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output)); - String line; - while ((line = reader.readLine()) != null) - { - if (!line.trim().contains("==: BendingPlayer")) - { - writer.write(line + "\n"); - } - } + DataOutputStream output = new DataOutputStream(new FileOutputStream(writeFile)); + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output)); + String line; + while ((line = reader.readLine()) != null) { + if (!line.trim().contains("==: BendingPlayer")) { + writer.write(line + "\n"); + } + } - reader.close(); - input.close(); - writer.close(); - output.close(); - } catch (IOException e) { - e.printStackTrace(); - } + reader.close(); + input.close(); + writer.close(); + output.close(); + } catch (IOException e) { + e.printStackTrace(); + } } - } + }