Java Code Examples for org.bukkit.event.player.PlayerInteractEvent#getMaterial()
The following examples show how to use
org.bukkit.event.player.PlayerInteractEvent#getMaterial() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EventFilterMatchModule.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onInteract(final PlayerInteractEvent event) { if (cancelUnlessInteracting(event, event.getPlayer())) { // Allow the how-to book to be read if (event.getMaterial() == Material.WRITTEN_BOOK) { event.setUseItemInHand(Event.Result.ALLOW); } MatchPlayer player = match.getPlayer(event.getPlayer()); if (player == null) return; ClickType clickType = convertClick(event.getAction(), event.getPlayer()); if (clickType == null) return; match.callEvent( new ObserverInteractEvent( player, clickType, event.getClickedBlock(), null, event.getItem())); } }
Example 2
Source File: EventFilterMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onInteract(final PlayerInteractEvent event) { if(cancelUnlessInteracting(event, event.getPlayer())) { // Allow the how-to book to be read if(event.getMaterial() == Material.WRITTEN_BOOK) { event.setUseItemInHand(Event.Result.ALLOW); } else { event.setUseItemInHand(Event.Result.DENY); event.setUseInteractedBlock(Event.Result.DENY); } MatchPlayer player = getMatch().getPlayer(event.getPlayer()); if(player == null) return; if(!player.isSpawned()) { ClickType clickType = convertClick(event.getAction(), event.getPlayer()); if(clickType == null) return; getMatch().callEvent(new ObserverInteractEvent(player, clickType, event.getClickedBlock(), null, event.getItem())); } // Right-clicking armor will put it on unless we do this event.getPlayer().updateInventory(); } }
Example 3
Source File: ItemUseListener.java From EnchantmentsEnhance with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onItemClick(final PlayerInteractEvent event) { final Player player = event.getPlayer(); if (event.getMaterial() == Material.AIR) { return; } if (event.getAction().equals(Action.LEFT_CLICK_BLOCK) || event.getAction().equals(Action.LEFT_CLICK_AIR)) { return; } final ItemStack item = event.getItem(); if (!ItemManager.getGive(item).isEmpty()) { String[] give = ItemManager.getGive(item).split(":"); if (give.length == 2) { int id = Integer.parseInt(give[0]); int amount = Integer.parseInt(give[1]); if (id < 0) { Main.getApi().addAdvice(player.getName(), amount); Util.sendMessage(SettingsManager.lang.getString("materialize.adviceSucess") .replace("%level%", Integer.toString(amount)), player); } else { Main.getApi().addItem(player.getName(), id, amount); Util.sendMessage(SettingsManager.lang.getString("materialize.success") .replace("%amount%", Integer.toString(amount)) .replace("%item%", SettingsManager.lang.getString("item." + id)), player); } // Consume the item. try { if (event.getHand().equals(EquipmentSlot.HAND)) { consumeItem(Util.getMainHand(player), player); } else if (event.getHand().equals(EquipmentSlot.OFF_HAND)) { consumeItem(player.getInventory().getItemInOffHand(), player); } } catch (NoSuchMethodError ex) { consumeItem(Util.getMainHand(player), player); } event.setCancelled(true); } } }
Example 4
Source File: AutoPotion.java From AACAdditionPro with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onInteract(final PlayerInteractEvent event) { final User user = UserManager.getUser(event.getPlayer().getUniqueId()); // Not bypassed if (User.isUserInvalid(user, this.getModuleType())) { return; } // Timeout if (user.getTimestampMap().recentlyUpdated(TimestampKey.AUTOPOTION_TIMEOUT, timeout)) { event.setCancelled(true); return; } // Is the action a right-click that can throw a potion if ((event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) && // The item is a throwable potion event.getItem() != null && event.getMaterial() == Material.SPLASH_POTION && // The last sudden movement was not long ago user.getTimestampMap().recentlyUpdated(TimestampKey.AUTOPOTION_DETECTION, timeOffset)) { user.getDataMap().setValue(DataKey.AUTOPOTION_ALREADY_THROWN, true); // Here the timestamp is used to contain the data of the last splash user.getTimestampMap().updateTimeStamp(TimestampKey.AUTOPOTION_DETECTION); } }
Example 5
Source File: ProtectionWallListener.java From BedwarsRel with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onInteract(PlayerInteractEvent interact) { if (interact.getAction().equals(Action.LEFT_CLICK_AIR) || interact.getAction().equals(Action.LEFT_CLICK_BLOCK)) { return; } if (interact.getMaterial() == null) { return; } ProtectionWall wall = new ProtectionWall(); if (interact.getMaterial() != wall.getItemMaterial()) { return; } Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(interact.getPlayer()); if (game == null) { return; } if (game.getState() != GameState.RUNNING) { return; } if (game.isSpectator(interact.getPlayer())) { return; } wall.create(interact.getPlayer(), game); interact.setCancelled(true); }