Java 类org.bukkit.block.ShulkerBox 实例源码

项目:Damocles    文件:EquipHandler.java   
@EventHandler
public void onPlace(BlockPlaceEvent event){
    BlockState state = event.getBlockPlaced().getState();
    if(state instanceof ShulkerBox){
        event.setCancelled(true);
    }

}
项目:Damocles    文件:NBTHandler.java   
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;
}
项目:Damocles    文件:NBTHandler.java   
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;
}
项目:TNE-Bukkit    文件:ShulkerData.java   
@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;
}
项目:TNE-Bukkit    文件:ShulkerData.java   
@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;
}