2015-11-15 23:32:04 +00:00
|
|
|
package me.totalfreedom.totalfreedommod;
|
2015-10-19 17:43:46 +00:00
|
|
|
|
2022-03-25 20:45:32 +00:00
|
|
|
import com.google.gson.Gson;
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
2023-03-27 03:59:17 +00:00
|
|
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
2015-10-19 17:43:46 +00:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.server.ServerListPingEvent;
|
|
|
|
|
2022-03-25 20:45:32 +00:00
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
2016-03-01 16:47:01 +00:00
|
|
|
public class ServerPing extends FreedomService
|
2015-10-19 17:43:46 +00:00
|
|
|
{
|
2022-03-25 20:45:32 +00:00
|
|
|
private final Gson gson = new Gson();
|
|
|
|
private final VersionMeta meta = gson.fromJson(new InputStreamReader(Bukkit.class.getClassLoader().getResourceAsStream("version.json")),VersionMeta.class);
|
|
|
|
|
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))
|
|
|
|
{
|
2023-03-27 03:59:17 +00:00
|
|
|
event.motd(FUtil.miniMessage(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
|
|
|
{
|
2023-03-27 03:59:17 +00:00
|
|
|
event.motd(FUtil.miniMessage(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())
|
|
|
|
{
|
2023-03-27 03:59:17 +00:00
|
|
|
event.motd(FUtil.miniMessage(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())
|
|
|
|
{
|
2023-03-27 03:59:17 +00:00
|
|
|
event.motd(FUtil.miniMessage(ConfigEntry.SERVER_WHITELIST_MOTD.getString()));
|
2015-10-19 17:43:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Bukkit.getOnlinePlayers().size() >= Bukkit.getMaxPlayers())
|
|
|
|
{
|
2023-03-27 03:59:17 +00:00
|
|
|
event.motd(FUtil.miniMessage(ConfigEntry.SERVER_FULL_MOTD.getString()));
|
2015-10-19 17:43:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-27 03:59:17 +00:00
|
|
|
event.motd(FUtil.miniMessage(ConfigEntry.SERVER_MOTD.getString(), Placeholder.unparsed("version", meta.id)));
|
2015-10-19 17:43:46 +00:00
|
|
|
}
|
2022-03-25 20:45:32 +00:00
|
|
|
|
|
|
|
private static class VersionMeta
|
|
|
|
{
|
|
|
|
private String id;
|
|
|
|
}
|
2020-12-04 00:28:53 +00:00
|
|
|
}
|