mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 14:38:53 +00:00
More refactoring; temporarily remove CrossServerListHandler
This commit is contained in:
1 parent
eac0b7a1d1
commit
71330f232e
6 files changed
+58
-109
No files matched your search
@@ -1,35 +0,0 @@
|
|||||||
package me.william278.huskhomes2;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
public class CrossServerListHandler {
|
|
||||||
|
|
||||||
// A HashMap mapping all the HuskHomes servers on the Bungee Network
|
|
||||||
// (with the same Cluster ID) with their list of players
|
|
||||||
/*private static final HashMap<String,HashSet<String>> playerList = new HashMap<>();
|
|
||||||
|
|
||||||
public static HashSet<String> getOtherServerPlayerList() {
|
|
||||||
HashSet<String> players = new HashSet<>();
|
|
||||||
for (String server : playerList.keySet()) {
|
|
||||||
players.addAll(playerList.get(server));
|
|
||||||
}
|
|
||||||
return players;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*public static void updateHashset(String server, HashSet<String> players) {
|
|
||||||
playerList.put(server, players);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
/*public static void updatePlayerList(Player p) {
|
|
||||||
playerList.clear();
|
|
||||||
if (p == null) {
|
|
||||||
for (Player x : Bukkit.getOnlinePlayers()) {
|
|
||||||
p = x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (p != null) {
|
|
||||||
PluginMessageHandler.requestPlayerLists(p);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
@@ -269,7 +269,7 @@ public class Settings {
|
|||||||
return maximumHomes;
|
return maximumHomes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRtpCooldown() {
|
public int getRtpCoolDown() {
|
||||||
return rtpCooldown;
|
return rtpCooldown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,12 +16,6 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class DataManager {
|
public class DataManager {
|
||||||
|
|
||||||
private static final HuskHomes plugin = HuskHomes.getInstance();
|
|
||||||
|
|
||||||
private static Connection getConnection() {
|
|
||||||
return HuskHomes.getConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return a player's ID from their UUID
|
// Return a player's ID from their UUID
|
||||||
private static Integer getPlayerId(UUID uuid, Connection connection) throws SQLException {
|
private static Integer getPlayerId(UUID uuid, Connection connection) throws SQLException {
|
||||||
PreparedStatement ps;
|
PreparedStatement ps;
|
||||||
@@ -61,7 +55,7 @@ public class DataManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return an integer from the player table from a player ID
|
// Return an integer from the player table from a player ID
|
||||||
public static Integer getPlayerInteger(Integer playerID, String column, Connection connection) throws SQLException {
|
private static Integer getPlayerInteger(Integer playerID, String column, Connection connection) throws SQLException {
|
||||||
PreparedStatement ps;
|
PreparedStatement ps;
|
||||||
ResultSet rs;
|
ResultSet rs;
|
||||||
|
|
||||||
@@ -80,17 +74,12 @@ public class DataManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return an integer from the player table from a player object
|
// Return an integer from the player table from a player object
|
||||||
public static Integer getPlayerInteger(Player p, String column, Connection connection) throws SQLException {
|
private static Integer getPlayerInteger(Player p, String column, Connection connection) throws SQLException {
|
||||||
return getPlayerInteger(getPlayerId(p.getUniqueId(), connection), column, connection);
|
return getPlayerInteger(getPlayerId(p.getUniqueId(), connection), column, connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return an integer from the player table from a player object
|
|
||||||
public static Integer getPlayerInteger(String username, String column, Connection connection) throws SQLException {
|
|
||||||
return getPlayerInteger(getPlayerId(username, connection), column, connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return an integer from the player table from a player ID
|
// Return an integer from the player table from a player ID
|
||||||
public static String getPlayerString(Integer playerID, String column, Connection connection) throws SQLException {
|
private static String getPlayerString(Integer playerID, String column, Connection connection) throws SQLException {
|
||||||
PreparedStatement ps;
|
PreparedStatement ps;
|
||||||
ResultSet rs;
|
ResultSet rs;
|
||||||
|
|
||||||
@@ -102,14 +91,12 @@ public class DataManager {
|
|||||||
final String player = rs.getString(column);
|
final String player = rs.getString(column);
|
||||||
ps.close();
|
ps.close();
|
||||||
return player;
|
return player;
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Bukkit.getLogger().severe("Result set for a player returned null; perhaps player ID was null");
|
Bukkit.getLogger().severe("Result set for a player returned null; perhaps player ID was null");
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
ps.close();
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return if the player is teleporting
|
// Return if the player is teleporting
|
||||||
@@ -125,13 +112,12 @@ public class DataManager {
|
|||||||
final boolean isTeleporting = rs.getBoolean("is_teleporting");
|
final boolean isTeleporting = rs.getBoolean("is_teleporting");
|
||||||
ps.close();
|
ps.close();
|
||||||
return isTeleporting;
|
return isTeleporting;
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Bukkit.getLogger().severe("Failed to retrieve if player was teleporting");
|
Bukkit.getLogger().severe("Failed to retrieve if player was teleporting");
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
ps.close();
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a player's UUID
|
// Return a player's UUID
|
||||||
@@ -287,15 +273,19 @@ public class DataManager {
|
|||||||
// Delete a home's corresponding home teleport location
|
// Delete a home's corresponding home teleport location
|
||||||
public static void deleteHomeTeleportLocation(int ownerID, String homeName, Connection connection) throws SQLException {
|
public static void deleteHomeTeleportLocation(int ownerID, String homeName, Connection connection) throws SQLException {
|
||||||
Integer locationID = getHomeLocationID(ownerID, homeName, connection);
|
Integer locationID = getHomeLocationID(ownerID, homeName, connection);
|
||||||
|
if (locationID != null) {
|
||||||
deleteTeleportationPoint(locationID, connection);
|
deleteTeleportationPoint(locationID, connection);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update a home's teleport location (deletion of the old one is done afterward to prevent cascading deletion from wiping the home
|
// Update a home's teleport location (deletion of the old one is done afterward to prevent cascading deletion from wiping the home
|
||||||
public static void updateHomeTeleportLocation(int ownerID, String homeName, TeleportationPoint teleportationPoint, Connection connection) throws SQLException {
|
public static void updateHomeTeleportLocation(int ownerID, String homeName, TeleportationPoint teleportationPoint, Connection connection) throws SQLException {
|
||||||
Integer oldLocationID = getHomeLocationID(ownerID, homeName, connection);
|
Integer oldLocationID = getHomeLocationID(ownerID, homeName, connection);
|
||||||
setHomeTeleportPoint(homeName, ownerID, teleportationPoint, connection);
|
setHomeTeleportPoint(homeName, ownerID, teleportationPoint, connection);
|
||||||
|
if (oldLocationID != null) {
|
||||||
deleteTeleportationPoint(oldLocationID, connection);
|
deleteTeleportationPoint(oldLocationID, connection);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Get the ID of the teleportation point of the warp
|
// Get the ID of the teleportation point of the warp
|
||||||
public static Integer getWarpLocationID(String warpName, Connection connection) throws SQLException {
|
public static Integer getWarpLocationID(String warpName, Connection connection) throws SQLException {
|
||||||
@@ -307,7 +297,8 @@ public class DataManager {
|
|||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
if (rs != null) {
|
if (rs != null) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
int locationID = rs.getInt("location_id");
|
final int locationID = rs.getInt("location_id");
|
||||||
|
ps.close();
|
||||||
return locationID;
|
return locationID;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -320,6 +311,7 @@ public class DataManager {
|
|||||||
// Delete a warp
|
// Delete a warp
|
||||||
public static void deleteWarp(String warpName, Connection connection) throws SQLException {
|
public static void deleteWarp(String warpName, Connection connection) throws SQLException {
|
||||||
Integer warpLocationID = getWarpLocationID(warpName, connection);
|
Integer warpLocationID = getWarpLocationID(warpName, connection);
|
||||||
|
if (warpLocationID != null) {
|
||||||
deleteTeleportationPoint(warpLocationID, connection);
|
deleteTeleportationPoint(warpLocationID, connection);
|
||||||
|
|
||||||
PreparedStatement ps;
|
PreparedStatement ps;
|
||||||
@@ -327,6 +319,8 @@ public class DataManager {
|
|||||||
ps = connection.prepareStatement("DELETE FROM " + HuskHomes.getSettings().getWarpsDataTable() + " WHERE `name`=?;");
|
ps = connection.prepareStatement("DELETE FROM " + HuskHomes.getSettings().getWarpsDataTable() + " WHERE `name`=?;");
|
||||||
ps.setString(1, warpName);
|
ps.setString(1, warpName);
|
||||||
ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
|
ps.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -339,7 +333,6 @@ public class DataManager {
|
|||||||
ps.setString(2, ownerUsername);
|
ps.setString(2, ownerUsername);
|
||||||
ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
ps.close();
|
ps.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addPlayer(Player p, Connection connection) throws SQLException {
|
public static void addPlayer(Player p, Connection connection) throws SQLException {
|
||||||
@@ -371,21 +364,6 @@ public class DataManager {
|
|||||||
ps.close();
|
ps.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert a player into the database
|
|
||||||
public static void addPlayer(UUID playerUUID, String playerName, int homeSlots, Connection connection) throws SQLException {
|
|
||||||
PreparedStatement ps;
|
|
||||||
|
|
||||||
ps = connection.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);
|
|
||||||
ps.setInt(4, 0);
|
|
||||||
ps.setBoolean(5, false);
|
|
||||||
|
|
||||||
ps.executeUpdate();
|
|
||||||
ps.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void updatePlayerUsername(UUID uuid, String newName, Connection connection) throws SQLException {
|
public static void updatePlayerUsername(UUID uuid, String newName, Connection connection) throws SQLException {
|
||||||
PreparedStatement ps;
|
PreparedStatement ps;
|
||||||
ps = connection.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `username`=? WHERE `user_uuid`=?;");
|
ps = connection.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `username`=? WHERE `user_uuid`=?;");
|
||||||
@@ -401,6 +379,7 @@ public class DataManager {
|
|||||||
ps.setBoolean(1, value);
|
ps.setBoolean(1, value);
|
||||||
ps.setString(2, uuid.toString());
|
ps.setString(2, uuid.toString());
|
||||||
ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
|
ps.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setPlayerHomeSlots(UUID uuid, int newValue, Connection connection) throws SQLException {
|
public static void setPlayerHomeSlots(UUID uuid, int newValue, Connection connection) throws SQLException {
|
||||||
@@ -443,6 +422,7 @@ public class DataManager {
|
|||||||
// Add the teleportation point
|
// Add the teleportation point
|
||||||
Integer locationID = addTeleportationPoint(point, connection);
|
Integer locationID = addTeleportationPoint(point, connection);
|
||||||
|
|
||||||
|
if (locationID != null) {
|
||||||
// Set the warp location ID to the new teleport point
|
// Set the warp location ID to the new teleport point
|
||||||
ps = connection.prepareStatement("UPDATE " + HuskHomes.getSettings().getWarpsDataTable() + " SET `location_id`=? WHERE `name`=?;");
|
ps = connection.prepareStatement("UPDATE " + HuskHomes.getSettings().getWarpsDataTable() + " SET `location_id`=? WHERE `name`=?;");
|
||||||
ps.setInt(1, locationID);
|
ps.setInt(1, locationID);
|
||||||
@@ -450,6 +430,7 @@ public class DataManager {
|
|||||||
ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
ps.close();
|
ps.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update the description of a home
|
// Update the description of a home
|
||||||
public static void setHomeDescription(String homeName, String ownerName, String newDescription, Connection connection) throws SQLException {
|
public static void setHomeDescription(String homeName, String ownerName, String newDescription, Connection connection) throws SQLException {
|
||||||
@@ -510,6 +491,7 @@ public class DataManager {
|
|||||||
// Add the teleportation point
|
// Add the teleportation point
|
||||||
Integer locationID = addTeleportationPoint(point, connection);
|
Integer locationID = addTeleportationPoint(point, connection);
|
||||||
|
|
||||||
|
if (locationID != null) {
|
||||||
// Set the destination location with the location_id of the last inserted teleport point
|
// Set the destination location with the location_id of the last inserted teleport point
|
||||||
ps = connection.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `dest_location_id`=? WHERE `username`=?;");
|
ps = connection.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `dest_location_id`=? WHERE `username`=?;");
|
||||||
ps.setInt(1, locationID);
|
ps.setInt(1, locationID);
|
||||||
@@ -517,13 +499,16 @@ public class DataManager {
|
|||||||
ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
ps.close();
|
ps.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update a warp's teleport location (deletion of the old one is done afterward to prevent cascading deletion from wiping the warp
|
// Update a warp's teleport location (deletion of the old one is done afterward to prevent cascading deletion from wiping the warp
|
||||||
public static void updateWarpTeleportLocation(String warpName, TeleportationPoint teleportationPoint, Connection connection) throws SQLException {
|
public static void updateWarpTeleportLocation(String warpName, TeleportationPoint teleportationPoint, Connection connection) throws SQLException {
|
||||||
Integer oldLocationID = getWarpLocationID(warpName, connection);
|
Integer oldLocationID = getWarpLocationID(warpName, connection);
|
||||||
setWarpTeleportPoint(warpName, teleportationPoint, connection);
|
setWarpTeleportPoint(warpName, teleportationPoint, connection);
|
||||||
|
if (oldLocationID != null) {
|
||||||
deleteTeleportationPoint(oldLocationID, connection);
|
deleteTeleportationPoint(oldLocationID, connection);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void updateHomePrivacy(String ownerName, String homeName, boolean isPublic, Connection connection) throws SQLException {
|
public static void updateHomePrivacy(String ownerName, String homeName, boolean isPublic, Connection connection) throws SQLException {
|
||||||
setHomePrivacy(homeName, ownerName, isPublic, connection);
|
setHomePrivacy(homeName, ownerName, isPublic, connection);
|
||||||
@@ -539,8 +524,10 @@ public class DataManager {
|
|||||||
|
|
||||||
public static void updateHomeLocation(String ownerName, String homeName, Location newLocation, Connection connection) throws SQLException {
|
public static void updateHomeLocation(String ownerName, String homeName, Location newLocation, Connection connection) throws SQLException {
|
||||||
Integer playerID = getPlayerId(ownerName, connection);
|
Integer playerID = getPlayerId(ownerName, connection);
|
||||||
updateHomeTeleportLocation(playerID, homeName,
|
if (playerID != null) {
|
||||||
new TeleportationPoint(newLocation, HuskHomes.getSettings().getServerID()), connection);
|
updateHomeTeleportLocation(playerID, homeName, new TeleportationPoint(newLocation,
|
||||||
|
HuskHomes.getSettings().getServerID()), connection);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateWarpName(String warpName, String newName, Connection connection) throws SQLException {
|
public static void updateWarpName(String warpName, String newName, Connection connection) throws SQLException {
|
||||||
@@ -568,28 +555,27 @@ public class DataManager {
|
|||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
if (rs != null) {
|
if (rs != null) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
int locationID = rs.getInt("location_id");
|
final int locationID = rs.getInt("location_id");
|
||||||
TeleportationPoint teleportationPoint = getTeleportationPoint(locationID, connection);
|
final TeleportationPoint teleportationPoint = getTeleportationPoint(locationID, connection);
|
||||||
return new Home(teleportationPoint,
|
final Home home = new Home(teleportationPoint,
|
||||||
ownerUsername,
|
ownerUsername,
|
||||||
getPlayerUUID(rs.getInt("player_id"), connection),
|
getPlayerUUID(rs.getInt("player_id"), connection),
|
||||||
rs.getString("name"),
|
rs.getString("name"),
|
||||||
rs.getString("description"),
|
rs.getString("description"),
|
||||||
rs.getBoolean("public"));
|
rs.getBoolean("public"));
|
||||||
|
ps.close();
|
||||||
|
return home;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Bukkit.getLogger().severe("Home returned null; perhaps player ID was null?");
|
Bukkit.getLogger().severe("Home returned null; perhaps player ID was null?");
|
||||||
|
}
|
||||||
|
ps.close();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
public static boolean warpExists(String warpName, Connection connection) throws SQLException {
|
||||||
}
|
|
||||||
|
|
||||||
public static Boolean warpExists(String warpName, Connection connection) throws SQLException {
|
|
||||||
PreparedStatement ps;
|
PreparedStatement ps;
|
||||||
ResultSet rs;
|
ResultSet rs;
|
||||||
|
|
||||||
|
|
||||||
ps = connection.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getWarpsDataTable() + " WHERE `name`=?;");
|
ps = connection.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getWarpsDataTable() + " WHERE `name`=?;");
|
||||||
ps.setString(1, warpName);
|
ps.setString(1, warpName);
|
||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
@@ -638,7 +624,6 @@ public class DataManager {
|
|||||||
ResultSet rs;
|
ResultSet rs;
|
||||||
String playerUUIDString = playerUUID.toString();
|
String playerUUIDString = playerUUID.toString();
|
||||||
|
|
||||||
|
|
||||||
ps = connection.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getPlayerDataTable() + " WHERE `user_uuid`=?;");
|
ps = connection.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getPlayerDataTable() + " WHERE `user_uuid`=?;");
|
||||||
ps.setString(1, playerUUIDString);
|
ps.setString(1, playerUUIDString);
|
||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
@@ -648,6 +633,7 @@ public class DataManager {
|
|||||||
return exists;
|
return exists;
|
||||||
} else {
|
} else {
|
||||||
Bukkit.getLogger().severe("An SQL exception occurred in retrieving if a player exists from the table.");
|
Bukkit.getLogger().severe("An SQL exception occurred in retrieving if a player exists from the table.");
|
||||||
|
ps.close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -718,6 +704,7 @@ public class DataManager {
|
|||||||
// Add the teleportation point
|
// Add the teleportation point
|
||||||
Integer locationID = addTeleportationPoint(point, connection);
|
Integer locationID = addTeleportationPoint(point, connection);
|
||||||
|
|
||||||
|
if (locationID != null) {
|
||||||
// Set the destination location with the location_id of the last inserted teleport point
|
// Set the destination location with the location_id of the last inserted teleport point
|
||||||
ps = connection.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `last_location_id`=? WHERE `user_uuid`=?;");
|
ps = connection.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `last_location_id`=? WHERE `user_uuid`=?;");
|
||||||
ps.setInt(1, locationID);
|
ps.setInt(1, locationID);
|
||||||
@@ -725,6 +712,7 @@ public class DataManager {
|
|||||||
ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
ps.close();
|
ps.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update a player's last position location on SQL
|
// Update a player's last position location on SQL
|
||||||
public static void setPlayerLastPosition(Player p, TeleportationPoint point, Connection connection) throws SQLException {
|
public static void setPlayerLastPosition(Player p, TeleportationPoint point, Connection connection) throws SQLException {
|
||||||
@@ -749,12 +737,12 @@ public class DataManager {
|
|||||||
|
|
||||||
public static void updateRtpCooldown(Player p, Connection connection) throws SQLException {
|
public static void updateRtpCooldown(Player p, Connection connection) throws SQLException {
|
||||||
long currentTime = Instant.now().getEpochSecond();
|
long currentTime = Instant.now().getEpochSecond();
|
||||||
int newCooldownTime = (int) currentTime + (60 * HuskHomes.getSettings().getRtpCooldown());
|
int newCoolDownTime = (int) currentTime + (60 * HuskHomes.getSettings().getRtpCoolDown());
|
||||||
setRtpCoolDown(p.getUniqueId(), newCooldownTime, connection);
|
setRtpCoolDown(p.getUniqueId(), newCoolDownTime, connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deletePlayerDestination(String playerName, Connection connection) throws SQLException {
|
public static void deletePlayerDestination(String playerName, Connection connection) throws SQLException {
|
||||||
Integer destinationID = getPlayerInteger(playerName, "dest_location_id", connection);
|
Integer destinationID = getPlayerInteger(getPlayerId(playerName, connection), "dest_location_id", connection);
|
||||||
if (destinationID != null) {
|
if (destinationID != null) {
|
||||||
deleteTeleportationPoint(destinationID, connection);
|
deleteTeleportationPoint(destinationID, connection);
|
||||||
clearPlayerDestData(playerName, connection);
|
clearPlayerDestData(playerName, connection);
|
||||||
@@ -767,6 +755,7 @@ public class DataManager {
|
|||||||
ps = connection.prepareStatement("DELETE FROM " + HuskHomes.getSettings().getLocationsDataTable() + " WHERE `location_id`=?;");
|
ps = connection.prepareStatement("DELETE FROM " + HuskHomes.getSettings().getLocationsDataTable() + " WHERE `location_id`=?;");
|
||||||
ps.setInt(1, locationID);
|
ps.setInt(1, locationID);
|
||||||
ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
|
ps.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deletePlayerLastPosition(Player p, Connection connection) throws SQLException {
|
public static void deletePlayerLastPosition(Player p, Connection connection) throws SQLException {
|
||||||
@@ -783,6 +772,7 @@ public class DataManager {
|
|||||||
// Add the teleportation point
|
// Add the teleportation point
|
||||||
Integer locationID = addTeleportationPoint(point, connection);
|
Integer locationID = addTeleportationPoint(point, connection);
|
||||||
|
|
||||||
|
if (locationID != null) {
|
||||||
// Set the home location ID to the new teleport point for the given home
|
// Set the home location ID to the new teleport point for the given home
|
||||||
ps = connection.prepareStatement("UPDATE " + HuskHomes.getSettings().getHomesDataTable() + " SET `location_id`=? WHERE `name`=? AND `player_id`=?;");
|
ps = connection.prepareStatement("UPDATE " + HuskHomes.getSettings().getHomesDataTable() + " SET `location_id`=? WHERE `name`=? AND `player_id`=?;");
|
||||||
ps.setInt(1, locationID);
|
ps.setInt(1, locationID);
|
||||||
@@ -791,6 +781,7 @@ public class DataManager {
|
|||||||
ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
ps.close();
|
ps.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Clear a player's destination
|
// Clear a player's destination
|
||||||
public static void clearPlayerDestData(String playerName, Connection connection) throws SQLException {
|
public static void clearPlayerDestData(String playerName, Connection connection) throws SQLException {
|
||||||
@@ -815,21 +806,24 @@ public class DataManager {
|
|||||||
// Add the teleportation point
|
// Add the teleportation point
|
||||||
Integer locationID = addTeleportationPoint(warp, connection);
|
Integer locationID = addTeleportationPoint(warp, connection);
|
||||||
|
|
||||||
|
if (locationID != null) {
|
||||||
// Insert the warp with the location_id of the last inserted teleport point
|
// Insert the warp with the location_id of the last inserted teleport point
|
||||||
ps = connection.prepareStatement("INSERT INTO " + HuskHomes.getSettings().getWarpsDataTable() + " (location_id,name,description) VALUES(?,?,?);");
|
ps = connection.prepareStatement("INSERT INTO " + HuskHomes.getSettings().getWarpsDataTable() + " (location_id,name,description) VALUES(?,?,?);");
|
||||||
ps.setInt(1, locationID);
|
ps.setInt(1, locationID);
|
||||||
ps.setString(2, warp.getName());
|
ps.setString(2, warp.getName());
|
||||||
ps.setString(3, warp.getDescription());
|
ps.setString(3, warp.getDescription());
|
||||||
ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
|
ps.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addHome(Home home, UUID playerUUID, Connection connection) throws SQLException {
|
public static void addHome(Home home, UUID playerUUID, Connection connection) throws SQLException {
|
||||||
Integer playerID = getPlayerId(playerUUID, connection);
|
Integer playerID = getPlayerId(playerUUID, connection);
|
||||||
if (playerID != null) {
|
if (playerID != null) {
|
||||||
PreparedStatement ps;
|
PreparedStatement ps;
|
||||||
|
|
||||||
Integer locationID = addTeleportationPoint(home, connection);
|
Integer locationID = addTeleportationPoint(home, connection);
|
||||||
|
|
||||||
|
if (locationID != null) {
|
||||||
ps = connection.prepareStatement("INSERT INTO " + HuskHomes.getSettings().getHomesDataTable() + " (player_id,location_id,name,description,public) VALUES(?,?,?,?,?);");
|
ps = connection.prepareStatement("INSERT INTO " + HuskHomes.getSettings().getHomesDataTable() + " (player_id,location_id,name,description,public) VALUES(?,?,?,?,?);");
|
||||||
ps.setInt(1, playerID);
|
ps.setInt(1, playerID);
|
||||||
ps.setInt(2, locationID);
|
ps.setInt(2, locationID);
|
||||||
@@ -837,6 +831,8 @@ public class DataManager {
|
|||||||
ps.setString(4, home.getDescription());
|
ps.setString(4, home.getDescription());
|
||||||
ps.setBoolean(5, home.isPublic());
|
ps.setBoolean(5, home.isPublic());
|
||||||
ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
|
ps.close();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Bukkit.getLogger().warning("Failed to add a home for a player!");
|
Bukkit.getLogger().warning("Failed to add a home for a player!");
|
||||||
}
|
}
|
||||||
@@ -865,13 +861,12 @@ public class DataManager {
|
|||||||
addPlayer(playerUUID, playerUsername, connection);
|
addPlayer(playerUUID, playerUsername, connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createPlayer(UUID playerUUID, String playerUsername, int homeSlots, Connection connection) throws SQLException {
|
|
||||||
addPlayer(playerUUID, playerUsername, homeSlots, connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void checkPlayerNameChange(Player p, Connection connection) throws SQLException {
|
public static void checkPlayerNameChange(Player p, Connection connection) throws SQLException {
|
||||||
if (!getPlayerUsername(getPlayerId(p.getUniqueId(), connection), connection).equals(p.getName())) {
|
final Integer playerID = getPlayerId(p.getUniqueId(), connection);
|
||||||
|
if (playerID != null) {
|
||||||
|
if (!getPlayerUsername(playerID, connection).equals(p.getName())) {
|
||||||
updatePlayerUsername(p.getUniqueId(), p.getName(), connection);
|
updatePlayerUsername(p.getUniqueId(), p.getName(), connection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -8,11 +8,6 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
/*
|
|
||||||
TODO Should not relay on SQL
|
|
||||||
Instead should contain abstract getters and setters etc, so some alternative way of storing data may exist
|
|
||||||
Current method should possibly go into the SQL class
|
|
||||||
*/
|
|
||||||
public abstract class Database {
|
public abstract class Database {
|
||||||
protected HuskHomes plugin;
|
protected HuskHomes plugin;
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package me.william278.huskhomes2.listeners;
|
package me.william278.huskhomes2.listeners;
|
||||||
|
|
||||||
|
import io.papermc.lib.PaperLib;
|
||||||
import me.william278.huskhomes2.HuskHomes;
|
import me.william278.huskhomes2.HuskHomes;
|
||||||
import me.william278.huskhomes2.MessageManager;
|
import me.william278.huskhomes2.MessageManager;
|
||||||
import me.william278.huskhomes2.commands.HomeCommand;
|
import me.william278.huskhomes2.commands.HomeCommand;
|
||||||
@@ -49,7 +50,7 @@ public class PlayerListener implements Listener {
|
|||||||
if (!DataManager.playerExists(p, connection)) {
|
if (!DataManager.playerExists(p, connection)) {
|
||||||
DataManager.createPlayer(p, connection);
|
DataManager.createPlayer(p, connection);
|
||||||
if (TeleportManager.getSpawnLocation() != null) {
|
if (TeleportManager.getSpawnLocation() != null) {
|
||||||
p.teleport(TeleportManager.getSpawnLocation().getLocation());
|
Bukkit.getScheduler().runTask(plugin, () -> PaperLib.teleportAsync(p, TeleportManager.getSpawnLocation().getLocation()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Check if they've changed their name and update if so
|
// Check if they've changed their name and update if so
|
||||||
@@ -67,13 +68,6 @@ public class PlayerListener implements Listener {
|
|||||||
TeleportManager.teleportPlayer(p);
|
TeleportManager.teleportPlayer(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*// Update player lists globally
|
|
||||||
if (HuskHomes.getSettings().doCrossServerTabCompletion()) {
|
|
||||||
CrossServerListHandler.updatePlayerList(p);
|
|
||||||
PluginMessageHandler.broadcastPlayerChange(p);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
} catch (SQLException sqlException) {
|
} catch (SQLException sqlException) {
|
||||||
plugin.getLogger().log(Level.SEVERE, "An SQL error handling a joining player", sqlException);
|
plugin.getLogger().log(Level.SEVERE, "An SQL error handling a joining player", sqlException);
|
||||||
|
|||||||
@@ -81,4 +81,4 @@ economy_integration:
|
|||||||
random_teleport: 20
|
random_teleport: 20
|
||||||
back: 0
|
back: 0
|
||||||
handle_vanished_players: true
|
handle_vanished_players: true
|
||||||
config_file_version: 3
|
config_file_version: 4
|
||||||
Reference in new issue
Block a user