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


Java Attributes类代码示例

本文整理汇总了Java中com.comphenix.attribute.Attributes的典型用法代码示例。如果您正苦于以下问题:Java Attributes类的具体用法?Java Attributes怎么用?Java Attributes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: checkItem

import com.comphenix.attribute.Attributes; //导入依赖的package包/类
@Override
public void checkItem(final ItemStack itemStack, final Inventory playerInventory, final Location playerLocation, final String playerName) {
    Attributes attributes = new Attributes(itemStack);
    for (Attributes.Attribute attribute : attributes.values()) {
        if (attribute.getAmount() > 10) {
            if (plugin.isRemove()) {
                SkyLog.log(LogKey.REMOVE_ATTRIBUTE, itemStack.getType(), attribute.getAttributeType(), attribute.getAmount(), playerName);
                itemStack.setType(Material.AIR);
                return;
            } else {
                SkyLog.log(LogKey.FIX_ATTRIBUTE, attribute.getAttributeType(), attribute.getAmount(), itemStack.getType(), playerName);
                attributes.remove(attribute);
            }
        }
    }
}
 
开发者ID:daboross,项目名称:RemoveGodItems,代码行数:17,代码来源:AttributesCheck.java

示例2: writeVanillaAttributes

import com.comphenix.attribute.Attributes; //导入依赖的package包/类
/**
 * Internal utility method for storing module data - do not use
 * @param values
 * @param item
 */
public static void writeVanillaAttributes(Collection<AttributeInfo> values, ItemStack item) {
    if (item.getType().equals(Material.AIR)) {
        throw new IllegalArgumentException("Cannot write nbt values to AIR");
    }
    Attributes a = new Attributes(item);
    for (AttributeInfo info : values) {
        a.add(info.toAttribute());
    }
    if (a.getStack() != item) {
        throw new IllegalArgumentException("Item target changed during NBT Write - Are you sure you wrote to a Crafty Item?");
    }
}
 
开发者ID:Kingdoms-of-Arden-Development,项目名称:Crafty,代码行数:18,代码来源:NBTUtil.java

示例3: dumpItemStack

import com.comphenix.attribute.Attributes; //导入依赖的package包/类
public static List<String> dumpItemStack(ItemStack stack) {
    if (stack == null) {
        return Collections.emptyList();
    }
    List<String> l = Lists.newArrayList();
    l.add("Quantity: " + stack.getAmount());
    l.add("Material/Data: " + stack.getType() + ":" + stack.getDurability());
    if (stack.hasItemMeta()) {
        ItemMeta meta = stack.getItemMeta();
        l.add("Display name: " + meta.getDisplayName());
        if (meta.hasLore()) {
            l.add("Lore: [" + Joiner.on(",").join(meta.getLore()) + "]");
        }
        if (meta.hasEnchants()) {
            for (Map.Entry<Enchantment, Integer> e : meta.getEnchants().entrySet()) {
                l.add("Enchant " + e.getKey() + " = " + e.getValue());
            }
        }
    } else {
        l.add("No metadata");
    }
    if (stack.getType() != Material.AIR) {
        Attributes a = new Attributes(stack);
        l.add("Attribute count: " + a.size());
        for (Attributes.Attribute attr : a.values()) {
            l.add(String.format("* ID=%s name=[%s] amount=%f type=%s op=%s",
                    attr.getUUID().toString(), attr.getName(), attr.getAmount(),
                    attr.getAttributeType().toString(), attr.getOperation().toString()));
        }
    }
    return l;
}
 
开发者ID:desht,项目名称:sensibletoolbox,代码行数:33,代码来源:STBUtil.java

示例4: toBase64

import com.comphenix.attribute.Attributes; //导入依赖的package包/类
public static String toBase64(Inventory inventory, int maxItems) {
    if (maxItems <= 0) maxItems = inventory.getSize();
    else if (maxItems > inventory.getSize())
        maxItems = inventory.getSize();

    try {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);

        // Write the size of the inventory
        dataOutput.writeInt(maxItems);

        // Save every element in the list
        for (int i = 0; i < maxItems; i++) {
            ItemStack stack = inventory.getItem(i);
            Attributes attributes = stack == null ? null : new Attributes(stack);
            dataOutput.writeObject(stack);
            if (attributes != null) {
                dataOutput.writeInt(attributes.size());
                for (Attributes.Attribute a : attributes.values()) {
                    String s = Joiner.on(";;").join(
                            a.getUUID().toString(), a.getOperation(), a.getName(),
                            a.getAmount(), a.getAttributeType().getMinecraftId()
                    );
                    dataOutput.writeObject(s);
                }
            } else {
                dataOutput.writeInt(0);
            }
        }

        // Serialize that array
        dataOutput.close();
        return Base64Coder.encodeLines(outputStream.toByteArray());
    } catch (IOException e) {
        throw new IllegalStateException("Unable to save item stacks.", e);
    }
}
 
开发者ID:desht,项目名称:sensibletoolbox,代码行数:39,代码来源:BukkitSerialization.java

示例5: fromBase64

import com.comphenix.attribute.Attributes; //导入依赖的package包/类
public static Inventory fromBase64(String data) throws IOException {
    try {
        ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
        BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
        int maxItems = dataInput.readInt();
        int invSize = STBUtil.roundUp(maxItems, 9);  // Bukkit inventory size must be multiple of 9
        Inventory inventory = Bukkit.getServer().createInventory(null, invSize);

        // Read the serialized inventory
        for (int i = 0; i < maxItems; i++) {
            ItemStack stack = (ItemStack) dataInput.readObject();
            int nAttrs = dataInput.readInt();
            if (nAttrs > 0) {
                Attributes attributes = new Attributes(stack);
                for (int n = 0; n < nAttrs; n++) {
                    String s = (String) dataInput.readObject();
                    String[] fields = s.split(";;");
                    attributes.add(Attributes.Attribute.newBuilder().
                            name(fields[2]).
                            amount(Double.parseDouble(fields[3])).
                            uuid(UUID.fromString(fields[0])).
                            operation(Attributes.Operation.valueOf(fields[1])).
                            type(Attributes.AttributeType.fromId(fields[4])).
                            build()
                    );
                }
                stack = attributes.getStack();
            }
            if (stack != null) {
                inventory.setItem(i, stack);
            }
        }
        dataInput.close();
        return inventory;
    } catch (ClassNotFoundException e) {
        throw new IOException("Unable to decode class type.", e);
    }
}
 
开发者ID:desht,项目名称:sensibletoolbox,代码行数:39,代码来源:BukkitSerialization.java


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