本文整理汇总了Java中org.bukkit.block.Chest.hasMetadata方法的典型用法代码示例。如果您正苦于以下问题:Java Chest.hasMetadata方法的具体用法?Java Chest.hasMetadata怎么用?Java Chest.hasMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.block.Chest
的用法示例。
在下文中一共展示了Chest.hasMetadata方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: remove
import org.bukkit.block.Chest; //导入方法依赖的package包/类
/**
* removes all memory allocated objects of the crate the player owns
*
* @author xize
*/
public void remove() {
if(pl.getCrateOwners().contains(p.getName())) {
pl.getCrateOwners().remove(p.getName());
}
if(p.hasMetadata("crate")) {
Chest chest = getCrateChest();
chest.getInventory().clear();
chest.removeMetadata("crate_owner", pl);
chest.removeMetadata("crate_serie", pl);
if(chest.hasMetadata("crate")) {
System.out.println("chest has metadata key \"crate\"");
}
//chest.removeMetadata("crate", pl);
chest.getBlock().setType(Material.AIR);
p.removeMetadata("crate", pl);
}
}
示例2: onInteract
import org.bukkit.block.Chest; //导入方法依赖的package包/类
@EventHandler
public void onInteract(PlayerInteractEvent e) {
if(e.isCancelled()) {
return;
}
if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
if(e.getClickedBlock().getType() == Material.CHEST) {
Chest chest = (Chest) e.getClickedBlock().getState();
if(chest.hasMetadata("crate_owner")) {
String owner = ((FixedMetadataValue)chest.getMetadata("crate_owner").get(0)).asString();
if(!e.getPlayer().getName().equalsIgnoreCase(owner)) {
e.getPlayer().sendMessage(ChatColor.RED + "this crate does not belongs to you!.");
e.setCancelled(true);
}
}
}
}
}
示例3: onBreak
import org.bukkit.block.Chest; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.LOW)
public void onBreak(BlockBreakEvent e) {
if(e.isCancelled()) {
return;
}
if(e.getBlock().getType() == Material.CHEST) {
Chest chest = (Chest) e.getBlock().getState();
if(chest.hasMetadata("crate_owner")) {
e.getPlayer().sendMessage(ChatColor.RED + "you cannot break crates.");
e.setCancelled(true);
}
}
}
示例4: onClose
import org.bukkit.block.Chest; //导入方法依赖的package包/类
@EventHandler
public void onClose(InventoryCloseEvent e) {
if(e.getInventory().getHolder() instanceof Chest) {
Chest chest = (Chest) e.getInventory().getHolder();
if(chest.hasMetadata("crate_owner")) {
CratePlayer player = pl.getCratePlayer(e.getPlayer().getName());
player.remove();
}
}
}
示例5: onPlayerInteract
import org.bukkit.block.Chest; //导入方法依赖的package包/类
/**
* Fill a legacy chest
*
* @param event Event
*/
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event)
{
if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK) && event.getClickedBlock().getType().equals(Material.CHEST))
{
Chest chest = (Chest) event.getClickedBlock().getState();
if (chest.hasMetadata("playerInteracted"))
return;
Inventory inventory = chest.getInventory();
inventory.clear();
int addedItems = 0;
int slot;
for (ItemStack item : this.items.keySet())
{
if (addedItems > 20)
break;
int frequency = 0;
for(Map.Entry<ItemStack, Integer> entry : this.items.entrySet())
if(entry.getKey().equals(item))
frequency = entry.getValue();
SecureRandom random = new SecureRandom();
if (random.nextInt(1000) <= frequency * 10)
{
ItemStack stack = item.clone();
stack.setAmount((random.nextInt(3) + 1) * stack.getAmount());
slot = random.nextInt(inventory.getSize());
while (inventory.getItem(slot) != null)
{
slot++;
if (slot >= inventory.getSize())
slot = 0;
}
inventory.setItem(slot, this.addMetaIfNeeded(stack));
addedItems++;
}
}
chest.setMetadata("playerInteracted", new FixedMetadataValue(this.plugin, true));
}
}
示例6: isCrate
import org.bukkit.block.Chest; //导入方法依赖的package包/类
private boolean isCrate(Chest chest) {
if(chest.hasMetadata("crate_owner")) {
return true;
}
return false;
}