Merge pull request #90 from Deauthorized/messagesincursion

Move most hard coded messages to messages.yml to allow customization.
This commit is contained in:
Video 2024-05-09 17:09:37 -06:00 committed by GitHub
commit 83ec997125
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 89 additions and 51 deletions

View File

@ -63,12 +63,12 @@ public class BanCMD extends PlexCommand
{
reason = StringUtils.join(args, " ", 1, args.length);
String newReason = StringUtils.normalizeSpace(reason.replace("-nrb", ""));
punishment.setReason(newReason.trim().isEmpty() ? "No reason provided." : newReason);
punishment.setReason(newReason.trim().isEmpty() ? messageString("noReasonProvided") : newReason);
rollBack = reason.startsWith("-rb") || reason.endsWith("-rb");
}
else
{
punishment.setReason("No reason provided.");
punishment.setReason(messageString("noReasonProvided"));
}
punishment.setPunishedUsername(plexPlayer.getName());
ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));

View File

@ -41,7 +41,7 @@ public class BcastLoginMessageCMD extends PlexCommand
if (!loginMessage.isEmpty())
{
PlexUtils.broadcast(PlexUtils.stringToComponent(loginMessage));
PlexUtils.broadcast(mmString("<yellow>" + plexPlayer.getName() + " joined the game"));
PlexUtils.broadcast(messageComponent("loginMessage", plexPlayer.getName()));
}
else
{

View File

@ -41,9 +41,9 @@ public class DebugCMD extends PlexCommand
if (plugin.getRedisConnection().getJedis().exists(player.getUniqueId().toString()))
{
plugin.getRedisConnection().getJedis().del(player.getUniqueId().toString());
return componentFromString("Successfully reset " + player.getName() + "'s Redis punishments!").color(NamedTextColor.YELLOW);
return messageComponent("redisResetSuccessful", player.getName());
}
return componentFromString("Couldn't find player in Redis punishments.");
return messageComponent("redisResetPlayerNotFound");
}
}
if (args[0].equalsIgnoreCase("gamerules"))
@ -62,7 +62,7 @@ public class DebugCMD extends PlexCommand
PlexLog.log("Set specific gamerules for world: " + world.toLowerCase(Locale.ROOT));
}
}
return mmString("<aqua>Re-applied game all the game rules!");
return messageComponent("reappliedGamerules");
}
if (args[0].equalsIgnoreCase("aliases"))
{
@ -72,9 +72,9 @@ public class DebugCMD extends PlexCommand
Command command = plugin.getServer().getCommandMap().getCommand(commandName);
if (command == null)
{
return mmString("<red>That command could not be found!");
return messageComponent("commandNotFound");
}
return mmString("<aqua>Aliases for " + commandName + " are: " + Arrays.toString(command.getAliases().toArray(new String[0])));
return messageComponent("commandAliases", commandName, Arrays.toString(command.getAliases().toArray(new String[0])));
}
}
if (args[0].equalsIgnoreCase("pagination"))

View File

@ -134,7 +134,7 @@ public class EntityWipeCMD extends PlexCommand
}
catch (NumberFormatException ex)
{
sender.sendMessage(mmString("<red>" + string + "<red> is not a valid number!"));
sender.sendMessage(messageComponent("notANumber", string));
}
return null;
}

View File

