diff --git a/README.md b/README.md new file mode 100644 index 0000000..2b395b4 --- /dev/null +++ b/README.md @@ -0,0 +1,56 @@ +# 介绍 +这个模组增加了一个命令(/rtp),用于将玩家随机传送到世界的任何一个位置。 + +# 命令格式 +- /rtp +- /rtp +- /rtp <被传送玩家名(PlayerID)> +- /rtp <被传送玩家名(PlayerID)> +- /rtp <被传送玩家名(PlayerID)> + +## 命令示例 +- /rtp +将执行命令的玩家随机传送到以(0,0)为中心点,2.9e7作为随机半径的范围内的随机一点 +2.9e+7 = 2.9 x 10^7 = 29000000 = 两千九百万 + +- /rtp 1000 +将执行命令的玩家随机传送到以(0,0)为中心点,1000作为随机半径的范围内的随机一点 + +- /rtp TheWhiteDog9487 +将TheWhiteDog9487随机传送到以(0,0)为中心点,2.9e7作为随机半径的范围内的随机一点 + +- /rtp TheWhiteDog9487 1000 +将TheWhiteDog9487随机传送到以(0,0)为中心点,1000作为随机半径的范围内的随机一点 + +- /rtp 1000 TheWhiteDog9487 +将TheWhiteDog9487随机传送到以(0,0)为中心点,1000作为随机半径的范围内的随机一点 + +# 依赖项 +由于我使用了fabric.api.command.v2中的CommandRegistrationCallback.EVENT来向游戏注册命令,所以这个模组需要依赖Fabric API + +# 关于玩家权限 +我参照原版的 /tp 命令,给 /rtp 设置了4级的权限要求。 +如果是原版或者类原版,你只需要让玩家有作弊的权限就可以用。 +插件服务器方面那些具体的权限分配,因为我自己没玩过所以我也没法给出参考意见。 + +# 在客户端还是服务器安装? +分以下情况: +1. 单人游戏 + 1. 物理服务器不存在,所以服务器不用管 + 2. 客户端安装即可 +2. 单人游戏 + 开放局域网 + 1. 使用客户端内置的服务器,开放局域网的那位玩家的客户端需要安装 + 2. 其他加入游戏的玩家不需要安装 +3. 使用独立服务器(类似server.jar这种文件) + 1. 服务器需要安装 + 2. 客户端不需要 + +# 一些小彩蛋 +你可以使用 /随机传送 来替代 /rtp +没错,Minecraft的命令是可以存在非ASCII字符的,所以我就整了一个 +例如: +- /rtp TheWhiteDog9487 1000 +- /随机传送 TheWhiteDog9487 1000 + +这两个命令的效果没有任何差别 +玩家权限限制和 /rtp 当然也是一样的,都是4级 \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 9c7db37..319739f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ yarn_mappings=1.20.4+build.3 loader_version=0.15.6 # Mod Properties -mod_version=0.2.0 +mod_version=0.2.1 maven_group=xyz.thewhitedog9487 archives_base_name=randomteleporter diff --git a/src/main/java/xyz/thewhitedog9487/CommandRegister.java b/src/main/java/xyz/thewhitedog9487/CommandRegister.java index 448912c..a339937 100644 --- a/src/main/java/xyz/thewhitedog9487/CommandRegister.java +++ b/src/main/java/xyz/thewhitedog9487/CommandRegister.java @@ -3,10 +3,13 @@ package xyz.thewhitedog9487; import com.mojang.brigadier.arguments.LongArgumentType; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.minecraft.block.Blocks; +import net.minecraft.command.argument.EntityArgumentType; import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; +import org.jetbrains.annotations.Nullable; import java.util.SplittableRandom; @@ -23,7 +26,7 @@ public class CommandRegister { dispatcher.register(literal(Name) .requires(source -> source.hasPermissionLevel(4)) .executes(context -> execute_command_radius( - context.getSource(),null)));}); + context.getSource(),null,null)));}); CommandRegistrationCallback.EVENT .register((dispatcher, registryAccess, environment) -> { dispatcher.register(literal(Name) @@ -31,12 +34,43 @@ public class CommandRegister { .requires(source -> source.hasPermissionLevel(4)) .executes(context -> execute_command_radius( context.getSource(), - LongArgumentType.getLong(context, "Radius(半径)")))));});} + LongArgumentType.getLong(context, "Radius(半径)"), + null))));}); + CommandRegistrationCallback.EVENT + .register((dispatcher, registryAccess, environment) -> { + dispatcher.register(literal(Name) + .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.player()) + .requires(source -> source.hasPermissionLevel(4)) + .executes(context -> execute_command_player( + context.getSource(), + null, + EntityArgumentType.getPlayer(context,"被传送玩家名(PlayerID)")))));}); + CommandRegistrationCallback.EVENT + .register((dispatcher, registryAccess, environment) -> { + dispatcher.register(literal(Name) + .then(argument("Radius(半径)", LongArgumentType.longArg()) + .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.player()) + .requires(source -> source.hasPermissionLevel(4)) + .executes(context -> execute_command_player( + context.getSource(), + LongArgumentType.getLong(context, "Radius(半径)"), + EntityArgumentType.getPlayer(context,"被传送玩家名(PlayerID)"))))));}); + CommandRegistrationCallback.EVENT + .register((dispatcher, registryAccess, environment) -> { + dispatcher.register(literal(Name) + .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.player()) + .then(argument("Radius(半径)", LongArgumentType.longArg()) + .requires(source -> source.hasPermissionLevel(4)) + .executes(context -> execute_command_player( + context.getSource(), + LongArgumentType.getLong(context, "Radius(半径)"), + EntityArgumentType.getPlayer(context,"被传送玩家名(PlayerID)"))))));});} public static void Register(){ Register("随机传送"); Register("rtp");} - static int execute_command_radius(ServerCommandSource Source, Long Radius){ - if (Source.getPlayer() == null) { + static int execute_command_radius(ServerCommandSource Source, @Nullable Long Radius, @Nullable ServerPlayerEntity Player){ + ServerPlayerEntity player = Player == null ? Source.getPlayer() : Player; + if (player == null) { Source.sendFeedback(()->{ return Text.translatable("error.twd.rtp.not_player"); }, true); return -1;} if (Radius == null){Radius = WorldBorder - (long) 1e4;} @@ -51,14 +85,16 @@ public class CommandRegister { ;Coordinate_Y--){} Coordinate_Y++; Vec3d Coordinate = new Vec3d(Coordinate_X, Coordinate_Y, Coordinate_Z); - if (Radius == WorldBorder && Retry < 126 && Distance(Source.getPlayer().getPos(), Coordinate) < 1e5){ + if (Radius == WorldBorder && Retry < 126 && Distance(player.getPos(), Coordinate) < 1e5){ Retry++; - execute_command_radius(Source, Radius); + execute_command_radius(Source, Radius,null); return 0;} if (Retry >= 126){ Source.sendFeedback(()->{ return Text.translatable("warning.twd.rtp.retry"); }, true);} - Source.getPlayer().teleport(Source.getWorld(), Coordinate_X, Coordinate_Y, Coordinate_Z, 0, 0); + player.teleport(Source.getWorld(), Coordinate_X, Coordinate_Y, Coordinate_Z, 0, 0); final int FinalCoordinate_Y = Coordinate_Y; - Source.sendFeedback(()->{ return Text.translatable("info.twd.rtp.success", Source.getPlayer().getName(), Coordinate_X, FinalCoordinate_Y, Coordinate_Z); },true); + Source.sendFeedback(()->{ return Text.translatable("info.twd.rtp.success", player.getName(), Coordinate_X, FinalCoordinate_Y, Coordinate_Z); },true); return 0;} + static int execute_command_player(ServerCommandSource Source, Long Radius, ServerPlayerEntity Player){ + return execute_command_radius(Source, Radius, Player);} } \ No newline at end of file diff --git a/src/main/resources/assets/randomteleporter/lang/en_us.json b/src/main/resources/assets/randomteleporter/lang/en_us.json index 988b421..83f2c2d 100644 --- a/src/main/resources/assets/randomteleporter/lang/en_us.json +++ b/src/main/resources/assets/randomteleporter/lang/en_us.json @@ -1,4 +1,6 @@ { - "twd-sasf.bilibili": "Bilibili", - "twd-sasf.blog": "Blog" + "modmenu.nameTranslation.randomteleporter": "RandomTeleporter", + "modmenu.descriptionTranslation.randomteleporter": "Added two commands for random teleportation", + "twd.bilibili": "Bilibili", + "twd.blog": "Blog" } \ No newline at end of file diff --git a/src/main/resources/assets/randomteleporter/lang/zh_cn.json b/src/main/resources/assets/randomteleporter/lang/zh_cn.json index f2ea851..9dd4a25 100644 --- a/src/main/resources/assets/randomteleporter/lang/zh_cn.json +++ b/src/main/resources/assets/randomteleporter/lang/zh_cn.json @@ -1,4 +1,6 @@ { + "modmenu.nameTranslation.randomteleporter": "随机传送", + "modmenu.descriptionTranslation.randomteleporter": "增加了两个用于随机传送的命令", "info.twd.rtp.success": "已将玩家%s传送到%d %d %d", "error.twd.rtp.not_player": "执行命令的不是玩家", "warning.twd.rtp.retry": "重试次数过大,为避免死循环将在本次传送中取消距离保护", diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 77aebd2..9a2510a 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -9,7 +9,8 @@ ], "contact": { "homepage": "https://modrinth.com/mod/randomteleporter", - "sources": "https://github.com/TheWhiteDog9487/RandomTeleporter" + "sources": "https://github.com/TheWhiteDog9487/RandomTeleporter", + "issues": "https://github.com/TheWhiteDog9487/RandomTeleporter/issues" }, "license": "WTFPL", "icon": "assets/randomteleporter/icon.png",