mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-15 05:41:51 +08:00
Added plan.ignore.afk permission #613
This commit is contained in:
parent
edce0a5b4f
commit
8788cf2d01
@ -24,6 +24,10 @@ public class AFKTracker {
|
||||
afkThresholdMs = Settings.AFK_THRESHOLD_MINUTES.getNumber() * TimeAmount.MINUTE.ms();
|
||||
}
|
||||
|
||||
public void hasIgnorePermission(UUID uuid) {
|
||||
lastMovement.put(uuid, -1L);
|
||||
}
|
||||
|
||||
public void usedAfkCommand(UUID uuid, long time) {
|
||||
usedAFKCommand.add(uuid);
|
||||
lastMovement.put(uuid, time - afkThresholdMs);
|
||||
@ -31,6 +35,9 @@ public class AFKTracker {
|
||||
|
||||
public void performedAction(UUID uuid, long time) {
|
||||
Long lastMoved = lastMovement.getOrDefault(uuid, time);
|
||||
if (lastMoved == -1) {
|
||||
return;
|
||||
}
|
||||
lastMovement.put(uuid, time);
|
||||
|
||||
try {
|
||||
@ -42,7 +49,6 @@ public class AFKTracker {
|
||||
long removeAfkCommandEffect = usedAFKCommand.contains(uuid) ? afkThresholdMs : 0;
|
||||
long timeAFK = time - lastMoved - removeAfkCommandEffect;
|
||||
|
||||
|
||||
Optional<Session> cachedSession = SessionCache.getCachedSession(uuid);
|
||||
if (!cachedSession.isPresent()) {
|
||||
return;
|
||||
|
@ -1,7 +1,9 @@
|
||||
package com.djrapitops.plan.system.listeners.bukkit;
|
||||
|
||||
import com.djrapitops.plan.system.afk.AFKTracker;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -27,9 +29,14 @@ public class AFKListener implements Listener {
|
||||
|
||||
private void event(PlayerEvent event) {
|
||||
try {
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
Player player = event.getPlayer();
|
||||
UUID uuid = player.getUniqueId();
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
if (player.hasPermission(Permissions.IGNORE_AFK.getPermission())) {
|
||||
AFK_TRACKER.hasIgnorePermission(uuid);
|
||||
}
|
||||
|
||||
AFK_TRACKER.performedAction(uuid, time);
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
|
@ -37,7 +37,7 @@ public class CommandPreprocessListener implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
|
||||
boolean hasIgnorePermission = event.getPlayer().hasPermission(Permissions.IGNORE_COMMANDUSE.getPermission());
|
||||
boolean hasIgnorePermission = event.getPlayer().hasPermission(Permissions.IGNORE_COMMAND_USE.getPermission());
|
||||
if (event.isCancelled() || hasIgnorePermission) {
|
||||
return;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.djrapitops.plan.system.listeners.sponge;
|
||||
|
||||
import com.djrapitops.plan.system.afk.AFKTracker;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
@ -29,10 +30,7 @@ public class SpongeAFKListener {
|
||||
|
||||
private void event(TargetPlayerEvent event) {
|
||||
try {
|
||||
UUID uuid = event.getTargetEntity().getUniqueId();
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
AFK_TRACKER.performedAction(uuid, time);
|
||||
performedAction(event.getTargetEntity());
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
}
|
||||
@ -40,26 +38,32 @@ public class SpongeAFKListener {
|
||||
|
||||
@Listener(order = Order.POST)
|
||||
public void onMove(MoveEntityEvent event, @First Player player) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
long time = System.currentTimeMillis();
|
||||
AFK_TRACKER.performedAction(uuid, time);
|
||||
performedAction(player);
|
||||
}
|
||||
|
||||
@Listener(order = Order.POST)
|
||||
public void onPlayerChat(MessageChannelEvent.Chat event, @First Player player) {
|
||||
performedAction(player);
|
||||
}
|
||||
|
||||
private void performedAction(Player player) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
if (player.hasPermission(Permissions.IGNORE_AFK.getPermission())) {
|
||||
AFK_TRACKER.hasIgnorePermission(uuid);
|
||||
}
|
||||
|
||||
AFK_TRACKER.performedAction(uuid, time);
|
||||
}
|
||||
|
||||
@Listener(order = Order.POST)
|
||||
public void onPlayerCommand(SendCommandEvent event, @First Player player) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
long time = System.currentTimeMillis();
|
||||
AFK_TRACKER.performedAction(uuid, time);
|
||||
performedAction(player);
|
||||
|
||||
boolean isAfkCommand = event.getCommand().toLowerCase().startsWith("afk");
|
||||
if (isAfkCommand) {
|
||||
AFK_TRACKER.usedAfkCommand(uuid, System.currentTimeMillis());
|
||||
AFK_TRACKER.usedAfkCommand(player.getUniqueId(), System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ public class SpongeCommandListener {
|
||||
|
||||
@Listener(order = Order.POST)
|
||||
public void onPlayerCommand(SendCommandEvent event, @First Player player) {
|
||||
boolean hasIgnorePermission = player.hasPermission(Permissions.IGNORE_COMMANDUSE.getPermission());
|
||||
boolean hasIgnorePermission = player.hasPermission(Permissions.IGNORE_COMMAND_USE.getPermission());
|
||||
if (event.isCancelled() || hasIgnorePermission) {
|
||||
return;
|
||||
}
|
||||
|
@ -25,7 +25,8 @@ public enum Permissions {
|
||||
MANAGE("plan.manage"),
|
||||
MANAGE_WEB("plan.webmanage"),
|
||||
|
||||
IGNORE_COMMANDUSE("plan.ignore.commanduse");
|
||||
IGNORE_COMMAND_USE("plan.ignore.commanduse"),
|
||||
IGNORE_AFK("plan.ignore.afk");
|
||||
|
||||
private final String permission;
|
||||
|
||||
|
@ -79,6 +79,9 @@ permissions:
|
||||
plan.ignore.commanduse:
|
||||
description: Commands used by this player are not saved
|
||||
default: false
|
||||
plan.ignore.afk:
|
||||
description: AFK time by this player is ignored
|
||||
default: false
|
||||
plan.manage:
|
||||
description: Manage the database, clear, move, combine.
|
||||
default: op
|
||||
|
Loading…
Reference in New Issue
Block a user