2019-04-07 13:04:08 -04:00
|
|
|
package com.redstoner.bungee.joinmessages;
|
|
|
|
|
|
|
|
import net.md_5.bungee.api.ChatColor;
|
|
|
|
import net.md_5.bungee.api.config.ServerInfo;
|
|
|
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
|
|
import net.md_5.bungee.api.event.ServerConnectEvent;
|
|
|
|
import net.md_5.bungee.api.event.ServerDisconnectEvent;
|
|
|
|
import net.md_5.bungee.api.plugin.Listener;
|
|
|
|
import net.md_5.bungee.api.plugin.Plugin;
|
|
|
|
import net.md_5.bungee.event.EventHandler;
|
2019-04-07 16:31:51 -04:00
|
|
|
import net.md_5.bungee.event.EventPriority;
|
2019-04-07 13:04:08 -04:00
|
|
|
|
2019-04-07 16:31:51 -04:00
|
|
|
public class JoinMessages extends Plugin implements Listener {
|
|
|
|
|
2019-04-07 13:04:08 -04:00
|
|
|
private String loginString = "&a&l+ &7%s";
|
|
|
|
private String logoutString = "&c&l- &7%s";
|
|
|
|
|
2019-04-07 16:31:51 -04:00
|
|
|
public void onEnable() {
|
2019-04-07 13:04:08 -04:00
|
|
|
getProxy().registerChannel("JoinMessage");
|
2019-04-07 16:31:51 -04:00
|
|
|
getProxy().getPluginManager().registerCommand(this, new CommandServer());
|
2019-04-07 13:04:08 -04:00
|
|
|
getProxy().getPluginManager().registerListener(this, this);
|
|
|
|
}
|
|
|
|
|
2019-04-07 16:31:51 -04:00
|
|
|
@EventHandler(priority = EventPriority.HIGHEST)
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
public void onServerConnect(ServerConnectEvent e) {
|
|
|
|
|
|
|
|
if (e.isCancelled())
|
|
|
|
return;
|
|
|
|
|
2019-04-07 13:04:08 -04:00
|
|
|
ServerInfo target = e.getTarget();
|
|
|
|
ProxiedPlayer jp = e.getPlayer();
|
2019-04-07 16:31:51 -04:00
|
|
|
|
|
|
|
if (CommandServer.justSwitched.contains(jp))
|
2019-04-07 13:04:08 -04:00
|
|
|
return;
|
2019-04-07 16:31:51 -04:00
|
|
|
|
|
|
|
String joinMessage = ChatColor.translateAlternateColorCodes('&',
|
|
|
|
String.format(this.loginString, new Object[] { jp.getName() }));
|
|
|
|
|
|
|
|
for (ProxiedPlayer p : target.getPlayers())
|
2019-04-07 13:04:08 -04:00
|
|
|
p.sendMessage(joinMessage);
|
2019-04-07 16:31:51 -04:00
|
|
|
|
2019-04-07 13:04:08 -04:00
|
|
|
jp.sendMessage(joinMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
2019-04-07 16:31:51 -04:00
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
public void onServerDisconnect(ServerDisconnectEvent e) {
|
|
|
|
|
2019-04-07 13:04:08 -04:00
|
|
|
ServerInfo target = e.getTarget();
|
|
|
|
ProxiedPlayer jp = e.getPlayer();
|
2019-04-07 16:31:51 -04:00
|
|
|
|
|
|
|
if (CommandServer.justSwitched.contains(jp)) {
|
|
|
|
CommandServer.justSwitched.remove(jp);
|
2019-04-07 13:04:08 -04:00
|
|
|
return;
|
|
|
|
}
|
2019-04-07 16:31:51 -04:00
|
|
|
|
|
|
|
String leaveMessage = ChatColor.translateAlternateColorCodes('&',
|
|
|
|
String.format(this.logoutString, new Object[] { jp.getName() }));
|
|
|
|
|
|
|
|
for (ProxiedPlayer p : target.getPlayers())
|
2019-04-07 13:04:08 -04:00
|
|
|
p.sendMessage(leaveMessage);
|
|
|
|
}
|
|
|
|
}
|