Add AFK broadcasts for main worlds
This commit is contained in:
1 parent
9e62db8b12
commit
0de1738130
3 files changed
+79
No files matched your search
@@ -5,6 +5,11 @@
|
||||
|
||||
package de.codecrafter.smartAfk.utils;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import de.codecrafter.smartAfk.AFKOG;
|
||||
@@ -25,6 +30,10 @@ public class AfkConfig {
|
||||
private double autoclickCvThreshold;
|
||||
private int autoclickMaxSameTarget;
|
||||
private int ncpFlagWindowSeconds;
|
||||
// lowercased world names where going AFK is broadcast to everyone.
|
||||
private Set<String> afkBroadcastWorlds;
|
||||
private String afkBroadcastMessage;
|
||||
private String afkBroadcastReturnMessage;
|
||||
|
||||
/**
|
||||
* Creates an instance of {@code TimerConfig} class.
|
||||
@@ -80,6 +89,21 @@ public class AfkConfig {
|
||||
this.autoclickMaxSameTarget = Math.max(2, config.getInt("autoclick-max-same-target", 6));
|
||||
this.ncpFlagWindowSeconds = Math.max(0, config.getInt("nocheatplus-flag-window-seconds", 2));
|
||||
|
||||
final Set<String> worlds = new HashSet<>();
|
||||
final List<String> configured = config.getStringList("afk-broadcast-worlds");
|
||||
for (final String world : configured) {
|
||||
|
||||
if (world != null && !world.isBlank()) {
|
||||
|
||||
worlds.add(world.toLowerCase(Locale.ROOT));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
this.afkBroadcastWorlds = worlds;
|
||||
this.afkBroadcastMessage = config.getString("afk-broadcast-message", "&e%player% &7is now AFK.");
|
||||
this.afkBroadcastReturnMessage = config.getString("afk-broadcast-return-message", "&e%player% &7is no longer AFK.");
|
||||
|
||||
}
|
||||
|
||||
public int getAfkTimeoutSeconds() {
|
||||
@@ -148,4 +172,28 @@ public class AfkConfig {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when going AFK in the given world should be broadcast to
|
||||
* everyone. World names are matched case-insensitively.
|
||||
*
|
||||
* @param worldName The name of the world the player is in.
|
||||
*/
|
||||
public boolean isBroadcastWorld(String worldName) {
|
||||
|
||||
return worldName != null && afkBroadcastWorlds.contains(worldName.toLowerCase(Locale.ROOT));
|
||||
|
||||
}
|
||||
|
||||
public String getAfkBroadcastMessage() {
|
||||
|
||||
return afkBroadcastMessage;
|
||||
|
||||
}
|
||||
|
||||
public String getAfkBroadcastReturnMessage() {
|
||||
|
||||
return afkBroadcastReturnMessage;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -78,6 +78,14 @@ public class AfkManager {
|
||||
|
||||
player.sendMessage(legacy(AFKOG.getPrefix() + "&cYou are now AFK."));
|
||||
|
||||
final AfkConfig config = AFKOG.getPlugin().getAfkConfig();
|
||||
if (config.isBroadcastWorld(player.getWorld().getName())) {
|
||||
|
||||
final String message = config.getAfkBroadcastMessage().replace("%player%", player.getName());
|
||||
AFKOG.getPlugin().getServer().broadcast(legacy(AFKOG.getPrefix() + message));
|
||||
|
||||
}
|
||||
|
||||
clearMobTargets(player);
|
||||
|
||||
}
|
||||
@@ -103,6 +111,14 @@ public class AfkManager {
|
||||
|
||||
player.sendMessage(legacy(AFKOG.getPrefix() + "&aYou are no longer AFK."));
|
||||
|
||||
final AfkConfig config = AFKOG.getPlugin().getAfkConfig();
|
||||
if (config.isBroadcastWorld(player.getWorld().getName())) {
|
||||
|
||||
final String message = config.getAfkBroadcastReturnMessage().replace("%player%", player.getName());
|
||||
AFKOG.getPlugin().getServer().broadcast(legacy(AFKOG.getPrefix() + message));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isAfk(Player player) {
|
||||
|
||||
@@ -12,6 +12,21 @@ cancel-afk-on-jump: true
|
||||
# the player cannot take damage when they are afk
|
||||
invulnerable-during-afk: true
|
||||
|
||||
# broadcast a chat message to everyone when a player goes AFK while in one of
|
||||
# these worlds. leave the list empty to disable the broadcast entirely.
|
||||
afk-broadcast-worlds:
|
||||
- world
|
||||
- world_nether
|
||||
- world_the_end
|
||||
|
||||
# message broadcast when a player goes AFK in a whitelisted world.
|
||||
# supports legacy '&' color codes. %player% is replaced with the player name.
|
||||
afk-broadcast-message: "&e%player% &7is now AFK."
|
||||
|
||||
# message broadcast when a player stops being AFK in a whitelisted world.
|
||||
# supports legacy '&' color codes. %player% is replaced with the player name.
|
||||
afk-broadcast-return-message: "&e%player% &7is no longer AFK."
|
||||
|
||||
# kick players after this many seconds of true inactivity (no movement, no input).
|
||||
# set to -1 to disable.
|
||||
afk-kick-seconds: 1200
|
||||
|
||||
Reference in new issue
Block a user