Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ public interface ISettings extends IConf {

long getAutoAfk();

long getAutoAfkKick();
long getAutoAfkTimeout();

Set<String> getAfkTimeoutCommands();

boolean getFreezeAfkPlayers();

Expand Down
19 changes: 17 additions & 2 deletions Essentials/src/main/java/com/earth2me/essentials/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public class Settings implements net.ess3.api.ISettings {
private Tag secondaryColor = DEFAULT_SECONDARY_COLOR;
private Set<String> multiplierPerms;
private BigDecimal defaultMultiplier;
private Set<String> afkTimeoutCommands = new HashSet<>();

public Settings(final IEssentials ess) {
this.ess = ess;
Expand Down Expand Up @@ -938,6 +939,7 @@ public void reloadConfig() {
secondaryColor = _getSecondaryColor();
multiplierPerms = _getMultiplierPerms();
defaultMultiplier = _getDefaultMultiplier();
afkTimeoutCommands = _getAfkTimeoutCommands();

reloadCount.incrementAndGet();
}
Expand Down Expand Up @@ -1262,8 +1264,21 @@ public long getAutoAfk() {
}

@Override
public long getAutoAfkKick() {
return config.getLong("auto-afk-kick", -1);
public long getAutoAfkTimeout() {
return config.getLong("auto-afk-timeout", config.getLong("auto-afk-kick", -1));
}

private Set<String> _getAfkTimeoutCommands() {
final Set<String> timeoutCommands = new HashSet<>();
for (final String cmd : config.getList("afk-timeout-commands", String.class)) {
timeoutCommands.add(cmd.toLowerCase(Locale.ENGLISH));
}
return timeoutCommands;
}

@Override
public Set<String> getAfkTimeoutCommands() {
return afkTimeoutCommands;
}

@Override
Expand Down
35 changes: 25 additions & 10 deletions Essentials/src/main/java/com/earth2me/essentials/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -832,19 +832,34 @@ public void checkActivity() {
return;
}

final long autoafkkick = ess.getSettings().getAutoAfkKick();
if (autoafkkick > 0
&& lastActivity > 0 && (lastActivity + (autoafkkick * 1000)) < System.currentTimeMillis()
final long autoafktimeout = ess.getSettings().getAutoAfkTimeout();

// Checks if the player has been inactive for longer than the configured auto-afk-timeout time.
if (autoafktimeout > 0
&& lastActivity > 0 && (lastActivity + (autoafktimeout * 1000)) < System.currentTimeMillis()
&& !isAuthorized("essentials.kick.exempt")
&& !isAuthorized("essentials.afk.kickexempt")) {
lastActivity = 0;
final double kickTime = autoafkkick / 60.0;

this.getBase().kickPlayer(AdventureUtil.miniToLegacy(playerTl("autoAfkKickReason", kickTime)));

for (final User user : ess.getOnlineUsers()) {
if (user.isAuthorized("essentials.kick.notify")) {
user.sendTl("playerKicked", Console.DISPLAY_NAME, getName(), user.playerTl("autoAfkKickReason", kickTime));
final double kickTime = autoafktimeout / 60.0;

// If `afk-timeout-command` in config.yml is empty, use default Essentials kicking behaviour instead of executing a command.
if (ess.getSettings().getAfkTimeoutCommands().isEmpty()) {
this.getBase().kickPlayer(AdventureUtil.miniToLegacy(playerTl("autoAfkKickReason", kickTime)));

for (final User user : ess.getOnlineUsers()) {
if (user.isAuthorized("essentials.kick.notify")) {
user.sendTl("playerKicked", Console.DISPLAY_NAME, getName(), user.playerTl("autoAfkKickReason", kickTime));
}
}
} else {
// If `afk-timeout-commands` in config.yml is populated, execute the command(s) instead of kicking the player.
for (final String command : ess.getSettings().getAfkTimeoutCommands()) {
if (command == null || command.isEmpty()){
continue;
}
// Replace placeholders in the command with actual values.
final String cmd = command.replace("{USERNAME}", getName()).replace("{KICKTIME}", String.valueOf(kickTime));
ess.getServer().dispatchCommand(ess.getServer().getConsoleSender(), cmd);
}
}
}
Expand Down
21 changes: 19 additions & 2 deletions Essentials/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,27 @@ remove-god-on-disconnect: false
# Set to -1 for no timeout.
auto-afk: 300

# After this timeout in seconds, the player will be kicked from the server.
# After this timeout in seconds, the player will either be kicked from
# the server or commands in 'afk-timeout-commands' will be executed.
# The 'essentials.afk.kickexempt' permission overrides this feature.
# Set to -1 for no timeout.
auto-afk-kick: -1
auto-afk-timeout: -1

# A list of commands to be executed instead of kicking the player once the
# threshold defined above in 'afk-auto-timeout' is reached. If this list is empty
# and 'afk-auto-timeout' is not set to -1, Essentials will default to
# kicking the player once they reach the timeout threshold.
#
# WARNING: You must include a command here that either removes the player from the server
# or stops them from being AFK. Otherwise, these commands will run every second
# until the player is no longer AFK!
#
# Available placeholders:
# {USERNAME} - The player's username.
# {KICKTIME} - The time, in minutes, the player has been AFK for.
afk-timeout-commands:
#- eco take {USERNAME} 10
#- kick {USERNAME} You have been kicked for being inactive for {KICKTIME} minutes! You lost $10.

# Set this to true if you want to freeze players when they are AFK.
# Other players or monsters won't be able to push them out of AFK mode.
Expand Down
Loading