类org.bukkit.inventory.DoubleChestInventory源码实例Demo

下面列出了怎么用org.bukkit.inventory.DoubleChestInventory的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: ProjectAres   文件: ViewInventoryMatchModule.java
public void previewInventory(Player viewer, Inventory realInventory) {
    if(viewer == null) { return; }

    if(realInventory instanceof PlayerInventory) {
        previewPlayerInventory(viewer, (PlayerInventory) realInventory);
    }else {
        Inventory fakeInventory;
        if(realInventory instanceof DoubleChestInventory) {
            if(realInventory.hasCustomName()) {
                fakeInventory = Bukkit.createInventory(viewer, realInventory.getSize(), realInventory.getName());
            } else {
                fakeInventory = Bukkit.createInventory(viewer, realInventory.getSize());
            }
        } else {
            if(realInventory.hasCustomName()) {
                fakeInventory = Bukkit.createInventory(viewer, realInventory.getType(), realInventory.getName());
            } else {
                fakeInventory = Bukkit.createInventory(viewer, realInventory.getType());
            }
        }
        fakeInventory.setContents(realInventory.contents());

        this.showInventoryPreview(viewer, realInventory, fakeInventory);
    }
}
 
源代码2 项目: FastAsyncWorldedit   文件: BukkitWorld.java
/**
 * Gets the single block inventory for a potentially double chest.
 * Handles people who have an old version of Bukkit.
 * This should be replaced with {@link org.bukkit.block.Chest#getBlockInventory()}
 * in a few months (now = March 2012) // note from future dev - lol
 *
 * @param chest The chest to get a single block inventory for
 * @return The chest's inventory
 */
private Inventory getBlockInventory(Chest chest) {
    try {
        return chest.getBlockInventory();
    } catch (Throwable t) {
        if (chest.getInventory() instanceof DoubleChestInventory) {
            DoubleChestInventory inven = (DoubleChestInventory) chest.getInventory();
            if (inven.getLeftSide().getHolder().equals(chest)) {
                return inven.getLeftSide();
            } else if (inven.getRightSide().getHolder().equals(chest)) {
                return inven.getRightSide();
            } else {
                return inven;
            }
        } else {
            return chest.getInventory();
        }
    }
}
 
源代码3 项目: civcraft   文件: PlayerListener.java
@EventHandler(priority = EventPriority.HIGHEST)
public void onInventoryOpenEvent(InventoryOpenEvent event) {
	if (event.getInventory() instanceof DoubleChestInventory) {
		DoubleChestInventory doubleInv = (DoubleChestInventory)event.getInventory();
					
		Chest leftChest = (Chest)doubleInv.getHolder().getLeftSide();			
		/*Generate a new player 'switch' event for the left and right chests. */
		PlayerInteractEvent interactLeft = new PlayerInteractEvent((Player)event.getPlayer(), Action.RIGHT_CLICK_BLOCK, null, leftChest.getBlock(), null);
		BlockListener.OnPlayerSwitchEvent(interactLeft);
		
		if (interactLeft.isCancelled()) {
			event.setCancelled(true);
			return;
		}
		
		Chest rightChest = (Chest)doubleInv.getHolder().getRightSide();
		PlayerInteractEvent interactRight = new PlayerInteractEvent((Player)event.getPlayer(), Action.RIGHT_CLICK_BLOCK, null, rightChest.getBlock(), null);
		BlockListener.OnPlayerSwitchEvent(interactRight);
		
		if (interactRight.isCancelled()) {
			event.setCancelled(true);
			return;
		}			
	}
}
 
