mirror of
https://github.com/TotalFreedomMC/TF-ProjectKorra.git
synced 2025-02-11 19:50:37 +00:00
Bad Commit, will revert
This commit is contained in:
parent
3354d4d6ad
commit
b0dddcb443
5 changed files with 107 additions and 64 deletions
|
@ -1,5 +1,7 @@
|
||||||
package com.projectkorra.ProjectKorra;
|
package com.projectkorra.ProjectKorra;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -107,6 +109,28 @@ public class BendingPlayer {
|
||||||
public boolean isChiBlocked() {
|
public boolean isChiBlocked() {
|
||||||
return blockedChi;
|
return blockedChi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<BendingPlayer> getBendingPlayers() {
|
||||||
|
List<BendingPlayer> bPlayers = new ArrayList<BendingPlayer>(players.values());
|
||||||
|
return bPlayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean dataExists(UUID uuid) {
|
||||||
|
ResultSet rs2 = DBConnection.sql.readQuery("SELECT * FROM pk_players WHERE uuid = '" + uuid.toString() + "'");
|
||||||
|
try {
|
||||||
|
if (rs2.next()) return true;
|
||||||
|
return false;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete() {
|
||||||
|
DBConnection.sql.modifyQuery("DELETE FROM pk_players WHERE uuid = '" + uuid.toString() + "'");
|
||||||
|
players.remove(player);
|
||||||
|
ProjectKorra.log.info("Deleted data for " + this.player);
|
||||||
|
}
|
||||||
|
|
||||||
public void setAbilities(HashMap<Integer, String> abilities) {
|
public void setAbilities(HashMap<Integer, String> abilities) {
|
||||||
this.abilities = abilities;
|
this.abilities = abilities;
|
||||||
|
|
|
@ -501,9 +501,10 @@ public class Commands {
|
||||||
Bukkit.getServer().getScheduler().cancelTask(importTask.getTaskId());
|
Bukkit.getServer().getScheduler().cancelTask(importTask.getTaskId());
|
||||||
plugin.getConfig().set("Properties.ImportEnabled", false);
|
plugin.getConfig().set("Properties.ImportEnabled", false);
|
||||||
plugin.saveConfig();
|
plugin.saveConfig();
|
||||||
for (Player player: Bukkit.getOnlinePlayers()) {
|
Methods.loadPlayers();
|
||||||
Methods.createBendingPlayer(player.getUniqueId(), player.getName());
|
// for (Player player: Bukkit.getOnlinePlayers()) {
|
||||||
}
|
// Methods.createBendingPlayer(player.getUniqueId(), player.getName());
|
||||||
|
// }
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
StringBuilder elements = new StringBuilder();
|
StringBuilder elements = new StringBuilder();
|
||||||
|
|
|
@ -139,6 +139,51 @@ public class Methods {
|
||||||
public static Integer[] nonOpaque = {0, 6, 8, 9, 10, 11, 27, 28, 30, 31, 32, 37, 38, 39, 40, 50, 51, 55, 59, 66, 68, 69, 70, 72,
|
public static Integer[] nonOpaque = {0, 6, 8, 9, 10, 11, 27, 28, 30, 31, 32, 37, 38, 39, 40, 50, 51, 55, 59, 66, 68, 69, 70, 72,
|
||||||
75, 76, 77, 78, 83, 90, 93, 94, 104, 105, 106, 111, 115, 119, 127, 131, 132};
|
75, 76, 77, 78, 83, 90, 93, 94, 104, 105, 106, 111, 115, 119, 127, 131, 132};
|
||||||
|
|
||||||
|
private static int timelimitdays = 30;
|
||||||
|
|
||||||
|
public static void loadPlayers() {
|
||||||
|
ResultSet rs2 = DBConnection.sql.readQuery("SELECT * FROM pk_players");
|
||||||
|
try {
|
||||||
|
if (!rs2.next()) {
|
||||||
|
return; // Nothing in the query!
|
||||||
|
} else {
|
||||||
|
do {
|
||||||
|
UUID uuid = UUID.fromString(rs2.getString("uuid"));
|
||||||
|
String player = rs2.getString("player");
|
||||||
|
String element = rs2.getString("element");
|
||||||
|
String permaremoved = rs2.getString("permaremoved");
|
||||||
|
boolean p = false;
|
||||||
|
ArrayList<Element> elements = new ArrayList<Element>();
|
||||||
|
if (element != null) { // Player has an element
|
||||||
|
if (element.contains("a")) elements.add(Element.Air);
|
||||||
|
if (element.contains("w")) elements.add(Element.Water);
|
||||||
|
if (element.contains("e")) elements.add(Element.Earth);
|
||||||
|
if (element.contains("f")) elements.add(Element.Fire);
|
||||||
|
if (element.contains("c")) elements.add(Element.Chi);
|
||||||
|
}
|
||||||
|
|
||||||
|
HashMap<Integer, String> abilities = new HashMap<Integer, String>();
|
||||||
|
for (int i = 1; i <= 9; i++) {
|
||||||
|
String slot = rs2.getString("slot" + i);
|
||||||
|
if (slot != null) abilities.put(i, slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (permaremoved == null) {
|
||||||
|
p = false;
|
||||||
|
}
|
||||||
|
else if (permaremoved.equals("true")) {
|
||||||
|
p = true;
|
||||||
|
}
|
||||||
|
else if (permaremoved.equals("false")) {
|
||||||
|
p = false;
|
||||||
|
}
|
||||||
|
new BendingPlayer(uuid, player, elements, abilities, p);
|
||||||
|
} while (rs2.next());
|
||||||
|
}
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Checks to see if an AbilityExists. Uses method {@link #getAbility(String)} to check if it exists.
|
* Checks to see if an AbilityExists. Uses method {@link #getAbility(String)} to check if it exists.
|
||||||
* @param string Ability Name
|
* @param string Ability Name
|
||||||
|
@ -321,56 +366,30 @@ public class Methods {
|
||||||
return player.hasPermission("bending.ability.plantbending");
|
return player.hasPermission("bending.ability.plantbending");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Creates a {@link BendingPlayer} with the data from the database. This runs when a player logs in.
|
// * Creates a {@link BendingPlayer} with the data from the database. This runs when a player logs in.
|
||||||
* @param uuid The UUID of the player
|
// * @param uuid The UUID of the player
|
||||||
* @param player The player name
|
// * @param player The player name
|
||||||
* @throws SQLException
|
// * @throws SQLException
|
||||||
*/
|
// */
|
||||||
public static void createBendingPlayer(UUID uuid, String player) {
|
// public static void createBendingPlayer(UUID uuid, String player) {
|
||||||
ResultSet rs2 = DBConnection.sql.readQuery("SELECT * FROM pk_players WHERE uuid = '" + uuid.toString() + "'");
|
// ResultSet rs2 = DBConnection.sql.readQuery("SELECT * FROM pk_players WHERE uuid = '" + uuid.toString() + "'");
|
||||||
try {
|
// try {
|
||||||
if (!rs2.next()) { // Data doesn't exist, we want a completely new player.
|
// if (!rs2.next()) { // Data doesn't exist, we want a completely new player.
|
||||||
new BendingPlayer(uuid, player, new ArrayList<Element>(), new HashMap<Integer, String>(), false);
|
// new BendingPlayer(uuid, player, new ArrayList<Element>(), new HashMap<Integer, String>(), false);
|
||||||
DBConnection.sql.modifyQuery("INSERT INTO pk_players (uuid, player) VALUES ('" + uuid.toString() + "', '" + player + "')");
|
// DBConnection.sql.modifyQuery("INSERT INTO pk_players (uuid, player) VALUES ('" + uuid.toString() + "', '" + player + "')");
|
||||||
ProjectKorra.log.info("Created new BendingPlayer for " + player);
|
// ProjectKorra.log.info("Created new BendingPlayer for " + player);
|
||||||
} else {
|
// } else {
|
||||||
// The player has at least played before.
|
// }
|
||||||
String player2 = rs2.getString("player");
|
// } catch (SQLException ex) {
|
||||||
if (!player.equalsIgnoreCase(player2)) DBConnection.sql.modifyQuery("UPDATE pk_players SET player = '" + player2 + "' WHERE uuid = '" + uuid.toString() + "'"); // They have changed names.
|
// ex.printStackTrace();
|
||||||
String element = rs2.getString("element");
|
// }
|
||||||
String permaremoved = rs2.getString("permaremoved");
|
// }
|
||||||
boolean p = false;
|
|
||||||
ArrayList<Element> elements = new ArrayList<Element>();
|
public static void createNewBendingPlayer(UUID uuid, String player) {
|
||||||
if (element != null) { // Player has an element.
|
new BendingPlayer(uuid, player, new ArrayList<Element>(), new HashMap<Integer, String>(), false);
|
||||||
if (element.contains("a")) elements.add(Element.Air);
|
DBConnection.sql.modifyQuery("INSERT INTO pk_players (uuid, player) VALUES ('" + uuid.toString() + "', '" + player + "')");
|
||||||
if (element.contains("w")) elements.add(Element.Water);
|
ProjectKorra.log.info("Created new BendingPlayer for " + player);
|
||||||
if (element.contains("e")) elements.add(Element.Earth);
|
|
||||||
if (element.contains("f")) elements.add(Element.Fire);
|
|
||||||
if (element.contains("c")) elements.add(Element.Chi);
|
|
||||||
}
|
|
||||||
|
|
||||||
HashMap<Integer, String> abilities = new HashMap<Integer, String>();
|
|
||||||
for (int i = 1; i <= 9; i++) {
|
|
||||||
String slot = rs2.getString("slot" + i);
|
|
||||||
if (slot != null) abilities.put(i, slot);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (permaremoved == null) {
|
|
||||||
p = false;
|
|
||||||
}
|
|
||||||
else if (permaremoved.equals("true")) {
|
|
||||||
p = true;
|
|
||||||
}
|
|
||||||
else if (permaremoved.equals("false")) {
|
|
||||||
p = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
new BendingPlayer(uuid, player2, elements, abilities, p);
|
|
||||||
}
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1620,9 +1639,6 @@ public class Methods {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reloadPlugin() {
|
public static void reloadPlugin() {
|
||||||
// for (Player player: Bukkit.getOnlinePlayers()) {
|
|
||||||
// Methods.saveBendingPlayer(player.getName());
|
|
||||||
// }
|
|
||||||
DBConnection.sql.close();
|
DBConnection.sql.close();
|
||||||
plugin.reloadConfig();
|
plugin.reloadConfig();
|
||||||
Methods.stopBending();
|
Methods.stopBending();
|
||||||
|
@ -1632,9 +1648,7 @@ public class Methods {
|
||||||
DBConnection.db = plugin.getConfig().getString("Storage.MySQL.db");
|
DBConnection.db = plugin.getConfig().getString("Storage.MySQL.db");
|
||||||
DBConnection.user = plugin.getConfig().getString("Storage.MySQL.user");
|
DBConnection.user = plugin.getConfig().getString("Storage.MySQL.user");
|
||||||
DBConnection.init();
|
DBConnection.init();
|
||||||
for (Player player: Bukkit.getOnlinePlayers()) {
|
loadPlayers();
|
||||||
Methods.createBendingPlayer(player.getUniqueId(), player.getName());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeAllEarthbendedBlocks() {
|
public static void removeAllEarthbendedBlocks() {
|
||||||
|
|
|
@ -286,7 +286,10 @@ public class PKListener implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||||
Player player = e.getPlayer();
|
Player player = e.getPlayer();
|
||||||
Methods.createBendingPlayer(e.getPlayer().getUniqueId(), player.getName());
|
BendingPlayer bPlayer = Methods.getBendingPlayer(player.getName());
|
||||||
|
if (bPlayer == null) {
|
||||||
|
Methods.createNewBendingPlayer(player.getUniqueId(), player.getName());
|
||||||
|
}
|
||||||
Preset.loadPresets(player);
|
Preset.loadPresets(player);
|
||||||
String append = "";
|
String append = "";
|
||||||
boolean chatEnabled = ProjectKorra.plugin.getConfig().getBoolean("Properties.Chat.Enable");
|
boolean chatEnabled = ProjectKorra.plugin.getConfig().getBoolean("Properties.Chat.Enable");
|
||||||
|
|
|
@ -48,10 +48,11 @@ public class ProjectKorra extends JavaPlugin {
|
||||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, new ChiblockingManager(this), 0, 1);
|
getServer().getScheduler().scheduleSyncRepeatingTask(this, new ChiblockingManager(this), 0, 1);
|
||||||
|
|
||||||
DBConnection.init();
|
DBConnection.init();
|
||||||
for (Player player: Bukkit.getOnlinePlayers()) {
|
Methods.loadPlayers();
|
||||||
Methods.createBendingPlayer(player.getUniqueId(), player.getName());
|
// for (Player player: Bukkit.getOnlinePlayers()) {
|
||||||
Preset.loadPresets(player);
|
// Methods.createBendingPlayer(player.getUniqueId(), player.getName());
|
||||||
}
|
// Preset.loadPresets(player);
|
||||||
|
// }
|
||||||
getServer().getPluginManager().registerEvents(new PKListener(this), this);
|
getServer().getPluginManager().registerEvents(new PKListener(this), this);
|
||||||
|
|
||||||
if (getServer().getPluginManager().getPlugin("TagAPI") != null) {
|
if (getServer().getPluginManager().getPlugin("TagAPI") != null) {
|
||||||
|
|
Loading…
Reference in a new issue