@ -38,7 +38,7 @@ public class KickCMD extends PlexCommand
}
PlexPlayer plexPlayer = DataUtils.getPlayer(args[0]);
String reason = "No reason provided";
String reason = messageString("noReasonProvided");
if (plexPlayer == null)
{

View File

@ -2,6 +2,7 @@ package dev.plex.command.impl;
import com.google.common.collect.Lists;
import dev.plex.command.PlexCommand;
import dev.plex.util.PlexUtils;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.hook.VaultHook;
@ -27,17 +28,7 @@ public class ListCMD extends PlexCommand
List<Player> players = Lists.newArrayList(Bukkit.getOnlinePlayers());
players.removeIf(PlayerMeta::isVanished);
Component list = Component.empty();
Component header = Component.text("There " + (players.size() == 1 ? "is" : "are") + " currently").color(NamedTextColor.GRAY)
.append(Component.space())
.append(Component.text(players.size()).color(NamedTextColor.YELLOW))
.append(Component.space())
.append(Component.text(players.size() == 1 ? "player" : "players").color(NamedTextColor.GRAY))
.append(Component.space())
.append(Component.text("online out of").color(NamedTextColor.GRAY))
.append(Component.space())
.append(Component.text(Bukkit.getMaxPlayers()).color(NamedTextColor.YELLOW))
.append(Component.space())
.append(Component.text(Bukkit.getMaxPlayers() == 1 ? "player." : "players.").color(NamedTextColor.GRAY));
Component header = PlexUtils.messageComponent(players.size() == 1 ? "listHeader" : "listHeaderPlural", players.size(), Bukkit.getMaxPlayers());
send(sender, header);
if (players.isEmpty())
{

View File

@ -124,11 +124,11 @@ public class NotesCMD extends PlexCommand
private void readNotes(@NotNull CommandSender sender, PlexPlayer plexPlayer, List<Note> notes)
{
AtomicReference<Component> noteList = new AtomicReference<>(Component.text("Player notes for: " + plexPlayer.getName()).color(NamedTextColor.GREEN));
AtomicReference<Component> noteList = new AtomicReference<>(messageComponent("notesHeader", plexPlayer.getName()));
for (Note note : notes)
{
Component noteLine = mmString("<gold><!italic>" + note.getId() + " - Written by: " + DataUtils.getPlayer(note.getWrittenBy()).getName() + " on " + TimeUtils.useTimezone(note.getTimestamp()));
noteLine = noteLine.append(mmString("<newline><yellow># " + note.getNote()));
Component noteLine = messageComponent("notePrefix", note.getId(), DataUtils.getPlayer(note.getWrittenBy()).getName(), TimeUtils.useTimezone(note.getTimestamp()));
noteLine = noteLine.append(messageComponent("noteLine", note.getNote()));
noteList.set(noteList.get().append(Component.newline()));
noteList.set(noteList.get().append(noteLine));
}

View File

@ -78,21 +78,16 @@ public class SmiteCMD extends PlexCommand
final Player player = getNonNullPlayer(args[0]);
final PlexPlayer plexPlayer = getPlexPlayer(player);
Title title = Title.title(Component.text("You've been smitten.").color(NamedTextColor.RED), Component.text("Be sure to follow the rules!").color(NamedTextColor.YELLOW));
Title title = Title.title(messageComponent("smiteTitleHeader"), messageComponent("smiteTitleMessage", reason, sender.getName()));
player.showTitle(title);
if (!silent)
{
PlexUtils.broadcast(mmString("<red>" + player.getName() + " has been a naughty, naughty boy."));
if (reason != null)
{
PlexUtils.broadcast(mmString(" <red>Reason: " + "<yellow>" + reason));
}
PlexUtils.broadcast(mmString(" <red>Smitten by: " + "<yellow>" + sender.getName()));
PlexUtils.broadcast(messageComponent("smiteBroadcast", player.getName(), reason != null ? reason : messageString("noReasonProvided"), sender.getName()));
}
else
{
send(sender, "Smitten " + player.getName() + " quietly.");
send(sender, messageComponent("smittenQuietly", player.getName()));
}
// Set gamemode to survival
@ -129,8 +124,8 @@ public class SmiteCMD extends PlexCommand
if (reason != null)
{
punishment.setReason(reason);
send(player, mmString("<red>You've been smitten. Reason: <yellow>" + reason));
}
send(player, messageComponent("smitten", reason != null ? reason : messageString("noReasonProvided")));
return null;
}

View File

@ -58,12 +58,12 @@ public class TempbanCMD extends PlexCommand
{
reason = StringUtils.join(args, " ", 2, args.length);
String newReason = StringUtils.normalizeSpace(reason.replace("-nrb", ""));
punishment.setReason(newReason.trim().isEmpty() ? "No reason provided." : newReason);
punishment.setReason(newReason.trim().isEmpty() ? messageString("noReasonProvided") : newReason);
rollBack = reason.startsWith("-rb") || reason.endsWith("-rb");
}
else
{
punishment.setReason("No reason provided.");
punishment.setReason(messageString("noReasonProvided"));
}
punishment.setPunishedUsername(target.getName());
punishment.setEndDate(TimeUtils.createDate(args[1]));

View File

@ -1,6 +1,7 @@
package dev.plex.listener.impl;
import dev.plex.listener.PlexListener;
import dev.plex.util.PlexUtils;
import dev.plex.services.impl.TimingService;
import net.kyori.adventure.text.Component;
import org.bukkit.event.EventHandler;
@ -19,7 +20,7 @@ public class AntiNukerListener extends PlexListener
if (getCount(event.getPlayer().getUniqueId()) > 200L)
{
TimingService.strikes.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
event.getPlayer().kick(Component.text("Please turn off your nuker!"));
event.getPlayer().kick(PlexUtils.messageComponent("nukerKickMessage"));
event.setCancelled(true);
}
}
@ -31,7 +32,7 @@ public class AntiNukerListener extends PlexListener
if (getCount(event.getPlayer().getUniqueId()) > 200L)
{
TimingService.strikes.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
event.getPlayer().kick(Component.text("Please turn off your nuker!"));
event.getPlayer().kick(PlexUtils.messageComponent("nukerKickMessage"));
event.setCancelled(true);
}
}

