From f934071367e07b353df0118b4875b45ed9d632db Mon Sep 17 00:00:00 2001 From: Phoenix616 Date: Thu, 16 Mar 2023 16:36:49 +0100 Subject: [PATCH] Add ability to select random world in -world parameter --- README.md | 2 +- .../main/java/de/themoep/randomteleport/RandomTeleport.java | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 64fc476..f3904d1 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Usage | Description Option | Description --------------------------------|------------------------------------------- `-p,-player ` | teleports other players -`-w,-world ` | teleports the player in a specific world +`-w,-world ` | teleports the player in a specific or random world `-b,-biome ` | only teleport to this biome (multiple allowed, Bukkit biome names!) `-x,-xPos ` | x axis of the center point, if not set the player's x axis is used `-z,-zPos ` | z axis of the center point, if not set the player's z axis is used diff --git a/randomteleport-plugin/src/main/java/de/themoep/randomteleport/RandomTeleport.java b/randomteleport-plugin/src/main/java/de/themoep/randomteleport/RandomTeleport.java index 524e4bd..ccfcfe8 100644 --- a/randomteleport-plugin/src/main/java/de/themoep/randomteleport/RandomTeleport.java +++ b/randomteleport-plugin/src/main/java/de/themoep/randomteleport/RandomTeleport.java @@ -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;