From 70da43b128a345c0048ca51472628954f6fa19d2 Mon Sep 17 00:00:00 2001 From: tanyaofei Date: Fri, 28 Jul 2023 16:23:57 +0800 Subject: [PATCH] =?UTF-8?q?spawn=20=E5=91=BD=E4=BB=A4=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E4=B8=96=E7=95=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hello09x/fakeplayer/command/Commands.java | 31 +++++++++++++------ .../fakeplayer/command/SpawnCommand.java | 7 ++++- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/github/hello09x/fakeplayer/command/Commands.java b/src/main/java/io/github/hello09x/fakeplayer/command/Commands.java index 7193fee..115c8bc 100644 --- a/src/main/java/io/github/hello09x/fakeplayer/command/Commands.java +++ b/src/main/java/io/github/hello09x/fakeplayer/command/Commands.java @@ -35,7 +35,7 @@ public class Commands { "可以创建模拟玩家的假人, 能保持附近区块的刷新、触发怪物生成。同时还提供了一些操作命令让你控制假人的物品、动作等等。" ) .withUsage( - "§6/fp spawn §7- §f创建假人", + "§6/fp spawn [世界] [位置] §7- §f创建假人", "§6/fp kill [假人] §7- §f移除假人", "§6/fp list [页码] [数量] §7- §f查看所有假人", "§6/fp distance §7- §f查看与假人的距离", @@ -47,14 +47,14 @@ public class Commands { "§6/fp health [假人] §7- §f查看生命值", "§6/fp exp [假人] §7- §f查看经验值", "§6/fp expme [假人] §7- §f转移经验值", - "§6/fp attack [假人] §7- §f攻击/破坏", - "§6/fp use [假人] §7- §f使用/交互/放置", - "§6/fp jump [假人] §7- §f跳跃", + "§6/fp attack (once|continuous|interval|stop) [假人] §7- §f攻击/破坏", + "§6/fp use (once|continuous|interval|stop) [假人] §7- §f使用/交互/放置", + "§6/fp jump (once|continuous|interval|stop) [假人] §7- §f跳跃", "§6/fp drop [假人] [-a|--all] §7- §f丢弃手上物品", "§6/fp dropinv [假人] §7- §f丢弃背包物品", - "§6/fp look §7- §f看向指定位置", - "§6/fp turn §7- §f转身到指定位置", - "§6/fp move §7- §f移动假人", + "§6/fp look (north|south|east|west|up|down|at) [假人] §7- §f看向指定位置", + "§6/fp turn (left|right|back|to) [假人] §7- §f转身到指定位置", + "§6/fp move (forward|backward|left|right) [假人] §7- §f移动假人", "§6/fp cmd §7- §f执行命令", "§6/fp reload §7- §f重载配置文件" ) @@ -66,7 +66,10 @@ public class Commands { command("spawn") .withPermission(PERMISSION_SPAWN) - .withOptionalArguments(location("location").withPermission(PERMISSION_SPAWN_LOCATION)) + .withOptionalArguments( + world("world").withPermission(PERMISSION_SPAWN_LOCATION), + location("location").withPermission(PERMISSION_SPAWN_LOCATION) + ) .executes(SpawnCommand.instance::spawn), command("kill") .withPermission(PERMISSION_SPAWN) @@ -164,7 +167,7 @@ public class Commands { .withOptionalArguments(target("target")) .executes(ActionCommand.instance.look(Direction.DOWN)), command("at") - .withArguments(new LocationArgument("location")) + .withArguments(location("location")) .withOptionalArguments(target("target")) .executes(ActionCommand.instance::lookAt) ), @@ -181,7 +184,7 @@ public class Commands { .withOptionalArguments(target("target")) .executes(ActionCommand.instance.turn(180, 0)), command("to") - .withArguments(new RotationArgument("rotation")) + .withArguments(rotation("rotation")) .withOptionalArguments(target("target")) .executes(ActionCommand.instance::turnTo) ) @@ -258,6 +261,14 @@ public class Commands { return new LocationArgument(name); } + public static RotationArgument rotation(String name) { + return new RotationArgument(name); + } + + public static WorldArgument world(String name) { + return new WorldArgument(name); + } + public static MultiLiteralArgument literals(String name, String... literals) { return new MultiLiteralArgument(name, Arrays.asList(literals)); } diff --git a/src/main/java/io/github/hello09x/fakeplayer/command/SpawnCommand.java b/src/main/java/io/github/hello09x/fakeplayer/command/SpawnCommand.java index 9572cf6..6316232 100644 --- a/src/main/java/io/github/hello09x/fakeplayer/command/SpawnCommand.java +++ b/src/main/java/io/github/hello09x/fakeplayer/command/SpawnCommand.java @@ -8,6 +8,7 @@ import net.kyori.adventure.text.event.ClickEvent; import org.apache.commons.lang3.StringUtils; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -34,13 +35,17 @@ public class SpawnCommand extends AbstractCommand { } public void spawn(@NotNull CommandSender sender, CommandArguments args) { + var world = (World) args.get("world"); var location = (Location) args.get("location"); - if (location == null) { + if (world == null || location == null) { if (sender instanceof Player p) { location = p.getLocation(); } else { location = Bukkit.getServer().getWorlds().get(0).getSpawnLocation(); } + } else { + location = location.clone(); + location.setWorld(world); } var fakePlayer = fakeplayerManager.spawn(sender, location.clone());