diff --git a/README.md b/README.md index 02be121f..9d2e3961 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,20 @@ -# CrossServerSync -**CrossServerSync** is a robust solution for synchronising player data (inventories, health, hunger & status effects) between servers. It was designed as a much faster alternative to MySQLPlayerDataBridge, +# HuskSync +**HuskSync** is a robust solution for synchronising player data (inventories, health, hunger & status effects) between servers. It was designed as a much faster alternative to MySQLPlayerDataBridge, -### Installation -Install CrossServerSync in the `/plugins/` folder of your Spigot (and derivatives) servers and Proxy (BungeeCord and derivatives) server. +## Installation +Install HuskSync in the `/plugins/` folder of your Spigot (and derivatives) servers and Proxy (BungeeCord and derivatives) server. Start your servers, then stop them again to allow the configuration files to generate. -Navigate to the generated config.yml files on your Spigot server and Proxy (located in `/plugins/CrossServerSync/`) and fill in the credentials of your redis server. On the Proxy server, you can additionally configure a MySQL database to save player data in, as by default the plugin will create a SQLite database for this. +Navigate to the generated config.yml files on your Spigot server and Proxy (located in `/plugins/HuskSync/`) and fill in the credentials of your redis server. On the Proxy server, you can additionally configure a MySQL database to save player data in, as by default the plugin will create a SQLite database for this. If you have multiple proxy servers (i.e. via RedisBungee), you need to install the plugin on all of them and make use of the MySQL option and ensure the proxies are using the same database. -### How it works +## How it works ![Flow chart showing different processes of how the plugin works](images/flow-chart.png) -CrossServerSync synchronises player data between servers using Redis to transfer cached data, loaded from a central database as necessary. +HuskSync synchronises player data between servers using Redis to transfer cached data, loaded from a central database as necessary. -### Building -To build CrossServerSync, run the following in the root of the repository: +## Building +To build HuskSync, run the following in the root of the repository: ``` ./gradlew clean build ``` \ No newline at end of file diff --git a/build.gradle b/build.gradle index 3211c6f7..605e4b97 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,7 @@ allprojects { javadoc { options.encoding = 'UTF-8' } } -logger.lifecycle('Building CrossServerSync v' + version.toString()) +logger.lifecycle('Building HuskSync v' + version.toString()) subprojects { apply plugin: 'com.github.johnrengelman.shadow' diff --git a/bukkit/build.gradle b/bukkit/build.gradle index 6bb021c1..592d1ad6 100644 --- a/bukkit/build.gradle +++ b/bukkit/build.gradle @@ -10,9 +10,9 @@ dependencies { } shadowJar { - relocate 'redis.clients', 'me.William278.crossserversync.libraries.jedis' - relocate 'org.bstats', 'me.William278.crossserversync.libraries.plan' - relocate 'de.themoep', 'me.William278.crossserversync.libraries.minedown' + relocate 'redis.clients', 'me.William278.husksync.libraries.jedis' + relocate 'org.bstats', 'me.William278.husksync.libraries.plan' + relocate 'de.themoep', 'me.William278.husksync.libraries.minedown' } tasks.register('prepareKotlinBuildScriptModel'){} \ No newline at end of file diff --git a/bukkit/src/main/java/me/william278/crossserversync/CrossServerSyncBukkit.java b/bukkit/src/main/java/me/william278/husksync/HuskSyncBukkit.java similarity index 55% rename from bukkit/src/main/java/me/william278/crossserversync/CrossServerSyncBukkit.java rename to bukkit/src/main/java/me/william278/husksync/HuskSyncBukkit.java index 51d007ed..307ec5a2 100644 --- a/bukkit/src/main/java/me/william278/crossserversync/CrossServerSyncBukkit.java +++ b/bukkit/src/main/java/me/william278/husksync/HuskSyncBukkit.java @@ -1,15 +1,15 @@ -package me.william278.crossserversync; +package me.william278.husksync; -import me.william278.crossserversync.bukkit.config.ConfigLoader; -import me.william278.crossserversync.bukkit.data.BukkitDataCache; -import me.william278.crossserversync.bukkit.listener.BukkitRedisListener; -import me.william278.crossserversync.bukkit.listener.EventListener; +import me.william278.husksync.bukkit.config.ConfigLoader; +import me.william278.husksync.bukkit.data.BukkitDataCache; +import me.william278.husksync.bukkit.listener.BukkitRedisListener; +import me.william278.husksync.bukkit.listener.EventListener; import org.bukkit.plugin.java.JavaPlugin; -public final class CrossServerSyncBukkit extends JavaPlugin { +public final class HuskSyncBukkit extends JavaPlugin { - private static CrossServerSyncBukkit instance; - public static CrossServerSyncBukkit getInstance() { + private static HuskSyncBukkit instance; + public static HuskSyncBukkit getInstance() { return instance; } @@ -41,12 +41,12 @@ public final class CrossServerSyncBukkit extends JavaPlugin { new BukkitRedisListener(); // Log to console - getLogger().info("Enabled CrossServerSync (" + getServer().getName() + ") v" + getDescription().getVersion()); + getLogger().info("Enabled HuskSync (" + getServer().getName() + ") v" + getDescription().getVersion()); } @Override public void onDisable() { // Plugin shutdown logic - getLogger().info("Disabled CrossServerSync (" + getServer().getName() + ") v" + getDescription().getVersion()); + getLogger().info("Disabled HuskSync (" + getServer().getName() + ") v" + getDescription().getVersion()); } } diff --git a/bukkit/src/main/java/me/william278/crossserversync/bukkit/DataSerializer.java b/bukkit/src/main/java/me/william278/husksync/bukkit/DataSerializer.java similarity index 94% rename from bukkit/src/main/java/me/william278/crossserversync/bukkit/DataSerializer.java rename to bukkit/src/main/java/me/william278/husksync/bukkit/DataSerializer.java index 2d6a0404..6f46c82f 100644 --- a/bukkit/src/main/java/me/william278/crossserversync/bukkit/DataSerializer.java +++ b/bukkit/src/main/java/me/william278/husksync/bukkit/DataSerializer.java @@ -1,6 +1,6 @@ -package me.william278.crossserversync.bukkit; +package me.william278.husksync.bukkit; -import me.william278.crossserversync.redis.RedisMessage; +import me.william278.husksync.redis.RedisMessage; import org.bukkit.*; import org.bukkit.advancement.Advancement; import org.bukkit.advancement.AdvancementProgress; @@ -175,7 +175,7 @@ public final class DataSerializer { return null; } try { - return (PlayerLocation) RedisMessage.deserialize(serializedLocationData); + return (PlayerLocation) me.william278.husksync.redis.RedisMessage.deserialize(serializedLocationData); } catch (ClassNotFoundException e) { throw new IOException("Unable to decode class type.", e); } @@ -183,7 +183,7 @@ public final class DataSerializer { public static String getSerializedLocation(Player player) throws IOException { final Location playerLocation = player.getLocation(); - return RedisMessage.serialize(new PlayerLocation(playerLocation.getX(), playerLocation.getY(), playerLocation.getZ(), + return me.william278.husksync.redis.RedisMessage.serialize(new PlayerLocation(playerLocation.getX(), playerLocation.getY(), playerLocation.getZ(), playerLocation.getYaw(), playerLocation.getPitch(), player.getWorld().getName(), player.getWorld().getEnvironment())); } @@ -197,7 +197,7 @@ public final class DataSerializer { return new ArrayList<>(); } try { - return (ArrayList) RedisMessage.deserialize(serializedAdvancementData); + return (ArrayList) me.william278.husksync.redis.RedisMessage.deserialize(serializedAdvancementData); } catch (ClassNotFoundException e) { throw new IOException("Unable to decode class type.", e); } @@ -214,7 +214,7 @@ public final class DataSerializer { advancementData.add(new AdvancementRecord(advancementKey.getNamespace() + ":" + advancementKey.getKey(), awardedCriteria)); } - return RedisMessage.serialize(advancementData); + return me.william278.husksync.redis.RedisMessage.serialize(advancementData); } public record AdvancementRecord(String advancementKey, @@ -226,7 +226,7 @@ public final class DataSerializer { return new StatisticData(new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>()); } try { - return (StatisticData) RedisMessage.deserialize(serializedStatisticData); + return (StatisticData) me.william278.husksync.redis.RedisMessage.deserialize(serializedStatisticData); } catch (ClassNotFoundException e) { throw new IOException("Unable to decode class type.", e); } diff --git a/bukkit/src/main/java/me/william278/crossserversync/bukkit/PlayerSetter.java b/bukkit/src/main/java/me/william278/husksync/bukkit/PlayerSetter.java similarity index 97% rename from bukkit/src/main/java/me/william278/crossserversync/bukkit/PlayerSetter.java rename to bukkit/src/main/java/me/william278/husksync/bukkit/PlayerSetter.java index 0481d9c2..df0dee3d 100644 --- a/bukkit/src/main/java/me/william278/crossserversync/bukkit/PlayerSetter.java +++ b/bukkit/src/main/java/me/william278/husksync/bukkit/PlayerSetter.java @@ -1,10 +1,10 @@ -package me.william278.crossserversync.bukkit; +package me.william278.husksync.bukkit; import de.themoep.minedown.MineDown; -import me.william278.crossserversync.CrossServerSyncBukkit; -import me.william278.crossserversync.MessageStrings; -import me.william278.crossserversync.PlayerData; -import me.william278.crossserversync.Settings; +import me.william278.husksync.HuskSyncBukkit; +import me.william278.husksync.MessageStrings; +import me.william278.husksync.PlayerData; +import me.william278.husksync.Settings; import net.md_5.bungee.api.ChatMessageType; import org.bukkit.*; import org.bukkit.advancement.Advancement; @@ -23,7 +23,7 @@ import java.util.logging.Level; public class PlayerSetter { - private static final CrossServerSyncBukkit plugin = CrossServerSyncBukkit.getInstance(); + private static final HuskSyncBukkit plugin = HuskSyncBukkit.getInstance(); /** * Set a player from their PlayerData, based on settings diff --git a/bukkit/src/main/java/me/william278/crossserversync/bukkit/config/ConfigLoader.java b/bukkit/src/main/java/me/william278/husksync/bukkit/config/ConfigLoader.java similarity index 93% rename from bukkit/src/main/java/me/william278/crossserversync/bukkit/config/ConfigLoader.java rename to bukkit/src/main/java/me/william278/husksync/bukkit/config/ConfigLoader.java index 20c02582..a12590e5 100644 --- a/bukkit/src/main/java/me/william278/crossserversync/bukkit/config/ConfigLoader.java +++ b/bukkit/src/main/java/me/william278/husksync/bukkit/config/ConfigLoader.java @@ -1,6 +1,6 @@ -package me.william278.crossserversync.bukkit.config; +package me.william278.husksync.bukkit.config; -import me.william278.crossserversync.Settings; +import me.william278.husksync.Settings; import org.bukkit.configuration.file.FileConfiguration; public class ConfigLoader { diff --git a/bukkit/src/main/java/me/william278/crossserversync/bukkit/data/BukkitDataCache.java b/bukkit/src/main/java/me/william278/husksync/bukkit/data/BukkitDataCache.java similarity index 52% rename from bukkit/src/main/java/me/william278/crossserversync/bukkit/data/BukkitDataCache.java rename to bukkit/src/main/java/me/william278/husksync/bukkit/data/BukkitDataCache.java index f5a2cff2..82374d00 100644 --- a/bukkit/src/main/java/me/william278/crossserversync/bukkit/data/BukkitDataCache.java +++ b/bukkit/src/main/java/me/william278/husksync/bukkit/data/BukkitDataCache.java @@ -1,34 +1,19 @@ -package me.william278.crossserversync.bukkit.data; +package me.william278.husksync.bukkit.data; -import java.util.HashMap; import java.util.HashSet; import java.util.UUID; public class BukkitDataCache { - /** - * Map of Player UUIDs to last-updated PlayerData version UUIDs - */ - private static HashMap bukkitDataCache; - /** * Map of Player UUIDs to request on join */ private static HashSet requestOnJoin; public BukkitDataCache() { - bukkitDataCache = new HashMap<>(); requestOnJoin = new HashSet<>(); } - public UUID getVersionUUID(UUID playerUUID) { - return bukkitDataCache.get(playerUUID); - } - - public void setVersionUUID(UUID playerUUID, UUID dataVersionUUID) { - bukkitDataCache.put(playerUUID, dataVersionUUID); - } - public boolean isPlayerRequestingOnJoin(UUID uuid) { return requestOnJoin.contains(uuid); } diff --git a/bukkit/src/main/java/me/william278/crossserversync/bukkit/listener/BukkitRedisListener.java b/bukkit/src/main/java/me/william278/husksync/bukkit/listener/BukkitRedisListener.java similarity index 70% rename from bukkit/src/main/java/me/william278/crossserversync/bukkit/listener/BukkitRedisListener.java rename to bukkit/src/main/java/me/william278/husksync/bukkit/listener/BukkitRedisListener.java index 522a458b..2d4ef0c3 100644 --- a/bukkit/src/main/java/me/william278/crossserversync/bukkit/listener/BukkitRedisListener.java +++ b/bukkit/src/main/java/me/william278/husksync/bukkit/listener/BukkitRedisListener.java @@ -1,13 +1,13 @@ -package me.william278.crossserversync.bukkit.listener; +package me.william278.husksync.bukkit.listener; import de.themoep.minedown.MineDown; -import me.william278.crossserversync.MessageStrings; -import me.william278.crossserversync.PlayerData; -import me.william278.crossserversync.Settings; -import me.william278.crossserversync.CrossServerSyncBukkit; -import me.william278.crossserversync.bukkit.PlayerSetter; -import me.william278.crossserversync.redis.RedisListener; -import me.william278.crossserversync.redis.RedisMessage; +import me.william278.husksync.PlayerData; +import me.william278.husksync.HuskSyncBukkit; +import me.william278.husksync.bukkit.PlayerSetter; +import me.william278.husksync.redis.RedisListener; +import me.william278.husksync.MessageStrings; +import me.william278.husksync.Settings; +import me.william278.husksync.redis.RedisMessage; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -17,7 +17,7 @@ import java.util.logging.Level; public class BukkitRedisListener extends RedisListener { - private static final CrossServerSyncBukkit plugin = CrossServerSyncBukkit.getInstance(); + private static final HuskSyncBukkit plugin = HuskSyncBukkit.getInstance(); // Initialize the listener on the bukkit server public BukkitRedisListener() { @@ -25,12 +25,12 @@ public class BukkitRedisListener extends RedisListener { } /** - * Handle an incoming {@link RedisMessage} + * Handle an incoming {@link me.william278.husksync.redis.RedisMessage} * - * @param message The {@link RedisMessage} to handle + * @param message The {@link me.william278.husksync.redis.RedisMessage} to handle */ @Override - public void handleMessage(RedisMessage message) { + public void handleMessage(me.william278.husksync.redis.RedisMessage message) { // Ignore messages for proxy servers if (!message.getMessageTarget().targetServerType().equals(Settings.ServerType.BUKKIT)) { return; @@ -39,11 +39,11 @@ public class BukkitRedisListener extends RedisListener { // Handle the message for the player if (message.getMessageTarget().targetPlayerUUID() == null) { - if (message.getMessageType() == RedisMessage.MessageType.REQUEST_DATA_ON_JOIN) { + if (message.getMessageType() == me.william278.husksync.redis.RedisMessage.MessageType.REQUEST_DATA_ON_JOIN) { UUID playerUUID = UUID.fromString(message.getMessageDataElements()[1]); - switch (RedisMessage.RequestOnJoinUpdateType.valueOf(message.getMessageDataElements()[0])) { - case ADD_REQUESTER -> CrossServerSyncBukkit.bukkitCache.setRequestOnJoin(playerUUID); - case REMOVE_REQUESTER -> CrossServerSyncBukkit.bukkitCache.removeRequestOnJoin(playerUUID); + switch (me.william278.husksync.redis.RedisMessage.RequestOnJoinUpdateType.valueOf(message.getMessageDataElements()[0])) { + case ADD_REQUESTER -> HuskSyncBukkit.bukkitCache.setRequestOnJoin(playerUUID); + case REMOVE_REQUESTER -> HuskSyncBukkit.bukkitCache.removeRequestOnJoin(playerUUID); } } } else { @@ -55,9 +55,6 @@ public class BukkitRedisListener extends RedisListener { // Deserialize the received PlayerData PlayerData data = (PlayerData) RedisMessage.deserialize(message.getMessageData()); - // Update last loaded data UUID - CrossServerSyncBukkit.bukkitCache.setVersionUUID(player.getUniqueId(), data.getDataVersionUUID()); - // Set the player's data PlayerSetter.setPlayerFrom(player, data); } catch (IOException | ClassNotFoundException e) { diff --git a/bukkit/src/main/java/me/william278/crossserversync/bukkit/listener/EventListener.java b/bukkit/src/main/java/me/william278/husksync/bukkit/listener/EventListener.java similarity index 68% rename from bukkit/src/main/java/me/william278/crossserversync/bukkit/listener/EventListener.java rename to bukkit/src/main/java/me/william278/husksync/bukkit/listener/EventListener.java index 1e17feca..a387ea2e 100644 --- a/bukkit/src/main/java/me/william278/crossserversync/bukkit/listener/EventListener.java +++ b/bukkit/src/main/java/me/william278/husksync/bukkit/listener/EventListener.java @@ -1,10 +1,10 @@ -package me.william278.crossserversync.bukkit.listener; +package me.william278.husksync.bukkit.listener; -import me.william278.crossserversync.CrossServerSyncBukkit; -import me.william278.crossserversync.PlayerData; -import me.william278.crossserversync.Settings; -import me.william278.crossserversync.bukkit.DataSerializer; -import me.william278.crossserversync.redis.RedisMessage; +import me.william278.husksync.HuskSyncBukkit; +import me.william278.husksync.PlayerData; +import me.william278.husksync.Settings; +import me.william278.husksync.bukkit.DataSerializer; +import me.william278.husksync.redis.RedisMessage; import org.bukkit.attribute.Attribute; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -18,7 +18,7 @@ import java.util.logging.Level; public class EventListener implements Listener { - private static final CrossServerSyncBukkit plugin = CrossServerSyncBukkit.getInstance(); + private static final HuskSyncBukkit plugin = HuskSyncBukkit.getInstance(); /** * Returns the new serialized PlayerData for a player. @@ -28,7 +28,7 @@ public class EventListener implements Listener { * @throws IOException If the serialization fails */ private static String getNewSerializedPlayerData(Player player) throws IOException { - return RedisMessage.serialize(new PlayerData(player.getUniqueId(), + return me.william278.husksync.redis.RedisMessage.serialize(new PlayerData(player.getUniqueId(), DataSerializer.getSerializedInventoryContents(player), DataSerializer.getSerializedEnderChestContents(player), player.getHealth(), @@ -53,15 +53,11 @@ public class EventListener implements Listener { // When a player leaves a Bukkit server final Player player = event.getPlayer(); + // Send a redis message with the player's last updated PlayerData version UUID and their new PlayerData try { - // Get the player's last updated PlayerData version UUID - //final UUID lastUpdatedDataVersion = CrossServerSyncBukkit.bukkitCache.getVersionUUID(player.getUniqueId()); - //if (lastUpdatedDataVersion == null) return; // Return if the player has not been properly updated. - - // Send a redis message with the player's last updated PlayerData version UUID and their new PlayerData final String serializedPlayerData = getNewSerializedPlayerData(player); - new RedisMessage(RedisMessage.MessageType.PLAYER_DATA_UPDATE, - new RedisMessage.MessageTarget(Settings.ServerType.BUNGEECORD, null), + new me.william278.husksync.redis.RedisMessage(me.william278.husksync.redis.RedisMessage.MessageType.PLAYER_DATA_UPDATE, + new me.william278.husksync.redis.RedisMessage.MessageTarget(Settings.ServerType.BUNGEECORD, null), serializedPlayerData).send(); } catch (IOException e) { plugin.getLogger().log(Level.SEVERE, "Failed to send a PlayerData update to the proxy", e); @@ -70,9 +66,6 @@ public class EventListener implements Listener { // Clear player inventory and ender chest player.getInventory().clear(); player.getEnderChest().clear(); - - // Set data version ID to null - CrossServerSyncBukkit.bukkitCache.setVersionUUID(player.getUniqueId(), null); } @EventHandler @@ -84,10 +77,10 @@ public class EventListener implements Listener { player.getInventory().clear(); player.getEnderChest().clear(); - if (CrossServerSyncBukkit.bukkitCache.isPlayerRequestingOnJoin(player.getUniqueId())) { + if (HuskSyncBukkit.bukkitCache.isPlayerRequestingOnJoin(player.getUniqueId())) { try { // Send a redis message requesting the player data - new RedisMessage(RedisMessage.MessageType.PLAYER_DATA_REQUEST, + new me.william278.husksync.redis.RedisMessage(me.william278.husksync.redis.RedisMessage.MessageType.PLAYER_DATA_REQUEST, new RedisMessage.MessageTarget(Settings.ServerType.BUNGEECORD, null), player.getUniqueId().toString()).send(); } catch (IOException e) { diff --git a/bungeecord/build.gradle b/bungeecord/build.gradle index 60cd7c7a..209e9e9c 100644 --- a/bungeecord/build.gradle +++ b/bungeecord/build.gradle @@ -10,10 +10,10 @@ dependencies { } shadowJar { - relocate 'redis.clients', 'me.William278.crossserversync.libraries.jedis' - relocate 'com.zaxxer', 'me.William278.crossserversync.libraries.hikari' - relocate 'org.bstats', 'me.William278.crossserversync.libraries.plan' - relocate 'de.themoep', 'me.William278.crossserversync.libraries.minedown' + relocate 'redis.clients', 'me.William278.husksync.libraries.jedis' + relocate 'com.zaxxer', 'me.William278.husksync.libraries.hikari' + relocate 'org.bstats', 'me.William278.husksync.libraries.plan' + relocate 'de.themoep', 'me.William278.husksync.libraries.minedown' } tasks.register('prepareKotlinBuildScriptModel'){} \ No newline at end of file diff --git a/bungeecord/src/main/java/me/william278/crossserversync/bungeecord/data/sql/Database.java b/bungeecord/src/main/java/me/william278/crossserversync/bungeecord/data/sql/Database.java deleted file mode 100644 index 3cef42bd..00000000 --- a/bungeecord/src/main/java/me/william278/crossserversync/bungeecord/data/sql/Database.java +++ /dev/null @@ -1,33 +0,0 @@ -package me.william278.crossserversync.bungeecord.data.sql; - -import me.william278.crossserversync.Settings; -import me.william278.crossserversync.CrossServerSyncBungeeCord; - -import java.sql.Connection; -import java.sql.SQLException; - -public abstract class Database { - protected CrossServerSyncBungeeCord plugin; - - public final static String DATA_POOL_NAME = "CrossServerSyncHikariPool"; - public final static String PLAYER_TABLE_NAME = "crossserversync_players"; - public final static String DATA_TABLE_NAME = "crossserversync_data"; - - public Database(CrossServerSyncBungeeCord instance) { - plugin = instance; - } - - public abstract Connection getConnection() throws SQLException; - - public abstract void load(); - - public abstract void backup(); - - public abstract void close(); - - public final int hikariMaximumPoolSize = Settings.hikariMaximumPoolSize; - public final int hikariMinimumIdle = Settings.hikariMinimumIdle; - public final long hikariMaximumLifetime = Settings.hikariMaximumLifetime; - public final long hikariKeepAliveTime = Settings.hikariKeepAliveTime; - public final long hikariConnectionTimeOut = Settings.hikariConnectionTimeOut; -} diff --git a/bungeecord/src/main/java/me/william278/crossserversync/CrossServerSyncBungeeCord.java b/bungeecord/src/main/java/me/william278/husksync/HuskSyncBungeeCord.java similarity index 56% rename from bungeecord/src/main/java/me/william278/crossserversync/CrossServerSyncBungeeCord.java rename to bungeecord/src/main/java/me/william278/husksync/HuskSyncBungeeCord.java index 1ba50b74..3e2b9d15 100644 --- a/bungeecord/src/main/java/me/william278/crossserversync/CrossServerSyncBungeeCord.java +++ b/bungeecord/src/main/java/me/william278/husksync/HuskSyncBungeeCord.java @@ -1,24 +1,24 @@ -package me.william278.crossserversync; - -import me.william278.crossserversync.bungeecord.command.CrossServerSyncCommand; -import me.william278.crossserversync.bungeecord.config.ConfigLoader; -import me.william278.crossserversync.bungeecord.config.ConfigManager; -import me.william278.crossserversync.bungeecord.data.DataManager; -import me.william278.crossserversync.bungeecord.data.sql.Database; -import me.william278.crossserversync.bungeecord.data.sql.MySQL; -import me.william278.crossserversync.bungeecord.data.sql.SQLite; -import me.william278.crossserversync.bungeecord.listener.BungeeEventListener; -import me.william278.crossserversync.bungeecord.listener.BungeeRedisListener; +package me.william278.husksync; + +import me.william278.husksync.bungeecord.command.HuskSyncCommand; +import me.william278.husksync.bungeecord.config.ConfigLoader; +import me.william278.husksync.bungeecord.config.ConfigManager; +import me.william278.husksync.bungeecord.data.DataManager; +import me.william278.husksync.bungeecord.data.sql.Database; +import me.william278.husksync.bungeecord.data.sql.MySQL; +import me.william278.husksync.bungeecord.data.sql.SQLite; +import me.william278.husksync.bungeecord.listener.BungeeEventListener; +import me.william278.husksync.bungeecord.listener.BungeeRedisListener; import net.md_5.bungee.api.plugin.Plugin; import java.sql.Connection; import java.sql.SQLException; import java.util.Objects; -public final class CrossServerSyncBungeeCord extends Plugin { +public final class HuskSyncBungeeCord extends Plugin { - private static CrossServerSyncBungeeCord instance; - public static CrossServerSyncBungeeCord getInstance() { + private static HuskSyncBungeeCord instance; + public static HuskSyncBungeeCord getInstance() { return instance; } @@ -56,13 +56,13 @@ public final class CrossServerSyncBungeeCord extends Plugin { getProxy().getPluginManager().registerListener(this, new BungeeEventListener()); // Register command - getProxy().getPluginManager().registerCommand(this, new CrossServerSyncCommand()); + getProxy().getPluginManager().registerCommand(this, new HuskSyncCommand()); // Initialize the redis listener new BungeeRedisListener(); // Log to console - getLogger().info("Enabled CrossServerSync (" + getProxy().getName() + ") v" + getDescription().getVersion()); + getLogger().info("Enabled HuskSync (" + getProxy().getName() + ") v" + getDescription().getVersion()); } @Override @@ -73,6 +73,6 @@ public final class CrossServerSyncBungeeCord extends Plugin { database.close(); // Log to console - getLogger().info("Disabled CrossServerSync (" + getProxy().getName() + ") v" + getDescription().getVersion()); + getLogger().info("Disabled HuskSync (" + getProxy().getName() + ") v" + getDescription().getVersion()); } } diff --git a/bungeecord/src/main/java/me/william278/crossserversync/bungeecord/command/CrossServerSyncCommand.java b/bungeecord/src/main/java/me/william278/husksync/bungeecord/command/HuskSyncCommand.java similarity index 74% rename from bungeecord/src/main/java/me/william278/crossserversync/bungeecord/command/CrossServerSyncCommand.java rename to bungeecord/src/main/java/me/william278/husksync/bungeecord/command/HuskSyncCommand.java index cb8786e6..253d7a84 100644 --- a/bungeecord/src/main/java/me/william278/crossserversync/bungeecord/command/CrossServerSyncCommand.java +++ b/bungeecord/src/main/java/me/william278/husksync/bungeecord/command/HuskSyncCommand.java @@ -1,10 +1,10 @@ -package me.william278.crossserversync.bungeecord.command; +package me.william278.husksync.bungeecord.command; import de.themoep.minedown.MineDown; -import me.william278.crossserversync.CrossServerSyncBungeeCord; -import me.william278.crossserversync.MessageStrings; -import me.william278.crossserversync.Settings; -import me.william278.crossserversync.redis.RedisMessage; +import me.william278.husksync.HuskSyncBungeeCord; +import me.william278.husksync.MessageStrings; +import me.william278.husksync.Settings; +import me.william278.husksync.redis.RedisMessage; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.plugin.Command; @@ -17,14 +17,14 @@ import java.util.Locale; import java.util.logging.Level; import java.util.stream.Collectors; -public class CrossServerSyncCommand extends Command implements TabExecutor { +public class HuskSyncCommand extends Command implements TabExecutor { - private final static CrossServerSyncBungeeCord plugin = CrossServerSyncBungeeCord.getInstance(); + private final static HuskSyncBungeeCord plugin = HuskSyncBungeeCord.getInstance(); private final static String[] COMMAND_TAB_ARGUMENTS = {"about", "reload"}; - private final static String PERMISSION = "crossserversync.command.csc"; + private final static String PERMISSION = "husksync.command.csc"; - //public CrossServerSyncCommand() { super("csc", PERMISSION, "crossserversync"); } - public CrossServerSyncCommand() { super("csc"); } + //public HuskSyncCommand() { super("husksync", PERMISSION, "hs"); } + public HuskSyncCommand() { super("husksync"); } @Override public void execute(CommandSender sender, String[] args) { @@ -47,7 +47,7 @@ public class CrossServerSyncCommand extends Command implements TabExecutor { */ private void sendAboutInformation(ProxiedPlayer player) { try { - new RedisMessage(RedisMessage.MessageType.SEND_PLUGIN_INFORMATION, + new me.william278.husksync.redis.RedisMessage(me.william278.husksync.redis.RedisMessage.MessageType.SEND_PLUGIN_INFORMATION, new RedisMessage.MessageTarget(Settings.ServerType.BUKKIT, player.getUniqueId()), plugin.getProxy().getName(), plugin.getDescription().getVersion()).send(); } catch (IOException e) { diff --git a/bungeecord/src/main/java/me/william278/crossserversync/bungeecord/config/ConfigLoader.java b/bungeecord/src/main/java/me/william278/husksync/bungeecord/config/ConfigLoader.java similarity index 81% rename from bungeecord/src/main/java/me/william278/crossserversync/bungeecord/config/ConfigLoader.java rename to bungeecord/src/main/java/me/william278/husksync/bungeecord/config/ConfigLoader.java index 78d44693..4e3f97c0 100644 --- a/bungeecord/src/main/java/me/william278/crossserversync/bungeecord/config/ConfigLoader.java +++ b/bungeecord/src/main/java/me/william278/husksync/bungeecord/config/ConfigLoader.java @@ -1,6 +1,6 @@ -package me.william278.crossserversync.bungeecord.config; +package me.william278.husksync.bungeecord.config; -import me.william278.crossserversync.Settings; +import me.william278.husksync.Settings; import net.md_5.bungee.config.Configuration; public class ConfigLoader { @@ -15,16 +15,16 @@ public class ConfigLoader { if (Settings.dataStorageType == Settings.DataStorageType.MYSQL) { Settings.mySQLHost = config.getString("data_storage_settings.mysql_settings.host", "localhost"); Settings.mySQLPort = config.getInt("data_storage_settings.mysql_settings.port", 8123); - Settings.mySQLDatabase = config.getString("data_storage_settings.mysql_settings.database", "CrossServerSync"); - Settings.mySQLUsername = config.getString("data_storage_settings.mysql_settings.username", "CrossServerSync"); - Settings.mySQLPassword = config.getString("data_storage_settings.mysql_settings.password", "CrossServerSync"); - Settings.mySQLParams = config.getString("data_storage_settings.mysql_settings.params", "CrossServerSync"); + Settings.mySQLDatabase = config.getString("data_storage_settings.mysql_settings.database", "HuskSync"); + Settings.mySQLUsername = config.getString("data_storage_settings.mysql_settings.username", "root"); + Settings.mySQLPassword = config.getString("data_storage_settings.mysql_settings.password", "pa55w0rd"); + Settings.mySQLParams = config.getString("data_storage_settings.mysql_settings.params", "?autoReconnect=true&useSSL=false"); } Settings.hikariMaximumPoolSize = config.getInt("data_storage_settings.hikari_pool_settings.maximum_pool_size", 10); Settings.hikariMinimumIdle = config.getInt("data_storage_settings.hikari_pool_settings.minimum_idle", 10); Settings.hikariMaximumLifetime = config.getLong("data_storage_settings.hikari_pool_settings.maximum_lifetime", 1800000); - Settings.hikariKeepAliveTime = config.getLong("data_storage_settings.hikari_pool_settings.keepalive_time", 10); + Settings.hikariKeepAliveTime = config.getLong("data_storage_settings.hikari_pool_settings.keepalive_time", 0); Settings.hikariConnectionTimeOut = config.getLong("data_storage_settings.hikari_pool_settings.connection_timeout", 5000); } diff --git a/bungeecord/src/main/java/me/william278/crossserversync/bungeecord/config/ConfigManager.java b/bungeecord/src/main/java/me/william278/husksync/bungeecord/config/ConfigManager.java similarity index 76% rename from bungeecord/src/main/java/me/william278/crossserversync/bungeecord/config/ConfigManager.java rename to bungeecord/src/main/java/me/william278/husksync/bungeecord/config/ConfigManager.java index 6fd4699c..93fdfef1 100644 --- a/bungeecord/src/main/java/me/william278/crossserversync/bungeecord/config/ConfigManager.java +++ b/bungeecord/src/main/java/me/william278/husksync/bungeecord/config/ConfigManager.java @@ -1,6 +1,6 @@ -package me.william278.crossserversync.bungeecord.config; +package me.william278.husksync.bungeecord.config; -import me.william278.crossserversync.CrossServerSyncBungeeCord; +import me.william278.husksync.HuskSyncBungeeCord; import net.md_5.bungee.config.Configuration; import net.md_5.bungee.config.ConfigurationProvider; import net.md_5.bungee.config.YamlConfiguration; @@ -12,19 +12,19 @@ import java.util.logging.Level; public class ConfigManager { - private static final CrossServerSyncBungeeCord plugin = CrossServerSyncBungeeCord.getInstance(); + private static final HuskSyncBungeeCord plugin = HuskSyncBungeeCord.getInstance(); public static void loadConfig() { try { if (!plugin.getDataFolder().exists()) { if (plugin.getDataFolder().mkdir()) { - plugin.getLogger().info("Created CrossServerSync data folder"); + plugin.getLogger().info("Created HuskSync data folder"); } } File configFile = new File(plugin.getDataFolder(), "config.yml"); if (!configFile.exists()) { Files.copy(plugin.getResourceAsStream("bungee-config.yml"), configFile.toPath()); - plugin.getLogger().info("Created CrossServerSync bungee-config.yml file"); + plugin.getLogger().info("Created HuskSync bungee-config.yml file"); } } catch (Exception e) { plugin.getLogger().log(Level.CONFIG, "An exception occurred loading the configuration file", e); diff --git a/bungeecord/src/main/java/me/william278/crossserversync/bungeecord/data/DataManager.java b/bungeecord/src/main/java/me/william278/husksync/bungeecord/data/DataManager.java similarity index 93% rename from bungeecord/src/main/java/me/william278/crossserversync/bungeecord/data/DataManager.java rename to bungeecord/src/main/java/me/william278/husksync/bungeecord/data/DataManager.java index 10c18628..468a7b99 100644 --- a/bungeecord/src/main/java/me/william278/crossserversync/bungeecord/data/DataManager.java +++ b/bungeecord/src/main/java/me/william278/husksync/bungeecord/data/DataManager.java @@ -1,8 +1,8 @@ -package me.william278.crossserversync.bungeecord.data; +package me.william278.husksync.bungeecord.data; -import me.william278.crossserversync.PlayerData; -import me.william278.crossserversync.CrossServerSyncBungeeCord; -import me.william278.crossserversync.bungeecord.data.sql.Database; +import me.william278.husksync.PlayerData; +import me.william278.husksync.HuskSyncBungeeCord; +import me.william278.husksync.bungeecord.data.sql.Database; import java.sql.*; import java.time.Instant; @@ -12,7 +12,7 @@ import java.util.logging.Level; public class DataManager { - private static final CrossServerSyncBungeeCord plugin = CrossServerSyncBungeeCord.getInstance(); + private static final HuskSyncBungeeCord plugin = HuskSyncBungeeCord.getInstance(); public static PlayerDataCache playerDataCache; /** @@ -33,7 +33,7 @@ public class DataManager { * @return {@code true} if the player is on the player table */ private static boolean playerExists(UUID playerUUID) { - try (Connection connection = CrossServerSyncBungeeCord.getConnection()) { + try (Connection connection = HuskSyncBungeeCord.getConnection()) { try (PreparedStatement statement = connection.prepareStatement( "SELECT * FROM " + Database.PLAYER_TABLE_NAME + " WHERE `uuid`=?;")) { statement.setString(1, playerUUID.toString()); @@ -47,7 +47,7 @@ public class DataManager { } private static void createPlayerEntry(UUID playerUUID) { - try (Connection connection = CrossServerSyncBungeeCord.getConnection()) { + try (Connection connection = HuskSyncBungeeCord.getConnection()) { try (PreparedStatement statement = connection.prepareStatement( "INSERT INTO " + Database.PLAYER_TABLE_NAME + " (`uuid`) VALUES(?);")) { statement.setString(1, playerUUID.toString()); @@ -59,7 +59,7 @@ public class DataManager { } public static PlayerData getPlayerData(UUID playerUUID) { - try (Connection connection = CrossServerSyncBungeeCord.getConnection()) { + try (Connection connection = HuskSyncBungeeCord.getConnection()) { try (PreparedStatement statement = connection.prepareStatement( "SELECT * FROM " + Database.DATA_TABLE_NAME + " WHERE `player_id`=(SELECT `id` FROM " + Database.PLAYER_TABLE_NAME + " WHERE `uuid`=?);")) { statement.setString(1, playerUUID.toString()); @@ -115,7 +115,7 @@ public class DataManager { } private static void updatePlayerSQLData(PlayerData playerData) { - try (Connection connection = CrossServerSyncBungeeCord.getConnection()) { + try (Connection connection = HuskSyncBungeeCord.getConnection()) { try (PreparedStatement statement = connection.prepareStatement( "UPDATE " + Database.DATA_TABLE_NAME + " SET `version_uuid`=?, `timestamp`=?, `inventory`=?, `ender_chest`=?, `health`=?, `max_health`=?, `hunger`=?, `saturation`=?, `saturation_exhaustion`=?, `selected_slot`=?, `status_effects`=?, `total_experience`=?, `exp_level`=?, `exp_progress`=?, `game_mode`=?, `statistics`=?, `is_flying`=?, `advancements`=?, `location`=? WHERE `player_id`=(SELECT `id` FROM " + Database.PLAYER_TABLE_NAME + " WHERE `uuid`=?);")) { statement.setString(1, playerData.getDataVersionUUID().toString()); @@ -147,7 +147,7 @@ public class DataManager { } private static void insertPlayerData(PlayerData playerData) { - try (Connection connection = CrossServerSyncBungeeCord.getConnection()) { + try (Connection connection = HuskSyncBungeeCord.getConnection()) { try (PreparedStatement statement = connection.prepareStatement( "INSERT INTO " + Database.DATA_TABLE_NAME + " (`player_id`,`version_uuid`,`timestamp`,`inventory`,`ender_chest`,`health`,`max_health`,`hunger`,`saturation`,`saturation_exhaustion`,`selected_slot`,`status_effects`,`total_experience`,`exp_level`,`exp_progress`,`game_mode`,`statistics`,`is_flying`,`advancements`,`location`) VALUES((SELECT `id` FROM " + Database.PLAYER_TABLE_NAME + " WHERE `uuid`=?),?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);")) { statement.setString(1, playerData.getPlayerUUID().toString()); @@ -185,7 +185,7 @@ public class DataManager { * @return {@code true} if the player has an entry in the data table */ private static boolean playerHasCachedData(UUID playerUUID) { - try (Connection connection = CrossServerSyncBungeeCord.getConnection()) { + try (Connection connection = HuskSyncBungeeCord.getConnection()) { try (PreparedStatement statement = connection.prepareStatement( "SELECT * FROM " + Database.DATA_TABLE_NAME + " WHERE `player_id`=(SELECT `id` FROM " + Database.PLAYER_TABLE_NAME + " WHERE `uuid`=?);")) { statement.setString(1, playerUUID.toString()); diff --git a/bungeecord/src/main/java/me/william278/husksync/bungeecord/data/sql/Database.java b/bungeecord/src/main/java/me/william278/husksync/bungeecord/data/sql/Database.java new file mode 100644 index 00000000..dee32de3 --- /dev/null +++ b/bungeecord/src/main/java/me/william278/husksync/bungeecord/data/sql/Database.java @@ -0,0 +1,33 @@ +package me.william278.husksync.bungeecord.data.sql; + +import me.william278.husksync.HuskSyncBungeeCord; +import me.william278.husksync.Settings; + +import java.sql.Connection; +import java.sql.SQLException; + +public abstract class Database { + protected HuskSyncBungeeCord plugin; + + public final static String DATA_POOL_NAME = "HuskSyncHikariPool"; + public final static String PLAYER_TABLE_NAME = "husksync_players"; + public final static String DATA_TABLE_NAME = "husksync_data"; + + public Database(HuskSyncBungeeCord instance) { + plugin = instance; + } + + public abstract Connection getConnection() throws SQLException; + + public abstract void load(); + + public abstract void backup(); + + public abstract void close(); + + public final int hikariMaximumPoolSize = me.william278.husksync.Settings.hikariMaximumPoolSize; + public final int hikariMinimumIdle = me.william278.husksync.Settings.hikariMinimumIdle; + public final long hikariMaximumLifetime = me.william278.husksync.Settings.hikariMaximumLifetime; + public final long hikariKeepAliveTime = me.william278.husksync.Settings.hikariKeepAliveTime; + public final long hikariConnectionTimeOut = Settings.hikariConnectionTimeOut; +} diff --git a/bungeecord/src/main/java/me/william278/crossserversync/bungeecord/data/sql/MySQL.java b/bungeecord/src/main/java/me/william278/husksync/bungeecord/data/sql/MySQL.java similarity index 87% rename from bungeecord/src/main/java/me/william278/crossserversync/bungeecord/data/sql/MySQL.java rename to bungeecord/src/main/java/me/william278/husksync/bungeecord/data/sql/MySQL.java index fcaff361..f52fdb55 100644 --- a/bungeecord/src/main/java/me/william278/crossserversync/bungeecord/data/sql/MySQL.java +++ b/bungeecord/src/main/java/me/william278/husksync/bungeecord/data/sql/MySQL.java @@ -1,8 +1,8 @@ -package me.william278.crossserversync.bungeecord.data.sql; +package me.william278.husksync.bungeecord.data.sql; import com.zaxxer.hikari.HikariDataSource; -import me.william278.crossserversync.Settings; -import me.william278.crossserversync.CrossServerSyncBungeeCord; +import me.william278.husksync.HuskSyncBungeeCord; +import me.william278.husksync.Settings; import java.sql.Connection; import java.sql.SQLException; @@ -47,16 +47,16 @@ public class MySQL extends Database { }; - final String host = Settings.mySQLHost; - final int port = Settings.mySQLPort; - final String database = Settings.mySQLDatabase; - final String username = Settings.mySQLUsername; - final String password = Settings.mySQLPassword; + final String host = me.william278.husksync.Settings.mySQLHost; + final int port = me.william278.husksync.Settings.mySQLPort; + final String database = me.william278.husksync.Settings.mySQLDatabase; + final String username = me.william278.husksync.Settings.mySQLUsername; + final String password = me.william278.husksync.Settings.mySQLPassword; final String params = Settings.mySQLParams; private HikariDataSource dataSource; - public MySQL(CrossServerSyncBungeeCord instance) { + public MySQL(HuskSyncBungeeCord instance) { super(instance); } diff --git a/bungeecord/src/main/java/me/william278/crossserversync/bungeecord/data/sql/SQLite.java b/bungeecord/src/main/java/me/william278/husksync/bungeecord/data/sql/SQLite.java similarity index 95% rename from bungeecord/src/main/java/me/william278/crossserversync/bungeecord/data/sql/SQLite.java rename to bungeecord/src/main/java/me/william278/husksync/bungeecord/data/sql/SQLite.java index 3beff88c..6f49029d 100644 --- a/bungeecord/src/main/java/me/william278/crossserversync/bungeecord/data/sql/SQLite.java +++ b/bungeecord/src/main/java/me/william278/husksync/bungeecord/data/sql/SQLite.java @@ -1,7 +1,7 @@ -package me.william278.crossserversync.bungeecord.data.sql; +package me.william278.husksync.bungeecord.data.sql; import com.zaxxer.hikari.HikariDataSource; -import me.william278.crossserversync.CrossServerSyncBungeeCord; +import me.william278.husksync.HuskSyncBungeeCord; import java.io.File; import java.io.IOException; @@ -53,11 +53,11 @@ public class SQLite extends Database { ");" }; - private static final String DATABASE_NAME = "CrossServerSyncData"; + private static final String DATABASE_NAME = "HuskSyncData"; private HikariDataSource dataSource; - public SQLite(CrossServerSyncBungeeCord instance) { + public SQLite(HuskSyncBungeeCord instance) { super(instance); } @@ -127,7 +127,7 @@ public class SQLite extends Database { .format(Instant.now()).replaceAll(" ", "-") + ".db"; final File databaseFile = new File(plugin.getDataFolder(), DATABASE_NAME + ".db"); if (new File(plugin.getDataFolder(), BACKUPS_FOLDER_NAME).mkdirs()) { - plugin.getLogger().info("Created backups directory in CrossServerSync plugin data folder."); + plugin.getLogger().info("Created backups directory in HuskSync plugin data folder."); } final File backUpFile = new File(plugin.getDataFolder(), BACKUPS_FOLDER_NAME + File.separator + backupFileName); try { diff --git a/bungeecord/src/main/java/me/william278/crossserversync/bungeecord/listener/BungeeEventListener.java b/bungeecord/src/main/java/me/william278/husksync/bungeecord/listener/BungeeEventListener.java similarity index 68% rename from bungeecord/src/main/java/me/william278/crossserversync/bungeecord/listener/BungeeEventListener.java rename to bungeecord/src/main/java/me/william278/husksync/bungeecord/listener/BungeeEventListener.java index 060f6e11..56b24afe 100644 --- a/bungeecord/src/main/java/me/william278/crossserversync/bungeecord/listener/BungeeEventListener.java +++ b/bungeecord/src/main/java/me/william278/husksync/bungeecord/listener/BungeeEventListener.java @@ -1,10 +1,10 @@ -package me.william278.crossserversync.bungeecord.listener; +package me.william278.husksync.bungeecord.listener; -import me.william278.crossserversync.CrossServerSyncBungeeCord; -import me.william278.crossserversync.PlayerData; -import me.william278.crossserversync.Settings; -import me.william278.crossserversync.bungeecord.data.DataManager; -import me.william278.crossserversync.redis.RedisMessage; +import me.william278.husksync.HuskSyncBungeeCord; +import me.william278.husksync.PlayerData; +import me.william278.husksync.bungeecord.data.DataManager; +import me.william278.husksync.Settings; +import me.william278.husksync.redis.RedisMessage; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.PostLoginEvent; @@ -16,7 +16,7 @@ import java.util.logging.Level; public class BungeeEventListener implements Listener { - private static final CrossServerSyncBungeeCord plugin = CrossServerSyncBungeeCord.getInstance(); + private static final HuskSyncBungeeCord plugin = HuskSyncBungeeCord.getInstance(); @EventHandler public void onPostLogin(PostLoginEvent event) { @@ -33,8 +33,8 @@ public class BungeeEventListener implements Listener { // Send a message asking the bukkit to request data on join try { - new RedisMessage(RedisMessage.MessageType.REQUEST_DATA_ON_JOIN, - new RedisMessage.MessageTarget(Settings.ServerType.BUKKIT, null), + new me.william278.husksync.redis.RedisMessage(me.william278.husksync.redis.RedisMessage.MessageType.REQUEST_DATA_ON_JOIN, + new me.william278.husksync.redis.RedisMessage.MessageTarget(Settings.ServerType.BUKKIT, null), RedisMessage.RequestOnJoinUpdateType.ADD_REQUESTER.toString(), player.getUniqueId().toString()).send(); } catch (IOException e) { plugin.getLogger().log(Level.SEVERE, "Failed to serialize request data on join message data"); diff --git a/bungeecord/src/main/java/me/william278/crossserversync/bungeecord/listener/BungeeRedisListener.java b/bungeecord/src/main/java/me/william278/husksync/bungeecord/listener/BungeeRedisListener.java similarity index 62% rename from bungeecord/src/main/java/me/william278/crossserversync/bungeecord/listener/BungeeRedisListener.java rename to bungeecord/src/main/java/me/william278/husksync/bungeecord/listener/BungeeRedisListener.java index b71fe538..4c0c1102 100644 --- a/bungeecord/src/main/java/me/william278/crossserversync/bungeecord/listener/BungeeRedisListener.java +++ b/bungeecord/src/main/java/me/william278/husksync/bungeecord/listener/BungeeRedisListener.java @@ -1,11 +1,11 @@ -package me.william278.crossserversync.bungeecord.listener; +package me.william278.husksync.bungeecord.listener; -import me.william278.crossserversync.CrossServerSyncBungeeCord; -import me.william278.crossserversync.PlayerData; -import me.william278.crossserversync.Settings; -import me.william278.crossserversync.bungeecord.data.DataManager; -import me.william278.crossserversync.redis.RedisListener; -import me.william278.crossserversync.redis.RedisMessage; +import me.william278.husksync.HuskSyncBungeeCord; +import me.william278.husksync.PlayerData; +import me.william278.husksync.bungeecord.data.DataManager; +import me.william278.husksync.redis.RedisListener; +import me.william278.husksync.Settings; +import me.william278.husksync.redis.RedisMessage; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -15,7 +15,7 @@ import java.util.logging.Level; public class BungeeRedisListener extends RedisListener { - private static final CrossServerSyncBungeeCord plugin = CrossServerSyncBungeeCord.getInstance(); + private static final HuskSyncBungeeCord plugin = HuskSyncBungeeCord.getInstance(); // Initialize the listener on the bungee public BungeeRedisListener() { @@ -38,14 +38,14 @@ public class BungeeRedisListener extends RedisListener { } /** - * Handle an incoming {@link RedisMessage} + * Handle an incoming {@link me.william278.husksync.redis.RedisMessage} * - * @param message The {@link RedisMessage} to handle + * @param message The {@link me.william278.husksync.redis.RedisMessage} to handle */ @Override - public void handleMessage(RedisMessage message) { + public void handleMessage(me.william278.husksync.redis.RedisMessage message) { // Ignore messages destined for Bukkit servers - if (message.getMessageTarget().targetServerType() != Settings.ServerType.BUNGEECORD) { + if (message.getMessageTarget().targetServerType() != me.william278.husksync.Settings.ServerType.BUNGEECORD) { return; } @@ -56,15 +56,15 @@ public class BungeeRedisListener extends RedisListener { ProxyServer.getInstance().getScheduler().runAsync(plugin, () -> { try { // Send the reply, serializing the message data - new RedisMessage(RedisMessage.MessageType.PLAYER_DATA_SET, - new RedisMessage.MessageTarget(Settings.ServerType.BUKKIT, requestingPlayerUUID), - RedisMessage.serialize(getPlayerCachedData(requestingPlayerUUID))) + new me.william278.husksync.redis.RedisMessage(me.william278.husksync.redis.RedisMessage.MessageType.PLAYER_DATA_SET, + new me.william278.husksync.redis.RedisMessage.MessageTarget(me.william278.husksync.Settings.ServerType.BUKKIT, requestingPlayerUUID), + me.william278.husksync.redis.RedisMessage.serialize(getPlayerCachedData(requestingPlayerUUID))) .send(); // Send an update to all bukkit servers removing the player from the requester cache - new RedisMessage(RedisMessage.MessageType.REQUEST_DATA_ON_JOIN, - new RedisMessage.MessageTarget(Settings.ServerType.BUKKIT, null), - RedisMessage.RequestOnJoinUpdateType.REMOVE_REQUESTER.toString(), requestingPlayerUUID.toString()) + new me.william278.husksync.redis.RedisMessage(me.william278.husksync.redis.RedisMessage.MessageType.REQUEST_DATA_ON_JOIN, + new me.william278.husksync.redis.RedisMessage.MessageTarget(me.william278.husksync.Settings.ServerType.BUKKIT, null), + me.william278.husksync.redis.RedisMessage.RequestOnJoinUpdateType.REMOVE_REQUESTER.toString(), requestingPlayerUUID.toString()) .send(); } catch (IOException e) { log(Level.SEVERE, "Failed to serialize data when replying to a data request"); @@ -77,7 +77,7 @@ public class BungeeRedisListener extends RedisListener { PlayerData playerData; final String serializedPlayerData = message.getMessageData(); try { - playerData = (PlayerData) RedisMessage.deserialize(serializedPlayerData); + playerData = (PlayerData) me.william278.husksync.redis.RedisMessage.deserialize(serializedPlayerData); } catch (IOException | ClassNotFoundException e) { log(Level.SEVERE, "Failed to deserialize PlayerData when handling a player update request"); e.printStackTrace(); @@ -92,8 +92,8 @@ public class BungeeRedisListener extends RedisListener { ProxiedPlayer player = ProxyServer.getInstance().getPlayer(playerData.getPlayerUUID()); if (player != null) { if (player.isConnected()) { - new RedisMessage(RedisMessage.MessageType.PLAYER_DATA_SET, - new RedisMessage.MessageTarget(Settings.ServerType.BUKKIT, playerData.getPlayerUUID()), + new me.william278.husksync.redis.RedisMessage(me.william278.husksync.redis.RedisMessage.MessageType.PLAYER_DATA_SET, + new me.william278.husksync.redis.RedisMessage.MessageTarget(Settings.ServerType.BUKKIT, playerData.getPlayerUUID()), RedisMessage.serialize(playerData)) .send(); } diff --git a/bungeecord/src/main/resources/bungee-config.yml b/bungeecord/src/main/resources/bungee-config.yml index 7914c84c..65c90bf9 100644 --- a/bungeecord/src/main/resources/bungee-config.yml +++ b/bungeecord/src/main/resources/bungee-config.yml @@ -7,10 +7,10 @@ data_storage_settings: mysql_settings: host: 'localhost' port: 8123 - database: 'CrossServerSync' + database: 'HuskSync' username: 'root' password: 'pa55w0rd' - params: '' + params: '?autoReconnect=true&useSSL=false' hikari_pool_settings: maximum_pool_size: 10 minimum_idle: 10 diff --git a/common/build.gradle b/common/build.gradle index 60216299..5951d822 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -26,5 +26,5 @@ shadowJar { exclude "module-info.class" // Relocations - relocate 'redis.clients', 'me.William278.crossserversync.libraries.jedis' + relocate 'redis.clients', 'me.William278.husksync.libraries.jedis' } \ No newline at end of file diff --git a/common/src/main/java/me/william278/crossserversync/MessageStrings.java b/common/src/main/java/me/william278/husksync/MessageStrings.java similarity index 77% rename from common/src/main/java/me/william278/crossserversync/MessageStrings.java rename to common/src/main/java/me/william278/husksync/MessageStrings.java index b8d4d1d5..c91d9aa3 100644 --- a/common/src/main/java/me/william278/crossserversync/MessageStrings.java +++ b/common/src/main/java/me/william278/husksync/MessageStrings.java @@ -1,12 +1,12 @@ -package me.william278.crossserversync; +package me.william278.husksync; public class MessageStrings { - public static final StringBuilder PLUGIN_INFORMATION = new StringBuilder().append("[CrossServerSync](#00fb9a bold) [| %proxy_brand% Version %proxy_version% (%bukkit_brand% v%bukkit_version%)](#00fb9a)\n") + public static final StringBuilder PLUGIN_INFORMATION = new StringBuilder().append("[HuskSync](#00fb9a bold) [| %proxy_brand% Version %proxy_version% (%bukkit_brand% v%bukkit_version%)](#00fb9a)\n") .append("[%plugin_description%](gray)\n") .append("[• Author:](white) [William278](gray show_text=&7Click to pay a visit open_url=https://youtube.com/William27528)\n") - .append("[• Help Wiki:](white) [[Link]](#00fb9a show_text=&7Click to open link open_url=https://github.com/WiIIiam278/CrossServerSync/wiki/)\n") - .append("[• Report Issues:](white) [[Link]](#00fb9a show_text=&7Click to open link open_url=https://github.com/WiIIiam278/CrossServerSync/issues)\n") + .append("[• Help Wiki:](white) [[Link]](#00fb9a show_text=&7Click to open link open_url=https://github.com/WiIIiam278/HuskSync/wiki/)\n") + .append("[• Report Issues:](white) [[Link]](#00fb9a show_text=&7Click to open link open_url=https://github.com/WiIIiam278/HuskSync/issues)\n") .append("[• Support Discord:](white) [[Link]](#00fb9a show_text=&7Click to join open_url=https://discord.gg/tVYhJfyDWG)"); public static final String ERROR_INVALID_SYNTAX = "[Error:](#ff3300) [Incorrect syntax. Usage: %1%](#ff7e5e)"; diff --git a/common/src/main/java/me/william278/crossserversync/PlayerData.java b/common/src/main/java/me/william278/husksync/PlayerData.java similarity index 99% rename from common/src/main/java/me/william278/crossserversync/PlayerData.java rename to common/src/main/java/me/william278/husksync/PlayerData.java index 7948b3db..8360bebb 100644 --- a/common/src/main/java/me/william278/crossserversync/PlayerData.java +++ b/common/src/main/java/me/william278/husksync/PlayerData.java @@ -1,4 +1,4 @@ -package me.william278.crossserversync; +package me.william278.husksync; import java.io.*; import java.util.UUID; diff --git a/common/src/main/java/me/william278/crossserversync/Settings.java b/common/src/main/java/me/william278/husksync/Settings.java similarity index 92% rename from common/src/main/java/me/william278/crossserversync/Settings.java rename to common/src/main/java/me/william278/husksync/Settings.java index 64c6914e..3780d82a 100644 --- a/common/src/main/java/me/william278/crossserversync/Settings.java +++ b/common/src/main/java/me/william278/husksync/Settings.java @@ -1,5 +1,8 @@ -package me.william278.crossserversync; +package me.william278.husksync; +/** + * Settings class, holds values loaded from the plugin config (either Bukkit or Bungee) + */ public class Settings { /* diff --git a/common/src/main/java/me/william278/crossserversync/redis/RedisListener.java b/common/src/main/java/me/william278/husksync/redis/RedisListener.java similarity index 91% rename from common/src/main/java/me/william278/crossserversync/redis/RedisListener.java rename to common/src/main/java/me/william278/husksync/redis/RedisListener.java index 3ae2ebcb..79f77543 100644 --- a/common/src/main/java/me/william278/crossserversync/redis/RedisListener.java +++ b/common/src/main/java/me/william278/husksync/redis/RedisListener.java @@ -1,6 +1,6 @@ -package me.william278.crossserversync.redis; +package me.william278.husksync.redis; -import me.william278.crossserversync.Settings; +import me.william278.husksync.Settings; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPubSub; @@ -37,7 +37,7 @@ public abstract class RedisListener { new Thread(() -> jedis.subscribe(new JedisPubSub() { @Override public void onMessage(String channel, String message) { - // Only accept messages to the CrossServerSync channel + // Only accept messages to the HuskSync channel if (!channel.equals(RedisMessage.REDIS_CHANNEL)) { return; } diff --git a/common/src/main/java/me/william278/crossserversync/redis/RedisMessage.java b/common/src/main/java/me/william278/husksync/redis/RedisMessage.java similarity index 96% rename from common/src/main/java/me/william278/crossserversync/redis/RedisMessage.java rename to common/src/main/java/me/william278/husksync/redis/RedisMessage.java index 177129f5..d61704a8 100644 --- a/common/src/main/java/me/william278/crossserversync/redis/RedisMessage.java +++ b/common/src/main/java/me/william278/husksync/redis/RedisMessage.java @@ -1,7 +1,7 @@ -package me.william278.crossserversync.redis; +package me.william278.husksync.redis; -import me.william278.crossserversync.PlayerData; -import me.william278.crossserversync.Settings; +import me.william278.husksync.PlayerData; +import me.william278.husksync.Settings; import redis.clients.jedis.Jedis; import java.io.*; @@ -11,7 +11,7 @@ import java.util.UUID; public class RedisMessage { - public static String REDIS_CHANNEL = "CrossServerSync"; + public static String REDIS_CHANNEL = "HuskSync"; public static String MESSAGE_META_SEPARATOR = "♦"; public static String MESSAGE_DATA_SEPARATOR = "♣"; diff --git a/common/src/main/resources/bungee.yml b/common/src/main/resources/bungee.yml index 19a9f6a6..673ea597 100644 --- a/common/src/main/resources/bungee.yml +++ b/common/src/main/resources/bungee.yml @@ -1,6 +1,6 @@ -name: CrossServerSync +name: HuskSync version: @version@ -main: me.william278.crossserversync.CrossServerSyncBungeeCord +main: me.william278.husksync.HuskSyncBungeeCord author: William278 description: 'Synchronize data cross-server' libraries: diff --git a/common/src/main/resources/plugin.yml b/common/src/main/resources/plugin.yml index 323a6434..e533b94c 100644 --- a/common/src/main/resources/plugin.yml +++ b/common/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: CrossServerSync version: @version@ -main: me.william278.crossserversync.CrossServerSyncBukkit +main: me.william278.husksync.HuskSyncBukkit api-version: 1.16 author: William278 description: 'Synchronize data cross-server' \ No newline at end of file diff --git a/plugin/build.gradle b/plugin/build.gradle index bbe15b4c..c4998acd 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -6,7 +6,7 @@ dependencies { shadowJar { destinationDirectory.set(file("$rootDir/target/")) - archiveBaseName.set('CrossServerSync') + archiveBaseName.set('HuskSync') archiveClassifier.set('') build { @@ -18,7 +18,7 @@ publishing { publications { mavenJava(MavenPublication) { groupId = 'me.William278' - artifactId = 'CrossServerSync-plugin' + artifactId = 'HuskSync-plugin' version = "$project.version" artifact shadowJar diff --git a/settings.gradle b/settings.gradle index b0b434fd..f3ebae97 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,7 +4,7 @@ pluginManagement { } } -rootProject.name = 'CrossServerSync' +rootProject.name = 'HuskSync' include 'common' include 'bukkit'