Java Code Examples for org.bukkit.event.player.PlayerInteractEvent#getAction()
The following examples show how to use
org.bukkit.event.player.PlayerInteractEvent#getAction() .
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: ItemListener.java From HubBasics with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) public void onLeftClick(PlayerInteractEvent event) { if (!(event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK)) { return; } ItemStack itemStack = ReflectionUtils.invokeMethod(event.getPlayer(), this.getItemInHandMethod); if (itemStack != null && itemStack.getType() != Material.AIR) { NBTItem nbtItem = new NBTItem(itemStack); if (!nbtItem.hasKey("HubBasics")) return; event.setCancelled(true); CustomItem item = HubBasics.getInstance().getItemManager().get(nbtItem.getString("HubBasics")); if (item == null) { itemStack.setType(Material.AIR); // Destroy old item return; } if (!item.getRunOnLeftClick()) return; item.onCommand(event.getPlayer()); } }
Example 2
Source File: SignListener.java From ChestCommands with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onInteract(PlayerInteractEvent event) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.hasBlock() && event.getClickedBlock().getState() instanceof Sign) { Sign sign = (Sign) event.getClickedBlock().getState(); if (sign.getLine(0).equalsIgnoreCase(ChatColor.DARK_BLUE + "[menu]")) { sign.getLine(1); ExtendedIconMenu iconMenu = ChestCommands.getFileNameToMenuMap().get(BukkitUtils.addYamlExtension(sign.getLine(1))); if (iconMenu != null) { if (event.getPlayer().hasPermission(iconMenu.getPermission())) { iconMenu.open(event.getPlayer()); } else { iconMenu.sendNoPermissionMessage(event.getPlayer()); } } else { sign.setLine(0, ChatColor.RED + ChatColor.stripColor(sign.getLine(0))); event.getPlayer().sendMessage(ChestCommands.getLang().menu_not_found); } } } }
Example 3
Source File: BlockListener.java From Carbon with GNU Lesser General Public License v3.0 | 6 votes |
@SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void slabInteract(PlayerInteractEvent event) { if (event.getItem() == null || event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getItem().getType() != Carbon.injector().redSandstoneSlabMat) return; Block clickedBlock = event.getClickedBlock(); if (clickedBlock.getType() == Carbon.injector().redSandstoneSlabMat) if ((clickedBlock.getData() == 0 && event.getBlockFace() == BlockFace.UP) || (clickedBlock.getData() == 8 && event.getBlockFace() == BlockFace.DOWN)) { setDoubleSlab(event.getPlayer(), clickedBlock); event.setCancelled(true); return; } Block adjacent = clickedBlock.getRelative(event.getBlockFace()); if (adjacent.getType() == Carbon.injector().redSandstoneSlabMat) { setDoubleSlab(event.getPlayer(), adjacent); event.setCancelled(true); } }
Example 4
Source File: AntiGriefListener.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR) public void cloneCraftingWindow(final PlayerInteractEvent event) { if (!event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getPlayer().getOpenInventory().getType() == InventoryType.CRAFTING /* nothing open */) { Block block = event.getClickedBlock(); if (block != null && block.getType() == Material.WORKBENCH && !event.getPlayer().isSneaking()) { // create the window ourself event.setCancelled(true); event.getPlayer().openWorkbench(null, true); // doesn't check reachable } } }
Example 5
Source File: BandageUse.java From Survival-Games with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("deprecation") @EventHandler public void onBandageUse(PlayerInteractEvent e) { Player p = e.getPlayer(); Boolean active = GameManager.getInstance().isPlayerActive(p); if (!active) { return; } if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) { if (e.getPlayer().getItemInHand().getType() == Material.PAPER) { e.getPlayer().getInventory().removeItem(new ItemStack(Material.PAPER, 1)); double newhealth = e.getPlayer().getHealth() + 10; if((newhealth > 20.0) || (newhealth < 0 )) { newhealth = 20.0; } e.getPlayer().setHealth(newhealth); e.getPlayer().sendMessage(ChatColor.GREEN + "You used a bandage and got 5 hearts."); } } }
Example 6
Source File: TrackerListener.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler public void onTrackerUse(PlayerInteractEvent event) { Player player = event.getPlayer(); if (!Main.isPlayerInGame(player)) { return; } GamePlayer gamePlayer = Main.getPlayerGameProfile(player); Game game = gamePlayer.getGame(); if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (game.getStatus() == GameStatus.RUNNING && !gamePlayer.isSpectator) { if (event.getItem() != null) { ItemStack stack = event.getItem(); String unhidden = APIUtils.unhashFromInvisibleStringStartsWith(stack, TRACKER_PREFIX); if (unhidden != null) { event.setCancelled(true); Tracker tracker = new Tracker(game, player, game.getTeamOfPlayer(player)); tracker.runTask(); } } } } }
Example 7
Source File: ArmorListener.java From AdditionsAPI with MIT License | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void playerInteractEvent(PlayerInteractEvent e){ if(e.getAction() == Action.PHYSICAL) return; if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){ Player player = e.getPlayer(); ArmorType newArmorType = ArmorType.matchType(e.getItem()); if(newArmorType != null){ if(newArmorType.equals(ArmorType.HELMET) && isAirOrNull(e.getPlayer().getInventory().getHelmet()) || newArmorType.equals(ArmorType.CHESTPLATE) && isAirOrNull(e.getPlayer().getInventory().getChestplate()) || newArmorType.equals(ArmorType.LEGGINGS) && isAirOrNull(e.getPlayer().getInventory().getLeggings()) || newArmorType.equals(ArmorType.BOOTS) && isAirOrNull(e.getPlayer().getInventory().getBoots())){ ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent(e.getPlayer(), EquipMethod.HOTBAR, ArmorType.matchType(e.getItem()), null, e.getItem()); Bukkit.getServer().getPluginManager().callEvent(armorEquipEvent); if(armorEquipEvent.isCancelled()){ e.setCancelled(true); player.updateInventory(); } } } } }
Example 8
Source File: MapRatingsMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler public void onOpenButtonClick(PlayerInteractEvent event) { if(event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) return; MatchPlayer player = this.getMatch().getPlayer(event.getPlayer()); if(player == null) return; ItemStack stack = event.getPlayer().getItemInHand(); if(stack == null) return; if(stack.getType() != Material.HOPPER) return; String name = stack.getItemMeta().getDisplayName(); if(name == null || !name.startsWith(BUTTON_PREFIX)) return; this.showDialog(player); }
Example 9
Source File: Spawning.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@Override public void onEvent(PlayerInteractEvent event) { super.onEvent(event); event.setCancelled(true); if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) { requestSpawn(); } }
Example 10
Source File: BrewingTaskType.java From Quests with MIT License | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockPlace(PlayerInteractEvent event) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (event.getClickedBlock().getType() == Material.BREWING_STAND) { brewingStands.put(event.getClickedBlock().getLocation(), event.getPlayer().getUniqueId()); } } }
Example 11
Source File: ListenerBlocks.java From CombatLogX with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority=EventPriority.HIGH, ignoreCancelled=true) public void onInteract(PlayerInteractEvent e) { Action action = e.getAction(); if(action != Action.RIGHT_CLICK_BLOCK) return; FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml"); if(!config.getBoolean("blocks.prevent-interaction")) return; Player player = e.getPlayer(); ICombatManager combatManager = this.plugin.getCombatManager(); if(!combatManager.isInCombat(player)) return; e.setCancelled(true); sendMessageWithCooldown(player, "cheat-prevention.blocks.no-interaction"); }
Example 12
Source File: MapBuilder.java From AnnihilationPro with MIT License | 5 votes |
@EventHandler(priority=EventPriority.HIGH) public void nexusHelperCheck(PlayerInteractEvent event) { if(event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) { final Player player = event.getPlayer(); TeamBlock t = null; if(KitUtils.itemHasName(player.getItemInHand(), TeamBlock.Red.getName())) t = TeamBlock.Red; else if(KitUtils.itemHasName(player.getItemInHand(), TeamBlock.Blue.getName())) t = TeamBlock.Blue; else if(KitUtils.itemHasName(player.getItemInHand(), TeamBlock.Green.getName())) t = TeamBlock.Green; else if(KitUtils.itemHasName(player.getItemInHand(), TeamBlock.Yellow.getName())) t = TeamBlock.Yellow; if(t != null) { //They made a click with a team block event.setCancelled(true); List<MetadataValue> vals = player.getMetadata("TeamHandler"); if(vals != null && vals.size() == 1) { Object obj = vals.get(0).value(); if(obj != null && obj instanceof TeamBlockHandler) { ((TeamBlockHandler)obj).onBlockClick(player, t.Team, event.getAction(), event.getClickedBlock(),event.getBlockFace()); } } } } }
Example 13
Source File: PlantsListener.java From ExoticGarden with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onInteract(PlayerInteractEvent e) { if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return; if (e.getHand() != EquipmentSlot.HAND) return; if (e.getPlayer().isSneaking()) return; if (SlimefunPlugin.getProtectionManager().hasPermission(e.getPlayer(), e.getClickedBlock().getLocation(), ProtectableAction.BREAK_BLOCK)) { ItemStack item = ExoticGarden.harvestPlant(e.getClickedBlock()); if (item != null) { e.getClickedBlock().getWorld().playEffect(e.getClickedBlock().getLocation(), Effect.STEP_SOUND, Material.OAK_LEAVES); e.getClickedBlock().getWorld().dropItemNaturally(e.getClickedBlock().getLocation(), item); } } }
Example 14
Source File: CancellableChunkEvents.java From ClaimChunk with MIT License | 5 votes |
@EventHandler public void onPlayerInteract(PlayerInteractEvent e) { if (e != null && e.getClickedBlock() != null && e.getAction() != Action.LEFT_CLICK_BLOCK && e.getAction() != Action.LEFT_CLICK_AIR && e.getAction() != Action.RIGHT_CLICK_AIR) { ChunkEventHelper.handleInteractionEvent(e.getPlayer(), e.getClickedBlock().getChunk(), e); } }
Example 15
Source File: TeamCommand.java From AnnihilationPro with MIT License | 5 votes |
@EventHandler(priority=EventPriority.HIGH) public void voteGUIcheck(PlayerInteractEvent event) { if(event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR) { final Player player = event.getPlayer(); if(KitUtils.itemHasName(player.getItemInHand(), CustomItem.TEAMMAP.getName())) { if(menu != null) menu.open(player); event.setCancelled(true); } } }
Example 16
Source File: KitLoading.java From AnnihilationPro with MIT License | 5 votes |
@EventHandler(priority=EventPriority.HIGHEST) public void openKitMenuCheck(PlayerInteractEvent event) { if(event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR) { final Player player = event.getPlayer(); if(KitUtils.itemHasName(player.getItemInHand(), CustomItem.KITMAP.getName())) { openKitMap(player); event.setCancelled(true); } } }
Example 17
Source File: TNTSheepListener.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler public void onTNTSheepUsed(PlayerInteractEvent event) { Player player = event.getPlayer(); if (!Main.isPlayerInGame(player)) { return; } GamePlayer gamePlayer = Main.getPlayerGameProfile(player); Game game = gamePlayer.getGame(); if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (game.getStatus() == GameStatus.RUNNING && !gamePlayer.isSpectator && event.getItem() != null) { ItemStack stack = event.getItem(); String unhidden = APIUtils.unhashFromInvisibleStringStartsWith(stack, TNT_SHEEP_PREFIX); if (unhidden != null) { event.setCancelled(true); double speed = Double.parseDouble(unhidden.split(":")[2]); double follow = Double.parseDouble(unhidden.split(":")[3]); double maxTargetDistance = Double.parseDouble(unhidden.split(":")[4]); int explosionTime = Integer.parseInt(unhidden.split(":")[5]); Location startLocation; if (event.getClickedBlock() == null) { startLocation = player.getLocation(); } else { startLocation = event.getClickedBlock().getRelative(BlockFace.UP).getLocation(); } TNTSheep sheep = new TNTSheep(game, player, game.getTeamOfPlayer(player), startLocation, stack, speed, follow, maxTargetDistance, explosionTime); sheep.spawn(); } } } }
Example 18
Source File: ItemListener.java From Carbon with GNU Lesser General Public License v3.0 | 4 votes |
@SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onCauldronClick(PlayerInteractEvent evt) { if (evt.getAction() == Action.RIGHT_CLICK_BLOCK) { if (evt.getBlockFace() == BlockFace.UP && evt.getClickedBlock().getType() == Material.CAULDRON && evt.getItem() != null && evt.getItem().getType() == Carbon.injector().bannerItemMat) { evt.setCancelled(true); ItemStack originalBanner = evt.getItem(); //create new banner with latest pattern removed net.minecraft.server.v1_7_R4.ItemStack nmsNewBanner = CraftItemStack.asNMSCopy(originalBanner); NBTTagCompound tag = nmsNewBanner.getTag(); byte waterLevel = evt.getClickedBlock().getData(); if (waterLevel > 0 && tag != null && tag.hasKey("BlockEntityTag") && tag.getCompound("BlockEntityTag").hasKey("Patterns")) { NBTTagCompound compound = tag.getCompound("BlockEntityTag"); NBTTagList list = compound.getList("Patterns", 10); NBTTagList newList = new NBTTagList(); for (int n = 0; n < list.size() - 1; n++) { newList.add(list.get(n)); } if (newList.size() > 0) { compound.set("Patterns", newList); } else { compound.remove("Patterns"); } ItemStack newBannerItem = CraftItemStack.asCraftMirror(nmsNewBanner); newBannerItem.setAmount(1); //update cauldron evt.getClickedBlock().setData(--waterLevel); //update used itemstack if (originalBanner.getAmount() > 1) { evt.getItem().setAmount(originalBanner.getAmount() - 1); } else { evt.getItem().setAmount(0); evt.getPlayer().setItemInHand(null); } //add new banner evt.getPlayer().getInventory().addItem(newBannerItem); evt.getPlayer().updateInventory(); } } } }
Example 19
Source File: DPlayerListener.java From DungeonsXL with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onPlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); if (isCitizensNPC(player)) { return; } Block clickedBlock = event.getClickedBlock(); DGameWorld gameWorld = (DGameWorld) plugin.getGameWorld(player.getWorld()); if (clickedBlock != null) { // Block Enderchests if (gameWorld != null || plugin.getEditWorld(player.getWorld()) != null) { if (event.getAction() != Action.LEFT_CLICK_BLOCK) { if (VanillaItem.ENDER_CHEST.is(clickedBlock)) { if (!DPermission.hasPermission(player, DPermission.BYPASS) && !DPermission.hasPermission(player, DPermission.ENDER_CHEST)) { MessageUtil.sendMessage(player, DMessage.ERROR_ENDERCHEST.getMessage()); event.setCancelled(true); } } else if (Category.BEDS.containsBlock(clickedBlock)) { if (!DPermission.hasPermission(player, DPermission.BYPASS) && !DPermission.hasPermission(player, DPermission.BED)) { MessageUtil.sendMessage(player, DMessage.ERROR_BED.getMessage()); event.setCancelled(true); } } } } // Block Dispensers if (gameWorld != null) { if (event.getAction() != Action.LEFT_CLICK_BLOCK) { if (VanillaItem.DISPENSER.is(clickedBlock)) { if (!DPermission.hasPermission(player, DPermission.BYPASS) && !DPermission.hasPermission(player, DPermission.DISPENSER)) { MessageUtil.sendMessage(player, DMessage.ERROR_DISPENSER.getMessage()); event.setCancelled(true); } } } for (LockedDoor door : gameWorld.getLockedDoors()) { if (clickedBlock.equals(door.getBlock()) || clickedBlock.equals(door.getAttachedBlock())) { event.setCancelled(true); return; } } } } // Check Portals if (event.getItem() != null) { ItemStack item = event.getItem(); // Copy/Paste a Sign and Block-info if (plugin.getEditWorld(player.getWorld()) != null) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (VanillaItem.STICK.is(item)) { DEditPlayer editPlayer = (DEditPlayer) dPlayers.getEditPlayer(player); if (editPlayer != null) { editPlayer.poke(clickedBlock); event.setCancelled(true); } } } } } }
Example 20
Source File: ShopInteractListener.java From ShopChest with MIT License | 3 votes |
@EventHandler(priority = EventPriority.HIGH) public void onPlayerInteractCreate(PlayerInteractEvent e) { Player p = e.getPlayer(); Block b = e.getClickedBlock(); if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return; if (!(ClickType.getPlayerClickType(p) instanceof CreateClickType)) return; if (b.getType() != Material.CHEST && b.getType() != Material.TRAPPED_CHEST) return; if (ClickType.getPlayerClickType(p).getClickType() != ClickType.EnumClickType.CREATE) return; if (Config.enableAuthMeIntegration && plugin.hasAuthMe() && !AuthMeApi.getInstance().isAuthenticated(p)) return; if (e.isCancelled() && !p.hasPermission(Permissions.CREATE_PROTECTED)) { p.sendMessage(LanguageUtils.getMessage(Message.NO_PERMISSION_CREATE_PROTECTED)); plugin.debug(p.getName() + " is not allowed to create a shop on the selected chest"); } else if (shopUtils.isShop(b.getLocation())) { p.sendMessage(LanguageUtils.getMessage(Message.CHEST_ALREADY_SHOP)); plugin.debug("Chest is already a shop"); } else if (!ItemUtils.isAir(b.getRelative(BlockFace.UP).getType())) { p.sendMessage(LanguageUtils.getMessage(Message.CHEST_BLOCKED)); plugin.debug("Chest is blocked"); } else { CreateClickType clickType = (CreateClickType) ClickType.getPlayerClickType(p); ShopProduct product = clickType.getProduct(); double buyPrice = clickType.getBuyPrice(); double sellPrice = clickType.getSellPrice(); ShopType shopType = clickType.getShopType(); create(p, b.getLocation(), product, buyPrice, sellPrice, shopType); } e.setCancelled(true); ClickType.removePlayerClickType(p); }