From b3db5197cc0fc357d6afe150a1fdb2f40b318db4 Mon Sep 17 00:00:00 2001 From: JiveOff Date: Sat, 14 Sep 2024 01:59:47 +0200 Subject: [PATCH] chore: refactor commands --- build.gradle | 11 +- .../java/fr/efreicraft/ecatup/ECATUP.java | 202 +++------ .../fr/efreicraft/ecatup/commands/Chat.java | 95 ----- .../ecatup/commands/FlyCommand.java | 47 +++ .../ecatup/commands/GameModeCommand.java | 74 ++++ .../efreicraft/ecatup/commands/HasPerm.java | 96 ----- .../ecatup/commands/HasPermCommand.java | 33 ++ .../ecatup/commands/RideCommand.java | 29 ++ .../fr/efreicraft/ecatup/commands/Skull.java | 44 -- .../ecatup/commands/SkullCommand.java | 44 ++ .../fr/efreicraft/ecatup/commands/Slap.java | 83 ---- .../ecatup/commands/SlapCommand.java | 35 ++ .../ecatup/commands/SpeedCommand.java | 60 +++ .../fr/efreicraft/ecatup/commands/Sudo.java | 39 -- .../ecatup/commands/SudoCommand.java | 25 ++ .../fr/efreicraft/ecatup/commands/WhoIs.java | 84 ---- .../commands/arguments/GameModeArgument.java | 43 ++ .../commands/exceptions/CommandException.java | 12 + .../ecatup/commands/gamemode/Gm.java | 60 --- .../ecatup/commands/gamemode/Gma.java | 37 -- .../ecatup/commands/gamemode/Gmc.java | 37 -- .../ecatup/commands/gamemode/Gms.java | 37 -- .../ecatup/commands/gamemode/Gmsp.java | 37 -- .../commands/handlers/InvalidUsage.java | 27 ++ .../commands/handlers/PermissionHandler.java | 25 ++ .../ecatup/commands/permissions/Common.java | 103 ----- .../commands/permissions/GroupsCom.java | 244 ----------- .../commands/permissions/PlayersCom.java | 113 ----- .../ecatup/commands/speeds/FlySpeed.java | 108 ----- .../ecatup/commands/speeds/ResetSpeed.java | 54 --- .../ecatup/commands/speeds/WalkSpeed.java | 108 ----- .../commands/validator/NotTheSamePlayer.java | 11 + .../validator/NotTheSamePlayerValidator.java | 28 ++ .../ecatup/commands/validator/Speed.java | 11 + .../commands/validator/SpeedValidator.java | 27 ++ .../ecatup/listeners/ChatListener.java | 114 +---- .../efreicraft/ecatup/players/ECPlayer.java | 5 + .../ecatup/utils/DiscordWebhook.java | 396 ------------------ .../efreicraft/ecatup/utils/MessageUtils.java | 33 ++ .../java/fr/efreicraft/ecatup/utils/Msg.java | 18 - src/main/resources/plugin.yml | 124 +----- 41 files changed, 649 insertions(+), 2164 deletions(-) delete mode 100644 src/main/java/fr/efreicraft/ecatup/commands/Chat.java create mode 100644 src/main/java/fr/efreicraft/ecatup/commands/FlyCommand.java create mode 100644 src/main/java/fr/efreicraft/ecatup/commands/GameModeCommand.java delete mode 100644 src/main/java/fr/efreicraft/ecatup/commands/HasPerm.java create mode 100644 src/main/java/fr/efreicraft/ecatup/commands/HasPermCommand.java create mode 100644 src/main/java/fr/efreicraft/ecatup/commands/RideCommand.java delete mode 100644 src/main/java/fr/efreicraft/ecatup/commands/Skull.java create mode 100644 src/main/java/fr/efreicraft/ecatup/commands/SkullCommand.java delete mode 100644 src/main/java/fr/efreicraft/ecatup/commands/Slap.java create mode 100644 src/main/java/fr/efreicraft/ecatup/commands/SlapCommand.java create mode 100644 src/main/java/fr/efreicraft/ecatup/commands/SpeedCommand.java delete mode 100644 src/main/java/fr/efreicraft/ecatup/commands/Sudo.java create mode 100644 src/main/java/fr/efreicraft/ecatup/commands/SudoCommand.java delete mode 100644 src/main/java/fr/efreicraft/ecatup/commands/WhoIs.java create mode 100644 src/main/java/fr/efreicraft/ecatup/commands/arguments/GameModeArgument.java create mode 100644 src/main/java/fr/efreicraft/ecatup/commands/exceptions/CommandException.java delete mode 100644 src/main/java/fr/efreicraft/ecatup/commands/gamemode/Gm.java delete mode 100644 src/main/java/fr/efreicraft/ecatup/commands/gamemode/Gma.java delete mode 100644 src/main/java/fr/efreicraft/ecatup/commands/gamemode/Gmc.java delete mode 100644 src/main/java/fr/efreicraft/ecatup/commands/gamemode/Gms.java delete mode 100644 src/main/java/fr/efreicraft/ecatup/commands/gamemode/Gmsp.java create mode 100644 src/main/java/fr/efreicraft/ecatup/commands/handlers/InvalidUsage.java create mode 100644 src/main/java/fr/efreicraft/ecatup/commands/handlers/PermissionHandler.java delete mode 100644 src/main/java/fr/efreicraft/ecatup/commands/permissions/Common.java delete mode 100644 src/main/java/fr/efreicraft/ecatup/commands/permissions/GroupsCom.java delete mode 100644 src/main/java/fr/efreicraft/ecatup/commands/permissions/PlayersCom.java delete mode 100644 src/main/java/fr/efreicraft/ecatup/commands/speeds/FlySpeed.java delete mode 100644 src/main/java/fr/efreicraft/ecatup/commands/speeds/ResetSpeed.java delete mode 100644 src/main/java/fr/efreicraft/ecatup/commands/speeds/WalkSpeed.java create mode 100644 src/main/java/fr/efreicraft/ecatup/commands/validator/NotTheSamePlayer.java create mode 100644 src/main/java/fr/efreicraft/ecatup/commands/validator/NotTheSamePlayerValidator.java create mode 100644 src/main/java/fr/efreicraft/ecatup/commands/validator/Speed.java create mode 100644 src/main/java/fr/efreicraft/ecatup/commands/validator/SpeedValidator.java delete mode 100644 src/main/java/fr/efreicraft/ecatup/utils/DiscordWebhook.java delete mode 100644 src/main/java/fr/efreicraft/ecatup/utils/Msg.java diff --git a/build.gradle b/build.gradle index dc07ba7..bb44939 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group = 'fr.efreicraft' -version = '1.2.1' +version = '1.3' compileJava.options.encoding "UTF-8" @@ -19,6 +19,9 @@ repositories { name = 'sonatype' url = 'https://oss.sonatype.org/content/groups/public/' } + maven { + url = 'https://repo.panda-lang.org/releases' + } maven { url "https://repo.dmulloy2.net/repository/public/" } if (System.getenv("NEXUS_REPOSITORY")) { println "Using Nexus repository" @@ -37,9 +40,14 @@ dependencies { compileOnly 'io.papermc.paper:paper-api:1.19.3-R0.1-SNAPSHOT' compileOnly "fr.efreicraft:AnimusClient:latest.integration" + + implementation "net.kyori:adventure-text-minimessage:4.15.0" + implementation "dev.rollczi:litecommands-bukkit:3.4.1" } jar { + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } } @@ -61,6 +69,7 @@ tasks.withType(JavaCompile).configureEach { if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) { options.release = targetJavaVersion } + options.compilerArgs.add("-parameters") } processResources { diff --git a/src/main/java/fr/efreicraft/ecatup/ECATUP.java b/src/main/java/fr/efreicraft/ecatup/ECATUP.java index 946bed9..4d2051d 100644 --- a/src/main/java/fr/efreicraft/ecatup/ECATUP.java +++ b/src/main/java/fr/efreicraft/ecatup/ECATUP.java @@ -1,39 +1,34 @@ package fr.efreicraft.ecatup; -import com.google.common.io.ByteArrayDataOutput; -import com.google.common.io.ByteStreams; +import dev.rollczi.litecommands.LiteCommands; +import dev.rollczi.litecommands.bukkit.LiteBukkitFactory; +import dev.rollczi.litecommands.schematic.SchematicFormat; +import fr.efreicraft.animus.invoker.ApiException; import fr.efreicraft.ecatup.commands.*; -import fr.efreicraft.ecatup.commands.gamemode.*; -import fr.efreicraft.ecatup.commands.permissions.GroupsCom; -import fr.efreicraft.ecatup.commands.permissions.PlayersCom; -import fr.efreicraft.ecatup.commands.speeds.FlySpeed; -import fr.efreicraft.ecatup.commands.speeds.ResetSpeed; -import fr.efreicraft.ecatup.commands.speeds.WalkSpeed; +import fr.efreicraft.ecatup.commands.arguments.GameModeArgument; +import fr.efreicraft.ecatup.commands.exceptions.CommandException; +import fr.efreicraft.ecatup.commands.handlers.InvalidUsage; +import fr.efreicraft.ecatup.commands.handlers.PermissionHandler; +import fr.efreicraft.ecatup.commands.validator.NotTheSamePlayer; +import fr.efreicraft.ecatup.commands.validator.NotTheSamePlayerValidator; +import fr.efreicraft.ecatup.commands.validator.Speed; +import fr.efreicraft.ecatup.commands.validator.SpeedValidator; import fr.efreicraft.ecatup.groups.GroupManager; import fr.efreicraft.ecatup.listeners.ChatListener; import fr.efreicraft.ecatup.listeners.JoinListener; import fr.efreicraft.ecatup.listeners.LeaveListener; import fr.efreicraft.ecatup.players.PlayerManager; import fr.efreicraft.ecatup.players.menus.MenuListener; -import fr.efreicraft.ecatup.utils.DiscordWebhook; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; +import fr.efreicraft.ecatup.utils.MessageUtils; import org.bukkit.Bukkit; -import org.bukkit.command.CommandExecutor; +import org.bukkit.GameMode; +import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; -import org.bukkit.permissions.Permission; import org.bukkit.plugin.java.JavaPlugin; -import javax.annotation.Nullable; import java.awt.*; -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; @SuppressWarnings("UnstableApiUsage") public final class ECATUP extends JavaPlugin { @@ -46,6 +41,8 @@ public final class ECATUP extends JavaPlugin { private GroupManager groupManager; + private LiteCommands liteCommands; + @Override public void onEnable() { @@ -57,52 +54,63 @@ public void onEnable() { config.options().copyDefaults(true); // au cas où le fichier existe, mais est incomplet. INSTANCE.saveConfig(); - // Register BungeeCord channel - getServer().getMessenger().registerOutgoingPluginChannel(INSTANCE, "BungeeCord"); - getServer().getMessenger().registerIncomingPluginChannel(INSTANCE, "BungeeCord", new ChatListener()); - // Register events Bukkit.getPluginManager().registerEvents(new ChatListener(), INSTANCE); Bukkit.getPluginManager().registerEvents(new JoinListener(), INSTANCE); Bukkit.getPluginManager().registerEvents(new LeaveListener(), INSTANCE); - registerCommand("chat", new fr.efreicraft.ecatup.commands.Chat()); - for (PreferenceCache.ChatChannel channel : PreferenceCache.ChatChannel.values()) { - Bukkit.getPluginManager().addPermission(new Permission("ecatup.channel." + channel.toString().toLowerCase())); - } - - registerCommand("flyspeed", new FlySpeed()); - registerCommand("gm", new Gm()); - registerCommand("gms", new Gms()); - registerCommand("gma", new Gma()); - registerCommand("gmc", new Gmc()); - registerCommand("gmsp", new Gmsp()); - registerCommand("resetspeed", new ResetSpeed()); - registerCommand("skull", new Skull()); - registerCommand("slap", new Slap()); - registerCommand("sudo", new Sudo()); - registerCommand("walkspeed", new WalkSpeed()); - registerCommand("whois", new WhoIs()); - - registerCommand("groupperms", new GroupsCom()); - registerCommand("playerperms", new PlayersCom()); - - registerCommand("hasperm", new HasPerm()); - - // Send log to Discord - DiscordWebhook webhook = new DiscordWebhook(config.getString("webhook")); - webhook.addEmbed(new DiscordWebhook.EmbedObject() - .setTitle("Serveur") - .setDescription("Le serveur a démarré !") - .setColor(Color.white) - .setFooter("Efrei Craft", "https://efreicraft.fr/img/favicon.png") - ); - try { - webhook.execute(); - } catch (IOException ignored) {} + this.liteCommands = LiteBukkitFactory.builder() + .settings(settings -> settings + .fallbackPrefix("ECATUP") + .nativePermissions(false) + ) + + .argument(GameMode.class, new GameModeArgument()) + + .annotations(configuration -> configuration + .validator(Player.class, NotTheSamePlayer.class, new NotTheSamePlayerValidator()) + .validator(Float.class, Speed.class, new SpeedValidator()) + ) + + .commands( + new GameModeCommand(), + new SpeedCommand(), + new FlyCommand(), + new HasPermCommand(), + new SkullCommand(), + new SlapCommand(), + new RideCommand(), + new SudoCommand() + ) + + .exception(ApiException.class, (invocation, exception, chain) -> { + if (invocation.sender() instanceof Player) { + MessageUtils.sendMessage( + invocation.sender(), + MessageUtils.ChatPrefix.PLUGIN, + "&cErreur API: &7%s".formatted(exception.getMessage()) + ); + } + }) + + .exception(CommandException.class, (invocation, exception, chain) -> { + if (invocation.sender() instanceof Player) { + MessageUtils.sendMessage( + invocation.sender(), + MessageUtils.ChatPrefix.COMMAND, + "&cErreur: &7%s".formatted(exception.getMessage()) + ); + } + }) + + .missingPermission(new PermissionHandler()) + .invalidUsage(new InvalidUsage()) + + .schematicGenerator(SchematicFormat.angleBrackets()) + + .build(); playerManager = new PlayerManager(); - groupManager = new GroupManager(); Bukkit.getPluginManager().registerEvents(new MenuListener(), INSTANCE); @@ -111,82 +119,6 @@ public void onEnable() { @Override public void onDisable() { // Plugin shutdown logic - - // Unregister BungeeCord channel - getServer().getMessenger().unregisterOutgoingPluginChannel(INSTANCE); - getServer().getMessenger().unregisterIncomingPluginChannel(INSTANCE); - - if (!config.getString("server_name", "").equalsIgnoreCase("lobby")) - for (Player player : Bukkit.getOnlinePlayers()) { - sendPlayerToServer(player, "lobby"); - } - - try { - // Send log to Discord - DiscordWebhook webhook = new DiscordWebhook(config.getString("webhook")); - webhook.addEmbed(new DiscordWebhook.EmbedObject() - .setTitle("Serveur") - .setDescription("Le serveur s'est arrêté !") - .setColor(java.awt.Color.decode("#ffffff")) - .setFooter("Efrei Craft", "https://efreicraft.fr/img/favicon.png") - ); -// webhook.execute(); - } catch (Throwable ignored) {} - } - - void registerCommand(String command, CommandExecutor executor) { - Objects.requireNonNull(Bukkit.getPluginCommand(command)).setExecutor(executor); - } - - public static List getPlayersForTabList(String[] args, int argPos) { - List players = Bukkit.getOnlinePlayers().stream().filter(player -> player.getName().toLowerCase().startsWith(args[argPos].toLowerCase())).collect(Collectors.toList()); - List results = new ArrayList<>(); - players.forEach(player -> results.add(player.getName())); - return results.isEmpty() ? null : results; - } - - public static void sendPlayerToServer(Player player, String server) { - if (!player.hasPermission("server." + server.toLowerCase())) { - Component nope = Component.text("Vous ne pouvez pas aller sur ce serveur !").color(NamedTextColor.RED); - player.sendMessage(nope); - INSTANCE.getLogger().info(player.getName() + " tried to join " + server + " but doesn't have permission to do so."); - return; - } - - ByteArrayDataOutput out = ByteStreams.newDataOutput(); - out.writeUTF("Connect"); - out.writeUTF(server); - player.sendPluginMessage(INSTANCE, "BungeeCord", out.toByteArray()); - } - - public static void sendGlobalChat(String msg, @Nullable Player player) { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); - - out.writeUTF("Forward"); - out.writeUTF("ONLINE"); - out.writeUTF("ecatup:globalchat"); - - ByteArrayOutputStream msgbytes = new ByteArrayOutputStream(); - DataOutputStream msgout = new DataOutputStream(msgbytes); - - try { - msgout.writeUTF(msg); - } catch (IOException e) { - e.printStackTrace(); - - INSTANCE.getLogger().severe("Couldn't send " + - (player == null ? "a player's" : (player.getName() + "'s")) + - " global message: " + msg); - if (player != null) { - Component failed = Component.text("Votre dernier message n'a pas été envoyé aux autres serveurs.").color(NamedTextColor.DARK_RED); - player.sendMessage(failed); - } - } - - out.writeShort(msgbytes.toByteArray().length); - out.write(msgbytes.toByteArray()); - - Bukkit.getServer().sendPluginMessage(INSTANCE, "BungeeCord", out.toByteArray()); } public static ECATUP getInstance() { diff --git a/src/main/java/fr/efreicraft/ecatup/commands/Chat.java b/src/main/java/fr/efreicraft/ecatup/commands/Chat.java deleted file mode 100644 index b0e9137..0000000 --- a/src/main/java/fr/efreicraft/ecatup/commands/Chat.java +++ /dev/null @@ -1,95 +0,0 @@ -package fr.efreicraft.ecatup.commands; - -import fr.efreicraft.animus.endpoints.PlayerService; -import fr.efreicraft.animus.invoker.ApiException; -import fr.efreicraft.animus.models.UuidChannelBody; -import fr.efreicraft.ecatup.PreferenceCache; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabExecutor; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -import static fr.efreicraft.ecatup.utils.Msg.colorize; - -@SuppressWarnings("ConstantConditions") -public class Chat implements CommandExecutor, TabExecutor { - - @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if (!(sender instanceof Player self)) { - sender.sendMessage(colorize("&cVous devez être un joueur pour exécuter cette commande !")); - return true; - } - - PreferenceCache.ChatChannel channelActuel = (PreferenceCache.ChatChannel) PreferenceCache.getPrefs(self).get(0); - if (args.length == 0) { - sender.sendMessage(colorize("&bVotre canal actuel est: &r&l" + channelActuel)); - return true; - } - - if (channelActuel.toString().equals(args[0].toUpperCase())) { - sender.sendMessage(colorize("&cVous êtes déjà sur le canal &r&l" + channelActuel)); - return true; - } - - boolean canUseGlobal = self.hasPermission("ecatup.channel.global"); - - if (args[0].equalsIgnoreCase("help") || args.length > 1) { - sender.sendMessage(colorize("&c&lUsage: &r&c/chat [" + (canUseGlobal ? "g|global OR " : "") + "s|server|normal OR t|team OR p|party]")); - return true; - } - - switch (args[0].toLowerCase()) { - case "g","global" -> { - if (canUseGlobal) { - sendChannelPrefToDB(self, PreferenceCache.ChatChannel.GLOBAL); - PreferenceCache.setPref(self, 0, PreferenceCache.ChatChannel.GLOBAL); - sender.sendMessage(colorize("&aVous basculez sur le canal &e[GLOBAL]")); - } else sender.sendMessage(colorize("&c&lUsage: &r&c/chat [s|server|normal OR t|team]")); - } - case "s","server","normal" -> { - sendChannelPrefToDB(self, PreferenceCache.ChatChannel.SERVER); - PreferenceCache.setPref(self, 0, PreferenceCache.ChatChannel.SERVER); - sender.sendMessage(colorize("&aVous basculez sur le canal &e[SERVER]")); - } - case "t","team" -> { - sendChannelPrefToDB(self, PreferenceCache.ChatChannel.TEAM); - PreferenceCache.setPref(self, 0, PreferenceCache.ChatChannel.TEAM); - sender.sendMessage(colorize("&aVous basculez sur le canal &e[TEAM]")); - } - case "p","party" -> { - sendChannelPrefToDB(self, PreferenceCache.ChatChannel.PARTY); - PreferenceCache.setPref(self, 0, PreferenceCache.ChatChannel.PARTY); - sender.sendMessage(colorize("&aVous basculez sur le canal &e[PARTY]")); - } - default -> sender.sendMessage(colorize("&c&lUsage: &r&c/chat [" + (canUseGlobal ? "g|global OR " : "") + "s|server|normal OR t|team OR p|party]")); - } - - return true; - } - - public void sendChannelPrefToDB(Player player, PreferenceCache.ChatChannel channel) { - try { - PlayerService.changePlayerChatChannel(player.getUniqueId().toString(), UuidChannelBody.ChannelEnum.valueOf(channel.toString())); - } catch (ApiException e) { - player.sendMessage(colorize("&cErreur : ce changement n'a pas été enregistré.")); - } - } - - @Override - public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if (args.length != 1) return Collections.emptyList(); - - return Arrays.stream(PreferenceCache.ChatChannel.values()) - .filter(channel -> channel.toString().startsWith(args[0].toUpperCase())) - .filter(channel -> sender.hasPermission("ecatup.channel.global") || channel != PreferenceCache.ChatChannel.GLOBAL).map(Enum::toString).collect(Collectors.toList()); - } -} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/FlyCommand.java b/src/main/java/fr/efreicraft/ecatup/commands/FlyCommand.java new file mode 100644 index 0000000..f330ea5 --- /dev/null +++ b/src/main/java/fr/efreicraft/ecatup/commands/FlyCommand.java @@ -0,0 +1,47 @@ +package fr.efreicraft.ecatup.commands; + +import dev.rollczi.litecommands.annotations.argument.Arg; +import dev.rollczi.litecommands.annotations.command.Command; +import dev.rollczi.litecommands.annotations.context.Context; +import dev.rollczi.litecommands.annotations.execute.Execute; +import dev.rollczi.litecommands.annotations.permission.Permission; +import fr.efreicraft.ecatup.ECATUP; +import fr.efreicraft.ecatup.players.ECPlayer; +import fr.efreicraft.ecatup.utils.MessageUtils; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@Command(name = "fly", aliases = {"f"}) +@Permission("ecatup.fly") +public class FlyCommand { + + @Execute + void execute(@Context Player sender) { + sender.setAllowFlight(!sender.getAllowFlight()); + MessageUtils.sendMessage( + sender, + MessageUtils.ChatPrefix.SERVER, + "&7Vous " + (sender.getAllowFlight() ? "&apouvez désormais" : "&cne pouvez plus") + "&7 voler!" + ); + } + + @Execute + void executeOther(@Context CommandSender sender, @Arg Player target) { + target.setAllowFlight(!target.getAllowFlight()); + + ECPlayer ecPlayer = ECPlayer.get(target); + + MessageUtils.sendMessage( + sender, + MessageUtils.ChatPrefix.SERVER, + "&7Le joueur " + ecPlayer.getChatName() + " " + (target.getAllowFlight() ? "&apossède désormais" : "&cne possède plus") + "&7 la capacité de voler!" + ); + + MessageUtils.sendMessage( + target, + MessageUtils.ChatPrefix.SERVER, + "&7Vous " + (target.getAllowFlight() ? "&apouvez désormais" : "&cne pouvez plus") + "&7 voler!" + ); + } + +} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/GameModeCommand.java b/src/main/java/fr/efreicraft/ecatup/commands/GameModeCommand.java new file mode 100644 index 0000000..04bb4cb --- /dev/null +++ b/src/main/java/fr/efreicraft/ecatup/commands/GameModeCommand.java @@ -0,0 +1,74 @@ +package fr.efreicraft.ecatup.commands; + +import dev.rollczi.litecommands.annotations.argument.Arg; +import dev.rollczi.litecommands.annotations.context.Context; +import dev.rollczi.litecommands.annotations.execute.Execute; +import dev.rollczi.litecommands.annotations.optional.OptionalArg; +import dev.rollczi.litecommands.annotations.permission.Permission; +import dev.rollczi.litecommands.annotations.command.Command; +import dev.rollczi.litecommands.annotations.shortcut.Shortcut; +import fr.efreicraft.ecatup.ECATUP; +import fr.efreicraft.ecatup.players.ECPlayer; +import fr.efreicraft.ecatup.utils.MessageUtils; +import org.bukkit.GameMode; +import org.bukkit.entity.Player; + +@Command(name = "gamemode", aliases = "gm") +@Permission("ecatup.gamemode") +public class GameModeCommand { + + @Execute + public void execute(@Context Player player, @Arg GameMode gameMode) { + player.setGameMode(gameMode); + MessageUtils.sendMessage(player, MessageUtils.ChatPrefix.SERVER,"&7Votre mode de jeu a été mis à jour en &a" + gameMode.name().toLowerCase() + "&7."); + } + + @Execute + public void execute(@Context Player player, @Arg GameMode gameMode, @Arg Player target) { + target.setGameMode(gameMode); + + ECPlayer ecPlayer = ECPlayer.get(target); + MessageUtils.sendMessage(player, MessageUtils.ChatPrefix.SERVER,"&7Le mode de jeu de " + ecPlayer.getChatName() + "&7 a été mis à jour en &a" + gameMode.name().toLowerCase() + "&7."); + } + + @Execute(name = "survival") + @Shortcut("gms") + public void setSurvival(@Context Player player, @OptionalArg Player target) { + if (target != null) { + execute(player, GameMode.SURVIVAL, target); + return; + } + execute(player, GameMode.SURVIVAL); + } + + @Execute(name = "creative") + @Shortcut("gmc") + public void setCreative(@Context Player player, @OptionalArg Player target) { + if (target != null) { + execute(player, GameMode.CREATIVE, target); + return; + } + execute(player, GameMode.CREATIVE); + } + + @Execute(name = "adventure") + @Shortcut("gma") + public void setAdventure(@Context Player player, @OptionalArg Player target) { + if (target != null) { + execute(player, GameMode.ADVENTURE, target); + return; + } + execute(player, GameMode.ADVENTURE); + } + + @Execute(name = "spectator") + @Shortcut("gmsp") + public void setSpectator(@Context Player player, @OptionalArg Player target) { + if (target != null) { + execute(player, GameMode.SPECTATOR, target); + return; + } + execute(player, GameMode.SPECTATOR); + } + +} \ No newline at end of file diff --git a/src/main/java/fr/efreicraft/ecatup/commands/HasPerm.java b/src/main/java/fr/efreicraft/ecatup/commands/HasPerm.java deleted file mode 100644 index 6033378..0000000 --- a/src/main/java/fr/efreicraft/ecatup/commands/HasPerm.java +++ /dev/null @@ -1,96 +0,0 @@ -package fr.efreicraft.ecatup.commands; - -import fr.efreicraft.animus.endpoints.PlayerService; -import fr.efreicraft.animus.invoker.ApiException; -import fr.efreicraft.animus.models.Permission; -import fr.efreicraft.ecatup.ECATUP; -import fr.efreicraft.ecatup.players.ECPlayer; -import fr.efreicraft.ecatup.utils.MessageUtils; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabExecutor; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -public class HasPerm implements CommandExecutor, TabExecutor { - - @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - OfflinePlayer player; - String permission; - boolean fromDB = false; - - if (args.length == 2) { - player = Bukkit.getOfflinePlayer(args[0]); - permission = args[1]; - } else if (args.length == 3) { - player = Bukkit.getOfflinePlayer(args[0]); - permission = args[1]; - fromDB = Boolean.parseBoolean(args[2].toLowerCase()); - } else { - MessageUtils.sendMessage(sender, MessageUtils.ChatPrefix.SERVER, "&cSyntaxe invalide : /hasperm "); - return true; - } - - if (!player.isOnline()) fromDB = true; - - permission = permission.toLowerCase(); - if (permission.endsWith(".*")) permission = permission.substring(0, permission.indexOf(".*")); - - if (fromDB) { - try { - List perms = PlayerService.getPermissionOfPlayer(player.getUniqueId().toString()); - for (Permission p : perms) { - if (p.getName().startsWith(permission)) { - MessageUtils.sendMessage(sender, MessageUtils.ChatPrefix.SERVER, - "%s possède la permission &a[%s]&r dans [%s].".formatted(player.getName(), permission, String.join(",", p.getServerTypes()))); - return true; - } - } - - MessageUtils.sendMessage(sender, MessageUtils.ChatPrefix.SERVER, - "%s ne possède pas la permission &a[%s]&r.".formatted(player.getName(), permission)); - } catch (ApiException e) { - MessageUtils.sendMessage(sender, MessageUtils.ChatPrefix.SERVER, - "&cLa base de données n'a pas répondu, ou a retourné une erreur. Veuillez voir les logs."); - Bukkit.getLogger().severe("Couldn't fetch %s's permissions".formatted(player.getName())); - Bukkit.getLogger().severe("It was to test permission [%s] (initiated by %s)".formatted(permission, sender.getName())); - Bukkit.getLogger().severe("Code: %s Message: %s".formatted(e.getCode(), e.getMessage())); - } - } else { - ECPlayer ecPlayer = ECATUP.getInstance().getPlayerManager().getPlayer(player.getPlayer()); - if (ecPlayer == null) { - MessageUtils.sendMessage(sender, MessageUtils.ChatPrefix.SERVER, - "&cWtf ? Joueur non trouvé...?"); - return true; - } - - - for (Permission p : ecPlayer.getAnimusPlayer().getPerms()) { - if (p.getName().startsWith(permission)) { - MessageUtils.sendMessage(sender, MessageUtils.ChatPrefix.SERVER, - "%s possède la permission &a[%s]&r dans [%s].".formatted(player.getName(), permission, String.join(",", p.getServerTypes()))); - return true; - } - } - - MessageUtils.sendMessage(sender, MessageUtils.ChatPrefix.SERVER, - "%s ne possède pas la permission &a[%s]&r.".formatted(player.getName(), permission)); - } - - return true; - } - - @Override - public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if (args.length == 1) return Bukkit.getOnlinePlayers().stream().map(Player::getName).sorted().toList(); - if (args.length == 3) return List.of("true", "false"); - return null; - } -} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/HasPermCommand.java b/src/main/java/fr/efreicraft/ecatup/commands/HasPermCommand.java new file mode 100644 index 0000000..3edab3d --- /dev/null +++ b/src/main/java/fr/efreicraft/ecatup/commands/HasPermCommand.java @@ -0,0 +1,33 @@ +package fr.efreicraft.ecatup.commands; + +import dev.rollczi.litecommands.annotations.argument.Arg; +import dev.rollczi.litecommands.annotations.command.Command; +import dev.rollczi.litecommands.annotations.context.Context; +import dev.rollczi.litecommands.annotations.execute.Execute; +import dev.rollczi.litecommands.annotations.permission.Permission; +import fr.efreicraft.ecatup.players.ECPlayer; +import fr.efreicraft.ecatup.utils.MessageUtils; +import org.bukkit.entity.Player; + +@Command(name = "hasperm") +@Permission("ecatup.hasperm") +public class HasPermCommand { + @Execute + void execute(@Context Player player, @Arg Player target, @Arg String permission) { + ECPlayer ecPlayer = ECPlayer.get(target); + + if (target.hasPermission(permission)) { + MessageUtils.sendMessage( + player, + MessageUtils.ChatPrefix.SERVER, + ecPlayer.getChatName() + " &apossède&7 la permission " + permission + "." + ); + } else { + MessageUtils.sendMessage( + player, + MessageUtils.ChatPrefix.SERVER, + ecPlayer.getChatName() + " &7ne &cpossède pas&7 la permission " + permission + "." + ); + } + } +} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/RideCommand.java b/src/main/java/fr/efreicraft/ecatup/commands/RideCommand.java new file mode 100644 index 0000000..9e775ef --- /dev/null +++ b/src/main/java/fr/efreicraft/ecatup/commands/RideCommand.java @@ -0,0 +1,29 @@ +package fr.efreicraft.ecatup.commands; + +import dev.rollczi.litecommands.annotations.argument.Arg; +import dev.rollczi.litecommands.annotations.command.Command; +import dev.rollczi.litecommands.annotations.context.Context; +import dev.rollczi.litecommands.annotations.execute.Execute; +import dev.rollczi.litecommands.annotations.permission.Permission; +import fr.efreicraft.ecatup.commands.exceptions.CommandException; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +@Command(name = "ride") +@Permission("ecatup.ride") +public class RideCommand { + + @Execute + void ride(@Context Player player, @Arg Player target) throws CommandException { + target.addPassenger(player); + } + + @Execute(name = "off") + void off(@Context Player player) { + Entity vehicle = player.getVehicle(); + + if (vehicle != null) { + vehicle.eject(); + } + } +} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/Skull.java b/src/main/java/fr/efreicraft/ecatup/commands/Skull.java deleted file mode 100644 index 886ab16..0000000 --- a/src/main/java/fr/efreicraft/ecatup/commands/Skull.java +++ /dev/null @@ -1,44 +0,0 @@ -package fr.efreicraft.ecatup.commands; - -import fr.efreicraft.ecatup.ECATUP; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabExecutor; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.SkullMeta; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -public class Skull implements CommandExecutor, TabExecutor { - @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if (sender instanceof Player player) { - if (args.length == 1) { - ItemStack skull = new ItemStack(Material.PLAYER_HEAD, 1); - SkullMeta skullMeta = (SkullMeta) skull.getItemMeta(); - skullMeta.setOwningPlayer(Bukkit.getOfflinePlayer(args[0])); - skull.setItemMeta(skullMeta); - player.getInventory().addItem(skull); - } - else { - sender.sendMessage(ChatColor.RED + "Usage: /skull "); - } - } - else { - sender.sendMessage(ChatColor.RED + "Vous devez être un joueur pour exécuter cette commande !"); - } - return true; - } - - @Override - public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - return args.length == 1 ? ECATUP.getPlayersForTabList(args, 0) : null; - } -} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/SkullCommand.java b/src/main/java/fr/efreicraft/ecatup/commands/SkullCommand.java new file mode 100644 index 0000000..76e97e7 --- /dev/null +++ b/src/main/java/fr/efreicraft/ecatup/commands/SkullCommand.java @@ -0,0 +1,44 @@ +package fr.efreicraft.ecatup.commands; + +import dev.rollczi.litecommands.annotations.argument.Arg; +import dev.rollczi.litecommands.annotations.command.Command; +import dev.rollczi.litecommands.annotations.context.Context; +import dev.rollczi.litecommands.annotations.execute.Execute; +import dev.rollczi.litecommands.annotations.permission.Permission; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.SkullMeta; + +@Command(name = "skull") +@Permission("ecatup.skull") +public class SkullCommand { + + @Execute + void execute(@Context Player player, @Arg String playerName) { + ItemStack skull = new ItemStack(Material.PLAYER_HEAD, 1); + SkullMeta skullMeta = (SkullMeta) skull.getItemMeta(); + skullMeta.setOwningPlayer(Bukkit.getOfflinePlayer(playerName)); + skull.setItemMeta(skullMeta); + player.getInventory().addItem(skull); + } + + @Execute + void execute(@Context Player player, @Arg Player target) { + ItemStack skull = new ItemStack(Material.PLAYER_HEAD, 1); + SkullMeta skullMeta = (SkullMeta) skull.getItemMeta(); + skullMeta.setOwningPlayer(target); + skull.setItemMeta(skullMeta); + player.getInventory().addItem(skull); + } + + @Execute + void execute(@Context Player player) { + ItemStack skull = new ItemStack(Material.PLAYER_HEAD, 1); + SkullMeta skullMeta = (SkullMeta) skull.getItemMeta(); + skullMeta.setOwningPlayer(player); + skull.setItemMeta(skullMeta); + player.getInventory().addItem(skull); + } +} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/Slap.java b/src/main/java/fr/efreicraft/ecatup/commands/Slap.java deleted file mode 100644 index c970cc4..0000000 --- a/src/main/java/fr/efreicraft/ecatup/commands/Slap.java +++ /dev/null @@ -1,83 +0,0 @@ -package fr.efreicraft.ecatup.commands; - -import fr.efreicraft.ecatup.ECATUP; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabExecutor; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collections; -import java.util.List; - -import static fr.efreicraft.ecatup.utils.Msg.colorize; - -public class Slap implements CommandExecutor, TabExecutor { - - @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if (args.length == 0 || args.length > 2 || args[0].equals("-a")) { - - sender.sendMessage(Component.text(colorize("&c&lUsage: &r&c/slap [-a]\n-a = Pousse le joueur dans la direction opposée par rapport à votre position."))); - return true; - } - - boolean sendAway = args.length == 2 && args[1].equals("-a"); - @NotNull List players = Bukkit.selectEntities(sender, args[0]); - - if (players.isEmpty()) { - sender.sendMessage(Component.text(colorize("&6"+args[0]+"&c n'est pas connecté !"))); - return true; - } - - Vector direction; - double force = 2.6; - - for (Entity p: players) { - if (sendAway) { - //noinspection ALL - if (!(sender instanceof Player slapper)) { - sender.sendMessage(Component.text("Vous ne pouvez pas utiliser \"-a\" dans la console !").color(NamedTextColor.RED)); - return true; - } - - if (slapper.getUniqueId() == p.getUniqueId()) { - sender.sendMessage(Component.text(colorize("&4Wtf ??"))); - continue; - } - - direction = p.getLocation().toVector().subtract(slapper.getLocation().toVector()).normalize(); - direction.setY(direction.getY() * Math.random() * 2); - - } else { - direction = Vector.getRandom(); - direction.setX(direction.getX() * ((Math.random() * (2 * force)) - force)); - direction.setY(direction.getY() * (Math.random() * force * 1.5)); - direction.setZ(direction.getZ() * ((Math.random() * (2 * force)) - force)); - } - - p.setVelocity(direction); - } - - - return true; - } - - @Override - public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if (args.length == 1) { - return ECATUP.getPlayersForTabList(args, 0); - } else if (args.length == 2) { - return Collections.singletonList("-a"); - } - - return null; - } -} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/SlapCommand.java b/src/main/java/fr/efreicraft/ecatup/commands/SlapCommand.java new file mode 100644 index 0000000..693d531 --- /dev/null +++ b/src/main/java/fr/efreicraft/ecatup/commands/SlapCommand.java @@ -0,0 +1,35 @@ +package fr.efreicraft.ecatup.commands; + +import dev.rollczi.litecommands.annotations.argument.Arg; +import dev.rollczi.litecommands.annotations.command.Command; +import dev.rollczi.litecommands.annotations.context.Context; +import dev.rollczi.litecommands.annotations.execute.Execute; +import dev.rollczi.litecommands.annotations.flag.Flag; +import dev.rollczi.litecommands.annotations.permission.Permission; +import fr.efreicraft.ecatup.commands.exceptions.CommandException; +import fr.efreicraft.ecatup.commands.validator.NotTheSamePlayer; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +@Command(name = "slap") +@Permission("ecatup.slap") +public class SlapCommand { + + @Execute + void slap(@Context Player player, @Arg @NotTheSamePlayer Player target, @Flag("-a") boolean sendAway) throws CommandException { + Vector direction; + double force = 2.6; + + if (sendAway) { + direction = target.getLocation().toVector().subtract(player.getLocation().toVector()).normalize(); + direction.setY(direction.getY() * Math.random() * 2); + } else { + direction = Vector.getRandom(); + direction.setX(direction.getX() * ((Math.random() * (2 * force)) - force)); + direction.setY(direction.getY() * (Math.random() * force * 1.5)); + direction.setZ(direction.getZ() * ((Math.random() * (2 * force)) - force)); + } + + target.setVelocity(direction); + } +} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/SpeedCommand.java b/src/main/java/fr/efreicraft/ecatup/commands/SpeedCommand.java new file mode 100644 index 0000000..a5e0f0e --- /dev/null +++ b/src/main/java/fr/efreicraft/ecatup/commands/SpeedCommand.java @@ -0,0 +1,60 @@ +package fr.efreicraft.ecatup.commands; + +import dev.rollczi.litecommands.annotations.argument.Arg; +import dev.rollczi.litecommands.annotations.command.Command; +import dev.rollczi.litecommands.annotations.context.Context; +import dev.rollczi.litecommands.annotations.execute.Execute; +import dev.rollczi.litecommands.annotations.permission.Permission; +import dev.rollczi.litecommands.annotations.shortcut.Shortcut; +import fr.efreicraft.ecatup.commands.validator.Speed; +import fr.efreicraft.ecatup.utils.MessageUtils; +import org.bukkit.entity.Player; + +@Command(name = "speed") +@Permission("ecatup.speed") +public class SpeedCommand { + + @Execute + void execute(@Context Player player, @Arg @Speed Float speed) { + player.setWalkSpeed(speed / 10); + player.setFlySpeed(speed / 10); + MessageUtils.sendMessage( + player, + MessageUtils.ChatPrefix.SERVER, + "&7Votre vitesse de déplacement (marche & vol) a été mise à jour en &a" + speed + "&7." + ); + } + + @Execute(name = "reset") + @Shortcut("reset") + void reset(@Context Player player) { + player.setWalkSpeed(0.2f); + player.setFlySpeed(0.1f); + MessageUtils.sendMessage( + player, + MessageUtils.ChatPrefix.SERVER, + "&7Votre vitesse de déplacement (marche & vol) a été réinitialisée." + ); + } + + @Shortcut("ws") + void setWalkSpeed(@Context Player player, @Arg @Speed Float speed) { + player.setWalkSpeed(speed / 10); + MessageUtils.sendMessage( + player, + MessageUtils.ChatPrefix.SERVER, + "&7Votre vitesse de déplacement a été mise à jour en &a" + speed + "&7." + ); + } + + @Shortcut("fs") + void setFlySpeed(@Context Player player, @Arg @Speed Float speed) { + player.setFlySpeed(speed / 10); + MessageUtils.sendMessage( + player, + MessageUtils.ChatPrefix.SERVER, + "&7Votre vitesse de vol a été mise à jour en &a" + speed + "&7." + ); + } + +} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/Sudo.java b/src/main/java/fr/efreicraft/ecatup/commands/Sudo.java deleted file mode 100644 index 0fb3e9c..0000000 --- a/src/main/java/fr/efreicraft/ecatup/commands/Sudo.java +++ /dev/null @@ -1,39 +0,0 @@ -package fr.efreicraft.ecatup.commands; - -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabExecutor; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class Sudo implements CommandExecutor, TabExecutor { - @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if (args.length <= 1) return false; - @NotNull List playerList = Bukkit.selectEntities(sender, args[0]).stream() - .filter(entity -> entity instanceof Player) - .map(entity -> (Player) entity) - .toList(); - - String message = String.join(" ", Arrays.copyOfRange(args, 1, args.length)); - for (Player player : playerList) { -// if (!sender.equals(player)) // il faut éviter l'auto sudo comme /sudo /sudo /say hi! - player.chat(message); - } - return true; - } - - @Override - public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if (args.length != 1) return new ArrayList<>(); - - return null; - } -} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/SudoCommand.java b/src/main/java/fr/efreicraft/ecatup/commands/SudoCommand.java new file mode 100644 index 0000000..c0778f6 --- /dev/null +++ b/src/main/java/fr/efreicraft/ecatup/commands/SudoCommand.java @@ -0,0 +1,25 @@ +package fr.efreicraft.ecatup.commands; + +import dev.rollczi.litecommands.annotations.argument.Arg; +import dev.rollczi.litecommands.annotations.command.Command; +import dev.rollczi.litecommands.annotations.context.Context; +import dev.rollczi.litecommands.annotations.execute.Execute; +import dev.rollczi.litecommands.annotations.join.Join; +import dev.rollczi.litecommands.annotations.permission.Permission; +import fr.efreicraft.ecatup.commands.validator.NotTheSamePlayer; +import org.bukkit.entity.Player; + +@Command(name = "sudo") +@Permission("ecatup.sudo") +public class SudoCommand { + + @Execute(name = "chat") + void executeChat(@Context Player player, @Arg @NotTheSamePlayer Player target, @Join String message) { + target.chat(message); + } + + @Execute(name = "command") + void executeCommand(@Context Player player, @Arg @NotTheSamePlayer Player target, @Join String command) { + target.performCommand(command); + } +} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/WhoIs.java b/src/main/java/fr/efreicraft/ecatup/commands/WhoIs.java deleted file mode 100644 index 8ae379f..0000000 --- a/src/main/java/fr/efreicraft/ecatup/commands/WhoIs.java +++ /dev/null @@ -1,84 +0,0 @@ -package fr.efreicraft.ecatup.commands; - -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.JoinConfiguration; -import net.kyori.adventure.text.event.ClickEvent; -import net.kyori.adventure.text.event.HoverEvent; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.format.TextColor; -import net.kyori.adventure.text.format.TextDecoration; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import static fr.efreicraft.ecatup.utils.Msg.colorize; - -public class WhoIs implements CommandExecutor { - - /** - * ====== [NOM] ====== - * UUID: [uuid] - * Rangs: [rang1, rang2...] - * Serveur (si connecté): serveur - **/ - - final TextColor KEY_COLOR = NamedTextColor.AQUA; - final TextColor VALUE_COLOR = NamedTextColor.WHITE; - - - // Jsuis obligé - final HoverEvent CLICK_TO_COPY = HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, Component.text("Cliquez pour copier !")); - - @SuppressWarnings("ConstantConditions") - @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - // ========== PRECISION : ON PEUT S'AUTO-WHOIS (because I said so) ========== - if (args.length > 1) return false; - - OfflinePlayer player; - if (args.length == 0) { - if (sender instanceof Player) - player = (Player) sender; // whois sur soi-même - else { - sender.sendMessage(colorize("&cVous devez etre un joueur (ou preciser le nom d'un joueur) pour executer cette commande !")); - return true; - } - } else { - player = Bukkit.getOfflinePlayerIfCached(args[0]); - if (player == null) { - sender.sendMessage(colorize("&cLe joueur &l&6" + args[0] + "&r&c n'est pas connecte (ou ne s'est pas connecte recemment) !")); - return true; - } - } - - - Component message; - - /* Obtenir les rangs */ - //TODO finir ça - String highestRank = "hm"; - - message = Component.join(JoinConfiguration.newlines(), - Component.join(JoinConfiguration.noSeparators(), Component.text("UUID: ", KEY_COLOR), Component.text(String.valueOf(player.getUniqueId()), VALUE_COLOR, TextDecoration.BOLD) - .clickEvent(ClickEvent.copyToClipboard(player.getUniqueId().toString()))) - .hoverEvent(CLICK_TO_COPY), - Component.join(JoinConfiguration.noSeparators(), Component.text("Rang: ", KEY_COLOR), Component.text(highestRank == null ? "rien" : colorize(highestRank), VALUE_COLOR, TextDecoration.BOLD) - .clickEvent(ClickEvent.copyToClipboard(highestRank == null ? "rien" : colorize(highestRank)))) - .hoverEvent(CLICK_TO_COPY), - Component.join(JoinConfiguration.noSeparators(), Component.text("Pos: ", KEY_COLOR), Component.text(player.isOnline() ? ((Player) player).getLocation().toString() : "couldn't get pos...", VALUE_COLOR, TextDecoration.BOLD) - .clickEvent(ClickEvent.copyToClipboard(player.isOnline() ? ((Player) player).getLocation().toString() : "couldn't get pos..."))) - .hoverEvent(CLICK_TO_COPY) - ); - - sender.sendMessage(colorize((player.isOnline() ? "&8====== &a" : "&8====== &4") + player.getName() + "&8 ======")); - sender.sendMessage(message); - sender.sendMessage(colorize("&8========" + new String(new char[player.getName().length()]).replace("\0", "=") + "========")); - - return true; - } - -} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/arguments/GameModeArgument.java b/src/main/java/fr/efreicraft/ecatup/commands/arguments/GameModeArgument.java new file mode 100644 index 0000000..c7606cd --- /dev/null +++ b/src/main/java/fr/efreicraft/ecatup/commands/arguments/GameModeArgument.java @@ -0,0 +1,43 @@ +package fr.efreicraft.ecatup.commands.arguments; + +import dev.rollczi.litecommands.argument.Argument; +import dev.rollczi.litecommands.argument.parser.ParseResult; +import dev.rollczi.litecommands.argument.resolver.ArgumentResolver; +import dev.rollczi.litecommands.invocation.Invocation; +import dev.rollczi.litecommands.suggestion.SuggestionContext; +import dev.rollczi.litecommands.suggestion.SuggestionResult; +import org.bukkit.GameMode; +import org.bukkit.command.CommandSender; + +import java.util.HashMap; +import java.util.Map; + +public class GameModeArgument extends ArgumentResolver { + + private static final Map GAME_MODE_ARGUMENTS = new HashMap<>(); + + static { + for (GameMode value : GameMode.values()) { + GAME_MODE_ARGUMENTS.put(value.name().toLowerCase(), value); + //noinspection deprecation + GAME_MODE_ARGUMENTS.put(String.valueOf(value.getValue()), value); + } + } + + @Override + protected ParseResult parse(Invocation invocation, Argument context, String argument) { + GameMode gameMode = GAME_MODE_ARGUMENTS.get(argument.toLowerCase()); + + if (gameMode == null) { + return ParseResult.failure("Invalid gamemode argument!"); + } + + return ParseResult.success(gameMode); + } + + @Override + public SuggestionResult suggest(Invocation invocation, Argument argument, SuggestionContext context) { + return SuggestionResult.of(GAME_MODE_ARGUMENTS.keySet()); + } + +} \ No newline at end of file diff --git a/src/main/java/fr/efreicraft/ecatup/commands/exceptions/CommandException.java b/src/main/java/fr/efreicraft/ecatup/commands/exceptions/CommandException.java new file mode 100644 index 0000000..9635273 --- /dev/null +++ b/src/main/java/fr/efreicraft/ecatup/commands/exceptions/CommandException.java @@ -0,0 +1,12 @@ +package fr.efreicraft.ecatup.commands.exceptions; + +public class CommandException extends Exception { + + public CommandException(String message) { + super(message); + } + + public CommandException() { + super("Une erreur inattendue est survenue."); + } +} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/gamemode/Gm.java b/src/main/java/fr/efreicraft/ecatup/commands/gamemode/Gm.java deleted file mode 100644 index 53927f8..0000000 --- a/src/main/java/fr/efreicraft/ecatup/commands/gamemode/Gm.java +++ /dev/null @@ -1,60 +0,0 @@ -package fr.efreicraft.ecatup.commands.gamemode; - -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import static fr.efreicraft.ecatup.utils.Msg.colorize; - -public class Gm implements CommandExecutor { - @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - Player player; - if (args.length == 1) { - if (sender instanceof Player) { - player = (Player) sender; - } - else { - sender.sendMessage(colorize("&cVous devez être un joueur pour exécuter cette commande !")); - return true; - } - } - else if (args.length == 2) { - player = Bukkit.getPlayer(args[1]); - if (player == null) { - sender.sendMessage(colorize("&cLe joueur &l&6" + args[1] + "&r&c n'est pas connecté !")); - return true; - } - } - else { - return false; - } - switch (args[0]) { - case "0", "s", "survival" -> { - player.setGameMode(GameMode.SURVIVAL); - player.sendMessage(colorize("&aVous êtes maintenant en mode survie !")); - } - case "1", "c", "creative" -> { - player.setGameMode(GameMode.CREATIVE); - player.sendMessage(colorize("&aVous êtes maintenant en mode créatif !")); - } - case "2", "a", "adventure" -> { - player.setGameMode(GameMode.ADVENTURE); - player.sendMessage(colorize("&aVous êtes maintenant en mode aventure !")); - } - case "3", "sp", "spectator" -> { - player.setGameMode(GameMode.SPECTATOR); - player.sendMessage(colorize("&aVous êtes maintenant en mode spectateur !")); - } - default -> { - sender.sendMessage(colorize("&cLe mode de jeu &l&6" + args[0] + "&r&c n'existe pas !")); - return true; - } - } - return true; - } -} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/gamemode/Gma.java b/src/main/java/fr/efreicraft/ecatup/commands/gamemode/Gma.java deleted file mode 100644 index 96e9964..0000000 --- a/src/main/java/fr/efreicraft/ecatup/commands/gamemode/Gma.java +++ /dev/null @@ -1,37 +0,0 @@ -package fr.efreicraft.ecatup.commands.gamemode; - -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import static fr.efreicraft.ecatup.utils.Msg.colorize; - -public class Gma implements CommandExecutor { - @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - Player player; - if (args.length == 0) { - if (sender instanceof Player) { - player = (Player) sender; - } - else { - sender.sendMessage(colorize("&cVous devez être un joueur pour exécuter cette commande !")); - return true; - } - } - else { - player = Bukkit.getPlayer(args[0]); - if (player == null) { - sender.sendMessage(colorize("&cLe joueur &l&6" + args[0] + "&r&c n'est pas connecté !")); - return true; - } - } - player.setGameMode(GameMode.ADVENTURE); - player.sendMessage(colorize("&aVous êtes maintenant en mode aventure !")); - return true; - } -} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/gamemode/Gmc.java b/src/main/java/fr/efreicraft/ecatup/commands/gamemode/Gmc.java deleted file mode 100644 index 849acab..0000000 --- a/src/main/java/fr/efreicraft/ecatup/commands/gamemode/Gmc.java +++ /dev/null @@ -1,37 +0,0 @@ -package fr.efreicraft.ecatup.commands.gamemode; - -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import static fr.efreicraft.ecatup.utils.Msg.colorize; - -public class Gmc implements CommandExecutor { - @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - Player player; - if (args.length == 0) { - if (sender instanceof Player) { - player = (Player) sender; - } - else { - sender.sendMessage(colorize("&cVous devez être un joueur pour exécuter cette commande !")); - return true; - } - } - else { - player = Bukkit.getPlayer(args[0]); - if (player == null) { - sender.sendMessage(colorize("&cLe joueur &l&6" + args[0] + "&r&c n'est pas connecté !")); - return true; - } - } - player.setGameMode(GameMode.CREATIVE); - player.sendMessage(colorize("&aVous êtes maintenant en mode créatif !")); - return true; - } -} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/gamemode/Gms.java b/src/main/java/fr/efreicraft/ecatup/commands/gamemode/Gms.java deleted file mode 100644 index a975874..0000000 --- a/src/main/java/fr/efreicraft/ecatup/commands/gamemode/Gms.java +++ /dev/null @@ -1,37 +0,0 @@ -package fr.efreicraft.ecatup.commands.gamemode; - -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import static fr.efreicraft.ecatup.utils.Msg.colorize; - -public class Gms implements CommandExecutor { - @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - Player player; - if (args.length == 0) { - if (sender instanceof Player) { - player = (Player) sender; - } - else { - sender.sendMessage(colorize("&cVous devez être un joueur pour exécuter cette commande !")); - return true; - } - } - else { - player = Bukkit.getPlayer(args[0]); - if (player == null) { - sender.sendMessage(colorize("&cLe joueur &l&6" + args[0] + "&r&c n'est pas connecté !")); - return true; - } - } - player.setGameMode(GameMode.SURVIVAL); - player.sendMessage(colorize("&aVous êtes maintenant en mode survie !")); - return true; - } -} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/gamemode/Gmsp.java b/src/main/java/fr/efreicraft/ecatup/commands/gamemode/Gmsp.java deleted file mode 100644 index 5e0b931..0000000 --- a/src/main/java/fr/efreicraft/ecatup/commands/gamemode/Gmsp.java +++ /dev/null @@ -1,37 +0,0 @@ -package fr.efreicraft.ecatup.commands.gamemode; - -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import static fr.efreicraft.ecatup.utils.Msg.colorize; - -public class Gmsp implements CommandExecutor { - @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - Player player; - if (args.length == 0) { - if (sender instanceof Player) { - player = (Player) sender; - } - else { - sender.sendMessage(colorize("&cVous devez être un joueur pour exécuter cette commande !")); - return true; - } - } - else { - player = Bukkit.getPlayer(args[0]); - if (player == null) { - sender.sendMessage(colorize("&cLe joueur &l&6" + args[0] + "&r&c n'est pas connecté !")); - return true; - } - } - player.setGameMode(GameMode.SPECTATOR); - player.sendMessage(colorize("&aVous êtes maintenant en mode spectateur !")); - return true; - } -} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/handlers/InvalidUsage.java b/src/main/java/fr/efreicraft/ecatup/commands/handlers/InvalidUsage.java new file mode 100644 index 0000000..85b15ec --- /dev/null +++ b/src/main/java/fr/efreicraft/ecatup/commands/handlers/InvalidUsage.java @@ -0,0 +1,27 @@ +package fr.efreicraft.ecatup.commands.handlers; + +import dev.rollczi.litecommands.handler.result.ResultHandlerChain; +import dev.rollczi.litecommands.invalidusage.InvalidUsageHandler; +import dev.rollczi.litecommands.invocation.Invocation; +import dev.rollczi.litecommands.schematic.Schematic; +import fr.efreicraft.ecatup.utils.MessageUtils; +import org.bukkit.command.CommandSender; + +public class InvalidUsage implements InvalidUsageHandler { + + @Override + public void handle(Invocation invocation, dev.rollczi.litecommands.invalidusage.InvalidUsage result, ResultHandlerChain chain) { + Schematic schematic = result.getSchematic(); + CommandSender sender = invocation.sender(); + + if (schematic.isOnlyFirst()) { + MessageUtils.sendMessage(sender, MessageUtils.ChatPrefix.COMMAND, "&cUsage incorrect. &7Syntaxe: " + schematic.first()); + return; + } + + MessageUtils.sendMessage(sender, MessageUtils.ChatPrefix.COMMAND, "&cUsage incorrect. &7Sous-commandes: "); + for (String sch : schematic.all()) { + MessageUtils.sendMessage(sender, MessageUtils.ChatPrefix.EMPTY, " &7- &c" + sch); + } + } +} \ No newline at end of file diff --git a/src/main/java/fr/efreicraft/ecatup/commands/handlers/PermissionHandler.java b/src/main/java/fr/efreicraft/ecatup/commands/handlers/PermissionHandler.java new file mode 100644 index 0000000..cc022d8 --- /dev/null +++ b/src/main/java/fr/efreicraft/ecatup/commands/handlers/PermissionHandler.java @@ -0,0 +1,25 @@ +package fr.efreicraft.ecatup.commands.handlers; + +import dev.rollczi.litecommands.handler.result.ResultHandlerChain; +import dev.rollczi.litecommands.invocation.Invocation; +import dev.rollczi.litecommands.permission.MissingPermissions; +import dev.rollczi.litecommands.permission.MissingPermissionsHandler; +import fr.efreicraft.ecatup.utils.MessageUtils; +import net.kyori.adventure.text.minimessage.MiniMessage; +import org.bukkit.command.CommandSender; + +public class PermissionHandler implements MissingPermissionsHandler { + + private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage(); + + @Override + public void handle(Invocation invocation, MissingPermissions missingPermissions, ResultHandlerChain chain) { + CommandSender sender = invocation.sender(); + + MessageUtils.sendMessage( + sender, + MessageUtils.ChatPrefix.COMMAND, + MINI_MESSAGE.deserialize("Vous n'avez pas la permission d'utiliser cette commande.") + ); + } +} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/permissions/Common.java b/src/main/java/fr/efreicraft/ecatup/commands/permissions/Common.java deleted file mode 100644 index 3fbeb11..0000000 --- a/src/main/java/fr/efreicraft/ecatup/commands/permissions/Common.java +++ /dev/null @@ -1,103 +0,0 @@ -package fr.efreicraft.ecatup.commands.permissions; - -import fr.efreicraft.animus.models.PermGroup; -import fr.efreicraft.animus.models.PermGroupPlayer; -import fr.efreicraft.ecatup.ECATUP; -import fr.efreicraft.ecatup.utils.MessageUtils; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Common { - - // Copilot va bientôt nous remplacer, je vous le dis. - public enum ErrorMessages { - NO_PERMISSION("&cVous n'avez pas la permission d'utiliser cette commande."), - NOT_ENOUGH_ARGUMENTS("&cPas assez d'arguments."), - TOO_MANY_ARGUMENTS("&cTrop d'arguments."), - BAD_ARGUMENT("&cMauvais argument : '%s'"), - PLAYER_NOT_FOUND("&cLe joueur %s n'est pas connecté."), - GROUP_NOT_FOUND("&e%s &cn'existe pas dans la base de données !"), - PLAYER_NOT_IN_GROUP("&e%s&c n'est pas dans ce groupe."), - PLAYER_ALREADY_IN_GROUP("&cLe joueur %s est déjà dans ce groupe."), - GROUP_ALREADY_EXISTS("&e%s &cexiste déjà dans la base de données !"), - COULD_NOT_REACH_DATABASE("&cBase de données inaccessible."), - BAD_DURATION("&cMauvaise durée donnée : '%s'"); - - private String msg = ""; - ErrorMessages(String s) { - msg = s; - } - public String get() { - return msg; - } - - public String format(String... args) { - return msg.formatted(args); - } - } - - public static void sendGroupHelp(CommandSender player) { - MessageUtils.sendMessage(player, MessageUtils.ChatPrefix.PLUGIN, "&3&l======= AIDE ======="); - - MessageUtils.sendMessage(player, " &8» &e/gperms groups &3Afficher les groupes"); - MessageUtils.sendMessage(player, " &8» &e/gperms &3Afficher les infos sur "); - MessageUtils.sendMessage(player, " &8» &e/gperms add &3Ajoute à "); - MessageUtils.sendMessage(player, " &8» &e/gperms remove &3Supprime de "); - MessageUtils.sendMessage(player, " &8» &e/gperms + &3Ajoute une permission au joueur"); - MessageUtils.sendMessage(player, " &8» &e/gperms setPrefix [newPrefix] &3Change ou annule le préfixe du groupe (entre ')"); - MessageUtils.sendMessage(player, " &8» &e/gperms - &3Retire une permission au joueur"); - MessageUtils.sendMessage(player, ""); - MessageUtils.sendMessage(player, " &8» &e/gperms add &3Crée un groupe"); - MessageUtils.sendMessage(player, " &8» &e/gperms remove &3Supprime un groupe"); - } - - public static void sendPlayerHelp(CommandSender player) { - MessageUtils.sendMessage(player, MessageUtils.ChatPrefix.PLUGIN, "&3&l======= AIDE ======="); - - MessageUtils.sendMessage(player, " &8» &e/pperms &3Afficher les groupes du joueur"); - MessageUtils.sendMessage(player, " &8» &e/pperms + &3Ajoute une permission au joueur"); - MessageUtils.sendMessage(player, " &8» &e/pperms setPrefix [newPrefix] &3Change ou réinitialise le préfixe du joueur (entre ')"); - MessageUtils.sendMessage(player, " &8» &e/pperms - &3Retire une permission au joueur"); - } - - // TODO: ajouter des infos ? - public static void printPlayerInfoTo(CommandSender to, Player player) { - MessageUtils.sendMessage(to, MessageUtils.ChatPrefix.PLUGIN, "&3======= &r%s&l%s &3=======".formatted(player.isOnline() ? "&a" : "&4", player.getName())); - // ew. - MessageUtils.sendMessage(to, " &8• Groupes : " + String.join(", ", - ECATUP.getInstance() - .getPlayerManager() - .getPlayer(player) - .getAnimusPlayer() - .getPermGroups() - .stream().map(PermGroupPlayer::getName) - .toList() - )); - } - - public static void printGroupInfoTo(CommandSender to, PermGroup group) { - MessageUtils.sendMessage(to, MessageUtils.ChatPrefix.PLUGIN, "&3======= &r&l%s &r&3=======".formatted(group.getName())); - // ew. - MessageUtils.sendMessage(to, " &8• Préfixe : &r%s".formatted(group.getPrefix())); - MessageUtils.sendMessage(to, " &8• Priorité : &r%s".formatted(group.getPriority())); - PermGroup parentGroup = ECATUP.getInstance().getGroupManager().getGroup(group.getParentGroupId()); - MessageUtils.sendMessage(to, " &8• Group parent : &r%s".formatted( - parentGroup == null ? "Aucun" : (parentGroup.getName() + " &8&o(id " + parentGroup.getId() + ")") - )); - - if (group.getPermissions().isEmpty()) - MessageUtils.sendMessage(to, " &8• &cAucune permission."); - else { - MessageUtils.sendMessage(to, " &8• Permission(s) :"); - final int displayed = 10; // Nombre de permissions affichées dans le tchat - for (int i = 0; i < Math.min(group.getPermissions().size(), displayed); i++) { - MessageUtils.sendMessage(to, " &8- &r%s".formatted(group.getPermissions().get(i).getName().replaceAll("\\*", "&e*&r"))); - } - if (group.getPermissions().size() > displayed) - MessageUtils.sendMessage(to, " &8&o...%s en plus".formatted(group.getPermissions().size() - displayed)); - } - - MessageUtils.sendMessage(to, " &8• Groupe par défaut ? " + (group.isDefaultGroup() ? "&a&oOui" : "&c&oNon")); - } - -} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/permissions/GroupsCom.java b/src/main/java/fr/efreicraft/ecatup/commands/permissions/GroupsCom.java deleted file mode 100644 index 9b3a0ed..0000000 --- a/src/main/java/fr/efreicraft/ecatup/commands/permissions/GroupsCom.java +++ /dev/null @@ -1,244 +0,0 @@ -package fr.efreicraft.ecatup.commands.permissions; - -import fr.efreicraft.animus.endpoints.PermGroupService; -import fr.efreicraft.animus.endpoints.PlayerService; -import fr.efreicraft.animus.invoker.ApiException; -import fr.efreicraft.animus.models.PermGroup; -import fr.efreicraft.animus.models.PermGroupPlayer; -import fr.efreicraft.animus.models.PermissionInput; -import fr.efreicraft.ecatup.ECATUP; -import fr.efreicraft.ecatup.players.ECPlayer; -import fr.efreicraft.ecatup.utils.MessageUtils; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.JoinConfiguration; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabExecutor; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.List; -import java.util.NoSuchElementException; -import java.util.Optional; - -import static fr.efreicraft.ecatup.commands.permissions.Common.ErrorMessages.*; - -public class GroupsCom implements TabExecutor { - @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if (args.length < 1) { - Common.sendGroupHelp(sender); - return true; - } else if (args[0].equalsIgnoreCase("groups")) { - try { - List permGroups = PermGroupService.getPermGroups(); - - MessageUtils.sendMessage(sender, MessageUtils.ChatPrefix.PLUGIN, "&3======= GROUPS &3======="); - for (PermGroup group : permGroups) { - MessageUtils.sendMessage(sender, " &8• &e&l%s &r&8(%s&r&8)".formatted(group.getName(), group.getPrefix())); - } - } catch (ApiException e) { - MessageUtils.sendMessage(sender, COULD_NOT_REACH_DATABASE.get()); - } - return true; - } - - // Setup arg0 qui est le groupe - PermGroup group = null; - if (!("add".equalsIgnoreCase(args[0]) || "remove".equalsIgnoreCase(args[0]) || "groups".equalsIgnoreCase(args[0]))) { - try { - Optional maybeGroup; - maybeGroup = PermGroupService.getPermGroups().stream().filter(permGroup -> permGroup.getName().equalsIgnoreCase(args[0])).findFirst(); - if (maybeGroup.isEmpty()) { - MessageUtils.sendMessage(sender, GROUP_NOT_FOUND.format(args[0])); - return true; - } else - group = maybeGroup.get(); - - } catch (ApiException e) { - MessageUtils.sendMessage(sender, COULD_NOT_REACH_DATABASE.get()); - return true; - } - } - - //Setup arg2 qui est le joueur - Player target = null; - if (args.length > 2) - if ("add".equalsIgnoreCase(args[2]) || "remove".equalsIgnoreCase(args[2])) - target = Bukkit.getPlayer(args[2]); - else - if ("add".equalsIgnoreCase(args[2]) || "remove".equalsIgnoreCase(args[2])) { - MessageUtils.sendMessage(sender, NOT_ENOUGH_ARGUMENTS.get()); - } - - switch (args.length) { - // Info groupes - case 1 -> { - if ("groups".equalsIgnoreCase(args[0])) - printGroups(sender); - } - // Créer/supprimer un groupe OU obtenir des infos sur un groupe - // ...OU reset préfixe - // OU ajouter/supprimer une perm - case 2 -> { - if ("add".equalsIgnoreCase(args[0])) { - try { - if (ECATUP.getInstance().getGroupManager().getGroup(args[1]) == null) { - PermGroupService.createPermGroup(args[1], "", "", false, false); - MessageUtils.sendMessage(sender, "&aLe groupe &e%s &aa bien été créé !".formatted(args[1])); - } else { - MessageUtils.sendMessage(sender, GROUP_ALREADY_EXISTS.format(args[1])); - } - } catch (ApiException e) { - MessageUtils.sendMessage(sender, COULD_NOT_REACH_DATABASE.get()); - } - } else if ("remove".equalsIgnoreCase(args[0])) { - removeGroup(args[1], sender); - } else { - String permission = args[1].substring(1); - if (args[1].charAt(0) == '+') { - try { - PermGroupService.addPermsToGroup(group.getId(), List.of(new PermissionInput().name(permission))); - ECATUP.getInstance().getPlayerManager().getPlayersInGroup(group).forEach(player -> player.updatePermission(permission, true)); - - MessageUtils.sendMessage(sender, "&8[&a+&8] &e%s &8<- &e%s".formatted(group.getName(), permission)); - } catch (ApiException e) { - MessageUtils.sendMessage(sender, COULD_NOT_REACH_DATABASE.get()); - } - } else if (args[1].charAt(0) == '-') { - try { - PermGroupService.removePermsOfGroup(group.getId(), List.of(permission)); - ECATUP.getInstance().getPlayerManager().getPlayersInGroup(group).forEach(ECPlayer::addPlayerPermissions); - MessageUtils.sendMessage(sender, "&8[&4-&8] &e%s &8<- &e%s".formatted(group.getName(), permission)); - } catch (ApiException e) { - MessageUtils.sendMessage(sender, COULD_NOT_REACH_DATABASE.get()); - } - } else if (args[1].equalsIgnoreCase("setPrefix")) { - try { - PermGroupService.updatePermGroup(group.getId(), null, args[2] + " ", null, null, false, true); - } catch (ApiException e) { - MessageUtils.sendMessage(sender, COULD_NOT_REACH_DATABASE.get()); - } - } else { - MessageUtils.sendMessage(sender, BAD_ARGUMENT.format(args[1])); - } - } - } - - // Ajouter/Supprimer un joueur d'un groupe - case 3 -> { - if ("add".equalsIgnoreCase(args[1])) { - if (target == null) { - MessageUtils.sendMessage(sender, PLAYER_NOT_FOUND.format(args[2])); - return true; - } - if (ECATUP.getInstance() - .getPlayerManager() - .getPlayer(target) - .getAnimusPlayer() - .getPermGroups().stream().map(PermGroupPlayer::getName).toList().contains(group.getName())) { - MessageUtils.sendMessage(sender, PLAYER_ALREADY_IN_GROUP.format(target.getName())); - return true; - } - - try { - PlayerService.addToGroup(target.getUniqueId().toString(), group.getName()); - MessageUtils.sendMessage(sender, "&aLe joueur &e%s &aa bien été ajouté au groupe &e%s &a!".formatted(target.getName(), group.getName())); - } catch (ApiException e) { - MessageUtils.sendMessage(sender, COULD_NOT_REACH_DATABASE.get()); - return true; - } - } else if ("remove".equalsIgnoreCase(args[1])) { - if (target == null) { - MessageUtils.sendMessage(sender, PLAYER_NOT_FOUND.format(args[2])); - return true; - } - if (ECATUP.getInstance() - .getPlayerManager() - .getPlayer(target) - .getAnimusPlayer() - .getPermGroups().stream().map(PermGroupPlayer::getName).toList().contains(group.getName())) { - MessageUtils.sendMessage(sender, PLAYER_ALREADY_IN_GROUP.format(target.getName())); - return true; - } - - try { - PlayerService.addToGroup(target.getUniqueId().toString(), group.getName()); - MessageUtils.sendMessage(sender, "&aLe joueur &e%s &aa bien été ajouté au groupe &e%s &a!".formatted(target.getName(), group.getName())); - } catch (ApiException e) { - MessageUtils.sendMessage(sender, COULD_NOT_REACH_DATABASE.get()); - return true; - } - } - } - } - - return true; - } - - @Override - public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - List specialArgList = List.of("groups", "add", "remove", ""); - - if (args.length == 1) { - return specialArgList; - } else if (args.length == 2) { - if (!specialArgList.contains(args[0])) return List.of("+", "setPrefix", "-"); - } - return new ArrayList<>(); - } - - public static void printGroups(CommandSender to) { - List permGroups; - try { - permGroups = PermGroupService.getPermGroups(); - } catch (ApiException e) { - MessageUtils.sendMessage(to, COULD_NOT_REACH_DATABASE.get()); - return; - } - - MessageUtils.sendMessage(to, MessageUtils.ChatPrefix.PLUGIN, "&3======= GROUPES &3======="); - - Component.join(JoinConfiguration.separators(Component.text("&8, "), Component.text(" &8et ")), - permGroups.stream().map(permGroup -> Component.text("&a%s".formatted(permGroup.getName()))).toList() - ); - } - - public static void removeGroup(String groupName, CommandSender sender) { - //TODO réviser la logique de suppression de groupe - - if (sender == null) sender = Bukkit.getConsoleSender(); - - // Toutes les autres perms qui ne sont pas dans le groupe à supprimer - List allOtherPerms = new ArrayList<>(); - try { - List permGroupList = PermGroupService.getPermGroups(); - - PermGroup groupToDelete = ECATUP.getInstance().getGroupManager().getGroup(groupName); - if (groupToDelete == null) throw new NoSuchElementException(); - - PermGroupService.deletePermGroup(groupToDelete.getId()); - - for (PermGroup permGroup : permGroupList) { - if (!permGroup.getName().equalsIgnoreCase(groupName)) { - allOtherPerms.addAll(permGroup.getPermissions()); - } - } - } catch (ApiException ignored) { - MessageUtils.sendMessage(sender, "&cPas pu accéder à la base de données pour supprimer le groupe."); - return; - } catch (NoSuchElementException ignored) { - MessageUtils.sendMessage(sender, "&cCe groupe n'existe pas dans la base de données !"); - return; - } - - for (ECPlayer ecPlayer : ECATUP.getInstance().getPlayerManager().getPlayers()) { - List permGroups = ecPlayer.getAnimusPlayer().getPermGroups(); - permGroups.removeIf(grp -> grp.getName().equalsIgnoreCase(groupName)); - ecPlayer.getAnimusPlayer().setPermGroups(permGroups); - } - } -} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/permissions/PlayersCom.java b/src/main/java/fr/efreicraft/ecatup/commands/permissions/PlayersCom.java deleted file mode 100644 index 2ae2bd1..0000000 --- a/src/main/java/fr/efreicraft/ecatup/commands/permissions/PlayersCom.java +++ /dev/null @@ -1,113 +0,0 @@ -package fr.efreicraft.ecatup.commands.permissions; - -import fr.efreicraft.animus.endpoints.PlayerService; -import fr.efreicraft.animus.invoker.ApiException; -import fr.efreicraft.animus.models.PermissionInput; -import fr.efreicraft.ecatup.ECATUP; -import fr.efreicraft.ecatup.utils.MessageUtils; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabExecutor; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.List; - -import static fr.efreicraft.ecatup.commands.permissions.Common.ErrorMessages.*; - -public class PlayersCom implements TabExecutor { - - private static final List NEVER_EXPIRE = List.of( - "null", - "never", - "-1", - "0", - "jamais" - ); - - @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if (args.length == 0) { - Common.sendPlayerHelp(sender); - return true; - } - - Player target = Bukkit.getPlayer(args[0]); - - if (target == null) { - MessageUtils.sendMessage(sender, MessageUtils.ChatPrefix.PLUGIN, PLAYER_NOT_FOUND.format(args[0])); - return true; - } - - switch (args.length) { - // Info joueur - case 1 -> Common.printPlayerInfoTo(sender, target); - - case 2 -> { - if (args[1].startsWith("+")) { - String permission = args[1].substring(1); - try { - PlayerService.addPermissions(target.getUniqueId().toString(), List.of(new PermissionInput().name(permission))); - ECATUP.getInstance().getPlayerManager().getPlayer(target).updatePermission(permission, true); - } catch (ApiException e) { - MessageUtils.sendMessage(sender, COULD_NOT_REACH_DATABASE.get()); - Bukkit.getLogger().severe("=== ERREUR API ==="); - Bukkit.getLogger().severe("%s a essayé d'ajouter la permission '%s' à %s".formatted(sender.getName(), permission, target.getName())); - Bukkit.getLogger().severe("Message d'exception API : %s".formatted(e.getMessage())); - Bukkit.getLogger().severe("Code de réponse API : %s".formatted(e.getCode())); - return true; - } - - // Message de succès - MessageUtils.sendMessage(sender, "&8[&a+&8] &e%s &8<- &e%s".formatted(target.getName(), permission)); - } - else if (args[1].startsWith("-")) { - String permission = args[1].substring(1); - try { - PermissionInput permissionInput = new PermissionInput().name(permission); - - PlayerService.revokePermissions(target.getUniqueId().toString(), List.of(permissionInput)); - ECATUP.getInstance().getPlayerManager().getPlayer(target).addPlayerPermissions(); - } catch (ApiException e) { - MessageUtils.sendMessage(sender, COULD_NOT_REACH_DATABASE.get()); - Bukkit.getLogger().severe("=== ERREUR API ==="); - Bukkit.getLogger().severe("%s a essayé de révoquer la permission '%s' à %s".formatted(sender.getName(), permission, target.getName())); - Bukkit.getLogger().severe("Message d'exception API : %s".formatted(e.getMessage())); - Bukkit.getLogger().severe("Code de réponse API : %s".formatted(e.getCode())); - return true; - } - - // Message de succès - MessageUtils.sendMessage(sender, "&8[&4-&8] &e%s &8<- &e%s".formatted(target.getName(), permission)); - } else if (args[1].equalsIgnoreCase("setPrefix")) { - //TODO: préfixes joueurs ajoutés ?? - MessageUtils.sendMessage(sender, "&cSoon..."); - } - else { - MessageUtils.sendMessage(sender, BAD_ARGUMENT.format(args[1])); - } - } - - // Ajout de préfixe OU ajout de perm avec contexte - case 3 -> { - if (args[1].equalsIgnoreCase("setPrefix")) { - //TODO: préfixes joueurs ajoutés ?? - } else - Common.sendPlayerHelp(sender); - } - - default -> Common.sendPlayerHelp(sender); - } - return true; - } - @Override - public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if (args.length == 2) - return List.of("+", "setPrefix", "-"); - return new ArrayList<>(); - } - -} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/speeds/FlySpeed.java b/src/main/java/fr/efreicraft/ecatup/commands/speeds/FlySpeed.java deleted file mode 100644 index d470778..0000000 --- a/src/main/java/fr/efreicraft/ecatup/commands/speeds/FlySpeed.java +++ /dev/null @@ -1,108 +0,0 @@ -package fr.efreicraft.ecatup.commands.speeds; - -import fr.efreicraft.ecatup.utils.Msg; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabExecutor; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.text.NumberFormat; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.List; - -public class FlySpeed implements CommandExecutor, TabExecutor { - @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if (args.length >= 1) { - Player p = Bukkit.getPlayer(args[0]); - if (p != null) { - sender.sendMessage(Msg.colorize("&7Vitesse de vol de " + p.getName() + " actuelle : &r&l" + (int) (p.getFlySpeed() * 10))); - return true; - } - } - if (!(sender instanceof Player self)) { - sender.sendMessage("Vous n'êtes pas un joueur !"); - return true; - } - if (args.length < 1) { - self.sendMessage(Msg.colorize("&7Vitesse de vol actuelle : &r&l" + (int) (self.getFlySpeed() * 10))); - } else { - if (args.length == 1) { - - float num; - try { - if (args[0].equalsIgnoreCase("reset") || args[0].equalsIgnoreCase("r")) { - self.setFlySpeed(0.1f); - self.sendMessage(Msg.colorize("&7Vitesse de vol réinitialisée.")); - return true; - } - num = NumberFormat.getInstance().parse(args[0]).floatValue(); - } catch (ParseException ignored) { - sender.sendMessage(Msg.colorize("&c\"" + args[0] + "\" n'est pas un nombre, ni \"reset\" !")); - return true; - } - - if (num > 10) { - sender.sendMessage(Msg.colorize("&cVotre vitesse doit être comprise entre -10 et 10 !\n &7&o→ Elle a été mise à &a&o10")); - self.setFlySpeed(1); - } else if (num < -10) { - sender.sendMessage(Msg.colorize("&cVotre vitesse doit être comprise entre -10 et 10 !\n &7&o→ Elle a été mise à &a&o-10")); - self.setFlySpeed(-1); - } else { - sender.sendMessage(Msg.colorize("&7Votre vitesse de vol a été réglée à &r" + num)); - self.setFlySpeed(num / 10); - } - } else { - List players; - try { - players = Bukkit.selectEntities(sender, args[1]).stream() - .filter(entity -> entity instanceof Player) - .map(entity -> (Player) entity) - .toList(); - } catch (IllegalArgumentException ignored) { - sender.sendMessage(Msg.colorize("&cMauvais sélecteur &o" + args[1])); - return true; - } - - float num; - try { - if (args[0].equalsIgnoreCase("reset") || args[0].equalsIgnoreCase("r")) { - players.forEach(player -> player.setFlySpeed(0.1f)); - sender.sendMessage(Msg.colorize("&7Vitesses de vol réinitialisées.")); - return true; - } - num = NumberFormat.getInstance().parse(args[0]).floatValue(); - } catch (ParseException ignored) { - sender.sendMessage(Msg.colorize("&c\"" + args[0] + "\" n'est pas un nombre, ni \"reset\" !")); - return false; - } - - if (num > 10) { - sender.sendMessage(Msg.colorize("&cLa vitesse doit être comprise entre -10 et 10 !\n &7&o→ Elle a été mise à &a&o10")); - players.forEach(player -> player.setFlySpeed(1)); - } else if (num < -10) { - sender.sendMessage(Msg.colorize("&cLa vitesse doit être comprise entre -10 et 10 !\n &7&o→ Elle a été mise à &a&o-10")); - players.forEach(player -> player.setFlySpeed(-1)); - } else { - sender.sendMessage(Msg.colorize("&7Vitesse de vol de %s réglée à %s".formatted(args[1].replace("@a", "tout le monde"), num) )); - players.forEach(player -> player.setFlySpeed(num / 10)); - } - } - } - - return true; - } - - @Override - public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if (args.length == 1) return List.of("reset"); - if (args.length != 2) return new ArrayList<>(); - - return null; - } -} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/speeds/ResetSpeed.java b/src/main/java/fr/efreicraft/ecatup/commands/speeds/ResetSpeed.java deleted file mode 100644 index 41ffc66..0000000 --- a/src/main/java/fr/efreicraft/ecatup/commands/speeds/ResetSpeed.java +++ /dev/null @@ -1,54 +0,0 @@ -package fr.efreicraft.ecatup.commands.speeds; - -import fr.efreicraft.ecatup.utils.Msg; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabExecutor; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.List; - -public class ResetSpeed implements CommandExecutor, TabExecutor { - @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if (args.length > 1) - return false; - else if (args.length == 1) { - try { - List players = Bukkit.selectEntities(sender, args[0]).stream() - .filter(entity -> entity instanceof Player) - .map(entity -> (Player) entity) - .toList(); - players.forEach(player -> { - player.setFlySpeed(0.1f); - player.setWalkSpeed(0.2f); - player.sendMessage(Msg.colorize("&7Vos vitesses ont été réinitialisées par " + sender.getName())); - }); - sender.sendMessage(Msg.colorize("&7Vitesses de %s réinitialisées.".formatted(args[0].replace("@a", "tout le monde")) )); - } catch (IllegalArgumentException ignored) { - sender.sendMessage(Msg.colorize("&cMauvais sélecteur &o" + args[0])); - } - } else { - if (!(sender instanceof Player player)) { - sender.sendMessage("Vous n'êtes pas un joueur !"); - return true; - } - player.setFlySpeed(0.1f); - player.setWalkSpeed(0.2f); - sender.sendMessage(Msg.colorize("&7Vitesses réinitialisées.")); - } - return true; - } - - @Override - public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if (args.length != 1) return new ArrayList<>(); - - return null; - } -} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/speeds/WalkSpeed.java b/src/main/java/fr/efreicraft/ecatup/commands/speeds/WalkSpeed.java deleted file mode 100644 index 75f80d9..0000000 --- a/src/main/java/fr/efreicraft/ecatup/commands/speeds/WalkSpeed.java +++ /dev/null @@ -1,108 +0,0 @@ -package fr.efreicraft.ecatup.commands.speeds; - -import fr.efreicraft.ecatup.utils.Msg; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabExecutor; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.text.NumberFormat; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.List; - -public class WalkSpeed implements CommandExecutor, TabExecutor { - @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if (args.length >= 1) { - Player p = Bukkit.getPlayer(args[0]); - if (p != null) { - sender.sendMessage(Msg.colorize("&7Vitesse de marche de " + p.getName() + " actuelle : &r&l" + (int) (p.getFlySpeed() * 10))); - return true; - } - } - if (!(sender instanceof Player self)) { - sender.sendMessage("Vous n'êtes pas un joueur !"); - return true; - } - if (args.length < 1) { - self.sendMessage(Msg.colorize("&7Vitesse de marche actuelle : &r&l" + (int) (self.getFlySpeed() * 10))); - } else { - if (args.length == 1) { - - float num; - try { - if (args[0].equalsIgnoreCase("reset") || args[0].equalsIgnoreCase("r")) { - self.setWalkSpeed(0.2f); - self.sendMessage(Msg.colorize("&7Vitesse de marche réinitialisée.")); - return true; - } - num = NumberFormat.getInstance().parse(args[0]).floatValue(); - } catch (ParseException ignored) { - sender.sendMessage(Msg.colorize("&c\"" + args[0] + "\" n'est pas un nombre, ni \"reset\" !")); - return true; - } - - if (num > 10) { - sender.sendMessage(Msg.colorize("&cVotre vitesse doit être comprise entre -10 et 10 !\n &7&o→ Elle a été mise à &a&o10")); - self.setWalkSpeed(1); - } else if (num < -10) { - sender.sendMessage(Msg.colorize("&cVotre vitesse doit être comprise entre -10 et 10 !\n &7&o→ Elle a été mise à &a&o-10")); - self.setWalkSpeed(-1); - } else { - sender.sendMessage(Msg.colorize("&7Votre vitesse de marche a été réglée à &r" + num)); - self.setWalkSpeed(num / 10); - } - } else { - List players; - try { - players = Bukkit.selectEntities(sender, args[1]).stream() - .filter(entity -> entity instanceof Player) - .map(entity -> (Player) entity) - .toList(); - } catch (IllegalArgumentException ignored) { - sender.sendMessage(Msg.colorize("&cMauvais sélecteur &o" + args[1])); - return true; - } - - float num; - try { - if (args[0].equalsIgnoreCase("reset") || args[0].equalsIgnoreCase("r")) { - players.forEach(player -> player.setWalkSpeed(0.2f)); - sender.sendMessage(Msg.colorize("&7Vitesses de marche réinitialisées.")); - return true; - } - num = NumberFormat.getInstance().parse(args[0]).floatValue(); - } catch (ParseException ignored) { - sender.sendMessage(Msg.colorize("&c\"" + args[0] + "\" n'est pas un nombre, ni \"reset\" !")); - return false; - } - - if (num > 10) { - sender.sendMessage(Msg.colorize("&cLa vitesse doit être comprise entre -10 et 10 !\n &7&o→ Elle a été mise à &a&o10")); - players.forEach(player -> player.setWalkSpeed(1)); - } else if (num < -10) { - sender.sendMessage(Msg.colorize("&cLa vitesse doit être comprise entre -10 et 10 !\n &7&o→ Elle a été mise à &a&o-10")); - players.forEach(player -> player.setWalkSpeed(-1)); - } else { - sender.sendMessage(Msg.colorize("&7Vitesse de marche de %s réglée à %s".formatted(args[1].replace("@a", "tout le monde"), num) )); - players.forEach(player -> player.setWalkSpeed(num / 10)); - } - } - } - - return true; - } - - @Override - public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if (args.length == 1) return List.of("reset"); - if (args.length != 2) return new ArrayList<>(); - - return null; - } -} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/validator/NotTheSamePlayer.java b/src/main/java/fr/efreicraft/ecatup/commands/validator/NotTheSamePlayer.java new file mode 100644 index 0000000..5692a6d --- /dev/null +++ b/src/main/java/fr/efreicraft/ecatup/commands/validator/NotTheSamePlayer.java @@ -0,0 +1,11 @@ +package fr.efreicraft.ecatup.commands.validator; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.PARAMETER) +public @interface NotTheSamePlayer { +} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/validator/NotTheSamePlayerValidator.java b/src/main/java/fr/efreicraft/ecatup/commands/validator/NotTheSamePlayerValidator.java new file mode 100644 index 0000000..4e1f8f7 --- /dev/null +++ b/src/main/java/fr/efreicraft/ecatup/commands/validator/NotTheSamePlayerValidator.java @@ -0,0 +1,28 @@ +package fr.efreicraft.ecatup.commands.validator; + +import dev.rollczi.litecommands.annotations.validator.requirment.AnnotatedValidator; +import dev.rollczi.litecommands.command.executor.CommandExecutor; +import dev.rollczi.litecommands.invocation.Invocation; +import dev.rollczi.litecommands.requirement.Requirement; +import dev.rollczi.litecommands.validator.ValidatorResult; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class NotTheSamePlayerValidator implements AnnotatedValidator { + + @Override + public ValidatorResult validate( + Invocation invocation, + CommandExecutor executor, + Requirement requirement, + Player player, + NotTheSamePlayer annotation + ) { + if (invocation.sender() == player) { + return ValidatorResult.invalid("Vous ne pouvez pas vous cibler vous-même."); + } + + return ValidatorResult.valid(); + } + +} \ No newline at end of file diff --git a/src/main/java/fr/efreicraft/ecatup/commands/validator/Speed.java b/src/main/java/fr/efreicraft/ecatup/commands/validator/Speed.java new file mode 100644 index 0000000..c661381 --- /dev/null +++ b/src/main/java/fr/efreicraft/ecatup/commands/validator/Speed.java @@ -0,0 +1,11 @@ +package fr.efreicraft.ecatup.commands.validator; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.PARAMETER) +public @interface Speed { +} diff --git a/src/main/java/fr/efreicraft/ecatup/commands/validator/SpeedValidator.java b/src/main/java/fr/efreicraft/ecatup/commands/validator/SpeedValidator.java new file mode 100644 index 0000000..dd3280b --- /dev/null +++ b/src/main/java/fr/efreicraft/ecatup/commands/validator/SpeedValidator.java @@ -0,0 +1,27 @@ +package fr.efreicraft.ecatup.commands.validator; + +import dev.rollczi.litecommands.annotations.validator.requirment.AnnotatedValidator; +import dev.rollczi.litecommands.command.executor.CommandExecutor; +import dev.rollczi.litecommands.invocation.Invocation; +import dev.rollczi.litecommands.requirement.Requirement; +import dev.rollczi.litecommands.validator.ValidatorResult; +import org.bukkit.command.CommandSender; + +public class SpeedValidator implements AnnotatedValidator { + + @Override + public ValidatorResult validate( + Invocation invocation, + CommandExecutor executor, + Requirement requirement, + Float speed, + Speed annotation + ) { + if (speed < -10 || speed > 10) { + return ValidatorResult.invalid("Valeur invalide! La vitesse doit être comprise entre -10 et 10."); + } + + return ValidatorResult.valid(); + } + +} \ No newline at end of file diff --git a/src/main/java/fr/efreicraft/ecatup/listeners/ChatListener.java b/src/main/java/fr/efreicraft/ecatup/listeners/ChatListener.java index 729a539..3aaf0a4 100644 --- a/src/main/java/fr/efreicraft/ecatup/listeners/ChatListener.java +++ b/src/main/java/fr/efreicraft/ecatup/listeners/ChatListener.java @@ -1,55 +1,14 @@ package fr.efreicraft.ecatup.listeners; -import com.google.common.io.ByteArrayDataInput; -import com.google.common.io.ByteStreams; import fr.efreicraft.ecatup.ECATUP; import fr.efreicraft.ecatup.players.ECPlayer; import fr.efreicraft.ecatup.utils.MessageUtils; import io.papermc.paper.event.player.AsyncChatEvent; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.event.ClickEvent; -import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.plugin.messaging.PluginMessageListener; -import org.jetbrains.annotations.NotNull; -import java.time.Clock; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; - -import static fr.efreicraft.ecatup.utils.Msg.colorize; - -@SuppressWarnings("ALL") -public class ChatListener implements Listener, PluginMessageListener { - - - @Override - public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) { - if (!channel.equals("BungeeCord")) return; - ByteArrayDataInput in = ByteStreams.newDataInput(message); - String subchannel = in.readUTF(); - if (!subchannel.equals("ecatup:globalchat")) return; - - in.readShort(); - - String msg = "§e" + in.readUTF(); - Bukkit.getLogger().severe(msg); - - StringBuilder msgCopie = new StringBuilder(msg); - while (msgCopie.indexOf("§") != -1) msgCopie.delete(msgCopie.indexOf("§"), msgCopie.indexOf("§") + 2); - - final String WHAT_TIME_IS_IT = " @ {" + LocalDateTime.now(Clock.systemUTC()).format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss")) + "UTC}"; - - Component component = Component.text(colorize(msg)) - .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, Component.text("Copier"))) - .clickEvent(ClickEvent.copyToClipboard(msgCopie + WHAT_TIME_IS_IT)); - - Bukkit.broadcast(component); - } +public class ChatListener implements Listener { @EventHandler public void onChat(AsyncChatEvent event) { @@ -57,75 +16,4 @@ public void onChat(AsyncChatEvent event) { ECPlayer player = ECATUP.getInstance().getPlayerManager().getPlayer(event.getPlayer()); MessageUtils.broadcastMessage(player.getChatName() + "&8: &f" + LegacyComponentSerializer.legacyAmpersand().serialize(event.message())); } - - /*@EventHandler - public void onChat(AsyncChatEvent event) throws IOException { - event.setCancelled(true); - - //TODO fix ça en obtenant ecatup.chat.color - boolean coloriseText = false; - - PreferenceCache.ChatChannel channelActuel = PreferenceCache.getChannel(event.getPlayer().getUniqueId()); - - Component channelPrefix = Component.text(channelActuel == PreferenceCache.ChatChannel.SERVER ? "" : ("["+channelActuel+"] ")).color(NamedTextColor.YELLOW); - Component msg = event.getPlayer().displayName() - .append(Component.text(ChatColor.GRAY + ": ")) - .append(coloriseText ? Component.text(colorize((TextComponent) event.message())) : event.message()) - .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, Component.text("Copier"))); - - final String WHAT_TIME_IS_IT = " @ {" + LocalDateTime.now(Clock.systemUTC()).format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss")) + "UTC}"; - - // LORE: msgCopie c'est ce que tu obtiens avec le clic gauche. msgGlobal c'est msgCopie mais AVEC les couleurs - // de sorte que je puisse le transmettre facilement sur d'autres serveurs. - StringBuilder msgCopie = new StringBuilder(new String("["+channelActuel.toString()+"] ")).append(((TextComponent) msg).content()); - StringBuilder msgGlobal = new StringBuilder(new String("["+channelActuel.toString()+"] ")).append(((TextComponent) msg).content()); - - msgGlobal = msgGlobal.append("§7: §r").append(coloriseText ? colorize(((TextComponent) event.message()).content()) : ((TextComponent) event.message()).content()); - - // Les messages Minecraft font au max 255 caractères, c'est pas très grave de les parcourir plusieurs fois. - while (msgCopie.indexOf("§") != -1) msgCopie.delete(msgCopie.indexOf("§"), msgCopie.indexOf("§") + 2); - - // Send log to Discord - DiscordWebhook webhook = new DiscordWebhook(ECATUP.getInstance().getConfig().getString("webhook")); - String name = event.getPlayer().getName(); - String message = ((TextComponent)event.message()).content(); - webhook.setContent(""); - webhook.addEmbed(new DiscordWebhook.EmbedObject() - .setTitle("Message") - .setDescription("["+channelActuel+"] " + "**" + name + "** : " + message) - .setColor(Color.decode("#3498db")) - .setFooter("Efrei Craft", "https://efreicraft.fr/img/favicon.png") - ); - webhook.execute(); - switch (channelActuel) { - case GLOBAL -> { - ECATUP.sendGlobalChat(msgGlobal.toString(), event.getPlayer()); - Bukkit.broadcast(Component.join(JoinConfiguration.noSeparators(),channelPrefix,msg - .clickEvent(ClickEvent.copyToClipboard(msgCopie + ": " + ((TextComponent)event.message()).content() + WHAT_TIME_IS_IT)))); - } - case SERVER -> Bukkit.broadcast(Component.join(JoinConfiguration.noSeparators(), channelPrefix, msg - .clickEvent(ClickEvent.copyToClipboard(msgCopie + ": " + ((TextComponent)event.message()).content() + WHAT_TIME_IS_IT)))); - case TEAM -> { - if (event.getPlayer().getScoreboardTags().isEmpty()) { - Bukkit.broadcast(Component.join(JoinConfiguration.noSeparators(),channelPrefix,msg - .clickEvent(ClickEvent.copyToClipboard(msgCopie + ": " + ((TextComponent)event.message()).content() + WHAT_TIME_IS_IT)))); - } else { - Team team = Bukkit.getScoreboardManager().getMainScoreboard().getPlayerTeam(event.getPlayer()); - - if (team == null) { - event.getPlayer().sendMessage(msg - .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, Component.text("Copier"))) - .clickEvent(ClickEvent.copyToClipboard(msgCopie + ": " + ((TextComponent) event.message()).content() + WHAT_TIME_IS_IT))); - return; - } - - for (String playerName : team.getEntries()) { - if (Bukkit.getPlayer(playerName) != null) Bukkit.getPlayer(playerName).sendMessage(Component.join(JoinConfiguration.noSeparators(),channelPrefix, msg - .clickEvent(ClickEvent.copyToClipboard(msgCopie + ": " + ((TextComponent) event.message()).content() + WHAT_TIME_IS_IT)))); - } - } - } - } - - }*/ } diff --git a/src/main/java/fr/efreicraft/ecatup/players/ECPlayer.java b/src/main/java/fr/efreicraft/ecatup/players/ECPlayer.java index 87066a9..72095ea 100644 --- a/src/main/java/fr/efreicraft/ecatup/players/ECPlayer.java +++ b/src/main/java/fr/efreicraft/ecatup/players/ECPlayer.java @@ -13,6 +13,7 @@ import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Sound; +import org.bukkit.entity.Player; import org.bukkit.help.HelpTopic; import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionAttachment; @@ -294,4 +295,8 @@ public List getPermissions() { public PlayerStatisticsManager getStatisticsManager() { return statisticsManager; } + + public static ECPlayer get(Player player) { + return ECATUP.getInstance().getPlayerManager().getPlayer(player); + } } diff --git a/src/main/java/fr/efreicraft/ecatup/utils/DiscordWebhook.java b/src/main/java/fr/efreicraft/ecatup/utils/DiscordWebhook.java deleted file mode 100644 index 32f8963..0000000 --- a/src/main/java/fr/efreicraft/ecatup/utils/DiscordWebhook.java +++ /dev/null @@ -1,396 +0,0 @@ -package fr.efreicraft.ecatup.utils; - -import javax.net.ssl.HttpsURLConnection; -import java.awt.*; -import java.io.IOException; -import java.io.OutputStream; -import java.lang.reflect.Array; -import java.net.URL; -import java.util.List; -import java.util.*; - -/** - * Class used to execute Discord Webhooks with low effort - * Come from: ... - */ - -@SuppressWarnings("FieldMayBeFinal") -public class DiscordWebhook { - - private final String url; - private String content; - private String username; - private String avatarUrl; - private boolean tts; - private List embeds = new ArrayList<>(); - - /** - * Constructs a new DiscordWebhook instance - * - * @param url The webhook URL obtained in Discord - */ - public DiscordWebhook(String url) { - this.url = url; - } - - public void setContent(String content) { - this.content = content; - } - - public void setUsername(String username) { - this.username = username; - } - - public void setAvatarUrl(String avatarUrl) { - this.avatarUrl = avatarUrl; - } - - public void setTts(boolean tts) { - this.tts = tts; - } - - public void addEmbed(EmbedObject embed) { - this.embeds.add(embed); - } - - public void execute() throws IOException { - if (this.content == null && this.embeds.isEmpty()) { - throw new IllegalArgumentException("Set content or add at least one EmbedObject"); - } - - JSONObject json = new JSONObject(); - - json.put("content", this.content); - json.put("username", this.username); - json.put("avatar_url", this.avatarUrl); - json.put("tts", this.tts); - - if (!this.embeds.isEmpty()) { - List embedObjects = new ArrayList<>(); - - for (EmbedObject embed : this.embeds) { - JSONObject jsonEmbed = new JSONObject(); - - jsonEmbed.put("title", embed.getTitle()); - jsonEmbed.put("description", embed.getDescription()); - jsonEmbed.put("url", embed.getUrl()); - - if (embed.getColor() != null) { - Color color = embed.getColor(); - int rgb = color.getRed(); - rgb = (rgb << 8) + color.getGreen(); - rgb = (rgb << 8) + color.getBlue(); - - jsonEmbed.put("color", rgb); - } - - EmbedObject.Footer footer = embed.getFooter(); - EmbedObject.Image image = embed.getImage(); - EmbedObject.Thumbnail thumbnail = embed.getThumbnail(); - EmbedObject.Author author = embed.getAuthor(); - List fields = embed.getFields(); - - if (footer != null) { - JSONObject jsonFooter = new JSONObject(); - - jsonFooter.put("text", footer.getText()); - jsonFooter.put("icon_url", footer.getIconUrl()); - jsonEmbed.put("footer", jsonFooter); - } - - if (image != null) { - JSONObject jsonImage = new JSONObject(); - - jsonImage.put("url", image.getUrl()); - jsonEmbed.put("image", jsonImage); - } - - if (thumbnail != null) { - JSONObject jsonThumbnail = new JSONObject(); - - jsonThumbnail.put("url", thumbnail.getUrl()); - jsonEmbed.put("thumbnail", jsonThumbnail); - } - - if (author != null) { - JSONObject jsonAuthor = new JSONObject(); - - jsonAuthor.put("name", author.getName()); - jsonAuthor.put("url", author.getUrl()); - jsonAuthor.put("icon_url", author.getIconUrl()); - jsonEmbed.put("author", jsonAuthor); - } - - List jsonFields = new ArrayList<>(); - for (EmbedObject.Field field : fields) { - JSONObject jsonField = new JSONObject(); - - jsonField.put("name", field.getName()); - jsonField.put("value", field.getValue()); - jsonField.put("inline", field.isInline()); - - jsonFields.add(jsonField); - } - - jsonEmbed.put("fields", jsonFields.toArray()); - embedObjects.add(jsonEmbed); - } - - json.put("embeds", embedObjects.toArray()); - } - - URL url = new URL(this.url); - HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); - connection.addRequestProperty("Content-Type", "application/json"); - connection.addRequestProperty("User-Agent", "Java-DiscordWebhook-BY-Gelox_"); - connection.setDoOutput(true); - connection.setRequestMethod("POST"); - - OutputStream stream = connection.getOutputStream(); - stream.write(json.toString().getBytes()); - stream.flush(); - stream.close(); - - connection.getInputStream().close(); //I'm not sure why, but it doesn't work without getting the InputStream - connection.disconnect(); - } - - @SuppressWarnings("FieldMayBeFinal") - public static class EmbedObject { - private String title; - private String description; - private String url; - private Color color; - - private Footer footer; - private Thumbnail thumbnail; - private Image image; - private Author author; - private List fields = new ArrayList<>(); - - public String getTitle() { - return title; - } - - public String getDescription() { - return description; - } - - public String getUrl() { - return url; - } - - public Color getColor() { - return color; - } - - public Footer getFooter() { - return footer; - } - - public Thumbnail getThumbnail() { - return thumbnail; - } - - public Image getImage() { - return image; - } - - public Author getAuthor() { - return author; - } - - public List getFields() { - return fields; - } - - public EmbedObject setTitle(String title) { - this.title = title; - return this; - } - - public EmbedObject setDescription(String description) { - this.description = description; - return this; - } - - public EmbedObject setUrl(String url) { - this.url = url; - return this; - } - - public EmbedObject setColor(Color color) { - this.color = color; - return this; - } - - public EmbedObject setFooter(String text, String icon) { - this.footer = new Footer(text, icon); - return this; - } - - public EmbedObject setThumbnail(String url) { - this.thumbnail = new Thumbnail(url); - return this; - } - - public EmbedObject setImage(String url) { - this.image = new Image(url); - return this; - } - - public EmbedObject setAuthor(String name, String url, String icon) { - this.author = new Author(name, url, icon); - return this; - } - - public EmbedObject addField(String name, String value, boolean inline) { - this.fields.add(new Field(name, value, inline)); - return this; - } - - @SuppressWarnings("FieldMayBeFinal") - private class Footer { - private String text; - private String iconUrl; - - private Footer(String text, String iconUrl) { - this.text = text; - this.iconUrl = iconUrl; - } - - private String getText() { - return text; - } - - private String getIconUrl() { - return iconUrl; - } - } - - @SuppressWarnings("FieldMayBeFinal") - private class Thumbnail { - private String url; - - private Thumbnail(String url) { - this.url = url; - } - - private String getUrl() { - return url; - } - } - - @SuppressWarnings("FieldMayBeFinal") - private class Image { - private String url; - - private Image(String url) { - this.url = url; - } - - private String getUrl() { - return url; - } - } - - @SuppressWarnings("FieldMayBeFinal") - private class Author { - private String name; - private String url; - private String iconUrl; - - private Author(String name, String url, String iconUrl) { - this.name = name; - this.url = url; - this.iconUrl = iconUrl; - } - - private String getName() { - return name; - } - - private String getUrl() { - return url; - } - - private String getIconUrl() { - return iconUrl; - } - } - - @SuppressWarnings("FieldMayBeFinal") - private class Field { - private String name; - private String value; - private boolean inline; - - private Field(String name, String value, boolean inline) { - this.name = name; - this.value = value; - this.inline = inline; - } - - private String getName() { - return name; - } - - private String getValue() { - return value; - } - - private boolean isInline() { - return inline; - } - } - } - - private class JSONObject { - - private final HashMap map = new HashMap<>(); - - void put(String key, Object value) { - if (value != null) { - map.put(key, value); - } - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - Set> entrySet = map.entrySet(); - builder.append("{"); - - int i = 0; - for (Map.Entry entry : entrySet) { - Object val = entry.getValue(); - builder.append(quote(entry.getKey())).append(":"); - - if (val instanceof String) { - builder.append(quote(String.valueOf(val))); - } else if (val instanceof Integer) { - builder.append(Integer.valueOf(String.valueOf(val))); - } else if (val instanceof Boolean) { - builder.append(val); - } else if (val instanceof JSONObject) { - builder.append(val); - } else if (val.getClass().isArray()) { - builder.append("["); - int len = Array.getLength(val); - for (int j = 0; j < len; j++) { - builder.append(Array.get(val, j).toString()).append(j != len - 1 ? "," : ""); - } - builder.append("]"); - } - - builder.append(++i == entrySet.size() ? "}" : ","); - } - - return builder.toString(); - } - - private String quote(String string) { - return "\"" + string + "\""; - } - } -} \ No newline at end of file diff --git a/src/main/java/fr/efreicraft/ecatup/utils/MessageUtils.java b/src/main/java/fr/efreicraft/ecatup/utils/MessageUtils.java index afbb0f4..3b0af76 100644 --- a/src/main/java/fr/efreicraft/ecatup/utils/MessageUtils.java +++ b/src/main/java/fr/efreicraft/ecatup/utils/MessageUtils.java @@ -1,6 +1,8 @@ package fr.efreicraft.ecatup.utils; +import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -57,6 +59,11 @@ public enum ChatPrefix { */ TEAM("&dÉquipe"), + /** + * Préfixe pour les commandes. + */ + COMMAND("&9Commande"), + /** * Préfixe pour les messages concernant les statistiques. */ @@ -138,6 +145,32 @@ public static void sendMessage(CommandSender player, String message) { sendMessage(new CommandSender[]{player}, ChatPrefix.EMPTY, message); } + /** + * Envoyer un message à un joueur sans préfixe et avec les composants Kyori. + * + * @param player Joueur. + * @param message Composant Kyori (MiniMessage conseillé). + */ + public static void sendMessage(CommandSender player, Component message) { + player.sendMessage(message); + } + + /** + * Envoyer un message à un joueur avec préfixe et avec les composants Kyori. + * + * @param player Joueur. + * @param prefix Préfixe du message. + * @param message Composant Kyori (MiniMessage conseillé). + */ + public static void sendMessage(CommandSender player, ChatPrefix prefix, Component message) { + sendMessage( + player, + Component.text().append( + LegacyComponentSerializer.legacyAmpersand().deserialize(prefix.toString()) + ).append(message).build() + ); + } + /** * Envoyer un message à tous les joueurs. * @param prefix Préfixe du message. diff --git a/src/main/java/fr/efreicraft/ecatup/utils/Msg.java b/src/main/java/fr/efreicraft/ecatup/utils/Msg.java deleted file mode 100644 index d55132a..0000000 --- a/src/main/java/fr/efreicraft/ecatup/utils/Msg.java +++ /dev/null @@ -1,18 +0,0 @@ -package fr.efreicraft.ecatup.utils; - -import net.kyori.adventure.text.TextComponent; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; - -import java.util.Objects; - -public class Msg { - //TODO: refactor pour delete cette classe !! - public static String colorize(String message) { - return ChatColor.translateAlternateColorCodes('&', Objects.requireNonNullElse(message, "")); - } - - public static String colorize(TextComponent message) { - return ChatColor.translateAlternateColorCodes('&', Objects.requireNonNullElse(message.content(), "")); - } -} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 6d4a913..e518bf7 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -8,125 +8,5 @@ description: Les commandes et fonctions utiles d'Efrei Craft website: https://github.com/efrei-craft/ECATUP database: true -depend: #Charger ECATUP APRÈS LP et ACP. - - AnimusClient-Paper - -permissions: - ecatup.channel.use: - description: Permet d'utiliser /channel - ecatup.channel: - description: Permet de changer de channel, tout court - children: - - ecatup.channel.global - ecatup.chat.color: - description: Permet l'utilisation de '&' pour colorer son texte - ecatup.gamemode: - description: Permet de changer de gamemode - ecatup.give.skull: - description: Permet de donner une tête de joueur - ecatup.lobby: - description: Ramène au lobby principal - ecatup.slap: - description: Permet d'utiliser /slap - ecatup.speed.fly: - description: Permet de configurer sa vitesse de vol - ecatup.speed.reset: - description: Permet de réinitialiser sa vitesse de vol et de marche - ecatup.speed.walk: - description: Permet de configurer sa vitesse de marche - ecatup.sudo: - description: Permet d'utiliser /sudo - ecatup.whois: - description: Permet d'utiliser /whois - ecatup.groupperms: - description: Utiliser les commandes de permissions de groupes - ecatup.playerperms: - description: Utiliser les commandes de permissions de groupes - -commands: - lobby: - description: Teleport to the lobby - usage: /lobby - aliases: [ hub, spawn ] - permission: ecatup.lobby - chat: - description: Change chat channel - aliases: - - channel - - c - permission: ecatup.channel.use - flyspeed: - description: Sets your flight speed - usage: /fspeed [[reset|r] OR [-10 - 10]] [player] - aliases: - - fspeed - - fsp - permission: ecatup.speed.fly - gm: - description: Change your gamemode - usage: /gm [player] - permission: ecatup.gamemode - gmc: - description: Change your gamemode to creative - usage: /gmc [player] - permission: ecatup.gamemode - gms: - description: Change your gamemode to survival - usage: /gms [player] - permission: ecatup.gamemode - gma: - description: Change your gamemode to adventure - usage: /gma [player] - permission: ecatup.gamemode - gmsp: - description: Change your gamemode to spectator - usage: /gmsp [player] - permission: ecatup.gamemode - resetspeed: - description: Resets all speeds - usage: /resetspeed [player] - aliases: - - resetsp - - rspeed - - rsp - permission: ecatup.speed.reset - skull: - description: Get a player skull - usage: /skull [player] - permission: ecatup.give.skull - slap: - description: Slaps the shit outta someone - aliases: - - bitchslap - usage: /slap [-a] - permission: ecatup.slap - sudo: - description: Makes someone say something or execute a command - usage: /sudo - permission: ecatup.sudo - whois: - description: Gets info about a player - usage: /whois [player] - permission: ecatup.whois - walkspeed: - description: Sets walking speed - usage: /walkspeed [[reset] OR [-10 - 10]] [player] - aliases: - - wspeed - - wsp - permission: ecatup.speed.walk - - groupperms: - description: All about group perms - aliases: - - gperms - permission: ecatup.groupperms - playerperms: - description: All about group perms - aliases: - - pperms - permission: ecatup.playerperms - - hasperm: - description: (Debug) Check if player has specified permission - permission: ecatup.hasperm \ No newline at end of file +depend: + - AnimusClient-Paper \ No newline at end of file