Add a delay for sending the MOTD (#1396)

* Add delay-motd setting
* Move MOTD to Runnable
* Refactored according to comments
* Delay motd loading as well as sending
This commit is contained in:
md678685 2017-07-28 19:20:44 +01:00 committed by GitHub
parent d7685dc1bc
commit 50f2e7a95f
4 changed files with 50 additions and 23 deletions

View File

@ -202,22 +202,6 @@ public class EssentialsPlayerListener implements Listener {
dUser.updateActivity(false);
dUser.stopTransaction();
IText tempInput = null;
if (!ess.getSettings().isCommandDisabled("motd")) {
try {
tempInput = new TextInput(dUser.getSource(), "motd", true, ess);
} catch (IOException ex) {
if (ess.getSettings().isDebug()) {
LOGGER.log(Level.WARNING, ex.getMessage(), ex);
} else {
LOGGER.log(Level.WARNING, ex.getMessage());
}
}
}
final IText input = tempInput;
class DelayJoinTask implements Runnable {
@Override
public void run() {
@ -262,10 +246,12 @@ public class EssentialsPlayerListener implements Listener {
ess.getServer().broadcastMessage(message);
}
if (input != null && user.isAuthorized("essentials.motd")) {
final IText output = new KeywordReplacer(input, user.getSource(), ess);
final TextPager pager = new TextPager(output, true);
pager.showPage("1", null, "motd", user.getSource());
int motdDelay = ess.getSettings().getMotdDelay() / 50;
DelayMotdTask motdTask = new DelayMotdTask(user);
if (motdDelay > 0) {
ess.scheduleSyncDelayedTask(motdTask, motdDelay);
} else {
motdTask.run();
}
if (!ess.getSettings().isCommandDisabled("mail") && user.isAuthorized("essentials.mail")) {
@ -302,6 +288,39 @@ public class EssentialsPlayerListener implements Listener {
user.stopTransaction();
}
class DelayMotdTask implements Runnable {
private User user;
public DelayMotdTask(User user) {
this.user = user;
}
@Override
public void run() {
IText tempInput = null;
if (!ess.getSettings().isCommandDisabled("motd")) {
try {
tempInput = new TextInput(user.getSource(), "motd", true, ess);
} catch (IOException ex) {
if (ess.getSettings().isDebug()) {
LOGGER.log(Level.WARNING, ex.getMessage(), ex);
} else {
LOGGER.log(Level.WARNING, ex.getMessage());
}
}
}
final IText input = tempInput;
if (input != null && user.isAuthorized("essentials.motd")) {
final IText output = new KeywordReplacer(input, user.getSource(), ess);
final TextPager pager = new TextPager(output, true);
pager.showPage("1", null, "motd", user.getSource());
}
}
}
}
ess.scheduleSyncDelayedTask(new DelayJoinTask());

View File

@ -279,4 +279,6 @@ public interface ISettings extends IConf {
boolean isAddingSuffixInPlayerlist();
int getNotifyPlayerOfMailCooldown();
int getMotdDelay();
}

View File

@ -24,7 +24,6 @@ import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.util.*;
import java.util.Locale.Category;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -33,8 +32,6 @@ import static com.earth2me.essentials.I18n.tl;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import com.google.common.base.Preconditions;
public class Settings implements net.ess3.api.ISettings {
private final transient EssentialsConf config;
@ -1414,4 +1411,9 @@ public class Settings implements net.ess3.api.ISettings {
public int getNotifyPlayerOfMailCooldown() {
return config.getInt("notify-player-of-mail-cooldown", 0);
}
@Override
public int getMotdDelay() {
return config.getInt("delay-motd", 0);
}
}

View File

@ -542,6 +542,10 @@ pastebin-createkit: true
# This is useful when a sign sells or buys one item at a time and the player wants to sell a bunch at once.
allow-bulk-buy-sell: true
# Delay for the MOTD display for players on join, in milliseconds.
# This has no effect if the MOTD command or permission are disabled.
delay-motd: 0
############################################################
# +------------------------------------------------------+ #
# | EssentialsHome | #