當前位置: 首頁>>代碼示例>>Java>>正文


Java BlockPlaceEvent.getItemInHand方法代碼示例

本文整理匯總了Java中org.bukkit.event.block.BlockPlaceEvent.getItemInHand方法的典型用法代碼示例。如果您正苦於以下問題:Java BlockPlaceEvent.getItemInHand方法的具體用法?Java BlockPlaceEvent.getItemInHand怎麽用?Java BlockPlaceEvent.getItemInHand使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.bukkit.event.block.BlockPlaceEvent的用法示例。


在下文中一共展示了BlockPlaceEvent.getItemInHand方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onBlockRegister

import org.bukkit.event.block.BlockPlaceEvent; //導入方法依賴的package包/類
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockRegister(BlockPlaceEvent e) {
	if (BlockStorage.hasBlockInfo(e.getBlock())) {
		e.setCancelled(true);
		return;
	}
	ItemStack item = e.getItemInHand();
	if (item != null && item.getType() == Material.INK_SACK) return;
	SlimefunItem sfItem = SlimefunItem.getByItem(item);
	if (sfItem != null && !(sfItem instanceof NotPlaceable)){
		BlockStorage.addBlockInfo(e.getBlock(), "id", sfItem.getID(), true);
		if (SlimefunItem.blockhandler.containsKey(sfItem.getID())) {
			SlimefunItem.blockhandler.get(sfItem.getID()).onPlace(e.getPlayer(), e.getBlock(), sfItem);
		}
	}
	else {
		for (ItemHandler handler: SlimefunItem.getHandlers("BlockPlaceHandler")) {
			if (((BlockPlaceHandler) handler).onBlockPlace(e, item)) break;
		}
	}
}
 
開發者ID:StarWishsama,項目名稱:Slimefun4-Chinese-Version,代碼行數:22,代碼來源:ToolListener.java

示例2: onBlockPlace

import org.bukkit.event.block.BlockPlaceEvent; //導入方法依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onBlockPlace(BlockPlaceEvent event) {
    Block block = event.getBlockPlaced();
    ItemStack stack = event.getItemInHand();
    Player player = event.getPlayer();
    if (block.getState() instanceof CreatureSpawner && stack.hasItemMeta()) {
        ItemMeta meta = stack.getItemMeta();

        if (meta.hasLore() && meta.hasDisplayName()) {
            CreatureSpawner spawner = (CreatureSpawner) block.getState();
            List<String> lore = meta.getLore();
            if (!lore.isEmpty()) {
                String spawnerName = ChatColor.stripColor(lore.get(0).toUpperCase());
                Optional<EntityType> entityTypeOptional = GuavaCompat.getIfPresent(EntityType.class, spawnerName);
                if (entityTypeOptional.isPresent()) {
                    spawner.setSpawnedType(entityTypeOptional.get());
                    spawner.update(true, true);
                    player.sendMessage(ChatColor.AQUA + "Placed a " + ChatColor.BLUE + spawnerName + ChatColor.AQUA + " spawner.");
                }
            }
        }
    }
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:24,代碼來源:CrowbarListener.java

示例3: onBlockPlace

