1
0
Fork 0

Bring back /fly command

The persistentFlight option just kicks in flight whenever a player joins
the server mid-air. Servers with this will have the /fly command enabled
anyway, so it doesn't hurt.
This commit is contained in:
Ryan Fox 2022-01-29 19:06:54 -08:00
parent 8c51919e4e
commit d7c1f5297a
Signed by: flewkey
GPG Key ID: 94F56ADFD848851E
5 changed files with 41 additions and 48 deletions

View File

@ -1,6 +1,7 @@
package party._2a03.mc.command;
import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.entity.player.PlayerAbilities;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
@ -11,21 +12,22 @@ public class FlyCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(CommandManager.literal("fly").executes(ctx -> {
ServerCommandSource source = ctx.getSource();
//if (Config.getBool("disableFlyCommand")) {
if (Config.getBool("disableFlyCommand")) {
source.sendFeedback(new LiteralText("The /fly command is disabled"), true);
return 0;
/*}
}
ServerPlayerEntity sender = source.getPlayer();
boolean flight = sender.abilities.allowFlying;
sender.abilities.allowFlying = !flight;
PlayerAbilities abilities = sender.getAbilities();
boolean flight = abilities.allowFlying;
abilities.allowFlying = !flight;
if (!flight)
source.sendFeedback(new LiteralText("I wanna fly like an eagle... to the sea!"), true);
else {
source.sendFeedback(new LiteralText("Flight disabled"), true);
sender.abilities.flying = false;
abilities.flying = false;
}
sender.sendAbilitiesUpdate();
return 1;*/
return 1;
}));
}
}

View File

@ -1,32 +0,0 @@
package party._2a03.mc.mixin;
import net.minecraft.entity.player.PlayerAbilities;
import net.minecraft.world.GameMode;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import party._2a03.mc.util.Config;
@Mixin(GameMode.class)
public class MixinGameMode {
private boolean flying;
@Inject(method = "setAbilities", at = @At("HEAD"))
public void checkFlight(PlayerAbilities abilities, CallbackInfo ci) {
this.flying = abilities.flying;
}
@Inject(method = "setAbilities", at = @At("TAIL"))
public void restoreFlight(PlayerAbilities abilities, CallbackInfo ci) {
if (!Config.getBool("persistentFlight"))
return;
if (abilities.flying)
return;
if (this.flying) {
abilities.allowFlying = true;
abilities.flying = true;
}
}
}

View File

@ -0,0 +1,32 @@
package party._2a03.mc.mixin;
import net.minecraft.entity.player.PlayerAbilities;
import net.minecraft.server.PlayerManager;
import net.minecraft.network.ClientConnection;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.world.GameMode;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import party._2a03.mc.util.Config;
@Mixin(PlayerManager.class)
public abstract class MixinPlayerManager {
@Inject(method = "onPlayerConnect", at = @At(value = "INVOKE",
target = "Lnet/minecraft/server/network/ServerPlayerEntity;getAbilities()Lnet/minecraft/entity/player/PlayerAbilities;"))
public void persistFlight(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) {
if (!Config.getBool("persistentFlight"))
return;
if (player.isOnGround())
return;
GameMode gameMode = player.interactionManager.getGameMode();
if (gameMode == GameMode.CREATIVE || gameMode == GameMode.SPECTATOR)
return;
PlayerAbilities abilities = player.getAbilities();
abilities.allowFlying = true;
abilities.flying = true;
}
}

View File

@ -3,7 +3,6 @@ package party._2a03.mc.mixin;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.GameMode;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@ -30,12 +29,4 @@ public abstract class MixinServerPlayerEntity extends PlayerEntity {
ci.cancel();
}
}
/*@Inject(method = "setGameMode", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;sendAbilitiesUpdate()V"))
public void disableFlightIfSafe(GameMode gameMode, CallbackInfo ci) {
if (gameMode != GameMode.CREATIVE && gameMode != GameMode.SPECTATOR) {
this.abilities.allowFlying = false;
this.abilities.flying = false;
}
}*/
}

View File

@ -3,8 +3,8 @@
"package": "party._2a03.mc.mixin",
"compatibilityLevel": "JAVA_17",
"server": [
"MixinGameMode",
"MixinGameModeCommand",
"MixinPlayerManager",
"MixinRespawnAnchorBlock",
"MixinServerPlayerEntity",
"MixinTntBlock",