From fbb1d57d54208c95e44a83ad3a2e02a54c542b64 Mon Sep 17 00:00:00 2001 From: FeuSalamander Date: Sun, 20 Aug 2023 09:31:55 +0200 Subject: [PATCH] added silent permission, added server aliases --- README.md | 3 +- pom.xml | 2 +- .../feusalamander/vmessage/Configuration.java | 19 ++++--- .../me/feusalamander/vmessage/Listeners.java | 50 +++++++++++++++---- .../me/feusalamander/vmessage/VMessage.java | 2 +- src/main/resources/config.toml | 2 + 6 files changed, 58 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 313a0dd..0a7a310 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,5 @@ - **MiniMessage support** ![](https://github.com/FeuSalamander/Vmessage/blob/main/src/main/resources/permissions.png?raw=true) - **"vmessage.reload" to access to the reload command** -- **"vmessage.minimessage" the player need to have it to use MiniMessage in his messages** +- **"vmessage.minimessage" the player needs to have it to use MiniMessage in his messages** +- **"vmessage.silent. leave,change, join" if the player have it/them, no message will be sent** diff --git a/pom.xml b/pom.xml index 927a240..1304943 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ Vmessage Vmessage - 1.5.5Pre + 1.5.6 jar Vmessage diff --git a/src/main/java/me/feusalamander/vmessage/Configuration.java b/src/main/java/me/feusalamander/vmessage/Configuration.java index c5bf700..9c20f6d 100644 --- a/src/main/java/me/feusalamander/vmessage/Configuration.java +++ b/src/main/java/me/feusalamander/vmessage/Configuration.java @@ -26,6 +26,7 @@ public final class Configuration { private List joincmd; private List leavecmd; private List changecmd; + private Toml aliases; Configuration(Toml config) { messageFormat = config.getString("Message.format", ""); @@ -38,11 +39,12 @@ public final class Configuration { leaveEnabled = config.getBoolean("Leave.enabled", false); changeEnabled = config.getBoolean("Server-change.enabled", false); + aliases = config.getTable("Aliases"); + messagecmd = config.getList("Message.commands"); joincmd = config.getList("Join.commands"); leavecmd = config.getList("Leave.commands"); changecmd = config.getList("Server-change.commands"); - minimessage = config.getBoolean("Message-format.minimessage"); all = config.getBoolean("Message.all", false); this.config = config; @@ -125,6 +127,9 @@ public final class Configuration { public List getChangecmd(){ return this.changecmd; } + public Toml getAliases() { + return aliases; + } void reload(){ config = config.read(file); this.messageFormat = config.getString("Message.format"); @@ -137,12 +142,14 @@ public final class Configuration { this.leaveEnabled = config.getBoolean("Leave.enabled"); this.changeEnabled = config.getBoolean("Server-change.enabled"); - messagecmd = config.getList("Message.commands"); - joincmd = config.getList("Join.commands"); - leavecmd = config.getList("Leave.commands"); - changecmd = config.getList("Server-change.commands"); + this.aliases = config.getTable("Aliases"); + + this.messagecmd = config.getList("Message.commands"); + this.joincmd = config.getList("Join.commands"); + this.leavecmd = config.getList("Leave.commands"); + this.changecmd = config.getList("Server-change.commands"); this.minimessage = config.getBoolean("Message-format.minimessage"); - all = config.getBoolean("Message.all", false); + this.all = config.getBoolean("Message.all", false); } } diff --git a/src/main/java/me/feusalamander/vmessage/Listeners.java b/src/main/java/me/feusalamander/vmessage/Listeners.java index 62d8d66..ada2bd9 100644 --- a/src/main/java/me/feusalamander/vmessage/Listeners.java +++ b/src/main/java/me/feusalamander/vmessage/Listeners.java @@ -55,18 +55,24 @@ public final class Listeners { if (!e.getLoginStatus().equals(DisconnectEvent.LoginStatus.SUCCESSFUL_LOGIN)){ return; } - + if(e.getPlayer().hasPermission("vmessage.silent.leave")){ + return; + } final Player p = e.getPlayer(); final Optional server = p.getCurrentServer(); if (server.isEmpty()) { return; } String message = configuration.getLeaveFormat(); + String servername = server.get().getServerInfo().getName(); + if(configuration.getAliases().contains(servername)){ + servername = configuration.getAliases().getString(servername); + } if(configuration.getLeavecmd() != null&&!configuration.getLeavecmd().isEmpty()) for(String s : configuration.getLeavecmd()){ s = s .replace("#player#", p.getUsername()) - .replace("#oldserver#", server.get().getServerInfo().getName()); + .replace("#oldserver#", servername); if (luckPermsAPI != null) { s = luckperms(s, p); } @@ -75,7 +81,7 @@ public final class Listeners { if(message.isEmpty())return; message = message .replace("#player#", p.getUsername()) - .replace("#oldserver#", server.get().getServerInfo().getName()); + .replace("#oldserver#", servername); if (luckPermsAPI != null) { message = luckperms(message, p); } @@ -98,14 +104,25 @@ public final class Listeners { if (!configuration.isChangeEnabled()) { return; } + if(e.getPlayer().hasPermission("vmessage.silent.change")){ + return; + } final ServerConnection actual = serverConnection.get(); String message = configuration.getChangeFormat(); + String actualservername = actual.getServerInfo().getName(); + if(configuration.getAliases().contains(actualservername)){ + actualservername = configuration.getAliases().getString(actualservername); + } + String oldservername = pre.getServerInfo().getName(); + if(configuration.getAliases().containsTable(oldservername)){ + oldservername = configuration.getAliases().getString(oldservername); + } if(configuration.getChangecmd() != null&&!configuration.getChangecmd().isEmpty()) for(String s : configuration.getChangecmd()){ s = s .replace("#player#", p.getUsername()) - .replace("#oldserver#", pre.getServerInfo().getName()) - .replace("#server#", actual.getServerInfo().getName()); + .replace("#oldserver#", oldservername) + .replace("#server#", actualservername); if (luckPermsAPI != null) { s = luckperms(s, p); } @@ -114,8 +131,8 @@ public final class Listeners { if(message.isEmpty())return; message = message .replace("#player#", p.getUsername()) - .replace("#oldserver#", pre.getServerInfo().getName()) - .replace("#server#", actual.getServerInfo().getName()); + .replace("#oldserver#", oldservername) + .replace("#server#", actualservername); if (luckPermsAPI != null) { message = luckperms(message, p); } @@ -128,11 +145,18 @@ public final class Listeners { if (!configuration.isJoinEnabled()) { return; } + if(e.getPlayer().hasPermission("vmessage.silent.join")){ + return; + } + String actualservername = serverConnection.get().getServerInfo().getName(); + if(configuration.getAliases().contains(actualservername)){ + actualservername = configuration.getAliases().getString(actualservername); + } if(configuration.getJoincmd() != null&&!configuration.getJoincmd().isEmpty()) for(String s : configuration.getJoincmd()){ s = s .replace("#player#", p.getUsername()) - .replace("#server#", serverConnection.get().getServerInfo().getName()); + .replace("#server#", actualservername); if (luckPermsAPI != null) { s = luckperms(s, p); } @@ -142,7 +166,7 @@ public final class Listeners { if(message.isEmpty())return; message = message .replace("#player#", p.getUsername()) - .replace("#server#", serverConnection.get().getServerInfo().getName()); + .replace("#server#", actualservername); if (luckPermsAPI != null) { message = luckperms(message, p); } @@ -167,11 +191,15 @@ public final class Listeners { return message; } public void message(final Player p, final String m) { + String actualservername = p.getCurrentServer().orElseThrow().getServerInfo().getName(); + if(configuration.getAliases().contains(actualservername)){ + actualservername = configuration.getAliases().getString(actualservername); + } if(configuration.getMessagecmd() != null&&!configuration.getMessagecmd().isEmpty()) for(String s : configuration.getMessagecmd()){ s = s .replace("#player#", p.getUsername()) - .replace("#server#", p.getCurrentServer().orElseThrow().getServerInfo().getName()); + .replace("#server#", actualservername); if (luckPermsAPI != null) { s = luckperms(s, p); } @@ -182,7 +210,7 @@ public final class Listeners { final boolean permission = p.hasPermission("vmessage.minimessage"); message = message .replace("#player#", p.getUsername()) - .replace("#server#", p.getCurrentServer().orElseThrow().getServerInfo().getName()); + .replace("#server#", actualservername); if (luckPermsAPI != null) { message = luckperms(message, p); } diff --git a/src/main/java/me/feusalamander/vmessage/VMessage.java b/src/main/java/me/feusalamander/vmessage/VMessage.java index 4c36081..72bd1c5 100644 --- a/src/main/java/me/feusalamander/vmessage/VMessage.java +++ b/src/main/java/me/feusalamander/vmessage/VMessage.java @@ -17,7 +17,7 @@ import java.nio.file.Path; @Plugin( id = "vmessage", name = "Vmessage", - version = "1.5.5Pre", + version = "1.6.0", description = "A velocity plugin that creates a multi server chat for the network", authors = {"FeuSalamander"}, dependencies = { diff --git a/src/main/resources/config.toml b/src/main/resources/config.toml index 1972786..eafe2a4 100644 --- a/src/main/resources/config.toml +++ b/src/main/resources/config.toml @@ -41,3 +41,5 @@ enabled = true format = "&7#prefix# #player# &eleft &c#oldserver# &eto join &a#server#" commands = [] enabled = true +[Aliases] +servername = "Server Name"