mirror of
https://github.com/plexusorg/Module-NickMiniMessage.git
synced 2026-06-04 09:16:55 +00:00
Update for Plex 2.0
This commit is contained in:
@@ -2,18 +2,22 @@ package dev.plex.module.nickmm.command;
|
||||
|
||||
import com.earth2me.essentials.I18n;
|
||||
import com.earth2me.essentials.User;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.SimplePlexCommand;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.module.nickmm.NickMiniMessageModule;
|
||||
import dev.plex.util.minimessage.SafeMiniMessage;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.Context;
|
||||
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.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -22,12 +26,22 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandParameters(name = "nickmm", description = "Change your nickname using MiniMessage formatting!", usage = "/<command> <nick>", aliases = "nickminimessage")
|
||||
@CommandPermissions(permission = "plex.nickmm", source = RequiredCommandSource.IN_GAME)
|
||||
public class NickMMCommand extends PlexCommand
|
||||
public class NickMMCommand extends SimplePlexCommand
|
||||
{
|
||||
private final PlainTextComponentSerializer plainText = PlainTextComponentSerializer.plainText();
|
||||
private final LegacyComponentSerializer legacyComponent = LegacyComponentSerializer.legacySection();
|
||||
private final MiniMessage miniMessage = MiniMessage.builder().tags(new NicknameTagResolver()).build();
|
||||
|
||||
public NickMMCommand()
|
||||
{
|
||||
super(command("nickmm")
|
||||
.description("Change your nickname using MiniMessage formatting!")
|
||||
.usage("/<command> <nick>")
|
||||
.aliases("nickminimessage")
|
||||
.permission("plex.nickmm")
|
||||
.source(RequiredCommandSource.IN_GAME)
|
||||
.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args)
|
||||
@@ -42,7 +56,7 @@ public class NickMMCommand extends PlexCommand
|
||||
return usage();
|
||||
}
|
||||
|
||||
final Component nick = SafeMiniMessage.mmDeserializeWithoutEvents(args[0]);
|
||||
final Component nick = miniMessage.deserialize(args[0]).clickEvent(null).hoverEvent(null);
|
||||
final String plain = plainText.serialize(nick);
|
||||
|
||||
if (plain.length() > NickMiniMessageModule.getEssentials().getSettings().getMaxNickLength()
|
||||
@@ -65,14 +79,45 @@ public class NickMMCommand extends PlexCommand
|
||||
}
|
||||
|
||||
final String legacy = legacyComponent.serialize(nick);
|
||||
NickMiniMessageModule.getEssentials().getUser(player).setNickname(legacy);
|
||||
User essentialsUser = NickMiniMessageModule.getEssentials().getUser(player);
|
||||
essentialsUser.setNickname(legacy);
|
||||
essentialsUser.setDisplayNick();
|
||||
|
||||
return mmString(I18n.tlLiteral("nickSet", legacy));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
protected @NotNull List<String> suggestions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args)
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private static class NicknameTagResolver implements TagResolver
|
||||
{
|
||||
private static final TagResolver STANDARD_RESOLVER = TagResolver.standard();
|
||||
private static final List<String> IGNORED_TAGS = Arrays.asList(
|
||||
"click",
|
||||
"hover",
|
||||
"insertion",
|
||||
"insert",
|
||||
"obfuscated",
|
||||
"obf",
|
||||
"br",
|
||||
"newline",
|
||||
"lang",
|
||||
"key",
|
||||
"translate");
|
||||
|
||||
@Override
|
||||
public @Nullable Tag resolve(@NotNull String name, @NotNull ArgumentQueue arguments, @NotNull Context ctx) throws ParsingException
|
||||
{
|
||||
return IGNORED_TAGS.contains(name.toLowerCase()) ? null : STANDARD_RESOLVER.resolve(name, arguments, ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(@NotNull String name)
|
||||
{
|
||||
return STANDARD_RESOLVER.has(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
name: Module-NickMiniMessage
|
||||
main: dev.plex.module.nickmm.NickMiniMessageModule
|
||||
description: Module for Plex that adds a command allowing for Essentials nicknames to be created with MiniMessage
|
||||
version: 1.6
|
||||
version: 2.0-SNAPSHOT
|
||||
apiCompatibility: 1
|
||||
|
||||
Reference in New Issue
Block a user