本文整理汇总了Java中org.bukkit.inventory.InventoryHolder.getInventory方法的典型用法代码示例。如果您正苦于以下问题:Java InventoryHolder.getInventory方法的具体用法?Java InventoryHolder.getInventory怎么用?Java InventoryHolder.getInventory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.inventory.InventoryHolder
的用法示例。
在下文中一共展示了InventoryHolder.getInventory方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addItems
import org.bukkit.inventory.InventoryHolder; //导入方法依赖的package包/类
@Override
public boolean addItems(String worldname, PlotItem items) {
World world = getWorld(worldname);
Block block = world.getBlockAt(items.x, items.y, items.z);
if (block == null) {
return false;
}
BlockState state = block.getState();
if (state != null && state instanceof InventoryHolder) {
InventoryHolder holder = ((InventoryHolder) state);
Inventory inv = holder.getInventory();
for (int i = 0; i < items.id.length; i++) {
ItemStack item = new ItemStack(items.id[i], items.amount[i], items.data[i]);
inv.addItem(item);
}
state.update(true);
return true;
}
return false;
}
示例2: onPlayerInteractContainer
import org.bukkit.inventory.InventoryHolder; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
void onPlayerInteractContainer(PlayerInteractEvent event)
{
Action action = event.getAction();
if(action != Action.RIGHT_CLICK_BLOCK) return;
Player player = event.getPlayer();
if(player.isSneaking()) return;
if(!PhantomAdmin.instance.isInvisible(player)) return;
Block clickedBlock = event.getClickedBlock();
BlockState state = clickedBlock.getState();
if(!(state instanceof InventoryHolder)) return;
String phantomIdentifier = this.getPhantomIdentifier(((InventoryHolder)state).getInventory().getHolder());
if(phantomIdentifier != null)
{
event.setCancelled(true);
InventoryHolder holder = (InventoryHolder)state;
Inventory inventory = holder.getInventory();
Inventory phantomInventory = PhantomAdmin.instance.getServer().createInventory(inventory.getHolder(), inventory.getSize());
phantomInventory.setContents(inventory.getContents());
player.openInventory(phantomInventory);
HashSet<Inventory> allInventories = this.inventorySyncMap.get(inventory);
if(allInventories == null)
{
allInventories = new HashSet<Inventory>();
}
allInventories.add(inventory);
allInventories.add(phantomInventory);
this.inventorySyncMap.put(phantomIdentifier, allInventories);
this.phantomInventories.add(phantomInventory);
}
}
示例3: registerWoolChest
import org.bukkit.inventory.InventoryHolder; //导入方法依赖的package包/类
private void registerWoolChest(InventoryHolder inventoryHolder) {
if (inventoryHolder instanceof DoubleChest) {
DoubleChest doubleChest = (DoubleChest) inventoryHolder;
// register both blocks
this.registerWoolChest(doubleChest.getLeftSide());
this.registerWoolChest(doubleChest.getRightSide());
return;
} else if (!(inventoryHolder instanceof BlockState)) {
return;
}
Inventory inventory = inventoryHolder.getInventory();
Block block = ((BlockState) inventoryHolder).getBlock();
ChestImage image = this.getChestImage(block);
if (image != null) {
// We have already seen this chest, don't register it.
return;
}
this.chestImages.put(block, image = new ChestImage(WoolUtils.containsAny(inventory)));
if (image.woolChest) {
WoolChestRegisterEvent event = new WoolChestRegisterEvent(this.game.getPlugin(), block, inventory);
this.game.getPlugin().getEventBus().publish(event);
if (!event.isCanceled()) {
for (int slot = 0; slot < inventory.getSize(); slot++) {
ItemStack item = inventory.getItem(slot);
if (item != null && WoolUtils.isWool(item)) {
image.snapshot.put(slot, item.clone());
}
}
}
}
}
示例4: onPlayerInteract
import org.bukkit.inventory.InventoryHolder; //导入方法依赖的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.");
}
}
示例5: convert
import org.bukkit.inventory.InventoryHolder; //导入方法依赖的package包/类
@Override
@Nullable
public Inventory convert(final InventoryHolder h) {
return h.getInventory();
}
示例6: onBlockDamage
import org.bukkit.inventory.InventoryHolder; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onBlockDamage(BlockDamageEvent event)
{
Player player = event.getPlayer();
if(!player.isSneaking()) return;
if(!featureEnabled(Features.QuickDeposit, player)) return;
Block clickedBlock = event.getBlock();
if(clickedBlock == null) return;
Material clickedMaterial = clickedBlock.getType();
if(clickedMaterial != Material.CHEST && clickedMaterial != Material.TRAPPED_CHEST) return;
@SuppressWarnings("deprecation")
PlayerInteractEvent fakeEvent = AutomaticInventory.instance.new FakePlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, player.getItemInHand(), clickedBlock, BlockFace.EAST);
Bukkit.getServer().getPluginManager().callEvent(fakeEvent);
if(fakeEvent.isCancelled()) return;
InventoryHolder chest = (InventoryHolder)clickedBlock.getState();
Inventory chestInventory = chest.getInventory();
PlayerInventory playerInventory = player.getInventory();
event.setCancelled(true);
@SuppressWarnings("deprecation")
int aboveBlockID = clickedBlock.getRelative(BlockFace.UP).getTypeId();
if(AutomaticInventory.preventsChestOpen(aboveBlockID))
{
AutomaticInventory.sendMessage(player, TextMode.Err, Messages.ChestLidBlocked);
return;
}
DepositRecord deposits = AutomaticInventory.depositMatching(playerInventory, chestInventory, true);
//send confirmation message to player with counts deposited. if none deposited, give instructions on how to set up the chest.
if(deposits.destinationFull && deposits.totalItems == 0)
{
AutomaticInventory.sendMessage(player, TextMode.Err, Messages.FailedDepositChestFull2);
}
else if(deposits.totalItems == 0)
{
AutomaticInventory.sendMessage(player, TextMode.Info, Messages.FailedDepositNoMatch);
}
else
{
AutomaticInventory.sendMessage(player, TextMode.Success, Messages.SuccessfulDeposit2, String.valueOf(deposits.totalItems));
//make a note that quick deposit was used so that player will not be bothered with advertisement messages again.
PlayerData playerData = PlayerData.FromPlayer(player);
if(!playerData.isUsedQuickDeposit())
{
playerData.setUsedQuickDeposit(true);
}
}
}
示例7: run
import org.bukkit.inventory.InventoryHolder; //导入方法依赖的package包/类
@Override
public void run()
{
Location chestLocation = this.remainingChestLocations.poll();
if(chestLocation == null)
{
AutomaticInventory.sendMessage(this.player, TextMode.Success, Messages.SuccessfulDepositAll2, String.valueOf(this.runningDepositRecord.totalItems));
PlayerData playerData = PlayerData.FromPlayer(player);
if(Math.random() < .1 && !playerData.isGotQuickDepositInfo() && AIEventHandler.featureEnabled(Features.QuickDeposit, player))
{
AutomaticInventory.sendMessage(player, TextMode.Instr, Messages.QuickDepositAdvertisement3);
playerData.setGotQuickDepositInfo(true);
}
}
else
{
Block block = chestLocation.getBlock();
PlayerInteractEvent fakeEvent = AutomaticInventory.instance.new FakePlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, player.getInventory().getItemInMainHand(), block, BlockFace.UP);
Bukkit.getServer().getPluginManager().callEvent(fakeEvent);
if(!fakeEvent.isCancelled())
{
BlockState state = block.getState();
if(state instanceof InventoryHolder)
{
InventoryHolder chest = (InventoryHolder)state;
Inventory chestInventory = chest.getInventory();
if(!this.respectExclusions || AIEventHandler.isSortableChestInventory(chestInventory))
{
PlayerInventory playerInventory = player.getInventory();
DepositRecord deposits = AutomaticInventory.depositMatching(playerInventory, chestInventory, false);
this.runningDepositRecord.totalItems += deposits.totalItems;
}
}
}
QuickDepositChain chain = new QuickDepositChain(this.remainingChestLocations, this.runningDepositRecord, this.player, this.respectExclusions);
Bukkit.getScheduler().runTaskLater(AutomaticInventory.instance, chain, 1L);
}
}
示例8: restoreWoolChest
import org.bukkit.inventory.InventoryHolder; //导入方法依赖的package包/类
private void restoreWoolChest(InventoryHolder inventoryHolder, GamePlayer player, List<GamePlayer> viewers) {
if (inventoryHolder == null) {
return;
}
Inventory inventory = inventoryHolder.getInventory();
if (!player.isParticipating()) {
return;
} else if (inventoryHolder instanceof DoubleChest) {
DoubleChest doubleChest = (DoubleChest) inventoryHolder;
// restore both blocks
this.restoreWoolChest(doubleChest.getLeftSide(), player, viewers);
this.restoreWoolChest(doubleChest.getRightSide(), player, viewers);
return;
} else if (!(inventoryHolder instanceof BlockState)) {
return;
}
Block block = ((BlockState) inventoryHolder).getBlock();
ChestImage image = this.getChestImage(block);
if (image == null || !image.woolChest || image.snapshot.isEmpty()) {
return;
}
boolean restoreWools = true;
// Don't retrace wools if there are players viewing this chest.
for (GamePlayer viewer : viewers) {
if (viewer.isParticipating() && !viewer.equals(player)) {
restoreWools = false;
}
}
if (restoreWools) {
WoolChestRestoreEvent event = new WoolChestRestoreEvent(this.game.getPlugin(), block, inventory, player, viewers);
this.game.getPlugin().getEventBus().publish(event);
if (!event.isCanceled()) {
for (int i = 0; i < inventory.getSize(); i++) {
ItemStack snapshotItem = image.snapshot.get(i);
if (snapshotItem == null) {
continue;
}
// Copy the item to not edit the snapshot!
inventory.setItem(i, snapshotItem.clone());
}
for (Map.Entry<Integer, ItemStack> entry : image.snapshot.entrySet()) {
inventory.setItem(entry.getKey(), entry.getValue().clone());
}
}
}
}
示例9: inventory
import org.bukkit.inventory.InventoryHolder; //导入方法依赖的package包/类
/**
* Get inventory of this account chest.
* @return inventory of this AccountChest, if any. otherwise null.
*/
private Inventory inventory() {
InventoryHolder chest = chest();
return (chest != null)? chest.getInventory() : null;
}