diff --git a/README.md b/README.md
index b26f417..9ea13ce 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@ I was disappointed with the current options so I made my own plugin. I hope its
- **Global chat**: your player's voice is echoed across your whole velocity network
- **Log to console**: the chat can be sent to your console (configurable, can be disabled)
- **Configurable format**: chat format can be changed or formatted using MiniMessage tags (or translated!)
-- **Global join/quit messages**: let your whole network know when a player joins or quits the velocity proxy (goes well with [HidePlayerJoinQuit](https://github.com/OskarZyg/HidePlayerJoinQuit/releases) or [SilentJoin](https://www.spigotmc.org/resources/silentjoin.34967/))
+- **Global join/leave messages**: let your whole network know when a player joins or leaves the velocity proxy (goes well with [HidePlayerJoinQuit](https://github.com/OskarZyg/HidePlayerJoinQuit/releases) or [SilentJoin](https://www.spigotmc.org/resources/silentjoin.34967/))
- **Server switch messages**
## Installation
diff --git a/build.gradle b/build.gradle
index e696e81..de6f34d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,19 +1,14 @@
plugins {
id 'java'
id 'eclipse'
- id 'org.jetbrains.gradle.plugin.idea-ext' version '1.0.1'
- id 'com.github.johnrengelman.shadow' version '7.0.0'
+ id 'org.jetbrains.gradle.plugin.idea-ext' version '1.1.7'
+ id 'com.github.johnrengelman.shadow' version '8.1.1'
}
group = 'me.confor.velocity'
version = '0.1.0'
repositories {
- mavenCentral()
- /*maven {
- name = 'velocitypowered-repo'
- url = 'https://nexus.velocitypowered.com/repository/maven-public/'
- }*/
maven {
name = 'papermc-repo'
url = 'https://repo.papermc.io/repository/maven-public/'
@@ -21,12 +16,12 @@ repositories {
}
dependencies {
- compileOnly 'com.velocitypowered:velocity-api:3.1.2-SNAPSHOT'
- annotationProcessor 'com.velocitypowered:velocity-api:3.1.2-SNAPSHOT'
+ compileOnly 'com.velocitypowered:velocity-api:3.2.0-SNAPSHOT'
+ annotationProcessor 'com.velocitypowered:velocity-api:3.2.0-SNAPSHOT'
// templating dependency
- implementation 'net.kyori:adventure-api:4.11.0-SNAPSHOT'
- implementation 'net.kyori:adventure-text-minimessage:4.11.0-SNAPSHOT'
+ implementation 'net.kyori:adventure-api:4.14.0'
+ implementation 'net.kyori:adventure-text-minimessage:4.14.0'
}
def targetJavaVersion = 17
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
index 249e583..943f0cb 100644
Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 8049c68..37aef8d 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
+networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
index a69d9cb..65dcd68 100755
--- a/gradlew
+++ b/gradlew
@@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
-# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -80,10 +80,10 @@ do
esac
done
-APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
-
-APP_NAME="Gradle"
+# This is normally unused
+# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
+APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
@@ -143,12 +143,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
+ # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
+ # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
diff --git a/gradlew.bat b/gradlew.bat
index 53a6b23..6689b85 100644
--- a/gradlew.bat
+++ b/gradlew.bat
@@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
+@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
diff --git a/src/main/java/me/confor/velocity/chat/Config.java b/src/main/java/me/confor/velocity/chat/Config.java
index d7e6fc5..373050e 100644
--- a/src/main/java/me/confor/velocity/chat/Config.java
+++ b/src/main/java/me/confor/velocity/chat/Config.java
@@ -14,7 +14,7 @@
import java.util.regex.Pattern;
public class Config {
- static final long CONFIG_VERSION = 4;
+ static final long CONFIG_VERSION = 6;
Path dataDir;
Toml toml;
@@ -33,14 +33,19 @@ public class Config {
public TextReplacementConfig urlReplacement;
public boolean JOIN_ENABLE;
+ public boolean JOIN_PASSTHROUGH;
public String JOIN_FORMAT;
- public boolean QUIT_ENABLE;
- public String QUIT_FORMAT;
+ public boolean LEAVE_ENABLE;
+ public boolean LEAVE_PASSTHROUGH;
+ public String LEAVE_FORMAT;
public boolean SWITCH_ENABLE;
public String SWITCH_FORMAT;
+ public boolean DISCONNECT_ENABLE;
+ public String DISCONNECT_FORMAT;
+
@Inject
public Config(@DataDirectory Path dataDir) {
this.dataDir = dataDir;
@@ -91,12 +96,17 @@ public void loadConfigs() {
this.URLS_PATTERN = this.toml.getString("urls.pattern", "https?:\\/\\/\\S+");
this.JOIN_ENABLE = this.toml.getBoolean("join.enable", false);
- this.JOIN_FORMAT = this.toml.getString("join.format", " joined the game");
+ this.JOIN_PASSTHROUGH = this.toml.getBoolean("join.passthrough", false);
+ this.JOIN_FORMAT = this.toml.getString("join.format", " joined ");
- this.QUIT_ENABLE = this.toml.getBoolean("quit.enable", true);
- this.QUIT_FORMAT = this.toml.getString("quit.format", " disconnected from ");
+ this.LEAVE_ENABLE = this.toml.getBoolean("leave.enable", false);
+ this.LEAVE_PASSTHROUGH = this.toml.getBoolean("leave.passthrough", false);
+ this.LEAVE_FORMAT = this.toml.getString("leave.format", " left ");
this.SWITCH_ENABLE = this.toml.getBoolean("switch.enable", true);
- this.SWITCH_FORMAT = this.toml.getString("switch.format", " connected to ");
+ this.SWITCH_FORMAT = this.toml.getString("switch.format", " switched from to ");
+
+ this.DISCONNECT_ENABLE = this.toml.getBoolean("disconnect.enable", true);
+ this.DISCONNECT_FORMAT = this.toml.getString("disconnect.format", " was disconnected");
}
}
diff --git a/src/main/java/me/confor/velocity/chat/modules/GlobalChat.java b/src/main/java/me/confor/velocity/chat/modules/GlobalChat.java
index 28e6698..fe6162f 100644
--- a/src/main/java/me/confor/velocity/chat/modules/GlobalChat.java
+++ b/src/main/java/me/confor/velocity/chat/modules/GlobalChat.java
@@ -3,11 +3,10 @@
import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.connection.DisconnectEvent;
-import com.velocitypowered.api.event.connection.LoginEvent;
import com.velocitypowered.api.event.player.PlayerChatEvent;
-import com.velocitypowered.api.event.player.PlayerChatEvent.ChatResult;
+import com.velocitypowered.api.event.player.ServerConnectedEvent;
import com.velocitypowered.api.event.proxy.ProxyReloadEvent;
-import com.velocitypowered.api.event.player.ServerPostConnectEvent;
+import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.ServerConnection;
import com.velocitypowered.api.proxy.server.RegisteredServer;
@@ -65,74 +64,79 @@ public void onPlayerChat(PlayerChatEvent event) {
if (config.URLS_CLICKABLE)
msg = msg.replaceText(config.urlReplacement);
- if (config.GLOBAL_CHAT_PASSTHROUGH)
- sendMessage(msg,currentServer.get().getServer());
- else
+ if (!config.GLOBAL_CHAT_PASSTHROUGH) {
+ sendMessage(msg, currentServer.get().getServer());
+ } else {
sendMessage(msg);
+ event.setResult(PlayerChatEvent.ChatResult.denied());
+ }
if (config.GLOBAL_CHAT_TO_CONSOLE)
this.logger.info("GLOBAL: <{}> {}", player, message);
-
- if (!config.GLOBAL_CHAT_PASSTHROUGH)
- event.setResult(ChatResult.denied());
}
@Subscribe
- public void onConnect(LoginEvent event) {
- if (!config.JOIN_ENABLE)
- return;
+ public void onConnect(ServerConnectedEvent event) {
+ RegisteredServer currentServer = event.getServer();
+ Optional previousServer = event.getPreviousServer();
String player = event.getPlayer().getUsername();
+ String server = currentServer.getServerInfo().getName();
- Component msg = parseMessage(config.JOIN_FORMAT, List.of(
- new ChatTemplate("player", player, false)
- ));
+ if (previousServer.isPresent()) {
+ if (!config.SWITCH_ENABLE)
+ return;
- sendMessage(msg);
- }
-
- @Subscribe
- public void onDisconnect(DisconnectEvent event) {
- if (!config.QUIT_ENABLE)
- return;
-
- Optional currentServer = event.getPlayer().getCurrentServer();
- if (currentServer.isEmpty())
- return;
+ Component msg = parseMessage(config.SWITCH_FORMAT, List.of(
+ new ChatTemplate("player", player, false),
+ new ChatTemplate("server", server, false),
+ new ChatTemplate("previous_server", previousServer.get().getServerInfo().getName(), false)
+ ));
- String player = event.getPlayer().getUsername();
- String server = currentServer.get().getServerInfo().getName();
+ sendMessage(msg);
+ } else {
+ if (!config.JOIN_ENABLE)
+ return;
- Component msg = parseMessage(config.QUIT_FORMAT, List.of(
+ Component msg = parseMessage(config.JOIN_FORMAT, List.of(
new ChatTemplate("player", player, false),
new ChatTemplate("server", server, false)
- ));
+ ));
- if (config.GLOBAL_CHAT_PASSTHROUGH)
- sendMessage(msg,currentServer.get().getServer());
- else
- sendMessage(msg);
+ if (!config.JOIN_PASSTHROUGH)
+ sendMessage(msg, currentServer);
+ else
+ sendMessage(msg);
+ }
}
@Subscribe
- public void onServerConnect(ServerPostConnectEvent event) {
- if (!config.SWITCH_ENABLE)
+ public void onDisconnect(DisconnectEvent event) {
+ if (!config.LEAVE_ENABLE)
return;
+ String player = event.getPlayer().getUsername();
Optional currentServer = event.getPlayer().getCurrentServer();
- if (currentServer.isEmpty())
+
+ if (currentServer.isEmpty() && config.DISCONNECT_ENABLE) {
+ Component msg = parseMessage(config.DISCONNECT_FORMAT, List.of(
+ new ChatTemplate("player", player, false)
+ ));
+
+ sendMessage(msg);
+
return;
+ }
- String player = event.getPlayer().getUsername();
String server = currentServer.get().getServerInfo().getName();
- Component msg = parseMessage(config.SWITCH_FORMAT, List.of(
+ Component msg = parseMessage(config.LEAVE_FORMAT, List.of(
new ChatTemplate("player", player, false),
new ChatTemplate("server", server, false)
));
- if (config.GLOBAL_CHAT_PASSTHROUGH)
- sendMessage(msg,currentServer.get().getServer());
+ if (!config.LEAVE_PASSTHROUGH)
+ sendMessage(msg, currentServer.get().getServer());
else
sendMessage(msg);
}
@@ -151,13 +155,13 @@ private Component parseMessage(String input, List templates) {
}
private void sendMessage(Component msg) {
- for (RegisteredServer server : this.server.getAllServers())
- server.sendMessage(msg);
+ for (Player player : this.server.getAllPlayers())
+ player.sendMessage(msg);
}
- private void sendMessage(Component msg, RegisteredServer currentServer) {
+ private void sendMessage(Component msg, RegisteredServer excludedServer) {
for (RegisteredServer server : this.server.getAllServers())
- if (server != currentServer) {
+ if (server != excludedServer) {
server.sendMessage(msg);
}
}
diff --git a/src/main/resources/config.toml b/src/main/resources/config.toml
index 4a142f5..6293f39 100644
--- a/src/main/resources/config.toml
+++ b/src/main/resources/config.toml
@@ -1,4 +1,4 @@
-config_version = 4
+config_version = 6
[chat]
# enable global chat?
@@ -7,35 +7,53 @@ enable = true
# should the chat messages be echoed to velocity's console?
log_to_console = false
-# should chat messages be passed through to the minecraft server?
-# if enabled, it will show duplicate messages in the senders chat
-passthrough = true
-
-# should chat messages be parsed through minimessage?
-# player will be able to use styles such as hello in their messages
+# should global chat messages (with the formatting below) be sent to all players, regardless of minecraft server?
+# if enabled, the original chat message will be formatted as below, and sent to all players.
+# however, this will prevent the target server from receiving the unmodified message, which may break a few mods (see: Botania's "Corporea Index")
+# if disabled, the target server will only see the original message.
+# players on other minecraft servers will always only see the global message.
+# NOTE: enabling this will kick players on >=1.19.1 servers when a chat message is sent.
+# a plugin can be used to solve this - i.e. https://modrinth.com/plugin/unsignedvelocity
+passthrough = false
+
+# should global chat messages be parsed through minimessage?
+# players will be able to use styles such as hello in their messages
parse_player_messages = false
-# global chat format, you can use minimessage tags here.
+# global chat format, you can use minimessage tags here
format = "<> "
[urls]
-# should urls typed in chat be clickable?
+# should urls in global chat be clickable?
clickable = true
# the regular expression used to determine whether something is a url
-# test using https://regex101.com/ set to Java 8 and only the "g" (global) flag
+# test using https://regex101.com/ - set to Java 8 and enable only the "g" (global) flag
pattern = "https?:\\/\\/\\S+"
[join]
-# send a chat message when a player connects to velocity? Useful for fabric servers which dont already have a Join message.
-enable = false
-format = " joined the game"
+# send a chat message when a player joins the proxy?
+enable = true
+# send that chat message to the server the player is joining?
+# useful for servers that have the default join message disabled (via mod / plugin)
+passthrough = false
+format = " joined "
-[quit]
-# send a chat message when a player disconnects?
+[leave]
+# send a chat message when a player leaves the proxy?
enable = true
-format = " disconnected from "
+# send that chat message to the server the player is leaving?
+# useful for servers that have the default leave message disabled (via mod / plugin)
+passthrough = false
+format = " left "
[switch]
-# send a chat message when a player connects to a minecraft server?
+# send a chat message when a player switches to a different server?
+# (e.g. via "/server ")
+enable = true
+format = " switched from to "
+
+[disconnect]
+# send a chat message when a player is forcibly disconnected from the proxy?
+# (e.g. due to timing out, having an incompatible client, or some other error)
enable = true
-format = " connected to "
\ No newline at end of file
+format = " was disconnected"