mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2024-06-28 08:50:57 +00:00
Allow toggling public broadcast of AFK messages (#2780)
(description from #2608) So... I've implemented a system for toggling whether or not AFK messages are broadcasted to the entire server and also changed a few things along the way: 1. I added a config toggle broadcast-afk-message that will change whether AFK messages are broadcast globally or not. 2. In both cases the AFK target now recieves a "self-oriented" message instead of the global default. Basically just says "You are now/no longer AFK". This would be a change from the default behaviour. 3. I created a way to exclude certain IUsers from broadcastMessage messages using an IUser... varargs parameter. I wasn't too sure how to implement the exclusion, but this seemed like a fairly good option. I'm not too sure if what I've come up with is an optimal solution, but it's been tested and confirmed to work as intended. closes #2116, closes #959 --- * implement toggle for broadcasting afk message * add "self-private" AFK messages, implement exclusion system for broadcastMessage * remove rogue import, clarify config comment * move excluded collection creation out of loop, use set instead * use set instead of varargs * ok but actually use the set this time * address requested changes * update missed message section * move from Collection to Predicate for broadcast exclusion * update Predicate variable name * use identity comparison (cleanup) * clean up unnecessary imports, remove extra spacing
This commit is contained in:
parent
5082badca4
commit
6f61010cf9
|
@ -34,14 +34,6 @@ import com.earth2me.essentials.textreader.SimpleTextInput;
|
||||||
import com.earth2me.essentials.utils.DateUtil;
|
import com.earth2me.essentials.utils.DateUtil;
|
||||||
import com.earth2me.essentials.utils.VersionUtil;
|
import com.earth2me.essentials.utils.VersionUtil;
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import net.ess3.api.IEssentials;
|
import net.ess3.api.IEssentials;
|
||||||
import net.ess3.api.ISettings;
|
import net.ess3.api.ISettings;
|
||||||
import net.ess3.api.*;
|
import net.ess3.api.*;
|
||||||
|
@ -83,6 +75,16 @@ import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
import org.yaml.snakeyaml.error.YAMLException;
|
import org.yaml.snakeyaml.error.YAMLException;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.earth2me.essentials.I18n.tl;
|
import static com.earth2me.essentials.I18n.tl;
|
||||||
|
|
||||||
|
|
||||||
|
@ -762,20 +764,25 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int broadcastMessage(final String message) {
|
public int broadcastMessage(final String message) {
|
||||||
return broadcastMessage(null, null, message, true);
|
return broadcastMessage(null, null, message, true, u -> false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int broadcastMessage(final IUser sender, final String message) {
|
public int broadcastMessage(final IUser sender, final String message) {
|
||||||
return broadcastMessage(sender, null, message, false);
|
return broadcastMessage(sender, null, message, false, u -> false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int broadcastMessage(final IUser sender, final String message, final Predicate<IUser> shouldExclude) {
|
||||||
|
return broadcastMessage(sender, null, message, false, shouldExclude);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int broadcastMessage(final String permission, final String message) {
|
public int broadcastMessage(final String permission, final String message) {
|
||||||
return broadcastMessage(null, permission, message, false);
|
return broadcastMessage(null, permission, message, false, u -> false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int broadcastMessage(final IUser sender, final String permission, final String message, final boolean keywords) {
|
private int broadcastMessage(final IUser sender, final String permission, final String message, final boolean keywords, final Predicate<IUser> shouldExclude) {
|
||||||
if (sender != null && sender.isHidden()) {
|
if (sender != null && sender.isHidden()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -783,10 +790,12 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||||
IText broadcast = new SimpleTextInput(message);
|
IText broadcast = new SimpleTextInput(message);
|
||||||
|
|
||||||
final Collection<Player> players = getOnlinePlayers();
|
final Collection<Player> players = getOnlinePlayers();
|
||||||
|
|
||||||
for (Player player : players) {
|
for (Player player : players) {
|
||||||
final User user = getUser(player);
|
final User user = getUser(player);
|
||||||
if ((permission == null && (sender == null || !user.isIgnoredPlayer(sender))) || (permission != null && user.isAuthorized(permission))) {
|
if ((permission == null && (sender == null || !user.isIgnoredPlayer(sender))) || (permission != null && user.isAuthorized(permission))) {
|
||||||
|
if (shouldExclude.test(user)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (keywords) {
|
if (keywords) {
|
||||||
broadcast = new KeywordReplacer(broadcast, new CommandSource(player), this, false);
|
broadcast = new KeywordReplacer(broadcast, new CommandSource(player), this, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import org.bukkit.scheduler.BukkitTask;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public interface IEssentials extends Plugin {
|
public interface IEssentials extends Plugin {
|
||||||
void addReloadListener(IConf listener);
|
void addReloadListener(IConf listener);
|
||||||
|
@ -47,6 +48,8 @@ public interface IEssentials extends Plugin {
|
||||||
|
|
||||||
int broadcastMessage(IUser sender, String message);
|
int broadcastMessage(IUser sender, String message);
|
||||||
|
|
||||||
|
int broadcastMessage(IUser sender, String message, Predicate<IUser> shouldExclude);
|
||||||
|
|
||||||
int broadcastMessage(String permission, String message);
|
int broadcastMessage(String permission, String message);
|
||||||
|
|
||||||
ISettings getSettings();
|
ISettings getSettings();
|
||||||
|
|
|
@ -196,6 +196,8 @@ public interface ISettings extends IConf {
|
||||||
|
|
||||||
String getAfkListName();
|
String getAfkListName();
|
||||||
|
|
||||||
|
boolean broadcastAfkMessage();
|
||||||
|
|
||||||
boolean areDeathMessagesEnabled();
|
boolean areDeathMessagesEnabled();
|
||||||
|
|
||||||
void setDebug(boolean debug);
|
void setDebug(boolean debug);
|
||||||
|
|
|
@ -513,6 +513,7 @@ public class Settings implements net.ess3.api.ISettings {
|
||||||
sleepIgnoresAfkPlayers = _sleepIgnoresAfkPlayers();
|
sleepIgnoresAfkPlayers = _sleepIgnoresAfkPlayers();
|
||||||
afkListName = _getAfkListName();
|
afkListName = _getAfkListName();
|
||||||
isAfkListName = !afkListName.equalsIgnoreCase("none");
|
isAfkListName = !afkListName.equalsIgnoreCase("none");
|
||||||
|
broadcastAfkMessage = _broadcastAfkMessage();
|
||||||
itemSpawnBl = _getItemSpawnBlacklist();
|
itemSpawnBl = _getItemSpawnBlacklist();
|
||||||
loginAttackDelay = _getLoginAttackDelay();
|
loginAttackDelay = _getLoginAttackDelay();
|
||||||
signUsePerSecond = _getSignUsePerSecond();
|
signUsePerSecond = _getSignUsePerSecond();
|
||||||
|
@ -949,6 +950,17 @@ public class Settings implements net.ess3.api.ISettings {
|
||||||
return afkListName;
|
return afkListName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean broadcastAfkMessage;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean broadcastAfkMessage() {
|
||||||
|
return broadcastAfkMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean _broadcastAfkMessage() {
|
||||||
|
return config.getBoolean("broadcast-afk-message", true);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean areDeathMessagesEnabled() {
|
public boolean areDeathMessagesEnabled() {
|
||||||
return config.getBoolean("death-messages", true);
|
return config.getBoolean("death-messages", true);
|
||||||
|
|
|
@ -615,8 +615,13 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||||
if (broadcast && !isHidden()) {
|
if (broadcast && !isHidden()) {
|
||||||
setDisplayNick();
|
setDisplayNick();
|
||||||
final String msg = tl("userIsNotAway", getDisplayName());
|
final String msg = tl("userIsNotAway", getDisplayName());
|
||||||
if (!msg.isEmpty()) {
|
final String selfmsg = tl("userIsNotAwaySelf");
|
||||||
ess.broadcastMessage(this, msg);
|
if (!msg.isEmpty() && ess.getSettings().broadcastAfkMessage()) {
|
||||||
|
// exclude user from receiving general AFK announcement in favor of personal message
|
||||||
|
ess.broadcastMessage(this, msg, u -> u == this);
|
||||||
|
}
|
||||||
|
if (!selfmsg.isEmpty()) {
|
||||||
|
this.sendMessage(selfmsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -663,8 +668,13 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||||
if (!isHidden()) {
|
if (!isHidden()) {
|
||||||
setDisplayNick();
|
setDisplayNick();
|
||||||
final String msg = tl("userIsAway", getDisplayName());
|
final String msg = tl("userIsAway", getDisplayName());
|
||||||
if (!msg.isEmpty()) {
|
final String selfmsg = tl("userIsAwaySelf");
|
||||||
ess.broadcastMessage(this, msg);
|
if (!msg.isEmpty() && ess.getSettings().broadcastAfkMessage()) {
|
||||||
|
// exclude user from receiving general AFK announcement in favor of personal message
|
||||||
|
ess.broadcastMessage(this, msg, u -> u == this);
|
||||||
|
}
|
||||||
|
if (!selfmsg.isEmpty()) {
|
||||||
|
this.sendMessage(selfmsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,25 +56,31 @@ public class Commandafk extends EssentialsCommand {
|
||||||
}
|
}
|
||||||
user.setDisplayNick();
|
user.setDisplayNick();
|
||||||
String msg = "";
|
String msg = "";
|
||||||
|
String selfmsg = "";
|
||||||
if (!user.toggleAfk(AfkStatusChangeEvent.Cause.COMMAND)) {
|
if (!user.toggleAfk(AfkStatusChangeEvent.Cause.COMMAND)) {
|
||||||
//user.sendMessage(_("markedAsNotAway"));
|
|
||||||
if (!user.isHidden()) {
|
if (!user.isHidden()) {
|
||||||
msg = tl("userIsNotAway", user.getDisplayName());
|
msg = tl("userIsNotAway", user.getDisplayName());
|
||||||
|
selfmsg = tl("userIsNotAwaySelf");
|
||||||
}
|
}
|
||||||
user.updateActivity(false, AfkStatusChangeEvent.Cause.COMMAND);
|
user.updateActivity(false, AfkStatusChangeEvent.Cause.COMMAND);
|
||||||
} else {
|
} else {
|
||||||
//user.sendMessage(_("markedAsAway"));
|
|
||||||
if (!user.isHidden()) {
|
if (!user.isHidden()) {
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
msg = tl("userIsAwayWithMessage", user.getDisplayName(), message);
|
msg = tl("userIsAwayWithMessage", user.getDisplayName(), message);
|
||||||
|
selfmsg = tl("userIsAwaySelfWithMessage", message);
|
||||||
} else {
|
} else {
|
||||||
msg = tl("userIsAway", user.getDisplayName());
|
msg = tl("userIsAway", user.getDisplayName());
|
||||||
|
selfmsg = tl("userIsAwaySelf");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
user.setAfkMessage(message);
|
user.setAfkMessage(message);
|
||||||
}
|
}
|
||||||
if (!msg.isEmpty()) {
|
if (!msg.isEmpty() && ess.getSettings().broadcastAfkMessage()) {
|
||||||
ess.broadcastMessage(user, msg);
|
// exclude user from receiving general AFK announcement in favor of personal message
|
||||||
|
ess.broadcastMessage(user, msg, u -> u == user);
|
||||||
|
}
|
||||||
|
if (!selfmsg.isEmpty()) {
|
||||||
|
user.sendMessage(selfmsg);
|
||||||
}
|
}
|
||||||
user.setDisplayNick(); // Set this again after toggling
|
user.setDisplayNick(); // Set this again after toggling
|
||||||
}
|
}
|
||||||
|
|
|
@ -437,6 +437,11 @@ sleep-ignores-afk-players: true
|
||||||
# You may use color codes, use {USERNAME} the player's name or {PLAYER} for the player's displayname.
|
# You may use color codes, use {USERNAME} the player's name or {PLAYER} for the player's displayname.
|
||||||
afk-list-name: "none"
|
afk-list-name: "none"
|
||||||
|
|
||||||
|
# When a player enters or exits AFK mode, should the AFK notification be broadcast
|
||||||
|
# to the entire server, or just to the player?
|
||||||
|
# When this setting is false, only the player will be notified upon changing their AFK state.
|
||||||
|
broadcast-afk-message: true
|
||||||
|
|
||||||
# You can disable the death messages of Minecraft here.
|
# You can disable the death messages of Minecraft here.
|
||||||
death-messages: true
|
death-messages: true
|
||||||
|
|
||||||
|
|
|
@ -587,6 +587,9 @@ userDoesNotExist=\u00a74The user\u00a7c {0} \u00a74does not exist.
|
||||||
userIsAway=\u00a77* {0} \u00a77is now AFK.
|
userIsAway=\u00a77* {0} \u00a77is now AFK.
|
||||||
userIsAwayWithMessage=\u00a77* {0} \u00a77is now AFK.
|
userIsAwayWithMessage=\u00a77* {0} \u00a77is now AFK.
|
||||||
userIsNotAway=\u00a77* {0} \u00a77is no longer AFK.
|
userIsNotAway=\u00a77* {0} \u00a77is no longer AFK.
|
||||||
|
userIsAwaySelf=\u00a77You are now AFK.
|
||||||
|
userIsAwaySelfWithMessage=\u00a77You are now AFK.
|
||||||
|
userIsNotAwaySelf=\u00a77You are no longer AFK.
|
||||||
userJailed=\u00a76You have been jailed\!
|
userJailed=\u00a76You have been jailed\!
|
||||||
userUnknown=\u00a74Warning\: The user ''\u00a7c{0}\u00a74'' has never joined this server.
|
userUnknown=\u00a74Warning\: The user ''\u00a7c{0}\u00a74'' has never joined this server.
|
||||||
usingTempFolderForTesting=Using temp folder for testing\:
|
usingTempFolderForTesting=Using temp folder for testing\:
|
||||||
|
|
Loading…
Reference in a new issue