Weird bug

Discussion in 'Plugin Development' started by W&L-Craft, Jul 30, 2014.

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

    W&L-Craft

    Hello, i was testing a new version of my plugin "iRevenge" and i suddenly found a bug
    I have 6 types of revenges that a player can choose from but for some reason when he choose for example poison it will also do the confusion and hellhound revenge :(

    This is the part of the code where there is (probably) something wrong:
    Code:java
    1.  
    2. @EventHandler
    3. public void PlayerDeath(PlayerDeathEvent e){
    4. Player killer = e.getEntity().getKiller();
    5. if(killer instanceof Player){
    6. }else{
    7. return;
    8. }
    9.  
    10. Player p = e.getEntity();
    11. World w = p.getWorld();
    12. Location victim = p.getLocation();
    13. EntityType wolf = EntityType.WOLF;
    14.  
    15. //Explosion revenge
    16. if(this.getConfig().getBoolean("explosion") == true)
    17. if(explosion.contains(p.getName()))
    18. if(p.hasPermission("irevenge.*") || p.hasPermission("irevenge.explosion"))
    19. w.createExplosion(victim, 1);
    20.  
    21. //Poison revenge
    22. if(this.getConfig().getBoolean("poison") == true)
    23. if(poison.contains(p.getName()))
    24. if(p.hasPermission("irevenge.*") || p.hasPermission("irevenge.poison"))
    25. killer.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 200, 1));
    26.  
    27. //Confusion revenge
    28. if(this.getConfig().getBoolean("confusion") == true)
    29. if(confusion.contains(p.getName()))
    30. if(p.hasPermission("irevenge.*") || p.hasPermission("irevenge.confusion"));
    31. killer.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 500, 1));
    32.  
    33. //Hellhound revenge
    34. if(this.getConfig().getBoolean("hellhound") == true)
    35. if(hellhound.contains(p.getName()))
    36. if(p.hasPermission("irevenge.*") || p.hasPermission("irevenge.hellhound"))
    37. p.sendMessage(ChatColor.GREEN+"[iRevenge]"+ChatColor.AQUA +"The hellhound revenge does not work properly");
    38. w.spawnCreature(victim, wolf);
    39. //TODO: Spawn wolf that targets killer
    40.  
    41. //launch revenge
    42. if(this.getConfig().getBoolean("launch") == true)
    43. if(launch.contains(p.getName()))
    44. if(p.hasPermission("irevenge.*") || p.hasPermission("irevenge.launch")){
    45. killer.setVelocity(new Vector(killer.getVelocity().getX(), 2, killer.getVelocity().getZ()));
    46. killer.sendMessage(ChatColor.GREEN +"Woooosh!");
    47. }
    48.  
    49. //Creeper revenge
    50. if(this.getConfig().getBoolean("creeper") == true)
    51. if(creeper.contains(p.getName()));
    52. if(p.hasPermission("irevenge.*") || p.hasPermission("irevenge.creeper"))
    53. return;
    54. w.spawnCreature(victim, EntityType.CREEPER);
    55. }
    56.  


    Thanks in advance
     
    ClassyInvader69 likes this.
  2. Offline

    ClassyInvader69

    Its probably that the booleans are also true for confusion and hellhound. Try turning the boolean to false.
     
  3. Offline

    techboy291

    On line 30 you put a semi-colon after the if statement. That makes it useless, and the code executed after it,

    Code:
    killer.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 500, 1));
    
    executes regardless of if the if statement returns true or not.

    The if statement at line 36 doesn't have curly braces around the code after it, meaning only

    Code:
    p.sendMessage(ChatColor.GREEN+"[iRevenge]"+ChatColor.AQUA +"The hellhound revenge does not work properly");
    
    executes, not

    Code:
    w.spawnCreature(victim, wolf);
    
     
Thread Status:
Not open for further replies.

Share This Page