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

The following examples show how to use org.bukkit.event.player.PlayerInteractEntityEvent#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: TNTSheepListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onTNTSheepInteractOtherUser(PlayerInteractEntityEvent event) {
    Player player = event.getPlayer();
    if (Main.isPlayerInGame(player)) {
        GamePlayer gamePlayer = Main.getPlayerGameProfile(player);
        Game game = gamePlayer.getGame();

        Entity rightClicked = event.getRightClicked();
        Entity vehicle = rightClicked.getVehicle();
        List<SpecialItem> sheeps = game.getActivedSpecialItems(TNTSheep.class);
        for (SpecialItem item : sheeps) {
            if (item instanceof TNTSheep) {
                TNTSheep sheep = (TNTSheep) item;
                if (sheep.getEntity().equals(rightClicked) || sheep.getEntity().equals(vehicle)) {
                    event.setCancelled(true);
                    return;
                }
            }
        }
    }
}
 
Example 2
Source File: PlayerInteractListener.java    From IridiumSkyblock with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
    try {
        final Player player = event.getPlayer();
        final User user = User.getUser(player);
        final Entity rightClicked = event.getRightClicked();
        final Location location = rightClicked.getLocation();
        final IslandManager islandManager = IridiumSkyblock.getIslandManager();
        final Island island = islandManager.getIslandViaLocation(location);
        if (island == null) return;

        if (island.getPermissions(user).interact) return;

        event.setCancelled(true);
    } catch (Exception e) {
        IridiumSkyblock.getInstance().sendErrorMessage(e);
    }
}
 
Example 3
Source File: TNTSheepListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onTNTSheepInteractOtherUser(PlayerInteractEntityEvent event) {
    Player player = event.getPlayer();
    if (Main.isPlayerInGame(player)) {
        GamePlayer gamePlayer = Main.getPlayerGameProfile(player);
        Game game = gamePlayer.getGame();

        Entity rightClicked = event.getRightClicked();
        Entity vehicle = rightClicked.getVehicle();
        List<SpecialItem> sheeps = game.getActivedSpecialItems(TNTSheep.class);
        for (SpecialItem item : sheeps) {
            if (item instanceof TNTSheep) {
                TNTSheep sheep = (TNTSheep) item;
                if (sheep.getEntity().equals(rightClicked) || sheep.getEntity().equals(vehicle)) {
                    event.setCancelled(true);
                    return;
                }
            }
        }
    }
}
 
Example 4
Source File: StickInteractEvent.java    From StackMob-3 with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onStickInteract(PlayerInteractEntityEvent event){
    Player player = event.getPlayer();
    Entity entity = event.getRightClicked();
    if(!(entity instanceof Mob)){
        return;
    }
    if(event.getHand() != EquipmentSlot.HAND) {
        return;
    }
    if (sm.getStickTools().isStackingStick(player.getInventory().getItemInMainHand())) {
        if (player.isSneaking()) {
            sm.getStickTools().toggleMode(player);
        } else {
            if(!(StackTools.hasValidMetadata(player, GlobalValues.STICK_MODE))){
                player.setMetadata(GlobalValues.STICK_MODE, new FixedMetadataValue(sm, 1));
            }
            sm.getStickTools().performAction(player, entity);
        }
    }
}
 
Example 5
Source File: EntityListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onInteractEvent(PlayerInteractEntityEvent e) {
    RedProtect.get().logger.debug(LogLevel.ENTITY, "EntityListener - Is PlayerInteractEntityEvent");

    Player p = e.getPlayer();
    if (p == null) {
        return;
    }
    Location l = e.getRightClicked().getLocation();
    Region r = RedProtect.get().rm.getTopRegion(l);
    Entity et = e.getRightClicked();
    if (r != null && !r.canInteractPassives(p) && (et instanceof Animals || et instanceof Villager || et instanceof Golem || (et instanceof WaterMob && !r.canFish(p)))) {
        if (et instanceof Tameable) {
            Tameable tam = (Tameable) et;
            if (tam.isTamed() && tam.getOwner() != null && tam.getOwner().getName().equals(p.getName())) {
                return;
            }
        }
        e.setCancelled(true);
        RedProtect.get().lang.sendMessage(p, "entitylistener.region.cantinteract");
    }
}
 
