mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 14:38:52 +00:00
Encapsulate some more variables
Refactor Settings class a bit and move header straight to the file
This commit is contained in:
30 files changed
+248
-255
No files matched your search
@@ -26,23 +26,23 @@ public class DataManager {
|
||||
|
||||
public static String createLocationsTable = "";
|
||||
|
||||
public static final String createHomesTable = "CREATE TABLE IF NOT EXISTS " + HuskHomes.settings.getHomesDataTable() + " (" +
|
||||
public static final String createHomesTable = "CREATE TABLE IF NOT EXISTS " + HuskHomes.getSettings().getHomesDataTable() + " (" +
|
||||
"`player_id` integer NOT NULL," +
|
||||
"`location_id` integer NOT NULL," +
|
||||
"`name` varchar(16) NOT NULL," +
|
||||
"`description` varchar(255) NOT NULL," +
|
||||
"`public` boolean NOT NULL," +
|
||||
"PRIMARY KEY (`player_id`, `name`)," +
|
||||
"FOREIGN KEY (`player_id`) REFERENCES " + HuskHomes.settings.getPlayerDataTable() + " (`player_id`) ON DELETE CASCADE ON UPDATE NO ACTION," +
|
||||
"FOREIGN KEY (`location_id`) REFERENCES " + HuskHomes.settings.getLocationsDataTable() + " (`location_id`) ON DELETE CASCADE ON UPDATE NO ACTION" +
|
||||
"FOREIGN KEY (`player_id`) REFERENCES " + HuskHomes.getSettings().getPlayerDataTable() + " (`player_id`) ON DELETE CASCADE ON UPDATE NO ACTION," +
|
||||
"FOREIGN KEY (`location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE CASCADE ON UPDATE NO ACTION" +
|
||||
");";
|
||||
|
||||
public static final String createWarpsTable = "CREATE TABLE IF NOT EXISTS " + HuskHomes.settings.getWarpsDataTable() + " (" +
|
||||
public static final String createWarpsTable = "CREATE TABLE IF NOT EXISTS " + HuskHomes.getSettings().getWarpsDataTable() + " (" +
|
||||
"`location_id` integer NOT NULL," +
|
||||
"`name` varchar(16) NOT NULL UNIQUE," +
|
||||
"`description` varchar(255) NOT NULL," +
|
||||
"PRIMARY KEY (`location_id`)," +
|
||||
"FOREIGN KEY (`location_id`) REFERENCES " + HuskHomes.settings.getLocationsDataTable() + " (`location_id`) ON DELETE CASCADE ON UPDATE NO ACTION" +
|
||||
"FOREIGN KEY (`location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE CASCADE ON UPDATE NO ACTION" +
|
||||
");";
|
||||
|
||||
private static final HuskHomes plugin = HuskHomes.getInstance();
|
||||
@@ -66,7 +66,7 @@ public class DataManager {
|
||||
|
||||
try {
|
||||
conn = getConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.settings.getPlayerDataTable() + " WHERE `user_uuid`=?;");
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getPlayerDataTable() + " WHERE `user_uuid`=?;");
|
||||
ps.setString(1, playerUUID.toString());
|
||||
rs = ps.executeQuery();
|
||||
if (rs != null) {
|
||||
@@ -92,7 +92,7 @@ public class DataManager {
|
||||
|
||||
try {
|
||||
conn = getConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.settings.getPlayerDataTable() + " WHERE `username`=?;");
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getPlayerDataTable() + " WHERE `username`=?;");
|
||||
ps.setString(1, playerUsername);
|
||||
rs = ps.executeQuery();
|
||||
if (rs != null) {
|
||||
@@ -118,7 +118,7 @@ public class DataManager {
|
||||
|
||||
try {
|
||||
conn = getConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.settings.getPlayerDataTable() + " WHERE `player_id`=?;");
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getPlayerDataTable() + " WHERE `player_id`=?;");
|
||||
ps.setInt(1, playerID);
|
||||
rs = ps.executeQuery();
|
||||
if (rs != null) {
|
||||
@@ -155,7 +155,7 @@ public class DataManager {
|
||||
|
||||
try {
|
||||
conn = getConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.settings.getPlayerDataTable() + " WHERE `player_id`=?;");
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getPlayerDataTable() + " WHERE `player_id`=?;");
|
||||
ps.setInt(1, playerID);
|
||||
rs = ps.executeQuery();
|
||||
if (rs != null) {
|
||||
@@ -183,7 +183,7 @@ public class DataManager {
|
||||
|
||||
try {
|
||||
conn = getConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.settings.getPlayerDataTable() + " WHERE `player_id`=?;");
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getPlayerDataTable() + " WHERE `player_id`=?;");
|
||||
ps.setInt(1, playerID);
|
||||
rs = ps.executeQuery();
|
||||
if (rs != null) {
|
||||
@@ -251,7 +251,7 @@ public class DataManager {
|
||||
|
||||
try {
|
||||
conn = getConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.settings.getHomesDataTable() + " WHERE `player_id`=?;");
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getHomesDataTable() + " WHERE `player_id`=?;");
|
||||
ps.setInt(1, playerID);
|
||||
rs = ps.executeQuery();
|
||||
if (rs != null) {
|
||||
@@ -286,7 +286,7 @@ public class DataManager {
|
||||
|
||||
try {
|
||||
conn = getConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.settings.getHomesDataTable() + " WHERE `public`;");
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getHomesDataTable() + " WHERE `public`;");
|
||||
rs = ps.executeQuery();
|
||||
if (rs != null) {
|
||||
List<Home> publicHomes = new ArrayList<>();
|
||||
@@ -317,7 +317,7 @@ public class DataManager {
|
||||
|
||||
try {
|
||||
conn = getConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.settings.getWarpsDataTable() + ";");
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getWarpsDataTable() + ";");
|
||||
rs = ps.executeQuery();
|
||||
List<Warp> warps = new ArrayList<>();
|
||||
if (rs != null) {
|
||||
@@ -348,7 +348,7 @@ public class DataManager {
|
||||
|
||||
try {
|
||||
conn = getConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.settings.getWarpsDataTable() + " WHERE `name`=?;");
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getWarpsDataTable() + " WHERE `name`=?;");
|
||||
ps.setString(1, name);
|
||||
rs = ps.executeQuery();
|
||||
if (rs != null) {
|
||||
@@ -382,7 +382,7 @@ public class DataManager {
|
||||
|
||||
try {
|
||||
conn = getConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.settings.getHomesDataTable() + " WHERE `player_id`=? AND `name`=?;");
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getHomesDataTable() + " WHERE `player_id`=? AND `name`=?;");
|
||||
ps.setInt(1, ownerID);
|
||||
ps.setString(2, homeName);
|
||||
rs = ps.executeQuery();
|
||||
@@ -420,7 +420,7 @@ public class DataManager {
|
||||
|
||||
try {
|
||||
conn = getConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.settings.getWarpsDataTable() + " WHERE `name`=?;");
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getWarpsDataTable() + " WHERE `name`=?;");
|
||||
ps.setString(1, warpName);
|
||||
rs = ps.executeQuery();
|
||||
if (rs != null) {
|
||||
@@ -467,7 +467,7 @@ public class DataManager {
|
||||
public static void updateHomeLocation(String ownerName, String homeName, Location newLocation) {
|
||||
Integer playerID = getPlayerId(ownerName);
|
||||
updateHomeTeleportLocation(playerID,homeName,
|
||||
new TeleportationPoint(newLocation, HuskHomes.settings.getServerID()));
|
||||
new TeleportationPoint(newLocation, HuskHomes.getSettings().getServerID()));
|
||||
}
|
||||
|
||||
public static void updateWarpName(String warpName, String newName) {
|
||||
@@ -480,7 +480,7 @@ public class DataManager {
|
||||
|
||||
public static void updateWarpLocation(String warpName, Location newLocation) {
|
||||
updateWarpTeleportLocation(warpName,
|
||||
new TeleportationPoint(newLocation, HuskHomes.settings.getServerID()));
|
||||
new TeleportationPoint(newLocation, HuskHomes.getSettings().getServerID()));
|
||||
}
|
||||
|
||||
// Return a home with a given owner username and home name
|
||||
@@ -492,7 +492,7 @@ public class DataManager {
|
||||
|
||||
try {
|
||||
conn = getConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.settings.getHomesDataTable() + " WHERE `player_id`=? AND `name`=?;");
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getHomesDataTable() + " WHERE `player_id`=? AND `name`=?;");
|
||||
ps.setInt(1, playerID);
|
||||
ps.setString(2, homeName);
|
||||
rs = ps.executeQuery();
|
||||
@@ -529,7 +529,7 @@ public class DataManager {
|
||||
|
||||
try {
|
||||
conn = getConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.settings.getWarpsDataTable() + " WHERE `name`=?;");
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getWarpsDataTable() + " WHERE `name`=?;");
|
||||
ps.setString(1, warpName);
|
||||
rs = ps.executeQuery();
|
||||
if (rs != null) {
|
||||
@@ -561,7 +561,7 @@ public class DataManager {
|
||||
|
||||
try {
|
||||
conn = getConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.settings.getHomesDataTable() + " WHERE `player_id`=? AND `name`=?;");
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getHomesDataTable() + " WHERE `player_id`=? AND `name`=?;");
|
||||
ps.setInt(1, playerID);
|
||||
ps.setString(2, homeName);
|
||||
rs = ps.executeQuery();
|
||||
@@ -589,7 +589,7 @@ public class DataManager {
|
||||
|
||||
try {
|
||||
conn = getConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.settings.getPlayerDataTable() + " WHERE `user_uuid`=?;");
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getPlayerDataTable() + " WHERE `user_uuid`=?;");
|
||||
ps.setString(1, playerUUIDString);
|
||||
rs = ps.executeQuery();
|
||||
if (rs != null) {
|
||||
@@ -611,7 +611,7 @@ public class DataManager {
|
||||
|
||||
try {
|
||||
conn = getConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.settings.getLocationsDataTable() + " WHERE `location_id`=?;");
|
||||
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getLocationsDataTable() + " WHERE `location_id`=?;");
|
||||
ps.setInt(1, locationID);
|
||||
rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
@@ -622,7 +622,7 @@ public class DataManager {
|
||||
} else {
|
||||
Bukkit.getLogger().severe("An SQL exception occurred in retrieving a teleportation location.");
|
||||
Bukkit.getLogger().severe("location ID: " + locationID.toString());
|
||||
Bukkit.getLogger().severe("SELECT * FROM " + HuskHomes.settings.getLocationsDataTable() + " WHERE `location_id`=" + locationID.toString() + ";");
|
||||
Bukkit.getLogger().severe("SELECT * FROM " + HuskHomes.getSettings().getLocationsDataTable() + " WHERE `location_id`=" + locationID.toString() + ";");
|
||||
return null;
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
@@ -697,7 +697,7 @@ public class DataManager {
|
||||
Integer playerID = getPlayerId(p.getUniqueId());
|
||||
if (playerID != null) {
|
||||
long currentTime = Instant.now().getEpochSecond();
|
||||
int newCooldownTime = (int) currentTime + (60 * HuskHomes.settings.getRtpCooldown());
|
||||
int newCooldownTime = (int) currentTime + (60 * HuskHomes.getSettings().getRtpCooldown());
|
||||
database.setRtpCooldown(playerID, newCooldownTime);
|
||||
}
|
||||
}
|
||||
@@ -754,8 +754,8 @@ public class DataManager {
|
||||
}
|
||||
|
||||
public static void setupStorage() {
|
||||
if (HuskHomes.settings.getStorageType().equalsIgnoreCase("mysql")) {
|
||||
createPlayerTable = "CREATE TABLE IF NOT EXISTS " + HuskHomes.settings.getPlayerDataTable() + " (" +
|
||||
if (HuskHomes.getSettings().getStorageType().equalsIgnoreCase("mysql")) {
|
||||
createPlayerTable = "CREATE TABLE IF NOT EXISTS " + HuskHomes.getSettings().getPlayerDataTable() + " (" +
|
||||
"`player_id` integer AUTO_INCREMENT," +
|
||||
"`user_uuid` char(36) NOT NULL UNIQUE," +
|
||||
"`username` varchar(16) NOT NULL," +
|
||||
@@ -766,10 +766,10 @@ public class DataManager {
|
||||
"`last_location_id` integer NULL," +
|
||||
|
||||
"PRIMARY KEY (`player_id`)," +
|
||||
"FOREIGN KEY (`dest_location_id`) REFERENCES " + HuskHomes.settings.getLocationsDataTable() + " (`location_id`) ON DELETE SET NULL ON UPDATE NO ACTION," +
|
||||
"FOREIGN KEY (`last_location_id`) REFERENCES " + HuskHomes.settings.getLocationsDataTable() + " (`location_id`) ON DELETE SET NULL ON UPDATE NO ACTION" +
|
||||
"FOREIGN KEY (`dest_location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE SET NULL ON UPDATE NO ACTION," +
|
||||
"FOREIGN KEY (`last_location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE SET NULL ON UPDATE NO ACTION" +
|
||||
");";
|
||||
createLocationsTable = "CREATE TABLE IF NOT EXISTS " + HuskHomes.settings.getLocationsDataTable() + " (" +
|
||||
createLocationsTable = "CREATE TABLE IF NOT EXISTS " + HuskHomes.getSettings().getLocationsDataTable() + " (" +
|
||||
"`location_id` integer AUTO_INCREMENT," +
|
||||
"`server` text NOT NULL," +
|
||||
"`world` text NOT NULL," +
|
||||
@@ -782,7 +782,7 @@ public class DataManager {
|
||||
"PRIMARY KEY (`location_id`)" +
|
||||
");";
|
||||
} else {
|
||||
createPlayerTable = "CREATE TABLE IF NOT EXISTS " + HuskHomes.settings.getPlayerDataTable() + " (" +
|
||||
createPlayerTable = "CREATE TABLE IF NOT EXISTS " + HuskHomes.getSettings().getPlayerDataTable() + " (" +
|
||||
"`player_id` integer NOT NULL," +
|
||||
"`user_uuid` char(36) NOT NULL UNIQUE," +
|
||||
"`username` varchar(16) NOT NULL," +
|
||||
@@ -792,10 +792,10 @@ public class DataManager {
|
||||
"`dest_location_id` integer NULL," +
|
||||
"`last_location_id` integer NULL," +
|
||||
"PRIMARY KEY (`player_id`)," +
|
||||
"FOREIGN KEY (`dest_location_id`) REFERENCES " + HuskHomes.settings.getLocationsDataTable() + " (`location_id`) ON DELETE SET NULL ON UPDATE NO ACTION," +
|
||||
"FOREIGN KEY (`last_location_id`) REFERENCES " + HuskHomes.settings.getLocationsDataTable() + " (`location_id`) ON DELETE SET NULL ON UPDATE NO ACTION" +
|
||||
"FOREIGN KEY (`dest_location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE SET NULL ON UPDATE NO ACTION," +
|
||||
"FOREIGN KEY (`last_location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE SET NULL ON UPDATE NO ACTION" +
|
||||
");";
|
||||
createLocationsTable = "CREATE TABLE IF NOT EXISTS " + HuskHomes.settings.getLocationsDataTable() + " (" +
|
||||
createLocationsTable = "CREATE TABLE IF NOT EXISTS " + HuskHomes.getSettings().getLocationsDataTable() + " (" +
|
||||
"`location_id` integer PRIMARY KEY," +
|
||||
"`server` text NOT NULL," +
|
||||
"`world` text NOT NULL," +
|
||||
|
||||
@@ -15,8 +15,8 @@ import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public abstract class Database {
|
||||
HuskHomes plugin;
|
||||
Connection connection;
|
||||
protected HuskHomes plugin;
|
||||
private Connection connection;
|
||||
|
||||
public Database(HuskHomes instance) {
|
||||
plugin = instance;
|
||||
@@ -29,7 +29,7 @@ public abstract class Database {
|
||||
public void initialize() {
|
||||
connection = getSQLConnection();
|
||||
try {
|
||||
PreparedStatement ps = connection.prepareStatement("SELECT * FROM " + HuskHomes.settings.getPlayerDataTable() + ";");
|
||||
PreparedStatement ps = connection.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getPlayerDataTable() + ";");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
close(ps, rs);
|
||||
|
||||
@@ -41,7 +41,7 @@ public abstract class Database {
|
||||
// Insert a teleportation point, returns generated id
|
||||
public Integer addTeleportationPoint(TeleportationPoint point, Connection conn) {
|
||||
try {
|
||||
PreparedStatement ps = conn.prepareStatement("INSERT INTO " + HuskHomes.settings.getLocationsDataTable() + " (world,server,x,y,z,yaw,pitch) VALUES(?,?,?,?,?,?,?);", Statement.RETURN_GENERATED_KEYS);
|
||||
PreparedStatement ps = conn.prepareStatement("INSERT INTO " + HuskHomes.getSettings().getLocationsDataTable() + " (world,server,x,y,z,yaw,pitch) VALUES(?,?,?,?,?,?,?);", Statement.RETURN_GENERATED_KEYS);
|
||||
|
||||
ps.setString(1, point.getWorldName());
|
||||
ps.setString(2, point.getServer());
|
||||
@@ -72,7 +72,7 @@ public abstract class Database {
|
||||
conn = getSQLConnection();
|
||||
Integer locationID = addTeleportationPoint(home, conn);
|
||||
|
||||
ps = conn.prepareStatement("INSERT INTO " + HuskHomes.settings.getHomesDataTable() + " (player_id,location_id,name,description,public) VALUES(?,?,?,?,?);");
|
||||
ps = conn.prepareStatement("INSERT INTO " + HuskHomes.getSettings().getHomesDataTable() + " (player_id,location_id,name,description,public) VALUES(?,?,?,?,?);");
|
||||
ps.setInt(1, playerID);
|
||||
ps.setInt(2, locationID);
|
||||
ps.setString(3, home.getName());
|
||||
@@ -96,7 +96,7 @@ public abstract class Database {
|
||||
Integer locationID = addTeleportationPoint(warp, conn);
|
||||
|
||||
// Insert the warp with the location_id of the last inserted teleport point
|
||||
ps = conn.prepareStatement("INSERT INTO " + HuskHomes.settings.getWarpsDataTable() + " (location_id,name,description) VALUES(?,?,?);");
|
||||
ps = conn.prepareStatement("INSERT INTO " + HuskHomes.getSettings().getWarpsDataTable() + " (location_id,name,description) VALUES(?,?,?);");
|
||||
ps.setInt(1, locationID);
|
||||
ps.setString(2, warp.getName());
|
||||
ps.setString(3, warp.getDescription());
|
||||
@@ -115,7 +115,7 @@ public abstract class Database {
|
||||
conn = getSQLConnection();
|
||||
|
||||
// Delete the warp with the given name
|
||||
ps = conn.prepareStatement("DELETE FROM " + HuskHomes.settings.getWarpsDataTable() + " WHERE `name`=?;");
|
||||
ps = conn.prepareStatement("DELETE FROM " + HuskHomes.getSettings().getWarpsDataTable() + " WHERE `name`=?;");
|
||||
ps.setString(1, warpName);
|
||||
ps.executeUpdate();
|
||||
|
||||
@@ -133,7 +133,7 @@ public abstract class Database {
|
||||
conn = getSQLConnection();
|
||||
|
||||
// Delete the home with the given name and player ID
|
||||
ps = conn.prepareStatement("DELETE FROM " + HuskHomes.settings.getHomesDataTable() + " WHERE `name`=? AND `player_id`=?;");
|
||||
ps = conn.prepareStatement("DELETE FROM " + HuskHomes.getSettings().getHomesDataTable() + " WHERE `name`=? AND `player_id`=?;");
|
||||
ps.setString(1, homeName);
|
||||
ps.setInt(2, playerID);
|
||||
ps.executeUpdate();
|
||||
@@ -151,7 +151,7 @@ public abstract class Database {
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
|
||||
ps = conn.prepareStatement("INSERT INTO " + HuskHomes.settings.getPlayerDataTable() + " (user_uuid,username,home_slots,rtp_cooldown,is_teleporting) VALUES(?,?,?,?,?);");
|
||||
ps = conn.prepareStatement("INSERT INTO " + HuskHomes.getSettings().getPlayerDataTable() + " (user_uuid,username,home_slots,rtp_cooldown,is_teleporting) VALUES(?,?,?,?,?);");
|
||||
ps.setString(1, p.getUniqueId().toString());
|
||||
ps.setString(2, p.getName());
|
||||
ps.setInt(3, Home.getFreeHomes(p));
|
||||
@@ -172,10 +172,10 @@ public abstract class Database {
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
|
||||
ps = conn.prepareStatement("INSERT INTO " + HuskHomes.settings.getPlayerDataTable() + " (user_uuid,username,home_slots,rtp_cooldown,is_teleporting) VALUES(?,?,?,?,?);");
|
||||
ps = conn.prepareStatement("INSERT INTO " + HuskHomes.getSettings().getPlayerDataTable() + " (user_uuid,username,home_slots,rtp_cooldown,is_teleporting) VALUES(?,?,?,?,?);");
|
||||
ps.setString(1, playerUUID.toString());
|
||||
ps.setString(2, playerName);
|
||||
ps.setInt(3, HuskHomes.settings.getFreeHomeSlots());
|
||||
ps.setInt(3, HuskHomes.getSettings().getFreeHomeSlots());
|
||||
ps.setInt(4, 0);
|
||||
ps.setBoolean(5, false);
|
||||
|
||||
@@ -193,7 +193,7 @@ public abstract class Database {
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
|
||||
ps = conn.prepareStatement("INSERT INTO " + HuskHomes.settings.getPlayerDataTable() + " (user_uuid,username,home_slots,rtp_cooldown,is_teleporting) VALUES(?,?,?,?,?);");
|
||||
ps = conn.prepareStatement("INSERT INTO " + HuskHomes.getSettings().getPlayerDataTable() + " (user_uuid,username,home_slots,rtp_cooldown,is_teleporting) VALUES(?,?,?,?,?);");
|
||||
ps.setString(1, playerUUID.toString());
|
||||
ps.setString(2, playerName);
|
||||
ps.setInt(3, homeSlots);
|
||||
@@ -212,7 +212,7 @@ public abstract class Database {
|
||||
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.settings.getPlayerDataTable() + " SET `username`=? WHERE `player_id`=?;");
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `username`=? WHERE `player_id`=?;");
|
||||
ps.setString(1, newName);
|
||||
ps.setInt(2, playerID);
|
||||
ps.executeUpdate();
|
||||
@@ -227,7 +227,7 @@ public abstract class Database {
|
||||
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.settings.getPlayerDataTable() + " SET `is_teleporting`=? WHERE `player_id`=?;");
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `is_teleporting`=? WHERE `player_id`=?;");
|
||||
ps.setBoolean(1, value);
|
||||
ps.setInt(2, playerID);
|
||||
ps.executeUpdate();
|
||||
@@ -242,7 +242,7 @@ public abstract class Database {
|
||||
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.settings.getPlayerDataTable() + " SET `home_slots`=? WHERE `player_id`=?;");
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `home_slots`=? WHERE `player_id`=?;");
|
||||
ps.setInt(1, newValue);
|
||||
ps.setInt(2, playerID);
|
||||
ps.executeUpdate();
|
||||
@@ -257,7 +257,7 @@ public abstract class Database {
|
||||
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.settings.getPlayerDataTable() + " SET `rtp_cooldown`=? WHERE `player_id`=?;");
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `rtp_cooldown`=? WHERE `player_id`=?;");
|
||||
ps.setInt(1, newTime);
|
||||
ps.setInt(2, playerID);
|
||||
ps.executeUpdate();
|
||||
@@ -274,7 +274,7 @@ public abstract class Database {
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
|
||||
ps = conn.prepareStatement("DELETE FROM " + HuskHomes.settings.getLocationsDataTable() + " WHERE `location_id`=?;");
|
||||
ps = conn.prepareStatement("DELETE FROM " + HuskHomes.getSettings().getLocationsDataTable() + " WHERE `location_id`=?;");
|
||||
ps.setInt(1, locationID);
|
||||
|
||||
ps.executeUpdate();
|
||||
@@ -292,7 +292,7 @@ public abstract class Database {
|
||||
conn = getSQLConnection();
|
||||
|
||||
// Set the home location ID to the new teleport point for the given home
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.settings.getHomesDataTable() + " SET `public`=? WHERE `name`=? AND `player_id`=?;");
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getHomesDataTable() + " SET `public`=? WHERE `name`=? AND `player_id`=?;");
|
||||
ps.setBoolean(1, isPublic);
|
||||
ps.setString(2, homeName);
|
||||
ps.setInt(3, ownerID);
|
||||
@@ -314,7 +314,7 @@ public abstract class Database {
|
||||
Integer locationID = addTeleportationPoint(point, conn);
|
||||
|
||||
// Set the home location ID to the new teleport point for the given home
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.settings.getHomesDataTable() + " SET `location_id`=? WHERE `name`=? AND `player_id`=?;");
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getHomesDataTable() + " SET `location_id`=? WHERE `name`=? AND `player_id`=?;");
|
||||
ps.setInt(1, locationID);
|
||||
ps.setString(2, homeName);
|
||||
ps.setInt(3, ownerID);
|
||||
@@ -336,7 +336,7 @@ public abstract class Database {
|
||||
Integer locationID = addTeleportationPoint(point, conn);
|
||||
|
||||
// Set the warp location ID to the new teleport point
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.settings.getWarpsDataTable() + " SET `location_id`=? WHERE `name`=?;");
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getWarpsDataTable() + " SET `location_id`=? WHERE `name`=?;");
|
||||
ps.setInt(1, locationID);
|
||||
ps.setString(2, warpName);
|
||||
ps.executeUpdate();
|
||||
@@ -353,7 +353,7 @@ public abstract class Database {
|
||||
conn = getSQLConnection();
|
||||
|
||||
// Update the home description
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.settings.getHomesDataTable() + " SET `description`=? WHERE `name`=? AND `player_id`=?;");
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getHomesDataTable() + " SET `description`=? WHERE `name`=? AND `player_id`=?;");
|
||||
ps.setString(1, newDescription);
|
||||
ps.setString(2, homeName);
|
||||
ps.setInt(3, ownerID);
|
||||
@@ -372,7 +372,7 @@ public abstract class Database {
|
||||
conn = getSQLConnection();
|
||||
|
||||
// Update the warp description
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.settings.getWarpsDataTable() + " SET `description`=? WHERE `name`=?;");
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getWarpsDataTable() + " SET `description`=? WHERE `name`=?;");
|
||||
ps.setString(1, newDescription);
|
||||
ps.setString(2, warpName);
|
||||
ps.executeUpdate();
|
||||
@@ -390,7 +390,7 @@ public abstract class Database {
|
||||
conn = getSQLConnection();
|
||||
|
||||
// Update the home name
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.settings.getHomesDataTable() + " SET `name`=? WHERE `name`=? AND `player_id`=?;");
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getHomesDataTable() + " SET `name`=? WHERE `name`=? AND `player_id`=?;");
|
||||
ps.setString(1, newHomeName);
|
||||
ps.setString(2, oldHomeName);
|
||||
ps.setInt(3, ownerID);
|
||||
@@ -410,7 +410,7 @@ public abstract class Database {
|
||||
conn = getSQLConnection();
|
||||
|
||||
// Update the warp name
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.settings.getWarpsDataTable() + " SET `name`=? WHERE `name`=?;");
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getWarpsDataTable() + " SET `name`=? WHERE `name`=?;");
|
||||
ps.setString(1, newWarpName);
|
||||
ps.setString(2, oldWarpName);
|
||||
|
||||
@@ -432,7 +432,7 @@ public abstract class Database {
|
||||
Integer locationID = addTeleportationPoint(point, conn);
|
||||
|
||||
// Set the destination location with the location_id of the last inserted teleport point
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.settings.getPlayerDataTable() + " SET `last_location_id`=? WHERE `player_id`=?;");
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `last_location_id`=? WHERE `player_id`=?;");
|
||||
ps.setInt(1, locationID);
|
||||
ps.setInt(2, playerID);
|
||||
ps.executeUpdate();
|
||||
@@ -453,7 +453,7 @@ public abstract class Database {
|
||||
Integer locationID = addTeleportationPoint(point, conn);
|
||||
|
||||
// Set the destination location with the location_id of the last inserted teleport point
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.settings.getPlayerDataTable() + " SET `dest_location_id`=? WHERE `player_id`=?;");
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `dest_location_id`=? WHERE `player_id`=?;");
|
||||
ps.setInt(1, locationID);
|
||||
ps.setInt(2, playerID);
|
||||
ps.executeUpdate();
|
||||
@@ -470,7 +470,7 @@ public abstract class Database {
|
||||
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.settings.getPlayerDataTable() + " SET `dest_location_id`=NULL WHERE `player_id`=?;");
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `dest_location_id`=NULL WHERE `player_id`=?;");
|
||||
ps.setInt(1, playerID);
|
||||
ps.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
@@ -485,7 +485,7 @@ public abstract class Database {
|
||||
|
||||
try {
|
||||
conn = getSQLConnection();
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.settings.getPlayerDataTable() + " SET `last_location_id`=NULL WHERE `player_id`=?;");
|
||||
ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `last_location_id`=NULL WHERE `player_id`=?;");
|
||||
ps.setInt(1, playerID);
|
||||
ps.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
|
||||
@@ -26,11 +26,11 @@ public class SQL extends Database {
|
||||
|
||||
// Initialise connection via mySQL
|
||||
private void getMySQLConnection() {
|
||||
String host = HuskHomes.settings.getMySQLhost();
|
||||
int port = HuskHomes.settings.getMySQLport();
|
||||
String database = HuskHomes.settings.getMySQLdatabase();
|
||||
String username = HuskHomes.settings.getMySQLusername();
|
||||
String password = HuskHomes.settings.getMySQLpassword();
|
||||
String host = HuskHomes.getSettings().getMySQLhost();
|
||||
int port = HuskHomes.getSettings().getMySQLport();
|
||||
String database = HuskHomes.getSettings().getMySQLdatabase();
|
||||
String username = HuskHomes.getSettings().getMySQLusername();
|
||||
String password = HuskHomes.getSettings().getMySQLpassword();
|
||||
|
||||
try {
|
||||
synchronized (HuskHomes.getInstance()) {
|
||||
@@ -70,7 +70,7 @@ public class SQL extends Database {
|
||||
public Connection getSQLConnection() {
|
||||
try {
|
||||
if (connection == null || connection.isClosed()) {
|
||||
String dataStorageType = HuskHomes.settings.getStorageType().toLowerCase();
|
||||
String dataStorageType = HuskHomes.getSettings().getStorageType().toLowerCase();
|
||||
switch (dataStorageType) {
|
||||
case "mysql":
|
||||
getMySQLConnection();
|
||||
|
||||
Reference in new issue
Block a user