suffix added, luckperms rework

This commit is contained in:
FeuSalamander 2022-12-25 21:50:44 +01:00 committed by arnaudferreres
parent 73ac5f0fc8
commit 103cac68fb
3 changed files with 24 additions and 15 deletions

View File

@ -16,6 +16,8 @@ import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider; import net.luckperms.api.LuckPermsProvider;
import net.luckperms.api.model.user.User; import net.luckperms.api.model.user.User;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
@ -48,8 +50,7 @@ public final class Listeners {
.replace("#message#", m) .replace("#message#", m)
.replace("#server#", p.getCurrentServer().orElseThrow().getServerInfo().getName()); .replace("#server#", p.getCurrentServer().orElseThrow().getServerInfo().getName());
if (luckPermsAPI != null){ if (luckPermsAPI != null){
User user = luckPermsAPI.getPlayerAdapter(Player.class).getUser(p); message = luckperms(message, p);
message = message.replace("#prefix#", Objects.requireNonNull(user.getCachedData().getMetaData().getPrefix()));
} }
final String finalMessage = message; final String finalMessage = message;
proxyServer.getAllServers().forEach(server -> { proxyServer.getAllServers().forEach(server -> {
@ -67,8 +68,7 @@ public final class Listeners {
String message = configuration.getLeaveFormat() String message = configuration.getLeaveFormat()
.replace("#player#", p.getUsername()); .replace("#player#", p.getUsername());
if (luckPermsAPI != null){ if (luckPermsAPI != null){
User user = luckPermsAPI.getPlayerAdapter(Player.class).getUser(p); message = luckperms(message, p);
message = message.replace("#prefix#", Objects.requireNonNull(user.getCachedData().getMetaData().getPrefix()));
} }
proxyServer.sendMessage(SERIALIZER.deserialize(message)); proxyServer.sendMessage(SERIALIZER.deserialize(message));
} }
@ -91,8 +91,7 @@ public final class Listeners {
.replace("#oldserver#", pre.getServerInfo().getName()) .replace("#oldserver#", pre.getServerInfo().getName())
.replace("#server#", actual.getServerInfo().getName()); .replace("#server#", actual.getServerInfo().getName());
if (luckPermsAPI != null){ if (luckPermsAPI != null){
User user = luckPermsAPI.getPlayerAdapter(Player.class).getUser(p); message = luckperms(message, p);
message = message.replace("#prefix#", Objects.requireNonNull(user.getCachedData().getMetaData().getPrefix()));
} }
proxyServer.sendMessage(SERIALIZER.deserialize(message)); proxyServer.sendMessage(SERIALIZER.deserialize(message));
}else{ }else{
@ -101,10 +100,19 @@ public final class Listeners {
} }
String message = configuration.getJoinFormat().replace("#player#", p.getUsername()); String message = configuration.getJoinFormat().replace("#player#", p.getUsername());
if (luckPermsAPI != null){ if (luckPermsAPI != null){
User user = luckPermsAPI.getPlayerAdapter(Player.class).getUser(p); message = luckperms(message, p);
message = message.replace("#prefix#", Objects.requireNonNull(user.getCachedData().getMetaData().getPrefix()));
} }
proxyServer.sendMessage(SERIALIZER.deserialize(message)); 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;
}
} }

View File

@ -1,8 +1,6 @@
package me.feusalamander.vmessage; package me.feusalamander.vmessage;
import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.SimpleCommand; import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.List; import java.util.List;
@ -17,7 +15,6 @@ public final class ReloadCommand implements SimpleCommand {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
CommandSource source = invocation.source();
String[] args = invocation.arguments(); String[] args = invocation.arguments();
if(args.length == 1){ if(args.length == 1){
return; return;

View File

@ -1,7 +1,8 @@
[Message] [Message]
#place holders: #place holders:
#- "#player#" : return the player name #- "#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 #- "#message#" : return the player's message
#- "#server#" : return the player's server name #- "#server#" : return the player's server name
format = "&a(#server#) #prefix# #player# &8&l> &r#message#" format = "&a(#server#) #prefix# #player# &8&l> &r#message#"
@ -9,19 +10,22 @@ enabled = true
[Join] [Join]
#place holders: #place holders:
#- "#player#" : return the player name #- "#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" format = "&7#prefix# #player# &ejoined the network"
enabled = true enabled = true
[Leave] [Leave]
#place holders: #place holders:
#- "#player#" : return the player name #- "#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" format = "#&7prefix# #player# &eleft the network"
enabled = true enabled = true
[Server-change] [Server-change]
#place holders: #place holders:
#- "#player#" : return the player name #- "#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 #- "#oldserver#" : return the previous player's server name
#- "#server#" : return the new player's server name #- "#server#" : return the new player's server name
format = "&7#prefix# #player# &eleft &c#oldserver# &eto join &a#server#" format = "&7#prefix# #player# &eleft &c#oldserver# &eto join &a#server#"