TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/ServerPing.java
speed 293ea04c56 staff -> admins
* rename everything containing staff back to admin (as requested by ryan i've renamed commands like slconfig to saconfig but left "slconfig" as an alias)
* format almost every file correctly
* a few other improvements
2020-12-03 19:28:53 -05:00

76 lines
2.1 KiB
Java

package me.totalfreedom.totalfreedommod;
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;
public class ServerPing extends FreedomService
{
@Override
public void onStart()
{
}
@Override
public void onStop()
{
}
@EventHandler(priority = EventPriority.HIGH)
public void onServerPing(ServerListPingEvent event)
{
final String ip = event.getAddress().getHostAddress().trim();
if (plugin.bm.isIpBanned(ip))
{
event.setMotd(FUtil.colorize(ConfigEntry.SERVER_BAN_MOTD.getString()));
return;
}
if (ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
{
event.setMotd(FUtil.colorize(ConfigEntry.SERVER_ADMINMODE_MOTD.getString()));
return;
}
if (LoginProcess.isLockdownEnabled())
{
event.setMotd(FUtil.colorize(ConfigEntry.SERVER_LOCKDOWN_MOTD.getString()));
return;
}
if (Bukkit.hasWhitelist())
{
event.setMotd(FUtil.colorize(ConfigEntry.SERVER_WHITELIST_MOTD.getString()));
return;
}
if (Bukkit.getOnlinePlayers().size() >= Bukkit.getMaxPlayers())
{
event.setMotd(FUtil.colorize(ConfigEntry.SERVER_FULL_MOTD.getString()));
return;
}
String baseMotd = ConfigEntry.SERVER_MOTD.getString().replace("%mcversion%", plugin.si.getVersion());
baseMotd = baseMotd.replace("\\n", "\n");
baseMotd = FUtil.colorize(baseMotd);
if (!ConfigEntry.SERVER_COLORFUL_MOTD.getBoolean())
{
event.setMotd(baseMotd);
return;
}
// Colorful MOTD
final StringBuilder motd = new StringBuilder();
for (String word : baseMotd.split(" "))
{
motd.append(FUtil.randomChatColor()).append(word).append(" ");
}
event.setMotd(motd.toString().trim());
}
}