Example 6
Source File: PetOwnerListener.java    From SonarPet with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
    Player p = event.getPlayer();
    Entity e = event.getRightClicked();
    if (p.getItemInHand() != null && p.getItemInHand().isSimilar(SelectorLayout.getSelectorItem())) {
        SelectorLayout.getSelectorMenu().showTo(p);
        event.setCancelled(true);
        return;
    }

    if (ReflectionUtil.getEntityHandle(e) instanceof IEntityPet) {
        IPet pet = ((IEntityPet) ReflectionUtil.getEntityHandle(e)).getPet();
        event.setCancelled(true);
        PetInteractEvent iEvent = new PetInteractEvent(pet, p, PetInteractEvent.Action.RIGHT_CLICK, false);
        EchoPet.getPlugin().getServer().getPluginManager().callEvent(iEvent);
        if (!iEvent.isCancelled()) {
            pet.getEntityPet().onInteract(p);
            return;
        }
    }
}
 
Example 7
Source File: PlayerListener.java    From BedwarsRel with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onInteractEntity(PlayerInteractEntityEvent iee) {
  Player p = iee.getPlayer();
  Game g = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(p);
  if (g == null) {
    return;
  }

  if (g.getState() == GameState.WAITING) {
    iee.setCancelled(true);
    return;
  }

  if (g.getState() == GameState.RUNNING) {
    this.inGameInteractEntity(iee, g, p);
  }
}
 
Example 8
Source File: VillagerInteractionListener.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
void onEntityInteract(PlayerInteractEntityEvent event) {
	if (!(event.getRightClicked() instanceof Villager)) return;
	Villager villager = (Villager) event.getRightClicked();

	if (plugin.isShopkeeper(villager)) return; // shopkeeper interaction is handled elsewhere
	Log.debug("Interaction with Non-shopkeeper villager ..");

	if (villager.hasMetadata("NPC")) {
		// ignore any interaction with citizens2 NPCs
		Log.debug("  ignoring (probably citizens2) NPC");
		return;
	}

	if (Settings.disableOtherVillagers) {
		// don't allow trading with other villagers
		event.setCancelled(true);
		Log.debug("  trade prevented");
	}

	// only trigger hiring for main-hand events:
	if (!NMSManager.getProvider().isMainHandInteraction(event)) return;

	if (Settings.hireOtherVillagers) {
		Player player = event.getPlayer();
		// allow hiring of other villagers
		Log.debug("  possible hire ..");
		if (this.handleHireOtherVillager(player, villager)) {
			// hiring was successful -> prevent normal trading
			Log.debug("    ..success (normal trading prevented)");
			event.setCancelled(true);
		} else {
			// hiring was not successful -> no preventing of normal villager trading
			Log.debug("    ..failed");
		}
	}
}
 
Example 9
Source File: VillagerListener.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onVillagerInteract(PlayerInteractEntityEvent event) {
    if (Main.isPlayerInGame(event.getPlayer())) {
        GamePlayer gPlayer = Main.getPlayerGameProfile(event.getPlayer());
        Game game = gPlayer.getGame();
        if (event.getRightClicked().getType().isAlive() && !gPlayer.isSpectator
                && gPlayer.getGame().getStatus() == GameStatus.RUNNING) {
            for (GameStore store : game.getGameStores()) {
                if (store.getEntity().equals(event.getRightClicked())) {
                    event.setCancelled(true);

                    BedwarsOpenShopEvent openShopEvent = new BedwarsOpenShopEvent(gPlayer.getGame(),
                            event.getPlayer(), store, event.getRightClicked());
                    Main.getInstance().getServer().getPluginManager().callEvent(openShopEvent);

                    if (openShopEvent.getResult() != Result.ALLOW) {
                        return;
                    }

                    Main.openStore(event.getPlayer(), store);
                    return;
                }
            }

        }
    }
}
 
Example 10
Source File: Listeners.java    From PlayerVaults with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onInteractEntity(PlayerInteractEntityEvent event) {
    Player player = event.getPlayer();
    EntityType type = event.getRightClicked().getType();
    if ((type == EntityType.VILLAGER || type == EntityType.MINECART) && PlayerVaults.getInstance().getInVault().containsKey(player.getUniqueId().toString())) {
        event.setCancelled(true);
    }
}
 
