From 76ae3103de2f8566486907004952713ca818a8f4 Mon Sep 17 00:00:00 2001 From: Len <40720638+destro174@users.noreply.github.com> Date: Fri, 4 Oct 2024 22:48:44 +0200 Subject: [PATCH] Add SpawnMobCommand.java --- .../commands/admin/SpawnMobCommand.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 plugin/src/main/java/com/alttd/essentia/commands/admin/SpawnMobCommand.java diff --git a/plugin/src/main/java/com/alttd/essentia/commands/admin/SpawnMobCommand.java b/plugin/src/main/java/com/alttd/essentia/commands/admin/SpawnMobCommand.java new file mode 100644 index 0000000..59eda00 --- /dev/null +++ b/plugin/src/main/java/com/alttd/essentia/commands/admin/SpawnMobCommand.java @@ -0,0 +1,55 @@ +package com.alttd.essentia.commands.admin; + +import com.alttd.essentia.commands.EssentiaCommand; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.tree.LiteralCommandNode; +import io.papermc.paper.command.brigadier.CommandSourceStack; +import io.papermc.paper.command.brigadier.Commands; +import io.papermc.paper.command.brigadier.argument.ArgumentTypes; +import io.papermc.paper.registry.RegistryKey; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; +import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.jetbrains.annotations.NotNull; + +// TODO -- FINISH ME - messages and options? +public class SpawnMobCommand implements EssentiaCommand { + + @Override + public String commandName() { + return "spawnmob"; + } + + @Override + public @NotNull LiteralCommandNode command() { + final LiteralArgumentBuilder builder = + Commands.literal(commandName()) + .requires( + commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) + ) + .then( + Commands.argument("entity", ArgumentTypes.resource(RegistryKey.ENTITY_TYPE)) + .requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission())) + .executes((source) -> { + EntityType entityType = source.getArgument("entity", EntityType.class); + execute(source.getSource().getSender(), (Player) source.getSource().getSender(), entityType); + + return 1; + }) + ); + return builder.build(); + } + + public void execute(CommandSender sender, Player target, EntityType entityType) { // TODO - implement player info + TagResolver placeholders = TagResolver.resolver( + Placeholder.component("requester", sender.name()), + Placeholder.component("target", target.displayName()) + ); + + target.getWorld().spawn(target.getLocation(), entityType.getEntityClass(), CreatureSpawnEvent.SpawnReason.COMMAND); + } + +}