Search in sources :

Example 56 with WrongUsageException

use of net.minecraft.command.WrongUsageException in project Armourers-Workshop by RiskyKen.

the class CommandGiveSkin method processCommand.

@Override
public void processCommand(ICommandSender commandSender, String[] currentCommand) {
    if (currentCommand.length < 3) {
        throw new WrongUsageException(getCommandUsage(commandSender), (Object) currentCommand);
    }
    String playerName = currentCommand[1];
    EntityPlayerMP player = getPlayer(commandSender, playerName);
    if (player == null) {
        return;
    }
    String skinName = currentCommand[2];
    if (!skinName.substring(0, 1).equals("\"")) {
        throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
    }
    int usedCommands = 2;
    if (!skinName.substring(skinName.length() - 1, skinName.length()).equals("\"")) {
        for (int i = 3; i < currentCommand.length; i++) {
            skinName += " " + currentCommand[i];
            if (skinName.substring(skinName.length() - 1, skinName.length()).equals("\"")) {
                usedCommands = i;
                break;
            }
        }
    }
    ModLogger.log("usedCommands used: " + usedCommands);
    ModLogger.log("total commands used: " + currentCommand.length);
    if (!skinName.substring(skinName.length() - 1, skinName.length()).equals("\"")) {
        throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
    }
    skinName = skinName.replace("\"", "");
    SkinDye skinDye = new SkinDye();
    for (int i = usedCommands + 1; i < currentCommand.length; i++) {
        String dyeCommand = currentCommand[i];
        ModLogger.log("Command dye: " + dyeCommand);
        if (!dyeCommand.contains("-")) {
            throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
        }
        String[] commandSplit = dyeCommand.split("-");
        if (commandSplit.length != 2) {
            throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
        }
        int dyeIndex = parseIntBounded(commandSender, commandSplit[0], 1, 8) - 1;
        String dye = commandSplit[1];
        if (dye.startsWith("#") && dye.length() == 7) {
            // dye = dye.substring(2, 8);
            if (isValidHex(dye)) {
                Color dyeColour = Color.decode(dye);
                int r = dyeColour.getRed();
                int g = dyeColour.getGreen();
                int b = dyeColour.getBlue();
                skinDye.addDye(dyeIndex, new byte[] { (byte) r, (byte) g, (byte) b, (byte) 255 });
            } else {
                throw new WrongUsageException("commands.armourers.invalidDyeFormat", (Object) dye);
            }
        } else if (dye.length() >= 5 & dye.contains(",")) {
            String[] dyeValues = dye.split(",");
            if (dyeValues.length != 3) {
                throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
            }
            int r = parseIntBounded(commandSender, dyeValues[0], 0, 255);
            int g = parseIntBounded(commandSender, dyeValues[1], 0, 255);
            int b = parseIntBounded(commandSender, dyeValues[2], 0, 255);
            skinDye.addDye(dyeIndex, new byte[] { (byte) r, (byte) g, (byte) b, (byte) 255 });
        } else {
            throw new WrongUsageException("commands.armourers.invalidDyeFormat", (Object) dye);
        }
    }
    LibraryFile libraryFile = new LibraryFile(skinName);
    Skin skin = SkinIOUtils.loadSkinFromLibraryFile(libraryFile);
    if (skin == null) {
        throw new WrongUsageException("commands.armourers.fileNotFound", (Object) skinName);
    }
    try {
        skin.lightHash();
    } catch (Exception e) {
        ModLogger.log(Level.ERROR, String.format("Unable to create ID for file %s.", libraryFile.toString()));
        return;
    }
    CommonSkinCache.INSTANCE.addEquipmentDataToCache(skin, libraryFile);
    SkinIdentifier skinIdentifier = new SkinIdentifier(0, libraryFile, 0, skin.getSkinType());
    ItemStack skinStack = SkinNBTHelper.makeEquipmentSkinStack(new SkinPointer(skinIdentifier, skinDye));
    EntityItem entityItem = player.dropPlayerItemWithRandomChoice(skinStack, false);
    entityItem.delayBeforeCanPickup = 0;
    entityItem.func_145797_a(player.getCommandSenderName());
}
Also used : SkinPointer(riskyken.armourersWorkshop.common.skin.data.SkinPointer) SkinDye(riskyken.armourersWorkshop.common.skin.data.SkinDye) Color(java.awt.Color) WrongUsageException(net.minecraft.command.WrongUsageException) SkinIdentifier(riskyken.armourersWorkshop.common.skin.data.SkinIdentifier) WrongUsageException(net.minecraft.command.WrongUsageException) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Skin(riskyken.armourersWorkshop.common.skin.data.Skin) LibraryFile(riskyken.armourersWorkshop.common.library.LibraryFile) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 57 with WrongUsageException

