From dd2057d9055618ac3067496b667966a4a03840e1 Mon Sep 17 00:00:00 2001 From: jones6096 Date: Sat, 6 Jan 2024 14:13:43 -0500 Subject: [PATCH 1/2] Add KickedFromServerEvent Temporarily removed VelocityDiscord Integration --- .../feusalamander/vmessage/Configuration.java | 18 +++++ .../me/feusalamander/vmessage/Listeners.java | 66 ++++++++++++++++--- src/main/resources/config.toml | 11 ++++ 3 files changed, 86 insertions(+), 9 deletions(-) diff --git a/src/main/java/me/feusalamander/vmessage/Configuration.java b/src/main/java/me/feusalamander/vmessage/Configuration.java index 224cc79..3f64572 100644 --- a/src/main/java/me/feusalamander/vmessage/Configuration.java +++ b/src/main/java/me/feusalamander/vmessage/Configuration.java @@ -13,10 +13,12 @@ public final class Configuration { private String messageFormat; private String joinFormat; private String leaveFormat; + private String kickFormat; private String changeFormat; private boolean messageEnabled; private boolean joinEnabled; private boolean leaveEnabled; + private boolean kickEnabled; private boolean changeEnabled; private boolean minimessage; private boolean all; @@ -25,6 +27,7 @@ public final class Configuration { private List messagecmd; private List joincmd; private List leavecmd; + private List kickcmd; private List changecmd; private String custom1; private String custom2; @@ -34,11 +37,13 @@ public final class Configuration { messageFormat = config.getString("Message.format", ""); joinFormat = config.getString("Join.format", ""); leaveFormat = config.getString("Leave.format", ""); + kickFormat = config.getString("Kick.format", ""); changeFormat = config.getString("Server-change.format", ""); messageEnabled = config.getBoolean("Message.enabled", false); joinEnabled = config.getBoolean("Join.enabled", false); leaveEnabled = config.getBoolean("Leave.enabled", false); + kickEnabled = config.getBoolean("Kick.enabled", false); changeEnabled = config.getBoolean("Server-change.enabled", false); aliases = config.getTable("Aliases"); @@ -46,6 +51,7 @@ public final class Configuration { messagecmd = config.getList("Message.commands"); joincmd = config.getList("Join.commands"); leavecmd = config.getList("Leave.commands"); + kickcmd = config.getList("Kick.commands"); changecmd = config.getList("Server-change.commands"); minimessage = config.getBoolean("Message-format.minimessage"); all = config.getBoolean("Message.all", false); @@ -94,6 +100,9 @@ public final class Configuration { public String getLeaveFormat() { return this.leaveFormat; } + public String getKickFormat() { + return this.kickFormat; + } public String getChangeFormat() { return this.changeFormat; @@ -110,6 +119,9 @@ public final class Configuration { public boolean isLeaveEnabled() { return this.leaveEnabled; } + public boolean isKickEnabled() { + return this.kickEnabled; + } public boolean isChangeEnabled() { return this.changeEnabled; @@ -129,6 +141,9 @@ public final class Configuration { public List getLeavecmd(){ return this.leavecmd; } + public List getKickcmd(){ + return this.kickcmd; + } public List getChangecmd(){ return this.changecmd; } @@ -147,11 +162,13 @@ public final class Configuration { this.messageFormat = config.getString("Message.format"); this.joinFormat = config.getString("Join.format"); this.leaveFormat = config.getString("Leave.format"); + this.kickFormat = config.getString("Kick.format"); this.changeFormat = config.getString("Server-change.format"); this.messageEnabled = config.getBoolean("Message.enabled"); this.joinEnabled = config.getBoolean("Join.enabled"); this.leaveEnabled = config.getBoolean("Leave.enabled"); + this.kickEnabled = config.getBoolean("Kick.enabled"); this.changeEnabled = config.getBoolean("Server-change.enabled"); this.aliases = config.getTable("Aliases"); @@ -159,6 +176,7 @@ public final class Configuration { this.messagecmd = config.getList("Message.commands"); this.joincmd = config.getList("Join.commands"); this.leavecmd = config.getList("Leave.commands"); + this.kickcmd = config.getList("Kick.commands"); this.changecmd = config.getList("Server-change.commands"); this.minimessage = config.getBoolean("Message-format.minimessage"); diff --git a/src/main/java/me/feusalamander/vmessage/Listeners.java b/src/main/java/me/feusalamander/vmessage/Listeners.java index c24b064..e14c00a 100644 --- a/src/main/java/me/feusalamander/vmessage/Listeners.java +++ b/src/main/java/me/feusalamander/vmessage/Listeners.java @@ -2,6 +2,7 @@ package me.feusalamander.vmessage; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.connection.DisconnectEvent; +import com.velocitypowered.api.event.player.KickedFromServerEvent; import com.velocitypowered.api.event.player.PlayerChatEvent; import com.velocitypowered.api.event.player.ServerPostConnectEvent; import com.velocitypowered.api.proxy.Player; @@ -14,7 +15,7 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.luckperms.api.LuckPerms; import net.luckperms.api.LuckPermsProvider; import net.luckperms.api.cacheddata.CachedMetaData; -import ooo.foooooooooooo.velocitydiscord.VelocityDiscord; + import java.util.Arrays; import java.util.Objects; @@ -101,10 +102,63 @@ public final class Listeners { } if (configuration.isMinimessageEnabled()) { proxyServer.sendMessage(mm.deserialize(message.replace("§", ""))); - if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw); } else { proxyServer.sendMessage(SERIALIZER.deserialize(message)); - if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw); + } + + } + @Subscribe + private void onKick(final KickedFromServerEvent e) { + if (!configuration.isKickEnabled()) { + 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.getKickFormat(); + String servername = server.get().getServerInfo().getName(); + if(configuration.getAliases().contains(servername)){ + servername = configuration.getAliases().getString(servername); + } + if(configuration.getKickcmd() != null&&!configuration.getKickcmd().isEmpty()) + for(String s : configuration.getKickcmd()){ + s = s + .replace("#player#", p.getUsername()) + .replace("#oldserver#", servername); + if (luckPermsAPI != null) { + s = luckperms(s, p); + } + proxyServer.getCommandManager().executeAsync(proxyServer.getConsoleCommandSource(), s); + } + if(message.isEmpty())return; + message = message + .replace("#player#", p.getUsername()) + .replace("#oldserver#", servername); + if (luckPermsAPI != null) { + message = luckperms(message, p); + } + String discordRaw; + if(VMessage.isDiscord()){ + String dump = ""; + String[] dump2 = message.replace("&", "§").split("§"); + proxyServer.sendMessage(Component.text(Arrays.toString(dump2))); + for(String string : dump2){ + if(string.length() >1) + dump = dump+string.substring(1); + } + discordRaw = dump; + } else { + discordRaw = message; + } + if (configuration.isMinimessageEnabled()) { + proxyServer.sendMessage(mm.deserialize(message.replace("§", ""))); + } else { + proxyServer.sendMessage(SERIALIZER.deserialize(message)); } } @@ -167,10 +221,8 @@ public final class Listeners { } if (configuration.isMinimessageEnabled()) { proxyServer.sendMessage(mm.deserialize(message.replace("§", ""))); - if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw); } else { proxyServer.sendMessage(SERIALIZER.deserialize(message)); - if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw); } } else if (serverConnection.isPresent()){ if (!configuration.isJoinEnabled()) { @@ -216,10 +268,8 @@ public final class Listeners { } if (configuration.isMinimessageEnabled()) { proxyServer.sendMessage(mm.deserialize(message.replace("§", ""))); - if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw); } else { proxyServer.sendMessage(SERIALIZER.deserialize(message)); - if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw); } } } @@ -292,13 +342,11 @@ public final class Listeners { } if(configuration.isAllEnabled()){ proxyServer.sendMessage(finalMessage); - if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw); }else { final Component FMessage = finalMessage; proxyServer.getAllServers().forEach(server -> { if (!Objects.equals(p.getCurrentServer().map(ServerConnection::getServerInfo).orElse(null), server.getServerInfo())) { server.sendMessage(FMessage); - if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw); } }); } diff --git a/src/main/resources/config.toml b/src/main/resources/config.toml index 4e37423..85d5127 100644 --- a/src/main/resources/config.toml +++ b/src/main/resources/config.toml @@ -37,6 +37,17 @@ enabled = true format = "#&7prefix# #player# &eleft &7#oldserver#" commands = [] enabled = true +[Kick] +#place holders: +#- "#player#" : return the player name +#- "#oldserver#" : return the previous player's server name +#- "#prefix#" : return the player's luckperms prefix +#- "#suffix#" : return the player's luckperms suffix +#- "#custom1#" : return the player's custom defined luckperms meta keys +#- "#custom2#" : return the player's custom defined luckperms meta keys +format = "&7#prefix# #player# &ewas kicked from &7#oldserver#" +commands = [] #The proxy commands which are executed (no / in the commands) +enabled = true [Server-change] #place holders: #- "#player#" : return the player name From bbd02becf1971b5dac10872396c4df53f87fea84 Mon Sep 17 00:00:00 2001 From: jones6096 Date: Sat, 6 Jan 2024 14:14:16 -0500 Subject: [PATCH 2/2] Reimplement VelocityDiscord --- .../java/me/feusalamander/vmessage/Listeners.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/feusalamander/vmessage/Listeners.java b/src/main/java/me/feusalamander/vmessage/Listeners.java index e14c00a..7c7c3a8 100644 --- a/src/main/java/me/feusalamander/vmessage/Listeners.java +++ b/src/main/java/me/feusalamander/vmessage/Listeners.java @@ -15,7 +15,7 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.luckperms.api.LuckPerms; import net.luckperms.api.LuckPermsProvider; import net.luckperms.api.cacheddata.CachedMetaData; - +import ooo.foooooooooooo.velocitydiscord.VelocityDiscord; import java.util.Arrays; import java.util.Objects; @@ -102,8 +102,10 @@ public final class Listeners { } if (configuration.isMinimessageEnabled()) { proxyServer.sendMessage(mm.deserialize(message.replace("§", ""))); + if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw); } else { proxyServer.sendMessage(SERIALIZER.deserialize(message)); + if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw); } } @@ -157,8 +159,10 @@ public final class Listeners { } if (configuration.isMinimessageEnabled()) { proxyServer.sendMessage(mm.deserialize(message.replace("§", ""))); + if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw); } else { proxyServer.sendMessage(SERIALIZER.deserialize(message)); + if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw); } } @@ -221,8 +225,10 @@ public final class Listeners { } if (configuration.isMinimessageEnabled()) { proxyServer.sendMessage(mm.deserialize(message.replace("§", ""))); + if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw); } else { proxyServer.sendMessage(SERIALIZER.deserialize(message)); + if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw); } } else if (serverConnection.isPresent()){ if (!configuration.isJoinEnabled()) { @@ -268,8 +274,10 @@ public final class Listeners { } if (configuration.isMinimessageEnabled()) { proxyServer.sendMessage(mm.deserialize(message.replace("§", ""))); + if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw); } else { proxyServer.sendMessage(SERIALIZER.deserialize(message)); + if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw); } } } @@ -342,11 +350,13 @@ public final class Listeners { } if(configuration.isAllEnabled()){ proxyServer.sendMessage(finalMessage); + if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw); }else { final Component FMessage = finalMessage; proxyServer.getAllServers().forEach(server -> { if (!Objects.equals(p.getCurrentServer().map(ServerConnection::getServerInfo).orElse(null), server.getServerInfo())) { server.sendMessage(FMessage); + if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw); } }); }