Getting type of splash potion

Discussion in 'Plugin Development' started by GotChuNow, Jul 7, 2013.

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

    GotChuNow

    I'm trying to get which type of splash potion gets thrown in PotionSplashEvent, I have looked around and only found highly outdated posts which don't work anymore.
    What would be the best way to go about doing this (if it's possible, anyway)?
     
  2. Offline

    John Cameron

    GotChuNow
    Here is an example
    Code:
        @EventHandler(priority = EventPriority.NORMAL)
        public void PotionSplashEvent(org.bukkit.event.entity.PotionSplashEvent event){
            for(PotionEffect e : event.getPotion().getEffects()){
                if(e.getType() == PotionEffectType.POISON){
                    if(event.getPotion().getShooter() instanceof Player){
                        Player p = (Player) event.getPotion().getShooter();
                        p.sendMessage("Poison potions are disabled!");
                        event.setCancelled(true);
                    }
                }
            }
        }
    You just need to loop all the potion effects and see if it has the potion type to block.
     
  3. Offline

    GotChuNow

    John Cameron It's not working, the player still gets damaged. This is my code:
    Code:java
    1. @EventHandler(priority=EventPriority.HIGHEST)
    2. public void splashPotion(PotionSplashEvent event) {
    3.  
    4. if(event.getPotion().getShooter() instanceof Player) {
    5. for(LivingEntity entity : event.getAffectedEntities()) {
    6.  
    7. Player damager = (Player) event.getPotion().getShooter();
    8. if(entity instanceof Player) {
    9.  
    10. Player damagedPlr = (Player) entity;
    11.  
    12. if(damagedPlr == damager) {
    13. return;
    14. }
    15.  
    16. boolean allowPvP = plugin.getConfig().getBoolean("players."+ damagedPlr.getName() +".pvpOn");
    17.  
    18. for(PotionEffect effect : event.getPotion().getEffects()) {
    19. if(effect.getType() == PotionEffectType.POISON) {
    20. if(!allowPvP) {
    21. damager.sendMessage(ChatColor.GOLD + damagedPlr.getDisplayName() + ChatColor.DARK_AQUA + " has PvP disabled!");
    22. event.setCancelled(true);
    23. }
    24. }
    25. }
    26. }
    27. }
    28. }
    29. }
    30.  
     
  4. Offline

    John Cameron

    Error?
     
  5. Offline

    GotChuNow

    John Cameron No error, it just doesn't work, the player still gets poisoned.
     
  6. Offline

    iFamasssxD

    Seems like the allowPvP is set to false in the config so its not cancelling the event. Remove that then try and see if thats the issue.
     
  7. Offline

    GotChuNow


    iFamasssxD I checked it multiple times throughout testing it, and it was set to false (It should be set to false as that's what I'm trying to do; disable any harmful splash potions when PvP is off.
     
  8. Offline

    iFamasssxD

    Try adding debug messages to the class and see how far it gets.
     
  9. Offline

    GotChuNow

    iFamasssxD It gets to right before checking the effect.getType()
     
Thread Status:
Not open for further replies.

Share This Page