2015-11-15 23:32:04 +00:00
|
|
|
package me.totalfreedom.totalfreedommod;
|
|
|
|
|
|
|
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
import org.bukkit.scheduler.BukkitTask;
|
|
|
|
|
2016-03-01 16:47:01 +00:00
|
|
|
public class AutoKick extends FreedomService
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
public static final long AUTOKICK_RATE = 10 * 20L;
|
|
|
|
//
|
|
|
|
private BukkitTask kickTask = null;
|
|
|
|
private long autoKickTicks;
|
|
|
|
private double autoKickThreshold;
|
|
|
|
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStart()
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
2018-07-31 07:01:29 +00:00
|
|
|
autoKickTicks = (long)ConfigEntry.AUTOKICK_TIME.getInteger() * 1000L;
|
2015-11-15 23:32:04 +00:00
|
|
|
autoKickThreshold = ConfigEntry.AUTOKICK_THRESHOLD.getDouble();
|
|
|
|
|
|
|
|
if (!ConfigEntry.AUTOKICK_ENABLED.getBoolean())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
kickTask = new BukkitRunnable()
|
|
|
|
{
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
autoKickCheck();
|
|
|
|
}
|
|
|
|
}.runTaskTimer(plugin, AUTOKICK_RATE, AUTOKICK_RATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStop()
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
FUtil.cancel(kickTask);
|
|
|
|
kickTask = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void autoKickCheck()
|
|
|
|
{
|
2020-12-25 19:46:43 +00:00
|
|
|
// No type cast was provided, one has been supplied.
|
2015-11-15 23:32:04 +00:00
|
|
|
final boolean doAwayKickCheck
|
2018-07-30 07:23:01 +00:00
|
|
|
= plugin.esb.isEnabled()
|
2020-12-25 19:46:43 +00:00
|
|
|
&& (((float)server.getOnlinePlayers().size() / (float)server.getMaxPlayers()) > autoKickThreshold);
|
2015-11-15 23:32:04 +00:00
|
|
|
|
|
|
|
if (!doAwayKickCheck)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Player player : server.getOnlinePlayers())
|
|
|
|
{
|
|
|
|
final long lastActivity = plugin.esb.getLastActivity(player.getName());
|
|
|
|
if (lastActivity > 0 && lastActivity + autoKickTicks < System.currentTimeMillis())
|
|
|
|
{
|
|
|
|
player.kickPlayer("Automatically kicked by server for inactivity.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|