本文整理汇总了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;
}
}
}
示例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.");
}
}
}
}
}
示例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();
}
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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);
}
示例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);
}
}
}