mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-01-07 07:41:03 +00:00
Merge pull request #3063 from schlatt-co/feature/3034
Implement better AfkStatusChangeEvent
This commit is contained in:
commit
ed4e7794c3
5 changed files with 54 additions and 11 deletions
|
@ -10,6 +10,7 @@ import com.earth2me.essentials.utils.MaterialUtil;
|
|||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.events.AfkStatusChangeEvent;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
|
@ -199,7 +200,7 @@ public class EssentialsPlayerListener implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
user.updateActivity(false);
|
||||
user.updateActivity(false, AfkStatusChangeEvent.Cause.QUIT);
|
||||
if (!user.isHidden()) {
|
||||
user.setLastLogout(System.currentTimeMillis());
|
||||
}
|
||||
|
@ -233,7 +234,7 @@ public class EssentialsPlayerListener implements Listener {
|
|||
|
||||
final long currentTime = System.currentTimeMillis();
|
||||
dUser.checkMuteTimeout(currentTime);
|
||||
dUser.updateActivity(false);
|
||||
dUser.updateActivity(false, AfkStatusChangeEvent.Cause.JOIN);
|
||||
dUser.stopTransaction();
|
||||
|
||||
class DelayJoinTask implements Runnable {
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.earth2me.essentials;
|
|||
import com.earth2me.essentials.commands.IEssentialsCommand;
|
||||
import net.ess3.api.ITeleport;
|
||||
import net.ess3.api.MaxMoneyException;
|
||||
import net.ess3.api.events.AfkStatusChangeEvent;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -59,8 +60,11 @@ public interface IUser {
|
|||
|
||||
void setMoney(final BigDecimal value) throws MaxMoneyException;
|
||||
|
||||
@Deprecated
|
||||
void setAfk(final boolean set);
|
||||
|
||||
void setAfk(final boolean set, final AfkStatusChangeEvent.Cause cause);
|
||||
|
||||
/**
|
||||
* 'Hidden' Represents when a player is hidden from others. This status includes when the player is hidden via other
|
||||
* supported plugins. Use isVanished() if you want to check if a user is vanished by Essentials.
|
||||
|
|
|
@ -498,7 +498,12 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
|||
|
||||
@Override
|
||||
public void setAfk(final boolean set) {
|
||||
final AfkStatusChangeEvent afkEvent = new AfkStatusChangeEvent(this, set);
|
||||
setAfk(set, AfkStatusChangeEvent.Cause.UNKNOWN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAfk(boolean set, AfkStatusChangeEvent.Cause cause) {
|
||||
final AfkStatusChangeEvent afkEvent = new AfkStatusChangeEvent(this, set, cause);
|
||||
ess.getServer().getPluginManager().callEvent(afkEvent);
|
||||
if (afkEvent.isCancelled()) {
|
||||
return;
|
||||
|
@ -516,7 +521,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
|||
_setAfk(set);
|
||||
updateAfkListName();
|
||||
}
|
||||
|
||||
|
||||
private void updateAfkListName() {
|
||||
if (ess.getSettings().isAfkListName()) {
|
||||
if(isAfk()) {
|
||||
|
@ -528,8 +533,13 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
|||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean toggleAfk() {
|
||||
setAfk(!isAfk());
|
||||
return toggleAfk(AfkStatusChangeEvent.Cause.UNKNOWN);
|
||||
}
|
||||
|
||||
public boolean toggleAfk(AfkStatusChangeEvent.Cause cause) {
|
||||
setAfk(!isAfk(), cause);
|
||||
return isAfk();
|
||||
}
|
||||
|
||||
|
@ -594,9 +604,14 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
|||
return false;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void updateActivity(final boolean broadcast) {
|
||||
updateActivity(broadcast, AfkStatusChangeEvent.Cause.UNKNOWN);
|
||||
}
|
||||
|
||||
public void updateActivity(final boolean broadcast, AfkStatusChangeEvent.Cause cause) {
|
||||
if (isAfk()) {
|
||||
setAfk(false);
|
||||
setAfk(false, cause);
|
||||
if (broadcast && !isHidden()) {
|
||||
setDisplayNick();
|
||||
final String msg = tl("userIsNotAway", getDisplayName());
|
||||
|
@ -610,13 +625,13 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
|||
|
||||
public void updateActivityOnMove(final boolean broadcast) {
|
||||
if(ess.getSettings().cancelAfkOnMove()) {
|
||||
updateActivity(broadcast);
|
||||
updateActivity(broadcast, AfkStatusChangeEvent.Cause.MOVE);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateActivityOnInteract(final boolean broadcast) {
|
||||
if(ess.getSettings().cancelAfkOnInteract()) {
|
||||
updateActivity(broadcast);
|
||||
updateActivity(broadcast, AfkStatusChangeEvent.Cause.INTERACT);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -644,7 +659,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
|||
}
|
||||
final long autoafk = ess.getSettings().getAutoAfk();
|
||||
if (!isAfk() && autoafk > 0 && lastActivity + autoafk * 1000 < System.currentTimeMillis() && isAuthorized("essentials.afk.auto")) {
|
||||
setAfk(true);
|
||||
setAfk(true, AfkStatusChangeEvent.Cause.ACTIVITY);
|
||||
if (!isHidden()) {
|
||||
setDisplayNick();
|
||||
final String msg = tl("userIsAway", getDisplayName());
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
|
|||
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.api.events.AfkStatusChangeEvent;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import java.util.Collections;
|
||||
|
@ -55,12 +56,12 @@ public class Commandafk extends EssentialsCommand {
|
|||
}
|
||||
user.setDisplayNick();
|
||||
String msg = "";
|
||||
if (!user.toggleAfk()) {
|
||||
if (!user.toggleAfk(AfkStatusChangeEvent.Cause.COMMAND)) {
|
||||
//user.sendMessage(_("markedAsNotAway"));
|
||||
if (!user.isHidden()) {
|
||||
msg = tl("userIsNotAway", user.getDisplayName());
|
||||
}
|
||||
user.updateActivity(false);
|
||||
user.updateActivity(false, AfkStatusChangeEvent.Cause.COMMAND);
|
||||
} else {
|
||||
//user.sendMessage(_("markedAsAway"));
|
||||
if (!user.isHidden()) {
|
||||
|
|
|
@ -4,7 +4,29 @@ import net.ess3.api.IUser;
|
|||
|
||||
|
||||
public class AfkStatusChangeEvent extends StatusChangeEvent {
|
||||
private Cause cause;
|
||||
|
||||
@Deprecated
|
||||
public AfkStatusChangeEvent(IUser affected, boolean value) {
|
||||
this(affected, value, Cause.UNKNOWN);
|
||||
}
|
||||
|
||||
public AfkStatusChangeEvent(IUser affected, boolean value, Cause cause) {
|
||||
super(affected, affected, value);
|
||||
this.cause = cause;
|
||||
}
|
||||
|
||||
public Cause getCause() {
|
||||
return cause;
|
||||
}
|
||||
|
||||
public enum Cause {
|
||||
ACTIVITY,
|
||||
MOVE,
|
||||
INTERACT,
|
||||
COMMAND,
|
||||
JOIN,
|
||||
QUIT,
|
||||
UNKNOWN
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue