mirror of
https://github.com/YouHaveTrouble/BlockEdit.git
synced 2026-06-29 13:36:19 +00:00
start moving to brigadier commands
This commit is contained in:
@@ -77,7 +77,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.papermc.paper</groupId>
|
<groupId>io.papermc.paper</groupId>
|
||||||
<artifactId>paper-api</artifactId>
|
<artifactId>paper-api</artifactId>
|
||||||
<version>1.20.6-R0.1-SNAPSHOT</version>
|
<version>1.21.3-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
package me.youhavetrouble.blockedit;
|
package me.youhavetrouble.blockedit;
|
||||||
|
|
||||||
import me.youhavetrouble.blockedit.commands.*;
|
|
||||||
import me.youhavetrouble.blockedit.wands.SelectionWand;
|
import me.youhavetrouble.blockedit.wands.SelectionWand;
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public final class BlockEdit extends JavaPlugin {
|
public final class BlockEdit extends JavaPlugin {
|
||||||
|
|
||||||
private static BlockEdit plugin;
|
private static BlockEdit plugin;
|
||||||
|
|
||||||
private static SchematicHandler schematicHandler;
|
private static SchematicHandler schematicHandler;
|
||||||
private static WandsHandler wandsHandler;
|
private static WandsHandler wandsHandler;
|
||||||
|
|
||||||
@@ -18,16 +15,6 @@ public final class BlockEdit extends JavaPlugin {
|
|||||||
|
|
||||||
getServer().getPluginManager().registerEvents(new JoinLeaveListener(), this);
|
getServer().getPluginManager().registerEvents(new JoinLeaveListener(), this);
|
||||||
|
|
||||||
registerCommand(new WandCommand());
|
|
||||||
registerCommand(new SetCommand());
|
|
||||||
registerCommand(new ReplaceCommand());
|
|
||||||
registerCommand(new DeselCommand());
|
|
||||||
registerCommand(new Pos1Command());
|
|
||||||
registerCommand(new Pos2Command());
|
|
||||||
registerCommand(new CopyCommand());
|
|
||||||
registerCommand(new PasteCommand());
|
|
||||||
registerCommand(new RotateCommand());
|
|
||||||
|
|
||||||
schematicHandler = new SchematicHandler(this);
|
schematicHandler = new SchematicHandler(this);
|
||||||
wandsHandler = new WandsHandler(this);
|
wandsHandler = new WandsHandler(this);
|
||||||
|
|
||||||
@@ -35,10 +22,9 @@ public final class BlockEdit extends JavaPlugin {
|
|||||||
wandsHandler.registerWand(selectionWand);
|
wandsHandler.registerWand(selectionWand);
|
||||||
getServer().getPluginManager().registerEvents(selectionWand, this);
|
getServer().getPluginManager().registerEvents(selectionWand, this);
|
||||||
|
|
||||||
|
BlockEditCommands.registerCommands(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static BlockEdit getPlugin() {
|
public static BlockEdit getPlugin() {
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
@@ -51,8 +37,4 @@ public final class BlockEdit extends JavaPlugin {
|
|||||||
return wandsHandler;
|
return wandsHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerCommand(Command command) {
|
|
||||||
getServer().getCommandMap().register("blockedit", command);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package me.youhavetrouble.blockedit;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
import io.papermc.paper.command.brigadier.Commands;
|
||||||
|
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
|
||||||
|
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
|
||||||
|
import me.youhavetrouble.blockedit.api.BlockEditAPI;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
|
public class BlockEditCommands {
|
||||||
|
|
||||||
|
protected static void registerCommands(@NotNull BlockEdit plugin) {
|
||||||
|
LifecycleEventManager<@NotNull Plugin> manager = plugin.getLifecycleManager();
|
||||||
|
manager.registerEventHandler(LifecycleEvents.COMMANDS, event -> {
|
||||||
|
final Commands commands = event.registrar();
|
||||||
|
|
||||||
|
commands.register(
|
||||||
|
wandCommand(),
|
||||||
|
"Gives the player chosen wand"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static LiteralCommandNode<CommandSourceStack> wandCommand() {
|
||||||
|
return Commands.literal("wand")
|
||||||
|
.requires(css -> {
|
||||||
|
if (!(css.getSender() instanceof Player player)) return false;
|
||||||
|
return player.hasPermission("blockedit.command.wand");
|
||||||
|
})
|
||||||
|
.then(
|
||||||
|
Commands.argument("wand_id", StringArgumentType.word())
|
||||||
|
.suggests((ctx, builder) -> {
|
||||||
|
String[] inputArgs = ctx.getInput().split(" ");
|
||||||
|
String lastArg = inputArgs[inputArgs.length - 1];
|
||||||
|
for (String id : BlockEditAPI.getWandsHandler().getWandIds()) {
|
||||||
|
if (inputArgs.length != 1) continue;
|
||||||
|
if (id.startsWith(lastArg)) continue;
|
||||||
|
builder.suggest(id);
|
||||||
|
}
|
||||||
|
return builder.buildFuture();
|
||||||
|
})
|
||||||
|
.executes(ctx -> {
|
||||||
|
if (!(ctx.getSource().getSender() instanceof Player player)) {
|
||||||
|
ctx.getSource().getSender().sendMessage(Component.text("Only players can use this command", NamedTextColor.RED));
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
String wandId = ctx.getArgument("wand_id", String.class);
|
||||||
|
ItemStack wand = BlockEditAPI.getWandsHandler().getWand(wandId);
|
||||||
|
if (wand == null) {
|
||||||
|
ctx.getSource().getSender().sendMessage(Component.text("Could not find wand with id %s".formatted(wandId), NamedTextColor.RED));
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
player.getInventory().addItem(wand);
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.executes(ctx -> {
|
||||||
|
if (!(ctx.getSource().getSender() instanceof Player player)) {
|
||||||
|
ctx.getSource().getSender().sendMessage(Component.text("Only players can use this command", NamedTextColor.RED));
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
ItemStack wand = BlockEditAPI.getWandsHandler().getWand("select");
|
||||||
|
player.getInventory().addItem(wand);
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
})
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
package me.youhavetrouble.blockedit.commands;
|
|
||||||
|
|
||||||
import me.youhavetrouble.blockedit.api.BlockEditAPI;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.util.StringUtil;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class WandCommand extends Command {
|
|
||||||
|
|
||||||
public WandCommand() {
|
|
||||||
super("wand");
|
|
||||||
setPermission("blockedit.command.wand");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean execute(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] args) {
|
|
||||||
if (!(commandSender instanceof Player player)) return true;
|
|
||||||
ItemStack wand;
|
|
||||||
if (args.length == 0) {
|
|
||||||
wand = BlockEditAPI.getWandsHandler().getWand("select");
|
|
||||||
if (wand == null) return true;
|
|
||||||
} else {
|
|
||||||
wand = BlockEditAPI.getWandsHandler().getWand(args[0]);
|
|
||||||
if (wand == null) {
|
|
||||||
player.sendMessage(Component.text("Could not find wand with id "+args[0]));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
player.getInventory().addItem(wand);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
|
||||||
if (args.length == 1)
|
|
||||||
return StringUtil.copyPartialMatches(args[0], BlockEditAPI.getWandsHandler().getWandIds(), new ArrayList<>());
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user