Database optimisations

This commit is contained in:
William278 committed 2021-04-06 22:13:38 +01:00
1 parent 398b47af55
commit 70883ada16
3 files changed
+71 -108

No files matched your search

+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>me.William278</groupId> <groupId>me.William278</groupId>
<artifactId>HuskHomes</artifactId> <artifactId>HuskHomes</artifactId>
<version>2.3</version> <version>2.3.1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>HuskHomes</name> <name>HuskHomes</name>
@@ -179,17 +179,16 @@ public class DataManager {
return null; return null;
} }
// Return an integer from the player table from a player ID // Return if the player is teleporting
public static Boolean getPlayerTeleporting(Player p) { public static Boolean getPlayerTeleporting(Player p) {
Connection conn; Connection conn;
PreparedStatement ps; PreparedStatement ps;
Integer playerID = getPlayerId(p.getUniqueId());
ResultSet rs; ResultSet rs;
try { try {
conn = getConnection(); conn = getConnection();
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getPlayerDataTable() + " WHERE `player_id`=?;"); ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getPlayerDataTable() + " WHERE `user_uuid`=?);");
ps.setInt(1, playerID); ps.setString(1, p.getUniqueId().toString());
rs = ps.executeQuery(); rs = ps.executeQuery();
if (rs != null) { if (rs != null) {
if (rs.next()) { if (rs.next()) {
@@ -198,7 +197,7 @@ public class DataManager {
return null; return null;
} }
} else { } else {
Bukkit.getLogger().severe("Result set for a player returned null; perhaps player ID was null"); Bukkit.getLogger().severe("Failed to retrieve if player was teleporting");
return null; return null;
} }
} catch (SQLException ex) { } catch (SQLException ex) {
@@ -234,7 +233,7 @@ public class DataManager {
// Set how many home slots a player has // Set how many home slots a player has
private static void setPlayerHomeSlots(Player p, int slots) { private static void setPlayerHomeSlots(Player p, int slots) {
database.setPlayerHomeSlots(getPlayerId(p.getUniqueId()), slots); database.setPlayerHomeSlots(p.getUniqueId(), slots);
} }
// Return how many home slots a player has // Return how many home slots a player has
@@ -251,13 +250,12 @@ public class DataManager {
public static List<Home> getPlayerHomes(String playerName) { public static List<Home> getPlayerHomes(String playerName) {
Connection conn; Connection conn;
PreparedStatement ps; PreparedStatement ps;
Integer playerID = getPlayerId(playerName);
ResultSet rs; ResultSet rs;
try { try {
conn = getConnection(); conn = getConnection();
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getHomesDataTable() + " WHERE `player_id`=?;"); ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getHomesDataTable() + " WHERE `player_id`=(SELECT `player_id` FROM " + HuskHomes.getSettings().getPlayerDataTable() + " WHERE `username`=?));");
ps.setInt(1, playerID); ps.setString(1, playerName);
rs = ps.executeQuery(); rs = ps.executeQuery();
if (rs != null) { if (rs != null) {
List<Home> playerHomes = new ArrayList<>(); List<Home> playerHomes = new ArrayList<>();
@@ -266,7 +264,7 @@ public class DataManager {
TeleportationPoint teleportationPoint = getTeleportationPoint(locationID); TeleportationPoint teleportationPoint = getTeleportationPoint(locationID);
if (teleportationPoint != null) { if (teleportationPoint != null) {
playerHomes.add(new Home(teleportationPoint, playerHomes.add(new Home(teleportationPoint,
playerName, getPlayerUUID(playerID), playerName, getPlayerUUID(rs.getInt("player_id")),
rs.getString("name"), rs.getString("name"),
rs.getString("description"), rs.getString("description"),
rs.getBoolean("public"))); rs.getBoolean("public")));
@@ -455,18 +453,15 @@ public class DataManager {
} }
public static void updateHomePrivacy(String ownerName, String homeName, boolean isPublic) { public static void updateHomePrivacy(String ownerName, String homeName, boolean isPublic) {
Integer playerID = getPlayerId(ownerName); database.setHomePrivacy(homeName, ownerName, isPublic);
database.setHomePrivacy(homeName, playerID, isPublic);
} }
public static void updateHomeName(String ownerName, String homeName, String newName) { public static void updateHomeName(String ownerName, String homeName, String newName) {
Integer playerID = getPlayerId(ownerName); database.setHomeName(homeName, ownerName, newName);
database.setHomeName(homeName, playerID, newName);
} }
public static void updateHomeDescription(String ownerName, String homeName, String newDescription) { public static void updateHomeDescription(String ownerName, String homeName, String newDescription) {
Integer playerID = getPlayerId(ownerName); database.setHomeDescription(homeName, ownerName, newDescription);
database.setHomeDescription(homeName, playerID, newDescription);
} }
public static void updateHomeLocation(String ownerName, String homeName, Location newLocation) { public static void updateHomeLocation(String ownerName, String homeName, Location newLocation) {
@@ -492,13 +487,12 @@ public class DataManager {
public static Home getHome(String ownerUsername, String homeName) { public static Home getHome(String ownerUsername, String homeName) {
Connection conn; Connection conn;
PreparedStatement ps; PreparedStatement ps;
Integer playerID = getPlayerId(ownerUsername);
ResultSet rs; ResultSet rs;
try { try {
conn = getConnection(); conn = getConnection();
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getHomesDataTable() + " WHERE `player_id`=? AND `name`=?;"); ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getHomesDataTable() + " WHERE `player_id`=(SELECT `player_id` FROM " + HuskHomes.getSettings().getPlayerDataTable() + " WHERE `username`=?) AND `name`=?;");
ps.setInt(1, playerID); ps.setString(1, ownerUsername);
ps.setString(2, homeName); ps.setString(2, homeName);
rs = ps.executeQuery(); rs = ps.executeQuery();
if (rs != null) { if (rs != null) {
@@ -508,7 +502,7 @@ public class DataManager {
if (teleportationPoint != null) { if (teleportationPoint != null) {
return new Home(teleportationPoint, return new Home(teleportationPoint,
ownerUsername, ownerUsername,
getPlayerUUID(playerID), getPlayerUUID(rs.getInt("player_id")),
rs.getString("name"), rs.getString("name"),
rs.getString("description"), rs.getString("description"),
rs.getBoolean("public")); rs.getBoolean("public"));
@@ -557,17 +551,11 @@ public class DataManager {
Connection conn; Connection conn;
PreparedStatement ps; PreparedStatement ps;
ResultSet rs; ResultSet rs;
Integer playerID = getPlayerId(ownerName);
// Return false if the player is invalid
if (playerID == null) {
return false;
}
try { try {
conn = getConnection(); conn = getConnection();
ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getHomesDataTable() + " WHERE `player_id`=? AND `name`=?;"); ps = conn.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getHomesDataTable() + " WHERE `player_id`=(SELECT `player_id` FROM " + HuskHomes.getSettings().getPlayerDataTable() + " WHERE `username`=?) AND `name`=?;");
ps.setInt(1, playerID); ps.setString(1, ownerName);
ps.setString(2, homeName); ps.setString(2, homeName);
rs = ps.executeQuery(); rs = ps.executeQuery();
if (rs != null) { if (rs != null) {
@@ -625,10 +613,7 @@ public class DataManager {
rs.getDouble("z"), rs.getFloat("yaw"), rs.getDouble("z"), rs.getFloat("yaw"),
rs.getFloat("pitch"), rs.getString("server")); rs.getFloat("pitch"), rs.getString("server"));
} else { } else {
Bukkit.getLogger().severe("An SQL exception occurred in retrieving a teleportation location."); throw new IllegalArgumentException("Could not return a teleportationPoint from the locations data table at (ID#" + locationID + ")");
Bukkit.getLogger().severe("location ID: " + locationID.toString());
Bukkit.getLogger().severe("SELECT * FROM " + HuskHomes.getSettings().getLocationsDataTable() + " WHERE `location_id`=" + locationID.toString() + ";");
return null;
} }
} catch (SQLException ex) { } catch (SQLException ex) {
plugin.getLogger().log(Level.SEVERE, Error.SQL_CONNECTION_EXECUTE, ex); plugin.getLogger().log(Level.SEVERE, Error.SQL_CONNECTION_EXECUTE, ex);
@@ -656,24 +641,14 @@ public class DataManager {
// 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) { public static void setPlayerLastPosition(Player p, TeleportationPoint point) {
Integer playerID = getPlayerId(p.getUniqueId()); deletePlayerLastPosition(p);
if (playerID != null) { database.setTeleportationLastPosition(p.getUniqueId(), point);
deletePlayerLastPosition(p);
database.setTeleportationLastPosition(playerID, point);
} else {
Bukkit.getLogger().warning("Failed to update player last position records for " + p.getName());
}
} }
// Update a player's destination location on SQL // Update a player's destination location on SQL
public static void setPlayerDestinationLocation(String playerName, TeleportationPoint point) { public static void setPlayerDestinationLocation(String playerName, TeleportationPoint point) {
Integer playerID = getPlayerId(playerName); deletePlayerDestination(playerName);
if (playerID != null) { database.setTeleportationDestination(playerName, point);
deletePlayerDestination(playerName);
database.setTeleportationDestination(playerID, point);
} else {
Bukkit.getLogger().warning("Failed to update player destination records for " + playerName);
}
} }
// Update a player's destination location on SQL // Update a player's destination location on SQL
@@ -682,36 +657,25 @@ public class DataManager {
} }
public static void setPlayerTeleporting(Player p, boolean value) { public static void setPlayerTeleporting(Player p, boolean value) {
Integer playerID = getPlayerId(p.getUniqueId()); database.setPlayerTeleporting(p.getUniqueId(), value);
if (playerID != null) {
database.setPlayerTeleporting(playerID, value);
} else {
Bukkit.getLogger().warning("Failed to set a player as teleporting (" + p.getName() + ")");
}
} }
public static void clearPlayerDestination(String playerName) { public static void clearPlayerDestination(String playerName) {
Integer playerID = getPlayerId(playerName); deletePlayerDestination(playerName);
if (playerID != null) { database.clearPlayerDestination(playerName);
deletePlayerDestination(playerName);
database.clearPlayerDestination(playerID);
}
} }
public static void updateRtpCooldown(Player p) { public static void updateRtpCooldown(Player p) {
Integer playerID = getPlayerId(p.getUniqueId()); long currentTime = Instant.now().getEpochSecond();
if (playerID != null) { int newCooldownTime = (int) currentTime + (60 * HuskHomes.getSettings().getRtpCooldown());
long currentTime = Instant.now().getEpochSecond(); database.setRtpCooldown(p.getUniqueId(), newCooldownTime);
int newCooldownTime = (int) currentTime + (60 * HuskHomes.getSettings().getRtpCooldown());
database.setRtpCooldown(playerID, newCooldownTime);
}
} }
public static void deletePlayerDestination(String playerName) { public static void deletePlayerDestination(String playerName) {
Integer destinationID = getPlayerInteger(playerName, "dest_location_id"); Integer destinationID = getPlayerInteger(playerName, "dest_location_id");
if (destinationID != null) { if (destinationID != null) {
database.deleteTeleportationPoint(destinationID); database.deleteTeleportationPoint(destinationID);
database.clearPlayerDestination(getPlayerId(playerName)); database.clearPlayerDestination(playerName);
} }
} }
@@ -723,7 +687,7 @@ public class DataManager {
Integer lastPositionID = getPlayerInteger(p, "last_location_id"); Integer lastPositionID = getPlayerInteger(p, "last_location_id");
if (lastPositionID != null) { if (lastPositionID != null) {
database.deleteTeleportationPoint(lastPositionID); database.deleteTeleportationPoint(lastPositionID);
database.clearPlayerLastPosition(getPlayerId(p.getUniqueId())); database.clearPlayerLastPosition(p.getUniqueId());
} }
} }
@@ -747,7 +711,7 @@ public class DataManager {
Integer playerID = getPlayerId(p.getUniqueId()); Integer playerID = getPlayerId(p.getUniqueId());
if (playerID != null) { if (playerID != null) {
deleteHomeTeleportLocation(playerID, homeName); deleteHomeTeleportLocation(playerID, homeName);
database.deleteHome(homeName, playerID); database.deleteHome(homeName, p.getName());
} else { } else {
Bukkit.getLogger().warning("Player ID returned null when deleting a home"); Bukkit.getLogger().warning("Player ID returned null when deleting a home");
} }
@@ -827,9 +791,8 @@ public class DataManager {
} }
public static void checkPlayerNameChange(Player p) { public static void checkPlayerNameChange(Player p) {
Integer playerID = getPlayerId(p.getUniqueId()); if (!getPlayerUsername(getPlayerId(p.getUniqueId())).equals(p.getName())) {
if (!getPlayerUsername(playerID).equals(p.getName())) { database.updatePlayerUsername(p.getUniqueId(), p.getName());
database.updatePlayerUsername(playerID, p.getName());
} }
} }
} }
@@ -130,7 +130,9 @@ public abstract class Database {
} }
// Delete a warp // Delete a warp
public void deleteHome(String homeName, int playerID) { // Insert a player into the database
public void deleteHome(String homeName, String ownerUsername) {
Connection conn; Connection conn;
PreparedStatement ps; PreparedStatement ps;
@@ -138,17 +140,15 @@ public abstract class Database {
conn = getSQLConnection(); conn = getSQLConnection();
// Delete the home with the given name and player ID // Delete the home with the given name and player ID
ps = conn.prepareStatement("DELETE FROM " + HuskHomes.getSettings().getHomesDataTable() + " WHERE `name`=? AND `player_id`=?;"); ps = conn.prepareStatement("DELETE FROM " + HuskHomes.getSettings().getHomesDataTable() + " WHERE `name`=? AND `player_id`=(SELECT `player_id` FROM " + HuskHomes.getSettings().getPlayerDataTable() + " WHERE `username`=?);");
ps.setString(1, homeName); ps.setString(1, homeName);
ps.setInt(2, playerID); ps.setString(2, ownerUsername);
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
plugin.getLogger().log(Level.SEVERE, Error.SQL_CONNECTION_EXECUTE, ex); plugin.getLogger().log(Level.SEVERE, Error.SQL_CONNECTION_EXECUTE, ex);
} }
} }
// Insert a player into the database
public void addPlayer(Player p) { public void addPlayer(Player p) {
Connection conn; Connection conn;
PreparedStatement ps; PreparedStatement ps;
@@ -211,60 +211,60 @@ public abstract class Database {
} }
} }
public void updatePlayerUsername(int playerID, String newName) { public void updatePlayerUsername(UUID uuid, String newName) {
Connection conn; Connection conn;
PreparedStatement ps; PreparedStatement ps;
try { try {
conn = getSQLConnection(); conn = getSQLConnection();
ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `username`=? WHERE `player_id`=?;"); ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `username`=? WHERE `user_uuid`=?;");
ps.setString(1, newName); ps.setString(1, newName);
ps.setInt(2, playerID); ps.setString(2, uuid.toString());
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
plugin.getLogger().log(Level.SEVERE, Error.SQL_CONNECTION_EXECUTE, ex); plugin.getLogger().log(Level.SEVERE, Error.SQL_CONNECTION_EXECUTE, ex);
} }
} }
public void setPlayerTeleporting(int playerID, boolean value) { public void setPlayerTeleporting(UUID uuid, boolean value) {
Connection conn; Connection conn;
PreparedStatement ps; PreparedStatement ps;
try { try {
conn = getSQLConnection(); conn = getSQLConnection();
ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `is_teleporting`=? WHERE `player_id`=?;"); ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `is_teleporting`=? WHERE `user_uuid`=?);");
ps.setBoolean(1, value); ps.setBoolean(1, value);
ps.setInt(2, playerID); ps.setString(2, uuid.toString());
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
plugin.getLogger().log(Level.SEVERE, Error.SQL_CONNECTION_EXECUTE, ex); plugin.getLogger().log(Level.SEVERE, Error.SQL_CONNECTION_EXECUTE, ex);
} }
} }
public void setPlayerHomeSlots(int playerID, int newValue) { public void setPlayerHomeSlots(UUID uuid, int newValue) {
Connection conn; Connection conn;
PreparedStatement ps; PreparedStatement ps;
try { try {
conn = getSQLConnection(); conn = getSQLConnection();
ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `home_slots`=? WHERE `player_id`=?;"); ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `home_slots`=? WHERE `user_uuid`=?;");
ps.setInt(1, newValue); ps.setInt(1, newValue);
ps.setInt(2, playerID); ps.setString(2, uuid.toString());
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
plugin.getLogger().log(Level.SEVERE, Error.SQL_CONNECTION_EXECUTE, ex); plugin.getLogger().log(Level.SEVERE, Error.SQL_CONNECTION_EXECUTE, ex);
} }
} }
public void setRtpCooldown(int playerID, int newTime) { public void setRtpCooldown(UUID uuid, int newTime) {
Connection conn; Connection conn;
PreparedStatement ps; PreparedStatement ps;
try { try {
conn = getSQLConnection(); conn = getSQLConnection();
ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `rtp_cooldown`=? WHERE `player_id`=?;"); ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `rtp_cooldown`=? WHERE `user_uuid`=?;");
ps.setInt(1, newTime); ps.setInt(1, newTime);
ps.setInt(2, playerID); ps.setString(2, uuid.toString());
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
plugin.getLogger().log(Level.SEVERE, Error.SQL_CONNECTION_EXECUTE, ex); plugin.getLogger().log(Level.SEVERE, Error.SQL_CONNECTION_EXECUTE, ex);
@@ -289,7 +289,7 @@ public abstract class Database {
} }
// Update the location of a home // Update the location of a home
public void setHomePrivacy(String homeName, int ownerID, boolean isPublic) { public void setHomePrivacy(String homeName, String ownerName, boolean isPublic) {
Connection conn; Connection conn;
PreparedStatement ps; PreparedStatement ps;
@@ -297,10 +297,10 @@ public abstract class Database {
conn = getSQLConnection(); conn = getSQLConnection();
// 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 = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getHomesDataTable() + " SET `public`=? WHERE `name`=? AND `player_id`=?;"); ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getHomesDataTable() + " SET `public`=? WHERE `name`=? AND `player_id`=(SELECT `player_id` FROM " + HuskHomes.getSettings().getPlayerDataTable() + " WHERE `username`=?);");
ps.setBoolean(1, isPublic); ps.setBoolean(1, isPublic);
ps.setString(2, homeName); ps.setString(2, homeName);
ps.setInt(3, ownerID); ps.setString(3, ownerName);
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
plugin.getLogger().log(Level.SEVERE, Error.SQL_CONNECTION_EXECUTE, ex); plugin.getLogger().log(Level.SEVERE, Error.SQL_CONNECTION_EXECUTE, ex);
@@ -350,7 +350,7 @@ public abstract class Database {
} }
} }
// Update the description of a home // Update the description of a home
public void setHomeDescription(String homeName, int ownerID, String newDescription) { public void setHomeDescription(String homeName, String ownerName, String newDescription) {
Connection conn; Connection conn;
PreparedStatement ps; PreparedStatement ps;
@@ -358,10 +358,10 @@ public abstract class Database {
conn = getSQLConnection(); conn = getSQLConnection();
// Update the home description // Update the home description
ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getHomesDataTable() + " SET `description`=? WHERE `name`=? AND `player_id`=?;"); ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getHomesDataTable() + " SET `description`=? WHERE `name`=? AND `player_id`=(SELECT `player_id` FROM " + HuskHomes.getSettings().getPlayerDataTable() + " WHERE `username`=?);");
ps.setString(1, newDescription); ps.setString(1, newDescription);
ps.setString(2, homeName); ps.setString(2, homeName);
ps.setInt(3, ownerID); ps.setString(3, ownerName);
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
plugin.getLogger().log(Level.SEVERE, Error.SQL_CONNECTION_EXECUTE, ex); plugin.getLogger().log(Level.SEVERE, Error.SQL_CONNECTION_EXECUTE, ex);
@@ -387,7 +387,7 @@ public abstract class Database {
} }
// Update the name of a home // Update the name of a home
public void setHomeName(String oldHomeName, int ownerID, String newHomeName) { public void setHomeName(String oldHomeName, String ownerName, String newHomeName) {
Connection conn; Connection conn;
PreparedStatement ps; PreparedStatement ps;
@@ -395,10 +395,10 @@ public abstract class Database {
conn = getSQLConnection(); conn = getSQLConnection();
// Update the home name // Update the home name
ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getHomesDataTable() + " SET `name`=? WHERE `name`=? AND `player_id`=?;"); ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getHomesDataTable() + " SET `name`=? WHERE `name`=? AND `player_id`=(SELECT `player_id` FROM " + HuskHomes.getSettings().getPlayerDataTable() + " WHERE `username`=?);");
ps.setString(1, newHomeName); ps.setString(1, newHomeName);
ps.setString(2, oldHomeName); ps.setString(2, oldHomeName);
ps.setInt(3, ownerID); ps.setString(3, ownerName);
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
@@ -426,7 +426,7 @@ public abstract class Database {
} }
// Update a player's last position teleport point // Update a player's last position teleport point
public void setTeleportationLastPosition(int playerID, TeleportationPoint point) { public void setTeleportationLastPosition(UUID uuid, TeleportationPoint point) {
Connection conn; Connection conn;
PreparedStatement ps; PreparedStatement ps;
@@ -437,9 +437,9 @@ public abstract class Database {
Integer locationID = addTeleportationPoint(point, conn); Integer locationID = addTeleportationPoint(point, conn);
// 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 = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `last_location_id`=? WHERE `player_id`=?;"); ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `last_location_id`=? WHERE `user_uuid`=?;");
ps.setInt(1, locationID); ps.setInt(1, locationID);
ps.setInt(2, playerID); ps.setString(2, uuid.toString());
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
plugin.getLogger().log(Level.SEVERE, Error.SQL_CONNECTION_EXECUTE, ex); plugin.getLogger().log(Level.SEVERE, Error.SQL_CONNECTION_EXECUTE, ex);
@@ -447,7 +447,7 @@ public abstract class Database {
} }
// Update a player's destination teleport point // Update a player's destination teleport point
public void setTeleportationDestination(int playerID, TeleportationPoint point) { public void setTeleportationDestination(String username, TeleportationPoint point) {
Connection conn; Connection conn;
PreparedStatement ps; PreparedStatement ps;
@@ -458,9 +458,9 @@ public abstract class Database {
Integer locationID = addTeleportationPoint(point, conn); Integer locationID = addTeleportationPoint(point, conn);
// 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 = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `dest_location_id`=? WHERE `player_id`=?;"); ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `dest_location_id`=? WHERE `username`=?;");
ps.setInt(1, locationID); ps.setInt(1, locationID);
ps.setInt(2, playerID); ps.setString(2, username);
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
@@ -469,14 +469,14 @@ public abstract class Database {
} }
// Clear a player's destination // Clear a player's destination
public void clearPlayerDestination(int playerID) { public void clearPlayerDestination(String playerName) {
Connection conn; Connection conn;
PreparedStatement ps; PreparedStatement ps;
try { try {
conn = getSQLConnection(); conn = getSQLConnection();
ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `dest_location_id`=NULL WHERE `player_id`=?;"); ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `dest_location_id`=NULL WHERE `username`=?;");
ps.setInt(1, playerID); ps.setString(1, playerName);
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
plugin.getLogger().log(Level.SEVERE, Error.SQL_CONNECTION_EXECUTE, ex); plugin.getLogger().log(Level.SEVERE, Error.SQL_CONNECTION_EXECUTE, ex);
@@ -484,14 +484,14 @@ public abstract class Database {
} }
// Clear a player's last position // Clear a player's last position
public void clearPlayerLastPosition(int playerID) { public void clearPlayerLastPosition(UUID uuid) {
Connection conn; Connection conn;
PreparedStatement ps; PreparedStatement ps;
try { try {
conn = getSQLConnection(); conn = getSQLConnection();
ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `last_location_id`=NULL WHERE `player_id`=?;"); ps = conn.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `last_location_id`=NULL WHERE `user_uuid`=?;");
ps.setInt(1, playerID); ps.setString(1, uuid.toString());
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
plugin.getLogger().log(Level.SEVERE, Error.SQL_CONNECTION_EXECUTE, ex); plugin.getLogger().log(Level.SEVERE, Error.SQL_CONNECTION_EXECUTE, ex);