本文整理汇总了Java中org.bukkit.block.Chest类的典型用法代码示例。如果您正苦于以下问题:Java Chest类的具体用法?Java Chest怎么用?Java Chest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Chest类属于org.bukkit.block包,在下文中一共展示了Chest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBlockInventory
import org.bukkit.block.Chest; //导入依赖的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: passesFilter
import org.bukkit.block.Chest; //导入依赖的package包/类
/**
* Return a predicate that applies a Filter to the given InventoryHolder,
* or null if the InventoryHolder is not something that we should be filling.
*/
private static @Nullable Predicate<Filter> passesFilter(InventoryHolder holder) {
if(holder instanceof DoubleChest) {
final DoubleChest doubleChest = (DoubleChest) holder;
return filter -> !filter.denies((Chest) doubleChest.getLeftSide()) ||
!filter.denies((Chest) doubleChest.getRightSide());
} else if(holder instanceof BlockState) {
return filter -> !filter.denies((BlockState) holder);
} else if(holder instanceof Player) {
// This happens with crafting inventories, and possibly other transient inventory types
// Pretty sure we never want to fill an inventory held by the player
return null;
} else if(holder instanceof Entity) {
return filter -> !filter.denies(new EntityQuery((Entity) holder));
} else {
// If we're not sure what it is, don't fill it
return null;
}
}
示例3: deliverSupplyDrop
import org.bukkit.block.Chest; //导入依赖的package包/类
public void deliverSupplyDrop(World world) {
Random r = new Random();
// Supply drops between -500, + 500
double x = r.nextInt(1000) - 500;
double y = 0.0D;
double z = r.nextInt(1000) - 500;
Location dropLocation = new Location(world, x, y, z);
// Get the highest block at that location.
dropLocation.setY(world.getHighestBlockYAt(dropLocation));
dropLocation.getBlock().setType(Material.CHEST);
Chest dropChest = (Chest) dropLocation.getBlock().getState();
SupplyDropObject supplyDrop = new SupplyDropObject(dropLocation, dropChest, dropChest.getInventory());
addSupplyDrop(supplyDrop);
for (Player p : world.getPlayers()) {
p.sendMessage(MortuusTerraCore.ALERT_PREFIX + StringUtilities
.color("&eSupply Drop spotted at: &6" + x + ", " + dropLocation.getY() + ", " + z + "&e!"));
}
}
示例4: onInventoryMoveItem
import org.bukkit.block.Chest; //导入依赖的package包/类
@EventHandler
public void onInventoryMoveItem(InventoryInteractEvent event) {
//System.out.println("E");
if (openchests.containsKey(event.getInventory())) {
System.out.println("move");
openchests.get(event.getInventory()).getInventory().setContents(event.getInventory().getContents());
openchests.remove(event.getInventory());
} else {
for (int i = 0; i < openchests.size(); i++) {
Chest c = ((List<Chest>) openchests.values()).get(i);
if (c.getInventory().equals(event.getInventory())) {
((List<Inventory>) openchests.keySet()).get(i).setContents(event.getInventory().getContents());
}
}
}
}
示例5: event
import org.bukkit.block.Chest; //导入依赖的package包/类
@EventHandler
public void event(BlockBreakEvent e) {
new OMGBreakEvent(e, get(e.getPlayer()), e.getBlock());
if (Area.registeredAreas.values().stream().anyMatch(a -> a.isInside(e.getBlock().getLocation())) && Area.registeredAreas.values().stream().noneMatch(a -> a.isInside(e.getBlock().getLocation()) && a.isBreakAllowed(get(e.getPlayer()).team, e.getBlock().getType()))) {
e.setCancelled(true);
return;
}
if (g.settings.isLootingOn && e.getBlock().getType() == Material.CHEST) {
e.setCancelled(true);
Inventory inv = ((Chest) e.getBlock().getState()).getBlockInventory();
String lootid = inv.getTitle() == null ? "" : inv.getTitle();
OMGLoot.LootParser lp = g.loot_contents(get(e.getPlayer()), lootid);
if (lp != null) {
inv.clear();
for (int i = 0; i < inv.getSize(); i++) {
ItemStack ii = lp.getRandom().toItem();
if (ii != null && NBTParser.getTagCompound(ii).getByte("Undroppable") != 1)
e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), ii);
}
}
e.getBlock().setType(Material.AIR);
e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), new ItemStack(Material.CHEST));
}
if (!GameArea.isBlockInside(e.getBlock())) e.setCancelled(true);
}
示例6: onPlayerOpenChest
import org.bukkit.block.Chest; //导入依赖的package包/类
@EventHandler
public void onPlayerOpenChest(PlayerInteractEvent event){
if(event.getClickedBlock() == null)return;
Block clicked = event.getClickedBlock();
Location blockClicked = event.getClickedBlock().getLocation();
Player p = event.getPlayer();
Arena a = am.getArena(p);
if(a == null)return;
if(clicked.getState() instanceof Chest){
Chest chest = (Chest)clicked.getState();
if(!a.contains(blockClicked)){
a.addChest(blockClicked);
Skywars.getCC().populateChest(a, chest);
}
}
}
示例7: checkWorth
import org.bukkit.block.Chest; //导入依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void checkWorth(InventoryOpenEvent event) {
// Do nothing if a player did not open the inventory or if chest events
// are disabled.
if (!(event.getPlayer() instanceof Player) || plugin.getSettings().isDisableChestEvents()) {
return;
}
Inventory inventory = event.getInventory();
// Set all default worth values for this chest.
if (inventory.getHolder() instanceof DoubleChest) {
DoubleChest chest = (DoubleChest) inventory.getHolder();
checkWorth((Chest) chest.getLeftSide());
checkWorth((Chest) chest.getRightSide());
}
if (inventory.getHolder() instanceof Chest) {
checkWorth((Chest) inventory.getHolder());
}
}
示例8: updateWorth
import org.bukkit.block.Chest; //导入依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void updateWorth(InventoryCloseEvent event) {
// Do nothing if a player did not close the inventory or if chest
// events are disabled.
if (!(event.getPlayer() instanceof Player) || plugin.getSettings().isDisableChestEvents()) {
return;
}
// Get cached values from when chest was opened and add the difference
// to the worth manager.
if (event.getInventory().getHolder() instanceof DoubleChest) {
DoubleChest chest = (DoubleChest) event.getInventory().getHolder();
updateWorth((Chest) chest.getLeftSide());
updateWorth((Chest) chest.getRightSide());
}
if (event.getInventory().getHolder() instanceof Chest) {
updateWorth((Chest) event.getInventory().getHolder());
}
}
示例9: handleChestDestruction
import org.bukkit.block.Chest; //导入依赖的package包/类
public void handleChestDestruction(Block b,List<Block> explodedBlocks)
{
Vector<ProtectedRegion> regions=ShopUtils.getRegions(b.getLocation());
if(regions!=null)
for(ProtectedRegion p:regions)
{
if(p!=null&&ShopUtils.shopExists(p))
{
BlockFace side=getDoubleChestSide(b);
if(side==null) //Single chest
{
ChestUtils.clearSingleChest((Chest)b.getState(),ShopUtils.getShop(p));
}
else //uuugggghhhh I have to deal with this freaking double chest
{
ChestUtils.dealWithThisFreakingDoubleChest((Chest)b.getState(),ShopUtils.getShop(p),side,explodedBlocks);
}
}
}
}
示例10: onInventoryCloseEvent
import org.bukkit.block.Chest; //导入依赖的package包/类
@EventHandler
public void onInventoryCloseEvent(InventoryCloseEvent event) {
//long time=System.nanoTime();
if(event.getInventory().getType()==InventoryType.CHEST&&CleanShop.shopScan)
{
Vector<ProtectedRegion> regions=null;
if(event.getInventory().getHolder() instanceof Chest)
regions=ShopUtils.getRegions(((Chest)event.getInventory().getHolder()).getLocation());
if(event.getInventory().getHolder() instanceof DoubleChest)
regions=ShopUtils.getRegions(((DoubleChest)event.getInventory().getHolder()).getLocation());
if(regions!=null)
for(ProtectedRegion p:regions)
{
if(p!=null)
if(ShopUtils.shopExists(p))
{
//plugin.calculateShopStock(plugin.getShop(p));
if(event.getInventory().getHolder() instanceof Chest)
ChestUtils.calculateChestStock((Chest)event.getInventory().getHolder(), ShopUtils.getShop(p));
else
ChestUtils.calculateChestStock((DoubleChest)event.getInventory().getHolder(), ShopUtils.getShop(p));
FileHandler.saveShops();
}
}
}
}
示例11: updatePearlHolder
import org.bukkit.block.Chest; //导入依赖的package包/类
/**
* Updates the pearl holder
* @param pearl The pearl to update
* @param holder The pearl holder
* @param event The event
*/
private void updatePearlHolder(ExilePearl pearl, InventoryHolder holder, Cancellable event) {
if (holder instanceof Chest) {
updatePearl(pearl, (Chest)holder);
} else if (holder instanceof DoubleChest) {
updatePearl(pearl, (Chest) ((DoubleChest) holder).getLeftSide());
} else if (holder instanceof Furnace) {
updatePearl(pearl, (Furnace) holder);
} else if (holder instanceof Dispenser) {
updatePearl(pearl, (Dispenser) holder);
} else if (holder instanceof Dropper) {
updatePearl(pearl, (Dropper) holder);
} else if (holder instanceof Hopper) {
updatePearl(pearl, (Hopper) holder);
} else if (holder instanceof BrewingStand) {
updatePearl(pearl, (BrewingStand) holder);
} else if (holder instanceof Player) {
updatePearl(pearl, (Player) holder);
}else {
event.setCancelled(true);
}
}
示例12: spawnChest
import org.bukkit.block.Chest; //导入依赖的package包/类
private void spawnChest(final Location l) {
if (InteractivePlugin.INSTANCE != null) {
Bukkit.getScheduler().runTaskLater(InteractivePlugin.INSTANCE, new Runnable() {
@Override
public void run() {
Block block = l.getBlock();
block.setType(Material.CHEST);
Chest chest = (Chest)block.getState();
Inventory inv = chest.getInventory();
int amount = 3 + CreateBonusIslandAction.this.random.nextInt(6);
for (int i = 0; i < amount; i++){
Material[] materials = Material.values();
Material material = materials[CreateBonusIslandAction.this.random.nextInt(materials.length)];
inv.addItem(new ItemStack(material, 1 + CreateBonusIslandAction.this.random.nextInt(3)));
}
}
}, 1);
}
}
示例13: onCommand
import org.bukkit.block.Chest; //导入依赖的package包/类
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)) {
return true;
}
Player player = (Player) sender;
if (player.getItemInHand().equals(Material.AIR)) {
Util.sendmessage(player, "&cアイテムが見つかりません。");
return true;
}
@SuppressWarnings("deprecation")
Block block = player.getTargetBlock((HashSet<Byte>) null, 10);
if (!(block.getType().equals(Material.CHEST)
|| block.getType().equals(Material.TRAPPED_CHEST))) {
Util.sendmessage(player, "&cチェストが見つかりません。");
return true;
}
Inventory inventory = ((Chest) block.getState()).getInventory();
inventory.clear();
Util.sendmessage(player, "&7インベントリ内のアイテムを削除しました。");
return true;
}
示例14: MagicChest
import org.bukkit.block.Chest; //导入依赖的package包/类
public void MagicChest(BlockBreakEvent event){
Location loc = event.getBlock().getLocation();
World world = loc.getWorld();
event.setCancelled(true);
Block block = event.getBlock();
block.setType(Material.CHEST);
DirectionalContainer chestData = (DirectionalContainer) block.getState().getData();
BlockFace directionInfo = new LuckyBlocksInvokeMethodClass().getCardinalDirection(event.getPlayer());
chestData.setFacingDirection(directionInfo);
//Next Line makes use of a Deprecated Method
block.setData(chestData.getData(),true);
Chest chest = (Chest) block.getState();
world.playEffect(loc,Effect.ENDER_SIGNAL,50);
int RandomSelection = (int) (Math.random()*100);
if (RandomSelection < 50) {
ItemStack goldenApples = new ItemStack(Material.GOLDEN_APPLE);
goldenApples.setAmount(5);
chest.getInventory().addItem(goldenApples);
}
else if (RandomSelection >= 50) isUnluckyChestActivated = 1;
}
示例15: clearContainerBlockContents
import org.bukkit.block.Chest; //导入依赖的package包/类
@Override
public boolean clearContainerBlockContents(Vector pt) {
Block block = getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (block == null) {
return false;
}
BlockState state = block.getState();
if (!(state instanceof org.bukkit.inventory.InventoryHolder)) {
return false;
}
org.bukkit.inventory.InventoryHolder chest = (org.bukkit.inventory.InventoryHolder) state;
Inventory inven = chest.getInventory();
if (chest instanceof Chest) {
inven = getBlockInventory((Chest) chest);
}
inven.clear();
return true;
}