Add config option for new username join messages (#4290)

Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com>
This commit is contained in:
Olivia 2021-07-07 10:46:54 -05:00 committed by GitHub
parent 5e178943a0
commit ff58d8e443
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 3 deletions

View File

@ -305,11 +305,15 @@ public class EssentialsPlayerListener implements Listener {
user.startTransaction();
final String lastAccountName = user.getLastAccountName(); // For comparison
user.setLastAccountName(user.getBase().getName());
user.setLastLogin(currentTime);
user.setDisplayNick();
updateCompass(user);
// Check for new username. If they don't want the message, let's just say it's false.
final boolean newUsername = ess.getSettings().isCustomNewUsernameMessage() && lastAccountName != null && !lastAccountName.equals(user.getBase().getName());
if (!ess.getVanishedPlayersNew().isEmpty() && !user.isAuthorized("essentials.vanish.see")) {
for (final String p : ess.getVanishedPlayersNew()) {
final Player toVanish = ess.getServer().getPlayerExact(p);
@ -335,13 +339,14 @@ public class EssentialsPlayerListener implements Listener {
} else if (message == null || hideJoinQuitMessages()) {
effectiveMessage = null;
} else if (ess.getSettings().isCustomJoinMessage()) {
final String msg = ess.getSettings().getCustomJoinMessage()
final String msg = (newUsername ? ess.getSettings().getCustomNewUsernameMessage() : ess.getSettings().getCustomJoinMessage())
.replace("{PLAYER}", player.getDisplayName()).replace("{USERNAME}", player.getName())
.replace("{UNIQUE}", NumberFormat.getInstance().format(ess.getUserMap().getUniqueUsers()))
.replace("{ONLINE}", NumberFormat.getInstance().format(ess.getOnlinePlayers().size()))
.replace("{UPTIME}", DateUtil.formatDateDiff(ManagementFactory.getRuntimeMXBean().getStartTime()))
.replace("{PREFIX}", FormatUtil.replaceFormat(ess.getPermissionsHandler().getPrefix(player)))
.replace("{SUFFIX}", FormatUtil.replaceFormat(ess.getPermissionsHandler().getSuffix(player)));
.replace("{SUFFIX}", FormatUtil.replaceFormat(ess.getPermissionsHandler().getSuffix(player)))
.replace("{OLDUSERNAME}", lastAccountName);
if (!msg.isEmpty()) {
ess.getServer().broadcastMessage(msg);
}

View File

@ -275,6 +275,10 @@ public interface ISettings extends IConf {
String getCustomQuitMessage();
String getCustomNewUsernameMessage();
boolean isCustomNewUsernameMessage();
boolean isCustomServerFullMessage();
boolean isNotifyNoNewMail();

View File

@ -116,6 +116,8 @@ public class Settings implements net.ess3.api.ISettings {
private boolean isCustomJoinMessage;
private String customQuitMessage;
private boolean isCustomQuitMessage;
private String customNewUsernameMessage;
private boolean isCustomNewUsernameMessage;
private List<String> spawnOnJoinGroups;
private Map<Pattern, Long> commandCooldowns;
private boolean npcsInBalanceRanking = false;
@ -717,6 +719,8 @@ public class Settings implements net.ess3.api.ISettings {
isCustomJoinMessage = !customJoinMessage.equals("none");
customQuitMessage = _getCustomQuitMessage();
isCustomQuitMessage = !customQuitMessage.equals("none");
customNewUsernameMessage = _getCustomNewUsernameMessage();
isCustomNewUsernameMessage = !customNewUsernameMessage.equals("none");
muteCommands = _getMuteCommands();
spawnOnJoinGroups = _getSpawnOnJoinGroups();
commandCooldowns = _getCommandCooldowns();
@ -1372,6 +1376,20 @@ public class Settings implements net.ess3.api.ISettings {
return isCustomQuitMessage;
}
public String _getCustomNewUsernameMessage() {
return FormatUtil.replaceFormat(config.getString("custom-new-username-message", "none"));
}
@Override
public String getCustomNewUsernameMessage() {
return customNewUsernameMessage;
}
@Override
public boolean isCustomNewUsernameMessage() {
return isCustomNewUsernameMessage;
}
@Override
public boolean isCustomServerFullMessage() {
return config.getBoolean("use-custom-server-full-message", true);

View File

@ -520,10 +520,34 @@ allow-silent-join-quit: false
# You can set custom join and quit messages here. Set this to "none" to use the default Minecraft message,
# or set this to "" to hide the message entirely.
# You may use color codes, {USERNAME} for the player's name, {PLAYER} for the player's displayname, {PREFIX} for the player's prefix, and {SUFFIX} for the player's suffix.
# Available placeholders:
# {PLAYER} - The player's displayname.
# {USERNAME} - The player's username.
# {PREFIX} - The player's prefix.
# {SUFFIX} - The player's suffix.
# {ONLINE} - The number of players online.
# {UNIQUE} - The number of unique players to join the server.
# {UPTIME} - The amount of time the server has been online.
custom-join-message: "none"
custom-quit-message: "none"
# You can set a custom join message for users who join with a new username here.
# This message will only be used if a user has joined before and have since changed their username.
# This will be displayed INSTEAD OF custom-join-message, so if you intend to keep them similar, make sure they match.
# Set this to "none" to use the the "custom-join-message" above for every join.
# Available placeholders:
# {PLAYER} - The player's displayname.
# {USERNAME} - The player's username.
# {OLDUSERNAME} - The player's old username.
# {PREFIX} - The player's prefix.
# {SUFFIX} - The player's suffix.
# {ONLINE} - The number of players online.
# {UNIQUE} - The number of unique players to join the server.
# {UPTIME} - The amount of time the server has been online.
custom-new-username-message: "none"
# Should Essentials override the vanilla "Server Full" message with its own from the language file?
# Set to false to keep the vanilla message.
use-custom-server-full-message: true