mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 09:15:38 +00:00
5c0f77c7c5
Lombok implementation removal. I have also gone through and replaced things with inline methods and variables, lambdas, and simplified loops down, removed unnecessary guard clauses, and overall cleaned up every single class. This took a long time, please do remember to follow proper naming conventions, don't include unnecessary guard clauses, follow exception rules and comment rules, and please PLEASE remember to use the DIAMOND OPERATOR rather than just inferring RAW TYPES!!! Thank you!!
70 lines
1.8 KiB
Java
70 lines
1.8 KiB
Java
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;
|
|
|
|
public class AutoKick extends FreedomService
|
|
{
|
|
|
|
public static final long AUTOKICK_RATE = 10 * 20L;
|
|
//
|
|
private BukkitTask kickTask = null;
|
|
private long autoKickTicks;
|
|
private double autoKickThreshold;
|
|
|
|
@Override
|
|
public void onStart()
|
|
{
|
|
autoKickTicks = (long)ConfigEntry.AUTOKICK_TIME.getInteger() * 1000L;
|
|
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
|
|
public void onStop()
|
|
{
|
|
FUtil.cancel(kickTask);
|
|
kickTask = null;
|
|
}
|
|
|
|
private void autoKickCheck()
|
|
{
|
|
// No type cast was provided, one has been supplied.
|
|
final boolean doAwayKickCheck
|
|
= plugin.esb.isEnabled()
|
|
&& (((float)server.getOnlinePlayers().size() / (float)server.getMaxPlayers()) > autoKickThreshold);
|
|
|
|
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.");
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|