mirror of
https://github.com/TheWhiteDog9487/RandomTeleporter.git
synced 2025-08-30 07:03:04 +00:00
0.2.1
完善了一下命令,非常的人性化。 添加了README
This commit is contained in:
@@ -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);}
|
||||
}
|
@@ -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"
|
||||
}
|
@@ -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": "重试次数过大,为避免死循环将在本次传送中取消距离保护",
|
||||
|
@@ -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",
|
||||
|
Reference in New Issue
Block a user