Skip to content

Commit

Permalink
added discord integration
Browse files Browse the repository at this point in the history
  • Loading branch information
FeuSalamander committed Nov 25, 2023
1 parent 6cb80c8 commit d6645fd
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 4 deletions.
63 changes: 62 additions & 1 deletion src/main/java/me/feusalamander/vmessage/Listeners.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
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;
import java.util.Optional;

Expand Down Expand Up @@ -51,7 +53,6 @@ private void onLeave(final DisconnectEvent e) {
if (!configuration.isLeaveEnabled()) {
return;
}

if (!e.getLoginStatus().equals(DisconnectEvent.LoginStatus.SUCCESSFUL_LOGIN)){
return;
}
Expand Down Expand Up @@ -85,10 +86,25 @@ private void onLeave(final DisconnectEvent e) {
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("§", "")));
if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw);
} else {
proxyServer.sendMessage(SERIALIZER.deserialize(message));
if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw);
}

}
Expand Down Expand Up @@ -136,10 +152,25 @@ private void onChange(final ServerPostConnectEvent e) {
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("§", "")));
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()) {
Expand Down Expand Up @@ -170,10 +201,25 @@ private void onChange(final ServerPostConnectEvent e) {
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("§", "")));
if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw);
} else {
proxyServer.sendMessage(SERIALIZER.deserialize(message));
if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw);
}
}
}
Expand Down Expand Up @@ -231,13 +277,28 @@ public void message(final Player p, final String m) {
finalMessage = SERIALIZER.deserialize(message);
}
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()){
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);
}
});
}
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/me/feusalamander/vmessage/VMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
import net.kyori.adventure.text.Component;
import org.slf4j.Logger;

import java.nio.file.Path;

@Plugin(
id = "vmessage",
name = "Vmessage",
version = "1.6.0",
version = "1.6.1",
description = "A velocity plugin that creates a multi server chat for the network",
authors = {"FeuSalamander"},
dependencies = {
@Dependency(id = "luckperms", optional = true),
@Dependency(id = "papiproxybridge",optional = true)
@Dependency(id = "discord",optional = true)
}
)
public class VMessage {
Expand All @@ -31,13 +32,15 @@ public class VMessage {
private final Metrics.Factory metricsFactory;
private final Path dataDirectory;
public Listeners listeners;
private static boolean discord;

@Inject
public VMessage(ProxyServer proxy, Logger logger, Metrics.Factory metricsFactory, @DataDirectory Path dataDirectory) {
this.proxy = proxy;
this.logger = logger;
this.metricsFactory = metricsFactory;
this.dataDirectory = dataDirectory;
this.discord = proxy.getPluginManager().isLoaded("discord");
}

@Subscribe
Expand All @@ -49,7 +52,6 @@ private void onProxyInitialization(ProxyInitializeEvent event) {
metricsFactory.make(this, 16527);
listeners = new Listeners(proxy, configuration);
proxy.getEventManager().register(this, listeners);
logger.info("Vmessage by FeuSalamander is working !");
CommandManager commandManager = proxy.getCommandManager();
CommandMeta commandMeta = commandManager.metaBuilder("Vmessage")
.plugin(this)
Expand All @@ -61,5 +63,9 @@ private void onProxyInitialization(ProxyInitializeEvent event) {
.build();
SimpleCommand sendcommand = new SendCommand(this);
commandManager.register(sendmeta, sendcommand);
logger.info("Vmessage by FeuSalamander is working !");
}
public static boolean isDiscord(){
return discord;
}
}
8 changes: 8 additions & 0 deletions src/main/resources/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ minimessage = false
#- "#suffix#" : return the player's luckperms suffix
#- "#message#" : return the player's message
#- "#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#"
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 = []
Expand All @@ -19,6 +21,8 @@ enabled = true
#- "#server#" : return the new 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# &ejoined &7#server#"
commands = [] #The proxy commands which are executed (no / in the commands)
enabled = true
Expand All @@ -28,6 +32,8 @@ enabled = true
#- "#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 = "#&7prefix# #player# &eleft &7#oldserver#"
commands = []
enabled = true
Expand All @@ -38,6 +44,8 @@ enabled = true
#- "#suffix#" : return the player's luckperms suffix
#- "#oldserver#" : return the previous 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#"
commands = []
enabled = true
Expand Down

0 comments on commit d6645fd

Please sign in to comment.