當前位置: 首頁>>代碼示例>>Java>>正文


Java IntNode類代碼示例

本文整理匯總了Java中org.cubeengine.converter.node.IntNode的典型用法代碼示例。如果您正苦於以下問題:Java IntNode類的具體用法?Java IntNode怎麽用?Java IntNode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


IntNode類屬於org.cubeengine.converter.node包,在下文中一共展示了IntNode類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toNode

import org.cubeengine.converter.node.IntNode; //導入依賴的package包/類
@Override
public Node toNode(ItemStack itemStack) throws ConversionException
{
    if (itemStack == null || itemStack.getItem() == Material.AIR)
    {
        return NullNode.emptyNode();
    }

    MapNode item = MapNode.emptyMap();
    item.set("Count", new IntNode(itemStack.getAmount()));
    item.set("Damage", new IntNode(itemStack.getDurability()));
    item.set("Item", StringNode.of(itemStack.getType().name()));
    net.minecraft.server.v1_8_R2.ItemStack nmsCopy = CraftItemStack.asNMSCopy(itemStack);
    if (nmsCopy == null)
    {
        CubeEngine.getLog().error("NMSCopy is unexpectedly null! " + itemStack);
        return null;
    }
    NBTTagCompound tag = nmsCopy.getTag();
    item.set("tag", tag == null ? MapNode.emptyMap() : NBTUtils.convertNBTToNode(tag));
    return item;
}
 
開發者ID:CubeEngine,項目名稱:modules-extra,代碼行數:23,代碼來源:ItemStackConverter.java

示例2: fromNode

import org.cubeengine.converter.node.IntNode; //導入依賴的package包/類
@Override
public Integer fromNode(Node node) throws ConversionException
{
    if (node instanceof IntNode)
    {
        return ((IntNode)node).getValue();
    }
    String s = node.asText();
    try
    {
        return Integer.parseInt(s);
    }
    catch (NumberFormatException e)
    {
        throw ConversionException.of(this, node, "Node incompatible with Integer!", e);
    }
}
 
開發者ID:CubeEngine,項目名稱:ReflecT,代碼行數:18,代碼來源:IntegerConverter.java

示例3: fromNode

import org.cubeengine.converter.node.IntNode; //導入依賴的package包/類
@Override
public ItemStack fromNode(Node node) throws ConversionException
{
    if (node instanceof MapNode)
    {
        Node count = ((MapNode)node).get("Count");
        Node damage = ((MapNode)node).get("Damage");
        Node item = ((MapNode)node).get("Item");
        Node tag = ((MapNode)node).get("tag");
        if (count instanceof IntNode && damage instanceof IntNode &&
            item instanceof StringNode && (tag instanceof MapNode))
        {
            try
            {
                ItemStack itemStack = new ItemStack(Material.valueOf(item.asText()));
                itemStack.setDurability(((IntNode)damage).getValue().shortValue());
                itemStack.setAmount(((IntNode)count).getValue());
                net.minecraft.server.v1_8_R2.ItemStack nms = CraftItemStack.asNMSCopy(itemStack);
                nms.setTag(((MapNode)tag).isEmpty() ? null : (NBTTagCompound)NBTUtils.convertNodeToNBT(tag));
                return CraftItemStack.asBukkitCopy(nms);
            }
            catch (IllegalArgumentException e)
            {
                throw ConversionException.of(this, item, "Unknown Material!");
            }
        }
        else
        {
            throw ConversionException.of(this, node, "Invalid SubNodes!");
        }
    }
    else if (node instanceof NullNode)
    {
        return null;
    }
    else
    {
        throw ConversionException.of(this, node, "Node is not a MapNode!");
    }
}
 
開發者ID:CubeEngine,項目名稱:modules-extra,代碼行數:41,代碼來源:ItemStackConverter.java

示例4: toNode

import org.cubeengine.converter.node.IntNode; //導入依賴的package包/類
@Override
public Node toNode(Integer object) throws ConversionException
{
    return new IntNode(object);
}
 
開發者ID:CubeEngine,項目名稱:ReflecT,代碼行數:6,代碼來源:IntegerConverter.java

示例5: convertValue

import org.cubeengine.converter.node.IntNode; //導入依賴的package包/類
private Tag<?> convertValue(String name, Node value)
{
    if (value instanceof MapNode)
    {
        CompoundMap map = new CompoundMap();
        this.convertMap(map, ((MapNode)value).getValue(), (MapNode)value);
        return new CompoundTag(name, map);
    }
    else if (value instanceof ListNode)
    {
        List<Tag> tagList = new ArrayList<Tag>();
        java.lang.Integer i = 0;
        for (Node node : ((ListNode)value).getValue())
        {
            i++;
            tagList.add(this.convertValue(i.toString(), node));
        }
        if (tagList.size() == 0)
        {
            return new ListTag(name, CompoundTag.class, tagList);
        }
        return new ListTag(name, tagList.get(0).getClass(), tagList);
    }
    else if (value instanceof BooleanNode)
    {
        return new ByteTag(name, (Boolean)value.getValue());
    }
    else if (value instanceof ByteNode)
    {
        return new ByteTag(name, (Byte)value.getValue());
    }
    else if (value instanceof CharNode)
    {
        return new StringTag(name, value.getValue().toString());
    }
    else if (value instanceof DoubleNode)
    {
        return new DoubleTag(name, (Double)value.getValue());
    }
    else if (value instanceof FloatNode)
    {
        return new FloatTag(name, (Float)value.getValue());
    }
    else if (value instanceof IntNode)
    {
        return new IntTag(name, (Integer)value.getValue());
    }
    else if (value instanceof LongNode)
    {
        return new LongTag(name, (Long)value.getValue());
    }
    else if (value instanceof ShortNode)
    {
        return new ShortTag(name, (Short)value.getValue());
    }
    else if (value instanceof StringNode)
    {
        return new StringTag(name, (String)value.getValue());
    }
    else if (value instanceof NullNode)
    {
        return new EndTag();
    }
    throw new IllegalStateException("Unknown Node! " + value.getClass().getName());
}
 
開發者ID:CubeEngine,項目名稱:ReflecT,代碼行數:66,代碼來源:NBTCodec.java


注:本文中的org.cubeengine.converter.node.IntNode類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。