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;
import com.minelittlepony.unicopia.player.IPlayer;
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);
player.capabilities.isFlying = ((IPlayer)player).getPlayerSpecies().canFly();
if (flying != player.capabilities.isFlying) {
player.sendPlayerAbilities();
}
player.fallDistance = 0;
}
}