Permalink
Browse files

Implemented a NPC compatibility mode for the AFK Component

  • Loading branch information...
DarkArc committed Aug 29, 2014
1 parent 5ecfeec commit 71eb39d4b00a793ffdbfd6d1f968fac0140ae271
Showing with 9 additions and 1 deletion.
  1. +9 −1 src/main/java/com/sk89q/commandbook/AFKComponent.java
@@ -27,6 +27,7 @@
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.*;
+import java.util.Collection;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
@@ -84,6 +85,8 @@ public void reload() {
public boolean afkGeneralProtection = true;
@Setting("afk-command-protection")
public boolean afkCommandProtection = false;
+ @Setting("npc-compatibility-mode")
+ public boolean npcCompatibilty = false;
}
/**
@@ -130,7 +133,7 @@ public boolean shouldKick(long time) {
if (config.afkKickMinutes < 1) return false;
double maxP = server.getMaxPlayers();
- double curP = server.getOnlinePlayers().length;
+ double curP = server.getOnlinePlayers().size();
double fraction = ((maxP - curP) + maxP * .2) / maxP;
int duration = (int) Math.max(config.afkMinutes + 2, Math.min(config.afkKickMinutes, config.afkKickMinutes * fraction));
@@ -206,12 +209,17 @@ public void update(Player player) {
@Override
public void run() {
+ Collection<? extends Player> onlinePlayers = config.npcCompatibilty ? server.getOnlinePlayers() : null;
for (final AFKSession session : sessions.getSessions(AFKSession.class).values()) {
if (session == null) continue;
final Player target = session.getPlayer();
if (target == null || !session.getPlayer().isValid()) continue;
+ if (onlinePlayers != null && !onlinePlayers.contains(target)) {
+ continue;
+ }
+
boolean passedTime = isAfk(session.getLastUpdate());
if (session.isRequested() || passedTime) {
if (shouldKick(session.getLastUpdate())) {

0 comments on commit 71eb39d

Please sign in to comment.