Invisibility Potion, customize effect

Discussion in 'Plugin Development' started by hutattedonmyarm, Nov 6, 2012.

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

    hutattedonmyarm

    Hi there,
    first I need to know whenever invisibility potion gets applied (Through PotionSplashEvent and PlayerInteractEvent I assume) and then I'd like to make the player invisible (like the potion does) but NOT to Admins (= players with a certain permission).
    I have no idea how to make it happen that the effect only applies to certain players.
    If nothing else helps, I'd block the effect and vanish the player, but that's not exactly what I want
     
  2. Offline

    fireblast709

    hutattedonmyarm for splash potions
    Code:java
    1. @EventHandler
    2. public void onSplash(PotionSplashEvent event)
    3. {
    4. ThrownPotion potion = event.getEntity();
    5. for(PotionEffect effect : potion.getEffects())
    6. {
    7. if(effect.getType() == PotionEffectType.INVISIBILITY)
    8. {
    9. Collection<LivingEntity> les = event.getAffectedEntities(); // To prevent the concurrent exception
    10. final ArrayList<String> unaffected = new ArrayList<String>();
    11. for(LivingEntity le : les)
    12. {
    13. if(le instanceof Player)
    14. {
    15. if(((Player)le).hasPermission("no.invis.perm"))
    16. {
    17. unaffected.add(((Player)le).getName());
    18. }
    19. }
    20. }
    21. if(unaffected.size() > 0)
    22. {
    23. Bukkit.getScheduler().scheduleSyncDelayedTask(ReplaceWithMainClassInstance, new Runnable()
    24. {
    25. @Override
    26. public void run()
    27. {
    28. for(String name : unaffected)
    29. {
    30. Player p = Bukkit.getPlayer(name);
    31. if(p != null)
    32. {
    33. p.removePotionEffect(PotionEffectType.INVISIBILITY);
    34. }
    35. }
    36. }
    37. }, 1L);
    38. }
    39. }
    40. }
    41. }

    And for normal potions:
    Code:java
    1. @EventHandler
    2. public void onUse(PlayerInteractEvent event)
    3. {
    4. Action a = event.getAction();
    5. final Player p = event.getPlayer();
    6. ItemStack i = event.getItem();
    7. if(!(a == Action.RIGHT_CLICK_AIR || a == Action.RIGHT_CLICK_BLOCK) || i.getType() != Material.POTION
    8. || !p.hasPermission("no.invis.permission"))
    9. {
    10. return;
    11. }
    12. Potion potion = Potion.fromItemStack(i);
    13. for(PotionEffect effect : potion.getEffects())
    14. {
    15. if(effect.getType() == PotionEffectType.INVISIBILITY)
    16. {
    17. Bukkit.getScheduler().scheduleSyncDelayedTask(ReplaceWithMainClassInstance, new Runnable()
    18. {
    19. @Override
    20. public void run()
    21. {
    22. p.removePotionEffect(PotionEffectType.INVISIBILITY);
    23. }
    24. }, 1L);
    25. break;
    26. }
    27. }
    28. }
     
    hutattedonmyarm likes this.
  3. Offline

    hutattedonmyarm

    Thanks, will have to test it tomorrow!
    EDIT: Okay, I took a look at it. I don't think it does what I need :( I want the player to be invisible to other players (no matter what perms they have) but still visible to admins.
     
  4. Offline

    hutattedonmyarm

  5. Offline

    fireblast709

    no real implementation to do this potion-wise. I tried looking at packets to find a packet where you could simulate the effect, but it had no effect
     
  6. Offline

    hutattedonmyarm

    Okay, thanks. Looks like I need to find another way... Maybe block the effect, but vanish the player or something like this...
     
  7. Offline

    fireblast709

    would probably be possible (and probably the only way?). Though I do not know if I might accidently tried on a 1.3.2 server, and invisibility was implemented at 1.4.2. Im off for the weekend, so could anyone else try for me? (its Packet41MobEffect for the ones that are willing to test, use CB.jar)
     
  8. Offline

    drtshock

  9. Offline

    hutattedonmyarm

    Okay, I never looked into Packets, but I'm sure I can handle it ;)
    Nice, when I googled around the first thing I found was your plugin :p If it's somehow possible to do it, and you add it, I'd use your plugin ;)

    EDIT: Okay, I don't seem to be into packets... I tried this:
    Code:
    MobEffect m = new MobEffect(14, 200);
    ((CraftPlayer)p).getHandle().netServerHandler.sendPacket(new Packet41MobEffect(8, m));
    when entering a command, but nothing happens. It seems this isn't very well documented, had to go through the source on github, and I'm tired... So maybe tomorrow...
     
  10. Offline

    drtshock

  11. Offline

    hutattedonmyarm

    To be honest: I have no clue. I just wanted to see what happens if I send that package.
    Sorry, never worked with packets before :/
     
  12. Offline

    fireblast709

    hutattedonmyarm where the 8 is, replace entity.getEntityId(). Ill try tonight
     
  13. Offline

    hutattedonmyarm

    Okay, I wrote a short test-command that sent this package to the sender, but always with my ID.
    If I use it, the effect is displayed in my inventory and the countdown counts down (as soon as it reaches 0:00 it just stays there). My friend I was testing with still saw me.
    If he entered it, nothing at all happened.
     
  14. Offline

    fireblast709

    hutattedonmyarm Yes the staying means you would have to call another packet afterwards x.x, though I believe there is a way to get this done, so I am currently browsing through minecraft and minecraft_server code to see the code from the moment the client drinks the invis potion

    It is still weird that the potion is applied to the inventory, but not to the player... Anyone who can tell what is happening?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
Thread Status:
Not open for further replies.

Share This Page