From 103cac68fba5b9d977401fb88313118abb1a16e8 Mon Sep 17 00:00:00 2001 From: FeuSalamander Date: Sun, 25 Dec 2022 21:50:44 +0100 Subject: [PATCH] suffix added, luckperms rework --- .../me/feusalamander/vmessage/Listeners.java | 24 ++++++++++++------- .../feusalamander/vmessage/ReloadCommand.java | 3 --- src/main/resources/config.toml | 12 ++++++---- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/main/java/me/feusalamander/vmessage/Listeners.java b/src/main/java/me/feusalamander/vmessage/Listeners.java index b566b67..f1af910 100644 --- a/src/main/java/me/feusalamander/vmessage/Listeners.java +++ b/src/main/java/me/feusalamander/vmessage/Listeners.java @@ -16,6 +16,8 @@ import net.luckperms.api.LuckPerms; import net.luckperms.api.LuckPermsProvider; import net.luckperms.api.model.user.User; +import java.text.SimpleDateFormat; +import java.time.LocalDateTime; import java.util.Objects; import java.util.Optional; @@ -48,8 +50,7 @@ public final class Listeners { .replace("#message#", m) .replace("#server#", p.getCurrentServer().orElseThrow().getServerInfo().getName()); if (luckPermsAPI != null){ - User user = luckPermsAPI.getPlayerAdapter(Player.class).getUser(p); - message = message.replace("#prefix#", Objects.requireNonNull(user.getCachedData().getMetaData().getPrefix())); + message = luckperms(message, p); } final String finalMessage = message; proxyServer.getAllServers().forEach(server -> { @@ -67,8 +68,7 @@ public final class Listeners { String message = configuration.getLeaveFormat() .replace("#player#", p.getUsername()); if (luckPermsAPI != null){ - User user = luckPermsAPI.getPlayerAdapter(Player.class).getUser(p); - message = message.replace("#prefix#", Objects.requireNonNull(user.getCachedData().getMetaData().getPrefix())); + message = luckperms(message, p); } proxyServer.sendMessage(SERIALIZER.deserialize(message)); } @@ -91,8 +91,7 @@ public final class Listeners { .replace("#oldserver#", pre.getServerInfo().getName()) .replace("#server#", actual.getServerInfo().getName()); if (luckPermsAPI != null){ - User user = luckPermsAPI.getPlayerAdapter(Player.class).getUser(p); - message = message.replace("#prefix#", Objects.requireNonNull(user.getCachedData().getMetaData().getPrefix())); + message = luckperms(message, p); } proxyServer.sendMessage(SERIALIZER.deserialize(message)); }else{ @@ -101,10 +100,19 @@ public final class Listeners { } String message = configuration.getJoinFormat().replace("#player#", p.getUsername()); if (luckPermsAPI != null){ - User user = luckPermsAPI.getPlayerAdapter(Player.class).getUser(p); - message = message.replace("#prefix#", Objects.requireNonNull(user.getCachedData().getMetaData().getPrefix())); + message = luckperms(message, p); } proxyServer.sendMessage(SERIALIZER.deserialize(message)); } } + private String luckperms(String message, Player p){ + User user = luckPermsAPI.getPlayerAdapter(Player.class).getUser(p); + if(message.contains("#prefix#")){ + message = message.replace("#prefix#", Objects.requireNonNull(user.getCachedData().getMetaData().getPrefix())); + } + if(message.contains("#suffix#")){ + message = message.replace("#suffix#", Objects.requireNonNull(user.getCachedData().getMetaData().getSuffix())); + } + return message; + } } diff --git a/src/main/java/me/feusalamander/vmessage/ReloadCommand.java b/src/main/java/me/feusalamander/vmessage/ReloadCommand.java index 9543d5d..653ed8a 100644 --- a/src/main/java/me/feusalamander/vmessage/ReloadCommand.java +++ b/src/main/java/me/feusalamander/vmessage/ReloadCommand.java @@ -1,8 +1,6 @@ package me.feusalamander.vmessage; import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.command.SimpleCommand; -import com.velocitypowered.api.plugin.annotation.DataDirectory; - import java.nio.file.Path; import java.util.concurrent.CompletableFuture; import java.util.List; @@ -17,7 +15,6 @@ public final class ReloadCommand implements SimpleCommand { @Override public void execute(final Invocation invocation) { - CommandSource source = invocation.source(); String[] args = invocation.arguments(); if(args.length == 1){ return; diff --git a/src/main/resources/config.toml b/src/main/resources/config.toml index 39fa1e8..c81689a 100644 --- a/src/main/resources/config.toml +++ b/src/main/resources/config.toml @@ -1,7 +1,8 @@ [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) +#- "#prefix#" : return the player's luckperms prefix +#- "#suffix#" : return the player's luckperms suffix #- "#message#" : return the player's message #- "#server#" : return the player's server name format = "&a(#server#) #prefix# #player# &8&l> &r#message#" @@ -9,19 +10,22 @@ 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) +#- "#prefix#" : return the player's luckperms prefix +#- "#suffix#" : return the player's luckperms suffix 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) +#- "#prefix#" : return the player's luckperms prefix +#- "#suffix#" : return the player's luckperms suffix format = "#&7prefix# #player# &eleft 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) +#- "#prefix#" : return the player's luckperms prefix +#- "#suffix#" : return the player's luckperms suffix #- "#oldserver#" : return the previous player's server name #- "#server#" : return the new player's server name format = "&7#prefix# #player# &eleft &c#oldserver# &eto join &a#server#"