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.Locale;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -75,6 +77,7 @@ import static com.earth2me.essentials.I18n.tl;
|
|||||||
public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||||
private static final Logger LOGGER = Logger.getLogger("Essentials");
|
private static final Logger LOGGER = Logger.getLogger("Essentials");
|
||||||
private final transient IEssentials ess;
|
private final transient IEssentials ess;
|
||||||
|
private final ConcurrentHashMap<UUID, Integer> pendingMotdTasks = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public EssentialsPlayerListener(final IEssentials parent) {
|
public EssentialsPlayerListener(final IEssentials parent) {
|
||||||
this.ess = parent;
|
this.ess = parent;
|
||||||
@ -216,6 +219,11 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
|||||||
public void onPlayerQuit(final PlayerQuitEvent event) {
|
public void onPlayerQuit(final PlayerQuitEvent event) {
|
||||||
final User user = ess.getUser(event.getPlayer());
|
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"))) {
|
if (hideJoinQuitMessages() || (ess.getSettings().allowSilentJoinQuit() && user.isAuthorized("essentials.silentquit"))) {
|
||||||
event.setQuitMessage(null);
|
event.setQuitMessage(null);
|
||||||
} else if (ess.getSettings().isCustomQuitMessage() && event.getQuitMessage() != null) {
|
} else if (ess.getSettings().isCustomQuitMessage() && event.getQuitMessage() != null) {
|
||||||
@ -360,12 +368,14 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
|||||||
|
|
||||||
ess.runTaskAsynchronously(() -> ess.getServer().getPluginManager().callEvent(new AsyncUserDataLoadEvent(user, effectiveMessage)));
|
ess.runTaskAsynchronously(() -> ess.getServer().getPluginManager().callEvent(new AsyncUserDataLoadEvent(user, effectiveMessage)));
|
||||||
|
|
||||||
final int motdDelay = ess.getSettings().getMotdDelay() / 50;
|
if (ess.getSettings().getMotdDelay() < 0) {
|
||||||
final DelayMotdTask motdTask = new DelayMotdTask(user);
|
final int motdDelay = ess.getSettings().getMotdDelay() / 50;
|
||||||
if (motdDelay > 0) {
|
final DelayMotdTask motdTask = new DelayMotdTask(user);
|
||||||
ess.scheduleSyncDelayedTask(motdTask, motdDelay);
|
if (motdDelay > 0) {
|
||||||
} else {
|
pendingMotdTasks.put(user.getUUID(), ess.scheduleSyncDelayedTask(motdTask, motdDelay));
|
||||||
motdTask.run();
|
} else {
|
||||||
|
motdTask.run();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ess.getSettings().isCommandDisabled("mail") && user.isAuthorized("essentials.mail")) {
|
if (!ess.getSettings().isCommandDisabled("mail") && user.isAuthorized("essentials.mail")) {
|
||||||
@ -427,6 +437,8 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
pendingMotdTasks.remove(user.getUUID());
|
||||||
|
|
||||||
IText tempInput = null;
|
IText tempInput = null;
|
||||||
|
|
||||||
if (!ess.getSettings().isCommandDisabled("motd")) {
|
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.
|
# Delay for the MOTD display for players on join, in milliseconds.
|
||||||
# This has no effect if the MOTD command or permission are disabled.
|
# 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
|
delay-motd: 0
|
||||||
|
|
||||||
# A list of commands that should have their complementary confirm commands enabled by default.
|
# A list of commands that should have their complementary confirm commands enabled by default.
|
||||||
|
Loading…
Reference in New Issue
Block a user