-
-
Notifications
You must be signed in to change notification settings - Fork 72
Add miscellaneous argument type 'World' #358
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Funnily enough, the World argument is used as an example in the documentation for making custom arguments: // Function that returns our custom argument
public Argument<World> worldArgument(String nodeName) {
// Construct our CustomArgument that takes in a String input and returns a World object
return new CustomArgument<World, String>(new StringArgument(nodeName), info -> {
// Parse the world from our input
World world = Bukkit.getWorld(info.input());
if(world == null) {
throw new CustomArgumentException(new MessageBuilder("Unknown world: ").appendArgInput());
} else {
return world;
}
}).replaceSuggestions(ArgumentSuggestions.strings(info ->
// List of world names on the server
Bukkit.getWorlds().stream().map(World::getName).toArray(String[]::new))
);
} In the meantime, that should work for your use, but I agree, an official WorldArgument might be a nice addition to the CommandAPI. On the point of having a list of worlds, if you want to do that right now, you could create a ListArgument (see https://commandapi.jorel.dev/8.5.1/listarguments.html for how to do that). |
Brilliant! Thanks so much @willkroboth. This ought to be the best documented library I have come across. In case context is useful for the addition of this feature, I am writing a 'Kill' command for LevelledMobs, |
Unfortunately the current workaround doesn't seem to work on |
As mentioned in #365, the CommandAPI will only be accepting "custom argument implementations" that satisfy the following points:
The World Argument requested in this issue can already be implemented without the use of Brigadier/NMS by using the Making use of the synchronous argument suggestions should work regardless of .replaceSuggestions(ArgumentSuggestions.strings(info ->
// List of world names on the server
Bukkit.getWorlds().stream().map(World::getName).toArray(String[]::new))
); Using asynchronous world suggestions is not recommended as asynchronous queries should not be accessing the Bukkit API. |
Thanks, no worries :) |
After a quick chat with a member from the CommandAPI Discord server, I've discovered that the CommandAPI's implementation of Minecraft's Scheduling the implementation of a |
Extra thanks to @booky10 for their help with cracking this one!
Implemented in release 8.6.0. |
Description
Allows us to select world names, such as:
/kill @e[type=creeper] my_cool_world
..where
my_cool_world
is a world loaded on the server.Can also be used as a list:
/kill @e[type=creeper] my_cool_world world world_nether world_the_end resource_world
Expected code
No response
Extra details
No response
The text was updated successfully, but these errors were encountered: