当前位置: 首页>>代码示例>>Java>>正文


Java NBTException.getMessage方法代码示例

本文整理汇总了Java中net.minecraft.nbt.NBTException.getMessage方法的典型用法代码示例。如果您正苦于以下问题:Java NBTException.getMessage方法的具体用法?Java NBTException.getMessage怎么用?Java NBTException.getMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.minecraft.nbt.NBTException的用法示例。


在下文中一共展示了NBTException.getMessage方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processCommand

import net.minecraft.nbt.NBTException; //导入方法依赖的package包/类
/**
 * Callback when the command is invoked
 */
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 1)
    {
        throw new WrongUsageException("commands.testfor.usage", new Object[0]);
    }
    else
    {
        Entity entity = func_175768_b(sender, args[0]);
        NBTTagCompound nbttagcompound = null;

        if (args.length >= 2)
        {
            try
            {
                nbttagcompound = JsonToNBT.getTagFromJson(buildString(args, 1));
            }
            catch (NBTException nbtexception)
            {
                throw new CommandException("commands.testfor.tagError", new Object[] {nbtexception.getMessage()});
            }
        }

        if (nbttagcompound != null)
        {
            NBTTagCompound nbttagcompound1 = new NBTTagCompound();
            entity.writeToNBT(nbttagcompound1);

            if (!NBTUtil.func_181123_a(nbttagcompound, nbttagcompound1, true))
            {
                throw new CommandException("commands.testfor.failure", new Object[] {entity.getName()});
            }
        }

        notifyOperators(sender, this, "commands.testfor.success", new Object[] {entity.getName()});
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:41,代码来源:CommandTestFor.java

示例2: execute

import net.minecraft.nbt.NBTException; //导入方法依赖的package包/类
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 1)
    {
        throw new WrongUsageException("commands.testfor.usage", new Object[0]);
    }
    else
    {
        Entity entity = getEntity(server, sender, args[0]);
        NBTTagCompound nbttagcompound = null;

        if (args.length >= 2)
        {
            try
            {
                nbttagcompound = JsonToNBT.getTagFromJson(buildString(args, 1));
            }
            catch (NBTException nbtexception)
            {
                throw new CommandException("commands.testfor.tagError", new Object[] {nbtexception.getMessage()});
            }
        }

        if (nbttagcompound != null)
        {
            NBTTagCompound nbttagcompound1 = entityToNBT(entity);

            if (!NBTUtil.areNBTEquals(nbttagcompound, nbttagcompound1, true))
            {
                throw new CommandException("commands.testfor.failure", new Object[] {entity.getName()});
            }
        }

        notifyCommandListener(sender, this, "commands.testfor.success", new Object[] {entity.getName()});
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:40,代码来源:CommandTestFor.java

示例3: addPlayerScore

import net.minecraft.nbt.NBTException; //导入方法依赖的package包/类
protected void addPlayerScore(ICommandSender sender, String[] p_184918_2_, int p_184918_3_, MinecraftServer server) throws CommandException
{
    String s = p_184918_2_[p_184918_3_ - 1];
    int i = p_184918_3_;
    String s1 = getEntityName(server, sender, p_184918_2_[p_184918_3_++]);

    if (s1.length() > 40)
    {
        throw new SyntaxErrorException("commands.scoreboard.players.name.tooLong", new Object[] {s1, Integer.valueOf(40)});
    }
    else
    {
        ScoreObjective scoreobjective = this.convertToObjective(p_184918_2_[p_184918_3_++], true, server);
        int j = "set".equalsIgnoreCase(s) ? parseInt(p_184918_2_[p_184918_3_++]) : parseInt(p_184918_2_[p_184918_3_++], 0);

        if (p_184918_2_.length > p_184918_3_)
        {
            Entity entity = getEntity(server, sender, p_184918_2_[i]);

            try
            {
                NBTTagCompound nbttagcompound = JsonToNBT.getTagFromJson(buildString(p_184918_2_, p_184918_3_));
                NBTTagCompound nbttagcompound1 = entityToNBT(entity);

                if (!NBTUtil.areNBTEquals(nbttagcompound, nbttagcompound1, true))
                {
                    throw new CommandException("commands.scoreboard.players.set.tagMismatch", new Object[] {s1});
                }
            }
            catch (NBTException nbtexception)
            {
                throw new CommandException("commands.scoreboard.players.set.tagError", new Object[] {nbtexception.getMessage()});
            }
        }

        Scoreboard scoreboard = this.getScoreboard(server);
        Score score = scoreboard.getOrCreateScore(s1, scoreobjective);

        if ("set".equalsIgnoreCase(s))
        {
            score.setScorePoints(j);
        }
        else if ("add".equalsIgnoreCase(s))
        {
            score.increaseScore(j);
        }
        else
        {
            score.decreaseScore(j);
        }

        notifyCommandListener(sender, this, "commands.scoreboard.players.set.success", new Object[] {scoreobjective.getName(), s1, Integer.valueOf(score.getScorePoints())});
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:55,代码来源:CommandScoreboard.java

示例4: processCommand

import net.minecraft.nbt.NBTException; //导入方法依赖的package包/类
/**
 * Callback when the command is invoked
 */
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 4)
    {
        throw new WrongUsageException("commands.blockdata.usage", new Object[0]);
    }
    else
    {
        sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
        BlockPos blockpos = parseBlockPos(sender, args, 0, false);
        World world = sender.getEntityWorld();

        if (!world.isBlockLoaded(blockpos))
        {
            throw new CommandException("commands.blockdata.outOfWorld", new Object[0]);
        }
        else
        {
            TileEntity tileentity = world.getTileEntity(blockpos);

            if (tileentity == null)
            {
                throw new CommandException("commands.blockdata.notValid", new Object[0]);
            }
            else
            {
                NBTTagCompound nbttagcompound = new NBTTagCompound();
                tileentity.writeToNBT(nbttagcompound);
                NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttagcompound.copy();
                NBTTagCompound nbttagcompound2;

                try
                {
                    nbttagcompound2 = JsonToNBT.getTagFromJson(getChatComponentFromNthArg(sender, args, 3).getUnformattedText());
                }
                catch (NBTException nbtexception)
                {
                    throw new CommandException("commands.blockdata.tagError", new Object[] {nbtexception.getMessage()});
                }

                nbttagcompound.merge(nbttagcompound2);
                nbttagcompound.setInteger("x", blockpos.getX());
                nbttagcompound.setInteger("y", blockpos.getY());
                nbttagcompound.setInteger("z", blockpos.getZ());

                if (nbttagcompound.equals(nbttagcompound1))
                {
                    throw new CommandException("commands.blockdata.failed", new Object[] {nbttagcompound.toString()});
                }
                else
                {
                    tileentity.readFromNBT(nbttagcompound);
                    tileentity.markDirty();
                    world.markBlockForUpdate(blockpos);
                    sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 1);
                    notifyOperators(sender, this, "commands.blockdata.success", new Object[] {nbttagcompound.toString()});
                }
            }
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:65,代码来源:CommandBlockData.java

示例5: execute

import net.minecraft.nbt.NBTException; //导入方法依赖的package包/类
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 2)
    {
        throw new WrongUsageException("commands.entitydata.usage", new Object[0]);
    }
    else
    {
        Entity entity = getEntity(server, sender, args[0]);

        if (entity instanceof EntityPlayer)
        {
            throw new CommandException("commands.entitydata.noPlayers", new Object[] {entity.getDisplayName()});
        }
        else
        {
            NBTTagCompound nbttagcompound = entityToNBT(entity);
            NBTTagCompound nbttagcompound1 = nbttagcompound.copy();
            NBTTagCompound nbttagcompound2;

            try
            {
                nbttagcompound2 = JsonToNBT.getTagFromJson(getChatComponentFromNthArg(sender, args, 1).getUnformattedText());
            }
            catch (NBTException nbtexception)
            {
                throw new CommandException("commands.entitydata.tagError", new Object[] {nbtexception.getMessage()});
            }

            UUID uuid = entity.getUniqueID();
            nbttagcompound.merge(nbttagcompound2);
            entity.setUniqueId(uuid);

            if (nbttagcompound.equals(nbttagcompound1))
            {
                throw new CommandException("commands.entitydata.failed", new Object[] {nbttagcompound.toString()});
            }
            else
            {
                entity.readFromNBT(nbttagcompound);
                notifyCommandListener(sender, this, "commands.entitydata.success", new Object[] {nbttagcompound.toString()});
            }
        }
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:49,代码来源:CommandEntityData.java

示例6: processCommand

import net.minecraft.nbt.NBTException; //导入方法依赖的package包/类
/**
 * Callback when the command is invoked
 */
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
    EntityPlayerMP entityplayermp = args.length == 0 ? getCommandSenderAsPlayer(sender) : getPlayer(sender, args[0]);
    Item item = args.length >= 2 ? getItemByText(sender, args[1]) : null;
    int i = args.length >= 3 ? parseInt(args[2], -1) : -1;
    int j = args.length >= 4 ? parseInt(args[3], -1) : -1;
    NBTTagCompound nbttagcompound = null;

    if (args.length >= 5)
    {
        try
        {
            nbttagcompound = JsonToNBT.getTagFromJson(buildString(args, 4));
        }
        catch (NBTException nbtexception)
        {
            throw new CommandException("commands.clear.tagError", new Object[] {nbtexception.getMessage()});
        }
    }

    if (args.length >= 2 && item == null)
    {
        throw new CommandException("commands.clear.failure", new Object[] {entityplayermp.getName()});
    }
    else
    {
        int k = entityplayermp.inventory.clearMatchingItems(item, i, j, nbttagcompound);
        entityplayermp.inventoryContainer.detectAndSendChanges();

        if (!entityplayermp.capabilities.isCreativeMode)
        {
            entityplayermp.updateHeldItem();
        }

        sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, k);

        if (k == 0)
        {
            throw new CommandException("commands.clear.failure", new Object[] {entityplayermp.getName()});
        }
        else
        {
            if (j == 0)
            {
                sender.addChatMessage(new ChatComponentTranslation("commands.clear.testing", new Object[] {entityplayermp.getName(), Integer.valueOf(k)}));
            }
            else
            {
                notifyOperators(sender, this, "commands.clear.success", new Object[] {entityplayermp.getName(), Integer.valueOf(k)});
            }
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:57,代码来源:CommandClearInventory.java

示例7: execute

import net.minecraft.nbt.NBTException; //导入方法依赖的package包/类
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 2)
    {
        throw new WrongUsageException("commands.give.usage", new Object[0]);
    }
    else
    {
        EntityPlayer entityplayer = getPlayer(server, sender, args[0]);
        Item item = getItemByText(sender, args[1]);
        int i = args.length >= 3 ? parseInt(args[2], 1, 64) : 1;
        int j = args.length >= 4 ? parseInt(args[3]) : 0;
        ItemStack itemstack = new ItemStack(item, i, j);

        if (args.length >= 5)
        {
            String s = getChatComponentFromNthArg(sender, args, 4).getUnformattedText();

            try
            {
                itemstack.setTagCompound(JsonToNBT.getTagFromJson(s));
            }
            catch (NBTException nbtexception)
            {
                throw new CommandException("commands.give.tagError", new Object[] {nbtexception.getMessage()});
            }
        }

        boolean flag = entityplayer.inventory.addItemStackToInventory(itemstack);

        if (flag)
        {
            entityplayer.worldObj.playSound((EntityPlayer)null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((entityplayer.getRNG().nextFloat() - entityplayer.getRNG().nextFloat()) * 0.7F + 1.0F) * 2.0F);
            entityplayer.inventoryContainer.detectAndSendChanges();
        }

        if (flag && itemstack.stackSize <= 0)
        {
            itemstack.stackSize = 1;
            sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, i);
            EntityItem entityitem1 = entityplayer.dropItem(itemstack, false);

            if (entityitem1 != null)
            {
                entityitem1.makeFakeItem();
            }
        }
        else
        {
            sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, i - itemstack.stackSize);
            EntityItem entityitem = entityplayer.dropItem(itemstack, false);

            if (entityitem != null)
            {
                entityitem.setNoPickupDelay();
                entityitem.setOwner(entityplayer.getName());
            }
        }

        notifyCommandListener(sender, this, "commands.give.success", new Object[] {itemstack.getTextComponent(), Integer.valueOf(i), entityplayer.getName()});
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:66,代码来源:CommandGive.java

示例8: processCommand

import net.minecraft.nbt.NBTException; //导入方法依赖的package包/类
/**
 * Callback when the command is invoked
 */
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 2)
    {
        throw new WrongUsageException("commands.entitydata.usage", new Object[0]);
    }
    else
    {
        Entity entity = func_175768_b(sender, args[0]);

        if (entity instanceof EntityPlayer)
        {
            throw new CommandException("commands.entitydata.noPlayers", new Object[] {entity.getDisplayName()});
        }
        else
        {
            NBTTagCompound nbttagcompound = new NBTTagCompound();
            entity.writeToNBT(nbttagcompound);
            NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttagcompound.copy();
            NBTTagCompound nbttagcompound2;

            try
            {
                nbttagcompound2 = JsonToNBT.getTagFromJson(getChatComponentFromNthArg(sender, args, 1).getUnformattedText());
            }
            catch (NBTException nbtexception)
            {
                throw new CommandException("commands.entitydata.tagError", new Object[] {nbtexception.getMessage()});
            }

            nbttagcompound2.removeTag("UUIDMost");
            nbttagcompound2.removeTag("UUIDLeast");
            nbttagcompound.merge(nbttagcompound2);

            if (nbttagcompound.equals(nbttagcompound1))
            {
                throw new CommandException("commands.entitydata.failed", new Object[] {nbttagcompound.toString()});
            }
            else
            {
                entity.readFromNBT(nbttagcompound);
                notifyOperators(sender, this, "commands.entitydata.success", new Object[] {nbttagcompound.toString()});
            }
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:50,代码来源:CommandEntityData.java

示例9: applyPlayerTag

import net.minecraft.nbt.NBTException; //导入方法依赖的package包/类
protected void applyPlayerTag(MinecraftServer server, ICommandSender sender, String[] p_184924_3_, int p_184924_4_) throws CommandException
{
    String s = getEntityName(server, sender, p_184924_3_[p_184924_4_]);
    Entity entity = getEntity(server, sender, p_184924_3_[p_184924_4_++]);
    String s1 = p_184924_3_[p_184924_4_++];
    Set<String> set = entity.getTags();

    if ("list".equals(s1))
    {
        if (!set.isEmpty())
        {
            TextComponentTranslation textcomponenttranslation = new TextComponentTranslation("commands.scoreboard.players.tag.list", new Object[] {s});
            textcomponenttranslation.getStyle().setColor(TextFormatting.DARK_GREEN);
            sender.addChatMessage(textcomponenttranslation);
            sender.addChatMessage(new TextComponentString(joinNiceString(set.toArray())));
        }

        sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, set.size());
    }
    else if (p_184924_3_.length < 5)
    {
        throw new WrongUsageException("commands.scoreboard.players.tag.usage", new Object[0]);
    }
    else
    {
        String s2 = p_184924_3_[p_184924_4_++];

        if (p_184924_3_.length > p_184924_4_)
        {
            try
            {
                NBTTagCompound nbttagcompound = JsonToNBT.getTagFromJson(buildString(p_184924_3_, p_184924_4_));
                NBTTagCompound nbttagcompound1 = entityToNBT(entity);

                if (!NBTUtil.areNBTEquals(nbttagcompound, nbttagcompound1, true))
                {
                    throw new CommandException("commands.scoreboard.players.tag.tagMismatch", new Object[] {s});
                }
            }
            catch (NBTException nbtexception)
            {
                throw new CommandException("commands.scoreboard.players.tag.tagError", new Object[] {nbtexception.getMessage()});
            }
        }

        if ("add".equals(s1))
        {
            if (!entity.addTag(s2))
            {
                throw new CommandException("commands.scoreboard.players.tag.tooMany", new Object[] {Integer.valueOf(1024)});
            }

            notifyCommandListener(sender, this, "commands.scoreboard.players.tag.success.add", new Object[] {s2});
        }
        else
        {
            if (!"remove".equals(s1))
            {
                throw new WrongUsageException("commands.scoreboard.players.tag.usage", new Object[0]);
            }

            if (!entity.removeTag(s2))
            {
                throw new CommandException("commands.scoreboard.players.tag.notFound", new Object[] {s2});
            }

            notifyCommandListener(sender, this, "commands.scoreboard.players.tag.success.remove", new Object[] {s2});
        }
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:71,代码来源:CommandScoreboard.java

示例10: execute

import net.minecraft.nbt.NBTException; //导入方法依赖的package包/类
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 4)
    {
        throw new WrongUsageException("commands.blockdata.usage", new Object[0]);
    }
    else
    {
        sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
        BlockPos blockpos = parseBlockPos(sender, args, 0, false);
        World world = sender.getEntityWorld();

        if (!world.isBlockLoaded(blockpos))
        {
            throw new CommandException("commands.blockdata.outOfWorld", new Object[0]);
        }
        else
        {
            IBlockState iblockstate = world.getBlockState(blockpos);
            TileEntity tileentity = world.getTileEntity(blockpos);

            if (tileentity == null)
            {
                throw new CommandException("commands.blockdata.notValid", new Object[0]);
            }
            else
            {
                NBTTagCompound nbttagcompound = tileentity.writeToNBT(new NBTTagCompound());
                NBTTagCompound nbttagcompound1 = nbttagcompound.copy();
                NBTTagCompound nbttagcompound2;

                try
                {
                    nbttagcompound2 = JsonToNBT.getTagFromJson(getChatComponentFromNthArg(sender, args, 3).getUnformattedText());
                }
                catch (NBTException nbtexception)
                {
                    throw new CommandException("commands.blockdata.tagError", new Object[] {nbtexception.getMessage()});
                }

                nbttagcompound.merge(nbttagcompound2);
                nbttagcompound.setInteger("x", blockpos.getX());
                nbttagcompound.setInteger("y", blockpos.getY());
                nbttagcompound.setInteger("z", blockpos.getZ());

                if (nbttagcompound.equals(nbttagcompound1))
                {
                    throw new CommandException("commands.blockdata.failed", new Object[] {nbttagcompound.toString()});
                }
                else
                {
                    tileentity.readFromNBT(nbttagcompound);
                    tileentity.markDirty();
                    world.notifyBlockUpdate(blockpos, iblockstate, iblockstate, 3);
                    sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 1);
                    notifyCommandListener(sender, this, "commands.blockdata.success", new Object[] {nbttagcompound.toString()});
                }
            }
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:65,代码来源:CommandBlockData.java

示例11: execute

import net.minecraft.nbt.NBTException; //导入方法依赖的package包/类
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 2)
    {
        throw new WrongUsageException("commands.give.usage", new Object[0]);
    }
    else
    {
        EntityPlayer entityplayer = getPlayer(server, sender, args[0]);
        Item item = getItemByText(sender, args[1]);
        int i = args.length >= 3 ? parseInt(args[2], 1, 64) : 1;
        int j = args.length >= 4 ? parseInt(args[3]) : 0;
        ItemStack itemstack = new ItemStack(item, i, j);

        if (args.length >= 5)
        {
            String s = getChatComponentFromNthArg(sender, args, 4).getUnformattedText();

            try
            {
                itemstack.setTagCompound(JsonToNBT.getTagFromJson(s));
            }
            catch (NBTException nbtexception)
            {
                throw new CommandException("commands.give.tagError", new Object[] {nbtexception.getMessage()});
            }
        }

        boolean flag = entityplayer.inventory.addItemStackToInventory(itemstack);

        if (flag)
        {
            entityplayer.world.playSound((EntityPlayer)null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((entityplayer.getRNG().nextFloat() - entityplayer.getRNG().nextFloat()) * 0.7F + 1.0F) * 2.0F);
            entityplayer.inventoryContainer.detectAndSendChanges();
        }

        if (flag && itemstack.func_190926_b())
        {
            itemstack.func_190920_e(1);
            sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, i);
            EntityItem entityitem1 = entityplayer.dropItem(itemstack, false);

            if (entityitem1 != null)
            {
                entityitem1.makeFakeItem();
            }
        }
        else
        {
            sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, i - itemstack.func_190916_E());
            EntityItem entityitem = entityplayer.dropItem(itemstack, false);

            if (entityitem != null)
            {
                entityitem.setNoPickupDelay();
                entityitem.setOwner(entityplayer.getName());
            }
        }

        notifyCommandListener(sender, this, "commands.give.success", new Object[] {itemstack.getTextComponent(), Integer.valueOf(i), entityplayer.getName()});
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:66,代码来源:CommandGive.java

示例12: execute

import net.minecraft.nbt.NBTException; //导入方法依赖的package包/类
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 1)
    {
        throw new WrongUsageException("commands.summon.usage", new Object[0]);
    }
    else
    {
        String s = args[0];
        BlockPos blockpos = sender.getPosition();
        Vec3d vec3d = sender.getPositionVector();
        double d0 = vec3d.xCoord;
        double d1 = vec3d.yCoord;
        double d2 = vec3d.zCoord;

        if (args.length >= 4)
        {
            d0 = parseDouble(d0, args[1], true);
            d1 = parseDouble(d1, args[2], false);
            d2 = parseDouble(d2, args[3], true);
            blockpos = new BlockPos(d0, d1, d2);
        }

        World world = sender.getEntityWorld();

        if (!world.isBlockLoaded(blockpos))
        {
            throw new CommandException("commands.summon.outOfWorld", new Object[0]);
        }
        else if ("LightningBolt".equals(s))
        {
            world.addWeatherEffect(new EntityLightningBolt(world, d0, d1, d2, false));
            notifyCommandListener(sender, this, "commands.summon.success", new Object[0]);
        }
        else
        {
            NBTTagCompound nbttagcompound = new NBTTagCompound();
            boolean flag = false;

            if (args.length >= 5)
            {
                ITextComponent itextcomponent = getChatComponentFromNthArg(sender, args, 4);

                try
                {
                    nbttagcompound = JsonToNBT.getTagFromJson(itextcomponent.getUnformattedText());
                    flag = true;
                }
                catch (NBTException nbtexception)
                {
                    throw new CommandException("commands.summon.tagError", new Object[] {nbtexception.getMessage()});
                }
            }

            nbttagcompound.setString("id", s);
            Entity entity = AnvilChunkLoader.readWorldEntityPos(nbttagcompound, world, d0, d1, d2, true);

            if (entity == null)
            {
                throw new CommandException("commands.summon.failed", new Object[0]);
            }
            else
            {
                entity.setLocationAndAngles(d0, d1, d2, entity.rotationYaw, entity.rotationPitch);

                if (!flag && entity instanceof EntityLiving)
                {
                    ((EntityLiving)entity).onInitialSpawn(world.getDifficultyForLocation(new BlockPos(entity)), (IEntityLivingData)null);
                }

                notifyCommandListener(sender, this, "commands.summon.success", new Object[0]);
            }
        }
    }
}
 
