当前位置: 首页>>代码示例>>Java>>正文


Java Chest.hasMetadata方法代码示例

本文整理汇总了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);
	}
}
 
开发者ID:xize,项目名称:manco2,代码行数:23,代码来源:CratePlayer.java

示例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);
				}
			}
		}
	}
}
 
开发者ID:xize,项目名称:manco2,代码行数:20,代码来源:PlayerCrateProtectionEvent.java

示例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);
		}
	}
}
 
开发者ID:xize,项目名称:manco2,代码行数:15,代码来源:BlockProtectEvent.java

示例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();
		}
	}
}
 
开发者ID:xize,项目名称:manco2,代码行数:11,代码来源:ChestCloseEvent.java

示例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));
    }
}
 
开发者ID:SamaGames,项目名称:SurvivalAPI,代码行数:58,代码来源:RandomChestModule.java

示例6: isCrate

import org.bukkit.block.Chest; //导入方法依赖的package包/类
private boolean isCrate(Chest chest) {
	if(chest.hasMetadata("crate_owner")) {
		return true;
	}
	return false;
}
 
开发者ID:xize,项目名称:manco2,代码行数:7,代码来源:ChestPlaceEvent.java


注:本文中的org.bukkit.block.Chest.hasMetadata方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。