From 406b4d08c2b4e3c1576c284863dcebfabdfef81b Mon Sep 17 00:00:00 2001 From: Caden Feller Date: Mon, 12 Aug 2024 19:49:07 -0700 Subject: [PATCH] completley server-side, better message configuration --- .settings/org.eclipse.buildship.core.prefs | 2 +- .../proxymessages/ProxyMessages.class | Bin 0 -> 1504 bytes ProxyMessagesPaper/bin/main/plugin.yml | 6 ++ .../proxymessages/ProxyMessages.java | 8 +- .../listener/MessageListener.java | 91 ------------------ .../src/main/resources/plugin.yml | 2 +- ProxyMessagesVelocity/.factorypath | 2 +- .../bin/default/velocity-plugin.json | 1 + ProxyMessagesVelocity/bin/main/config.yml | 27 ++++++ .../proxymessages/ProxyMessages.class | Bin 0 -> 7736 bytes .../proxymessages/util/MessageUtil.class | Bin 0 -> 3057 bytes .../proxymessages/ProxyMessages.java | 67 ++++++++----- .../proxymessages/util/MessageUtil.java | 73 ++++++++++++++ .../src/main/resources/config.yml | 11 +++ README.md | 7 +- 15 files changed, 172 insertions(+), 125 deletions(-) create mode 100644 ProxyMessagesPaper/bin/main/dev/ogblackdiamond/proxymessages/ProxyMessages.class create mode 100644 ProxyMessagesPaper/bin/main/plugin.yml delete mode 100644 ProxyMessagesPaper/src/main/java/dev/ogblackdiamond/proxymessages/listener/MessageListener.java create mode 100644 ProxyMessagesVelocity/bin/default/velocity-plugin.json create mode 100644 ProxyMessagesVelocity/bin/main/config.yml create mode 100644 ProxyMessagesVelocity/bin/main/dev/ogblackdiamond/proxymessages/ProxyMessages.class create mode 100644 ProxyMessagesVelocity/bin/main/dev/ogblackdiamond/proxymessages/util/MessageUtil.class create mode 100644 ProxyMessagesVelocity/src/main/java/dev/ogblackdiamond/proxymessages/util/MessageUtil.java diff --git a/.settings/org.eclipse.buildship.core.prefs b/.settings/org.eclipse.buildship.core.prefs index d20e549..f06ead8 100644 --- a/.settings/org.eclipse.buildship.core.prefs +++ b/.settings/org.eclipse.buildship.core.prefs @@ -5,7 +5,7 @@ connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) connection.project.dir= eclipse.preferences.version=1 gradle.user.home= -java.home=/home/caden/.sdkman/candidates/java/21.0.4-oracle +java.home=/usr/lib/jvm/java-21-openjdk-21.0.4.0.7-2.fc40.x86_64 jvm.arguments= offline.mode=false override.workspace.settings=true diff --git a/ProxyMessagesPaper/bin/main/dev/ogblackdiamond/proxymessages/ProxyMessages.class b/ProxyMessagesPaper/bin/main/dev/ogblackdiamond/proxymessages/ProxyMessages.class new file mode 100644 index 0000000000000000000000000000000000000000..d7d97f82953e31ece6bcfc347e11f13a3ca44f81 GIT binary patch literal 1504 zcmb7E+foxj5IqwD3(EpR1OZWkD1?g)ctwL)NMTu2uuv#`uzc8%VHvWSiJM&tKFb$G zAN&A6%CdJ7LsEh%A2PGu(|!8%nd$ue_5BBcHN3QtU|1-KW3Iit@9q~1(k*FK;N?J{ zoR&nT;(DUOw_|IoW?4uwOz6Pl`KVZwAus!pClx<(k6pe=%eJvCbTEuGgo$IJLY|YA zP$&^FbgW1v!&Qd1%*-A`a$OgMjW%>Uu+YiSmy=4ojY@eD?7DehFbw4MzU%L~fsE~% zGZ`Mr3d3UV|GLOBbZWJsVk8>_xNafE(BHuKmFdpGAch#Oc_OU#wdE?(g!oTpW^xVT zH5HnIvfUWQsD%-R@fM*DZeom~HxOQ|P_PlJMSU%28jCb*m~A|2s-Ks?N zE@Ge4o}oQPw9QpTq4c>=Ua34@JljhT*HA9ZVxbw=C6xW*E#=IruKs-U$OjB+3kqR@=UNDuPWd6~p``&6mwNzX&r* zne37GkqTu=?8%CxYh6=Hhi)jfA|1yYwW`W!65qJ0;ENz@V*!g6IKylz literal 0 HcmV?d00001 diff --git a/ProxyMessagesPaper/bin/main/plugin.yml b/ProxyMessagesPaper/bin/main/plugin.yml new file mode 100644 index 0000000..62f5be0 --- /dev/null +++ b/ProxyMessagesPaper/bin/main/plugin.yml @@ -0,0 +1,6 @@ +name: ProxyMessages +version: 1.1.0 +main: dev.ogblackdiamond.proxymessages.ProxyMessages +description: Paper plugin to interface with Velocity +author: BlackDiamond +api-version: '1.21' diff --git a/ProxyMessagesPaper/src/main/java/dev/ogblackdiamond/proxymessages/ProxyMessages.java b/ProxyMessagesPaper/src/main/java/dev/ogblackdiamond/proxymessages/ProxyMessages.java index fff2d81..187900b 100644 --- a/ProxyMessagesPaper/src/main/java/dev/ogblackdiamond/proxymessages/ProxyMessages.java +++ b/ProxyMessagesPaper/src/main/java/dev/ogblackdiamond/proxymessages/ProxyMessages.java @@ -1,7 +1,5 @@ package dev.ogblackdiamond.proxymessages; -import dev.ogblackdiamond.proxymessages.listener.MessageListener; - import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -14,15 +12,11 @@ */ public class ProxyMessages extends JavaPlugin implements Listener { - MessageListener listener; - @Override public void onEnable() { Bukkit.getPluginManager().registerEvents(this, this); - listener = new MessageListener(this); - - Bukkit.getLogger().info("Thank you for using ProxyMessages"); + Bukkit.getLogger().info("[ProxyMessages] Thank you for using ProxyMessages"); } diff --git a/ProxyMessagesPaper/src/main/java/dev/ogblackdiamond/proxymessages/listener/MessageListener.java b/ProxyMessagesPaper/src/main/java/dev/ogblackdiamond/proxymessages/listener/MessageListener.java deleted file mode 100644 index 0a655e0..0000000 --- a/ProxyMessagesPaper/src/main/java/dev/ogblackdiamond/proxymessages/listener/MessageListener.java +++ /dev/null @@ -1,91 +0,0 @@ -package dev.ogblackdiamond.proxymessages.listener; - -import com.google.common.io.ByteArrayDataInput; -import com.google.common.io.ByteStreams; - -import dev.ogblackdiamond.proxymessages.ProxyMessages; - -import net.kyori.adventure.audience.Audience; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.format.TextDecoration; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.plugin.messaging.PluginMessageListener; - - -/** - * Listens for messages from the velocity plugin. - */ -public class MessageListener implements PluginMessageListener { - - - public MessageListener(ProxyMessages proxyMessages) { - proxyMessages.getServer().getMessenger() - .registerIncomingPluginChannel(proxyMessages, "proxymessages:main", this); - } - - - @Override - public void onPluginMessageReceived(String channel, Player player, byte[] message) { - if (!channel.equals("proxymessages:main")) { - return; - } - - ByteArrayDataInput in = ByteStreams.newDataInput(message); - - String type = in.readUTF(); - String playerString = in.readUTF(); - - Component text; - - switch (type) { - - case "join": { - - text = Component.text() - .content(playerString).color(NamedTextColor.YELLOW).decoration(TextDecoration.BOLD, true) - .append(Component.text(" joined the network").decoration(TextDecoration.BOLD, false)) - .build(); - break; - } - - case "switch": { - - String previousServer = in.readUTF(); - String currentServer = in.readUTF(); - - text = Component.text() - .content(playerString).color(NamedTextColor.YELLOW).decoration(TextDecoration.BOLD, true) - .append(Component.text(" left ").decoration(TextDecoration.BOLD, false)) - .append(Component.text(previousServer).decoration(TextDecoration.BOLD, true)) - .append(Component.text(" and joined ").decoration(TextDecoration.BOLD, false)) - .append(Component.text(currentServer).decoration(TextDecoration.BOLD, true)) - .build(); - break; - } - - case "quit": { - - text = Component.text() - .content(playerString).color(NamedTextColor.YELLOW).decoration(TextDecoration.BOLD, true) - .append(Component.text(" left the network").decoration(TextDecoration.BOLD, false)) - .build(); - break; - } - - default: { - Bukkit.getLogger().warning("INVALID TYPE PASSED"); - return; - } - - } - - Audience audience = Bukkit.getServer(); - - audience.sendMessage(text); - - } - -} diff --git a/ProxyMessagesPaper/src/main/resources/plugin.yml b/ProxyMessagesPaper/src/main/resources/plugin.yml index 62f5be0..670ea22 100644 --- a/ProxyMessagesPaper/src/main/resources/plugin.yml +++ b/ProxyMessagesPaper/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: ProxyMessages -version: 1.1.0 +version: 2.0.0 main: dev.ogblackdiamond.proxymessages.ProxyMessages description: Paper plugin to interface with Velocity author: BlackDiamond diff --git a/ProxyMessagesVelocity/.factorypath b/ProxyMessagesVelocity/.factorypath index 656ad74..b2aa666 100644 --- a/ProxyMessagesVelocity/.factorypath +++ b/ProxyMessagesVelocity/.factorypath @@ -26,11 +26,11 @@ + - diff --git a/ProxyMessagesVelocity/bin/default/velocity-plugin.json b/ProxyMessagesVelocity/bin/default/velocity-plugin.json new file mode 100644 index 0000000..52164a2 --- /dev/null +++ b/ProxyMessagesVelocity/bin/default/velocity-plugin.json @@ -0,0 +1 @@ +{"id":"proxymessages","name":"Proxy Messages","version":"2.0.0","description":"A message system for servers to interact over a proxy.","authors":["BlackDiamond"],"dependencies":[],"main":"dev.ogblackdiamond.proxymessages.ProxyMessages"} \ No newline at end of file diff --git a/ProxyMessagesVelocity/bin/main/config.yml b/ProxyMessagesVelocity/bin/main/config.yml new file mode 100644 index 0000000..1ed6979 --- /dev/null +++ b/ProxyMessagesVelocity/bin/main/config.yml @@ -0,0 +1,27 @@ +# enables a network-wide join message for when a player joins the network +global-network-join: true + +# enables a network-wide leave message for when a player leaves the network +global-network-leave: true + +# enables a network-wide message that notifies players when a player switches between servers when true +global-network-switch: true + +# options from this list will be randomly chosen to be displayed when a player joins the network +# {player} will be replaced by the player name +join-message-options: + - "{player} joined the network" + +# options from this list will be randomly chosen to be displayed when a player leaves the network +# {player} will be replaced by the player name +leave-message-options: + - "{player} left the network" + +# options from this list will be randomly chosen to be displayed when a player changes between two servers on the network +# {player} will be replaced by the player name +# {prev} will be replaced by the server the player is connecting from +# {cur} will be replaced by the server the player is connecting to +switch-message-options: + - "{player} left {prev} and joined {cur}" + + diff --git a/ProxyMessagesVelocity/bin/main/dev/ogblackdiamond/proxymessages/ProxyMessages.class b/ProxyMessagesVelocity/bin/main/dev/ogblackdiamond/proxymessages/ProxyMessages.class new file mode 100644 index 0000000000000000000000000000000000000000..bdc1984e4cf31a2aeeac028bc91992655716d27d GIT binary patch literal 7736 zcmbtZ349dQ8UMdz!z9^(XaFT%EQjPGS-=C#LL?+Xqaj2BcvhWcht0t5&N?$22;$kp zYOS}eTD4MZX|>kcN+ep9URtfK)}Ge3_OP|~u=k<0rT_P4H=AtO1ocOfnfJc$ecw0V z{XL%f-y@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MessagesVelocity/src/main/java/dev/ogblackdiamond/proxymessages/ProxyMessages.java index b2b1e05..b41c6c7 100644 --- a/ProxyMessagesVelocity/src/main/java/dev/ogblackdiamond/proxymessages/ProxyMessages.java +++ b/ProxyMessagesVelocity/src/main/java/dev/ogblackdiamond/proxymessages/ProxyMessages.java @@ -14,6 +14,11 @@ import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; import com.velocitypowered.api.proxy.server.RegisteredServer; +import dev.ogblackdiamond.proxymessages.util.MessageUtil; +import net.kyori.adventure.text.Component; + +import java.util.List; +import java.util.Random; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; @@ -26,7 +31,7 @@ /** * Main class for ProxyMessages. */ -@Plugin(id = "proxymessages", name = "Proxy Messages", version = "1.1.0", +@Plugin(id = "proxymessages", name = "Proxy Messages", version = "2.0.0", description = "A message system for servers to interact over a proxy.", authors = {"BlackDiamond"}) public class ProxyMessages { @@ -37,6 +42,7 @@ public class ProxyMessages { @DataDirectory private final Path dataDirectory; + private MessageUtil messageUtil; private boolean globalJoin; @@ -44,6 +50,12 @@ public class ProxyMessages { private boolean globalSwitch; + private List joinMessageOptions; + + private List leaveMessageOptions; + + private List switchMessageOptions; + /** * Constructor, initializes the logger and the proxy server. */ @@ -53,6 +65,8 @@ public ProxyMessages(ProxyServer server, Logger logger, @DataDirectory Path data this.logger = logger; this.dataDirectory = dataDirectory; + messageUtil = new MessageUtil(); + logger.info("Thank you for using ProxyMessages"); } @@ -76,7 +90,10 @@ public void onProxyInitialization(ProxyInitializeEvent event) throws IOException globalLeave = root.node("global-network-leave").getBoolean(); globalSwitch = root.node("global-network-switch").getBoolean(); - + + joinMessageOptions = root.node("join-message-options").getList(String.class); + leaveMessageOptions = root.node("leave-message-options").getList(String.class); + switchMessageOptions = root.node("switch-message-options").getList(String.class); } /** @@ -90,20 +107,26 @@ public void onPlayerConnect(ServerPostConnectEvent event) { if (event.getPreviousServer() == null && !globalJoin) return; Player player = event.getPlayer(); + + boolean previousServerNull = event.getPreviousServer() == null; - ByteArrayDataOutput out = ByteStreams.newDataOutput(); - - out.writeUTF(event.getPreviousServer() == null ? "join" : "switch"); - out.writeUTF(player.getUsername()); - + String message; if (event.getPreviousServer() != null) { - out.writeUTF(event.getPreviousServer().getServerInfo().getName()); - out.writeUTF(player.getCurrentServer().get().getServerInfo().getName()); + message = switchMessageOptions.get(new Random().nextInt(switchMessageOptions.size())); + } else { + message = joinMessageOptions.get(new Random().nextInt(switchMessageOptions.size())); } - sendMessage(out.toByteArray()); - + sendMessage( + messageUtil.compileFormattedMessage( + event.getPreviousServer() == null ? "join" : "switch", + player.getUsername(), + previousServerNull ? "" : event.getPreviousServer().getServerInfo().getName(), + previousServerNull ? "" : player.getCurrentServer().get().getServerInfo().getName(), + message + ) + ); } /** @@ -116,23 +139,23 @@ public void onPlayerDisconnect(DisconnectEvent event) { Player player = event.getPlayer(); - ByteArrayDataOutput out = ByteStreams.newDataOutput(); - - out.writeUTF("quit"); - out.writeUTF(player.getUsername()); - - sendMessage(out.toByteArray()); + sendMessage( + messageUtil.compileFormattedMessage( + "quit", + player.getUsername(), + "", + "", + leaveMessageOptions.get(new Random().nextInt(switchMessageOptions.size())) + ) + ); } - private void sendMessage(byte[] message) { + private void sendMessage(Component message) { for (RegisteredServer srvr : server.getAllServers()) { if (!srvr.getPlayersConnected().isEmpty()) { - srvr.sendPluginMessage( - MinecraftChannelIdentifier.from("proxymessages:main"), - message - ); + srvr.sendMessage(message); } } } diff --git a/ProxyMessagesVelocity/src/main/java/dev/ogblackdiamond/proxymessages/util/MessageUtil.java b/ProxyMessagesVelocity/src/main/java/dev/ogblackdiamond/proxymessages/util/MessageUtil.java new file mode 100644 index 0000000..2a8d199 --- /dev/null +++ b/ProxyMessagesVelocity/src/main/java/dev/ogblackdiamond/proxymessages/util/MessageUtil.java @@ -0,0 +1,73 @@ +package dev.ogblackdiamond.proxymessages.util; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextDecoration; + +public class MessageUtil { + + public Component compileFormattedMessage(String type, String playerName, String previousServer, String newServer, String chosenMessage) { + + TextComponent.Builder finalMessage = Component.text().color(NamedTextColor.YELLOW); + + int messageLength = chosenMessage.length(); + int playerNameLength = "{player}".length(); + int previousServerNameLength = "{prev}".length(); + int newServerNameLength = "{cur}".length(); + + + + // builds the final component, interpolating the correct strings when need + switch (type) { + + case "join": + case "leave": { + + for (int i = 0; i < messageLength; i++) { + + boolean atLength = i + playerNameLength > messageLength; + + if (!atLength && chosenMessage.substring(i, i + playerNameLength).equals("{player}")) { + finalMessage.append(Component.text(playerName).decoration(TextDecoration.BOLD, true)); + i += playerNameLength - 1; + } else { + finalMessage.append(Component.text(chosenMessage.substring(i, i+1)).decoration(TextDecoration.BOLD, false)); + } + } + break; + } + + case "switch": { + + for (int i = 0; i < messageLength; i++) { + + boolean playerAtLength = i + playerNameLength > messageLength; + boolean previousServerLength = i + previousServerNameLength > messageLength; + boolean newServerLength = i + newServerNameLength > messageLength; + + if (!playerAtLength && chosenMessage.substring(i, i + playerNameLength).equals("{player}")) { + finalMessage.append(Component.text(playerName).decoration(TextDecoration.BOLD, true)); + i += playerNameLength - 1; + } else if (!previousServerLength && chosenMessage.substring(i, i + previousServerNameLength).equals("{prev}")) { + finalMessage.append(Component.text(previousServer).decoration(TextDecoration.BOLD, true)); + i += previousServerNameLength - 1; + } else if (!newServerLength && chosenMessage.substring(i, i + newServerNameLength).equals("{cur}")) { + finalMessage.append(Component.text(newServer).decoration(TextDecoration.BOLD, true)); + i += newServerNameLength - 1; + } else { + finalMessage.append(Component.text(chosenMessage.substring(i, i+1)).decoration(TextDecoration.BOLD, false)); + } + } + break; + } + + default: { + return Component.text("[ProxyMessages] Invalid type passed! Cannot render message."); + } + + } + + return finalMessage.build(); + } +} diff --git a/ProxyMessagesVelocity/src/main/resources/config.yml b/ProxyMessagesVelocity/src/main/resources/config.yml index cfac932..dbdd3d1 100644 --- a/ProxyMessagesVelocity/src/main/resources/config.yml +++ b/ProxyMessagesVelocity/src/main/resources/config.yml @@ -6,3 +6,14 @@ global-network-leave: true # enables a network-wide message that notifies players when a player switches between servers when true global-network-switch: true + +join-message-options: + - "{player} joined the network" + +leave-message-options: + - "{player} left the network" + +switch-message-options: + - "{player} left {prev} and joined {cur}" + + diff --git a/README.md b/README.md index beec09d..71c2719 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,10 @@ A minecraft plugin for server to interact over a proxy. Currently, the only support is for Velocity and Paper. ## About -This plugin will remove boring "Player has joined the game" messages from in game. Instead, everyone on every server in the network will be notified when someone joins the network, when they switch between two servers, and when they disconnect from the network. +This plugin will send messages to every player on every server in the network to notify when someone joins the network, when they switch between two servers, and when they disconnect from the network. ## Usage -Place each jar in their respective plugin folders, and run your server(s) and proxy! Its as easy as that. +This plugin is only required to be on the proxy server. However, the vanilla "{player} has joined the game." messages will still appear. I reccommend using a plugin on all of your backend servers to remove this message. I created and built one for your convenience, but it has no correlation to the function of the proxy plugin. Use whatever plugin you like. ### Configuration All configuration is proxy side, no need to copy configurations between backend servers. @@ -15,6 +15,9 @@ In `plugins/proxymessages/config.yml` of your proxy server: * global-network-join: enables and disables the join message that all users on the network recieve when a player joins the network. * global-network-leave: enables and disables the leave message that all users on the network recieve when a player leaves the network. * global-network-switch: enables and disables the switch message that all users on the network recieve when a player switches between servers on the network. +* join-message-options: a list of messages that will be randomly chosen to be displayed when a player joins the network. Any instance of `{player}` in the string will be replaced with the relevant username. +* leave-message-options: a list of messages that will be randomly chosen to be displayed when a player leaves the network. Any instance of `{player}` in the string will be replaced with the relevant username. +* switch-message-options: a list of messages that will be randomly chosen to be displayed when a player switches between servers on the network. Any instance of `{player}` will be replaced with the relevant username. Any instance of `{prev}` will be replaced by the server that the player is connecting from. Any instance of `{cur}` will be replaced by the server that the player is connecting to. ## Building I use gradle to build this plugin. Ensure you have Java 21 or older and run `./gradle build` on Linux & MacOS, or `.\gradle.bat build` on Windows. Given that the build succeeds, the jars will spawn under their respective directories, in the `build/libs/` directory in each subproject.