开发者ID:BlazeAxtrius,项目名称:ExpandedRailsMod,代码行数:79,代码来源:CommandSummon.java

示例13: execute

import net.minecraft.nbt.NBTException; //导入方法依赖的package包/类
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    EntityPlayerMP entityplayermp = args.length == 0 ? getCommandSenderAsPlayer(sender) : getPlayer(server, sender, args[0]);
    Item item = args.length >= 2 ? getItemByText(sender, args[1]) : null;
    int i = args.length >= 3 ? parseInt(args[2], -1) : -1;
    int j = args.length >= 4 ? parseInt(args[3], -1) : -1;
    NBTTagCompound nbttagcompound = null;

    if (args.length >= 5)
    {
        try
        {
            nbttagcompound = JsonToNBT.getTagFromJson(buildString(args, 4));
        }
        catch (NBTException nbtexception)
        {
            throw new CommandException("commands.clear.tagError", new Object[] {nbtexception.getMessage()});
        }
    }

    if (args.length >= 2 && item == null)
    {
        throw new CommandException("commands.clear.failure", new Object[] {entityplayermp.getName()});
    }
    else
    {
        int k = entityplayermp.inventory.clearMatchingItems(item, i, j, nbttagcompound);
        entityplayermp.inventoryContainer.detectAndSendChanges();

        if (!entityplayermp.capabilities.isCreativeMode)
        {
            entityplayermp.updateHeldItem();
        }

        sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, k);

        if (k == 0)
        {
            throw new CommandException("commands.clear.failure", new Object[] {entityplayermp.getName()});
        }
        else
        {
            if (j == 0)
            {
                sender.addChatMessage(new TextComponentTranslation("commands.clear.testing", new Object[] {entityplayermp.getName(), Integer.valueOf(k)}));
            }
            else
            {
                notifyCommandListener(sender, this, "commands.clear.success", new Object[] {entityplayermp.getName(), Integer.valueOf(k)});
            }
        }
    }
}
 
开发者ID:BlazeAxtrius,项目名称:ExpandedRailsMod,代码行数:57,代码来源:CommandClearInventory.java


注:本文中的net.minecraft.nbt.NBTException.getMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。