From ea9344d2a59befd5e7d055ca8edabe1f6abea0d1 Mon Sep 17 00:00:00 2001 From: FireInstall Date: Mon, 6 May 2024 00:05:54 +0200 Subject: [PATCH] Code clean update to getFirst get uuid via non deprecated method consistent line continuation indentation add some javaDoc --- .../java/de/minebench/syncinv/SyncInv.java | 64 ++++++++++------- ...PlayerConnectionValidateLoginListener.java | 6 +- .../listeners/PlayerFreezeListener.java | 24 +++---- .../syncinv/listeners/PlayerJoinListener.java | 1 - .../syncinv/listeners/PlayerQuitListener.java | 3 +- .../minebench/syncinv/messenger/Message.java | 28 ++++---- .../syncinv/messenger/PlayerDataQuery.java | 16 ++++- .../syncinv/messenger/RedisMessenger.java | 9 ++- .../syncinv/messenger/ServerMessenger.java | 71 +++++++++++-------- .../messenger/VersionMismatchException.java | 6 ++ src/main/resources/plugin.yml | 48 ++++++------- 11 files changed, 157 insertions(+), 119 deletions(-) diff --git a/src/main/java/de/minebench/syncinv/SyncInv.java b/src/main/java/de/minebench/syncinv/SyncInv.java index df46549..64a50a7 100644 --- a/src/main/java/de/minebench/syncinv/SyncInv.java +++ b/src/main/java/de/minebench/syncinv/SyncInv.java @@ -11,8 +11,8 @@ import de.minebench.syncinv.listeners.PlayerConnectionValidateLoginListener; import de.minebench.syncinv.listeners.PlayerFreezeListener; import de.minebench.syncinv.listeners.PlayerJoinListener; -import de.minebench.syncinv.listeners.PlayerLoginListener; import de.minebench.syncinv.listeners.PlayerQuitListener; +import de.minebench.syncinv.listeners.PlayerLoginListener; import de.minebench.syncinv.messenger.Message; import de.minebench.syncinv.messenger.MessageType; import de.minebench.syncinv.messenger.PlayerDataQuery; @@ -50,7 +50,6 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.AbstractMap; import java.util.Date; @@ -177,8 +176,8 @@ public void onEnable() { loadConfig(); playerDataFolder = getServer().getMinecraftVersion().startsWith("1.") - ? new File(getServer().getWorlds().get(0).getWorldFolder(), "playerdata") - : new File(new File(getServer().getWorlds().get(0).getWorldFolder(), "players"), "data"); + ? new File(getServer().getWorlds().getFirst().getWorldFolder(), "playerdata") + : new File(new File(getServer().getWorlds().getFirst().getWorldFolder(), "players"), "data"); MethodHandle tempUUIDGetterHandle = null; try { @@ -410,7 +409,7 @@ && getConfig().contains("sync-" + syncType.getKey(), true)) { } if (getServer().getMap((short) 0) == null) { - getServer().createMap(getServer().getWorlds().get(0)); + getServer().createMap(getServer().getWorlds().getFirst()); } try { MapView map = null; @@ -483,10 +482,10 @@ public boolean isLocked(UUID playerId) { /** * Get the date when a player last logged out - * @param playerId The UUID of the player - * @param online Whether or not it should return the current time if the player is online - * @return The timestamp of his last known data on the server in milliseconds; - * 0 if the file doesn't exist or an error occurs. (Take a look at {File#lastModified}) + * @param playerId The UUID of the player + * @param online Whether or not it should return the current time if the player is online + * @return The timestamp of his last known data on the server in milliseconds; + * 0 if the file doesn't exist or an error occurs. (Take a look at {File#lastModified}) */ public long getLastSeen(UUID playerId, boolean online) { if (online) { @@ -536,7 +535,7 @@ public boolean setLastSeen(UUID playerId, long timeStamp) { } // Workaround for systems that don't allow modifying the dat directly try { - Files.write(lastSeen.toPath(), String.valueOf(timeStamp).getBytes(StandardCharsets.UTF_8)); + Files.writeString(lastSeen.toPath(), String.valueOf(timeStamp)); return true; } catch (IOException e) { getLogger().log(Level.SEVERE, "Unable to store lastseen file for " + playerId, e); @@ -585,7 +584,7 @@ public void connectToServer(UUID playerId, String server) { /** * Apply a PlayerData object to its player - * @param data The data to apply + * @param data The data to apply */ public void applyData(PlayerData data, Runnable finished) { if (data == null) @@ -929,27 +928,32 @@ private void forceRender(MapView map) { map.addRenderer(new EmptyRenderer()); } + /** + * @return Reference to the OpenInv plugin to load data for the query option + */ public OpenInv getOpenInv() { - return this.openInv; + return openInv; } + /** + * @return The messenger for communications between the servers + */ public ServerMessenger getMessenger() { - return this.messenger; + return messenger; } + /** + * @return The amount of seconds we should wait for a query to stopTimeout + */ public int getQueryTimeout() { - return this.queryTimeout; + return queryTimeout; } + /** + * @return The id of the newest map that was seen on this server + */ public int getNewestMap() { - return this.newestMap; - } - - private static class EmptyRenderer extends MapRenderer { - @Override - public void render(@NotNull MapView map, @NotNull MapCanvas canvas, @NotNull Player player) { - - } + return newestMap; } private void cacheData(PlayerData data, Runnable finished) { @@ -958,7 +962,7 @@ private void cacheData(PlayerData data, Runnable finished) { /** * Get data that was cached which should be applied on a player's login - * @param player The player to get the data for + * @param player The player to get the data for * @return A cache entry containing the PlayerData and the notification Runnable when applied successfully */ public Map.Entry getCachedData(Player player) { @@ -967,7 +971,7 @@ public Map.Entry getCachedData(Player player) { /** * Remove the cached data of a player - * @param player The player to remove the data for + * @param player The player to remove the data for */ public void removeCachedData(Player player) { playerDataCache.invalidate(player.getUniqueId()); @@ -1124,7 +1128,7 @@ public PlayerData getData(Player player) { /** * The sound to play when a player gets unlocked, should match the vanilla levelup - * @param playerId The uuid of the Player to play the sound to + * @param playerId The uuid of the Player to play the sound to */ public void playLoadSound(UUID playerId) { Player player = getServer().getPlayer(playerId); @@ -1135,7 +1139,7 @@ public void playLoadSound(UUID playerId) { /** * The sound to play when a player gets unlocked, should match the vanilla levelup - * @param player The Player to play the sound to + * @param player The Player to play the sound to */ public void playLoadSound(Player player) { player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 0.7f, 1); @@ -1150,7 +1154,7 @@ public void checkMap(int id) { logDebug("Checking map " + id); try { while (getServer().getMap(id) == null) { - MapView map = getServer().createMap(getServer().getWorlds().get(0)); + MapView map = getServer().createMap(getServer().getWorlds().getFirst()); logDebug("Created map " + map.getId()); } } catch (Exception e) { @@ -1235,4 +1239,10 @@ private enum FilterMode { DENY, ALLOW } + + private static class EmptyRenderer extends MapRenderer { + @Override + public void render(@NotNull MapView map, @NotNull MapCanvas canvas, @NotNull Player player) { + } + } } diff --git a/src/main/java/de/minebench/syncinv/listeners/PlayerConnectionValidateLoginListener.java b/src/main/java/de/minebench/syncinv/listeners/PlayerConnectionValidateLoginListener.java index 455d274..1aff650 100644 --- a/src/main/java/de/minebench/syncinv/listeners/PlayerConnectionValidateLoginListener.java +++ b/src/main/java/de/minebench/syncinv/listeners/PlayerConnectionValidateLoginListener.java @@ -41,16 +41,16 @@ public void onPlayerLogin(PlayerConnectionValidateLoginEvent e) { // Event will have pre-cancelled result set for whitelist/banlist if (e.isAllowed() && e.getConnection() instanceof PlayerLoginConnection connection && connection.getUnsafeProfile() != null) { // Sync login listener for sanity checking as we don't want to allow the player to exist twice - Entity entity = plugin.getServer().getEntity(connection.getUnsafeProfile().getUniqueId()); + Entity entity = plugin.getServer().getEntity(connection.getUnsafeProfile().getId()); if (entity instanceof Player) { e.kickMessage(Component.text("A player with your UUID already exists!").color(NamedTextColor.RED)); - plugin.logDebug("A player object with the same UUID " + connection.getUnsafeProfile().getUniqueId() + " already exists on the server."); + plugin.logDebug("A player object with the same UUID " + connection.getUnsafeProfile().getId() + " already exists on the server."); // Kick player. This should do nothing if it's not a real one (e.g. one loaded by OpenInv) // Removal of such players is up to OpenInv itself ((Player) entity).kickPlayer("Login from different location."); } else if (entity != null) { // Well... this is weird. An entity with the same UUID as the player's exists?!? Removing it just to be sure... - plugin.getLogger().info("A " + entity + " with the same UUID " + connection.getUnsafeProfile().getUniqueId() + plugin.getLogger().info("A " + entity + " with the same UUID " + connection.getUnsafeProfile().getId() + " as the player login in existed on the server at " + entity.getLocation() + "... removing it!"); entity.remove(); } diff --git a/src/main/java/de/minebench/syncinv/listeners/PlayerFreezeListener.java b/src/main/java/de/minebench/syncinv/listeners/PlayerFreezeListener.java index 089f71a..fba5ee6 100644 --- a/src/main/java/de/minebench/syncinv/listeners/PlayerFreezeListener.java +++ b/src/main/java/de/minebench/syncinv/listeners/PlayerFreezeListener.java @@ -47,7 +47,7 @@ public PlayerFreezeListener(SyncInv plugin) { @EventHandler(ignoreCancelled = true) public void onDropItem(PlayerDropItemEvent e) { - if(plugin.isLocked(e.getPlayer().getUniqueId())) { + if (plugin.isLocked(e.getPlayer().getUniqueId())) { e.setCancelled(true); e.getPlayer().sendMessage(plugin.getLang("cant-drop-items")); } @@ -55,7 +55,7 @@ public void onDropItem(PlayerDropItemEvent e) { @EventHandler(ignoreCancelled = true) public void onPlayerMove(PlayerMoveEvent e) { - if(!sameBlock(e.getFrom(), e.getTo()) && plugin.isLocked(e.getPlayer().getUniqueId())) { + if (!sameBlock(e.getFrom(), e.getTo()) && plugin.isLocked(e.getPlayer().getUniqueId())) { e.setCancelled(true); if (e.getFrom().getBlockY() == e.getTo().getBlockY()) { e.getPlayer().sendMessage(plugin.getLang("cant-move")); @@ -79,7 +79,7 @@ public void onPlayerPickupItem(EntityPickupItemEvent e) { @EventHandler(ignoreCancelled = true) public void onPlayerPickupExp(PlayerExpChangeEvent e) { - if(plugin.isLocked(e.getPlayer().getUniqueId())) { + if (plugin.isLocked(e.getPlayer().getUniqueId())) { e.setAmount(0); e.getPlayer().sendMessage(plugin.getLang("cant-pickup-exp")); } @@ -87,7 +87,7 @@ public void onPlayerPickupExp(PlayerExpChangeEvent e) { @EventHandler(ignoreCancelled = true) public void onPlayerDamage(EntityDamageEvent e) { - if(e.getEntity() instanceof Player && plugin.isLocked(e.getEntity().getUniqueId())) { + if (e.getEntity() instanceof Player && plugin.isLocked(e.getEntity().getUniqueId())) { e.setCancelled(true); } } @@ -101,7 +101,7 @@ public void onPlayerDeath(PlayerDeathEvent e) { @EventHandler(ignoreCancelled = true) public void onInventoryInteraction(InventoryClickEvent e) { - if(plugin.isLocked(e.getWhoClicked().getUniqueId())) { + if (plugin.isLocked(e.getWhoClicked().getUniqueId())) { e.setCancelled(true); e.getWhoClicked().sendMessage(plugin.getLang("wait-for-loading")); } @@ -109,7 +109,7 @@ public void onInventoryInteraction(InventoryClickEvent e) { @EventHandler(ignoreCancelled = true) public void onInventoryInteraction(InventoryDragEvent e) { - if(plugin.isLocked(e.getWhoClicked().getUniqueId())) { + if (plugin.isLocked(e.getWhoClicked().getUniqueId())) { e.setCancelled(true); e.getWhoClicked().sendMessage(plugin.getLang("wait-for-loading")); } @@ -117,7 +117,7 @@ public void onInventoryInteraction(InventoryDragEvent e) { @EventHandler(ignoreCancelled = true) public void onInventoryInteraction(InventoryOpenEvent e) { - if(plugin.isLocked(e.getPlayer().getUniqueId())) { + if (plugin.isLocked(e.getPlayer().getUniqueId())) { e.setCancelled(true); e.getPlayer().sendMessage(plugin.getLang("wait-for-loading")); } @@ -125,7 +125,7 @@ public void onInventoryInteraction(InventoryOpenEvent e) { @EventHandler(ignoreCancelled = true) public void onInteraction(PlayerInteractEvent e) { - if(plugin.isLocked(e.getPlayer().getUniqueId())) { + if (plugin.isLocked(e.getPlayer().getUniqueId())) { e.setCancelled(true); e.getPlayer().sendMessage(plugin.getLang("wait-for-loading")); } @@ -133,7 +133,7 @@ public void onInteraction(PlayerInteractEvent e) { @EventHandler(ignoreCancelled = true) public void onDamageEntity(EntityDamageByEntityEvent e) { - if(e.getDamager() instanceof Player && plugin.isLocked(e.getDamager().getUniqueId())) { + if (e.getDamager() instanceof Player && plugin.isLocked(e.getDamager().getUniqueId())) { e.setCancelled(true); e.getDamager().sendMessage(plugin.getLang("wait-for-loading")); } @@ -141,7 +141,7 @@ public void onDamageEntity(EntityDamageByEntityEvent e) { @EventHandler(ignoreCancelled = true) public void onBlockDamage(BlockDamageEvent e) { - if(plugin.isLocked(e.getPlayer().getUniqueId())) { + if (plugin.isLocked(e.getPlayer().getUniqueId())) { e.setCancelled(true); e.getPlayer().sendMessage(plugin.getLang("wait-for-loading")); } @@ -149,7 +149,7 @@ public void onBlockDamage(BlockDamageEvent e) { @EventHandler(ignoreCancelled = true) public void onChat(AsyncPlayerChatEvent e) { - if(plugin.isLocked(e.getPlayer().getUniqueId())) { + if (plugin.isLocked(e.getPlayer().getUniqueId())) { e.setCancelled(true); e.getPlayer().sendMessage(plugin.getLang("wait-for-loading")); } @@ -157,7 +157,7 @@ public void onChat(AsyncPlayerChatEvent e) { @EventHandler(ignoreCancelled = true) public void onChat(PlayerCommandPreprocessEvent e) { - if(plugin.isLocked(e.getPlayer().getUniqueId())) { + if (plugin.isLocked(e.getPlayer().getUniqueId())) { e.setCancelled(true); e.getPlayer().sendMessage(plugin.getLang("wait-for-loading")); } diff --git a/src/main/java/de/minebench/syncinv/listeners/PlayerJoinListener.java b/src/main/java/de/minebench/syncinv/listeners/PlayerJoinListener.java index 58da001..9ca94c8 100644 --- a/src/main/java/de/minebench/syncinv/listeners/PlayerJoinListener.java +++ b/src/main/java/de/minebench/syncinv/listeners/PlayerJoinListener.java @@ -47,7 +47,6 @@ public void onPlayerPreLogin(AsyncPlayerPreLoginEvent e) { if (plugin.getMessenger().queryData(e.getUniqueId()) == null && (!plugin.getMessenger().isAllowedToBeAlone() || !plugin.getMessenger().isAlone())) { e.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER); e.setKickMessage(ChatColor.RED + "Unable to query player data!"); - return; } } } diff --git a/src/main/java/de/minebench/syncinv/listeners/PlayerQuitListener.java b/src/main/java/de/minebench/syncinv/listeners/PlayerQuitListener.java index cf84061..8946888 100644 --- a/src/main/java/de/minebench/syncinv/listeners/PlayerQuitListener.java +++ b/src/main/java/de/minebench/syncinv/listeners/PlayerQuitListener.java @@ -43,7 +43,7 @@ public void onPlayerQuit(PlayerQuitEvent event) { } PlayerDataQuery query = plugin.getMessenger().removeQuery(event.getPlayer().getUniqueId()); if (query != null) { - // The player is gone although he had a query... + // The player is gone, although he had a query... // We have to make sure now that the time of the data file matches the old one // and not send our data to all the other servers as it might be outdated plugin.runLater(() -> { @@ -67,5 +67,4 @@ public void onPlayerQuit(PlayerQuitEvent event) { // Update last seen plugin.runLater(() -> plugin.setLastSeen(event.getPlayer().getUniqueId(), System.currentTimeMillis()), 1); } - } diff --git a/src/main/java/de/minebench/syncinv/messenger/Message.java b/src/main/java/de/minebench/syncinv/messenger/Message.java index ce840b3..ee52709 100644 --- a/src/main/java/de/minebench/syncinv/messenger/Message.java +++ b/src/main/java/de/minebench/syncinv/messenger/Message.java @@ -40,10 +40,11 @@ public class Message { /** * A Message of a certain type. Optionally with some data - * @param sender The sender which sent the message - * @param id The transaction ID this Message is associated with - * @param type The type of the message - * @param objects The data, in the order that it should be sent + * + * @param sender The sender which sent the message + * @param id The transaction ID this Message is associated with + * @param type The type of the message + * @param objects The data, in the order that it should be sent * @throws IllegalArgumentException when the amount of Objects given didn't match the MessageType requirements */ public Message(String sender, long id, MessageType type, Object... objects) { @@ -100,10 +101,10 @@ public Object read() { /** * Generate a byte array out of the data of this message - * @return The generated byte array (starts with the sender - * then the type ordinal, then the amount - * of data being sent and each data object); - * an empty one if an error occurred + * @return The generated byte array (starts with the sender + * then the type ordinal, then the amount + * of data being sent and each data object); + * an empty one if an error occurred */ public byte[] toByteArray() { try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); @@ -127,12 +128,12 @@ public byte[] toByteArray() { /** * Get the message from a bytearray generated as described in the toByteArray method * @param bytes The bytes - * @return The Message object + * @return The Message object * @throws IOException - * @throws IllegalArgumentException When the message type is not supported + * @throws IllegalArgumentException When the message type is not supported * @throws ClassNotFoundException - * @throws InvalidConfigurationException If the data is invalid - * @throws VersionMismatchException If the received message is of a different version than it can accept + * @throws InvalidConfigurationException If the data is invalid + * @throws VersionMismatchException If the received message is of a different version than it can accept */ public static Message fromByteArray(byte[] bytes) throws IOException, IllegalArgumentException, ClassNotFoundException, InvalidConfigurationException, VersionMismatchException { try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes); @@ -152,6 +153,9 @@ public static Message fromByteArray(byte[] bytes) throws IOException, IllegalArg } } + /** + * @return a Sting representation of this message + */ public String toString() { return "Message(sender=" + this.getSender() + ", id=" + this.getId() + ", type=" + this.getType() + ", data=" + this.getData() + ")"; } diff --git a/src/main/java/de/minebench/syncinv/messenger/PlayerDataQuery.java b/src/main/java/de/minebench/syncinv/messenger/PlayerDataQuery.java index c028444..b8a4ad3 100644 --- a/src/main/java/de/minebench/syncinv/messenger/PlayerDataQuery.java +++ b/src/main/java/de/minebench/syncinv/messenger/PlayerDataQuery.java @@ -33,7 +33,7 @@ public class PlayerDataQuery { private BukkitTask timeoutTask; private boolean completed = false; - private Map servers = new ConcurrentHashMap<>(); + private final Map servers = new ConcurrentHashMap<>(); public PlayerDataQuery(UUID playerId, long localLastSeen, Consumer onComplete) { this.playerId = playerId; @@ -41,21 +41,30 @@ public PlayerDataQuery(UUID playerId, long localLastSeen, Consumer getServers() { return servers; } /** * Add a new response to this query - * @param server The name of the server + * @param server The name of the server * @param lastSeen When the user was last seen on that server */ public void addResponse(String server, long lastSeen) { @@ -86,6 +95,9 @@ public long getTimestamp() { return timestamp; } + /** + * @param timeoutTask the task to get canceled whenever the query completes + */ public void setTimeoutTask(BukkitTask timeoutTask) { this.timeoutTask = timeoutTask; } diff --git a/src/main/java/de/minebench/syncinv/messenger/RedisMessenger.java b/src/main/java/de/minebench/syncinv/messenger/RedisMessenger.java index 6f18f39..ed77366 100644 --- a/src/main/java/de/minebench/syncinv/messenger/RedisMessenger.java +++ b/src/main/java/de/minebench/syncinv/messenger/RedisMessenger.java @@ -36,10 +36,10 @@ */ public class RedisMessenger extends ServerMessenger { - private final RedisClient client; - private StatefulRedisConnection connection; private static final String CHANNEL_PREFIX = "syncinv:"; private static final String VERSION_PREFIX = Message.VERSION + ":"; + private final RedisClient client; + private StatefulRedisConnection connection; public RedisMessenger(SyncInv plugin) { super(plugin); @@ -62,7 +62,7 @@ public RedisMessenger(SyncInv plugin) { client = RedisClient.create(uri); StatefulRedisPubSubConnection connection = client.connectPubSub(new StringByteArrayCodec()); - connection.addListener(new RedisPubSubListener() { + connection.addListener(new RedisPubSubListener<>() { @Override public void message(String channel, byte[] bytes) { if (!channel.startsWith(CHANNEL_PREFIX)) { @@ -126,8 +126,7 @@ protected void sendMessageImplementation(String target, Message message, boolean } } - private class StringByteArrayCodec implements RedisCodec { - + private static class StringByteArrayCodec implements RedisCodec { private final StringCodec stringCodec = new StringCodec(); private final ByteArrayCodec byteArrayCodec = new ByteArrayCodec(); diff --git a/src/main/java/de/minebench/syncinv/messenger/ServerMessenger.java b/src/main/java/de/minebench/syncinv/messenger/ServerMessenger.java index 747e104..4fbed5e 100644 --- a/src/main/java/de/minebench/syncinv/messenger/ServerMessenger.java +++ b/src/main/java/de/minebench/syncinv/messenger/ServerMessenger.java @@ -70,7 +70,7 @@ public abstract class ServerMessenger { /** * List of channels that this plugin listens on */ - private Set channels = new HashSet<>(); + private final Set channels = new HashSet<>(); public ServerMessenger(SyncInv plugin) { this.plugin = plugin; @@ -99,7 +99,7 @@ public void goodbye() { /** * Register channels that this messenger should listen on - * @param channels The channels to listen on + * @param channels The channels to listen on */ private void registerChannel(String... channels) { for (String channel : channels) { @@ -144,8 +144,8 @@ public PlayerDataQuery queryData(UUID playerId) { /** * Query the data of a player - * @param playerId The UUID of the player - * @param onComplete Handle the player data when all we have all information from the other servers + * @param playerId The UUID of the player + * @param onComplete Handle the player data when all we have all information from the other servers * @return The PlayerDataQuery object, either a new one or the existing one. null if we are unable to query. */ public PlayerDataQuery queryData(UUID playerId, Consumer onComplete) { @@ -192,8 +192,8 @@ public boolean isAllowedToBeAlone() { /** * Reaction on a message, this has to be called by the messenger implementation! - * @param target The server this message is targeted at - * @param message The message received + * @param target The server this message is targeted at + * @param message The message received */ protected void onMessage(String target, Message message) { if (message.getSender().equals(getServerName()) // don't read messages from ourselves @@ -207,7 +207,7 @@ protected void onMessage(String target, Message message) { servers.add(message.getSender()); - UUID playerId = null; + UUID playerId; long lastSeen; Player player; PlayerDataQuery query; @@ -308,7 +308,7 @@ protected void onMessage(String target, Message message) { break; case CANT_GET_DATA: - // Send the player to the server if we can't get the data and he has an open request + // Send the player to the server if we can't get the data, and he has an open request playerId = (UUID) message.read(); plugin.logDebug(message.getId() + " Received " + message.getType() + " for " + playerId + " from " + message.getSender() + " targeted at " + target); if (hasQuery(playerId)) { @@ -346,7 +346,7 @@ private void completeQuery(PlayerDataQuery query) { /** * Check if a query was answered by all known servers * @param query The query to check - * @return Whether or not all servers responded + * @return Whether or not all servers responded */ private boolean isCompleted(PlayerDataQuery query) { if (query.getServers().size() < servers.size()) { @@ -364,12 +364,12 @@ private boolean isCompleted(PlayerDataQuery query) { /** * Send a simple message with only a type to other servers - * @param target The name of the target server; - * use "group:" to only send to a specific group of servers; - * use "*" to send it to everyone - * @param id The transaction ID this Message is associated with - * @param type The type of the message to send - * @param objects The data to send in the order the exact order + * @param target The name of the target server; + * use "group:" to only send to a specific group of servers; + * use "*" to send it to everyone + * @param id The transaction ID this Message is associated with + * @param type The type of the message to send + * @param objects The data to send in the order the exact order */ public void sendMessage(String target, long id, MessageType type, Object... objects) { sendMessage(target, new Message(getServerName(), id, type, objects), false); @@ -377,11 +377,11 @@ public void sendMessage(String target, long id, MessageType type, Object... obje /** * Send a message to other servers - * @param target The name of the target server; - * use "group:" to only send to a specific group of servers; - * use "*" to send it to everyone - * @param message The message to send - * @param sync Whether the message should be send sync or on its own thread + * @param target The name of the target server; + * use "group:" to only send to a specific group of servers; + * use "*" to send it to everyone + * @param message The message to send + * @param sync Whether the message should be send sync or on its own thread */ public void sendMessage(String target, Message message, boolean sync) { plugin.logDebug(message.getId() + " Sending " + (sync ? "sync " : "") + message.getType() + " to " + target + " containing " + message.getData().size() + " objects."); @@ -390,9 +390,9 @@ public void sendMessage(String target, Message message, boolean sync) { /** * Send a simple message with only a type to all servers of the group - * @param id The transaction ID this Message is associated with - * @param type The type of the message to send - * @param objects The data to send in the order the exact order + * @param id The transaction ID this Message is associated with + * @param type The type of the message to send + * @param objects The data to send in the order the exact order */ public void sendGroupMessage(long id, MessageType type, Object... objects) { sendMessage("group:" + getServerGroup(), id, type, objects); @@ -400,8 +400,8 @@ public void sendGroupMessage(long id, MessageType type, Object... objects) { /** * Send a message to all servers of the group - * @param message The message to send - * @param sync Whether the message should be send sync or on its own thread + * @param message The message to send + * @param sync Whether the message should be send sync or on its own thread */ public void sendGroupMessage(Message message, boolean sync) { sendMessage("group:" + getServerGroup(), message, sync); @@ -429,7 +429,7 @@ public PlayerDataQuery getQuery(UUID playerId) { * Add a query for a player * @param playerId The UUID of the player * @param query The query to add - * @return The previous PlayerDataQuery if there was one + * @return The previous PlayerDataQuery if there was one */ public PlayerDataQuery addQuery(UUID playerId, PlayerDataQuery query) { Player player = plugin.getServer().getPlayer(playerId); @@ -443,8 +443,8 @@ public PlayerDataQuery addQuery(UUID playerId, PlayerDataQuery query) { /** * Remove an active query of a player - * @param playerId The UUID of the player - * @return The previous PlayerDataQuery if there was one + * @param playerId The UUID of the player + * @return The previous PlayerDataQuery if there was one */ public PlayerDataQuery removeQuery(UUID playerId) { return queries.remove(playerId); @@ -483,15 +483,24 @@ public void fulfillQueuedDataRequest(PlayerData data) { } } + /** + * @return The group that this server is in + */ public String getServerGroup() { - return this.serverGroup; + return serverGroup; } + /** + * @return The name of this server, should be the same as in the Bungee's config. yml + */ public String getServerName() { - return this.serverName; + return serverName; } + /** + * @return modifiable set of all the channels the plugin is listening to + */ public Set getChannels() { - return this.channels; + return channels; } } diff --git a/src/main/java/de/minebench/syncinv/messenger/VersionMismatchException.java b/src/main/java/de/minebench/syncinv/messenger/VersionMismatchException.java index 57c6899..20e3029 100644 --- a/src/main/java/de/minebench/syncinv/messenger/VersionMismatchException.java +++ b/src/main/java/de/minebench/syncinv/messenger/VersionMismatchException.java @@ -27,10 +27,16 @@ public VersionMismatchException(int receivedVersion, int supportedVersion, Strin this.supportedVersion = supportedVersion; } + /** + * @return get the actual version that was received + */ public int getReceivedVersion() { return receivedVersion; } + /** + * @return get the version that is supported and was expected + */ public int getSupportedVersion() { return supportedVersion; } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 186866f..7d58f06 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -2,30 +2,30 @@ name: ${project.name} version: '${minecraft.plugin.version}' api-version: '1.21.1' main: de.minebench.syncinv.SyncInv -softdepend: [OpenInv] -authors: [Phoenix616] +softdepend: [ OpenInv ] +authors: [ Phoenix616 ] description: ${project.description} commands: - syncinv: - aliases: [syncinv] - description: Plugin command description. - usage: / [reload] - permission: SyncInv.command - permission-message: You don't have the permission - openinv: - aliases: [oi, inv, open] - description: Open a player's inventory - permission: SyncInv.openinv - usage: / - Open a player's inventory - openender: - aliases: [oe] - description: Opens the enderchest of a player - permission: SyncInv.openender - usage: / - Open a player's enderchest + syncinv: + aliases: [ syncinv ] + description: Plugin command description. + usage: / [reload] + permission: SyncInv.command + permission-message: You don't have the permission + openinv: + aliases: [ oi, inv, open ] + description: Open a player's inventory + permission: SyncInv.openinv + usage: / - Open a player's inventory + openender: + aliases: [ oe ] + description: Opens the enderchest of a player + permission: SyncInv.openender + usage: / - Open a player's enderchest permissions: - syncinv.command: - description: Gives permission to the plugin command - default: op - syncinv.command.reload: - description: Gives permission to reload the plugin - default: op \ No newline at end of file + syncinv.command: + description: Gives permission to the plugin command + default: op + syncinv.command.reload: + description: Gives permission to reload the plugin + default: op \ No newline at end of file