Java Code Examples for org.bukkit.event.player.PlayerInteractAtEntityEvent#getRightClicked()
The following examples show how to use
org.bukkit.event.player.PlayerInteractAtEntityEvent#getRightClicked() .
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: InteractListener.java From TradePlus with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onInteract(PlayerInteractAtEntityEvent event) { if (event.getRightClicked() instanceof Player) { Long last = lastTrigger.get(event.getPlayer().getUniqueId()); if (last != null && System.currentTimeMillis() < last + 5000L) return; Player player = event.getPlayer(); Player interacted = (Player) event.getRightClicked(); String action = pl.getConfig().getString("action", "").toLowerCase(); if ((action.contains("sneak") || action.contains("crouch") || action.contains("shift")) && !player.isSneaking()) return; if (action.contains("right")) { event.setCancelled(true); Bukkit.getPluginManager() .callEvent( new PlayerCommandPreprocessEvent( event.getPlayer(), "/trade " + interacted.getName())); lastTrigger.put(event.getPlayer().getUniqueId(), System.currentTimeMillis()); } } }
Example 2
Source File: Compat18.java From RedProtect with GNU General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) public void onAttemptInteractAS(PlayerInteractAtEntityEvent e) { Entity ent = e.getRightClicked(); Location l = ent.getLocation(); Region r = RedProtect.get().rm.getTopRegion(l); Player p = e.getPlayer(); if (r == null) { //global flags if (ent instanceof ArmorStand) { if (!RedProtect.get().config.globalFlagsRoot().worlds.get(l.getWorld().getName()).build) { e.setCancelled(true); return; } } return; } if (ent instanceof ArmorStand) { if (!r.canBuild(p)) { RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantedit"); e.setCancelled(true); } } }
Example 3
Source File: IslandGuard1_8.java From askyblock with GNU General Public License v2.0 | 6 votes |
/** * Handle interaction with armor stands V1.8 * Note - some armor stand protection is done in IslandGuard.java, e.g. against projectiles. * * @param e - event */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) public void onPlayerInteract(final PlayerInteractAtEntityEvent e) { if (DEBUG) { plugin.getLogger().info("1.8 " + e.getEventName()); } if (!IslandGuard.inWorld(e.getPlayer())) { return; } if (e.getRightClicked() != null && e.getRightClicked().getType().equals(EntityType.ARMOR_STAND)) { if (actionAllowed(e.getPlayer(), e.getRightClicked().getLocation(), SettingsFlag.ARMOR_STAND)) { return; } e.setCancelled(true); Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected); } }
Example 4
Source File: IslandGuard1_9.java From askyblock with GNU General Public License v2.0 | 5 votes |
/** * Handle interaction with end crystals 1.9 * * @param e - event */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) public void onHitEndCrystal(final PlayerInteractAtEntityEvent e) { if (!IslandGuard.inWorld(e.getPlayer())) { return; } if (e.getPlayer().isOp()) { return; } // This permission bypasses protection if (VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) { return; } if (e.getRightClicked() != null && e.getRightClicked().getType().equals(EntityType.ENDER_CRYSTAL)) { // Check island Island island = plugin.getGrid().getIslandAt(e.getRightClicked().getLocation()); if (island == null && Settings.defaultWorldSettings.get(SettingsFlag.BREAK_BLOCKS)) { return; } if (island !=null) { if (island.getMembers().contains(e.getPlayer().getUniqueId()) || island.getIgsFlag(SettingsFlag.BREAK_BLOCKS)) { return; } } e.setCancelled(true); Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected); } }
Example 5
Source File: EntityListener.java From BedwarsRel with GNU General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.HIGH) public void onInteractEntity(PlayerInteractAtEntityEvent event) { if (event.getRightClicked() == null) { return; } Entity entity = event.getRightClicked(); Player player = event.getPlayer(); if (!player.hasMetadata("bw-addteamjoin")) { if (!(entity instanceof LivingEntity)) { return; } LivingEntity livEntity = (LivingEntity) entity; Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player); if (game == null) { return; } if (game.getState() != GameState.WAITING) { return; } Team team = game.getTeam(ChatColor.stripColor(livEntity.getCustomName())); if (team == null) { return; } game.playerJoinTeam(player, team); event.setCancelled(true); return; } List<MetadataValue> values = player.getMetadata("bw-addteamjoin"); if (values == null || values.size() == 0) { return; } event.setCancelled(true); TeamJoinMetaDataValue value = (TeamJoinMetaDataValue) values.get(0); if (!((boolean) value.value())) { return; } if (!(entity instanceof LivingEntity)) { player.sendMessage( ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel ._l(player, "errors.entitynotcompatible"))); return; } LivingEntity living = (LivingEntity) entity; living.setRemoveWhenFarAway(false); living.setCanPickupItems(false); living.setCustomName(value.getTeam().getChatColor() + value.getTeam().getDisplayName()); living.setCustomNameVisible( BedwarsRel.getInstance().getBooleanConfig("jointeam-entity.show-name", true)); if (living.getType().equals(EntityType.valueOf("ARMOR_STAND"))) { Utils.equipArmorStand(living, value.getTeam()); } player.removeMetadata("bw-addteamjoin", BedwarsRel.getInstance()); player.sendMessage(ChatWriter .pluginMessage( ChatColor.GREEN + BedwarsRel._l(player, "success.teamjoinadded", ImmutableMap.of("team", value.getTeam().getChatColor() + value.getTeam().getDisplayName() + ChatColor.GREEN)))); }