Unicopia/src/main/java/com/minelittlepony/unicopia/command/CommandOverrideGameMode.java

49 lines
1.8 KiB
Java
Raw Normal View History

2018-09-12 01:29:49 +02:00
package com.minelittlepony.unicopia.command;
2018-09-12 02:26:07 +02:00
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
2018-09-12 01:29:49 +02:00
import net.minecraft.command.CommandException;
import net.minecraft.command.CommandGameMode;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.GameType;
class CommandOverrideGameMode extends CommandGameMode {
public void execute(MinecraftServer server, ICommandSender sender, String[] params) throws CommandException {
if (params.length <= 0) {
throw new WrongUsageException("commands.gamemode.usage");
}
GameType gametype = getGameModeFromCommand(sender, params[0]);
EntityPlayerMP entityplayermp = params.length >= 2 ? getPlayer(server, sender, params[1]) : getCommandSenderAsPlayer(sender);
updateGameMode(entityplayermp, gametype);
ITextComponent chatcomponenttranslation = new TextComponentTranslation("gameMode." + gametype.getName(), new Object[0]);
if (entityplayermp != sender) {
notifyCommandListener(sender, this, 1, "commands.gamemode.success.other", entityplayermp.getName(), chatcomponenttranslation);
} else {
notifyCommandListener(sender, this, 1, "commands.gamemode.success.self", chatcomponenttranslation);
}
}
private void updateGameMode(EntityPlayerMP player, GameType m) {
boolean flying = player.capabilities.isFlying;
player.setGameType(m);
2018-09-12 02:26:07 +02:00
player.capabilities.isFlying = PlayerSpeciesList.instance().getPlayer(player).getPlayerSpecies().canFly();
2018-09-12 01:29:49 +02:00
if (flying != player.capabilities.isFlying) {
player.sendPlayerAbilities();
}
player.fallDistance = 0;
}
}