java类org.bukkit.inventory.meta.BlockStateMeta的实例源码

SignEditListener.java 文件源码 项目:NyaaUtils 阅读 25 收藏 0 点赞 0 评论 0
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
    Block block = event.getBlock();
    ItemStack item = event.getItemInHand();
    if (block != null && item != null && item.getType().equals(Material.SIGN) &&
            (block.getType().equals(Material.WALL_SIGN) || block.getType().equals(Material.SIGN_POST))) {
        Player player = event.getPlayer();
        if ((player.isOp() && player.getGameMode().equals(GameMode.CREATIVE)) ||
                !item.hasItemMeta() || !(item.getItemMeta() instanceof BlockStateMeta) ||
                !player.hasPermission("nu.se.player")) {
            return;
        }
        SignContent c = SignContent.fromItemStack(item);
        if (!c.getContent().isEmpty()) {
            signContents.put(event.getPlayer().getUniqueId(), c);
        }
    }
}
EquipHandler.java 文件源码 项目:Damocles 阅读 25 收藏 0 点赞 0 评论 0
@EventHandler
public void onBankClick(InventoryClickEvent event){
    Player player = (Player) event.getWhoClicked();
    Account account = new Account(player);
    ca.damocles.accountsystem.Character character = account.getLoadedCharacter();

    if(character == null){
        return;
    }

    if(event.getInventory().getName().equalsIgnoreCase(character.getUsername()+"'s Bank")){
        if(event.getCurrentItem() == null){
            return;
        }
        event.setCancelled(true);

        if(event.getCurrentItem().hasItemMeta()){

            if(event.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GOLD+"Empty Bank")){
                event.setCancelled(true);
                return;
            }

            if(event.getSlot() == 5){
                if(event.getCurrentItem().getItemMeta() instanceof BlockStateMeta){
                    ItemStack item = event.getCurrentItem();
                    event.getWhoClicked().closeInventory();
                    event.getWhoClicked().openInventory(new NBTHandler(item).getBoxInventory());
                }
            }


        }

    }
}
NBTHandler.java 文件源码 项目:Damocles 阅读 24 收藏 0 点赞 0 评论 0
public void setBoxInventory(Inventory inventory){
    if(item.getItemMeta() instanceof BlockStateMeta){
        BlockStateMeta im = (BlockStateMeta)item.getItemMeta();
        if(im.getBlockState() instanceof ShulkerBox){
            ShulkerBox shulker = (ShulkerBox) im.getBlockState();
            shulker.getInventory().setContents(inventory.getContents());
            im.setBlockState(shulker);
            item.setItemMeta(im);
            return;
        }
    }
    return;
}
NBTHandler.java 文件源码 项目:Damocles 阅读 20 收藏 0 点赞 0 评论 0
public Inventory getBoxInventory(){
    Inventory inv = Bukkit.createInventory(null, 27, "Bank");
    if(item.getItemMeta() instanceof BlockStateMeta){
        BlockStateMeta im = (BlockStateMeta)item.getItemMeta();
        if(im.getBlockState() instanceof ShulkerBox){
            ShulkerBox shulker = (ShulkerBox) im.getBlockState();
            inv.setContents(shulker.getInventory().getContents());
            return inv;
        }
    }
    return inv;
}
MarketManager.java 文件源码 项目:HamsterEcoHelper 阅读 23 收藏 0 点赞 0 评论 0
public static boolean containsBook(ItemStack item) {
    if (item.hasItemMeta() && item.getItemMeta() instanceof BlockStateMeta) {
        BlockStateMeta blockStateMeta = (BlockStateMeta) item.getItemMeta();
        if (blockStateMeta.hasBlockState() && blockStateMeta.getBlockState() instanceof InventoryHolder) {
            InventoryHolder inventoryHolder = (InventoryHolder) blockStateMeta.getBlockState();
            for (ItemStack itemStack : inventoryHolder.getInventory().getContents()) {
                if (itemStack != null && itemStack.getType() != Material.AIR &&
                        itemStack.hasItemMeta() && itemStack.getItemMeta() instanceof BookMeta) {
                    return true;
                }
            }
        }
    }
    return false;
}
SignContent.java 文件源码 项目:NyaaUtils 阅读 20 收藏 0 点赞 0 评论 0
public static SignContent fromItemStack(ItemStack item) {
    SignContent content = new SignContent();
    if (item.hasItemMeta() && item.getItemMeta() instanceof BlockStateMeta) {
        BlockStateMeta blockStateMeta = (BlockStateMeta) item.getItemMeta();
        if (blockStateMeta.hasBlockState() && blockStateMeta.getBlockState() instanceof Sign) {
            Sign sign = ((Sign) blockStateMeta.getBlockState());
            for (int i = 0; i < 4; i++) {
                content.setLine(i, sign.getLine(i));
            }
        }
    }
    return content;
}
SignContent.java 文件源码 项目:NyaaUtils 阅读 25 收藏 0 点赞 0 评论 0
public ItemStack toItemStack(ItemStack item) {
    if (item.getItemMeta() instanceof BlockStateMeta) {
        BlockStateMeta blockStateMeta = (BlockStateMeta) item.getItemMeta();
        if (blockStateMeta.getBlockState() instanceof Sign) {
            Sign sign = ((Sign) blockStateMeta.getBlockState());
            for (int i = 0; i < 4; i++) {
                sign.setLine(i, getLine(i));
            }
            blockStateMeta.setBlockState(sign);
        }
        item.setItemMeta(blockStateMeta);
    }
    return item;
}
BannerUtils.java 文件源码 项目:NovaGuilds 阅读 26 收藏 0 点赞 0 评论 0
/**
 * Applies meta to a shield
 *
 * @param itemStack  shield item
 * @param bannerMeta banner meta
 * @return shield item
 */