View File

@ -1,6 +1,7 @@
package dev.plex.listener.impl;
import dev.plex.listener.PlexListener;
import dev.plex.util.PlexUtils;
import dev.plex.services.impl.TimingService;
import io.papermc.paper.event.player.AsyncChatEvent;
import net.kyori.adventure.text.Component;
@ -19,7 +20,7 @@ public class AntiSpamListener extends PlexListener
TimingService.spamCooldown.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
if (getCount(event.getPlayer().getUniqueId()) > 8L)
{
event.getPlayer().sendMessage(Component.text("Please refrain from spamming messages.").color(NamedTextColor.GRAY));
event.getPlayer().sendMessage(PlexUtils.messageComponent("antiSpamMessage"));
event.setCancelled(true);
}
}
@ -30,7 +31,7 @@ public class AntiSpamListener extends PlexListener
TimingService.spamCooldown.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
if (getCount(event.getPlayer().getUniqueId()) > 8L)
{
event.getPlayer().sendMessage(Component.text("Please refrain from spamming commands.").color(NamedTextColor.GRAY));
event.getPlayer().sendMessage(PlexUtils.messageComponent("antiSpamMessage"));
event.setCancelled(true);
}
}

View File

@ -71,11 +71,9 @@ public class PlayerListener extends PlexListener
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
{
String plural = notes.size() == 1 ? "note." : "notes.";
if (!notes.isEmpty())
{
PlexUtils.broadcastToAdmins(Component.text(plexPlayer.getName() + " has " + notes.size() + " " + plural).color(NamedTextColor.GOLD), "plex.notes.notify");
PlexUtils.broadcastToAdmins(Component.text("Click to view their " + plural).clickEvent(ClickEvent.runCommand("/notes " + plexPlayer.getName() + " list")).color(NamedTextColor.GOLD), "plex.notes.notify");
PlexUtils.broadcastToAdmins(PlexUtils.messageComponent(notes.size() == 1 ? "playerNoteAlert" : "playerNoteAlertPlural", plexPlayer.getName(), notes.size()), "plex.notes.notify");
}
});
}

View File

@ -112,7 +112,8 @@ public class WorldListener extends PlexListener
boolean isFaweCommand = command instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) command).getPlugin().equals(Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit"));
if (isWeCommand || isFaweCommand || EDIT_COMMANDS.contains(message.toLowerCase()))
{
event.getPlayer().sendMessage(Component.text("You do not have permission to use that command in this world.").color(NamedTextColor.RED));
String noEdit = plugin.config.getString("worlds." + event.getPlayer().getWorld().getName().toLowerCase() + ".modification.message");
event.getPlayer().sendMessage(MiniMessage.miniMessage().deserialize(noEdit));
event.setCancelled(true);
}
}

View File

