2015-11-15 23:32:04 +00:00
|
|
|
package me.totalfreedom.totalfreedommod;
|
2015-10-19 17:43:46 +00:00
|
|
|
|
|
|
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.server.ServerListPingEvent;
|
|
|
|
|
2016-03-01 16:47:01 +00:00
|
|
|
public class ServerPing extends FreedomService
|
2015-10-19 17:43:46 +00:00
|
|
|
{
|
2015-11-15 23:32:04 +00:00
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStart()
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStop()
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.HIGH)
|
2015-10-19 17:43:46 +00:00
|
|
|
public void onServerPing(ServerListPingEvent event)
|
|
|
|
{
|
|
|
|
final String ip = event.getAddress().getHostAddress().trim();
|
|
|
|
|
|
|
|
if (plugin.bm.isIpBanned(ip))
|
|
|
|
{
|
2020-01-04 23:35:41 +00:00
|
|
|
event.setMotd(FUtil.colorize(ConfigEntry.SERVER_BAN_MOTD.getString()));
|
2015-10-19 17:43:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
if (ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
|
2015-10-19 17:43:46 +00:00
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
event.setMotd(FUtil.colorize(ConfigEntry.SERVER_ADMINMODE_MOTD.getString()));
|
2015-10-19 17:43:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-18 08:32:50 +00:00
|
|
|
if (LoginProcess.isLockdownEnabled())
|
|
|
|
{
|
2020-01-04 23:35:41 +00:00
|
|
|
event.setMotd(FUtil.colorize(ConfigEntry.SERVER_LOCKDOWN_MOTD.getString()));
|
2018-03-18 08:32:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
if (Bukkit.hasWhitelist())
|
|
|
|
{
|
2020-01-04 23:35:41 +00:00
|
|
|
event.setMotd(FUtil.colorize(ConfigEntry.SERVER_WHITELIST_MOTD.getString()));
|
2015-10-19 17:43:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Bukkit.getOnlinePlayers().size() >= Bukkit.getMaxPlayers())
|
|
|
|
{
|
2020-01-04 23:35:41 +00:00
|
|
|
event.setMotd(FUtil.colorize(ConfigEntry.SERVER_FULL_MOTD.getString()));
|
2015-10-19 17:43:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-18 08:32:50 +00:00
|
|
|
String baseMotd = ConfigEntry.SERVER_MOTD.getString().replace("%mcversion%", plugin.si.getVersion());
|
2016-05-12 19:40:39 +00:00
|
|
|
baseMotd = baseMotd.replace("\\n", "\n");
|
|
|
|
baseMotd = FUtil.colorize(baseMotd);
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
if (!ConfigEntry.SERVER_COLORFUL_MOTD.getBoolean())
|
|
|
|
{
|
2016-05-12 19:40:39 +00:00
|
|
|
event.setMotd(baseMotd);
|
2015-10-19 17:43:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-02 19:28:01 +00:00
|
|
|
// Colorful MOTD
|
2015-10-19 17:43:46 +00:00
|
|
|
final StringBuilder motd = new StringBuilder();
|
2016-05-12 19:40:39 +00:00
|
|
|
for (String word : baseMotd.split(" "))
|
2015-10-19 17:43:46 +00:00
|
|
|
{
|
|
|
|
motd.append(FUtil.randomChatColor()).append(word).append(" ");
|
|
|
|
}
|
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
event.setMotd(motd.toString().trim());
|
2015-10-19 17:43:46 +00:00
|
|
|
}
|
2020-12-04 00:28:53 +00:00
|
|
|
}
|