源代码4 项目: PGM   文件: ViewInventoryMatchModule.java
public void previewInventory(Player viewer, Inventory realInventory) {
  if (viewer == null) {
    return;
  }

  if (realInventory instanceof PlayerInventory) {
    previewPlayerInventory(viewer, (PlayerInventory) realInventory);
  } else {
    Inventory fakeInventory;
    if (realInventory instanceof DoubleChestInventory) {
      if (realInventory.hasCustomName()) {
        fakeInventory =
            Bukkit.createInventory(viewer, realInventory.getSize(), realInventory.getName());
      } else {
        fakeInventory = Bukkit.createInventory(viewer, realInventory.getSize());
      }
    } else {
      if (realInventory.hasCustomName()) {
        fakeInventory =
            Bukkit.createInventory(viewer, realInventory.getType(), realInventory.getName());
      } else {
        fakeInventory = Bukkit.createInventory(viewer, realInventory.getType());
      }
    }
    fakeInventory.setContents(realInventory.getContents());

    this.showInventoryPreview(viewer, realInventory, fakeInventory);
  }
}
 
源代码5 项目: QuickShop-Reremake   文件: Util.java
public static boolean isDoubleChest(@Nullable Block b) {
    if (b == null) {
        return false;
    }
    if (!(b.getState() instanceof Container)) {
        return false;
    }
    final Container container = (Container) b.getState();
    return (container.getInventory() instanceof DoubleChestInventory);
}
 
源代码6 项目: QuickShop-Reremake   文件: BlockListener.java
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlace(BlockPlaceEvent e) {

    final Material type = e.getBlock().getType();
    final Block placingBlock = e.getBlock();
    final Player player = e.getPlayer();

    if (type != Material.CHEST) {
        return;
    }
    Block chest = null;
    //Chest combine mechanic based checking
    if (player.isSneaking()) {
        Block blockAgainst = e.getBlockAgainst();
        if (blockAgainst.getType() == Material.CHEST && placingBlock.getFace(blockAgainst) != BlockFace.UP && placingBlock.getFace(blockAgainst) != BlockFace.DOWN && !(((Chest) blockAgainst.getState()).getInventory() instanceof DoubleChestInventory)) {
            chest = e.getBlockAgainst();
        } else {
            return;
        }
    } else {
        //Get all chest in vertical Location
        BlockFace placingChestFacing = ((Directional) (placingBlock.getState().getBlockData())).getFacing();
        for (BlockFace face : Util.getVerticalFacing()) {
            //just check the right side and left side
            if (face != placingChestFacing && face != placingChestFacing.getOppositeFace()) {
                Block nearByBlock = placingBlock.getRelative(face);
                if (nearByBlock.getType() == Material.CHEST
                        //non double chest
                        && !(((Chest) nearByBlock.getState()).getInventory() instanceof DoubleChestInventory)
                        //same facing
                        && placingChestFacing == ((Directional) nearByBlock.getState().getBlockData()).getFacing()) {
                    if (chest == null) {
                        chest = nearByBlock;
                    } else {
                        //when multiply chests competed, minecraft will always combine with right side
                        if (placingBlock.getFace(nearByBlock) == Util.getRightSide(placingChestFacing)) {
                            chest = nearByBlock;
                        }
                    }
                }
            }
        }
    }
    if (chest == null) {
        return;
    }

    Shop shop = getShopPlayer(chest.getLocation(), false);
    if (shop != null) {
        if (!QuickShop.getPermissionManager().hasPermission(player, "quickshop.create.double")) {
            e.setCancelled(true);
            MsgUtil.sendMessage(player, MsgUtil.getMessage("no-double-chests", player));

        } else if (!shop.getModerator().isModerator(player.getUniqueId())) {
            e.setCancelled(true);
            MsgUtil.sendMessage(player, MsgUtil.getMessage("not-managed-shop", player));
        }
    }
}
 
源代码7 项目: Kettle   文件: DoubleChest.java
public DoubleChest(DoubleChestInventory chest) {
    inventory = chest;
}
 
源代码8 项目: civcraft   文件: MultiInventory.java
public void addInventory (DoubleChestInventory inv) {
	invs.add(inv.getLeftSide());
	invs.add(inv.getRightSide());
}
 
 类所在包
 同包方法