mirror of
https://github.com/TotalFreedomMC/TF-ProjectKorra.git
synced 2025-01-12 01:48:31 +00:00
Updated importer to add slot abilities
This commit is contained in:
parent
293d480e51
commit
6bad38cc18
3 changed files with 62 additions and 32 deletions
src/com/projectkorra/ProjectKorra
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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> element = new ArrayList<Element>();
|
||||
List<Integer> oe = bendingPlayers.getIntegerList(string + ".BendingTypes");
|
||||
HashMap<Integer, String> abilities = new HashMap<Integer, String>();
|
||||
List<Integer> 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<Integer, String>(), 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<Integer, String> 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 {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue