added discord integration

This commit is contained in:
FeuSalamander 2023-11-25 18:32:59 +01:00
parent 6cb80c86d1
commit d6645fddd2
3 changed files with 79 additions and 4 deletions

View File

@ -14,7 +14,9 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.LuckPerms; import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider; import net.luckperms.api.LuckPermsProvider;
import net.luckperms.api.cacheddata.CachedMetaData; import net.luckperms.api.cacheddata.CachedMetaData;
import ooo.foooooooooooo.velocitydiscord.VelocityDiscord;
import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
@ -51,7 +53,6 @@ public final class Listeners {
if (!configuration.isLeaveEnabled()) { if (!configuration.isLeaveEnabled()) {
return; return;
} }
if (!e.getLoginStatus().equals(DisconnectEvent.LoginStatus.SUCCESSFUL_LOGIN)){ if (!e.getLoginStatus().equals(DisconnectEvent.LoginStatus.SUCCESSFUL_LOGIN)){
return; return;
} }
@ -85,10 +86,25 @@ public final class Listeners {
if (luckPermsAPI != null) { if (luckPermsAPI != null) {
message = luckperms(message, p); 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()) { if (configuration.isMinimessageEnabled()) {
proxyServer.sendMessage(mm.deserialize(message.replace("§", ""))); proxyServer.sendMessage(mm.deserialize(message.replace("§", "")));
if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw);
} else { } else {
proxyServer.sendMessage(SERIALIZER.deserialize(message)); proxyServer.sendMessage(SERIALIZER.deserialize(message));
if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw);
} }
} }
@ -136,10 +152,25 @@ public final class Listeners {
if (luckPermsAPI != null) { if (luckPermsAPI != null) {
message = luckperms(message, p); 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()) { if (configuration.isMinimessageEnabled()) {
proxyServer.sendMessage(mm.deserialize(message.replace("§", ""))); proxyServer.sendMessage(mm.deserialize(message.replace("§", "")));
if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw);
} else { } else {
proxyServer.sendMessage(SERIALIZER.deserialize(message)); proxyServer.sendMessage(SERIALIZER.deserialize(message));
if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw);
} }
} else if (serverConnection.isPresent()){ } else if (serverConnection.isPresent()){
if (!configuration.isJoinEnabled()) { if (!configuration.isJoinEnabled()) {
@ -170,10 +201,25 @@ public final class Listeners {
if (luckPermsAPI != null) { if (luckPermsAPI != null) {
message = luckperms(message, p); 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()) { if (configuration.isMinimessageEnabled()) {
proxyServer.sendMessage(mm.deserialize(message.replace("§", ""))); proxyServer.sendMessage(mm.deserialize(message.replace("§", "")));
if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw);
} else { } else {
proxyServer.sendMessage(SERIALIZER.deserialize(message)); proxyServer.sendMessage(SERIALIZER.deserialize(message));
if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw);
} }
} }
} }
@ -231,13 +277,28 @@ public final class Listeners {
finalMessage = SERIALIZER.deserialize(message); finalMessage = SERIALIZER.deserialize(message);
} }
if(!permission)finalMessage = finalMessage.replaceText("#message#", Component.text(m)); if(!permission)finalMessage = finalMessage.replaceText("#message#", Component.text(m));
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.isAllEnabled()){ if(configuration.isAllEnabled()){
proxyServer.sendMessage(finalMessage); proxyServer.sendMessage(finalMessage);
if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw);
}else { }else {
final Component FMessage = finalMessage; final Component FMessage = finalMessage;
proxyServer.getAllServers().forEach(server -> { proxyServer.getAllServers().forEach(server -> {
if (!Objects.equals(p.getCurrentServer().map(ServerConnection::getServerInfo).orElse(null), server.getServerInfo())) { if (!Objects.equals(p.getCurrentServer().map(ServerConnection::getServerInfo).orElse(null), server.getServerInfo())) {
server.sendMessage(FMessage); server.sendMessage(FMessage);
if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw);
} }
}); });
} }

View File

