Splash Potion Issues

Discussion in 'Plugin Development' started by maxben34, Nov 14, 2013.

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

    maxben34

    I'm writing a code that gets the effected entities of a potion and gives them a random effect. Currently nothing is happening for some reason. I don't seem to know why. ( Yes i registered events. No, there aren't any stack traces.)

    Code:
    Code:java
    1.  
    2. Player p = (Player) e.getPotion().getShooter();
    3. if (e.getAffectedEntities() instanceof Player && Madman.contains(p)) {
    4. final DisguiseCraftAPI api = DisguiseCraft.getAPI();
    5. for(final LivingEntity effected : e.getAffectedEntities()){
    6. Random r = new Random();
    7. int rand = r.nextInt(100);
    8. if (rand >= 90) {
    9. api.disguisePlayer((Player) effected, new Disguise(api.newEntityID(), DisguiseType.Zombie));
    10. ((LivingEntity) effected).addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 15 * 20, 0));
    11. ((Player)effected).sendMessage(ChatColor.GOLD + "You lucked out and got transformed into a Zombie by the Madman!");
    12. p.sendMessage(ChatColor.RED + "Potion gone wrong! You have created Zombies!");
    13. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    14. public void run() {
    15. api.undisguisePlayer((Player) effected);
    16. ((Player)effected).sendMessage(ChatColor.GOLD + "You have been returned to normal!");
    17. }
    18. }, 15 * 20);
    19. } else if (rand >= 80) {
    20. api.disguisePlayer(((Player) effected), new Disguise(api.newEntityID(), DisguiseType.Villager));
    21. effected.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 8 * 20, 50));
    22. ((Player)effected).sendMessage(ChatColor.GOLD + "You are not very lucky, you were transformed into a Villager by the Madman!");
    23. p.sendMessage(ChatColor.GREEN + "Potion applied successfully! You have created Villagers!");
    24. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    25. public void run() {
    26. api.undisguisePlayer((Player) effected);
    27. ((Player)effected).sendMessage(ChatColor.GOLD + "You have been returned to normal!");
    28. }
    29. }, 8 * 20);
    30. }else if (rand >=70) {
    31. effected.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 20 * 20, 1));
    32. ((Player)effected).sendMessage(ChatColor.GOLD + "You are not very lucky, you were given Weakness II by the Madman!");
    33. p.sendMessage(ChatColor.GREEN + "Potion applied successfully! You have given them weakness II!");
    34. }else if (rand >=60) {
    35. effected.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 20 * 20, 0));
    36. effected.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 20 * 20, 0));
    37. ((Player)effected).sendMessage(ChatColor.GOLD + "You lucked out and got Speed and Regeneration from the Madman!");
    38. p.sendMessage(ChatColor.RED + "Potion gone wrong! You have given them speed and regeneration I!");
    39. }else if (rand >=50) {
    40. p.sendMessage(ChatColor.RED+ "Potion gone wrong! Nothing happend!");
    41. ((Player)effected).sendMessage(ChatColor.GOLD + "You lucked out and got no effects from the Madman!");
    42. }else if (rand >=40) {
    43. api.disguisePlayer(((Player) effected), new Disguise(api.newEntityID(), DisguiseType.IronGolem));
    44. effected.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 15 * 20, 1));
    45. effected.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 15 * 20, 1));
    46. ((Player)effected).sendMessage(ChatColor.GOLD + "You have nuteural luck! You have been transformed into an Iron Golum by the Madman!");
    47. p.sendMessage(ChatColor.GOLD + "Potion is Nuteural! You have created Iron Golums!");
    48. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    49. public void run() {
    50. api.undisguisePlayer((Player) effected);
    51. ((Player)effected).sendMessage(ChatColor.GOLD + "You have been returned to normal!");
    52. }
    53. }, 15 * 20);
    54. }else if (rand >=30) {
    55. api.disguisePlayer((Player) effected, new Disguise(api.newEntityID(), DisguiseType.Snowman));
    56. effected.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 20 * 20, 0));
    57. ((HumanEntity) effected).getInventory().addItem(new ItemStack(Material.SNOW_BALL, 16));
    58. ((Player)effected).sendMessage(ChatColor.GREEN + "You lucked out and got transformed into a Snowman by the Madman!");
    59. p.sendMessage(ChatColor.RED + "Potion gone wrong! You have created Snowmen!");
    60. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    61. public void run() {
    62. api.undisguisePlayer((Player) effected);
    63. ((Player)effected).sendMessage(ChatColor.GOLD + "You have been returned to normal!");
    64. }
    65. }, 20 * 20);
    66. }else if (rand >=20) {
    67. ((Player) effected).setLevel(((Player) effected).getLevel() + 5);
    68. ((Player)effected).sendMessage(ChatColor.GOLD + "You lucked out and got 5 levels from the Madman!");
    69. p.sendMessage(ChatColor.RED + "Potion gone wrong! You have given them 5 levels!");
    70. }else if (rand >=10) {
    71. ((Player) effected).setLevel(((Player) effected).getLevel() + 5);
    72. ((Player)effected).sendMessage(ChatColor.GOLD + "You are not lucky and have been transformed into a Skeleton with no bow! by the Madman!");
    73. effected.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 10 * 20, -1));
    74. p.sendMessage(ChatColor.GREEN + "Potion applied successfully! They are now a Skeleton!");
    75. api.disguisePlayer((Player) effected, new Disguise(api.newEntityID(), DisguiseType.Skeleton));
    76. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    77. public void run() {
    78. api.undisguisePlayer((Player) effected);
    79. ((Player)effected).sendMessage(ChatColor.GOLD + "You have been returned to normal!");
    80. }
    81. }, 10 * 20);
    82. }else{
    83. effected.teleport(c);
    84. ((Player)effected).sendMessage(ChatColor.GOLD + "You lucked out and got tp'ed to the capture point by the Madman!");
    85. p.sendMessage(ChatColor.RED + "Potion gone wrong! You have tp'ed them to the capture point!");
    86. }
    87. }
    88. }
    89. }
     
  2. Offline

    RealDope

    You're casting things unsafely (for instance, Player to effected without ever checking)

    The real problem though is that you're checking if
    Code:JAVA
    1.  
    2. if(e.getAffectedEntities() instanceof Player) {
    3.  
    4. }
    5.  

    This makes no sense. How could a list of entities ever be an instance of Player?
     
  3. Offline

    maxben34

    That's true. I'll try that. Thanks.
     
Thread Status:
Not open for further replies.

Share This Page