Finish up refactoring, start fixing

This commit is contained in:
WiIIiam278 committed 2021-05-30 23:13:03 +01:00
1 parent a63f1a77ad
commit cc90d5f15d
36 files changed
+520 -556

No files matched your search

@@ -204,8 +204,8 @@ public class DataManager {
ps = connection.prepareStatement("SELECT * FROM " + HuskHomes.getSettings().getHomesDataTable() + " WHERE `public`;");
rs = ps.executeQuery();
final List<Home> publicHomes = new ArrayList<>();
if (rs != null) {
final List<Home> publicHomes = new ArrayList<>();
while (rs.next()) {
int playerID = rs.getInt("player_id");
int locationID = rs.getInt("location_id");
@@ -215,10 +215,9 @@ public class DataManager {
rs.getString("description"), true));
}
ps.close();
return publicHomes;
}
ps.close();
return null;
return publicHomes;
}
// Return an array of all the warps
@@ -398,7 +397,7 @@ public class DataManager {
ps.close();
}
public static void setPlayerTeleporting(UUID uuid, boolean value, Connection connection) throws SQLException {
public static void setPlayerTeleportingData(UUID uuid, boolean value, Connection connection) throws SQLException {
PreparedStatement ps;
ps = connection.prepareStatement("UPDATE " + HuskHomes.getSettings().getPlayerDataTable() + " SET `is_teleporting`=? WHERE `user_uuid`=?;");
ps.setBoolean(1, value);
@@ -507,7 +506,7 @@ public class DataManager {
}
// Update a player's destination teleport point
public static void setTeleportationDestination(String username, TeleportationPoint point, Connection connection) throws SQLException {
public static void setTeleportationDestinationData(String username, TeleportationPoint point, Connection connection) throws SQLException {
PreparedStatement ps;
// Add the teleportation point
@@ -716,7 +715,7 @@ public class DataManager {
}
// Update a player's last position teleport point
public static void setTeleportationLastPosition(UUID uuid, TeleportationPoint point, Connection connection) throws SQLException {
public static void setTeleportationLastPositionData(UUID uuid, TeleportationPoint point, Connection connection) throws SQLException {
PreparedStatement ps;
// Add the teleportation point
Integer locationID = addTeleportationPoint(point, connection);
@@ -732,13 +731,13 @@ public class DataManager {
// Update a player's last position location on SQL
public static void setPlayerLastPosition(Player p, TeleportationPoint point, Connection connection) throws SQLException {
deletePlayerLastPosition(p, connection);
setTeleportationLastPosition(p.getUniqueId(), point, connection);
setTeleportationLastPositionData(p.getUniqueId(), point, connection);
}
// Update a player's destination location on SQL
public static void setPlayerDestinationLocation(String playerName, TeleportationPoint point, Connection connection) throws SQLException {
deletePlayerDestination(playerName, connection);
setTeleportationDestination(playerName, point, connection);
setTeleportationDestinationData(playerName, point, connection);
}
// Update a player's destination location on SQL
@@ -747,12 +746,7 @@ public class DataManager {
}
public static void setPlayerTeleporting(Player p, boolean value, Connection connection) throws SQLException {
setPlayerTeleporting(p, value, connection);
}
public static void clearPlayerDestination(String playerName, Connection connection) throws SQLException {
deletePlayerDestination(playerName, connection);
clearPlayerDestData(playerName, connection);
setPlayerTeleportingData(p.getUniqueId(), value, connection);
}
public static void updateRtpCooldown(Player p, Connection connection) throws SQLException {
@@ -765,14 +759,10 @@ public class DataManager {
Integer destinationID = getPlayerInteger(playerName, "dest_location_id", connection);
if (destinationID != null) {
deleteTeleportationPoint(destinationID, connection);
clearPlayerDestination(playerName, connection);
clearPlayerDestData(playerName, connection);
}
}
public static void deletePlayerDestination(Player p, Connection connection) throws SQLException {
deletePlayerDestination(p.getName(), connection);
}
// Delete a teleportation point from SQL
public static void deleteTeleportationPoint(int locationID, Connection connection) throws SQLException {
PreparedStatement ps;
@@ -1,18 +1,11 @@
package me.william278.huskhomes2.data.SQL;
import me.william278.huskhomes2.HuskHomes;
import me.william278.huskhomes2.data.Error;
import me.william278.huskhomes2.teleport.points.Home;
import me.william278.huskhomes2.teleport.points.TeleportationPoint;
import me.william278.huskhomes2.teleport.points.Warp;
import org.bukkit.entity.Player;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.UUID;
import java.util.logging.Level;
/*
@@ -11,6 +11,19 @@ import java.util.logging.Level;
public class MySQL extends Database {
final static String[] SQL_SETUP_STATEMENTS = {
"CREATE TABLE IF NOT EXISTS " + HuskHomes.getSettings().getLocationsDataTable() + " (" +
"`location_id` integer AUTO_INCREMENT," +
"`server` text NOT NULL," +
"`world` text NOT NULL," +
"`x` double NOT NULL," +
"`y` double NOT NULL," +
"`z` double NOT NULL," +
"`yaw` float NOT NULL," +
"`pitch` float NOT NULL," +
"PRIMARY KEY (`location_id`)" +
");",
"CREATE TABLE IF NOT EXISTS " + HuskHomes.getSettings().getPlayerDataTable() + " (" +
"`player_id` integer AUTO_INCREMENT," +
"`user_uuid` char(36) NOT NULL UNIQUE," +
@@ -26,19 +39,6 @@ public class MySQL extends Database {
"FOREIGN KEY (`last_location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE SET NULL ON UPDATE NO ACTION" +
");",
"CREATE TABLE IF NOT EXISTS " + HuskHomes.getSettings().getLocationsDataTable() + " (" +
"`location_id` integer AUTO_INCREMENT," +
"`server` text NOT NULL," +
"`world` text NOT NULL," +
"`x` double NOT NULL," +
"`y` double NOT NULL," +
"`z` double NOT NULL," +
"`yaw` float NOT NULL," +
"`pitch` float NOT NULL," +
"PRIMARY KEY (`location_id`)" +
");",
"CREATE TABLE IF NOT EXISTS " + HuskHomes.getSettings().getHomesDataTable() + " (" +
"`player_id` integer NOT NULL," +
"`location_id` integer NOT NULL," +
@@ -15,6 +15,17 @@ public class SQLite extends Database {
final static String[] SQL_SETUP_STATEMENTS = {
"PRAGMA foreign_keys = ON;",
"CREATE TABLE IF NOT EXISTS " + HuskHomes.getSettings().getLocationsDataTable() + " (" +
"`location_id` integer PRIMARY KEY," +
"`server` text NOT NULL," +
"`world` text NOT NULL," +
"`x` double NOT NULL," +
"`y` double NOT NULL," +
"`z` double NOT NULL," +
"`yaw` float NOT NULL," +
"`pitch` float NOT NULL" +
");",
"CREATE TABLE IF NOT EXISTS " + HuskHomes.getSettings().getPlayerDataTable() + " (" +
"`player_id` integer NOT NULL," +
"`user_uuid` char(36) NOT NULL UNIQUE," +
@@ -29,17 +40,6 @@ public class SQLite extends Database {
"FOREIGN KEY (`last_location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE SET NULL ON UPDATE NO ACTION" +
");",
"CREATE TABLE IF NOT EXISTS " + HuskHomes.getSettings().getLocationsDataTable() + " (" +
"`location_id` integer PRIMARY KEY," +
"`server` text NOT NULL," +
"`world` text NOT NULL," +
"`x` double NOT NULL," +
"`y` double NOT NULL," +
"`z` double NOT NULL," +
"`yaw` float NOT NULL," +
"`pitch` float NOT NULL" +
");",
"CREATE TABLE IF NOT EXISTS " + HuskHomes.getSettings().getHomesDataTable() + " (" +
"`player_id` integer NOT NULL," +
"`location_id` integer NOT NULL," +
@@ -3,6 +3,7 @@ package me.william278.huskhomes2.data.pluginmessage;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import me.william278.huskhomes2.HuskHomes;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.io.ByteArrayOutputStream;
@@ -77,59 +78,63 @@ public class PluginMessage {
* @param sender The player to send the message
*/
public void send(Player sender) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
Bukkit.getScheduler().runTask(plugin, () -> {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
// Send a plugin message to the specified player name
out.writeUTF("ForwardToPlayer");
out.writeUTF(targetPlayerName);
// Send a plugin message to the specified player name
out.writeUTF("ForwardToPlayer");
out.writeUTF(targetPlayerName);
// Send the HuskHomes message with a specific type
out.writeUTF("HuskHomes:" + clusterID + ":" + getPluginMessageString(messageType));
ByteArrayOutputStream messageBytes = new ByteArrayOutputStream();
DataOutputStream messageOut = new DataOutputStream(messageBytes);
// Send the HuskHomes message with a specific type
out.writeUTF("HuskHomes:" + clusterID + ":" + getPluginMessageString(messageType));
ByteArrayOutputStream messageBytes = new ByteArrayOutputStream();
DataOutputStream messageOut = new DataOutputStream(messageBytes);
// Send the message data; output an exception if there's an error
try {
messageOut.writeUTF(messageData);
} catch (IOException e) {
plugin.getLogger().warning("An error occurred trying to send a plugin message (" + e.getCause() + ")");
e.printStackTrace();
}
// Send the message data; output an exception if there's an error
try {
messageOut.writeUTF(messageData);
} catch (IOException e) {
plugin.getLogger().warning("An error occurred trying to send a plugin message (" + e.getCause() + ")");
e.printStackTrace();
}
// Write the messages to the output packet
out.writeShort(messageBytes.toByteArray().length);
out.write(messageBytes.toByteArray());
// Write the messages to the output packet
out.writeShort(messageBytes.toByteArray().length);
out.write(messageBytes.toByteArray());
// Send the constructed plugin message packet
sender.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
// Send the constructed plugin message packet
sender.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
});
}
public void sendToAll(Player sender) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
Bukkit.getScheduler().runTask(plugin, () -> {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
// Send a plugin message to all players
out.writeUTF("Forward");
out.writeUTF("ALL");
// Send a plugin message to all players
out.writeUTF("Forward");
out.writeUTF("ALL");
// Send the HuskHomes message with a specific type
out.writeUTF("HuskHomes:" + clusterID + ":" + getPluginMessageString(messageType));
ByteArrayOutputStream messageBytes = new ByteArrayOutputStream();
DataOutputStream messageOut = new DataOutputStream(messageBytes);
// Send the HuskHomes message with a specific type
out.writeUTF("HuskHomes:" + clusterID + ":" + getPluginMessageString(messageType));
ByteArrayOutputStream messageBytes = new ByteArrayOutputStream();
DataOutputStream messageOut = new DataOutputStream(messageBytes);
// Send the message data; output an exception if there's an error
try {
messageOut.writeUTF(messageData);
} catch (IOException e) {
plugin.getLogger().warning("An error occurred trying to send a plugin message (" + e.getCause() + ")");
e.printStackTrace();
}
// Send the message data; output an exception if there's an error
try {
messageOut.writeUTF(messageData);
} catch (IOException e) {
plugin.getLogger().warning("An error occurred trying to send a plugin message (" + e.getCause() + ")");
e.printStackTrace();
}
// Write the messages to the output packet
out.writeShort(messageBytes.toByteArray().length);
out.write(messageBytes.toByteArray());
// Write the messages to the output packet
out.writeShort(messageBytes.toByteArray().length);
out.write(messageBytes.toByteArray());
// Send the constructed plugin message packet
sender.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
// Send the constructed plugin message packet
sender.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
});
}
public int getClusterID() {