diff --git a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/CommandRegistry.java b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/CommandRegistry.java index ba1f1ae..bb74829 100644 --- a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/CommandRegistry.java +++ b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/CommandRegistry.java @@ -3,6 +3,7 @@ package io.github.hello09x.fakeplayer.core.command; import com.google.inject.Inject; import com.google.inject.Singleton; import dev.jorel.commandapi.CommandPermission; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; import io.github.hello09x.devtools.command.HelpCommand; import io.github.hello09x.devtools.core.utils.ComponentUtils; import io.github.hello09x.fakeplayer.api.spi.ActionSetting; @@ -387,6 +388,11 @@ public class CommandRegistry { .withShortDescription("fakeplayer.command.ride.vehicle.description") .withOptionalArguments(fakeplayer("name")) .executes(rideCommand::rideVehicle), + command("entity") + .withShortDescription("fakeplayer.command.ride.entity.description") + .withArguments(new EntitySelectorArgument.OneEntity("entity")) + .withOptionalArguments(fakeplayer("name")) + .executes(rideCommand::rideEntity), command("stop") .withShortDescription("fakeplayer.command.ride.stop.description") .withOptionalArguments(fakeplayer("name")) diff --git a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/impl/RideCommand.java b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/impl/RideCommand.java index 2f7bfa4..91401d1 100644 --- a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/impl/RideCommand.java +++ b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/impl/RideCommand.java @@ -4,15 +4,13 @@ import com.google.inject.Singleton; import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; import dev.jorel.commandapi.executors.CommandArguments; import org.bukkit.command.CommandSender; -import org.bukkit.entity.AbstractHorse; -import org.bukkit.entity.Boat; -import org.bukkit.entity.Minecart; -import org.bukkit.entity.Player; +import org.bukkit.entity.*; import org.jetbrains.annotations.NotNull; import static net.kyori.adventure.text.Component.text; import static net.kyori.adventure.text.Component.translatable; -import static net.kyori.adventure.text.format.NamedTextColor.*; +import static net.kyori.adventure.text.format.NamedTextColor.RED; +import static net.kyori.adventure.text.format.NamedTextColor.WHITE; @Singleton public class RideCommand extends AbstractCommand { @@ -26,7 +24,11 @@ public class RideCommand extends AbstractCommand { if (entities.isEmpty()) { return; } - bridge.fromPlayer(fake).startRiding(entities.get(0), true); + var entity = entities.stream().filter(e -> e != fake).findAny().orElse(null); + if (entity == null) { + return; + } + bridge.fromPlayer(fake).startRiding(entity, true); } /** @@ -42,6 +44,28 @@ public class RideCommand extends AbstractCommand { bridge.fromPlayer(fake).startRiding(entity, true); } + public void rideEntity(@NotNull CommandSender sender, @NotNull CommandArguments args) throws WrapperCommandSyntaxException { + var fake = getFakeplayer(sender, args); + var entity = (Entity) args.get("entity"); + if (entity == fake) { + sender.sendMessage(translatable("fakeplayer.command.ride.entity.error.ride-self").color(RED)); + return; + } + if (entity == null) { + return; + } + if (entity.isDead()) { + return; + } + + if (entity.getWorld() != fake.getWorld() || entity.getLocation().distance(fake.getLocation()) > 24) { + sender.sendMessage(translatable("fakeplayer.command.ride.entity.error.too-far", text(fake.getName(), WHITE)).color(RED)); + return; + } + + bridge.fromPlayer(fake).startRiding(entity, true); + } + /** * 骑正常可以骑的附近实体 */ @@ -65,17 +89,11 @@ public class RideCommand extends AbstractCommand { */ public void rideMe(@NotNull Player sender, @NotNull CommandArguments args) throws WrapperCommandSyntaxException { var fake = getFakeplayer(sender, args); - if (!fake.getWorld().equals(sender.getWorld())) { - sender.sendMessage(translatable("fakeplayer.command.ride.me.error.too-far", RED)); - return; - } - - var distance = fake.getLocation().distance(sender.getLocation()); - if (distance > 24) { + if (!fake.getWorld().equals(sender.getWorld()) || fake.getLocation().distance(sender.getLocation()) > 20) { sender.sendMessage(translatable( "fakeplayer.command.ride.me.error.too-far", - text(fake.getName(), WHITE) - ).color(GRAY)); + text(fake.getName(), WHITE)).color(RED) + ); return; } diff --git a/fakeplayer-core/src/main/resources/message/message.properties b/fakeplayer-core/src/main/resources/message/message.properties index 4cb5615..a109f42 100644 --- a/fakeplayer-core/src/main/resources/message/message.properties +++ b/fakeplayer-core/src/main/resources/message/message.properties @@ -68,7 +68,6 @@ fakeplayer.command.move.forward.description=Move forward fakeplayer.command.move.left.description=Move left fakeplayer.command.move.right.description=Move right fakeplayer.command.reload-translation.description=Reload translation file -fakeplayer.command.reload.config-file-not-found=Config file {0} is not found, you should rename {1} to {0} as config file, NEVER MODIFY {1} ! fakeplayer.command.reload.description=Reload config file fakeplayer.command.respawn.description=Respawn a dead fake player fakeplayer.command.ride.anything.description=Ride any nearby entity @@ -77,6 +76,7 @@ fakeplayer.command.ride.me.description=Ride me fakeplayer.command.ride.me.error.too-far=You are too far away from {0} fakeplayer.command.ride.stop.description=Stop riding fakeplayer.command.ride.target.description=Ride entity that looking at +fakeplayer.command.ride.entity.error.ride-self=Not allowed to touch youself! fakeplayer.command.ride.vehicle.description=Ride nearby vehicle fakeplayer.command.select.description=Select a fake player as a target fakeplayer.command.select.success.clear=Selection canceled @@ -147,5 +147,7 @@ fakeplayer.spawn.error.name.start-with-illegal-character=Name can not start with fakeplayer.spawn.error.name.too-long=Requires a name has less than {0} characters fakeplayer.spawn.error.name.too-short=Requires a name has more than {0} characters fakeplayer.spawn.error.name.used=Name {0} was used by a real player({1}) +fakeplayer.command.ride.entity.error.too-far=Entity is too far away from {0} +fakeplayer.command.ride.entity.description=Ride specified entity diff --git a/fakeplayer-core/src/main/resources/message/message_zh.properties b/fakeplayer-core/src/main/resources/message/message_zh.properties index 89bf840..14c22c9 100644 --- a/fakeplayer-core/src/main/resources/message/message_zh.properties +++ b/fakeplayer-core/src/main/resources/message/message_zh.properties @@ -68,7 +68,6 @@ fakeplayer.command.move.forward.description=\u5411\u524D\u79FB\u52A8 fakeplayer.command.move.left.description=\u5411\u5DE6\u79FB\u52A8 fakeplayer.command.move.right.description=\u5411\u53F3\u79FB\u52A8 fakeplayer.command.reload-translation.description=\u91CD\u65B0\u52A0\u8F7D\u8BED\u8A00\u6587\u4EF6 -fakeplayer.command.reload.config-file-not-found=\u914D\u7F6E\u6587\u4EF6 {0} \u4E0D\u5B58\u5728, \u4F60\u5E94\u8BE5\u5C06 {1} \u91CD\u547D\u540D\u4E3A {0} \u4F5C\u4E3A\u914D\u7F6E\u6587\u4EF6, \u6C38\u8FDC\u4E0D\u8981\u76F4\u63A5\u4FEE\u6539 {1} ! fakeplayer.command.reload.description=\u91CD\u65B0\u52A0\u8F7D\u914D\u7F6E\u6587\u4EF6 fakeplayer.command.respawn.description=\u590D\u6D3B\u5047\u4EBA fakeplayer.command.ride.anything.description=\u9A91\u9644\u8FD1\u7684\u5B9E\u4F53 @@ -77,6 +76,7 @@ fakeplayer.command.ride.me.description=\u9A91\u4F60 fakeplayer.command.ride.me.error.too-far=\u4F60\u79BB {0} \u592A\u8FDC\u4E86 fakeplayer.command.ride.stop.description=\u505C\u6B62\u9A91\u4E58 fakeplayer.command.ride.target.description=\u9A91\u76EE\u5149\u6240\u6307\u5B9E\u4F53 +fakeplayer.command.ride.entity.error.ride-self=\u7981\u6B62\u81EA\u5A31\u81EA\u4E50 fakeplayer.command.ride.vehicle.description=\u9A91\u9644\u8FD1\u80FD\u9A91\u7684\u5B9E\u4F53 fakeplayer.command.select.description=\u9009\u4E2D\u5047\u4EBA fakeplayer.command.select.success.clear=\u6E05\u9664\u9009\u4E2D\u5047\u4EBA @@ -147,5 +147,7 @@ fakeplayer.spawn.error.name.start-with-illegal-character=\u81EA\u5B9A\u4E49\u540 fakeplayer.spawn.error.name.too-long=\u540D\u79F0\u6700\u591A {0} \u4E2A\u5B57\u7B26 fakeplayer.spawn.error.name.too-short=\u540D\u79F0\u6700\u5C11 {0} \u4E2A\u5B57\u7B26 fakeplayer.spawn.error.name.used=\u540D\u79F0 {0} \u88AB\u771F\u5B9E\u73A9\u5BB6({1})\u4F7F\u7528\u8FC7\u4E86 +fakeplayer.command.ride.entity.error.too-far=\u6307\u5B9A\u7684\u5B9E\u4F53\u79BB {0} \u592A\u8FDC\u4E86 +fakeplayer.command.ride.entity.description=\u9A91\u6307\u5B9A\u5B9E\u4F53 diff --git a/fakeplayer-core/src/main/resources/message/message_zh_HK.properties b/fakeplayer-core/src/main/resources/message/message_zh_HK.properties index c1dc770..d65646e 100644 --- a/fakeplayer-core/src/main/resources/message/message_zh_HK.properties +++ b/fakeplayer-core/src/main/resources/message/message_zh_HK.properties @@ -68,7 +68,6 @@ fakeplayer.command.move.forward.description=\u5411\u524D\u79FB\u52D5 fakeplayer.command.move.left.description=\u5411\u5DE6\u79FB\u52D5 fakeplayer.command.move.right.description=\u5411\u53F3\u79FB\u52D5 fakeplayer.command.reload-translation.description=\u91CD\u65B0\u52A0\u8F09\u8A9E\u8A00\u6587\u4EF6 -fakeplayer.command.reload.config-file-not-found=\u914D\u7F6E\u6587\u4EF6 {0} \u4E0D\u5B58\u5728, \u4F60\u61C9\u8A72\u5C07 {1} \u6539\u540D\u70BA {0} \u4F5C\u70BA\u914D\u7F6E\u6587\u4EF6, \u6C38\u9060\u4E0D\u8981\u76F4\u63A5\u4FEE\u6539 {1} ! fakeplayer.command.reload.description=\u91CD\u65B0\u52A0\u8F09\u914D\u7F6E\u6587\u4EF6 fakeplayer.command.respawn.description=\u590D\u6D3B\u5047\u4EBA fakeplayer.command.ride.anything.description=\u9A0E\u9644\u8FD1\u5605\u5BE6\u9AD4 @@ -77,6 +76,7 @@ fakeplayer.command.ride.me.description=\u9A0E\u4F60 fakeplayer.command.ride.me.error.too-far=\u4F60\u96E2 {0} \u592A\u9060\u4E86 fakeplayer.command.ride.stop.description=\u505C\u6B62\u9A0E\u4E58 fakeplayer.command.ride.target.description=\u9A0E\u76EE\u5149\u6240\u6307\u5BE6\u9AD4 +fakeplayer.command.ride.entity.error.ride-self=\u7121\u6CD5\u5DE6\u8173\u8E29\u53F3\u8173 fakeplayer.command.ride.vehicle.description=\u9A0E\u9644\u8FD1\u53EF\u4EE5\u9A0E\u5605\u5BE6\u9AD4 fakeplayer.command.select.description=\u9078\u4E2D\u5047\u4EBA fakeplayer.command.select.success.clear=\u6E05\u9664\u9078\u4E2D\u5047\u4EBA @@ -146,4 +146,6 @@ fakeplayer.spawn.error.name.online-dead=\u540D\u7A31 {0} \u6B63\u5728\u904A\u623 fakeplayer.spawn.error.name.start-with-illegal-character=\u81EA\u5B9A\u7FA9\u540D\u7A31\u5514\u53EF\u4EE5\u4EE5 {0} \u958B\u982D fakeplayer.spawn.error.name.too-long=\u540D\u7A31\u81F3\u591A {0} \u500B\u5B57 fakeplayer.spawn.error.name.too-short=\u540D\u7A31\u81F3\u5C11 {0} \u500B\u5B57 -fakeplayer.spawn.error.name.used=\u540D\u7A31 {0} \u88AB\u771F\u5BE6\u73A9\u5BB6({1})\u4F7F\u7528\u904E\u4E86 \ No newline at end of file +fakeplayer.spawn.error.name.used=\u540D\u7A31 {0} \u88AB\u771F\u5BE6\u73A9\u5BB6({1})\u4F7F\u7528\u904E\u4E86 +fakeplayer.command.ride.entity.error.too-far=\u6307\u5B9A\u7684\u5BE6\u9AD4\u96E2 {0} \u592A\u9060\u4E86 +fakeplayer.command.ride.entity.description=\u9A0E\u6307\u5B9A\u5BE6\u9AD4 \ No newline at end of file diff --git a/fakeplayer-core/src/main/resources/message/message_zh_TW.properties b/fakeplayer-core/src/main/resources/message/message_zh_TW.properties index f53e2ff..a45b95c 100644 --- a/fakeplayer-core/src/main/resources/message/message_zh_TW.properties +++ b/fakeplayer-core/src/main/resources/message/message_zh_TW.properties @@ -68,7 +68,6 @@ fakeplayer.command.move.forward.description=\u5411\u524D\u79FB\u52D5 fakeplayer.command.move.left.description=\u5411\u5DE6\u79FB\u52D5 fakeplayer.command.move.right.description=\u5411\u53F3\u79FB\u52D5 fakeplayer.command.reload-translation.description=\u91CD\u65B0\u52A0\u8F09\u8A9E\u8A00\u6587\u4EF6 -fakeplayer.command.reload.config-file-not-found=\u914D\u7F6E\u6587\u4EF6 {0} \u4E0D\u5B58\u5728, \u4F60\u61C9\u8A72\u5C07 {1} \u91CD\u547D\u540D\u70BA {0} \u4F5C\u70BA\u914D\u7F6E\u6587\u4EF6, \u6C38\u9060\u4E0D\u8981\u76F4\u63A5\u4FEE\u6539 {1} ! fakeplayer.command.reload.description=\u91CD\u65B0\u52A0\u8F09\u914D\u7F6E\u6587\u4EF6 fakeplayer.command.respawn.description=\u5FA9\u6D3B\u5047\u4EBA fakeplayer.command.ride.anything.description=\u9A0E\u9644\u8FD1\u7684\u5BE6\u9AD4 @@ -77,6 +76,7 @@ fakeplayer.command.ride.me.description=\u9A0E\u4F60 fakeplayer.command.ride.me.error.too-far=\u4F60\u96E2 {0} \u592A\u9060\u4E86 fakeplayer.command.ride.stop.description=\u505C\u6B62\u9A0E\u4E58 fakeplayer.command.ride.target.description=\u9A0E\u76EE\u5149\u6240\u6307\u5BE6\u9AD4 +fakeplayer.command.ride.entity.error.ride-self=\u7121\u6CD5\u5DE6\u8173\u8E29\u53F3\u8173 fakeplayer.command.ride.vehicle.description=\u9A0E\u9644\u8FD1\u80FD\u9A0E\u7684\u5BE6\u9AD4 fakeplayer.command.select.description=\u9078\u4E2D\u5047\u4EBA fakeplayer.command.select.success.clear=\u6E05\u9664\u9078\u4E2D\u5047\u4EBA @@ -146,4 +146,6 @@ fakeplayer.spawn.error.name.online-dead=\u540D\u7A31 {0} \u6B63\u5728\u904A\u623 fakeplayer.spawn.error.name.start-with-illegal-character=\u81EA\u5B9A\u7FA9\u540D\u7A31\u4E0D\u80FD\u4EE5 {0} \u958B\u982D fakeplayer.spawn.error.name.too-long=\u540D\u7A31\u6700\u591A {0} \u500B\u5B57\u7B26 fakeplayer.spawn.error.name.too-short=\u540D\u7A31\u6700\u5C11 {0} \u500B\u5B57\u7B26 -fakeplayer.spawn.error.name.used=\u540D\u7A31 {0} \u88AB\u771F\u5BE6\u73A9\u5BB6({1})\u4F7F\u7528\u904E\u4E86 \ No newline at end of file +fakeplayer.spawn.error.name.used=\u540D\u7A31 {0} \u88AB\u771F\u5BE6\u73A9\u5BB6({1})\u4F7F\u7528\u904E\u4E86 +fakeplayer.command.ride.entity.error.too-far=\u6307\u5B9A\u7684\u5BE6\u9AD4\u96E2 {0} \u592A\u9060\u4E86 +fakeplayer.command.ride.entity.description=\u9A0E\u6307\u5B9A\u5BE6\u9AD4 \ No newline at end of file