This commit is contained in:
Telesphoreo 2022-04-09 23:51:29 -05:00
commit c4be024619
10 changed files with 55 additions and 18 deletions

View File

@ -160,7 +160,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
} }
catch (PlayerNotFoundException | CommandFailException | ConsoleOnlyException | ConsoleMustDefinePlayerException | PlayerNotBannedException ex) catch (PlayerNotFoundException | CommandFailException | ConsoleOnlyException | ConsoleMustDefinePlayerException | PlayerNotBannedException ex)
{ {
send(sender, MiniMessage.miniMessage().deserialize(ex.getMessage())); send(sender, PlexUtils.mmDeserialize(ex.getMessage()));
} }
return true; return true;
} }
@ -544,7 +544,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
*/ */
protected Component mmString(String s) protected Component mmString(String s)
{ {
return MiniMessage.miniMessage().deserialize(s); return PlexUtils.mmDeserialize(s);
} }
public Rank getLevel() public Rank getLevel()

View File

@ -7,6 +7,7 @@ import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank; import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
@ -48,7 +49,7 @@ public class TagCMD extends PlexCommand
} }
String prefix = StringUtils.join(args, " ", 1, args.length); String prefix = StringUtils.join(args, " ", 1, args.length);
Component convertedComponent = removeEvents(noColorComponentFromString(prefix)); Component convertedComponent = removeEvents(noColorComponentFromString(prefix));
convertedComponent = removeEvents(MiniMessage.miniMessage().deserialize(LegacyComponentSerializer.legacySection().serialize(convertedComponent))); convertedComponent = removeEvents(PlexUtils.mmDeserialize(LegacyComponentSerializer.legacySection().serialize(convertedComponent)));
if (PlainTextComponentSerializer.plainText().serialize(convertedComponent).length() > plugin.config.getInt("chat.max-tag-length", 16)) if (PlainTextComponentSerializer.plainText().serialize(convertedComponent).length() > plugin.config.getInt("chat.max-tag-length", 16))
{ {

View File

@ -47,7 +47,7 @@ public class UnbanCMD extends PlexCommand
PlexPlayer plexPlayer = getOfflinePlexPlayer(targetUUID); PlexPlayer plexPlayer = getOfflinePlexPlayer(targetUUID);
if (!aBoolean) if (!aBoolean)
{ {
send(sender, MiniMessage.miniMessage().deserialize(new PlayerNotBannedException().getMessage())); send(sender, PlexUtils.mmDeserialize(new PlayerNotBannedException().getMessage()));
return; return;
} }
plugin.getPunishmentManager().unban(targetUUID); plugin.getPunishmentManager().unban(targetUUID);

View File

@ -8,7 +8,6 @@ import dev.plex.command.blocker.RegexCommand;
import dev.plex.listener.PlexListener; import dev.plex.listener.PlexListener;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -65,7 +64,7 @@ public class CommandListener extends PlexListener
{ {
event.setCancelled(true); event.setCancelled(true);
//PlexLog.debug("Command blocked."); //PlexLog.debug("Command blocked.");
player.sendMessage(MiniMessage.miniMessage().deserialize(PlexUtils.messageString("blockedCommandColor") + blockedCommand.getMessage())); player.sendMessage(PlexUtils.mmDeserialize(PlexUtils.messageString("blockedCommandColor") + blockedCommand.getMessage()));
return; return;
} }
} }

View File

@ -77,7 +77,7 @@ public class PlayerListener extends PlexListener
String loginMessage = plugin.getRankManager().getLoginMessage(plexPlayer); String loginMessage = plugin.getRankManager().getLoginMessage(plexPlayer);
if (!loginMessage.isEmpty()) if (!loginMessage.isEmpty())
{ {
PlexUtils.broadcast(MiniMessage.miniMessage().deserialize("<aqua>" + player.getName() + " is " + loginMessage)); PlexUtils.broadcast(PlexUtils.mmDeserialize("<aqua>" + player.getName() + " is " + loginMessage));
} }
if (plugin.getStorageType() != StorageType.MONGODB) if (plugin.getStorageType() != StorageType.MONGODB)

View File