@ -3,6 +3,7 @@ package dev.plex.services.impl;
import dev.plex.Plex;
import dev.plex.services.AbstractService;
import dev.plex.util.TimeUtils;
import dev.plex.util.PlexUtils;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
@ -27,7 +28,7 @@ public class BanService extends AbstractService
if (ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)).isAfter(punishment.getEndDate()))
{
Plex.get().getPunishmentManager().unban(punishment);
Bukkit.broadcast(Component.text("Plex - Unbanned " + Bukkit.getOfflinePlayer(punishment.getPunished()).getName()));
Bukkit.broadcast(PlexUtils.messageComponent("banExpiredBroadcast", Bukkit.getOfflinePlayer(punishment.getPunished()).getName()));
}
});
});

View File

@ -27,6 +27,8 @@ indefBanMessageReason: "<red>Your {0} is indefinitely banned! You may appeal at
playerNotFound: "<red>Player not found!"
specifyPlayer: "<red>You must specify a player!"
worldNotFound: "<red>World not found!"
# This will always be used for punishments where the sanctioning administrator has not provided a reason. Will ignore MiniMessage tags.
noReasonProvided: "No reason provided."
# 0 - The world you have been teleported to
playerWorldTeleport: "<aqua>You have been teleported to {0}."
# 0 - The person who is freezing
@ -210,3 +212,51 @@ playersMaterialCleared: "<gray>{0} has been removed from the following players:
nobodyHasThatMaterial: "<gray>No one online has that in their inventory."
# 0 - The attempted material name
materialNotFound: "<red>{0} is not a valid item/block name."
# 0 - The players name
loginMessage: "<yellow>{0} joined the game"
# 0 - The string that wasn't a valid integer
notANumber: "<red>{0} is not a valid number!"
# 0 - Players currently online
# 1 - Max players
listHeader: "<gray>There is currently <yellow>{0}<gray> player online out of <yellow>{1}<gray> players."
# 0 - Players currently online
# 1 - Max players
listHeaderPlural: "<gray>There are currently <yellow>{0}<gray> players online out of <yellow>{1}<gray> players."
# 0 - Player who is having their notes fetched
notesHeader: "Player notes for: <green>{0}"
# 0 - Note ID
# 1 - Author of the note
# 2 - Timestamp
notePrefix: "<gold><!italic>{0} - Written by: {1} on {2}"
# 0 - The content of the note
noteLine: "<newline><yellow># {0}"
# 0 - The player
# 1 - The number of notes logged for said player
playerNoteAlert: "<gold>{0} has {1} note. <click:run_command:/notes {0} list><underlined>Click here to view their note."
# 0 - The player
# 1 - The number of notes logged for said player
playerNoteAlertPlural: "<gold>{0} has {1} notes. <click:run_command:/notes {0} list><underlined>Click here to view their notes."
smiteTitleHeader: "<red>You've been smitten."
# 0 - The reason for the smite. Will default to noReasonProvided if no reason is specified.
# 1 - The admin / staff member
smiteTitleMessage: "<yellow>Be sure to follow the rules!"
# 0 - The player
# 1 - The reason for the smite. Will default to noReasonProvided if no reason is specified.
# 2 - The admin / staff member
smiteBroadcast: "<red>{0} has been a naughty, naughty boy.<newline><red> - Reason: <yellow>{1}<newline><red> - Smitten by: <yellow>{2}"
# 0 - The player
smittenQuietly: "<gray>Smitten {0} quietly."
# 0 - The reason for being smitten
smitten: "<red>You've been smitten. Reason: <yellow>{0}"
nukerKickMessage: "Please turn off your nuker!"
antiSpamMessage: "<gray>Please refrain from spamming messages."
# 0 - The player
banExpiredBroadcast: "Plex - Automatically unbanning {0}"
# 0 - The player
redisResetSuccessful: "<yellow>Successfuly reset {0}'s Redis punishments!"
redisResetPlayerNotFound: "Couldn't find player in Redis punishments."
reappliedGamerules: "<aqua>All game rules have been re-applied!"
commandNotFound: "<red>That command could not be found!"
# 0 - The command
# 1 - A list of aliases found
commandAliases: "<aqua>Aliases for {0} are: {1}"