Java Code Examples for org.bukkit.event.player.PlayerInteractAtEntityEvent#getPlayer()

The following examples show how to use org.bukkit.event.player.PlayerInteractAtEntityEvent#getPlayer() . 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: 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 3
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 4
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 5
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))));
}