@ -10,6 +10,7 @@ import com.velocitypowered.api.plugin.Dependency;
import com.velocitypowered.api.plugin.Plugin; import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory; import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ProxyServer;
import net.kyori.adventure.text.Component;
import org.slf4j.Logger; import org.slf4j.Logger;
import java.nio.file.Path; import java.nio.file.Path;
@ -17,12 +18,12 @@ import java.nio.file.Path;
@Plugin( @Plugin(
id = "vmessage", id = "vmessage",
name = "Vmessage", name = "Vmessage",
version = "1.6.0", version = "1.6.1",
description = "A velocity plugin that creates a multi server chat for the network", description = "A velocity plugin that creates a multi server chat for the network",
authors = {"FeuSalamander"}, authors = {"FeuSalamander"},
dependencies = { dependencies = {
@Dependency(id = "luckperms", optional = true), @Dependency(id = "luckperms", optional = true),
@Dependency(id = "papiproxybridge",optional = true) @Dependency(id = "discord",optional = true)
} }
) )
public class VMessage { public class VMessage {
@ -31,6 +32,7 @@ public class VMessage {
private final Metrics.Factory metricsFactory; private final Metrics.Factory metricsFactory;
private final Path dataDirectory; private final Path dataDirectory;
public Listeners listeners; public Listeners listeners;
private static boolean discord;
@Inject @Inject
public VMessage(ProxyServer proxy, Logger logger, Metrics.Factory metricsFactory, @DataDirectory Path dataDirectory) { public VMessage(ProxyServer proxy, Logger logger, Metrics.Factory metricsFactory, @DataDirectory Path dataDirectory) {
@ -38,6 +40,7 @@ public class VMessage {
this.logger = logger; this.logger = logger;
this.metricsFactory = metricsFactory; this.metricsFactory = metricsFactory;
this.dataDirectory = dataDirectory; this.dataDirectory = dataDirectory;
this.discord = proxy.getPluginManager().isLoaded("discord");
} }
@Subscribe @Subscribe
@ -49,7 +52,6 @@ public class VMessage {
metricsFactory.make(this, 16527); metricsFactory.make(this, 16527);
listeners = new Listeners(proxy, configuration); listeners = new Listeners(proxy, configuration);
proxy.getEventManager().register(this, listeners); proxy.getEventManager().register(this, listeners);
logger.info("Vmessage by FeuSalamander is working !");
CommandManager commandManager = proxy.getCommandManager(); CommandManager commandManager = proxy.getCommandManager();
CommandMeta commandMeta = commandManager.metaBuilder("Vmessage") CommandMeta commandMeta = commandManager.metaBuilder("Vmessage")
.plugin(this) .plugin(this)
@ -61,5 +63,9 @@ public class VMessage {
.build(); .build();
SimpleCommand sendcommand = new SendCommand(this); SimpleCommand sendcommand = new SendCommand(this);
commandManager.register(sendmeta, sendcommand); commandManager.register(sendmeta, sendcommand);
logger.info("Vmessage by FeuSalamander is working !");
}
public static boolean isDiscord(){
return discord;
} }
} }

View File

@ -9,6 +9,8 @@ minimessage = false
#- "#suffix#" : return the player's luckperms suffix #- "#suffix#" : return the player's luckperms suffix
#- "#message#" : return the player's message #- "#message#" : return the player's message
#- "#server#" : return the player's server name #- "#server#" : return the player's server name
#- "#custom1#" : return the player's custom defined luckperms meta keys
#- "#custom2#" : return the player's custom defined luckperms meta keys
format = "&a(#server#) #prefix# #player# &8&l> &r#message#" format = "&a(#server#) #prefix# #player# &8&l> &r#message#"
all = false #if the formated message is sent even in the server where the player is located (can cause some issues with other plugins) all = false #if the formated message is sent even in the server where the player is located (can cause some issues with other plugins)
commands = [] commands = []
@ -19,6 +21,8 @@ enabled = true
#- "#server#" : return the new player's server name #- "#server#" : return the new player's server name
#- "#prefix#" : return the player's luckperms prefix #- "#prefix#" : return the player's luckperms prefix
#- "#suffix#" : return the player's luckperms suffix #- "#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# &ejoined &7#server#" format = "&7#prefix# #player# &ejoined &7#server#"
commands = [] #The proxy commands which are executed (no / in the commands) commands = [] #The proxy commands which are executed (no / in the commands)
enabled = true enabled = true
@ -28,6 +32,8 @@ enabled = true
#- "#oldserver#" : return the previous player's server name #- "#oldserver#" : return the previous player's server name
#- "#prefix#" : return the player's luckperms prefix #- "#prefix#" : return the player's luckperms prefix
#- "#suffix#" : return the player's luckperms suffix #- "#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 = "#&7prefix# #player# &eleft &7#oldserver#" format = "#&7prefix# #player# &eleft &7#oldserver#"
commands = [] commands = []
enabled = true enabled = true
@ -38,6 +44,8 @@ enabled = true
#- "#suffix#" : return the player's luckperms suffix #- "#suffix#" : return the player's luckperms suffix
#- "#oldserver#" : return the previous player's server name #- "#oldserver#" : return the previous player's server name
#- "#server#" : return the new player's server name #- "#server#" : return the new player's server name
#- "#custom1#" : return the player's custom defined luckperms meta keys
#- "#custom2#" : return the player's custom defined luckperms meta keys
format = "&7#prefix# #player# &eleft &c#oldserver# &eto join &a#server#" format = "&7#prefix# #player# &eleft &c#oldserver# &eto join &a#server#"
commands = [] commands = []
enabled = true enabled = true