From e0d6040662ba915f63a9f90d14ed419646533045 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Sun, 25 Dec 2022 15:59:23 -0500 Subject: [PATCH] Add IUser#isFreeze & IUser#setFreeze --- .../essentials/EssentialsPlayerListener.java | 21 +++++++++++++------ .../java/com/earth2me/essentials/IUser.java | 4 ++++ .../java/com/earth2me/essentials/User.java | 11 ++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java index 338bcbc34..021baaa69 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java @@ -193,17 +193,26 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor { return; } - if (!ess.getSettings().cancelAfkOnMove() && !ess.getSettings().getFreezeAfkPlayers()) { - event.getHandlers().unregister(this); + final User user = ess.getUser(event.getPlayer()); - if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.INFO, "Unregistering move listener"); + if (user.isFreeze()) { + final Location from = event.getFrom(); + final Location to = event.getTo().clone(); + to.setX(from.getX()); + to.setY(from.getY()); + to.setZ(from.getZ()); + try { + event.setTo(LocationUtil.getSafeDestination(to)); + } catch (final Exception ex) { + event.setTo(to); } - return; } - final User user = ess.getUser(event.getPlayer()); + if (!ess.getSettings().cancelAfkOnMove() && !ess.getSettings().getFreezeAfkPlayers()) { + return; + } + if (user.isAfk() && ess.getSettings().getFreezeAfkPlayers()) { final Location from = event.getFrom(); final Location origTo = event.getTo(); diff --git a/Essentials/src/main/java/com/earth2me/essentials/IUser.java b/Essentials/src/main/java/com/earth2me/essentials/IUser.java index 3c4e8361f..2625b1fc8 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/IUser.java +++ b/Essentials/src/main/java/com/earth2me/essentials/IUser.java @@ -336,4 +336,8 @@ public interface IUser { List getPastUsernames(); void addPastUsername(String username); + + boolean isFreeze(); + + void setFreeze(boolean freeze); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index d23d50281..4c63fd0be 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -90,6 +90,7 @@ public class User extends UserData implements Comparable, IMessageRecipien private String lastHomeConfirmation; private long lastHomeConfirmationTimestamp; private Boolean toggleShout; + private boolean freeze = false; private transient final List signCopy = Lists.newArrayList("", "", "", ""); private transient long lastVanishTime = System.currentTimeMillis(); @@ -1191,6 +1192,16 @@ public class User extends UserData implements Comparable, IMessageRecipien return signCopy; } + @Override + public boolean isFreeze() { + return freeze; + } + + @Override + public void setFreeze(boolean freeze) { + this.freeze = freeze; + } + public boolean isBaltopExempt() { if (getBase().isOnline()) { final boolean exempt = isAuthorized("essentials.balancetop.exclude");