use of net.minecraft.command.WrongUsageException in project Armourers-Workshop by RiskyKen.

the class CommandResyncWardrobe method processCommand.

@Override
public void processCommand(ICommandSender commandSender, String[] currentCommand) {
    if (currentCommand.length != 2) {
        throw new WrongUsageException(getCommandUsage(commandSender), (Object) currentCommand);
    }
    String playerName = currentCommand[1];
    EntityPlayerMP player = getPlayer(commandSender, playerName);
    if (player == null) {
        return;
    }
    ExPropsPlayerSkinData.get(player).updateEquipmentDataToPlayersAround();
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 58 with WrongUsageException

use of net.minecraft.command.WrongUsageException in project Armourers-Workshop by RiskyKen.

the class CommandSetSkin method processCommand.

@Override
public void processCommand(ICommandSender commandSender, String[] currentCommand) {
    if (currentCommand.length < 3) {
        throw new WrongUsageException(getCommandUsage(commandSender), (Object) currentCommand);
    }
    String playerName = currentCommand[1];
    EntityPlayerMP player = getPlayer(commandSender, playerName);
    if (player == null) {
        return;
    }
    int slotNum = 0;
    slotNum = parseIntBounded(commandSender, currentCommand[2], 1, 8);
    String skinName = currentCommand[3];
    if (!skinName.substring(0, 1).equals("\"")) {
        throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
    }
    int usedCommands = 3;
    if (!skinName.substring(skinName.length() - 1, skinName.length()).equals("\"")) {
        for (int i = 3; i < currentCommand.length; i++) {
            skinName += " " + currentCommand[i];
            if (skinName.substring(skinName.length() - 1, skinName.length()).equals("\"")) {
                usedCommands = i;
                break;
            }
        }
    }
    ModLogger.log("usedCommands used: " + usedCommands);
    ModLogger.log("total commands used: " + currentCommand.length);
    if (!skinName.substring(skinName.length() - 1, skinName.length()).equals("\"")) {
        throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
    }
    skinName = skinName.replace("\"", "");
    SkinDye skinDye = new SkinDye();
    for (int i = usedCommands + 1; i < currentCommand.length; i++) {
        String dyeCommand = currentCommand[i];
        ModLogger.log("Command dye: " + dyeCommand);
        if (!dyeCommand.contains("-")) {
            throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
        }
        String[] commandSplit = dyeCommand.split("-");
        if (commandSplit.length != 2) {
            throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
        }
        int dyeIndex = parseIntBounded(commandSender, commandSplit[0], 1, 8) - 1;
        String dye = commandSplit[1];
        if (dye.startsWith("#") && dye.length() == 7) {
            // dye = dye.substring(2, 8);
            if (isValidHex(dye)) {
                Color dyeColour = Color.decode(dye);
                int r = dyeColour.getRed();
                int g = dyeColour.getGreen();
                int b = dyeColour.getBlue();
                skinDye.addDye(dyeIndex, new byte[] { (byte) r, (byte) g, (byte) b, (byte) 255 });
            } else {
                throw new WrongUsageException("commands.armourers.invalidDyeFormat", (Object) dye);
            }
        } else if (dye.length() >= 5 & dye.contains(",")) {
            String[] dyeValues = dye.split(",");
            if (dyeValues.length != 3) {
                throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
            }
            int r = parseIntBounded(commandSender, dyeValues[0], 0, 255);
            int g = parseIntBounded(commandSender, dyeValues[1], 0, 255);
            int b = parseIntBounded(commandSender, dyeValues[2], 0, 255);
            skinDye.addDye(dyeIndex, new byte[] { (byte) r, (byte) g, (byte) b, (byte) 255 });
        } else {
            throw new WrongUsageException("commands.armourers.invalidDyeFormat", (Object) dye);
        }
    }
    LibraryFile libraryFile = new LibraryFile(skinName);
    Skin skin = SkinIOUtils.loadSkinFromLibraryFile(libraryFile);
    if (skin == null) {
        throw new WrongUsageException("commands.armourers.fileNotFound", (Object) skinName);
    }
    try {
        skin.lightHash();
    } catch (Exception e) {
        ModLogger.log(Level.ERROR, String.format("Unable to create ID for file %s.", libraryFile.toString()));
        return;
    }
    CommonSkinCache.INSTANCE.addEquipmentDataToCache(skin, libraryFile);
    SkinIdentifier skinIdentifier = new SkinIdentifier(0, libraryFile, 0, skin.getSkinType());
    ItemStack skinStack = SkinNBTHelper.makeEquipmentSkinStack(new SkinPointer(skinIdentifier, skinDye));
    ExPropsPlayerSkinData.get(player).setEquipmentStack(skinStack, slotNum - 1);
}
Also used : SkinPointer(riskyken.armourersWorkshop.common.skin.data.SkinPointer) SkinDye(riskyken.armourersWorkshop.common.skin.data.SkinDye) Color(java.awt.Color) WrongUsageException(net.minecraft.command.WrongUsageException) SkinIdentifier(riskyken.armourersWorkshop.common.skin.data.SkinIdentifier) WrongUsageException(net.minecraft.command.WrongUsageException) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Skin(riskyken.armourersWorkshop.common.skin.data.Skin) LibraryFile(riskyken.armourersWorkshop.common.library.LibraryFile) ItemStack(net.minecraft.item.ItemStack)

Example 59 with WrongUsageException

use of net.minecraft.command.WrongUsageException in project Armourers-Workshop by RiskyKen.

the class CommandSetUnlockedWardrobeSlots method processCommand.

@Override
public void processCommand(ICommandSender commandSender, String[] currentCommand) {
    if (currentCommand.length != 4) {
        throw new WrongUsageException(getCommandUsage(commandSender), (Object) currentCommand);
    }
    String playerName = currentCommand[1];
    EntityPlayerMP player = getPlayer(commandSender, playerName);
    if (player == null) {
        return;
    }
    String skinTypeName = currentCommand[2];
    if (StringUtils.isNullOrEmpty(skinTypeName)) {
        throw new WrongUsageException(getCommandUsage(commandSender), (Object) currentCommand);
    }
    int count = 3;
    count = parseIntBounded(commandSender, currentCommand[3], 1, 8);
    ISkinType skinType = SkinTypeRegistry.INSTANCE.getSkinTypeFromRegistryName(skinTypeName);
    if (skinType == null) {
        throw new WrongUsageException(getCommandUsage(commandSender), (Object) currentCommand);
    }
    ExPropsPlayerSkinData.get(player).setSkinColumnCount(skinType, count);
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) ISkinType(riskyken.armourersWorkshop.api.common.skin.type.ISkinType) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 60 with WrongUsageException

use of net.minecraft.command.WrongUsageException in project Armourers-Workshop by RiskyKen.

the class CommandSetWardrobeOption method processCommand.

@Override
public void processCommand(ICommandSender commandSender, String[] currentCommand) {
    if (currentCommand.length != 4) {
        throw new WrongUsageException(getCommandUsage(commandSender), (Object) currentCommand);
    }
    EntityPlayerMP player = getPlayer(commandSender, currentCommand[1]);
    if (player == null) {
        return;
    }
    String subOption = currentCommand[2];
    boolean value = parseBoolean(commandSender, currentCommand[3]);
    int subOptionIndex = -1;
    for (int i = 0; i < SUB_OPTIONS.length; i++) {
        if (subOption.equals(SUB_OPTIONS[i])) {
            subOptionIndex = i;
            break;
        }
    }
    if (subOptionIndex == -1) {
        throw new WrongUsageException(getCommandUsage(commandSender), (Object) currentCommand);
    }
    ExPropsPlayerSkinData playerEquipmentData = ExPropsPlayerSkinData.get(player);
    if (playerEquipmentData != null) {
        EquipmentWardrobeData ewd = playerEquipmentData.getEquipmentWardrobeData();
        if (subOptionIndex < 4) {
            ewd.armourOverride.set(subOptionIndex, !value);
        }
        if (subOptionIndex == 4) {
            ewd.headOverlay = !value;
        }
        playerEquipmentData.setSkinInfo(ewd, true);
    }
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) EquipmentWardrobeData(riskyken.armourersWorkshop.common.skin.EquipmentWardrobeData) ExPropsPlayerSkinData(riskyken.armourersWorkshop.common.skin.ExPropsPlayerSkinData) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Aggregations

WrongUsageException (net.minecraft.command.WrongUsageException)63 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)28 CommandException (net.minecraft.command.CommandException)21 EntityPlayer (net.minecraft.entity.player.EntityPlayer)21 ItemStack (net.minecraft.item.ItemStack)11 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)8 ChatComponentText (net.minecraft.util.ChatComponentText)7 BlockPos (net.minecraft.util.math.BlockPos)6 MinecraftServer (net.minecraft.server.MinecraftServer)5 Entity (net.minecraft.entity.Entity)4 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)4 World (net.minecraft.world.World)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 Affinity (am2.api.spell.enums.Affinity)2 PlayerIdentifier (com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)2 Color (java.awt.Color)2 File (java.io.File)2 List (java.util.List)2 SpaceStationWorldData (micdoodle8.mods.galacticraft.core.dimension.SpaceStationWorldData)2 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)2