public static ItemStack applyMeta(ItemStack itemStack, BannerMeta bannerMeta) {
    if(itemStack.getType() != Material.SHIELD && itemStack.getType() != Material.BANNER) {
        throw new IllegalArgumentException("Passed ItemStack is not a shield nor a banner");
    }

    ItemMeta meta = itemStack.getItemMeta();
    BlockStateMeta blockStateMeta = (BlockStateMeta) meta;
    Banner banner = (Banner) blockStateMeta.getBlockState();
    applyMeta(banner, bannerMeta);
    banner.update();
    blockStateMeta.setBlockState(banner);
    itemStack.setItemMeta(blockStateMeta);
    return itemStack;
}
ShulkerData.java 文件源码 项目:TNE-Bukkit 阅读 21 收藏 0 点赞 0 评论 0
@Override
public SerialItemData initialize(ItemStack stack) {
  TNE.debug("ShulkerData.initialize.");
  if(SerialItem.isShulker(stack.getType())) {
    TNE.debug("Passed shulker check");
    ItemMeta meta = stack.getItemMeta();
    if(meta instanceof BlockStateMeta) {
      TNE.debug("Is BlockStateMeta");
      BlockStateMeta state = (BlockStateMeta)meta;
      if(state.getBlockState() instanceof ShulkerBox) {
        TNE.debug("Is ShulkerBox BlockState");
        valid = true;
        ShulkerBox shulker = (ShulkerBox)state.getBlockState();
        Inventory inventory = shulker.getInventory();
        TNE.debug("Initializing shulker box..");
        for(int i = 0; i < inventory.getSize(); i++) {
          if(inventory.getItem(i) == null || inventory.getItem(i).getType().equals(Material.AIR)) {
            if(items.containsKey(i)) {
              items.remove(i);
              TNE.debug("Removing item from slot " + i);
            }
          } else {
            TNE.debug("Adding Item: " + inventory.getItem(i).getType().name());
            TNE.debug("Item Slot: " + i);
            items.put(i, new SerialItem(inventory.getItem(i)));
          }
        }
      }
    }
  }
  return this;
}
ShulkerData.java 文件源码 项目:TNE-Bukkit 阅读 19 收藏 0 点赞 0 评论 0
@Override
public ItemStack build(ItemStack stack) {
  if(valid) {
    BlockStateMeta meta = (BlockStateMeta)stack.getItemMeta();
    ShulkerBox shulkerBox = (ShulkerBox)meta;
    items.forEach((slot, item)->shulkerBox.getInventory().setItem(slot, item.getStack()));
    meta.setBlockState(shulkerBox);
    stack.setItemMeta(meta);

  }
  return stack;
}
Message.java 文件源码 项目:NyaaCore 阅读 40 收藏 0 点赞 0 评论 0
private String getItemJsonStripped(ItemStack item) {
    ItemStack cloned = item.clone();
    if (cloned.hasItemMeta() && cloned.getItemMeta() instanceof BookMeta) {
        return ItemStackUtils.itemToJson(removeBookContent(cloned));
    }
    if (cloned.hasItemMeta() && cloned.getItemMeta() instanceof BlockStateMeta) {
        BlockStateMeta blockStateMeta = (BlockStateMeta) cloned.getItemMeta();
        if (blockStateMeta.hasBlockState() && blockStateMeta.getBlockState() instanceof InventoryHolder) {
            InventoryHolder inventoryHolder = (InventoryHolder) blockStateMeta.getBlockState();
            ArrayList<ItemStack> items = new ArrayList<>();
            for (int i = 0; i < inventoryHolder.getInventory().getSize(); i++) {
                ItemStack itemStack = inventoryHolder.getInventory().getItem(i);
                if (itemStack != null && itemStack.getType() != Material.AIR) {
                    if (items.size() < 5) {
                        if (itemStack.hasItemMeta()) {
                            if (itemStack.getItemMeta().hasLore()) {
                                ItemMeta meta = itemStack.getItemMeta();
                                meta.setLore(new ArrayList<String>());
                                itemStack.setItemMeta(meta);
                            }
                            if (itemStack.getItemMeta() instanceof BookMeta) {
                                itemStack = removeBookContent(itemStack);
                            }
                        }
                        items.add(itemStack);
                    } else {
                        items.add(new ItemStack(Material.STONE));
                    }
                }
            }
            inventoryHolder.getInventory().clear();
            for (int i = 0; i < items.size(); i++) {
                inventoryHolder.getInventory().setItem(i, items.get(i));
            }
            blockStateMeta.setBlockState((BlockState) inventoryHolder);
            cloned.setItemMeta(blockStateMeta);
            return ItemStackUtils.itemToJson(cloned);
        }
    }
    return ItemStackUtils.itemToJson(cloned);
}
Craftbukkit18R3.java 文件源码 项目:factions-top 阅读 22 收藏 0 点赞 0 评论 0
@Override
public EntityType getSpawnerType(ItemStack item) {
    BlockStateMeta bsm = (BlockStateMeta) item.getItemMeta();
    CreatureSpawner bs = (CreatureSpawner) bsm.getBlockState();
    return bs.getSpawnedType();
}
TestItemFactory.java 文件源码 项目:ExilePearl 阅读 22 收藏 0 点赞 0 评论 0
private ItemMeta getItemMetaIntenal(Material material) {
      switch (material) {
      case AIR:
          return null;
      case WRITTEN_BOOK:
      case BOOK_AND_QUILL:
        return mock(BookMeta.class);
      case SKULL_ITEM:
        return mock(SkullMeta.class);
      case LEATHER_HELMET:
      case LEATHER_CHESTPLATE:
      case LEATHER_LEGGINGS:
      case LEATHER_BOOTS:
        return mock(LeatherArmorMeta.class);
      case POTION:
      case SPLASH_POTION:
      case LINGERING_POTION:
      case TIPPED_ARROW:
        return mock(PotionMeta.class);
      case MAP:
        return mock(PotionMeta.class);
      case FIREWORK:
        return mock(PotionMeta.class);
      case FIREWORK_CHARGE:
        return mock(FireworkEffectMeta.class);
      case ENCHANTED_BOOK:
        return mock(EnchantmentStorageMeta.class);
      case BANNER:
        return mock(BannerMeta.class);
      case FURNACE:
      case CHEST:
      case TRAPPED_CHEST:
      case JUKEBOX:
      case DISPENSER:
      case DROPPER:
      case SIGN:
      case MOB_SPAWNER:
      case NOTE_BLOCK:
      case PISTON_BASE:
      case BREWING_STAND_ITEM:
      case ENCHANTMENT_TABLE:
      case COMMAND:
      case COMMAND_REPEATING:
      case COMMAND_CHAIN:
      case BEACON:
      case DAYLIGHT_DETECTOR:
      case DAYLIGHT_DETECTOR_INVERTED:
      case HOPPER:
      case REDSTONE_COMPARATOR:
      case FLOWER_POT_ITEM:
      case SHIELD:
      case STRUCTURE_BLOCK:
return mock(BlockStateMeta.class);
      default:
        return mock(ItemMeta.class);
      }
  }


问题


面经


文章

微信
公众号

扫码关注公众号