org.bukkit.event.player.PlayerInteractAtEntityEvent Java Examples

The following examples show how to use org.bukkit.event.player.PlayerInteractAtEntityEvent. 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 vote down vote up
@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: BookOfSoulsEmptyCI.java    From NBTEditor with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onInteractAtEntity(final PlayerInteractAtEntityEvent event, PlayerDetails details) {
	if (EntityNBT.isValidType(event.getRightClicked().getType())) {
		details.consumeItem();
		Player player = event.getPlayer();
		long tNow = System.currentTimeMillis();
		long t = tNow;
		// prevent spam while holding the mouse button
		if (player.hasMetadata("BookOfSoulsEmptyCI-Time")) {
			t = player.getMetadata("BookOfSoulsEmptyCI-Time").get(0).asLong();
		}
		if (tNow >= t) {
			player.getInventory().addItem((new BookOfSouls(EntityNBT.fromEntity(event.getRightClicked()))).getBook());
			player.setMetadata("BookOfSoulsEmptyCI-Time", new FixedMetadataValue(getPlugin(), tNow + 500));
		}
		event.setCancelled(true);
	}
}
 
Example #3
Source File: Compat18.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@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 #4
Source File: IslandGuard1_8.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #5
Source File: PlayerInteractEntityListener.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onInteractEntity(PlayerInteractAtEntityEvent e) {
    if (!e.getRightClicked().isValid()) {
        return;
    }

    ItemStack itemStack;

    if (e.getHand() == EquipmentSlot.OFF_HAND) {
        itemStack = e.getPlayer().getInventory().getItemInOffHand();
    }
    else {
        itemStack = e.getPlayer().getInventory().getItemInMainHand();
    }

    SlimefunItem sfItem = SlimefunItem.getByItem(itemStack);

    if (sfItem != null && Slimefun.hasUnlocked(e.getPlayer(), sfItem, true)) {
        sfItem.callItemHandler(EntityInteractHandler.class, handler -> handler.onInteract(e.getPlayer(), e.getRightClicked(), itemStack, e.getHand() == EquipmentSlot.OFF_HAND));
    }
}
 
Example #6
Source File: ExprClicked.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
	clickable = ClickableType.getClickable(parseResult.mark);
	switch (clickable) {
		case BLOCK_AND_ITEMS:
			final Object type = exprs[0] == null ? null : ((Literal<?>) exprs[0]).getSingle();
			if (type instanceof EntityData) {
				entityType = (EntityData<?>) type;
				if (!ScriptLoader.isCurrentEvent(PlayerInteractEntityEvent.class) && !ScriptLoader.isCurrentEvent(PlayerInteractAtEntityEvent.class)) {
					Skript.error("The expression 'clicked entity' may only be used in a click event", ErrorQuality.SEMANTIC_ERROR);
					return false;
				}
			} else {
				itemType = (ItemType) type;
				if (!ScriptLoader.isCurrentEvent(PlayerInteractEvent.class)) {
					Skript.error("The expression 'clicked block' may only be used in a click event", ErrorQuality.SEMANTIC_ERROR);
					return false;
				}
			}
			break;
		case INVENTORY:
		case ACTION:
		case TYPE:
		case SLOT:
			if (!ScriptLoader.isCurrentEvent(InventoryClickEvent.class)) {
				Skript.error("The expression '" + clickable.getName() + "' may only be used in an inventory click event", ErrorQuality.SEMANTIC_ERROR);
				return false;
			}
			break;
	}
	return true;
}
 
Example #7
Source File: CustomItemListener.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
private void playerInteractAtEntity(PlayerInteractAtEntityEvent event) {
	Player player = event.getPlayer();
	ItemStack item = player.getInventory().getItemInMainHand();
	CustomItem customItem = CustomItemManager.getCustomItem(item);

	if (customItem != null) {
		if (verifyCustomItem(customItem, event.getPlayer(), false)) {
			event.setCancelled(true);
			customItem.onInteractAtEntity(event, new PlayerDetails(item, event.getPlayer()));
		}
	}
}
 
