mirror of
https://github.com/plexusorg/Module-NickMiniMessage.git
synced 2024-12-22 01:07:38 +00:00
This was a PITA
This commit is contained in:
parent
d5b4da89ab
commit
83a76e380d
3
.gitignore
vendored
3
.gitignore
vendored
@ -13,3 +13,6 @@ Thumbs.db
|
||||
# Gradle
|
||||
/build/
|
||||
/.gradle/
|
||||
|
||||
# Libraries
|
||||
/libs/
|
||||
|
@ -20,11 +20,12 @@ dependencies {
|
||||
annotationProcessor("org.projectlombok:lombok:1.18.28")
|
||||
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
|
||||
compileOnly("dev.plex:server:1.3")
|
||||
compileOnly(files("libs/EssentialsX.jar"))
|
||||
}
|
||||
|
||||
group = "dev.plex"
|
||||
group = "me.videogamesm12"
|
||||
version = "1.0"
|
||||
description = "ExampleModule"
|
||||
description = "Module-NickMiniMessage"
|
||||
|
||||
java {
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
||||
@ -39,7 +40,7 @@ publishing {
|
||||
}
|
||||
|
||||
tasks.getByName<Jar>("jar") {
|
||||
archiveBaseName.set("Plex-ExampleModule")
|
||||
archiveBaseName.set("Module-NickMiniMessage")
|
||||
archiveVersion.set("")
|
||||
}
|
||||
|
||||
|
@ -1 +1 @@
|
||||
rootProject.name = "plexmodule-template"
|
||||
rootProject.name = "Module-NickMiniMessage"
|
||||
|
@ -1,21 +0,0 @@
|
||||
package dev.plex;
|
||||
|
||||
import dev.plex.command.ExampleCommand;
|
||||
import dev.plex.listener.ExampleListener;
|
||||
import dev.plex.module.PlexModule;
|
||||
|
||||
public class ExampleModule extends PlexModule
|
||||
{
|
||||
@Override
|
||||
public void enable()
|
||||
{
|
||||
registerCommand(new ExampleCommand());
|
||||
registerListener(new ExampleListener());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable()
|
||||
{
|
||||
// Unregistering listeners / commands is handled by Plex
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package dev.plex.command;
|
||||
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandParameters(name = "examplemodule", description = "An example command provided by Plex's example module")
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.module.command")
|
||||
public class ExampleCommand extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] strings)
|
||||
{
|
||||
return Component.text("Example module command");
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package dev.plex.listener;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class ExampleListener extends PlexListener
|
||||
{
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
player.sendMessage(Component.text("This is a message from Plex's example module!").color(NamedTextColor.GOLD));
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package me.videogamesm12.nickmm;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import dev.plex.module.PlexModule;
|
||||
import me.videogamesm12.nickmm.command.NickMMCommand;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class NickMiniMessageModule extends PlexModule
|
||||
{
|
||||
@Override
|
||||
public void enable()
|
||||
{
|
||||
if (!Bukkit.getPluginManager().isPluginEnabled("Essentials"))
|
||||
{
|
||||
throw new IllegalStateException("We need Essentials for this module to work!");
|
||||
}
|
||||
|
||||
registerCommand(new NickMMCommand());
|
||||
}
|
||||
|
||||
public static Essentials getEssentials()
|
||||
{
|
||||
return (Essentials) Bukkit.getPluginManager().getPlugin("Essentials");
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package me.videogamesm12.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.source.RequiredCommandSource;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.minimessage.SafeMiniMessage;
|
||||
import me.videogamesm12.nickmm.NickMiniMessageModule;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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
|
||||
{
|
||||
private final PlainTextComponentSerializer plainText = PlainTextComponentSerializer.plainText();
|
||||
private final LegacyComponentSerializer legacyComponent = LegacyComponentSerializer.legacySection();
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] strings)
|
||||
{
|
||||
if (!Bukkit.getPluginManager().isPluginEnabled("Essentials"))
|
||||
{
|
||||
return Component.text("Essentials is not enabled!", NamedTextColor.RED);
|
||||
}
|
||||
|
||||
if (strings.length == 0)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
|
||||
final Component nick = SafeMiniMessage.mmDeserializeWithoutEvents(strings[0]);
|
||||
final String plain = plainText.serialize(nick);
|
||||
|
||||
if (plain.length() > NickMiniMessageModule.getEssentials().getSettings().getMaxNickLength()
|
||||
&& !commandSender.hasPermission("plex.nickmm.ignore_length_limit"))
|
||||
{
|
||||
return legacyComponent.deserialize(I18n.tl("nickTooLong"));
|
||||
}
|
||||
|
||||
if (!commandSender.hasPermission("plex.nickmm.ignore_matching"))
|
||||
{
|
||||
for (final User user : NickMiniMessageModule.getEssentials().getOnlineUsers())
|
||||
{
|
||||
final String name = user.getNickname() != null ? plainText.serialize(legacyComponent.deserialize(user.getNickname())) : user.getName();
|
||||
|
||||
if (name.equalsIgnoreCase(plain) && !user.getUUID().equals(player.getUniqueId()))
|
||||
{
|
||||
return legacyComponent.deserialize(I18n.tl("nickInUse"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final String legacy = legacyComponent.serialize(nick);
|
||||
NickMiniMessageModule.getEssentials().getUser(player).setNickname(legacy);
|
||||
|
||||
return legacyComponent.deserialize(I18n.tl("nickSet", legacy));
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
name: Module-Example
|
||||
main: dev.plex.ExampleModule
|
||||
description: An example module for Plex
|
||||
name: Module-NickMiniMessage
|
||||
main: me.videogamesm12.nickmm.NickMiniMessageModule
|
||||
description: Module for Plex that adds a command allowing for Essentials nicknames to be created with MiniMessage
|
||||
version: 1.0
|
Loading…
Reference in New Issue
Block a user