1
0
Fork 0

Add /fly command

This commit is contained in:
Ryan Fox 2020-05-29 07:26:43 +00:00
parent 6c8b3433fe
commit ca4acc3011
Signed by: flewkey
GPG Key ID: 94F56ADFD848851E
2 changed files with 28 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import java.nio.file.Path;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import party._2a03.mc.command.ConfigCommand;
import party._2a03.mc.command.FlyCommand;
import party._2a03.mc.command.HatCommand;
import party._2a03.mc.command.HeadCommand;
import party._2a03.mc.command.HomeCommand;
@ -43,6 +44,7 @@ public class MinecraftTweaks2a03 implements ModInitializer {
LOGGER.info("Registering 2a03.party commands");
CommandRegistry.INSTANCE.register(false, dispatcher -> {
ConfigCommand.register(dispatcher);
FlyCommand.register(dispatcher);
HatCommand.register(dispatcher);
HeadCommand.register(dispatcher);
HomeCommand.register(dispatcher);

View File

@ -0,0 +1,26 @@
package party._2a03.mc.command;
import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText;
public class FlyCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(CommandManager.literal("fly").executes(ctx -> {
ServerCommandSource source = ctx.getSource();
ServerPlayerEntity sender = source.getPlayer();
boolean flight = sender.abilities.allowFlying;
sender.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;
}
sender.sendAbilitiesUpdate();
return 1;
}));
}
}