bukkit/paper: Add NamespacedKeyArgument (#376)

This commit is contained in:
Jason 2022-06-09 22:26:36 -07:00
parent a441f42666
commit c250aa642f
12 changed files with 645 additions and 0 deletions

View file

@ -44,6 +44,7 @@ import cloud.commandframework.arguments.standard.IntegerArgument;
import cloud.commandframework.arguments.standard.StringArrayArgument;
import cloud.commandframework.bukkit.BukkitCommandManager;
import cloud.commandframework.bukkit.CloudBukkitCapabilities;
import cloud.commandframework.bukkit.argument.NamespacedKeyArgument;
import cloud.commandframework.bukkit.arguments.selector.SingleEntitySelector;
import cloud.commandframework.bukkit.data.ProtoItemStack;
import cloud.commandframework.bukkit.parsers.EnchantmentArgument;
@ -89,6 +90,7 @@ import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
@ -393,6 +395,8 @@ public final class ExamplePlugin extends JavaPlugin {
new Mc113(this.manager).registerCommands();
}
this.registerNamespacedKeyUsingCommand();
//
// Create a Bukkit-like command
//
@ -457,6 +461,28 @@ public final class ExamplePlugin extends JavaPlugin {
}));
}
private void registerNamespacedKeyUsingCommand() {
boolean nsk = true;
try {
Class.forName("org.bukkit.NamespacedKey");
} catch (final ClassNotFoundException e) {
nsk = false;
}
if (!nsk) {
return;
}
this.manager.command(this.manager.commandBuilder("example")
.literal("namespacedkey")
.argument(NamespacedKeyArgument.of("key"))
.handler(ctx -> {
final NamespacedKey namespacedKey = ctx.get("key");
final String key = namespacedKey.getNamespace() + ":" + namespacedKey.getKey();
ctx.getSender().sendMessage("The key you typed is '" + key + "'.");
}));
}
@CommandMethod("example|e|ex help [query]")
@CommandDescription("Help menu")
public void commandHelp(