Hide a Player From Monster?

Discussion in 'Plugin Development' started by suckycomedian, Sep 15, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    suckycomedian

    I know how to hide a player from players, but how do you do the same with monsters? This is what I have for players
    Code:
    for(Player players : Bukkit.getOnlinePlayers()){
                    players.hidePlayer(event.getPlayer());
                }
    I was trying something like this for monsters but I can't do .hidePlayer
    Code:
    for(Entity ent : event.getPlayer().getWorld().getEntities()){
     
  2. Offline

    zippy120

    You could try adding a potion effect to the entity

    Code:
    PotionEffect effect = new PotionEffect(PotionEffectType.INVISIBILITY, /*A Duration*/, /*An Amplifier*/);
    effect.apply(entity);
     
    
     
  3. Offline

    libraryaddict

    Use the target event.

    Get the target event, Then cancel it.
     
  4. Offline

    suckycomedian

    Ok thanks :)

    I used this
    Code:
    public void noSee(EntityTargetLivingEntityEvent event){
            Player target = (Player) event.getTarget();
            if(target instanceof Player){
                if(plugin.invisible.contains(target.getName().toLowerCase())){
                    event.setCancelled(true);
                }
            }
    And it works except for with spiders lol... Do you know what's wrong?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  5. Offline

    libraryaddict

    I'd do that like this.
    You are also using the wrong event?

    Only slimes don't fire this event :\

    Code:
      public void noSee(EntityTargetEvent event) {
        if (event.getTarget() instanceof Player) {
          Player target = (Player) event.getTarget();
          if (plugin.invisible.contains(target.getName().toLowerCase())) {
            event.setCancelled(true);
          }
        }
      ]
     
Thread Status:
Not open for further replies.

Share This Page