Skip to content

Commit

Permalink
Implemented a NPC compatibility mode for the AFK Component
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkArc committed Aug 29, 2014
1 parent 5ecfeec commit 71eb39d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/java/com/sk89q/commandbook/AFKComponent.java
Expand Up @@ -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;

Expand Down Expand Up @@ -84,6 +85,8 @@ private static class LocalConfiguration extends ConfigurationBase {
public boolean afkGeneralProtection = true;
@Setting("afk-command-protection")
public boolean afkCommandProtection = false;
@Setting("npc-compatibility-mode")
public boolean npcCompatibilty = false;
}

/**
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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())) {
Expand Down

0 comments on commit 71eb39d

Please sign in to comment.