本文整理匯總了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);
}
}
}