Java Code Examples for org.bukkit.event.player.PlayerInteractEvent#hasBlock()
The following examples show how to use
org.bukkit.event.player.PlayerInteractEvent#hasBlock() .
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: NoCauldronWash.java From civcraft with GNU General Public License v2.0 | 6 votes |
@SuppressWarnings("deprecation") public void onInteract(PlayerInteractEvent event) { if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { if (!event.hasBlock()) { return; } BlockCoord bcoord = new BlockCoord(event.getClickedBlock()); if (ItemManager.getId(bcoord.getBlock()) == ItemManager.getId(Material.CAULDRON)) { event.getPlayer().updateInventory(); event.setCancelled(true); return; } } }
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: ChestListener.java From Shopkeepers with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.LOW) void onPlayerInteract(PlayerInteractEvent event) { // prevent opening shop chests if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; Block block = event.getClickedBlock(); if (event.hasBlock() && Utils.isChest(block.getType())) { Player player = event.getPlayer(); // check for protected chest if (!Utils.hasPermission(player, ShopkeepersAPI.BYPASS_PERMISSION)) { if (plugin.getProtectedChests().isChestProtected(block, player)) { // TODO always allow access to own shop chests, even if cancelled by other plugins? Log.debug("Cancelled chest opening by '" + player.getName() + "' at '" + Utils.getLocationString(block) + "': Protected chest"); event.setCancelled(true); } } } }
Example 4
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 5
Source File: GriefEvents.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onTrampling(PlayerInteractEvent event) { if (!tramplingEnabled || !plugin.getWorldManager().isSkyAssociatedWorld(event.getPlayer().getWorld())) { return; } if (event.getAction() == Action.PHYSICAL && !isValidTarget(event.getPlayer()) && event.hasBlock() && event.getClickedBlock().getType() == Material.FARMLAND ) { event.setCancelled(true); } }
Example 6
Source File: CannonListener.java From civcraft with GNU General Public License v2.0 | 5 votes |
@EventHandler(priority = EventPriority.NORMAL) public void onPlayerInteract(PlayerInteractEvent event) { if (!event.hasBlock()) { return; } try { bcoord.setFromLocation(event.getClickedBlock().getLocation()); Cannon cannon = Cannon.fireSignLocations.get(bcoord); if (cannon != null) { cannon.processFire(event); event.setCancelled(true); return; } cannon = Cannon.angleSignLocations.get(bcoord); if (cannon != null) { cannon.processAngle(event); event.setCancelled(true); return; } cannon = Cannon.powerSignLocations.get(bcoord); if (cannon != null) { cannon.processPower(event); event.setCancelled(true); return; } } catch (CivException e) { CivMessage.sendError(event.getPlayer(), e.getMessage()); event.setCancelled(true); } }
Example 7
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 8
Source File: ClaimSignListener.java From Guilds with MIT License | 4 votes |
@EventHandler public void onSignInteract(PlayerInteractEvent event) { if (!event.hasBlock()) return; Block block = event.getClickedBlock(); BlockState state = block.getState(); if (!(state instanceof Sign)) return; Sign sign = (Sign) state; Player player = event.getPlayer(); if (!sign.getLine(0).equalsIgnoreCase("[Guild Claim]")) return; if (!settingsManager.getProperty(ClaimSettings.CLAIM_SIGNS)) { guilds.getCommandManager().getCommandIssuer(player).sendInfo(Messages.CLAIM__SIGN_NOT_ENABLED); event.setCancelled(true); return; } Guild guild = guildHandler.getGuild(player); if (guild == null) { guilds.getCommandManager().getCommandIssuer(player).sendInfo(Messages.ERROR__NO_GUILD); return; } if (!guild.memberHasPermission(player, GuildRolePerm.CLAIM_LAND)) { guilds.getCommandManager().getCommandIssuer(player).sendInfo(Messages.ERROR__ROLE_NO_PERMISSION); return; } if (ClaimUtils.checkAlreadyExist(wrapper, guild)) { guilds.getCommandManager().getCommandIssuer(player).sendInfo(Messages.CLAIM__ALREADY_EXISTS); return; } if (guild.getBalance() < Double.valueOf(sign.getLine(2))) { guilds.getCommandManager().getCommandIssuer(player).sendInfo(Messages.CLAIM__SIGN_NOT_ENOUGH); return; } ClaimUtils.getClaim(wrapper, player, sign.getLine(1)).ifPresent(region -> { ICuboidSelection selection = ClaimUtils.getSelection(wrapper, player, region.getId()); wrapper.removeRegion(player.getWorld(), region.getId()); ClaimUtils.createClaim(wrapper, guild, selection); }); ClaimUtils.getGuildClaim(wrapper, player, guild).ifPresent(region -> { ClaimUtils.addOwner(region, guild); ClaimUtils.addMembers(region, guild); ClaimUtils.setEnterMessage(wrapper, region, settingsManager, guild); ClaimUtils.setExitMessage(wrapper, region, settingsManager, guild); }); player.getWorld().getBlockAt(block.getLocation()).breakNaturally(); guild.setBalance(guild.getBalance() - Double.valueOf(sign.getLine(2))); guilds.getCommandManager().getCommandIssuer(player).sendInfo(Messages.CLAIM__SIGN_BUY_SUCCESS); }
Example 9
Source File: SitListener.java From NyaaUtils with MIT License | 4 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onClickBlock(PlayerInteractEvent event) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.hasBlock() && !event.hasItem()) { Block block = event.getClickedBlock(); BlockFace face = event.getBlockFace(); if (face == BlockFace.DOWN || block.isLiquid() || !plugin.cfg.sit_blocks.contains(block.getType())) { return; } Block relative = block.getRelative(0, 1, 0); Player player = event.getPlayer(); if (messageCooldown.getIfPresent(player.getUniqueId()) != null) { return; } messageCooldown.put(player.getUniqueId(), true); if (!player.hasPermission("nu.sit") || !enabledPlayers.contains(player.getUniqueId()) || player.isInsideVehicle() || !player.getPassengers().isEmpty() || player.getGameMode() == GameMode.SPECTATOR || !player.isOnGround()) { return; } if (relative.isLiquid() || !(relative.isEmpty() || relative.isPassable())) { player.sendMessage(I18n.format("user.sit.invalid_location")); return; } Vector vector = block.getBoundingBox().getCenter().clone(); Location loc = vector.setY(block.getBoundingBox().getMaxY()).toLocation(player.getWorld()).clone(); for (SitLocation sl : plugin.cfg.sit_locations.values()) { if (sl.blocks != null && sl.x != null && sl.y != null && sl.z != null && sl.blocks.contains(block.getType().name())) { loc.add(sl.x, sl.y, sl.z); } } if (block.getBlockData() instanceof Directional) { face = ((Directional) block.getBlockData()).getFacing(); if (face == BlockFace.EAST) { loc.setYaw(90); } else if (face == BlockFace.WEST) { loc.setYaw(-90); } else if (face == BlockFace.NORTH) { loc.setYaw(0); } else if (face == BlockFace.SOUTH) { loc.setYaw(-180); } } else { if (face == BlockFace.WEST) { loc.setYaw(90); } else if (face == BlockFace.EAST) { loc.setYaw(-90); } else if (face == BlockFace.SOUTH) { loc.setYaw(0); } else if (face == BlockFace.NORTH) { loc.setYaw(-180); } else { loc.setYaw(player.getEyeLocation().getYaw()); } } for (Entity e : loc.getWorld().getNearbyEntities(loc, 0.5, 0.7, 0.5)) { if (e instanceof LivingEntity) { if (e.hasMetadata(metadata_key) || (e instanceof Player && e.isInsideVehicle() && e.getVehicle().hasMetadata(metadata_key))) { player.sendMessage(I18n.format("user.sit.invalid_location")); return; } } } Location safeLoc = player.getLocation().clone(); ArmorStand armorStand = loc.getWorld().spawn(loc, ArmorStand.class, (e) -> { e.setVisible(false); e.setPersistent(false); e.setCanPickupItems(false); e.setBasePlate(false); e.setArms(false); e.setMarker(true); e.setInvulnerable(true); e.setGravity(false); }); if (armorStand != null) { armorStand.setMetadata(metadata_key, new FixedMetadataValue(plugin, true)); if (armorStand.addPassenger(player)) { safeLocations.put(player.getUniqueId(), safeLoc); } else { armorStand.remove(); } } } }
Example 10
Source File: BukkitPlotListener.java From PlotMe-Core with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onPlayerInteract(PlayerInteractEvent event) { IPlayer player = plugin.wrapPlayer(event.getPlayer()); Location location = BukkitUtil.adapt(event.getClickedBlock().getLocation()); PlotMapInfo pmi = manager.getMap(location); if (player.hasPermission(PermissionNames.ADMIN_BUILDANYWHERE)) { return; } if (manager.isPlotWorld(location)) { Plot plot = manager.getPlot(location); if (plot == null) { player.sendMessage(api.C("CannotBuild")); event.setCancelled(true); } else if (!plot.getOwnerId().equals(event.getPlayer().getUniqueId())) { Optional<Plot.AccessLevel> member = plot.isMember(player.getUniqueId()); if (member.isPresent()) { if (member.get().equals(Plot.AccessLevel.TRUSTED)) { if (!api.getServerBridge().getOfflinePlayer(plot.getOwnerId()) .isOnline()) { if (event.hasBlock() && pmi.isProtectedBlock(event.getClickedBlock().getTypeId())) { if (!player.hasPermission("plotme.unblock." + event.getClickedBlock().getTypeId())) { player.sendMessage(api.C("CannotBuild")); event.setCancelled(true); return; } else { return; } } if (event.hasItem() && (pmi.isPreventedItem(String.valueOf(event.getItem().getTypeId())) || pmi .isPreventedItem(event.getItem().getTypeId() + ":" + event.getItem().getData()))) { if (!player.hasPermission("plotme.unblock." + event.getClickedBlock().getTypeId())) { player.sendMessage(api.C("CannotBuild")); event.setCancelled(true); } } } } } else { if (event.hasBlock() && pmi.isProtectedBlock(event.getClickedBlock().getTypeId())) { if (player.hasPermission("plotme.unblock." + event.getClickedBlock().getTypeId())) { return; } else { player.sendMessage(api.C("CannotBuild")); event.setCancelled(true); return; } } if (event.hasItem() && (pmi.isPreventedItem(String.valueOf(event.getItem().getTypeId())) || pmi.isPreventedItem( event.getItem().getTypeId() + ":" + event.getItem().getData()))) { if (!player.hasPermission("plotme.unblock." + event.getClickedBlock().getTypeId())) { player.sendMessage(api.C("CannotBuild")); event.setCancelled(true); } } } } } }