Fix god mode enabled after afk player quit the game

This commit is contained in:
snowleo 2011-09-30 00:09:48 +02:00
parent 44e920e441
commit 458068ae87

View File

@ -20,14 +20,12 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
private transient long lastOnlineActivity; private transient long lastOnlineActivity;
private transient long lastActivity = System.currentTimeMillis(); private transient long lastActivity = System.currentTimeMillis();
private boolean hidden = false; private boolean hidden = false;
private transient boolean godStateBeforeAfk;
private transient Location afkPosition; private transient Location afkPosition;
User(final Player base, final IEssentials ess) User(final Player base, final IEssentials ess)
{ {
super(base, ess); super(base, ess);
teleport = new Teleport(this, ess); teleport = new Teleport(this, ess);
godStateBeforeAfk = isGodModeEnabled();
afkPosition = getLocation(); afkPosition = getLocation();
} }
@ -348,15 +346,6 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
public void setAfk(final boolean set) public void setAfk(final boolean set)
{ {
this.setSleepingIgnored(this.isAuthorized("essentials.sleepingignored") ? true : set); this.setSleepingIgnored(this.isAuthorized("essentials.sleepingignored") ? true : set);
if (set && !isAfk() && ess.getSettings().getFreezeAfkPlayers())
{
godStateBeforeAfk = isGodModeEnabled();
setGodModeEnabled(true);
}
if (!set && isAfk() && ess.getSettings().getFreezeAfkPlayers())
{
setGodModeEnabled(godStateBeforeAfk);
}
if (set && !isAfk()) { if (set && !isAfk()) {
afkPosition = getLocation(); afkPosition = getLocation();
} }
@ -481,5 +470,11 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
setFoodLevel(20); setFoodLevel(20);
} }
return super.toggleGodModeEnabled(); return super.toggleGodModeEnabled();
} }
@Override
public boolean isGodModeEnabled()
{
return super.isGodModeEnabled() || (isAfk() && ess.getSettings().getFreezeAfkPlayers());
}
} }