Add KickedFromServerEvent

Temporarily removed VelocityDiscord Integration
This commit is contained in:
jones6096 2024-01-06 14:13:43 -05:00
parent 983a64dafb
commit dd2057d905
3 changed files with 86 additions and 9 deletions

View File

@ -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<String> messagecmd;
private List<String> joincmd;
private List<String> leavecmd;
private List<String> kickcmd;
private List<String> 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<String> getLeavecmd(){
return this.leavecmd;
}
public List<String> getKickcmd(){
return this.kickcmd;
}
public List<String> 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");

View File

@ -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<ServerConnection> 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);
}
});
}

View File

@ -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