fix /tag
This commit is contained in:
Taah 2022-04-09 22:10:35 -07:00
parent f274e20f84
commit 6086f761eb
11 changed files with 83 additions and 26 deletions

View File

@ -23,19 +23,7 @@ public class CommandBlockerManager extends PlexBase
private static CommandMap getCommandMap()
{
try
{
SimplePluginManager spm = (SimplePluginManager) Bukkit.getServer().getPluginManager();
Field cmf = SimplePluginManager.class.getDeclaredField("commandMap");
cmf.setAccessible(true);
return (SimpleCommandMap)cmf.get(spm);
}
catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e)
{
PlexLog.error("Unable to get command map for command blocker.");
e.printStackTrace();
}
return null;
return plugin.getServer().getCommandMap();
}
public void syncCommands()

View File

@ -8,12 +8,15 @@ import dev.plex.command.annotation.System;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@ -59,6 +62,16 @@ public class DebugCMD extends PlexCommand
}
return mmString("<aqua>Re-applied game all the game rules!");
}
if (args[0].equalsIgnoreCase("aliases"))
{
String commandName = args[1];
Command command = plugin.getServer().getCommandMap().getCommand(commandName);
if (command == null)
{
return mmString("<red>That command could not be found!");
}
return mmString("<aqua>Aliases for " + commandName + " are: " + Arrays.toString(command.getAliases().toArray(new String[0])));
}
return null;
}

View File

@ -14,7 +14,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.SENIOR_ADMIN, permission = "plex.rawsay", source = RequiredCommandSource.ANY)
@CommandParameters(name = "rawsay", usage = "/<command> <message>", description = "Displays a message to everyone")
@CommandParameters(name = "rawsay", usage = "/<command> <message>", description = "Displays a raw message to everyone")
public class RawSayCMD extends PlexCommand
{
@Override

View File

@ -0,0 +1,31 @@
package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component;
import org.apache.commons.lang.StringUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.ADMIN, permission = "plex.say", source = RequiredCommandSource.ANY)
@CommandParameters(name = "say", usage = "/<command> <message>", description = "Displays a message to everyone")
public class SayCMD extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length == 0)
{
return usage();
}
PlexUtils.broadcast(PlexUtils.messageComponent("sayCommand", sender.getName(), StringUtils.join(args, " ")));
return null;
}
}

View File

@ -10,6 +10,8 @@ import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.apache.commons.lang.StringUtils;
@ -48,15 +50,15 @@ public class TagCMD extends PlexCommand
return usage("/tag set <prefix>");
}
String prefix = StringUtils.join(args, " ", 1, args.length);
Component convertedComponent = removeEvents(noColorComponentFromString(prefix));
convertedComponent = removeEvents(PlexUtils.mmDeserialize(LegacyComponentSerializer.legacySection().serialize(convertedComponent)));
Component convertedComponent = removeEvents(PlexUtils.mmCustomDeserialize(prefix = prefix.replace("<newline>", "").replace("<br>", ""), StandardTags.color(), StandardTags.rainbow(), StandardTags.decorations(), StandardTags.gradient(), StandardTags.transition())); //noColorComponentFromString(prefix)
if (PlainTextComponentSerializer.plainText().serialize(convertedComponent).length() > plugin.config.getInt("chat.max-tag-length", 16))
{
return messageComponent("maximumPrefixLength", plugin.config.getInt("chat.max-tag-length", 16));
}
player.setPrefix(MiniMessage.miniMessage().serialize(convertedComponent));
player.setPrefix(prefix);
DataUtils.update(player);
return messageComponent("prefixSetTo", MiniMessage.miniMessage().serialize(convertedComponent));
}

View File

