Java Code Examples for org.spongepowered.api.event.entity.InteractEntityEvent#getTargetEntity()
The following examples show how to use
org.spongepowered.api.event.entity.InteractEntityEvent#getTargetEntity() .
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: PlayerInteractListener.java From EagleFactions with MIT License | 6 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onEntityInteract(final InteractEntityEvent event, @Root final Player player) { final Entity targetEntity = event.getTargetEntity(); final Optional<Vector3d> optionalInteractionPoint = event.getInteractionPoint(); if((targetEntity instanceof Living) && !(targetEntity instanceof ArmorStand)) return; final Vector3d blockPosition = optionalInteractionPoint.orElseGet(() -> targetEntity.getLocation().getPosition()); final Location<World> location = new Location<>(targetEntity.getWorld(), blockPosition); boolean canInteractWithEntity = super.getPlugin().getProtectionManager().canInteractWithBlock(location, player, true).hasAccess(); if(!canInteractWithEntity) { event.setCancelled(true); return; } }
Example 2
Source File: InteractPermListener.java From Nations with MIT License | 5 votes |
@Listener(order=Order.FIRST, beforeModifications = true) public void onInteract(InteractEntityEvent event, @First Player player) { if (!ConfigHandler.getNode("worlds").getNode(player.getWorld().getName()).getNode("enabled").getBoolean()) { return; } if (player.hasPermission("nations.admin.bypass.perm.interact")) { return; } Entity target = event.getTargetEntity(); if (target instanceof Player || target instanceof Monster) { return; } if (target instanceof ItemFrame || target instanceof ArmorStand) { if (player.hasPermission("nations.admin.bypass.perm.build")) { return; } if (!DataHandler.getPerm("build", player.getUniqueId(), event.getTargetEntity().getLocation())) { event.setCancelled(true); player.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_BUILD)); } return; } if (!DataHandler.getPerm("interact", player.getUniqueId(), event.getTargetEntity().getLocation())) { event.setCancelled(true); player.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_INTERACT)); } }
Example 3
Source File: EntityListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onAttemptInteractAS(InteractEntityEvent e, @First Player p) { Entity ent = e.getTargetEntity(); Location<World> l = ent.getLocation(); Region r = RedProtect.get().rm.getTopRegion(l, this.getClass().getName()); if (r == null) { //global flags if (ent.getType().equals(EntityTypes.ARMOR_STAND)) { if (!RedProtect.get().config.globalFlagsRoot().worlds.get(l.getExtent().getName()).build) { e.setCancelled(true); return; } } return; } ItemType itemInHand = RedProtect.get().getVersionHelper().getItemInHand(p); if (!itemInHand.equals(ItemTypes.NONE) && itemInHand.getType().equals(ItemTypes.ARMOR_STAND)) { if (!r.canBuild(p)) { e.setCancelled(true); RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbuild"); return; } } //TODO Not working! if (ent.getType().equals(EntityTypes.ARMOR_STAND)) { if (!r.canBuild(p)) { if (!RedProtect.get().ph.hasPerm(p, "redprotect.bypass")) { RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantedit"); e.setCancelled(true); } } } }