mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
Implemented Essentials-based AFK Auto-Kick w/ server load based trigger threshold.
This commit is contained in:
parent
a38f7b3469
commit
1a5f854552
@ -1,5 +1,5 @@
|
|||||||
#Fri, 27 Sep 2013 10:59:36 -0400
|
#Tue, 08 Oct 2013 13:58:56 -0400
|
||||||
|
|
||||||
program.VERSION=3.2
|
program.VERSION=3.2
|
||||||
program.BUILDNUM=615
|
program.BUILDNUM=616
|
||||||
program.BUILDDATE=09/27/2013 10\:59 AM
|
program.BUILDDATE=10/08/2013 01\:58 PM
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
#Build Number for ANT. Do not edit!
|
#Build Number for ANT. Do not edit!
|
||||||
#Fri Sep 27 10:59:36 EDT 2013
|
#Tue Oct 08 13:58:56 EDT 2013
|
||||||
build.number=616
|
build.number=617
|
||||||
|
@ -184,3 +184,10 @@ service_checker_url: http://status.mojang.com/check
|
|||||||
httpd_enabled: true
|
httpd_enabled: true
|
||||||
httpd_public_folder: ./public_html
|
httpd_public_folder: ./public_html
|
||||||
httpd_port: 28966
|
httpd_port: 28966
|
||||||
|
|
||||||
|
# Inactivity Auto-Kick (Requires Essentials)
|
||||||
|
autokick_enabled: true
|
||||||
|
# autokick_threshold - Percentage of server player capacity used at which players will be automatically kicked for being inactive. Range: 0.0 - 1.0
|
||||||
|
autokick_threshold: 0.9
|
||||||
|
# autokick_time - Time, in seconds, after which a player should be kicked when inactive
|
||||||
|
autokick_time: 120
|
||||||
|
@ -32,16 +32,19 @@ public enum TFM_ConfigEntry
|
|||||||
TOSSMOB_ENABLED(Boolean.class, "tossmob_enabled"),
|
TOSSMOB_ENABLED(Boolean.class, "tossmob_enabled"),
|
||||||
TWITTERBOT_ENABLED(Boolean.class, "twitterbot_enabled"),
|
TWITTERBOT_ENABLED(Boolean.class, "twitterbot_enabled"),
|
||||||
HTTPD_ENABLED(Boolean.class, "httpd_enabled"),
|
HTTPD_ENABLED(Boolean.class, "httpd_enabled"),
|
||||||
|
AUTOKICK_ENABLED(Boolean.class, "autokick_enabled"),
|
||||||
//
|
//
|
||||||
AUTO_PROTECT_RADIUS(Double.class, "auto_protect_radius"),
|
AUTO_PROTECT_RADIUS(Double.class, "auto_protect_radius"),
|
||||||
EXPLOSIVE_RADIUS(Double.class, "explosive_radius"),
|
EXPLOSIVE_RADIUS(Double.class, "explosive_radius"),
|
||||||
NUKE_MONITOR_RANGE(Double.class, "nuke_monitor_range"),
|
NUKE_MONITOR_RANGE(Double.class, "nuke_monitor_range"),
|
||||||
|
AUTOKICK_THRESHOLD(Double.class, "autokick_threshold"),
|
||||||
//
|
//
|
||||||
FREECAM_TRIGGER_COUNT(Integer.class, "freecam_trigger_count"),
|
FREECAM_TRIGGER_COUNT(Integer.class, "freecam_trigger_count"),
|
||||||
MOB_LIMITER_MAX(Integer.class, "mob_limiter_max"),
|
MOB_LIMITER_MAX(Integer.class, "mob_limiter_max"),
|
||||||
NUKE_MONITOR_COUNT_BREAK(Integer.class, "nuke_monitor_count_break"),
|
NUKE_MONITOR_COUNT_BREAK(Integer.class, "nuke_monitor_count_break"),
|
||||||
NUKE_MONITOR_COUNT_PLACE(Integer.class, "nuke_monitor_count_place"),
|
NUKE_MONITOR_COUNT_PLACE(Integer.class, "nuke_monitor_count_place"),
|
||||||
HTTPD_PORT(Integer.class, "httpd_port"),
|
HTTPD_PORT(Integer.class, "httpd_port"),
|
||||||
|
AUTOKICK_TIME(Integer.class, "autokick_time"),
|
||||||
//
|
//
|
||||||
FLATLANDS_GENERATION_PARAMS(String.class, "flatlands_generation_params"),
|
FLATLANDS_GENERATION_PARAMS(String.class, "flatlands_generation_params"),
|
||||||
LOGS_REGISTER_PASSWORD(String.class, "logs_register_password"),
|
LOGS_REGISTER_PASSWORD(String.class, "logs_register_password"),
|
||||||
|
@ -70,6 +70,40 @@ public class TFM_EssentialsBridge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getLastActivity(String username)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final User user = getEssentialsUser(username);
|
||||||
|
if (user != null)
|
||||||
|
{
|
||||||
|
return TFM_Util.getField(user, "lastActivity");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEssentialsEnabled()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Essentials essentials = getEssentialsPlugin();
|
||||||
|
if (essentials != null)
|
||||||
|
{
|
||||||
|
return essentials.isEnabled();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static TFM_EssentialsBridge getInstance()
|
public static TFM_EssentialsBridge getInstance()
|
||||||
{
|
{
|
||||||
return TFM_EssentialsBridgeHolder.INSTANCE;
|
return TFM_EssentialsBridgeHolder.INSTANCE;
|
||||||
|
@ -7,6 +7,7 @@ import org.bukkit.scheduler.BukkitRunnable;
|
|||||||
|
|
||||||
public class TFM_Heartbeat extends BukkitRunnable
|
public class TFM_Heartbeat extends BukkitRunnable
|
||||||
{
|
{
|
||||||
|
private static final long AUTO_KICK_TIME = (long) TFM_ConfigEntry.AUTOKICK_TIME.getInteger() * 1000L;
|
||||||
private final TotalFreedomMod plugin;
|
private final TotalFreedomMod plugin;
|
||||||
private final Server server;
|
private final Server server;
|
||||||
private static Long lastRan = null;
|
private static Long lastRan = null;
|
||||||
@ -27,12 +28,27 @@ public class TFM_Heartbeat extends BukkitRunnable
|
|||||||
{
|
{
|
||||||
lastRan = System.currentTimeMillis();
|
lastRan = System.currentTimeMillis();
|
||||||
|
|
||||||
|
final TFM_EssentialsBridge essentialsBridge = TFM_EssentialsBridge.getInstance();
|
||||||
|
final boolean doAwayKickCheck =
|
||||||
|
TFM_ConfigEntry.AUTOKICK_ENABLED.getBoolean()
|
||||||
|
&& essentialsBridge.isEssentialsEnabled()
|
||||||
|
&& ((server.getOnlinePlayers().length / server.getMaxPlayers()) > TFM_ConfigEntry.AUTOKICK_THRESHOLD.getDouble());
|
||||||
|
|
||||||
for (Player player : server.getOnlinePlayers())
|
for (Player player : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
||||||
playerdata.resetMsgCount();
|
playerdata.resetMsgCount();
|
||||||
playerdata.resetBlockDestroyCount();
|
playerdata.resetBlockDestroyCount();
|
||||||
playerdata.resetBlockPlaceCount();
|
playerdata.resetBlockPlaceCount();
|
||||||
|
|
||||||
|
if (doAwayKickCheck)
|
||||||
|
{
|
||||||
|
final long lastActivity = essentialsBridge.getLastActivity(player.getName());
|
||||||
|
if (lastActivity > 0 && lastActivity + AUTO_KICK_TIME < System.currentTimeMillis())
|
||||||
|
{
|
||||||
|
player.kickPlayer("Automatically kicked by server for inactivity.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TFM_ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
|
if (TFM_ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
|
||||||
|
Loading…
Reference in New Issue
Block a user