feat: add /fly speed <0.1-2.0> command, rename admin command to /fly player <player>, bump version to 1.1.0
This commit is contained in:
1 parent
d3a684b6e4
commit
bfbdfd2199
4 files changed
+68
-25
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package top.gtb520.java.mods.openfly.Commands;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.arguments.FloatArgumentType;
|
||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||
import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents;
|
||||
import net.minecraft.command.argument.EntityArgumentType;
|
||||
@@ -17,6 +18,10 @@ public class fly {
|
||||
// 记录开启了飞行的玩家UUID
|
||||
private static final Set<UUID> flyingPlayers = new HashSet<>();
|
||||
|
||||
// 飞行速度范围(/fly speed 参数范围)
|
||||
public static final float MIN_FLY_SPEED = 0.1F;
|
||||
public static final float MAX_FLY_SPEED = 2.0F;
|
||||
|
||||
public static void register() {
|
||||
// 注册命令
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
||||
@@ -40,24 +45,42 @@ public class fly {
|
||||
}
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})
|
||||
// /fly <player> - 切换指定玩家的飞行状态(需要OP权限)
|
||||
.then(CommandManager.argument("player", EntityArgumentType.player())
|
||||
.requires(source -> source.hasPermissionLevel(2))
|
||||
.executes(context -> {
|
||||
ServerPlayerEntity targetPlayer = EntityArgumentType.getPlayer(context, "player");
|
||||
UUID playerId = targetPlayer.getUuid();
|
||||
// /fly speed <0.1-2.0> - 设置自己的飞行速度(所有玩家可用)
|
||||
.then(CommandManager.literal("speed")
|
||||
.then(CommandManager.argument("speed", FloatArgumentType.floatArg(MIN_FLY_SPEED, MAX_FLY_SPEED))
|
||||
.executes(context -> {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
if (player == null) {
|
||||
context.getSource().sendFeedback(() -> Text.literal("该命令只能由玩家执行"), false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (flyingPlayers.contains(playerId)) {
|
||||
disableFly(targetPlayer);
|
||||
context.getSource().sendFeedback(
|
||||
() -> Text.literal("已禁用玩家 " + targetPlayer.getName().getString() + " 的飞行"), true);
|
||||
} else {
|
||||
enableFly(targetPlayer);
|
||||
context.getSource().sendFeedback(
|
||||
() -> Text.literal("已启用玩家 " + targetPlayer.getName().getString() + " 的飞行"), true);
|
||||
}
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}))
|
||||
float speed = FloatArgumentType.getFloat(context, "speed");
|
||||
player.getAbilities().setFlySpeed(speed);
|
||||
player.sendAbilitiesUpdate();
|
||||
context.getSource().sendFeedback(
|
||||
() -> Text.literal("飞行速度已设置为 " + String.format("%.2f", speed)), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})))
|
||||
// /fly player <player> - 切换指定玩家的飞行状态(需要OP权限)
|
||||
.then(CommandManager.literal("player")
|
||||
.requires(source -> source.hasPermissionLevel(2))
|
||||
.then(CommandManager.argument("player", EntityArgumentType.player())
|
||||
.executes(context -> {
|
||||
ServerPlayerEntity targetPlayer = EntityArgumentType.getPlayer(context, "player");
|
||||
UUID playerId = targetPlayer.getUuid();
|
||||
|
||||
if (flyingPlayers.contains(playerId)) {
|
||||
disableFly(targetPlayer);
|
||||
context.getSource().sendFeedback(
|
||||
() -> Text.literal("已禁用玩家 " + targetPlayer.getName().getString() + " 的飞行"), true);
|
||||
} else {
|
||||
enableFly(targetPlayer);
|
||||
context.getSource().sendFeedback(
|
||||
() -> Text.literal("已启用玩家 " + targetPlayer.getName().getString() + " 的飞行"), true);
|
||||
}
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})))
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user