From 304c921a600e46ab518e349d69416563db0acf9f Mon Sep 17 00:00:00 2001 From: FeuSalamander Date: Mon, 12 Dec 2022 17:28:35 +0100 Subject: [PATCH] finished join and leave --- .../me/feusalamander/vmessage/vmessage.java | 56 ++++++++++++------- src/main/resources/config.toml | 12 ++-- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/main/java/me/feusalamander/vmessage/vmessage.java b/src/main/java/me/feusalamander/vmessage/vmessage.java index 62ffa5f..5971356 100644 --- a/src/main/java/me/feusalamander/vmessage/vmessage.java +++ b/src/main/java/me/feusalamander/vmessage/vmessage.java @@ -46,7 +46,14 @@ public class vmessage { this.metricsFactory = metricsFactory; this.dataDirectory = dataDirectory; } + private String messageraw = ""; + private String joinraw = ""; + private String leaveraw = ""; + private String changeraw = ""; private String message = ""; + private String join = ""; + private String leave = ""; + private String change = ""; private boolean messageb = false; private boolean joinb = false; private boolean leaveb = false; @@ -63,42 +70,59 @@ public class vmessage { 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"); + messageraw = config.getString("Message.format"); + joinraw = config.getString("Join.format"); + leaveraw = config.getString("Leave.format"); + changeraw = config.getString("Server-change.format"); } @Subscribe private void onMessage(PlayerChatEvent e){ - proxy.getAllServers().stream().forEach(registeredServer -> sendMessage(registeredServer, e.getPlayer(), e.getMessage())); + 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 = message.replaceAll("#player#", p.getUsername()); - message = message.replaceAll("#message#",m); - message = message.replaceAll("#server#",p.getCurrentServer().get().getServerInfo().getName()); - message = message.replaceAll("&", "§"); + 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(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)); - message = getmessage("Message.format"); - }else{ - s.sendMessage(Component.text(message)); - message = getmessage("Message.format"); } + s.sendMessage(Component.text(message)); + 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("&", "§")); + } + 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("&", "§")); + } + s.sendMessage(Component.text(leave)); + leave = ""; + } private void createconfig(){ File dataDirectoryFile = this.dataDirectory.toFile(); if (!dataDirectoryFile.exists()){ @@ -114,10 +138,4 @@ public class vmessage { } } } - private String getmessage(String s){ - File directory = dataDirectory.toFile(); - File f = new File(directory, "config.toml"); - Toml config = new Toml().read(f); - return config.getString(s); - } } diff --git a/src/main/resources/config.toml b/src/main/resources/config.toml index 506f37b..faf3808 100644 --- a/src/main/resources/config.toml +++ b/src/main/resources/config.toml @@ -10,23 +10,19 @@ 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) -#- "#message#" : return the player's message -#- "#server#" : return the player's server name -format = "§a(#server#) #prefix# #player# §8§l> §r#message#" +format = "#prefix# §e#player# joined 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) -#- "#message#" : return the player's message -#- "#server#" : return the player's server name -format = "§a(#server#) #prefix# #player# §8§l> §r#message#" +format = "#prefix# §e#player# left the network" 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 +#- "#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#" enabled = true \ No newline at end of file