From 19679e85f22aad9b61f0926fd76817f515cfe915 Mon Sep 17 00:00:00 2001 From: FeuSalamander Date: Sat, 17 Dec 2022 15:52:45 +0100 Subject: [PATCH] finished 1.2 --- .../me/feusalamander/vmessage/vmessage.java | 90 +++++++++++-------- src/main/resources/config.toml | 6 +- 2 files changed, 58 insertions(+), 38 deletions(-) diff --git a/src/main/java/me/feusalamander/vmessage/vmessage.java b/src/main/java/me/feusalamander/vmessage/vmessage.java index 5971356..5719589 100644 --- a/src/main/java/me/feusalamander/vmessage/vmessage.java +++ b/src/main/java/me/feusalamander/vmessage/vmessage.java @@ -14,7 +14,6 @@ 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,6 +22,9 @@ import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.Objects; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; + @Plugin( id = "vmessage", name = "Vmessage", @@ -77,51 +79,69 @@ public class vmessage { } @Subscribe private void onMessage(PlayerChatEvent e){ - if(messageb) proxy.getAllServers().forEach(registeredServer -> sendMessage(registeredServer, e.getPlayer(), e.getMessage())); - } - @Subscribe - private void onJoin(LoginEvent e){ - if(joinb) proxy.getAllServers().forEach(registeredServer -> join(registeredServer, e.getPlayer())); - } - @Subscribe - private void onLeave(DisconnectEvent e){ - if(leaveb) proxy.getAllServers().forEach(registeredServer -> leave(registeredServer, e.getPlayer())); - } - @Subscribe - private void onChange(ServerConnectedEvent e){ - - } - private void sendMessage(RegisteredServer s, Player p, String m){ - message = messageraw.replaceAll("#player#", p.getUsername()).replaceAll("#message#",m).replaceAll("#server#",p.getCurrentServer().get().getServerInfo().getName()).replaceAll("&", "§"); - if(!(Objects.equals(p.getCurrentServer().get().getServerInfo().getName(), s.getServerInfo().getName()))){ + if(messageb){ + Player p = e.getPlayer(); + String m = e.getMessage(); + message = messageraw.replaceAll("#player#", p.getUsername()).replaceAll("#message#",m).replaceAll("#server#",p.getCurrentServer().get().getServerInfo().getName()).replaceAll("&", "§"); if(proxy.getPluginManager().getPlugin("luckperms").isPresent()){ LuckPerms api = LuckPermsProvider.get(); User user = api.getPlayerAdapter(Player.class).getUser(p); message = message.replaceAll("#prefix#", user.getCachedData().getMetaData().getPrefix().replaceAll("&", "§")); } - s.sendMessage(Component.text(message)); + proxy.getAllServers().forEach(registeredServer -> sendMessage(registeredServer, p)); message = ""; } } - private void join(RegisteredServer s, Player p){ - join = joinraw.replaceAll("#player#", p.getUsername()); - if(proxy.getPluginManager().getPlugin("luckperms").isPresent()){ - LuckPerms api = LuckPermsProvider.get(); - User user = api.getPlayerAdapter(Player.class).getUser(p); - join = join.replaceAll("#prefix#", user.getCachedData().getMetaData().getPrefix().replaceAll("&", "§")); + @Subscribe + private void onJoin(LoginEvent e){ + if(joinb){ + Player p = e.getPlayer(); + join = joinraw.replaceAll("#player#", p.getUsername()); + if(proxy.getPluginManager().getPlugin("luckperms").isPresent()){ + LuckPerms api = LuckPermsProvider.get(); + User user = api.getPlayerAdapter(Player.class).getUser(p); + join = join.replaceAll("#prefix#", user.getCachedData().getMetaData().getPrefix().replaceAll("&", "§")); + } + proxy.getAllServers().forEach(registeredServer -> registeredServer.sendMessage(Component.text(join))); + join = ""; } - s.sendMessage(Component.text(join)); - join = ""; } - private void leave(RegisteredServer s, Player p){ - leave = leaveraw.replaceAll("#player#", p.getUsername()); - if(proxy.getPluginManager().getPlugin("luckperms").isPresent()){ - LuckPerms api = LuckPermsProvider.get(); - User user = api.getPlayerAdapter(Player.class).getUser(p); - leave = leave.replaceAll("#prefix#", user.getCachedData().getMetaData().getPrefix().replaceAll("&", "§")); + @Subscribe + private void onLeave(DisconnectEvent e){ + if(leaveb){ + Player p = e.getPlayer(); + leave = leaveraw.replaceAll("#player#", p.getUsername()); + if(proxy.getPluginManager().getPlugin("luckperms").isPresent()){ + LuckPerms api = LuckPermsProvider.get(); + User user = api.getPlayerAdapter(Player.class).getUser(p); + leave = leave.replaceAll("#prefix#", user.getCachedData().getMetaData().getPrefix().replaceAll("&", "§")); + } + proxy.getAllServers().forEach(registeredServer -> registeredServer.sendMessage(Component.text(leave))); + leave = ""; + } + } + @Subscribe + private void onChange(ServerConnectedEvent e){ + if(changeb){ + Optional old = e.getPreviousServer(); + RegisteredServer New = e.getServer(); + Player p = e.getPlayer(); + if(old.isPresent()){ + change = changeraw.replaceAll("#player#", p.getUsername()).replaceAll("#oldserver#", old.get().getServerInfo().getName()).replaceAll("#server#", New.getServerInfo().getName()); + if(proxy.getPluginManager().getPlugin("luckperms").isPresent()){ + LuckPerms api = LuckPermsProvider.get(); + User user = api.getPlayerAdapter(Player.class).getUser(p); + change = change.replaceAll("#prefix#", user.getCachedData().getMetaData().getPrefix().replaceAll("&", "§")); + } + proxy.getAllServers().forEach(registeredServer -> registeredServer.sendMessage(Component.text(change))); + change = ""; + } + } + } + private void sendMessage(RegisteredServer s, Player p){ + if(!(Objects.equals(p.getCurrentServer().get().getServerInfo().getName(), s.getServerInfo().getName()))){ + s.sendMessage(Component.text(message)); } - s.sendMessage(Component.text(leave)); - leave = ""; } private void createconfig(){ File dataDirectoryFile = this.dataDirectory.toFile(); diff --git a/src/main/resources/config.toml b/src/main/resources/config.toml index faf3808..cd7d74e 100644 --- a/src/main/resources/config.toml +++ b/src/main/resources/config.toml @@ -10,13 +10,13 @@ enabled = true #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) -format = "#prefix# §e#player# joined the network" +format = "§7#prefix# #player# §ejoined the network" 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) -format = "#prefix# §e#player# left the network" +format = "#§7prefix# #player# §eleft the network" enabled = true [Server-change] #place holders: @@ -24,5 +24,5 @@ enabled = true #- "#prefix#" : return the player's luckperms prefix (don't place it if you don't have luckperms on your server) #- "#oldserver#" : return the previous player's server name #- "#server#" : return the new player's server name -format = "§a(#server#) #prefix# #player# §8§l> §r#message#" +format = "§7#prefix# #player# §eleft §c#oldserver# §eto join §a#server#" enabled = true \ No newline at end of file