@ -9,7 +9,10 @@ import io.papermc.paper.event.player.AsyncChatEvent;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.apache.commons.lang.StringUtils;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.jetbrains.annotations.NotNull;
@ -51,14 +54,14 @@ public class ChatListener extends PlexListener
return Component.empty()
.append(prefix)
.append(Component.space())
.append(LegacyComponentSerializer.legacyAmpersand().deserialize("&" + plugin.config.getString("chat.name-color") + LegacyComponentSerializer.legacyAmpersand().serialize(sourceDisplayName)))
.append(MiniMessage.miniMessage().deserialize(plugin.config.getString("chat.name-color", "<white>"))).append(sourceDisplayName)
.append(Component.space())
.append(Component.text("»").color(NamedTextColor.GRAY))
.append(Component.space())
.append(message);
}
return Component.empty()
.append(LegacyComponentSerializer.legacyAmpersand().deserialize("&" + plugin.config.getString("chat.name-color") + LegacyComponentSerializer.legacyAmpersand().serialize(sourceDisplayName)))
.append(MiniMessage.miniMessage().deserialize(plugin.config.getString("chat.name-color", "<white>"))).append(sourceDisplayName)
.append(Component.space())
.append(Component.text("»").color(NamedTextColor.GRAY))
.append(Component.space())

View File

@ -1,6 +1,7 @@
package dev.plex.listener.impl;
import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
import com.destroystokyo.paper.event.server.ServerTickEndEvent;
import dev.plex.listener.PlexListener;
import dev.plex.util.PlexUtils;
import java.util.List;
@ -8,6 +9,7 @@ import java.util.stream.Collectors;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerKickEvent;
public class ServerListener extends PlexListener
{

View File

@ -15,6 +15,7 @@ import lombok.SneakyThrows;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;
@ -95,7 +96,7 @@ public class RankManager
{
if (!player.getPrefix().equals(""))
{
return PlexUtils.mmDeserialize(player.getPrefix());
return PlexUtils.mmCustomDeserialize(player.getPrefix(), StandardTags.color(), StandardTags.rainbow(), StandardTags.decorations(), StandardTags.gradient(), StandardTags.transition());
}
if (Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(player.getName()))
{

View File

@ -37,6 +37,7 @@ import java.sql.Connection;
import java.sql.SQLException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.ZoneId;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
@ -180,14 +181,27 @@ public class PlexUtils extends PlexBase
public static Component mmDeserialize(String input)
{
Calendar calendar = Calendar.getInstance();
/*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)));
return mm.deserialize(PlainTextComponentSerializer.plainText().serialize(LegacyComponentSerializer.legacySection().deserialize(input)));*/
boolean aprilFools = plugin.config.getBoolean("april_fools");
LocalDateTime date = LocalDateTime.now();
if (aprilFools && date.getMonth() == Month.APRIL && date.getDayOfMonth() == 1)
{
Component component = PlainTextComponentSerializer.plainText().deserialize(input);
return MiniMessage.miniMessage().deserialize("<rainbow>" + PlainTextComponentSerializer.plainText().serialize(component));
}
return MiniMessage.miniMessage().deserialize(input);
}
public static Component mmCustomDeserialize(String input, TagResolver... resolvers)
{
return MiniMessage.builder().tags(TagResolver.builder().resolvers(resolvers).build()).build().deserialize(input);
}
public static Component messageComponent(String entry, Object... objects)
{
return mmDeserialize(messageString(entry, objects));
return MiniMessage.miniMessage().deserialize(messageString(entry, objects));
}
public static String messageString(String entry, Object... objects)

View File

@ -24,8 +24,8 @@ chat:
# The maximum amount of characters a player can have for their tag
# This does not include color tags such as <red> or <rainbow>
max-tag-length: 64
# Color code for name color
name-color: 'f'
# Color tag for name color
name-color: '<white>'
# Should Plex use a "true op" system with ranks or only permission nodes
# Options are "permissions" or "ranks"

View File

@ -168,4 +168,7 @@ autoWipeDisabled: "<gray>Item wiping is currently disabled in the config!"
allowDropsDisabled: "<gray>No longer allowing drops from players."
allowDropsEnabled: "<gray>Now allowing drops from players."
blockedCommandColor: "<gray>"
commandBlocked: "That command is blocked."
commandBlocked: "That command is blocked."
# 0 - The command sender
# 1 - The message being said
sayCommand: "[Server: {0}] {1}"