本文整理汇总了Java中org.bukkit.inventory.DoubleChestInventory类的典型用法代码示例。如果您正苦于以下问题:Java DoubleChestInventory类的具体用法?Java DoubleChestInventory怎么用?Java DoubleChestInventory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DoubleChestInventory类属于org.bukkit.inventory包,在下文中一共展示了DoubleChestInventory类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBlockInventory
import org.bukkit.inventory.DoubleChestInventory; //导入依赖的package包/类
/**
* 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();
}
}
}
示例2: previewInventory
import org.bukkit.inventory.DoubleChestInventory; //导入依赖的package包/类
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);
}
}
示例3: getAttachedSigns
import org.bukkit.inventory.DoubleChestInventory; //导入依赖的package包/类
/**
* Gets the attached {@link Sign}s on a {@link Block}.
*
* @param block
* the {@link Block} to get for
* @return collection of attached {@link Sign}s
*/
public Collection<Sign> getAttachedSigns(Block block) {
Set<Sign> results = new HashSet<>();
getSignsAround(block, results);
BlockState state = block.getState();
if (state instanceof Chest) {
Inventory chestInventory = ((Chest) state).getInventory();
if (chestInventory instanceof DoubleChestInventory) {
DoubleChest doubleChest = ((DoubleChestInventory) chestInventory).getHolder();
Block left = ((Chest) doubleChest.getLeftSide()).getBlock();
Block right = ((Chest) doubleChest.getRightSide()).getBlock();
getSignsAround(left.equals(block) ? right : left, results);
}
}
return results;
}
示例4: connectedChests
import org.bukkit.inventory.DoubleChestInventory; //导入依赖的package包/类
/**
* Connected chests that comprise the inventory of this account chest.
* @return chest blocks connected to this chest, if any
*/
private Chest[] connectedChests() {
Inventory inv = inventory();
if (inv == null)
return new Chest[0];
if (inv instanceof DoubleChestInventory) {
DoubleChestInventory dinv = (DoubleChestInventory)inv;
Chest left = (Chest)(dinv.getLeftSide().getHolder());
Chest right = (Chest)(dinv.getRightSide().getHolder());
return new Chest[] {left, right};
} else {
InventoryHolder invHolder = inv.getHolder();
if (invHolder instanceof Chest)
return new Chest[] {(Chest)(inv.getHolder())};
}
return new Chest[0];
}
示例5: connected
import org.bukkit.inventory.DoubleChestInventory; //导入依赖的package包/类
/**
* Determine whether the chest of another AccountChest would be connected to this chest.
* @param chest another AccountChest
* @return whether the chest of another AccountChest would be connected to this chest
*/
public boolean connected(AccountChest chest) {
// no valid account chest anymore -> no connection
if (! updateValid())
return false;
if (chestLocation().equals(chest.chestLocation()))
return true;
// no double chest -> no further connection possible
if (! (inventory() instanceof DoubleChestInventory))
return false;
Location myLoc = chestLocation();
for (Chest c : chest.connectedChests())
if (c.getLocation().equals(myLoc))
return true;
return false;
}
示例6: onInventoryOpenEvent
import org.bukkit.inventory.DoubleChestInventory; //导入依赖的package包/类
@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;
}
}
}
示例7: updateOtherDoubleChestBlocks
import org.bukkit.inventory.DoubleChestInventory; //导入依赖的package包/类
private void updateOtherDoubleChestBlocks() {
if (cachedInv.getHolder() instanceof DoubleChest) {
Material chestMaterial = block.getType();
Location otherChestLoc = null;
for (WrappedDirection pd : WrappedDirection.values()) {
if (pd.isSide()) {
if (block.getRelative(pd.getX(), pd.getY(), pd.getZ()).getType() == chestMaterial) {
otherChestLoc = block.getRelative(pd.getX(), pd.getY(), pd.getZ()).getLocation();
}
}
}
Map<BlockLoc, TransportPipesContainer> containerMap = TransportPipes.instance
.getContainerMap(block.getWorld());
if (containerMap != null) {
BlockLoc bl = BlockLoc.convertBlockLoc(otherChestLoc);
if (containerMap.containsKey(bl)) {
TransportPipesContainer tpc = containerMap.get(bl);
if (tpc instanceof SimpleInventoryContainer) {
SimpleInventoryContainer sic = (SimpleInventoryContainer) tpc;
if (!(sic.cachedInv instanceof DoubleChestInventory)) {
sic.updateBlock();
}
}
}
}
}
}
示例8: getSafeInventory
import org.bukkit.inventory.DoubleChestInventory; //导入依赖的package包/类
/**
* Returns the inventory belonging only to the given block, filtering out
* double inventories. Does not check whether the given block has an
* inventory.
*
* @return The inventory for the given block.
*/
public static Inventory getSafeInventory(Block block) {
Inventory inventory = ((InventoryHolder) block.getState()).getInventory();
if (inventory instanceof DoubleChestInventory) {
DoubleChestInventory doubleChest = (DoubleChestInventory) inventory;
Inventory left = doubleChest.getLeftSide();
if (((BlockState) doubleChest.getLeftSide().getHolder()).getBlock().equals(block)) {
return left;
} else {
return doubleChest.getRightSide();
}
} else {
return inventory;
}
}
示例9: onPlayerInteract
import org.bukkit.inventory.DoubleChestInventory; //导入依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
Action action = event.getAction();
ItemStack stack = event.getItem();
// Keys can only be used by right clicking blocks.
if (action != Action.RIGHT_CLICK_BLOCK)
return;
Key key = plugin.getKeyManager().getKey(stack);
// No keys were used in the making of this video.
if (key == null)
return;
Block block = event.getClickedBlock();
BlockState state = block.getState();
if (key instanceof EventKey && state instanceof Chest) {
EventKey eventKey = (EventKey) key;
EventKey.EventKeyData eventKeyData = eventKey.getData(stack.getItemMeta().getLore());
EventType eventType = eventKeyData.getEventType();
List<Inventory> inventories = eventKey.getInventories(eventType);
int inventoryNumber = eventKeyData.getInventoryNumber();
if (inventories.size() < inventoryNumber) {
player.sendMessage(ChatColor.RED + "This key is for " + eventType.getDisplayName() + ChatColor.RED + " loottable " + inventoryNumber + ", whilst there are only " + inventories.size()
+ " possible. Please inform an admin.");
return;
}
Inventory inventory = inventories.get(inventoryNumber - 1);
ItemStack[] contents = inventory.getContents();
Chest chest = (Chest) state;
InventoryHolder inventoryHolder = chest.getInventory().getHolder();
if (inventoryHolder instanceof DoubleChestInventory) {
inventoryHolder = ((DoubleChestInventory) inventoryHolder).getHolder();
}
if (contents.length > chest.getInventory().getSize()) {
player.sendMessage(ChatColor.RED + "This single chest is too small to fit the contents of this key.");
return;
}
Inventory chestInventory = inventoryHolder.getInventory();
if (!InventoryUtils.isEmpty(chestInventory)) {
player.sendMessage(ChatColor.RED + "This chest is not empty.");
return;
}
chestInventory.setContents(inventory.getContents());
decrementHand(player);
event.setCancelled(true);
player.openInventory(chestInventory);
player.sendMessage(ChatColor.YELLOW + "Your " + ChatColor.AQUA + eventType.getDisplayName() + ' ' + eventKey.getDisplayName() + ChatColor.YELLOW + " key has transferred loot "
+ inventoryNumber + ChatColor.YELLOW + " to the chest.");
}
}
示例10: DoubleChest
import org.bukkit.inventory.DoubleChestInventory; //导入依赖的package包/类
public DoubleChest(DoubleChestInventory chest) {
inventory = chest;
}
示例11: addInventory
import org.bukkit.inventory.DoubleChestInventory; //导入依赖的package包/类
public void addInventory (DoubleChestInventory inv) {
invs.add(inv.getLeftSide());
invs.add(inv.getRightSide());
}
示例12: DoubleChest
import org.bukkit.inventory.DoubleChestInventory; //导入依赖的package包/类
public DoubleChest(DoubleChestInventory chest) {
}