Add ability to select random world in -world parameter

This commit is contained in:
Phoenix616 2023-03-16 16:36:49 +01:00
parent 11cbc0abb8
commit f934071367
No known key found for this signature in database
GPG Key ID: 40E2321E71738EB0
2 changed files with 5 additions and 3 deletions

View File

@ -24,7 +24,7 @@ Usage | Description
Option | Description
--------------------------------|-------------------------------------------
`-p,-player <playername>` | teleports other players
`-w,-world <worldname>` | teleports the player in a specific world
`-w,-world <world1,world2,...>` | teleports the player in a specific or random world
`-b,-biome <biomename...>` | only teleport to this biome (multiple allowed, Bukkit biome names!)
`-x,-xPos <x value>` | x axis of the center point, if not set the player's x axis is used
`-z,-zPos <z value>` | z axis of the center point, if not set the player's z axis is used

View File

@ -183,9 +183,11 @@ public class RandomTeleport extends JavaPlugin implements RandomTeleportAPI {
}));
addOptionParser(new SimpleOptionParser(array("w", "world"), (searcher, args) -> {
if (args.length > 0) {
World world = getServer().getWorld(args[0]);
String[] worldNames = args[0].split(",");
String worldName = worldNames[searcher.getRandom().nextInt(worldNames.length)];
World world = getServer().getWorld(worldName);
if (world == null) {
throw new WorldNotFoundException(args[0]);
throw new WorldNotFoundException(worldName);
}
searcher.setWorld(world);
return true;