@ -95,7 +95,7 @@ public class RankManager
{ {
if (!player.getPrefix().equals("")) if (!player.getPrefix().equals(""))
{ {
return MiniMessage.miniMessage().deserialize(player.getPrefix()); return PlexUtils.mmDeserialize(player.getPrefix());
} }
if (Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(player.getName())) if (Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(player.getName()))
{ {

View File

@ -1,5 +1,6 @@
package dev.plex.rank.enums; package dev.plex.rank.enums;
import dev.plex.util.PlexUtils;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@ -47,7 +48,7 @@ public enum Rank
public Component getPrefix() public Component getPrefix()
{ {
return MiniMessage.miniMessage().deserialize(this.prefix); return PlexUtils.mmDeserialize(this.prefix);
} }
public JSONObject toJSON() public JSONObject toJSON()

View File

@ -1,5 +1,6 @@
package dev.plex.rank.enums; package dev.plex.rank.enums;
import dev.plex.util.PlexUtils;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@ -39,7 +40,7 @@ public enum Title
public Component getPrefix() public Component getPrefix()
{ {
return MiniMessage.miniMessage().deserialize(this.prefix); return PlexUtils.mmDeserialize(this.prefix);
} }
public JSONObject toJSON() public JSONObject toJSON()

View File

@ -7,14 +7,23 @@ import dev.plex.PlexBase;
import dev.plex.config.Config; import dev.plex.config.Config;
import dev.plex.storage.StorageType; import dev.plex.storage.StorageType;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.Context;
import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.ParsingException;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.text.minimessage.tag.standard.*;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.PluginCommandYamlParser; import org.bukkit.command.PluginCommandYamlParser;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser; import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
@ -145,9 +154,40 @@ public class PlexUtils extends PlexBase
return ChatColor.translateAlternateColorCodes('&', string); return ChatColor.translateAlternateColorCodes('&', string);
} }
private static final MiniMessage safeMessage = MiniMessage.builder().tags(TagResolver.builder().resolvers(
StandardTags.color(),
StandardTags.decorations(),
StandardTags.gradient(),
StandardTags.rainbow(),
StandardTags.reset()
).build()).build();
private static final MiniMessage eggMessage = MiniMessage.builder().tags(new TagResolver()
{
@Override
public @Nullable Tag resolve(@NotNull String name, @NotNull ArgumentQueue arguments, @NotNull Context ctx) throws ParsingException
{
return StandardTags.rainbow().resolve("rainbow", arguments, ctx);
}
@Override
public boolean has(@NotNull String name)
{
return true;
}
}
).build();
public static Component mmDeserialize(String input)
{
Calendar calendar = Calendar.getInstance();
MiniMessage mm = (calendar.get(Calendar.MONTH) == Calendar.APRIL && calendar.get(Calendar.DAY_OF_MONTH) == 1 && (!plugin.config.contains("april_fools") || plugin.config.getBoolean("april_fools"))) ? eggMessage : safeMessage;
return mm.deserialize(PlainTextComponentSerializer.plainText().serialize(LegacyComponentSerializer.legacySection().deserialize(input)));
}
public static Component messageComponent(String entry, Object... objects) public static Component messageComponent(String entry, Object... objects)
{ {
return MiniMessage.miniMessage().deserialize(messageString(entry, objects)); return mmDeserialize(messageString(entry, objects));
} }
public static String messageString(String entry, Object... objects) public static String messageString(String entry, Object... objects)

View File

@ -147,11 +147,6 @@ public class UpdateChecker extends PlexBase
} }
} }
private void sendMini(CommandSender sender, String message)
{
sender.sendMessage(MiniMessage.miniMessage().deserialize(message));
}
public void updateJar(CommandSender sender) public void updateJar(CommandSender sender)
{ {
CloseableHttpClient client = HttpClients.createDefault(); CloseableHttpClient client = HttpClients.createDefault();
@ -162,7 +157,7 @@ public class UpdateChecker extends PlexBase
JSONObject object = new JSONObject(EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8)); JSONObject object = new JSONObject(EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8));
JSONObject artifact = object.getJSONArray("artifacts").getJSONObject(0); JSONObject artifact = object.getJSONArray("artifacts").getJSONObject(0);
String name = artifact.getString("fileName"); String name = artifact.getString("fileName");
sendMini(sender, "<green>Downloading latest Plex jar file: " + name); sender.sendMessage(PlexUtils.mmDeserialize("<green>Downloading latest Plex jar file: " + name));
CompletableFuture.runAsync(() -> CompletableFuture.runAsync(() ->
{ {
try try
@ -171,7 +166,7 @@ public class UpdateChecker extends PlexBase
new URL(DOWNLOAD_PAGE + "job/" + branch + "/lastSuccessfulBuild/artifact/build/libs/" + name), new URL(DOWNLOAD_PAGE + "job/" + branch + "/lastSuccessfulBuild/artifact/build/libs/" + name),
new File(Bukkit.getUpdateFolderFile(), name) new File(Bukkit.getUpdateFolderFile(), name)
); );
sendMini(sender, "<green>Saved new jar. Please restart your server."); sender.sendMessage(PlexUtils.mmDeserialize("<green>Saved new jar. Please restart your server."));
} }
catch (IOException e) catch (IOException e)
{ {