From 997906cd02f94063acfbc44374abfb4c611b17d7 Mon Sep 17 00:00:00 2001 From: kento2 Date: Sun, 9 Aug 2026 00:42:09 +0200 Subject: [PATCH] . --- README.md | 11 ++----- .../kencommandapi/type/WorldArgumentType.java | 32 +++++++++++++++++++ defs.bzl | 2 +- 3 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 bukkit/src/main/java/de/kentoj/kencommandapi/type/WorldArgumentType.java diff --git a/README.md b/README.md index 7ebb953..930c863 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,3 @@ -## TODO - -CI/CD: -- actually publish package - ## Build after installing bazel: @@ -51,20 +46,18 @@ literal:coins/balance ### As code ```java -import de.kentoj.kencommandapi.api.literal.RootLiteral; - /** * Show the amount coins a user has. * If no user is given, it should show the amount the sender of the command has. */ -public class CoinsCommand { +public final class CoinsCommand { private final RootLiteral rootLiteral; private final CommandArgumentSpec userArg; public CoinsCommand() { userArg = CommandArgumentSpec.builder("user", new UserArgumentType()) - .withRequirement(p -> !p.hasPermission("economy.immune.getcoins"), + .withRequirement(user -> !user.hasPermission("economy.immune.getcoins"), "you can't see that player's balance") .withDefaultValue(CommandContext::sender) .build(); diff --git a/bukkit/src/main/java/de/kentoj/kencommandapi/type/WorldArgumentType.java b/bukkit/src/main/java/de/kentoj/kencommandapi/type/WorldArgumentType.java new file mode 100644 index 0000000..f51e7b1 --- /dev/null +++ b/bukkit/src/main/java/de/kentoj/kencommandapi/type/WorldArgumentType.java @@ -0,0 +1,32 @@ +package de.kentoj.kencommandapi.type; + +import de.kentoj.kencommandapi.api.argument.ArgumentType; +import de.kentoj.kencommandapi.api.suggestion.SuggestionProvider; +import org.bukkit.Bukkit; +import org.bukkit.World; + +import java.util.UUID; +import java.util.stream.Stream; + +public class WorldArgumentType implements ArgumentType { + @Override + public World parseInputUnchecked(String input) throws IllegalArgumentException { + var world = Bukkit.getWorld(input); + if (world == null && input.length() == 36) { + try { + return Bukkit.getWorld(UUID.fromString(input)); + } catch (IllegalArgumentException _) { + throw new IllegalArgumentException("World not found"); + } + } + return world; + } + + @Override + public SuggestionProvider getDefaultSuggestionProvider() { + return _ -> Stream.concat( + Bukkit.getWorlds().stream().map(World::getName), + Bukkit.getWorlds().stream().map(w -> w.getUID().toString()) + ).toList(); + } +} diff --git a/defs.bzl b/defs.bzl index 798102b..3dce00c 100644 --- a/defs.bzl +++ b/defs.bzl @@ -1,2 +1,2 @@ GROUP = "de.kentoj.scrow" -VERSION = "0.36-SNAPSHOT" \ No newline at end of file +VERSION = "0.37-SNAPSHOT" \ No newline at end of file