mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-01 05:57:09 +00:00
71 lines
2.0 KiB
Java
71 lines
2.0 KiB
Java
package me.totalfreedom.totalfreedommod;
|
|
|
|
import com.google.gson.Gson;
|
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.EventPriority;
|
|
import org.bukkit.event.server.ServerListPingEvent;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
public class ServerPing extends FreedomService
|
|
{
|
|
private final Gson gson = new Gson();
|
|
private final VersionMeta meta = gson.fromJson(new InputStreamReader(Bukkit.class.getClassLoader().getResourceAsStream("version.json")),VersionMeta.class);
|
|
|
|
@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.motd(FUtil.miniMessage(ConfigEntry.SERVER_BAN_MOTD.getString()));
|
|
return;
|
|
}
|
|
|
|
if (ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
|
|
{
|
|
event.motd(FUtil.miniMessage(ConfigEntry.SERVER_ADMINMODE_MOTD.getString()));
|
|
return;
|
|
}
|
|
|
|
if (LoginProcess.isLockdownEnabled())
|
|
{
|
|
event.motd(FUtil.miniMessage(ConfigEntry.SERVER_LOCKDOWN_MOTD.getString()));
|
|
return;
|
|
}
|
|
|
|
if (Bukkit.hasWhitelist())
|
|
{
|
|
event.motd(FUtil.miniMessage(ConfigEntry.SERVER_WHITELIST_MOTD.getString()));
|
|
return;
|
|
}
|
|
|
|
if (Bukkit.getOnlinePlayers().size() >= Bukkit.getMaxPlayers())
|
|
{
|
|
event.motd(FUtil.miniMessage(ConfigEntry.SERVER_FULL_MOTD.getString()));
|
|
return;
|
|
}
|
|
|
|
event.motd(FUtil.miniMessage(ConfigEntry.SERVER_MOTD.getString(), Placeholder.unparsed("version", meta.id)));
|
|
}
|
|
|
|
private static class VersionMeta
|
|
{
|
|
private String id;
|
|
}
|
|
} |