当前位置: 首页>>代码示例>>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;未经允许,请勿转载。