This commit is contained in:
parent
40af6b246d
commit
997906cd02
3 changed files with 35 additions and 10 deletions
|
|
@ -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<T> implements ArgumentType<T, World> {
|
||||
@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<T> getDefaultSuggestionProvider() {
|
||||
return _ -> Stream.concat(
|
||||
Bukkit.getWorlds().stream().map(World::getName),
|
||||
Bukkit.getWorlds().stream().map(w -> w.getUID().toString())
|
||||
).toList();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue