From 1153a65d48bd022c75fea12d54e1b62f1e6a41e8 Mon Sep 17 00:00:00 2001 From: FeuSalamander Date: Mon, 12 Dec 2022 12:45:00 +0100 Subject: [PATCH] added booleans --- pom.xml | 2 +- .../me/feusalamander/vmessage/vmessage.java | 42 +++++++++++++++---- src/main/resources/config.toml | 29 ++++++++++++- 3 files changed, 62 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 71c00ff..9ae3956 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ org.apache.maven.plugins maven-source-plugin - 3.2.0 + 3.2.1 attach-sources diff --git a/src/main/java/me/feusalamander/vmessage/vmessage.java b/src/main/java/me/feusalamander/vmessage/vmessage.java index 693da0b..62ffa5f 100644 --- a/src/main/java/me/feusalamander/vmessage/vmessage.java +++ b/src/main/java/me/feusalamander/vmessage/vmessage.java @@ -1,7 +1,9 @@ package me.feusalamander.vmessage; import com.google.inject.Inject; import com.moandjiezana.toml.Toml; -import com.velocitypowered.api.event.player.PlayerChatEvent; +import com.velocitypowered.api.event.connection.DisconnectEvent; +import com.velocitypowered.api.event.connection.LoginEvent; +import com.velocitypowered.api.event.player.*; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.plugin.Plugin; @@ -12,6 +14,7 @@ import com.velocitypowered.api.proxy.server.RegisteredServer; import net.kyori.adventure.text.Component; import net.luckperms.api.LuckPerms; import net.luckperms.api.LuckPermsProvider; +import net.luckperms.api.event.player.PlayerLoginProcessEvent; import net.luckperms.api.model.user.User; import org.slf4j.Logger; import java.io.File; @@ -23,7 +26,7 @@ import java.util.Objects; @Plugin( id = "vmessage", name = "Vmessage", - version = "1.1", + version = "1.2", description = "A velocity plugin that creates a multi server chat for the network", authors = {"FeuSalamander"} ) @@ -43,17 +46,40 @@ public class vmessage { this.metricsFactory = metricsFactory; this.dataDirectory = dataDirectory; } - public String message = ""; + private String message = ""; + private boolean messageb = false; + private boolean joinb = false; + private boolean leaveb = false; + private boolean changeb = false; @Subscribe - public void onProxyInitialization(ProxyInitializeEvent event) { + private void onProxyInitialization(ProxyInitializeEvent event) { logger.info("Vmessage by FeuSalamander is working !"); Metrics metrics = metricsFactory.make(this, 16527); + File directory = dataDirectory.toFile(); + File f = new File(directory, "config.toml"); + Toml config = new Toml().read(f); createconfig(); - message = getmessage("Message-format.format"); + if(config.getBoolean("Message.enabled"))messageb = true; + if(config.getBoolean("Join.enabled"))joinb = true; + if(config.getBoolean("Leave.enabled"))leaveb = true; + if(config.getBoolean("Server-change.enabled"))changeb = true; + message = getmessage("Message.format"); } @Subscribe - public void onMessage(PlayerChatEvent e){ + private void onMessage(PlayerChatEvent e){ proxy.getAllServers().stream().forEach(registeredServer -> sendMessage(registeredServer, e.getPlayer(), e.getMessage())); + } + @Subscribe + private void onJoin(LoginEvent e){ + + } + @Subscribe + private void onLeave(DisconnectEvent e){ + + } + @Subscribe + private void onChange(ServerConnectedEvent e){ + } private void sendMessage(RegisteredServer s, Player p, String m){ message = message.replaceAll("#player#", p.getUsername()); @@ -66,10 +92,10 @@ public class vmessage { User user = api.getPlayerAdapter(Player.class).getUser(p); message = message.replaceAll("#prefix#", user.getCachedData().getMetaData().getPrefix().replaceAll("&", "§")); s.sendMessage(Component.text(message)); - message = getmessage("Message-format.format"); + message = getmessage("Message.format"); }else{ s.sendMessage(Component.text(message)); - message = getmessage("Message-format.format"); + message = getmessage("Message.format"); } } } diff --git a/src/main/resources/config.toml b/src/main/resources/config.toml index 6b2bc28..506f37b 100644 --- a/src/main/resources/config.toml +++ b/src/main/resources/config.toml @@ -1,7 +1,32 @@ -[Message-format] +[Message] #place holders: #- "#player#" : return the player name #- "#prefix#" : return the player's luckperms prefix (don't place it if you don't have luckperms on your server) #- "#message#" : return the player's message #- "#server#" : return the player's server name -format = "§a(#server#) #prefix# #player# §8§l> §r#message#" \ No newline at end of file +format = "§a(#server#) #prefix# #player# §8§l> §r#message#" +enabled = true +[Join] +#place holders: +#- "#player#" : return the player name +#- "#prefix#" : return the player's luckperms prefix (don't place it if you don't have luckperms on your server) +#- "#message#" : return the player's message +#- "#server#" : return the player's server name +format = "§a(#server#) #prefix# #player# §8§l> §r#message#" +enabled = true +[Leave] +#place holders: +#- "#player#" : return the player name +#- "#prefix#" : return the player's luckperms prefix (don't place it if you don't have luckperms on your server) +#- "#message#" : return the player's message +#- "#server#" : return the player's server name +format = "§a(#server#) #prefix# #player# §8§l> §r#message#" +enabled = true +[Server-change] +#place holders: +#- "#player#" : return the player name +#- "#prefix#" : return the player's luckperms prefix (don't place it if you don't have luckperms on your server) +#- "#message#" : return the player's message +#- "#server#" : return the player's server name +format = "§a(#server#) #prefix# #player# §8§l> §r#message#" +enabled = true \ No newline at end of file