Example 11
Source File: MenuConvIO.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void playerInteractEntityEvent(PlayerInteractEntityEvent event) {
    if (event.getPlayer() != player) {
        return;
    }

    event.setCancelled(true);

    if (debounce) {
        return;
    }

    if (controls.containsKey(CONTROL.LEFT_CLICK)) {
        switch (controls.get(CONTROL.LEFT_CLICK)) {
            case CANCEL:
                if (!conv.isMovementBlock()) {
                    conv.endConversation();
                }
                debounce = true;
                break;
            case SELECT:
                conv.passPlayerAnswer(selectedOption + 1);
                debounce = true;
                break;
        case MOVE:
            break;
        default:
            break;
        }
    }
}
 
Example 12
Source File: EntityInspectorTool.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public  void onInteractEntity(PlayerInteractEntityEvent event, PlayerDetails details) {
	Player player = event.getPlayer();
	Entity entity = event.getRightClicked();
	if (EntityNBT.isValidType(entity.getType())) {
		EntityNBT entityNBT = EntityNBT.fromEntity(entity);
		player.sendMessage(ChatColor.YELLOW + "Information about " + EntityTypeMap.getName(entity.getType()) + "");
		for (NBTVariableContainer container : entityNBT.getAllVariables()) {
			player.sendMessage("" + ChatColor.LIGHT_PURPLE + ChatColor.ITALIC + container.getName() + ":");
			for (String name : container.getVariableNames()) {
				String value = container.getVariable(name).get();
				player.sendMessage("  " + ChatColor.AQUA + name + ": " + ChatColor.WHITE + (value != null ? value : ChatColor.ITALIC + "none"));
			}
		}
		player.sendMessage(ChatColor.YELLOW + "Extra information:");

		boolean extra = false;
		if (entityNBT.getEntityType() == EntityType.VILLAGER) {
			player.sendMessage("" + ChatColor.LIGHT_PURPLE + ChatColor.ITALIC + "Trades done:");
			int i = 1;
			for (VillagerOffersVariable.Offer offer : ((VillagerOffersVariable) entityNBT.getVariable("Offers")).getOffers()) {
				player.sendMessage("  " + ChatColor.AQUA + "trade " + i + ": " + ChatColor.WHITE + offer.uses);
				++i;
			}
			extra = true;
		}
		if (!extra) {
			player.sendMessage("none");
		}
		event.setCancelled(true);
	} else {
		player.sendMessage(ChatColor.RED + "Not a valid entity!");
	}
}
 
Example 13
Source File: PlayerInteractListener.java    From PetMaster with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
	if (shouldHandleEvent(event)) {
		Tameable tameable = (Tameable) event.getRightClicked();
		AnimalTamer currentOwner = tameable.getOwner();
		if (currentOwner == null || currentOwner.getName() == null) {
			return;
		}
		// Has the player clicked on one of his own pets?
		Player player = event.getPlayer();
		boolean isOwner = player.getUniqueId().equals(currentOwner.getUniqueId());
		// Retrieve new owner from the map and delete corresponding entry.
		Player newOwner = plugin.getSetOwnerCommand().collectPendingSetOwnershipRequest(player);
		// Has the player requested to free one of his pets?
		boolean freePet = plugin.getFreeCommand().collectPendingFreeRequest(player);

		// Cannot change ownership or free pet if not owner and no bypass permission.
		if ((newOwner != null || freePet) && !isOwner && !player.hasPermission("petmaster.admin")) {
			player.sendMessage(plugin.getChatHeader() + plugin.getPluginLang()
					.getString("not-owner", "You do not own this pet!").replace("PLAYER", player.getName()));
			return;
		}

		if (newOwner != null) {
			changeOwner(player, currentOwner, newOwner, tameable);
		} else if (freePet) {
			freePet(player, currentOwner, tameable);
		} else if ((displayToOwner || !isOwner) && player.hasPermission("petmaster.showowner")) {
			displayHologramAndMessage(player, currentOwner, tameable);
		}
	}
}
 
Example 14
Source File: TNTSheepListener.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onInteractOtherUser(PlayerInteractEntityEvent event) {
  if (event.getPlayer() == null) {
    return;
  }

  Player player = event.getPlayer();
  Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);

  if (game == null) {
    return;
  }

  if (game.getState() != GameState.RUNNING) {
    return;
  }

  if (event.getRightClicked() == null) {
    return;
  }

  if (event.getRightClicked() instanceof ITNTSheep) {
    event.setCancelled(true);
    return;
  }

  if (event.getRightClicked().getVehicle() != null
      && event.getRightClicked().getVehicle() instanceof ITNTSheep) {
    event.setCancelled(true);
    return;
  }
}
 
