當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。