import org.bukkit.event.block.BlockPlaceEvent; //導入方法依賴的package包/類
@EventHandler(ignoreCancelled=true, priority=EventPriority.HIGHEST)
public void onBlockPlace(BlockPlaceEvent event)
{
  ItemStack stack = event.getItemInHand();
  BlockState state = event.getBlock().getState();
  if (((state instanceof Sign)) && (stack.hasItemMeta()))
  {
    ItemMeta meta = stack.getItemMeta();
    if ((meta.hasDisplayName()) && (meta.getDisplayName().equals(EVENT_SIGN_ITEM_NAME)))
    {
      Sign sign = (Sign)state;
      List<String> lore = meta.getLore();
      int count = 0;
      for (String loreLine : lore)
      {
        sign.setLine(count++, loreLine);
        if (count == 4) {
          break;
        }
      }
      sign.update();
    }
  }
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:25,代碼來源:EventSignListener.java

示例4: onBlockPlace

import org.bukkit.event.block.BlockPlaceEvent; //導入方法依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockPlace(BlockPlaceEvent event) {
    ItemStack stack = event.getItemInHand();
    BlockState state = event.getBlock().getState();
    if (state instanceof Sign && stack.hasItemMeta()) {
        ItemMeta meta = stack.getItemMeta();
        if (meta.hasDisplayName() && meta.getDisplayName().equals(DEATH_SIGN_ITEM_NAME)) {
            Sign sign = (Sign) state;
            List<String> lore = meta.getLore();
            int count = 0;
            for (String loreLine : lore) {
                sign.setLine(count++, loreLine);
                if (count == 4)
                    break;
            }

            sign.update();
            
            //sign.setEditible(false);
        }
    }
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:23,代碼來源:DeathSignListener.java

示例5: handleInstantActivation

import org.bukkit.event.block.BlockPlaceEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void handleInstantActivation(BlockPlaceEvent event) {
    if(this.properties.instantIgnite && event.getBlock().getType() == Material.TNT) {
        World world = event.getBlock().getWorld();
        TNTPrimed tnt = world.spawn(BlockUtils.base(event.getBlock()), TNTPrimed.class);

        if(this.properties.fuse != null) {
            tnt.setFuseTicks(this.getFuseTicks());
        }

        if(this.properties.power != null) {
            tnt.setYield(this.properties.power); // Note: not related to EntityExplodeEvent.yield
        }

        if(callPrimeEvent(tnt, event.getPlayer(), true)) {
            // Only cancel the block placement if the prime event is NOT cancelled.
            // If priming is cancelled, the block is allowed to stay (unless some
            // other handler has already cancelled the place event).
            event.setCancelled(true);
            world.playSound(tnt.getLocation(), Sound.ENTITY_TNT_PRIMED, 1, 1);

            ItemStack inHand = event.getItemInHand();
            if(inHand.getAmount() == 1) {
                inHand = null;
            } else {
                inHand.setAmount(inHand.getAmount() - 1);
            }
            event.getPlayer().getInventory().setItem(event.getHand(), inHand);
        }
    }
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:32,代碼來源:TNTMatchModule.java

示例6: onBlockPlace

import org.bukkit.event.block.BlockPlaceEvent; //導入方法依賴的package包/類
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {

	if (event.getItemInHand().getType() != Material.MOB_SPAWNER)
		return;

	ItemStack is = event.getItemInHand();
	if (!is.hasItemMeta())
		return;

	ItemMeta im = is.getItemMeta();

	if (!im.hasLore())
		return;

	String lore = im.getLore().toString();

	if (!lore.contains("Spawner:"))
		return;

	EntityType entity = getEntity(lore);

	if (entity == EntityType.AREA_EFFECT_CLOUD) {
		event.setCancelled(true);
		return;
	}

	setSpawner(event.getBlock(), entity);
}
 
開發者ID:ThEWiZ76,項目名稱:KingdomFactions,代碼行數:30,代碼來源:BlockPlace.java

示例7: unplaceable

import org.bukkit.event.block.BlockPlaceEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void unplaceable(BlockPlaceEvent evt) {
    ItemStack stack = evt.getItemInHand();
    if (stack == null) return;
    ItemMeta meta = stack.getItemMeta();
    if (!meta.hasLore()) return;
    
    for (String lore : meta.getLore()) {
        Item item = ItemFactory.items.get(lore);
        if (item instanceof UnplaceableItem) {
            evt.setCancelled(true);
        }
    }
}
 
開發者ID:Recraft,項目名稱:Recreator,代碼行數:15,代碼來源:ItemActionListener.java


注:本文中的org.bukkit.event.block.BlockPlaceEvent.getItemInHand方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。