Java Code Examples for org.bukkit.event.player.PlayerInteractEvent#getClickedBlock()
The following examples show how to use
org.bukkit.event.player.PlayerInteractEvent#getClickedBlock() .
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: PlayerBlockModifyEventHandler.java From SuperVanish with Mozilla Public License 2.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGH) public void onInteract(PlayerInteractEvent e) { try { if (!plugin.getVanishStateMgr().isVanished(e.getPlayer().getUniqueId())) return; if (e.getAction().equals(Action.PHYSICAL) && e.getClickedBlock() != null) { if (!plugin.getSettings().getBoolean("InvisibilityFeatures.DisablePressurePlates")) return; String material = e.getClickedBlock().getType().toString(); List<String> disallowedMaterials = Arrays.asList("STONE_PLATE", "GOLD_PLATE", "IRON_PLATE", "WOOD_PLATE"/* <- LEGACY*/, "TRIPWIRE", "PRESSURE_PLATE"); for (String disallowedMaterial : disallowedMaterials) if (material.equals(disallowedMaterial) || material.contains(disallowedMaterial)) { e.setCancelled(true); } } } catch (Exception er) { plugin.logException(er); } }
Example 2
Source File: Playable.java From CardinalPGM with MIT License | 5 votes |
@EventHandler public void onPlayerInteract(PlayerInteractEvent event) { Optional<TeamModule> team = Teams.getTeamByPlayer(event.getPlayer()); if (GameHandler.getGameHandler().getMatch().isRunning() && team.isPresent() && !team.get().isObserver()) { if (region != null && event.getClickedBlock() != null) { if (region.contains(event.getClickedBlock().getLocation())) { ChatUtil.sendWarningMessage(event.getPlayer(), new LocalizedChatMessage(ChatConstant.ERROR_PLAYABLE_INTERACT)); event.setCancelled(true); } } } }
Example 3
Source File: EventRuleMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void checkUse(final PlayerInteractEvent event) { if(event.getAction() == Action.RIGHT_CLICK_BLOCK) { MatchPlayer player = this.match.getParticipant(event.getPlayer()); if(player == null) return; Block block = event.getClickedBlock(); if(block == null) return; this.handleUse(event, block.getState(), player); } }
Example 4
Source File: BlockListener.java From civcraft with GNU General Public License v2.0 | 5 votes |
private void OnPlayerUseItem(PlayerInteractEvent event) { Location loc = (event.getClickedBlock() == null) ? event.getPlayer().getLocation() : event.getClickedBlock().getLocation(); ItemStack stack = event.getItem(); coord.setFromLocation(event.getPlayer().getLocation()); Camp camp = CivGlobal.getCampFromChunk(coord); if (camp != null) { if (!camp.hasMember(event.getPlayer().getName())) { CivMessage.sendError(event.getPlayer(), "You cannot use "+stack.getType().toString()+" in a camp you do not belong to."); event.setCancelled(true); return; } } TownChunk tc = CivGlobal.getTownChunk(loc); if (tc == null) { return; } Resident resident = CivGlobal.getResident(event.getPlayer().getName()); if (resident == null) { event.setCancelled(true); } if(!tc.perms.hasPermission(PlotPermissions.Type.ITEMUSE, resident)) { event.setCancelled(true); CivMessage.sendErrorNoRepeat(event.getPlayer(), "You do not have permission to use "+stack.getType().toString()+" here."); } return; }
Example 5
Source File: GameMap.java From AnnihilationPro with MIT License | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void signClickCheck(PlayerInteractEvent event) { if(event.getAction() == Action.RIGHT_CLICK_BLOCK) { Block b = event.getClickedBlock(); if(b != null) { //Bukkit.getLogger().info("Error test 1"); if(b.getType() == Material.FURNACE || b.getType() == Material.BURNING_FURNACE) { //Bukkit.getLogger().info("Error test 1"); MapKey key = MapKey.getKey(b.getLocation()); if(this.enderFurnaces.containsKey(key)) { //Bukkit.getLogger().info("Error test 2"); event.setCancelled(true); AnniPlayer p = AnniPlayer.getPlayer(event.getPlayer().getUniqueId()); if(p != null) { // Bukkit.getLogger().info("Error test 3"); // if(p.getFurnace() != null) // { // Bukkit.getLogger().info("Error test 4"); p.openFurnace(); // } // else // Bukkit.getLogger().warning("[Annihilation] Someones enderfurnace was null!"); } } } } } }
Example 6
Source File: DWorldListener.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onBlockInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); if (DPlayerListener.isCitizensNPC(player)) { return; } Block block = event.getClickedBlock(); if (block == null) { return; } GameWorld gameWorld = plugin.getGameWorld(block.getWorld()); if (gameWorld == null) { return; } if (!gameWorld.isPlaying()) { if (!plugin.getMainConfig().areLobbyContainersEnabled() || !ContainerAdapter.isValidContainer(block)) { event.setCancelled(true); } return; } Map<ExItem, HashSet<ExItem>> blacklist = gameWorld.getDungeon().getRules().getState(GameRule.INTERACTION_BLACKLIST); if (blacklist == null) { return; } ExItem material = VanillaItem.get(block.getType()); ExItem tool = caliburn.getExItem(getItemInHand(event)); if (blacklist.containsKey(material) && (blacklist.get(material) == null || blacklist.get(material).isEmpty() || blacklist.get(material).contains(tool))) { event.setCancelled(true); } }
Example 7
Source File: GlobalProtectionListener.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); if (DPlayerListener.isCitizensNPC(player) || plugin.getPlayerCache().get(player).isInBreakMode()) { return; } Block clickedBlock = event.getClickedBlock(); if (clickedBlock == null) { return; } if (Category.SIGNS.containsBlock(clickedBlock)) { GroupSign groupSign = GroupSign.getByBlock(plugin, clickedBlock); if (groupSign != null) { groupSign.onPlayerInteract(clickedBlock, player); event.setCancelled(true); } GameSign gameSign = GameSign.getByBlock(plugin, clickedBlock); if (gameSign != null) { gameSign.onPlayerInteract(clickedBlock, player); event.setCancelled(true); } LeaveSign leaveSign = LeaveSign.getByBlock(plugin, clickedBlock); if (leaveSign != null) { leaveSign.onPlayerInteract(player); event.setCancelled(true); } } }
Example 8
Source File: GuiKeepModule.java From CardinalPGM with MIT License | 5 votes |
@EventHandler public void onPlayerInteract(PlayerInteractEvent event) { if (GameHandler.getGameHandler().getMatch().isRunning() && !ObserverModule.testObserverOrDead(event.getPlayer())) { if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { if (event.getClickedBlock() != null) { if (event.getClickedBlock().getType().equals(Material.WORKBENCH)) { if (!event.getPlayer().isSneaking() || event.getPlayer().getItemInHand() == null) { event.setCancelled(true); event.getPlayer().openWorkbench(event.getPlayer().getLocation(), true); } } } } } }
Example 9
Source File: ItemUseListener.java From CS-CoreLib with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onRightClick(PlayerInteractEvent e) throws Exception { if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) { ItemUseEvent event = new ItemUseEvent(e, e.getAction() == Action.RIGHT_CLICK_BLOCK ? e.getClickedBlock(): null); Bukkit.getPluginManager().callEvent(event); if (!e.isCancelled()) e.setCancelled(event.isCancelled()); } }
Example 10
Source File: IslandGuard1_9.java From askyblock with GNU General Public License v2.0 | 5 votes |
/** * Handle blocks that need special treatment * Tilling of coarse dirt into dirt using off-hand (regular hand is in 1.8) * Usually prevented because it could lead to an endless supply of dirt with gravel * * @param e - event */ @SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) public void onPlayerInteract(final PlayerInteractEvent e) { if (!e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { return; } if (!IslandGuard.inWorld(e.getPlayer())) { return; } if (e.getPlayer().isOp()) { return; } // This permission bypasses protection if (VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect") || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "craft.dirt")) { return; } // Prevents tilling of coarse dirt into dirt ItemStack inHand = e.getPlayer().getInventory().getItemInOffHand(); if (inHand.getType() == Material.WOOD_HOE || inHand.getType() == Material.IRON_HOE || inHand.getType() == Material.GOLD_HOE || inHand.getType() == Material.DIAMOND_HOE || inHand.getType() == Material.STONE_HOE) { // plugin.getLogger().info("1.8 " + "DEBUG: hoe in hand"); Block block = e.getClickedBlock(); // plugin.getLogger().info("1.8 " + "DEBUG: block is " + block.getType() + // ":" + block.getData()); // Check if coarse dirt if (block.getType() == Material.DIRT && block.getData() == (byte) 1) { // plugin.getLogger().info("1.8 " + "DEBUG: hitting coarse dirt!"); e.setCancelled(true); } } }
Example 11
Source File: ATM.java From TimeIsMoney with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onInteract(PlayerInteractEvent e) { if (e.getClickedBlock() != null) { if (e.getClickedBlock().getState() instanceof Sign) { Sign sign = (Sign) e.getClickedBlock().getState(); if (sign.getLine(0).equalsIgnoreCase(CC("&cATM"))) { if (!e.getPlayer().hasPermission("tim.atm.use")) { e.getPlayer().sendMessage(CC(Main.finalconfig.getString("message_atm_noperms"))); } else { this.openGUI(e.getPlayer()); } } } } }
Example 12
Source File: PlayerListener.java From ObsidianDestroyer with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); ItemStack inHand = player.getItemInHand(); // They no longer throw the interact event if the player is in creative, so lets do right click. if (inHand == null || event.getAction() != Action.RIGHT_CLICK_BLOCK || !event.hasBlock() || !player.hasPermission("obsidiandestroyer.check")) { return; } Material type = inHand.getType(); Block block = event.getClickedBlock(); if (!ConfigManager.getInstance().getDurabilityCheckItem().equals(type)) { return; } MaterialManager mm = MaterialManager.getInstance(); if (block != null && mm.getDurabilityEnabled(block.getType().name())) { int amount = ChunkManager.getInstance().getMaterialDurability(block); double mult = Util.getMultiplier(block.getLocation()); if (mult == 0) { player.sendMessage(ConfigManager.getInstance().getDurabilityMessage().replace("{DURABILITY}", "∞")); } else { int max = (int) Math.round(mm.getDurability(block.getType().name(), block.getData()) * Util.getMultiplier(block.getLocation())); player.sendMessage(ConfigManager.getInstance().getDurabilityMessage().replace("{DURABILITY}", !mm.isDestructible(block.getType().name(), block.getData()) ? "∞" : (max - amount) + "/" + max)); } } }
Example 13
Source File: MailboxListener.java From NyaaUtils with MIT License | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onRightClickChest(PlayerInteractEvent ev) { if (callbackMap.containsKey(ev.getPlayer()) && ev.hasBlock() && ev.getAction() == Action.RIGHT_CLICK_BLOCK) { Block b = ev.getClickedBlock(); if (b.getType() == Material.CHEST || b.getType() == Material.TRAPPED_CHEST) { callbackMap.remove(ev.getPlayer()).accept(b.getLocation()); if (timeoutListener.containsKey(ev.getPlayer())) timeoutListener.remove(ev.getPlayer()).cancel(); ev.setCancelled(true); } } }
Example 14
Source File: EasyHarvestListener.java From MineTinker with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onHarvestTry(PlayerInteractEvent event) { if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { return; } Player player = event.getPlayer(); if (Lists.WORLDS_EASYHARVEST.contains(player.getWorld().getName())) { return; } if (!(player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE || player.getGameMode() == GameMode.CREATIVE)) { return; } ItemStack tool = player.getInventory().getItemInMainHand(); if (!ToolType.HOE.contains(tool.getType())) { return; } if (!modManager.isToolViable(tool)) { return; } if (event.getClickedBlock() == null) { return; } if (event.getItem() == null) { return; } Block block = event.getClickedBlock(); if (!(block.getBlockData() instanceof Ageable)) { return; } //triggers a pseudoevent to find out if the Player can build BlockPlaceEvent placeEvent = new BlockPlaceEvent(block, block.getState(), block, event.getItem(), player, true, EquipmentSlot.HAND); Bukkit.getPluginManager().callEvent(placeEvent); //check the pseudoevent if (!placeEvent.canBuild() || placeEvent.isCancelled()) { return; } harvestCrops(player, tool, block); }
Example 15
Source File: PlayerListener.java From MineTinker with GNU General Public License v3.0 | 4 votes |
/** * Updates the HashMap BLOCKFACE with the clicked face of the Block * * @param event PlayerInteractEvent */ @EventHandler(priority = EventPriority.LOW) public void onInteract(PlayerInteractEvent event) { if (Lists.WORLDS.contains(event.getPlayer().getWorld().getName())) { return; } if (!event.getBlockFace().equals(BlockFace.SELF)) { Lists.BLOCKFACE.replace(event.getPlayer(), event.getBlockFace()); } if (!modManager.allowBookToModifier()) { return; } if (event.getClickedBlock() == null || event.getClickedBlock().getType() != Material.BOOKSHELF) { return; } if (event.getItem() == null || event.getItem().getType() != Material.ENCHANTED_BOOK) { return; } if (event.getItem().getItemMeta() == null || !(event.getItem().getItemMeta() instanceof EnchantmentStorageMeta)) { return; } EnchantmentStorageMeta meta = (EnchantmentStorageMeta) event.getItem().getItemMeta(); for (Map.Entry<Enchantment, Integer> entry : meta.getStoredEnchants().entrySet()) { Modifier modifier = modManager.getModifierFromEnchantment(entry.getKey()); if (modifier == null) { continue; } ItemStack modDrop = modifier.getModItem(); modDrop.setAmount(entry.getValue()); event.getClickedBlock().getWorld().dropItem(event.getClickedBlock().getLocation(), modDrop); meta.removeStoredEnchant(entry.getKey()); } if (meta.getStoredEnchants().isEmpty()) { event.getPlayer().getInventory().removeItem(event.getItem()); } else { event.getItem().setItemMeta(meta); } }
Example 16
Source File: RepairEffect.java From Civs with GNU General Public License v3.0 | 4 votes |
@EventHandler(ignoreCancelled = true) public void onPlayerInteract(PlayerInteractEvent event) { if (event.getClickedBlock() == null || event.getHand() == null) { return; } if ((!event.getAction().equals(Action.RIGHT_CLICK_BLOCK) && !event.getAction().equals(Action.LEFT_CLICK_BLOCK)) || (!event.getClickedBlock().getType().equals(Material.IRON_BLOCK)) || event.getHand().equals(EquipmentSlot.HAND)) { return; } Region r = RegionManager.getInstance().getRegionAt(event.getClickedBlock().getLocation()); if (r == null || !r.getEffects().containsKey(KEY)) { return; } Player player = event.getPlayer(); ItemStack item = player.getInventory().getItemInMainHand(); ItemMeta itemMeta = item.getItemMeta(); if (!(itemMeta instanceof Damageable)) { return; } Damageable damageable = (Damageable) itemMeta; if (getRequiredReagent(item.getType()).isEmpty()) { return; } if (item.getType() == Material.AIR) { player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslationWithPlaceholders(player, "hold-repair-item")); return; } if (!damageable.hasDamage()) { return; } repairItem(event, player, item); }
Example 17
Source File: RegionInteractListener.java From NovaGuilds with GNU General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); if(event.getClickedBlock() == null) { return; } List<String> denyInteract = Config.REGION_DENYINTERACT.getStringList(); List<String> denyUse = Config.REGION_DENYUSE.getStringList(); String clickedBlockName = event.getClickedBlock().getType().name(); String usedItemName = (event.getItem() == null ? Material.AIR : event.getItem().getType()).name(); NovaRegion region = RegionManager.get(event.getClickedBlock()); if(region == null) { return; } NovaPlayer nPlayer = PlayerManager.getPlayer(player); NovaGuild guild = region.getGuild(); if(nPlayer.getPreferences().getBypass()) { return; } if(!denyInteract.contains(clickedBlockName) && !denyUse.contains(usedItemName)) { return; } if(nPlayer.hasGuild()) { if(guild.isMember(nPlayer)) { if(nPlayer.hasPermission(GuildPermission.INTERACT)) { if(event.getAction() != Action.RIGHT_CLICK_BLOCK || (!plugin.getGuildManager().isVaultBlock(event.getClickedBlock()) || nPlayer.hasPermission(GuildPermission.VAULT_ACCESS))) { return; } } } else if(guild.isAlly(nPlayer.getGuild()) && Config.REGION_ALLYINTERACT.getBoolean()) { return; } } event.setCancelled(true); if(clickedBlockName.contains("_PLATE")) { //Suppress for plates return; } Message.CHAT_REGION_DENY_INTERACT.send(player); }
Example 18
Source File: BlockListener.java From MineTinker with GNU General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onShovelUse(PlayerInteractEvent event) { Player player = event.getPlayer(); if (Lists.WORLDS.contains(player.getWorld().getName())) { return; } if (!(player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE)) { return; } ItemStack tool = player.getInventory().getItemInMainHand(); if (!ToolType.SHOVEL.contains(tool.getType())) { return; } if (!modManager.isToolViable(tool)) { return; } boolean apply = false; if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock() != null) { if (event.getClickedBlock().getType() == Material.GRASS_BLOCK) apply = true; Block b = player.getWorld().getBlockAt(event.getClickedBlock().getLocation().add(0, 1, 0)); if (b.getType() != Material.AIR && b.getType() != Material.CAVE_AIR) //Case Block is on top of clicked Block -> No Path created -> no Exp apply = false; } if (!apply) { return; } if (!modManager.durabilityCheck(event, player, tool)) { return; } modManager.addExp(player, tool, MineTinker.getPlugin().getConfig().getInt("ExpPerBlockBreak")); MTPlayerInteractEvent interactEvent = new MTPlayerInteractEvent(tool, event); Bukkit.getPluginManager().callEvent(interactEvent); }
Example 19
Source File: DropCrate.java From CratesPlus with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onPlayerInteract(PlayerInteractEvent event) { if (event.getClickedBlock() != null && event.getClickedBlock().getType() == getBlock() && drops.contains(event.getClickedBlock().getLocation())) { openCrate(event.getPlayer(), event.getClickedBlock().getLocation()); } }
Example 20
Source File: TNTSheepListener.java From BedwarsRel with GNU General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onInteract(PlayerInteractEvent event) { if (event.getAction().equals(Action.LEFT_CLICK_AIR) || event.getAction().equals(Action.LEFT_CLICK_BLOCK)) { return; } if (event.getPlayer() == null) { return; } Player player = event.getPlayer(); Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player); if (game == null) { return; } if (game.getState() != GameState.RUNNING && !game.isStopping()) { return; } TNTSheep creature = new TNTSheep(); if (!event.getMaterial().equals(creature.getItemMaterial())) { return; } if (game.isSpectator(player)) { return; } Location startLocation = null; if (event.getClickedBlock() == null || event.getClickedBlock().getRelative(BlockFace.UP).getType() != Material.AIR) { startLocation = player.getLocation().getBlock() .getRelative(Utils.getCardinalDirection(player.getLocation())).getLocation(); } else { startLocation = event.getClickedBlock().getRelative(BlockFace.UP).getLocation(); } creature.setPlayer(player); creature.setGame(game); creature.run(startLocation); event.setCancelled(true); }