From 071c0eb8c0749d962315c57be42ce0d59874f26e Mon Sep 17 00:00:00 2001 From: webhead1104 Date: Sat, 25 May 2024 13:52:24 -0500 Subject: [PATCH] Chat Channels and formatting --- .idea/misc.xml | 2 +- .../java/net/cytonic/cytosis/Cytosis.java | 5 +- .../cytosis/commands/ChatChannelCommand.java | 126 ++++++--------- .../cytonic/cytosis/commands/RankCommand.java | 6 +- .../cytosis/config/CytosisSettings.java | 9 +- .../net/cytonic/cytosis/data/Database.java | 147 +++++++++--------- .../cytonic/cytosis/data/objects/Request.java | 66 -------- .../cytonic/cytosis/events/EventHandler.java | 4 +- .../cytosis/events/ServerEventListeners.java | 57 +++---- .../cytosis/events/ranks/RankChangeEvent.java | 2 +- .../cytosis/events/ranks/RankSetupEvent.java | 2 +- .../cytonic/cytosis/files/FileManager.java | 5 +- .../cytonic/cytosis/managers/ChatManager.java | 10 +- .../cytosis/messaging/MessagingManager.java | 6 +- .../cytonic/cytosis/messaging/RabbitMQ.java | 114 +++++++------- .../net/cytonic/cytosis/ranks/PlayerRank.java | 4 +- .../cytonic/cytosis/ranks/RankManager.java | 4 +- src/main/resources/config.toml | 1 + 18 files changed, 224 insertions(+), 346 deletions(-) delete mode 100644 src/main/java/net/cytonic/cytosis/data/objects/Request.java diff --git a/.idea/misc.xml b/.idea/misc.xml index 0738616b..2758df87 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/src/main/java/net/cytonic/cytosis/Cytosis.java b/src/main/java/net/cytonic/cytosis/Cytosis.java index fe8d83f0..e22386e9 100644 --- a/src/main/java/net/cytonic/cytosis/Cytosis.java +++ b/src/main/java/net/cytonic/cytosis/Cytosis.java @@ -5,7 +5,6 @@ import java.util.Optional; import java.util.Set; import java.util.UUID; - import lombok.Getter; import net.cytonic.cytosis.commands.CommandHandler; import net.cytonic.cytosis.config.CytosisSettings; @@ -89,7 +88,7 @@ public static void main(String[] args) { //chat manager Logger.info("Starting chat manager."); - chatManager = new ChatManager(); + chatManager = new ChatManager(); // instances Logger.info("Creating instance container"); @@ -191,7 +190,7 @@ public static void completeNonEssentialTasks(long start) { Logger.info("Initializing server commands"); commandHandler = new CommandHandler(); commandHandler.setupConsole(); - commandHandler.registerCystosisCommands(); + commandHandler.registerCytosisCommands(); messagingManager = new MessagingManager(); messagingManager.initialize().whenComplete((_, throwable) -> { diff --git a/src/main/java/net/cytonic/cytosis/commands/ChatChannelCommand.java b/src/main/java/net/cytonic/cytosis/commands/ChatChannelCommand.java index 863f7bbc..9581b3ec 100644 --- a/src/main/java/net/cytonic/cytosis/commands/ChatChannelCommand.java +++ b/src/main/java/net/cytonic/cytosis/commands/ChatChannelCommand.java @@ -5,7 +5,6 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.minestom.server.command.builder.Command; -import net.minestom.server.command.builder.arguments.ArgumentEnum; import net.minestom.server.command.builder.arguments.ArgumentType; import net.minestom.server.command.builder.suggestion.SuggestionEntry; import net.minestom.server.entity.Player; @@ -14,82 +13,72 @@ public class ChatChannelCommand extends Command { public ChatChannelCommand() { super("chat"); - setDefaultExecutor(((sender, commandContext) -> sender.sendMessage(Component.text("You must specify a channel!", NamedTextColor.RED)))); + setDefaultExecutor((sender, _) -> sender.sendMessage(Component.text("You must specify a channel!", NamedTextColor.RED))); - var chatChannelArgument = ArgumentType.Enum("channel", ChatChannel.class).setFormat(ArgumentEnum.Format.LOWER_CASED); - chatChannelArgument.setCallback((sender, exception) -> sender.sendMessage(STR."The channel \{exception.getInput()} is invalid!")); + var chatChannelArgument = ArgumentType.Word("channel").from("mod", "admin", "staff", "all", "party", "league", "private_message"); + chatChannelArgument.setCallback((sender, exception) -> sender.sendMessage(STR."The channel \{exception.getInput()} is invalid!")); + chatChannelArgument.setSuggestionCallback((sender, _, suggestion) -> { + if (sender.hasPermission("cytonic.chat.mod")) + suggestion.addEntry(new SuggestionEntry("mod")); + if (sender.hasPermission("cytonic.chat.admin")) + suggestion.addEntry(new SuggestionEntry("admin")); + if (sender.hasPermission("cytonic.chat.staff")) + suggestion.addEntry(new SuggestionEntry("staff")); + suggestion.addEntry(new SuggestionEntry("all")); + suggestion.addEntry(new SuggestionEntry("party")); + suggestion.addEntry(new SuggestionEntry("league")); + suggestion.addEntry(new SuggestionEntry("private_message")); + }); - var shorthand = ArgumentType.Word("shorthand").from("a"); - shorthand.setSuggestionCallback((sender, commandContext, suggestion) -> { - Player player = (Player) sender; - if (player.hasPermission("cytonic.chat.mod")) - suggestion.addEntry(new SuggestionEntry("m", Component.text("Represents the Mod channel"))); - if (player.hasPermission("cytonic.chat.staff")) - suggestion.addEntry(new SuggestionEntry("s", Component.text("Represents the Staff channel"))); - if (player.hasPermission("cytonic.chat.admin")) - suggestion.addEntry(new SuggestionEntry("ad", Component.text("Represents the Admin channel"))); - //parties - suggestion.addEntry(new SuggestionEntry("a",Component.text("Represents the All channel"))); + var shorthand = ArgumentType.Word("shorthand").from("m", "ad", "s", "a"); + shorthand.setCallback((sender, exception) -> sender.sendMessage(STR."The shorthand \{exception.getInput()} is invalid!")); + shorthand.setSuggestionCallback((sender, _, suggestion) -> { + if (sender.hasPermission("cytonic.chat.mod")) + suggestion.addEntry(new SuggestionEntry("m")); + if (sender.hasPermission("cytonic.chat.admin")) + suggestion.addEntry(new SuggestionEntry("ad")); + if (sender.hasPermission("cytonic.chat.staff")) + suggestion.addEntry(new SuggestionEntry("s")); + suggestion.addEntry(new SuggestionEntry("a")); }); shorthand.setCallback((sender, exception) -> sender.sendMessage(Component.text(STR."The shorthand '\{exception.getInput()}' is invalid!", NamedTextColor.RED))); - + addSyntax((sender, context) -> { if (sender instanceof final Player player) { - final ChatChannel channel = context.get(chatChannelArgument); + final String channel = context.get(chatChannelArgument); switch (channel) { - case ALL -> { + case "all" -> { Cytosis.getChatManager().setChannel(player.getUuid(), ChatChannel.ALL); - player.sendMessage( - Component.text("You are now in the ", NamedTextColor.GREEN) - .append(Component.text("ALL", NamedTextColor.GOLD)) - .append(Component.text(" channel.", NamedTextColor.GREEN)) - ); + player.sendMessage(Component.text("You are now in the ", NamedTextColor.GREEN).append(Component.text("ALL", NamedTextColor.GOLD)).append(Component.text(" channel.", NamedTextColor.GREEN))); + player.getAllPermissions().forEach((permission -> player.sendMessage(permission.getPermissionName()))); } - case ADMIN -> { + case "admin" -> { if (player.hasPermission("cytonic.chat.admin")) { Cytosis.getChatManager().setChannel(player.getUuid(), ChatChannel.ADMIN); - player.sendMessage( - Component.text("You are now in the ", NamedTextColor.GREEN) - .append(Component.text("ADMIN", NamedTextColor.GOLD)) - .append(Component.text(" channel.", NamedTextColor.GREEN)) - ); + player.sendMessage(Component.text("You are now in the ", NamedTextColor.GREEN).append(Component.text("ADMIN", NamedTextColor.GOLD)).append(Component.text(" channel.", NamedTextColor.GREEN))); } else { player.sendMessage(Component.text("You do not have access to this channel.", NamedTextColor.RED)); } } - case MOD -> { + case "mod" -> { if (player.hasPermission("cytonic.chat.mod")) { Cytosis.getChatManager().setChannel(player.getUuid(), ChatChannel.MOD); - player.sendMessage( - Component.text("You are now in the ", NamedTextColor.GREEN) - .append(Component.text("MOD", NamedTextColor.GOLD)) - .append(Component.text(" channel.", NamedTextColor.GREEN)) - ); + player.sendMessage(Component.text("You are now in the ", NamedTextColor.GREEN).append(Component.text("MOD", NamedTextColor.GOLD)).append(Component.text(" channel.", NamedTextColor.GREEN))); } else { player.sendMessage(Component.text("You do not have access to this channel.", NamedTextColor.RED)); } } - case STAFF -> { + case "staff" -> { if (player.hasPermission("cytonic.chat.staff")) { Cytosis.getChatManager().setChannel(player.getUuid(), ChatChannel.STAFF); - player.sendMessage( - Component.text("You are now in the ", NamedTextColor.GREEN) - .append(Component.text("STAFF", NamedTextColor.GOLD)) - .append(Component.text(" channel.", NamedTextColor.GREEN)) - ); + player.sendMessage(Component.text("You are now in the ", NamedTextColor.GREEN).append(Component.text("STAFF", NamedTextColor.GOLD)).append(Component.text(" channel.", NamedTextColor.GREEN))); } else { player.sendMessage(Component.text("You do not have access to this channel.", NamedTextColor.RED)); } } - case PARTY -> { - player.sendMessage("party"); - } - case LEAGUE -> { - player.sendMessage("league"); - } - case PRIVATE_MESSAGE -> { - player.sendMessage("private message"); - } + case "party" -> player.sendMessage("party"); + case "league" -> player.sendMessage("league"); + case "private message" -> player.sendMessage("private message"); } } else { sender.sendMessage(Component.text("Hey! You can't do this.", NamedTextColor.RED)); @@ -102,20 +91,12 @@ public ChatChannelCommand() { switch (channel.toLowerCase()) { case "a" -> { Cytosis.getChatManager().setChannel(player.getUuid(), ChatChannel.ALL); - player.sendMessage( - Component.text("You are now in the ", NamedTextColor.GREEN) - .append(Component.text("ALL", NamedTextColor.GOLD)) - .append(Component.text(" channel.", NamedTextColor.GREEN)) - ); + player.sendMessage(Component.text("You are now in the ", NamedTextColor.GREEN).append(Component.text("ALL", NamedTextColor.GOLD)).append(Component.text(" channel.", NamedTextColor.GREEN))); } case "ad" -> { if (player.hasPermission("cytonic.chat.admin")) { Cytosis.getChatManager().setChannel(player.getUuid(), ChatChannel.ADMIN); - player.sendMessage( - Component.text("You are now in the ", NamedTextColor.GREEN) - .append(Component.text("ADMIN", NamedTextColor.GOLD)) - .append(Component.text(" channel.", NamedTextColor.GREEN)) - ); + player.sendMessage(Component.text("You are now in the ", NamedTextColor.GREEN).append(Component.text("ADMIN", NamedTextColor.GOLD)).append(Component.text(" channel.", NamedTextColor.GREEN))); } else { player.sendMessage(Component.text("You do not have access to this channel.", NamedTextColor.RED)); } @@ -123,11 +104,7 @@ public ChatChannelCommand() { case "m" -> { if (player.hasPermission("cytonic.chat.mod")) { Cytosis.getChatManager().setChannel(player.getUuid(), ChatChannel.MOD); - player.sendMessage( - Component.text("You are now in the ", NamedTextColor.GREEN) - .append(Component.text("MOD", NamedTextColor.GOLD)) - .append(Component.text(" channel.", NamedTextColor.GREEN)) - ); + player.sendMessage(Component.text("You are now in the ", NamedTextColor.GREEN).append(Component.text("MOD", NamedTextColor.GOLD)).append(Component.text(" channel.", NamedTextColor.GREEN))); } else { player.sendMessage(Component.text("You do not have access to this channel.", NamedTextColor.RED)); } @@ -135,26 +112,19 @@ public ChatChannelCommand() { case "s" -> { if (player.hasPermission("cytonic.chat.staff")) { Cytosis.getChatManager().setChannel(player.getUuid(), ChatChannel.STAFF); - player.sendMessage( - Component.text("You are now in the ", NamedTextColor.GREEN) - .append(Component.text("STAFF", NamedTextColor.GOLD)) - .append(Component.text(" channel.", NamedTextColor.GREEN)) - ); + player.sendMessage(Component.text("You are now in the ", NamedTextColor.GREEN).append(Component.text("STAFF", NamedTextColor.GOLD)).append(Component.text(" channel.", NamedTextColor.GREEN))); } else { player.sendMessage(Component.text("You do not have access to this channel.", NamedTextColor.RED)); } } - case "p" -> { - player.sendMessage("party"); - } - case "l" -> { - player.sendMessage("league"); - } - default -> player.sendMessage(Component.text(STR."The shorthand '\{channel}' is invalid!", NamedTextColor.RED)); + case "p" -> player.sendMessage("party"); + case "l" -> player.sendMessage("league"); + default -> + player.sendMessage(Component.text(STR."The shorthand '\{channel}' is invalid!", NamedTextColor.RED)); } } else { sender.sendMessage(Component.text("Hey! You can't do this.", NamedTextColor.RED)); } }, shorthand); -} + } } \ No newline at end of file diff --git a/src/main/java/net/cytonic/cytosis/commands/RankCommand.java b/src/main/java/net/cytonic/cytosis/commands/RankCommand.java index 131c5b89..47cf9ca3 100644 --- a/src/main/java/net/cytonic/cytosis/commands/RankCommand.java +++ b/src/main/java/net/cytonic/cytosis/commands/RankCommand.java @@ -40,18 +40,15 @@ public RankCommand() { sender.sendMessage(MM."The player \{context.get(group).getRaw("player")} doesn't exist!"); return; } - if (player == sender) { sender.sendMessage(MM."You cannot change your own rank!"); return; } - Cytosis.getDatabaseManager().getDatabase().getPlayerRank(player.getUuid()).whenComplete((rank, throwable) -> { if (throwable != null) { sender.sendMessage("An error occurred whilst fetching the old rank!"); return; } - // if it's a console we don't care (There isn't a console impl) if (sender instanceof Player s) { PlayerRank senderRank = Cytosis.getRankManager().getPlayerRank(s.getUuid()).orElseThrow(); @@ -60,7 +57,6 @@ public RankCommand() { return; } } - setRank(player, newRank, sender); }); }, group); @@ -77,4 +73,4 @@ private void setRank(Player player, PlayerRank rank, CommandSender sender) { sender.sendMessage(MM."Successfully updated \{player.getUsername()}'s rank!"); }); } -} +} \ No newline at end of file diff --git a/src/main/java/net/cytonic/cytosis/config/CytosisSettings.java b/src/main/java/net/cytonic/cytosis/config/CytosisSettings.java index 7ea6435f..1ffc596e 100644 --- a/src/main/java/net/cytonic/cytosis/config/CytosisSettings.java +++ b/src/main/java/net/cytonic/cytosis/config/CytosisSettings.java @@ -27,7 +27,8 @@ public class CytosisSettings { public static String SERVER_SECRET = ""; public static int SERVER_PORT = 25565; public static String SERVER_WORLD_NAME = ""; - public static Pos SERVER_SPAWN_POS = new Pos(0,1,0); + public static Pos SERVER_SPAWN_POS = new Pos(0, 1, 0); + public static String SERVER_HOSTNAME = "UNKNOWN"; // RabbitMQ public static boolean RABBITMQ_ENABLED = false; public static String RABBITMQ_HOST = ""; @@ -45,7 +46,6 @@ public static void inportConfig(Map config) { case "logging.player_quit" -> LOG_PLAYER_QUITS = (boolean) value; case "logging.player_command" -> LOG_PLAYER_COMMANDS = (boolean) value; case "logging.player_chat" -> LOG_PLAYER_CHAT = (boolean) value; - // database case "database.enabled" -> DATABASE_ENABLED = (boolean) value; case "database.user" -> DATABASE_USER = (String) value; @@ -54,14 +54,13 @@ public static void inportConfig(Map config) { case "database.port" -> DATABASE_PORT = toInt(value); case "database.name" -> DATABASE_NAME = (String) value; case "database.use_ssl" -> DATABASE_USE_SSL = (boolean) value; - // server case "server.proxy_mode" -> SERVER_PROXY_MODE = (boolean) value; case "server.secret" -> SERVER_SECRET = (String) value; case "server.port" -> SERVER_PORT = toInt(value); case "server.world_name" -> SERVER_WORLD_NAME = (String) value; case "server.spawn_point" -> SERVER_SPAWN_POS = PosSerializer.deserialize((String) value); - + case "server.hostname" -> SERVER_HOSTNAME = (String) value; // RabbitMQ case "rabbitmq.host" -> RABBITMQ_HOST = (String) value; case "rabbitmq.password" -> RABBITMQ_PASSWORD = (String) value; @@ -103,6 +102,7 @@ public static void loadEnvironmentVariables() { if (!(System.getenv("SERVER_PORT") == null)) CytosisSettings.SERVER_PORT = Integer.parseInt(System.getenv("SERVER_PORT")); if (!(System.getenv("SERVER_WORLD_NAME") == null)) CytosisSettings.SERVER_WORLD_NAME = System.getenv("SERVER_WORLD_NAME"); if (!(System.getenv("SERVER_SPAWN_POINT") == null)) CytosisSettings.SERVER_SPAWN_POS = PosSerializer.deserialize(System.getenv("SERVER_SPAWN_POINT")); + if (!(System.getenv("SERVER_HOSTNAME") == null)) CytosisSettings.SERVER_HOSTNAME = System.getenv("SERVER_HOSTNAME"); // RabbitMQ if (!(System.getenv("RABBITMQ_ENABLED") == null)) CytosisSettings.RABBITMQ_ENABLED = Boolean.parseBoolean(System.getenv("RABBITMQ_ENABLED")); if (!(System.getenv("RABBITMQ_HOST") == null)) CytosisSettings.RABBITMQ_HOST = System.getenv("RABBITMQ_HOST"); @@ -131,6 +131,7 @@ public static void loadCommandArgs() { if (!(System.getProperty("SERVER_PORT") == null)) CytosisSettings.SERVER_PORT = Integer.parseInt(System.getProperty("SERVER_PORT")); if (!(System.getProperty("SERVER_WORLD_NAME") == null)) CytosisSettings.SERVER_WORLD_NAME = System.getProperty("SERVER_WORLD_NAME"); if (!(System.getProperty("SERVER_SPAWN_POINT") == null)) CytosisSettings.SERVER_SPAWN_POS = PosSerializer.deserialize(System.getProperty("SERVER_SPAWN_POINT")); + if (!(System.getProperty("SERVER_HOSTNAME") == null)) CytosisSettings.SERVER_HOSTNAME = System.getProperty("SERVER_HOSTNAME"); // RabbitMQ if (!(System.getProperty("RABBITMQ_ENABLED") == null)) CytosisSettings.RABBITMQ_ENABLED = Boolean.parseBoolean(System.getProperty("RABBITMQ_ENABLED")); if (!(System.getProperty("RABBITMQ_HOST") == null)) CytosisSettings.RABBITMQ_HOST = System.getProperty("RABBITMQ_HOST"); diff --git a/src/main/java/net/cytonic/cytosis/data/Database.java b/src/main/java/net/cytonic/cytosis/data/Database.java index 0478a111..f634c400 100644 --- a/src/main/java/net/cytonic/cytosis/data/Database.java +++ b/src/main/java/net/cytonic/cytosis/data/Database.java @@ -10,9 +10,8 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; - +import net.cytonic.cytosis.data.enums.ChatChannel; import org.jetbrains.annotations.NotNull; - import net.cytonic.cytosis.Cytosis; import net.cytonic.cytosis.config.CytosisSettings; import net.cytonic.cytosis.logging.Logger; @@ -67,7 +66,6 @@ public void connect() { } } }); - } public void disconnect() { @@ -135,16 +133,6 @@ private void createRanksTable() { }); } - public void createNameTable() { - PreparedStatement ps; - try { - ps = getConnection().prepareStatement("CREATE TABLE IF NOT EXISTS cytonicnames (uuid VARCHAR(36), name VARCHAR(16), PRIMARY KEY(uuid))"); - ps.executeUpdate(); - } catch (SQLException e) { - Logger.error("An error occurred whilst creating the `cytonic_names` table.", e); - } - } - /** * Creates the 'cytonic_worlds' table in the database if it doesn't exist. * The table contains information about the worlds stored in the database. @@ -165,19 +153,25 @@ public void createWorldTable() { }); } - private void createChatChannelsTable() { - worker.submit(() -> { - if (isConnected()) { - PreparedStatement ps; - try { - ps = getConnection().prepareStatement("CREATE TABLE IF NOT EXISTS cytonic_chat_channels (player_uuid VARCHAR(36), chat_channel TEXT, PRIMARY KEY(player_uuid))"); - ps.executeUpdate(); - } catch (SQLException e) { - Logger.error("An error occurred whilst creating the `cytonic_chat_channels` table.", e); - } + /** + * Creates the 'cytonic_chat_channels' table in the database if it doesn't exist. + * The table contains information about player's chat channels. + * + * @throws IllegalStateException if the database connection is not open. + */ +private void createChatChannelsTable() { + worker.submit(() -> { + if (isConnected()) { + PreparedStatement ps; + try { + ps = getConnection().prepareStatement("CREATE TABLE IF NOT EXISTS cytonic_chat_channels (uuid VARCHAR(36), chat_channel TEXT, PRIMARY KEY(uuid))"); + ps.executeUpdate(); + } catch (SQLException e) { + Logger.error("An error occurred whilst creating the `cytonic_chat_channels` table.", e); } - }); - } + } + }); +} private void createPlayerJoinsTable() { worker.submit(() -> { @@ -264,43 +258,46 @@ public void addChat(UUID uuid, String message) { ps.setString(2, message); ps.executeUpdate(); } catch (SQLException e) { - Logger.error("An error occurred whilst adding a chat message.",e); + Logger.error("An error occurred whilst adding a chat message.", e); } }); } - public String getName(UUID uuid) { - PreparedStatement ps; - try { - ps = connection.prepareStatement("SELECT name FROM cytonicnames WHERE uuid = ?"); - ps.setString(1, uuid.toString()); - ResultSet rs = ps.executeQuery(); - if (rs.next()) { - return rs.getString("name"); + public void setChatChannel(UUID uuid, ChatChannel chatChannel) { + worker.submit(() -> { + if (!isConnected()) + throw new IllegalStateException("The database must have an open connection to add a player's chat!"); + PreparedStatement ps; + try { + ps = connection.prepareStatement("INSERT INTO cytonic_chat_channels (uuid, chat_channel) VALUES (?, ?) ON DUPLICATE KEY UPDATE chat_channel = VALUES(chat_channel)"); + ps.setString(1, uuid.toString()); + ps.setString(2, chatChannel.name()); + ps.executeUpdate(); + } catch (SQLException e) { + Logger.error("An error occurred whilst setting a players chat channel.", e); } - } catch (SQLException e) { - Logger.error(STR."An error occurred whilst fetching the name of '\{uuid}'"); - } - return "ERROR!"; + }); } - public UUID getUUID(String name) { - PreparedStatement ps; - try { - ps = connection.prepareStatement("SELECT uuid FROM cytonicnames WHERE name = ?"); - ps.setString(1, name); - ResultSet rs = ps.executeQuery(); - if (rs.next()) { - try { - return UUID.fromString(rs.getString("uuid")); - } catch (IllegalArgumentException ex) { - return null; + public CompletableFuture getChatChannel(@NotNull final UUID uuid) { + CompletableFuture future = new CompletableFuture<>(); + if (!isConnected()) + throw new IllegalStateException("The database must have an open connection to fetch a player's chat channel!"); + worker.submit(() -> { + String channel = "ALL"; + try { + PreparedStatement ps = connection.prepareStatement("SELECT chat_channel FROM cytonic_chat_channels WHERE uuid = ?"); + ps.setString(1, uuid.toString()); + ResultSet rs = ps.executeQuery(); + while (rs.next()) { + channel = rs.getString("chat_channel"); } + future.complete(ChatChannel.valueOf(channel)); + } catch (SQLException e) { + Logger.error(STR."An error occurred whilst fetching the chat channel of '\{uuid}'", e); } - } catch (SQLException e) { - Logger.error(STR."An error occurred whilst fetching the uuid of '\{name}'"); - } - return null; + }); + return future; } /** @@ -363,26 +360,26 @@ public CompletableFuture getWorld(String worldName) { } /** - * Logs a player's join event to the database. - * - * @param uuid The unique identifier of the player. - * @param ip The IP address of the player. - *

- * This method uses a worker thread to execute the database operation. - * It prepares a SQL statement to insert a new record into the 'cytonic_player_joins' table. - * The 'joined' column is set to the current timestamp, the 'uuid' column is set to the provided UUID, - * and the 'ip' column is set to the provided IP address. - * If an error occurs during the database operation, it is logged using the Logger. - */ -public void logPlayerJoin(UUID uuid, SocketAddress ip) { - worker.submit(() -> { - try (PreparedStatement ps = connection.prepareStatement("INSERT INTO cytonic_player_joins (joined, uuid, ip) VALUES (CURRENT_TIMESTAMP,?,?)")) { - ps.setString(1, uuid.toString()); - ps.setString(2, ip.toString()); - ps.executeUpdate(); - } catch (SQLException e) { - Logger.error("Failed to add a player to the database!", e); - } - }); -} + * Logs a player's join event to the database. + * + * @param uuid The unique identifier of the player. + * @param ip The IP address of the player. + *

+ * This method uses a worker thread to execute the database operation. + * It prepares a SQL statement to insert a new record into the 'cytonic_player_joins' table. + * The 'joined' column is set to the current timestamp, the 'uuid' column is set to the provided UUID, + * and the 'ip' column is set to the provided IP address. + * If an error occurs during the database operation, it is logged using the Logger. + */ + public void logPlayerJoin(UUID uuid, SocketAddress ip) { + worker.submit(() -> { + try (PreparedStatement ps = connection.prepareStatement("INSERT INTO cytonic_player_joins (joined, uuid, ip) VALUES (CURRENT_TIMESTAMP,?,?)")) { + ps.setString(1, uuid.toString()); + ps.setString(2, ip.toString()); + ps.executeUpdate(); + } catch (SQLException e) { + Logger.error("Failed to add a player to the database!", e); + } + }); + } } \ No newline at end of file diff --git a/src/main/java/net/cytonic/cytosis/data/objects/Request.java b/src/main/java/net/cytonic/cytosis/data/objects/Request.java deleted file mode 100644 index 0278e3e8..00000000 --- a/src/main/java/net/cytonic/cytosis/data/objects/Request.java +++ /dev/null @@ -1,66 +0,0 @@ -package net.cytonic.cytosis.data.objects; - -import java.time.Instant; -import java.util.UUID; - -public class Request { - private final Instant expiry; - private final UUID author; - private final UUID target; - private final RequestType type; - private final Instant issuedAt; - private boolean accepted; - private boolean declined; - - public Request(Instant expiry, UUID author, UUID target, RequestType type) { - this.expiry = expiry; - this.author = author; - this.target = target; - this.type = type; - issuedAt = Instant.now(); - accepted = false; - declined = false; - } - - public Instant getExpiry() { - return expiry; - } - - public RequestType getType() { - return type; - } - - public Instant getIssuedAt() { - return issuedAt; - } - - public UUID getAuthor() { - return author; - } - - public UUID getTarget() { - return target; - } - - public boolean isAccepted() { - return accepted; - } - - public boolean isDeclined() { - return declined; - } - - public void setAccepted(boolean accepted) { - this.accepted = accepted; - } - - public void setDeclined(boolean declined) { - this.declined = declined; - } - - public enum RequestType { - FRIEND, - LEAGUE, - PARTY - } -} diff --git a/src/main/java/net/cytonic/cytosis/events/EventHandler.java b/src/main/java/net/cytonic/cytosis/events/EventHandler.java index 021f3c54..cb4b75dc 100644 --- a/src/main/java/net/cytonic/cytosis/events/EventHandler.java +++ b/src/main/java/net/cytonic/cytosis/events/EventHandler.java @@ -79,8 +79,7 @@ public boolean registerListener(EventListener listener) { public void handleEvent(T event) { List> matchingListeners = new ArrayList<>(); for (EventListener listener : NAMESPACED_HANDLERS.values()) { - if (listener.getEventClass() == event.getClass() && - !(event instanceof CancellableEvent && ((CancellableEvent) event).isCancelled())) { + if (listener.getEventClass() == event.getClass() && !(event instanceof CancellableEvent && ((CancellableEvent) event).isCancelled())) { matchingListeners.add(listener); } } @@ -184,7 +183,6 @@ private void setupInternalListeners() { GLOBAL_HANDLER.addListener(ClientPingServerEvent.class, (this::handleEvent)); GLOBAL_HANDLER.addListener(ServerListPingEvent.class, (this::handleEvent)); GLOBAL_HANDLER.addListener(ServerTickMonitorEvent.class, (this::handleEvent)); - // Cytosis Events GLOBAL_HANDLER.addListener(RankSetupEvent.class, (this::handleEvent)); GLOBAL_HANDLER.addListener(RankChangeEvent.class, (this::handleEvent)); diff --git a/src/main/java/net/cytonic/cytosis/events/ServerEventListeners.java b/src/main/java/net/cytonic/cytosis/events/ServerEventListeners.java index 60f541a4..6c9fa00a 100644 --- a/src/main/java/net/cytonic/cytosis/events/ServerEventListeners.java +++ b/src/main/java/net/cytonic/cytosis/events/ServerEventListeners.java @@ -5,12 +5,12 @@ import net.cytonic.cytosis.data.enums.ChatChannel; import net.cytonic.cytosis.logging.Logger; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; import net.minestom.server.entity.Player; import net.minestom.server.event.player.AsyncPlayerConfigurationEvent; import net.minestom.server.event.player.PlayerChatEvent; import net.minestom.server.event.player.PlayerDisconnectEvent; import net.minestom.server.event.player.PlayerSpawnEvent; +import static net.cytonic.cytosis.utils.MiniMessageTemplate.MM; public class ServerEventListeners { @@ -28,6 +28,11 @@ public static void initServerEvents() { Logger.info(STR."\{player.getUsername()} (\{player.getUuid()}) joined with the ip: \{player.getPlayerConnection().getServerAddress()}"); Cytosis.getDatabaseManager().getDatabase().logPlayerJoin(player.getUuid(), player.getPlayerConnection().getRemoteAddress()); Cytosis.getRankManager().addPlayer(player); + Cytosis.getDatabaseManager().getDatabase().getChatChannel(player.getUuid()).whenComplete(((chatChannel, throwable) -> { + if (throwable != null) { + Logger.error("An error occurred whilst getting a player's chat channel!", throwable); + } else Cytosis.getChatManager().setChannel(player.getUuid(), chatChannel); + })); }))); Logger.info("Registering player chat event."); @@ -37,23 +42,29 @@ public static void initServerEvents() { Cytosis.getDatabaseManager().getDatabase().addChat(player.getUuid(), event.getMessage()); event.setCancelled(true); String originalMessage = event.getMessage(); - if(Cytosis.getChatManager().getChannel(player.getUuid()) != ChatChannel.ALL) { - ChatChannel channel = Cytosis.getChatManager().getChannel(player.getUuid()); - Component message = Component.text("") - .append(channel.getPrefix()) - .append(Cytosis.getRankManager().getPlayerRank(player.getUuid()).orElseThrow().getPrefix()) - .append(Component.text(player.getUsername(), (Cytosis.getRankManager().getPlayerRank(player.getUuid()).orElseThrow().getChatColor()))) - .appendSpace() - .append(Component.text(originalMessage, NamedTextColor.WHITE)); + if (!originalMessage.contains("|")) { + if (Cytosis.getChatManager().getChannel(player.getUuid()) != ChatChannel.ALL) { + ChatChannel channel = Cytosis.getChatManager().getChannel(player.getUuid()); + Component message = Component.text("") + .append(channel.getPrefix()) + .append(Cytosis.getRankManager().getPlayerRank(player.getUuid()).orElseThrow().getPrefix()) + .appendSpace() + .append(Component.text(player.getUsername(), (Cytosis.getRankManager().getPlayerRank(player.getUuid()).orElseThrow().getTeamColor()))) + .append(Component.text(":", Cytosis.getRankManager().getPlayerRank(player.getUuid()).orElseThrow().getChatColor())) + .appendSpace() + .append(Component.text(originalMessage, Cytosis.getRankManager().getPlayerRank(player.getUuid()).orElseThrow().getChatColor())); Cytosis.getChatManager().sendMessageToChannel(message, Cytosis.getChatManager().getChannel(player.getUuid())); } else { Component message = Component.text("") - .append(Cytosis.getRankManager().getPlayerRank(player.getUuid()).orElseThrow().getPrefix()) - .append(Component.text(player.getUsername(), (Cytosis.getRankManager().getPlayerRank(player.getUuid()).orElseThrow().getChatColor()))) - .appendSpace() - .append(Component.text(originalMessage, NamedTextColor.WHITE)); - Cytosis.getOnlinePlayers().forEach((p) -> {p.sendMessage(message);}); + .append(Cytosis.getRankManager().getPlayerRank(player.getUuid()).orElseThrow().getPrefix()) + .appendSpace() + .append(Component.text(player.getUsername(), (Cytosis.getRankManager().getPlayerRank(player.getUuid()).orElseThrow().getTeamColor()))) + .append(Component.text(":", Cytosis.getRankManager().getPlayerRank(player.getUuid()).orElseThrow().getChatColor())) + .appendSpace() + .append(Component.text(originalMessage, Cytosis.getRankManager().getPlayerRank(player.getUuid()).orElseThrow().getChatColor())); + Cytosis.getOnlinePlayers().forEach((p) -> p.sendMessage(message)); } + } else player.sendMessage(MM."Hey you cannot do that!"); })); Logger.info("Registering player disconnect event."); @@ -62,22 +73,4 @@ public static void initServerEvents() { Cytosis.getRankManager().removePlayer(player); })); } - - public static void chatEvent(PlayerChatEvent event) { - Player player = event.getPlayer(); - if(Cytosis.getChatManager().getChannel(player.getUuid()) != ChatChannel.ALL) { - ChatChannel channel = Cytosis.getChatManager().getChannel(player.getUuid()); - event.setCancelled(true); - String originalMessage = event.getMessage(); - Component message = Component.text("") - .append(channel.getPrefix()) - .append(Cytosis.getRankManager().getPlayerRank(player.getUuid()).orElseThrow().getPrefix()) - .append(Component.text(player.getUsername(), (Cytosis.getRankManager().getPlayerRank(player.getUuid()).orElseThrow().getChatColor()))) - .appendSpace() - .append(Component.text(originalMessage, NamedTextColor.WHITE)); - Cytosis.getChatManager().sendMessageToChannel(message, Cytosis.getChatManager().getChannel(player.getUuid())); - } else { - event.setCancelled(false); - } - } } \ No newline at end of file diff --git a/src/main/java/net/cytonic/cytosis/events/ranks/RankChangeEvent.java b/src/main/java/net/cytonic/cytosis/events/ranks/RankChangeEvent.java index 325788c1..364f0bb5 100644 --- a/src/main/java/net/cytonic/cytosis/events/ranks/RankChangeEvent.java +++ b/src/main/java/net/cytonic/cytosis/events/ranks/RankChangeEvent.java @@ -28,4 +28,4 @@ public boolean isCancelled() { public void setCancelled(boolean cancel) { this.canceled = cancel; } -} +} \ No newline at end of file diff --git a/src/main/java/net/cytonic/cytosis/events/ranks/RankSetupEvent.java b/src/main/java/net/cytonic/cytosis/events/ranks/RankSetupEvent.java index fd06ecf1..a85f4df4 100644 --- a/src/main/java/net/cytonic/cytosis/events/ranks/RankSetupEvent.java +++ b/src/main/java/net/cytonic/cytosis/events/ranks/RankSetupEvent.java @@ -27,4 +27,4 @@ public boolean isCancelled() { public void setCancelled(boolean canceled) { this.canceled = canceled; } -} +} \ No newline at end of file diff --git a/src/main/java/net/cytonic/cytosis/files/FileManager.java b/src/main/java/net/cytonic/cytosis/files/FileManager.java index 2514c57c..ec35fd4f 100644 --- a/src/main/java/net/cytonic/cytosis/files/FileManager.java +++ b/src/main/java/net/cytonic/cytosis/files/FileManager.java @@ -41,7 +41,6 @@ public CompletableFuture init() { */ public CompletableFuture createConfigFile() { CompletableFuture future = new CompletableFuture<>(); - worker.submit(() -> { if (!CONFIG_PATH.toFile().exists()) { Logger.info("No config file found, creating..."); @@ -131,14 +130,12 @@ private Map recursiveParse(Map map, String paren // If it's a list, check for nested tables within the list else if (value instanceof Iterable iterable) { for (Object item : iterable) { - if (item instanceof TomlTable toml) - resultMap.putAll(recursiveParse(toml.toMap(), key)); + if (item instanceof TomlTable toml) resultMap.putAll(recursiveParse(toml.toMap(), key)); } } else { resultMap.put(key, value); } } - return resultMap; } } \ No newline at end of file diff --git a/src/main/java/net/cytonic/cytosis/managers/ChatManager.java b/src/main/java/net/cytonic/cytosis/managers/ChatManager.java index dca764c9..35af4364 100644 --- a/src/main/java/net/cytonic/cytosis/managers/ChatManager.java +++ b/src/main/java/net/cytonic/cytosis/managers/ChatManager.java @@ -3,7 +3,6 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; - import net.cytonic.cytosis.Cytosis; import net.cytonic.cytosis.data.enums.ChatChannel; import net.kyori.adventure.text.Component; @@ -11,11 +10,14 @@ public class ChatManager { private final Map channels = new HashMap<>(); + public void removeChannel(UUID uuid) { channels.remove(uuid); } + public void setChannel(UUID uuid, ChatChannel channel) { channels.put(uuid, channel); + Cytosis.getDatabaseManager().getDatabase().setChatChannel(uuid,channel); } public ChatChannel getChannel(UUID uuid) { @@ -24,7 +26,7 @@ public ChatChannel getChannel(UUID uuid) { public void sendMessageToChannel(Component component, ChatChannel chatChannel) { switch (chatChannel) { - case ADMIN,MOD,STAFF -> // send a message to all servers + case ADMIN, MOD, STAFF -> // send a message to all servers Cytosis.getMessagingManager().getRabbitMQ().sendChatMessage(component, chatChannel); case PARTY -> { // parties.. @@ -35,8 +37,8 @@ public void sendMessageToChannel(Component component, ChatChannel chatChannel) { case PRIVATE_MESSAGE -> { // private messages } - case ALL -> throw new UnsupportedOperationException("Unimplemented case: " + chatChannel); - default -> throw new IllegalArgumentException("Unexpected value: " + chatChannel); + case ALL -> throw new UnsupportedOperationException(STR."Unimplemented case: \{chatChannel}"); + default -> throw new IllegalArgumentException(STR."Unexpected value: \{chatChannel}"); } } } \ No newline at end of file diff --git a/src/main/java/net/cytonic/cytosis/messaging/MessagingManager.java b/src/main/java/net/cytonic/cytosis/messaging/MessagingManager.java index ba7a331b..44fe832d 100644 --- a/src/main/java/net/cytonic/cytosis/messaging/MessagingManager.java +++ b/src/main/java/net/cytonic/cytosis/messaging/MessagingManager.java @@ -3,11 +3,8 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; - import lombok.Getter; import net.cytonic.cytosis.config.CytosisSettings; -import net.cytonic.cytosis.data.enums.ChatChannel; -import net.kyori.adventure.text.Component; public class MessagingManager { @@ -27,9 +24,8 @@ public CompletableFuture initialize() { if (rabbitMQ != null) { rabbitMQ.initializeConnection(); rabbitMQ.initializeQueues(); - rabbitMQ.sendServerDeclarationMessage(); + rabbitMQ.sendServerDeclarationMessage(); rabbitMQ.receiveChatMessages(); - rabbitMQ.sendChatMessage(Component.text("hello world!"), ChatChannel.ADMIN); } future.complete(null); }); diff --git a/src/main/java/net/cytonic/cytosis/messaging/RabbitMQ.java b/src/main/java/net/cytonic/cytosis/messaging/RabbitMQ.java index 85e5fdd7..03fbd002 100644 --- a/src/main/java/net/cytonic/cytosis/messaging/RabbitMQ.java +++ b/src/main/java/net/cytonic/cytosis/messaging/RabbitMQ.java @@ -1,15 +1,10 @@ package net.cytonic.cytosis.messaging; import java.io.IOException; -import java.net.InetAddress; -import java.net.UnknownHostException; +import java.net.*; +import java.nio.charset.StandardCharsets; import java.util.concurrent.TimeoutException; - -import com.rabbitmq.client.Channel; -import com.rabbitmq.client.Connection; -import com.rabbitmq.client.ConnectionFactory; -import com.rabbitmq.client.DeliverCallback; - +import com.rabbitmq.client.*; import net.cytonic.cytosis.Cytosis; import net.cytonic.cytosis.config.CytosisSettings; import net.cytonic.cytosis.data.enums.ChatChannel; @@ -21,7 +16,7 @@ public class RabbitMQ { public static final String SERVER_DECLARE_QUEUE = "server-declaration"; public static final String SHUTDOWN_QUEUE = "server-shutdown"; - public static final String CHAT_CHANNEL_QUEUE = "chat-channel"; + public static final String CHAT_CHANNEL_QUEUE = STR."chat-channel-\{CytosisSettings.SERVER_HOSTNAME}"; private Connection connection; private Channel channel; @@ -39,8 +34,7 @@ public void initializeConnection() { Logger.info("Connected to RabbitMQ!"); try { channel = connection.createChannel(); - connection = factory.newConnection(); - } catch (IOException | TimeoutException e) { + } catch (IOException e) { Logger.error("An error occurred whilst connecting to RabbitMQ!", e); } } @@ -58,9 +52,9 @@ public void initializeQueues() { Logger.error("An error occurred whilst initializing the 'SHUTDOWN_QUEUE'.", e); } try { + channel.exchangeDeclare("chat-testing", BuiltinExchangeType.FANOUT); channel.queueDeclare(CHAT_CHANNEL_QUEUE, false, false, false, null); - channel.exchangeDeclare("chat-messages", "fanout"); - channel.queueBind(CHAT_CHANNEL_QUEUE, "chat-messages", ""); + channel.queueBind(CHAT_CHANNEL_QUEUE,"chat-testing",""); } catch (IOException e) { Logger.error("An error occurred whilst initializing the 'CHAT_CHANNEL_QUEUE'.", e); } @@ -68,7 +62,6 @@ public void initializeQueues() { public void sendServerDeclarationMessage() { //formatting: {server-name}|:|{server-ip}|:|{server-port} - String serverName = System.getenv("HOSTNAME"); String serverIP; try { serverIP = InetAddress.getLocalHost().getHostAddress(); @@ -76,7 +69,7 @@ public void sendServerDeclarationMessage() { Logger.error("An error occurred whilst fetching this server's IP address! Bailing out!", e); return; } - String message = STR."\{serverName}|:|\{serverIP}|:|\{CytosisSettings.SERVER_PORT}"; + String message = STR."\{CytosisSettings.SERVER_HOSTNAME}|:|\{serverIP}|:|\{CytosisSettings.SERVER_PORT}"; try { channel.basicPublish("", SERVER_DECLARE_QUEUE, null, message.getBytes()); } catch (IOException e) { @@ -85,54 +78,59 @@ public void sendServerDeclarationMessage() { Logger.info(STR."Server Declaration message sent! '\{message}'."); } - public void sendChatMessage(Component chatMessage, ChatChannel chatChannel) { - //formatting: {chat-message}|{chat-channel} - String message = STR."\{JSONComponentSerializer.json().serialize(chatMessage)}|\{chatChannel.name()}"; - try { - channel.basicPublish("chat-messages", CHAT_CHANNEL_QUEUE, null, message.getBytes()); - } catch (IOException e) { - Logger.error("An error occurred whilst attempting to send a chat message!", e); - } + /** + * Sends a chat message to all the servers. + * + * @param chatMessage The chat message to be sent. This should be a {@link Component}. + * @param chatChannel The channel to which the chat message should be sent. + * + */ +public void sendChatMessage(Component chatMessage, ChatChannel chatChannel) { + // Formatting: {chat-message}|:|{chat-channel} + String message = STR."\{JSONComponentSerializer.json().serialize(chatMessage)}|\{chatChannel.name()}"; + try { + channel.basicPublish("chat-testing","", null, message.getBytes()); + } catch (IOException e) { + Logger.error("An error occurred whilst attempting to send a chat message!", e); } +} public void receiveChatMessages() { try { - DeliverCallback deliverCallback = (consumerTag, delivery) -> { - String[] thing = new String(delivery.getBody(), "UTF-8").split("\\|"); - Component chatMessage = JSONComponentSerializer.json().deserialize(thing[0]); - ChatChannel chatChannel = ChatChannel.valueOf(thing[1]); - switch (chatChannel) { - case MOD -> // send a message to all players with cytonic.chat.mod permission - Cytosis.getOnlinePlayers().forEach(player -> { - if (player.hasPermission("cytonic.chat.mod")) { - player.sendMessage(chatMessage); - } - }); + DeliverCallback deliverCallback = (_, delivery) -> { + String[] thing = new String(delivery.getBody(), StandardCharsets.UTF_8).split("\\|"); + Component chatMessage = JSONComponentSerializer.json().deserialize(thing[0]); + ChatChannel chatChannel = ChatChannel.valueOf(thing[1]); + switch (chatChannel) { + case MOD -> // send a message to all players with cytonic.chat.mod permission + Cytosis.getOnlinePlayers().forEach(player -> { + if (player.hasPermission("cytonic.chat.mod")) { + player.sendMessage(chatMessage); + } + }); - case STAFF -> // send a message to all players with cytonic.chat.staff permission - Cytosis.getOnlinePlayers().forEach(player -> { - if (player.hasPermission("cytonic.chat.staff")) { - player.sendMessage(chatMessage); - } - }); - case ADMIN -> // send a message to all players with cytonic.chat.admin permission - Cytosis.getOnlinePlayers().forEach(player -> { - if (player.hasPermission("cytonic.chat.admin")) { - player.sendMessage(chatMessage); - } - }); - case LEAGUE -> { - // leagues.. - } + case STAFF -> // send a message to all players with cytonic.chat.staff permission + Cytosis.getOnlinePlayers().forEach(player -> { + if (player.hasPermission("cytonic.chat.staff")) { + player.sendMessage(chatMessage); + } + }); + case ADMIN -> // send a message to all players with cytonic.chat.admin permission + Cytosis.getOnlinePlayers().forEach(player -> { + if (player.hasPermission("cytonic.chat.admin")) { + player.sendMessage(chatMessage); + } + }); + case LEAGUE -> {// leagues.. + } - case PARTY -> { - // parties.. - } + case PARTY -> {// parties.. + } + } + }; + channel.basicConsume(CHAT_CHANNEL_QUEUE, true, deliverCallback, _ -> {}); + } catch (IOException e) { + Logger.error("error", e); } - }; - channel.basicConsume(CHAT_CHANNEL_QUEUE, true, deliverCallback, consumerTag -> { }); -} catch (IOException e) { - Logger.error("error", e); -} -} + } } \ No newline at end of file diff --git a/src/main/java/net/cytonic/cytosis/ranks/PlayerRank.java b/src/main/java/net/cytonic/cytosis/ranks/PlayerRank.java index 606cf646..f63d0a38 100644 --- a/src/main/java/net/cytonic/cytosis/ranks/PlayerRank.java +++ b/src/main/java/net/cytonic/cytosis/ranks/PlayerRank.java @@ -57,13 +57,11 @@ public static boolean canChangeRank(PlayerRank currentUserRole, PlayerRank targe if (isDemotion(targetOriginalRole, targetNewRole)) { return currentUserRole.ordinal() <= targetOriginalRole.ordinal(); } - if (isPromotion(targetOriginalRole, targetNewRole)) { return currentUserRole.ordinal() <= targetOriginalRole.ordinal(); } - // If it's neither promotion nor demotion, it's an invalid operation return false; } -} +} \ No newline at end of file diff --git a/src/main/java/net/cytonic/cytosis/ranks/RankManager.java b/src/main/java/net/cytonic/cytosis/ranks/RankManager.java index 6028c580..9a63d0c7 100644 --- a/src/main/java/net/cytonic/cytosis/ranks/RankManager.java +++ b/src/main/java/net/cytonic/cytosis/ranks/RankManager.java @@ -12,7 +12,6 @@ import net.minestom.server.scoreboard.Team; import net.minestom.server.scoreboard.TeamBuilder; import org.jetbrains.annotations.NotNull; - import java.util.Optional; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @@ -28,7 +27,6 @@ public void init() { .teamColor(value.getTeamColor()) .prefix(value.getPrefix().appendSpace()) .build(); - teamMap.put(value, team); } } @@ -83,4 +81,4 @@ public final void removePermissions(@NotNull final Player player, @NotNull final public Optional getPlayerRank(UUID uuid) { return Optional.ofNullable(rankMap.get(uuid)); } -} +} \ No newline at end of file diff --git a/src/main/resources/config.toml b/src/main/resources/config.toml index 684c6fb0..c885f7c0 100644 --- a/src/main/resources/config.toml +++ b/src/main/resources/config.toml @@ -15,6 +15,7 @@ secret = "hi i am the secret" # this can NOT be empty port = 25565 world_name = "" spawn_point = "" +hostname = "UNKNOWN" # Logging Configuration # Enable/disable logging for various player activities