Example #8
Source File: CreativeModeListener.java    From ShopChest with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent e) {
    // Cancel any entity interactions if SelectClickType is set
    ClickType clickType = ClickType.getPlayerClickType(e.getPlayer());
    if (clickType instanceof SelectClickType)
        e.setCancelled(true);
}
 
Example #9
Source File: IslandGuard1_9.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #10
Source File: ExtendEventExecutor.java    From PlayerSQL with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler(priority = LOWEST)
public void pre(PlayerInteractAtEntityEvent event) {
    handle(event);
}
 
Example #11
Source File: PlayerListenerTest.java    From AuthMeReloaded with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void shouldCancelPlayerInteractAtEntityEvent() {
    withServiceMock(listenerService)
        .check(listener::onPlayerInteractAtEntity, PlayerInteractAtEntityEvent.class);
}
 
Example #12
Source File: PlayerListener.java    From AuthMeReloaded with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) {
    if (listenerService.shouldCancelEvent(event)) {
        event.setCancelled(true);
    }
}
 
Example #13
Source File: ObserverModule.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler
public void PlayerInteractAtEntityEvent(PlayerInteractAtEntityEvent event) {
    if (testObserverOrDead(event.getPlayer())) {
        event.setCancelled(true);
    }
}
 
Example #14
Source File: EventFilterMatchModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onArmorStandInteract(final PlayerInteractAtEntityEvent event) {
  cancelUnlessInteracting(event, event.getPlayer());
}
 
Example #15
Source File: ExtendEventExecutor.java    From PlayerSQL with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = HIGHEST)
public void handle(PlayerInteractAtEntityEvent event) {
    if (manager.isLocked(event.getPlayer().getUniqueId())) {
        event.setCancelled(true);
    }
}
 
Example #16
Source File: EntityListener.java    From BedwarsRel with GNU General Public License v3.0 4 votes vote down vote up
@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))));
}
 
Example #17
Source File: NPCInteractions.java    From EliteMobs with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void playerNPCInteract(PlayerInteractAtEntityEvent event) {

    NPCEntity npcEntity = EntityTracker.getNPCEntity(event.getRightClicked());
    if (npcEntity == null) return;
    if (npcEntity.getIsSleeping()) return;

    event.setCancelled(true);

    switch (npcEntity.getInteractionType()) {
        case GUILD_GREETER:
            if (event.getPlayer().hasPermission("elitemobs.adventurersguild"))
                new BukkitRunnable() {
                    @Override
                    public void run() {
                        AdventurersGuildGUI.mainMenu(event.getPlayer());
                    }
                }.runTaskLater(MetadataHandler.PLUGIN, 1);
            break;
        case CHAT:
            npcEntity.sayDialog(event.getPlayer());
            break;
        case CUSTOM_SHOP:
            if (event.getPlayer().hasPermission("elitemobs.customshop"))
                new BukkitRunnable() {
                    @Override
                    public void run() {
                        CustomShopHandler.CustomShopHandler(event.getPlayer());
                    }
                }.runTaskLater(MetadataHandler.PLUGIN, 1);

            break;
        case PROCEDURALLY_GENERATED_SHOP:
            if (event.getPlayer().hasPermission("elitemobs.shop"))
                new BukkitRunnable() {
                    @Override
                    public void run() {
                        new ShopHandler(event.getPlayer());
                    }
                }.runTaskLater(MetadataHandler.PLUGIN, 1);
            break;
        case BAR:
            break;
        case ARENA:
            break;
        case NONE:
            break;

    }

}
 
Example #18
Source File: EnvironmentControlListener.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void interactAtEntity(PlayerInteractAtEntityEvent event) {
    event.setCancelled(true);
}
 
Example #19
Source File: EventFilterMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onArmorStandInteract(final PlayerInteractAtEntityEvent event) {
    cancelUnlessInteracting(event, event.getPlayer());
}
 
Example #20
Source File: CustomItem.java    From NBTEditor with GNU General Public License v3.0 votes vote down vote up
public void onInteractAtEntity(PlayerInteractAtEntityEvent event, PlayerDetails details) { }