mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 22:16:08 +00:00
Added cross-server teleportation handling
This commit is contained in:
1 parent
2aeab951c6
commit
879293237f
18 files changed
+823
-82
No files matched your search
@@ -81,14 +81,40 @@ public class dataManager {
|
||||
}
|
||||
}
|
||||
|
||||
// Return an integer from the player table
|
||||
private static Integer getPlayerInteger(String playerName, String column) {
|
||||
try {
|
||||
Integer playerID = getPlayerId(playerName);
|
||||
ResultSet rs = queryDatabase("SELECT * FROM " + Main.settings.getHomesTable() + " WHERE `player_id`=" + playerID + ";");
|
||||
if (rs != null) {
|
||||
if (rs.next()) {
|
||||
return rs.getInt(column);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
Bukkit.getLogger().severe("Could not return integer for " + playerName + " because the player ID was null");
|
||||
return null;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Bukkit.getLogger().severe("An SQL exception occurred returning a value for " + playerName);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Return an integer from the player table
|
||||
public static Integer getPlayerInteger(Player p, String column) {
|
||||
try {
|
||||
Integer playerID = getPlayerId(p.getName());
|
||||
ResultSet rs = queryDatabase("SELECT * FROM " + Main.settings.getHomesTable() + " WHERE `player_id`=" + playerID + ";");
|
||||
if (rs.next()) {
|
||||
return rs.getInt(column);
|
||||
if (rs != null) {
|
||||
if (rs.next()) {
|
||||
return rs.getInt(column);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
Bukkit.getLogger().severe("Could not return integer for " + p.getName() + " because the player ID was null");
|
||||
return null;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
@@ -97,18 +123,37 @@ public class dataManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static void createPlayer(Player p) {
|
||||
if (Main.settings.getStorageType().equalsIgnoreCase("mysql")) {
|
||||
|
||||
} else {
|
||||
sqliteDatabase.addPlayer(p);
|
||||
}
|
||||
}
|
||||
|
||||
// Get a string value from a player's data row
|
||||
public static String getPlayerString(Player p, String column) {
|
||||
return getPlayerString(getPlayerId(p.getName()), column);
|
||||
Integer playerID = getPlayerId(p.getName());
|
||||
if (playerID != null) {
|
||||
return getPlayerString(playerID, column);
|
||||
} else {
|
||||
Bukkit.getLogger().severe("Could not return string for " + p.getName() + " because the player ID was null");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Get a string value from a player with given ID's data row
|
||||
public static String getPlayerString(int playerID, String column) {
|
||||
try {
|
||||
ResultSet rs = queryDatabase("SELECT * FROM " + Main.settings.getPlayerTable() + " WHERE `player_id`=" + (playerID) + ";");
|
||||
if (rs.next()) {
|
||||
return rs.getString(column);
|
||||
if (rs != null) {
|
||||
if (rs.next()) {
|
||||
return rs.getString(column);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
Bukkit.getLogger().severe("An error occurred retrieving a string");
|
||||
return null;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
@@ -122,8 +167,12 @@ public class dataManager {
|
||||
try {
|
||||
Integer playerID = getPlayerId(p.getName());
|
||||
ResultSet rs = queryDatabase("SELECT * FROM " + Main.settings.getHomesTable() + " WHERE `player_id`=" + playerID + ";");
|
||||
if (rs.next()) {
|
||||
return rs.getBoolean("is_teleporting");
|
||||
if (rs != null) {
|
||||
if (rs.next()) {
|
||||
return rs.getBoolean("is_teleporting");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@@ -145,7 +194,12 @@ public class dataManager {
|
||||
|
||||
// Return how many homes the player has set
|
||||
public static int getPlayerHomeCount(Player p) {
|
||||
return getPlayerHomes(p.getName()).size();
|
||||
ArrayList<Home> playerHomes = getPlayerHomes(p.getName());
|
||||
if (playerHomes != null) {
|
||||
return playerHomes.size();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Return how many home slots a player has
|
||||
@@ -164,11 +218,24 @@ public class dataManager {
|
||||
Integer playerID = getPlayerId(playerName);
|
||||
ResultSet rs = queryDatabase("SELECT * FROM " + Main.settings.getHomesTable() + " WHERE `player_id`=" + playerID + ";");
|
||||
ArrayList<Home> publicHomes = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
int locationID = rs.getInt("location_id");
|
||||
publicHomes.add(new Home(getTeleportationPoint(locationID), playerName, getPlayerUUID(playerID), rs.getString("name"), rs.getString("description"), rs.getBoolean("public")));
|
||||
if (rs != null) {
|
||||
while (rs.next()) {
|
||||
int locationID = rs.getInt("location_id");
|
||||
TeleportationPoint teleportationPoint = getTeleportationPoint(locationID);
|
||||
if (teleportationPoint != null && playerID != null) {
|
||||
publicHomes.add(new Home(teleportationPoint,
|
||||
playerName, getPlayerUUID(playerID),
|
||||
rs.getString("name"),
|
||||
rs.getString("description"),
|
||||
rs.getBoolean("public")));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return publicHomes;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return publicHomes;
|
||||
} catch (SQLException e) {
|
||||
Bukkit.getLogger().severe("An SQL exception occurred returning a home!");
|
||||
return null;
|
||||
@@ -180,10 +247,17 @@ public class dataManager {
|
||||
try {
|
||||
ResultSet rs = queryDatabase("SELECT * FROM " + Main.settings.getHomesTable() + " WHERE `public`;");
|
||||
ArrayList<Home> publicHomes = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
int playerID = rs.getInt("player_id");
|
||||
int locationID = rs.getInt("location_id");
|
||||
publicHomes.add(new Home(getTeleportationPoint(locationID), getPlayerUsername(playerID), getPlayerUUID(playerID), rs.getString("name"), rs.getString("description"), true));
|
||||
if (rs != null) {
|
||||
while (rs.next()) {
|
||||
int playerID = rs.getInt("player_id");
|
||||
int locationID = rs.getInt("location_id");
|
||||
TeleportationPoint teleportationPoint = getTeleportationPoint(locationID);
|
||||
if (teleportationPoint != null) {
|
||||
publicHomes.add(new Home(teleportationPoint, getPlayerUsername(playerID), getPlayerUUID(playerID), rs.getString("name"), rs.getString("description"), true));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return publicHomes;
|
||||
} catch (SQLException e) {
|
||||
@@ -197,9 +271,16 @@ public class dataManager {
|
||||
try {
|
||||
ResultSet rs = queryDatabase("SELECT * FROM " + Main.settings.getWarpsTable() + ";");
|
||||
ArrayList<Warp> warps = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
int locationID = rs.getInt("location_id");
|
||||
warps.add(new Warp(getTeleportationPoint(locationID), rs.getString("name"), rs.getString("description")));
|
||||
if (rs != null) {
|
||||
while (rs.next()) {
|
||||
int locationID = rs.getInt("location_id");
|
||||
TeleportationPoint teleportationPoint = getTeleportationPoint(locationID);
|
||||
if (teleportationPoint != null) {
|
||||
warps.add(new Warp(teleportationPoint,
|
||||
rs.getString("name"),
|
||||
rs.getString("description")));
|
||||
}
|
||||
}
|
||||
}
|
||||
return warps;
|
||||
} catch (SQLException e) {
|
||||
@@ -212,14 +293,27 @@ public class dataManager {
|
||||
public static Warp getWarp(String name) {
|
||||
try {
|
||||
ResultSet rs = queryDatabase("SELECT * FROM " + Main.settings.getWarpsTable() + " WHERE `name`=" + name + ";");
|
||||
if (rs.next()) {
|
||||
int locationID = rs.getInt("location_id");
|
||||
return new Warp(getTeleportationPoint(locationID), rs.getString("name"), rs.getString("description"));
|
||||
if (rs != null) {
|
||||
if (rs.next()) {
|
||||
int locationID = rs.getInt("location_id");
|
||||
TeleportationPoint teleportationPoint = getTeleportationPoint(locationID);
|
||||
if (teleportationPoint != null) {
|
||||
return new Warp(teleportationPoint,
|
||||
rs.getString("name"),
|
||||
rs.getString("description"));
|
||||
} else {
|
||||
Bukkit.getLogger().severe("An error occurred returning a warp!");
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Bukkit.getLogger().severe("An SQL exception occurred returning a list of warps!");
|
||||
Bukkit.getLogger().severe("An SQL exception occurred returning a warp");
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -229,27 +323,77 @@ public class dataManager {
|
||||
try {
|
||||
Integer playerID = getPlayerId(ownerUsername);
|
||||
ResultSet rs = queryDatabase("SELECT * FROM " + Main.settings.getHomesTable() + " WHERE `player_id`=" + (playerID) + " AND `name`=" + homeName +";");
|
||||
if (rs.next()) {
|
||||
int locationID = rs.getInt("location_id");
|
||||
return new Home(getTeleportationPoint(locationID),
|
||||
ownerUsername,
|
||||
getPlayerUUID(playerID),
|
||||
rs.getString("name"),
|
||||
rs.getString("description"),
|
||||
rs.getBoolean("public"));
|
||||
if (rs != null) {
|
||||
if (rs.next()) {
|
||||
int locationID = rs.getInt("location_id");
|
||||
TeleportationPoint teleportationPoint = getTeleportationPoint(locationID);
|
||||
if (teleportationPoint != null && playerID != null) {
|
||||
return new Home(teleportationPoint,
|
||||
ownerUsername,
|
||||
getPlayerUUID(playerID),
|
||||
rs.getString("name"),
|
||||
rs.getString("description"),
|
||||
rs.getBoolean("public"));
|
||||
} else {
|
||||
Bukkit.getLogger().severe("An error occurred retrieving a home from the table!");
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
Bukkit.getLogger().severe("An error occurred retrieving a home from the table!");
|
||||
return null;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Bukkit.getLogger().severe("An SQL exception occurred returning a home!");
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean warpExists(String warpName) {
|
||||
try {
|
||||
ResultSet rs = queryDatabase("SELECT * FROM " + Main.settings.getWarpsTable() + " WHERE `name`=" + warpName + ";");
|
||||
if (rs != null) {
|
||||
return rs.next();
|
||||
} else {
|
||||
Bukkit.getLogger().severe("An SQL exception occurred in retrieving warp data from the table.");
|
||||
return false;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Bukkit.getLogger().severe("An SQL exception occurred in checking if warp data exists in the table.");
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean homeExists(Player p, String homeName) {
|
||||
Integer playerID = getPlayerId(p.getName());
|
||||
try {
|
||||
ResultSet rs = queryDatabase("SELECT * FROM " + Main.settings.getHomesTable() + " WHERE `player_id`=" + playerID + " AND `name`=" + homeName +";");
|
||||
if (rs != null) {
|
||||
return rs.next();
|
||||
} else {
|
||||
Bukkit.getLogger().severe("An SQL exception occurred in retrieving player data from the table.");
|
||||
return false;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Bukkit.getLogger().severe("An SQL exception occurred in checking if player data exists in the table.");
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean playerExists(Player p) {
|
||||
try {
|
||||
ResultSet rs = queryDatabase("SELECT * FROM " + Main.settings.getPlayerTable() + " WHERE `uuid`=" + p.getUniqueId().toString() + ";");
|
||||
return rs.next();
|
||||
if (rs != null) {
|
||||
return rs.next();
|
||||
} else {
|
||||
Bukkit.getLogger().severe("An SQL exception retrieving SQL data from the player table in determining if they exist.");
|
||||
return false;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Bukkit.getLogger().severe("An SQL exception occurred in determining if a player exists in the player table.");
|
||||
e.printStackTrace();
|
||||
@@ -260,9 +404,14 @@ public class dataManager {
|
||||
private static Integer getPlayerId(String playerUsername) {
|
||||
try {
|
||||
ResultSet rs = queryDatabase("SELECT * FROM " + Main.settings.getPlayerTable() + " WHERE `username`=" + (playerUsername) + ";");
|
||||
if (rs.next()) {
|
||||
return rs.getInt("player_id");
|
||||
if (rs != null) {
|
||||
if (rs.next()) {
|
||||
return rs.getInt("player_id");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
Bukkit.getLogger().severe("An SQL exception occurred in retrieving a player ID.");
|
||||
return null;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
@@ -272,13 +421,21 @@ public class dataManager {
|
||||
}
|
||||
|
||||
public static TeleportationPoint getPlayerDestination(Player p) {
|
||||
int locationID = getPlayerInteger(p, "dest_location_id");
|
||||
return getTeleportationPoint(locationID);
|
||||
Integer locationID = getPlayerInteger(p, "dest_location_id");
|
||||
if (locationID != null) {
|
||||
return getTeleportationPoint(locationID);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static TeleportationPoint getPlayerLastPosition(Player p) {
|
||||
int locationID = getPlayerInteger(p, "last_location_id");
|
||||
return getTeleportationPoint(locationID);
|
||||
Integer locationID = getPlayerInteger(p, "last_location_id");
|
||||
if (locationID != null) {
|
||||
return getTeleportationPoint(locationID);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Update a player's last position location on SQL
|
||||
@@ -296,6 +453,21 @@ public class dataManager {
|
||||
}
|
||||
}
|
||||
|
||||
// Update a player's destination location on SQL
|
||||
public static void setPlayerDestinationLocation(String playerName, TeleportationPoint point) {
|
||||
Integer playerID = getPlayerId(playerName);
|
||||
if (playerID != null) {
|
||||
deletePlayerDestination(playerName);
|
||||
if (Main.settings.getStorageType().equalsIgnoreCase("mySQL")) {
|
||||
|
||||
} else {
|
||||
sqliteDatabase.setTeleportationLastOrDest(playerID, point, "dest");
|
||||
}
|
||||
} else {
|
||||
Bukkit.getLogger().warning("Failed to update player destination records for " + playerName);
|
||||
}
|
||||
}
|
||||
|
||||
// Update a player's destination location on SQL
|
||||
public static void setPlayerDestinationLocation(Player p, TeleportationPoint point) {
|
||||
Integer playerID = getPlayerId(p.getName());
|
||||
@@ -325,21 +497,36 @@ public class dataManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static void deletePlayerDestination(Player p) {
|
||||
int destinationID = getPlayerInteger(p, "dest_location_id");
|
||||
if (Main.settings.getStorageType().equalsIgnoreCase("mySQL")) {
|
||||
public static void deletePlayerDestination(String playerName) {
|
||||
Integer destinationID = getPlayerInteger(playerName, "dest_location_id");
|
||||
if (destinationID != null) {
|
||||
if (Main.settings.getStorageType().equalsIgnoreCase("mySQL")) {
|
||||
|
||||
} else {
|
||||
sqliteDatabase.deleteTeleportationPoint(destinationID);
|
||||
} else {
|
||||
sqliteDatabase.deleteTeleportationPoint(destinationID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void deletePlayerDestination(Player p) {
|
||||
Integer destinationID = getPlayerInteger(p, "dest_location_id");
|
||||
if (destinationID != null) {
|
||||
if (Main.settings.getStorageType().equalsIgnoreCase("mySQL")) {
|
||||
|
||||
} else {
|
||||
sqliteDatabase.deleteTeleportationPoint(destinationID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void deletePlayerLastPosition(Player p) {
|
||||
int lastPositionID = getPlayerInteger(p, "last_location_id");
|
||||
if (Main.settings.getStorageType().equalsIgnoreCase("mySQL")) {
|
||||
Integer lastPositionID = getPlayerInteger(p, "last_location_id");
|
||||
if (lastPositionID != null) {
|
||||
if (Main.settings.getStorageType().equalsIgnoreCase("mySQL")) {
|
||||
|
||||
} else {
|
||||
sqliteDatabase.deleteTeleportationPoint(lastPositionID);
|
||||
} else {
|
||||
sqliteDatabase.deleteTeleportationPoint(lastPositionID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,15 +551,39 @@ public class dataManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteHome(String homeName, Player p) {
|
||||
if (Main.settings.getStorageType().equalsIgnoreCase("mySQL")) {
|
||||
|
||||
} else {
|
||||
Integer playerID = getPlayerId(p.getName());
|
||||
if (playerID != null) {
|
||||
sqliteDatabase.deleteHome(homeName, playerID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteWarp(String warpName) {
|
||||
if (Main.settings.getStorageType().equalsIgnoreCase("mySQL")) {
|
||||
|
||||
} else {
|
||||
sqliteDatabase.deleteWarp(warpName);
|
||||
}
|
||||
}
|
||||
|
||||
public static TeleportationPoint getTeleportationPoint(int locationID) {
|
||||
try {
|
||||
ResultSet rs = queryDatabase("SELECT * FROM " + Main.settings.getLocationsTable() + " WHERE `location_id`=" + (locationID) + ";");
|
||||
if (rs.next()) {
|
||||
return new TeleportationPoint(rs.getString("world"),
|
||||
rs.getDouble("x"), rs.getDouble("y"),
|
||||
rs.getDouble("z"), rs.getFloat("yaw"),
|
||||
rs.getFloat("pitch"), rs.getString("server"));
|
||||
if (rs != null) {
|
||||
if (rs.next()) {
|
||||
return new TeleportationPoint(rs.getString("world"),
|
||||
rs.getDouble("x"), rs.getDouble("y"),
|
||||
rs.getDouble("z"), rs.getFloat("yaw"),
|
||||
rs.getFloat("pitch"), rs.getString("server"));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
Bukkit.getLogger().severe("An error occurred returning a transportation point!");
|
||||
return null;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
|
||||
Reference in new issue
Block a user