Example 15
Source File: ListenerEntities.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority= EventPriority.HIGH, ignoreCancelled=true)
public void onInteract(PlayerInteractEntityEvent e) {
    FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml");
    if(!config.getBoolean("prevent-entity-interaction")) return;

    Player player = e.getPlayer();
    ICombatManager manager = this.plugin.getCombatManager();
    if(!manager.isInCombat(player)) return;

    e.setCancelled(true);
    String message = this.plugin.getLanguageMessageColoredWithPrefix("cheat-prevention.no-entity-interaction");
    this.plugin.sendMessage(player, message);
}
 
Example 16
Source File: VillagerListener.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onVillagerInteract(PlayerInteractEntityEvent event) {
    if (Main.isPlayerInGame(event.getPlayer())) {
        GamePlayer gPlayer = Main.getPlayerGameProfile(event.getPlayer());
        Game game = gPlayer.getGame();
        if (event.getRightClicked().getType().isAlive() && !gPlayer.isSpectator
                && gPlayer.getGame().getStatus() == GameStatus.RUNNING) {
            for (GameStore store : game.getGameStores()) {
                if (store.getEntity().equals(event.getRightClicked())) {
                    event.setCancelled(true);

                    BedwarsOpenShopEvent openShopEvent = new BedwarsOpenShopEvent(gPlayer.getGame(),
                            event.getPlayer(), store, event.getRightClicked());
                    Main.getInstance().getServer().getPluginManager().callEvent(openShopEvent);

                    if (openShopEvent.getResult() != Result.ALLOW) {
                        return;
                    }

                    Main.openStore(event.getPlayer(), store);
                    return;
                }
            }

        }
    }
}
 
Example 17
Source File: CustomItemListener.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
private void playerInteractEntity(PlayerInteractEntityEvent 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.onInteractEntity(event, new PlayerDetails(item, event.getPlayer()));
		}
	}
}
 
Example 18
Source File: MilkingTaskType.java    From Quests with MIT License 4 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMilk(PlayerInteractEntityEvent event) {
    if (!(event.getRightClicked() instanceof Cow) || (event.getPlayer().getItemInHand().getType() != Material.BUCKET)) {
        return;
    }

    Player player = event.getPlayer();

    QPlayer qPlayer = QuestsAPI.getPlayerManager().getPlayer(player.getUniqueId(), true);
    QuestProgressFile questProgressFile = qPlayer.getQuestProgressFile();

    for (Quest quest : super.getRegisteredQuests()) {
        if (questProgressFile.hasStartedQuest(quest)) {
            QuestProgress questProgress = questProgressFile.getQuestProgress(quest);

            for (Task task : quest.getTasksOfType(super.getType())) {
                TaskProgress taskProgress = questProgress.getTaskProgress(task.getId());

                if (taskProgress.isCompleted()) {
                    continue;
                }

                int cowsNeeded = (int) task.getConfigValue("amount");

                int progressMilked;
                if (taskProgress.getProgress() == null) {
                    progressMilked = 0;
                } else {
                    progressMilked = (int) taskProgress.getProgress();
                }

                taskProgress.setProgress(progressMilked + 1);

                if (((int) taskProgress.getProgress()) >= cowsNeeded) {
                    taskProgress.setCompleted(true);
                }
            }
        }
    }
}
 
Example 19
Source File: LWCEntityInteractEvent.java    From Modern-LWC with MIT License 4 votes vote down vote up
public LWCEntityInteractEvent(PlayerInteractEntityEvent event, Entity entity, Set<String> actions) {
    super(ModuleLoader.Event.INTERACT_ENTITY, event.getPlayer());

    this.entity = entity;
    this.actions = actions;
}
 
Example 20
Source File: LWCProtectionInteractEntityEvent.java    From Modern-LWC with MIT License 4 votes vote down vote up
public LWCProtectionInteractEntityEvent(PlayerInteractEntityEvent event, Protection protection, Set<String> actions, boolean canAccess, boolean canAdmin) {
    super(ModuleLoader.Event.INTERACT_PROTECTION_ENTITY, event.getPlayer(), protection, canAccess, canAdmin);

    this.event = event;
    this.actions = actions;
}