mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-03 15:08:18 +01:00
Allow disabling MOTD task and cancel on player logout (#4411)
This PR allows setting `delay-motd` to a negative value in `config.yml` to disable the MOTD join task without disabling `/motd`, and fixes an issue where delayed MOTD tasks would run even after a player logged out (in case someone previously set an insanely high MOTD delay to "disable" the MOTD on join). Fixes #4408.
This commit is contained in:
parent
5334a3fd34
commit
14fbfe360e
@ -66,6 +66,8 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
@ -75,6 +77,7 @@ import static com.earth2me.essentials.I18n.tl;
|
||||
public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
private static final Logger LOGGER = Logger.getLogger("Essentials");
|
||||
private final transient IEssentials ess;
|
||||
private final ConcurrentHashMap<UUID, Integer> pendingMotdTasks = new ConcurrentHashMap<>();
|
||||
|
||||
public EssentialsPlayerListener(final IEssentials parent) {
|
||||
this.ess = parent;
|
||||
@ -216,6 +219,11 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
public void onPlayerQuit(final PlayerQuitEvent event) {
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
|
||||
final Integer pendingId = pendingMotdTasks.remove(user.getUUID());
|
||||
if (pendingId != null) {
|
||||
ess.getScheduler().cancelTask(pendingId);
|
||||
}
|
||||
|
||||
if (hideJoinQuitMessages() || (ess.getSettings().allowSilentJoinQuit() && user.isAuthorized("essentials.silentquit"))) {
|
||||
event.setQuitMessage(null);
|
||||
} else if (ess.getSettings().isCustomQuitMessage() && event.getQuitMessage() != null) {
|
||||
@ -360,13 +368,15 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
|
||||
ess.runTaskAsynchronously(() -> ess.getServer().getPluginManager().callEvent(new AsyncUserDataLoadEvent(user, effectiveMessage)));
|
||||
|
||||
if (ess.getSettings().getMotdDelay() < 0) {
|
||||
final int motdDelay = ess.getSettings().getMotdDelay() / 50;
|
||||
final DelayMotdTask motdTask = new DelayMotdTask(user);
|
||||
if (motdDelay > 0) {
|
||||
ess.scheduleSyncDelayedTask(motdTask, motdDelay);
|
||||
pendingMotdTasks.put(user.getUUID(), ess.scheduleSyncDelayedTask(motdTask, motdDelay));
|
||||
} else {
|
||||
motdTask.run();
|
||||
}
|
||||
}
|
||||
|
||||
if (!ess.getSettings().isCommandDisabled("mail") && user.isAuthorized("essentials.mail")) {
|
||||
if (user.getUnreadMailAmount() == 0) {
|
||||
@ -427,6 +437,8 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
pendingMotdTasks.remove(user.getUUID());
|
||||
|
||||
IText tempInput = null;
|
||||
|
||||
if (!ess.getSettings().isCommandDisabled("motd")) {
|
||||
|
@ -669,6 +669,7 @@ allow-selling-named-items: false
|
||||
|
||||
# Delay for the MOTD display for players on join, in milliseconds.
|
||||
# This has no effect if the MOTD command or permission are disabled.
|
||||
# This can also be set to -1 to completely disable the join MOTD all together.
|
||||
delay-motd: 0
|
||||
|
||||
# A list of commands that should have their complementary confirm commands enabled by default.
|
||||
|
Loading…
Reference in New Issue
Block a user