finished join and leave
This commit is contained in:
parent
1153a65d48
commit
304c921a60
@ -46,7 +46,14 @@ public class vmessage {
|
|||||||
this.metricsFactory = metricsFactory;
|
this.metricsFactory = metricsFactory;
|
||||||
this.dataDirectory = dataDirectory;
|
this.dataDirectory = dataDirectory;
|
||||||
}
|
}
|
||||||
|
private String messageraw = "";
|
||||||
|
private String joinraw = "";
|
||||||
|
private String leaveraw = "";
|
||||||
|
private String changeraw = "";
|
||||||
private String message = "";
|
private String message = "";
|
||||||
|
private String join = "";
|
||||||
|
private String leave = "";
|
||||||
|
private String change = "";
|
||||||
private boolean messageb = false;
|
private boolean messageb = false;
|
||||||
private boolean joinb = false;
|
private boolean joinb = false;
|
||||||
private boolean leaveb = false;
|
private boolean leaveb = false;
|
||||||
@ -63,42 +70,59 @@ public class vmessage {
|
|||||||
if(config.getBoolean("Join.enabled"))joinb = true;
|
if(config.getBoolean("Join.enabled"))joinb = true;
|
||||||
if(config.getBoolean("Leave.enabled"))leaveb = true;
|
if(config.getBoolean("Leave.enabled"))leaveb = true;
|
||||||
if(config.getBoolean("Server-change.enabled"))changeb = 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
|
@Subscribe
|
||||||
private void onMessage(PlayerChatEvent e){
|
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
|
@Subscribe
|
||||||
private void onJoin(LoginEvent e){
|
private void onJoin(LoginEvent e){
|
||||||
|
if(joinb) proxy.getAllServers().forEach(registeredServer -> join(registeredServer, e.getPlayer()));
|
||||||
}
|
}
|
||||||
@Subscribe
|
@Subscribe
|
||||||
private void onLeave(DisconnectEvent e){
|
private void onLeave(DisconnectEvent e){
|
||||||
|
if(leaveb) proxy.getAllServers().forEach(registeredServer -> leave(registeredServer, e.getPlayer()));
|
||||||
}
|
}
|
||||||
@Subscribe
|
@Subscribe
|
||||||
private void onChange(ServerConnectedEvent e){
|
private void onChange(ServerConnectedEvent e){
|
||||||
|
|
||||||
}
|
}
|
||||||
private void sendMessage(RegisteredServer s, Player p, String m){
|
private void sendMessage(RegisteredServer s, Player p, String m){
|
||||||
message = message.replaceAll("#player#", p.getUsername());
|
message = messageraw.replaceAll("#player#", p.getUsername()).replaceAll("#message#",m).replaceAll("#server#",p.getCurrentServer().get().getServerInfo().getName()).replaceAll("&", "§");
|
||||||
message = message.replaceAll("#message#",m);
|
|
||||||
message = message.replaceAll("#server#",p.getCurrentServer().get().getServerInfo().getName());
|
|
||||||
message = message.replaceAll("&", "§");
|
|
||||||
if(!(Objects.equals(p.getCurrentServer().get().getServerInfo().getName(), s.getServerInfo().getName()))){
|
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));
|
|
||||||
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(){
|
private void createconfig(){
|
||||||
File dataDirectoryFile = this.dataDirectory.toFile();
|
File dataDirectoryFile = this.dataDirectory.toFile();
|
||||||
if (!dataDirectoryFile.exists()){
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -10,23 +10,19 @@ 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)
|
||||||
#- "#message#" : return the player's message
|
format = "#prefix# §e#player# joined the network"
|
||||||
#- "#server#" : return the player's server name
|
|
||||||
format = "§a(#server#) #prefix# #player# §8§l> §r#message#"
|
|
||||||
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)
|
||||||
#- "#message#" : return the player's message
|
format = "#prefix# §e#player# left the network"
|
||||||
#- "#server#" : return the player's server name
|
|
||||||
format = "§a(#server#) #prefix# #player# §8§l> §r#message#"
|
|
||||||
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 (don't place it if you don't have luckperms on your server)
|
||||||
#- "#message#" : return the player's message
|
#- "#oldserver#" : return the previous player's server name
|
||||||
#- "#server#" : return the player's server name
|
#- "#server#" : return the new player's server name
|
||||||
format = "§a(#server#) #prefix# #player# §8§l> §r#message#"
|
format = "§a(#server#) #prefix# #player# §8§l> §r#message#"
|
||||||
enabled = true
|
enabled = true
|
Loading…
Reference in New Issue
Block a user