finished 1.2

This commit is contained in:
FeuSalamander 2022-12-17 15:52:45 +01:00
parent 304c921a60
commit 19679e85f2
2 changed files with 58 additions and 38 deletions

View File

@ -14,7 +14,6 @@ import com.velocitypowered.api.proxy.server.RegisteredServer;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.luckperms.api.LuckPerms; import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider; import net.luckperms.api.LuckPermsProvider;
import net.luckperms.api.event.player.PlayerLoginProcessEvent;
import net.luckperms.api.model.user.User; import net.luckperms.api.model.user.User;
import org.slf4j.Logger; import org.slf4j.Logger;
import java.io.File; import java.io.File;
@ -23,6 +22,9 @@ import java.io.InputStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
@Plugin( @Plugin(
id = "vmessage", id = "vmessage",
name = "Vmessage", name = "Vmessage",
@ -77,52 +79,70 @@ public class vmessage {
} }
@Subscribe @Subscribe
private void onMessage(PlayerChatEvent e){ private void onMessage(PlayerChatEvent e){
if(messageb) proxy.getAllServers().forEach(registeredServer -> sendMessage(registeredServer, e.getPlayer(), e.getMessage())); if(messageb){
} Player p = e.getPlayer();
@Subscribe String m = e.getMessage();
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("&", "§"); 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()){ if(proxy.getPluginManager().getPlugin("luckperms").isPresent()){
LuckPerms api = LuckPermsProvider.get(); LuckPerms api = LuckPermsProvider.get();
User user = api.getPlayerAdapter(Player.class).getUser(p); User user = api.getPlayerAdapter(Player.class).getUser(p);
message = message.replaceAll("#prefix#", user.getCachedData().getMetaData().getPrefix().replaceAll("&", "§")); message = message.replaceAll("#prefix#", user.getCachedData().getMetaData().getPrefix().replaceAll("&", "§"));
} }
s.sendMessage(Component.text(message)); proxy.getAllServers().forEach(registeredServer -> sendMessage(registeredServer, p));
message = ""; message = "";
} }
} }
private void join(RegisteredServer s, Player p){ @Subscribe
private void onJoin(LoginEvent e){
if(joinb){
Player p = e.getPlayer();
join = joinraw.replaceAll("#player#", p.getUsername()); join = joinraw.replaceAll("#player#", p.getUsername());
if(proxy.getPluginManager().getPlugin("luckperms").isPresent()){ if(proxy.getPluginManager().getPlugin("luckperms").isPresent()){
LuckPerms api = LuckPermsProvider.get(); LuckPerms api = LuckPermsProvider.get();
User user = api.getPlayerAdapter(Player.class).getUser(p); User user = api.getPlayerAdapter(Player.class).getUser(p);
join = join.replaceAll("#prefix#", user.getCachedData().getMetaData().getPrefix().replaceAll("&", "§")); join = join.replaceAll("#prefix#", user.getCachedData().getMetaData().getPrefix().replaceAll("&", "§"));
} }
s.sendMessage(Component.text(join)); proxy.getAllServers().forEach(registeredServer -> registeredServer.sendMessage(Component.text(join)));
join = ""; join = "";
} }
private void leave(RegisteredServer s, Player p){ }
@Subscribe
private void onLeave(DisconnectEvent e){
if(leaveb){
Player p = e.getPlayer();
leave = leaveraw.replaceAll("#player#", p.getUsername()); leave = leaveraw.replaceAll("#player#", p.getUsername());
if(proxy.getPluginManager().getPlugin("luckperms").isPresent()){ if(proxy.getPluginManager().getPlugin("luckperms").isPresent()){
LuckPerms api = LuckPermsProvider.get(); LuckPerms api = LuckPermsProvider.get();
User user = api.getPlayerAdapter(Player.class).getUser(p); User user = api.getPlayerAdapter(Player.class).getUser(p);
leave = leave.replaceAll("#prefix#", user.getCachedData().getMetaData().getPrefix().replaceAll("&", "§")); leave = leave.replaceAll("#prefix#", user.getCachedData().getMetaData().getPrefix().replaceAll("&", "§"));
} }
s.sendMessage(Component.text(leave)); proxy.getAllServers().forEach(registeredServer -> registeredServer.sendMessage(Component.text(leave)));
leave = ""; leave = "";
} }
}
@Subscribe
private void onChange(ServerConnectedEvent e){
if(changeb){
Optional<RegisteredServer> 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));
}
}
private void createconfig(){ private void createconfig(){
File dataDirectoryFile = this.dataDirectory.toFile(); File dataDirectoryFile = this.dataDirectory.toFile();
if (!dataDirectoryFile.exists()){ if (!dataDirectoryFile.exists()){

View File

@ -10,13 +10,13 @@ enabled = true
#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 (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 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 (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 enabled = true
[Server-change] [Server-change]
#place holders: #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) #- "#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 #- "#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 = a(#server#) #prefix# #player# §8§l> §r#message#" format = 7#prefix# #player# §eleft §c#oldserver# §eto join §a#server#"
enabled = true enabled = true