本文整理汇总了Java中com.comphenix.protocol.wrappers.nbt.NbtCompound.containsKey方法的典型用法代码示例。如果您正苦于以下问题:Java NbtCompound.containsKey方法的具体用法?Java NbtCompound.containsKey怎么用?Java NbtCompound.containsKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.comphenix.protocol.wrappers.nbt.NbtCompound
的用法示例。
在下文中一共展示了NbtCompound.containsKey方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadBackpack
import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入方法依赖的package包/类
@Nullable
static Backpack loadBackpack(Path file) throws IOException {
Backpack backpack;
try (DataInputStream dataInput = new DataInputStream(new GZIPInputStream(Files.newInputStream(file)))) {
NbtCompound nbtList = NbtBinarySerializer.DEFAULT.deserializeCompound(dataInput);
BackpackType type = BackpackManager.getBackpackType(nbtList.getString("type"));
if (type == null) {
return null;
}
long lastUse = (nbtList.containsKey("last-use")) ? nbtList.getLong("last-use") : System.currentTimeMillis();
backpack = new Backpack(type, UUID.fromString(FileUtils.stripExtension(file.getFileName().toString())));
backpack.setLastUse(lastUse);
NbtCompound itemList = nbtList.getCompound("contents");
ItemStack[] contents = new ItemStack[type.getSize()];
for (int i = 0; i < type.getSize() && itemList.containsKey(i + ""); i++) {
NbtCompound compound = itemList.getCompound(i + "");
contents[i] = compound == null ? new ItemStack(Material.AIR) : ItemUtils.nbtToItemStack(compound);
}
backpack.setContents(contents);
}
return backpack;
}
示例2: getDeathTime
import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入方法依赖的package包/类
public static long getDeathTime(ItemStack item) {
NbtCompound nbt = NbtFactory.asCompound(NbtFactory.fromItemTag(item.clone()));
if (!nbt.containsKey(DEATH_TIME_TAG)) {
return 0;
}
return nbt.getLong(DEATH_TIME_TAG);
}
示例3: getHealth
import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入方法依赖的package包/类
public static double getHealth(ItemStack item, double maxHealth) {
NbtCompound nbt = NbtFactory.asCompound(NbtFactory.fromItemTag(item.clone()));
if (!nbt.containsKey("pet.health")) {
return maxHealth;
}
return nbt.getDouble("pet.health");
}
示例4: setTag
import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入方法依赖的package包/类
public static ItemStack setTag(ItemStack item, String tag, String value) {
item = toBukkitItemStack(item);
NbtCompound nbt = NbtFactory.asCompound(NbtFactory.fromItemTag(item));
if (!nbt.containsKey(tag)) {
if (UNBREAKABLE_TAG.equals(tag) || HIDE_FLAGS_TAG.equals(tag)) {
nbt.put(tag, Integer.parseInt(value));
} else {
nbt.put(tag, value);
}
}
NbtFactory.setItemTag(item, nbt);
return item;
}
示例5: getTag
import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入方法依赖的package包/类
@SuppressWarnings("WeakerAccess")
public static String getTag(ItemStack item, String tag, @Nullable String defaultValue) {
item = toBukkitItemStack(item);
NbtCompound nbt = NbtFactory.asCompound(NbtFactory.fromItemTag(item));
if (!nbt.containsKey(tag)) {
return defaultValue;
}
return nbt.getString(tag);
}
示例6: hasTag
import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入方法依赖的package包/类
public static boolean hasTag(@Nullable ItemStack originalItem, String tag) {
if (originalItem == null || !originalItem.hasItemMeta()) {
return false;
}
ItemStack item = toBukkitItemStack(originalItem.clone());
NbtCompound nbt = NbtFactory.asCompound(NbtFactory.fromItemTag(item));
return nbt.containsKey(tag);
}
示例7: nbtToItemStack
import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入方法依赖的package包/类
public static ItemStack nbtToItemStack(NbtCompound nbt) {
ItemStack item = new ItemStack(Material.valueOf(nbt.getString("material")));
if (!ItemUtils.isEmpty(item)) {
item.setAmount(nbt.getInteger("amount"));
item.setDurability(nbt.getShort("data"));
if (nbt.containsKey("tag")) {
item = toBukkitItemStack(item);
NbtFactory.setItemTag(item, nbt.getCompound("tag"));
}
}
return item;
}
示例8: loadPlayer
import com.comphenix.protocol.wrappers.nbt.NbtCompound; //导入方法依赖的package包/类
static PlayerWrapper loadPlayer(Player player, Path file) throws IOException {
PlayerWrapper playerWrapper = new PlayerWrapper(player);
Inventory inventory = playerWrapper.getInventory();
try (DataInputStream dataInput = new DataInputStream(new GZIPInputStream(Files.newInputStream(file)))) {
NbtCompound playerNbt = NbtBinarySerializer.DEFAULT.deserializeCompound(dataInput);
// =========== Added in v1.1.8 ============
if (playerNbt.containsKey("free-slots")) {
int savedFreeSlots = playerNbt.getInteger("free-slots");
int freeSlotsFromConfig = Config.getConfig().getInt("slots.free");
playerWrapper.setBuyedSlots(savedFreeSlots - freeSlotsFromConfig);
playerNbt.remove("free-slots");
} else {
playerWrapper.setBuyedSlots(playerNbt.getInteger("buyed-slots"));
playerNbt.remove("buyed-slots");
}
// ========================================
// =========== Added in v1.2.1 ============
NbtCompound itemsNbt = playerNbt.containsKey("slots") ? playerNbt.getCompound("slots") : playerNbt;
// ========================================
for (Slot slot : SlotManager.instance().getSlots()) {
if (itemsNbt.containsKey(slot.getName())) {
NbtCompound slotNbt = itemsNbt.getCompound(slot.getName());
if (slot.getSlotType() != Slot.SlotType.valueOf(slotNbt.getString("type"))) {
continue;
}
if (slotNbt.containsKey("buyed")) {
playerWrapper.setBuyedSlots(slot.getName());
}
NbtCompound itemListNbt = slotNbt.getCompound("items");
List<ItemStack> itemList = new ArrayList<>();
for (String key : itemListNbt.getKeys()) {
itemList.add(ItemUtils.nbtToItemStack(itemListNbt.getCompound(key)));
}
List<Integer> slotIds = slot.getSlotIds();
for (int i = 0; i < slotIds.size(); i++) {
if (itemList.size() > i) {
inventory.setItem(slotIds.get(i), itemList.get(i));
}
}
}
}
}
return playerWrapper;
}