Listener Plugin Not Doing Anything

Discussion in 'Plugin Development' started by XDdrummer, Apr 10, 2014.

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

    XDdrummer

    I am making a plugin that will give players effects if they stand on certain blocks. My code is below. It is loading with no errors, and shows in /plugins, but the events are not working, as standing on the specified blocks give me no effect.

    I am indeed in a world with the specified name, and I am Op, so I have sufficient permissions.

    Any idea what I am doing wrong? I'm somewhat new to Bukkit.

    Update! Found an error, fixed it. Code still not working, but I am finding no stacktraces.

    Update! It was because I was doing == instead of .equals()! Thanks for the replies.

    Code:java
    1.  
    2. package plugin.XDdrummer.PowerUps;
    3.  
    4. import java.util.logging.Logger;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.Material;
    9. import org.bukkit.block.BlockFace;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.event.EventHandler;
    12. import org.bukkit.event.Listener;
    13. import org.bukkit.event.player.PlayerMoveEvent;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15. import org.bukkit.potion.PotionEffect;
    16. import org.bukkit.potion.PotionEffectType;
    17. import org.bukkit.util.Vector;
    18.  
    19. public class MCZPowerupsMain extends JavaPlugin implements Listener
    20. {
    21. Logger log = Bukkit.getLogger();
    22.  
    23. MCZPowerupsMain plugin;
    24.  
    25. @Override
    26. public void onEnable() {
    27. log.info("[MCZPowerups] Enabled MC-ZPowerups!");
    28. log.info("[MCZPowerups] Plugin in Beta!");
    29. this.getServer().getPluginManager().registerEvents(this, this);
    30.  
    31. this.saveConfig();
    32. }
    33.  
    34. @Override
    35. public void onDisable() {
    36. log.info("[MCZPowerups] Disabled MC-ZPowerups!");
    37. log.info("[MCZPowerups] Plugin in Beta!");
    38. }
    39.  
    40. @EventHandler
    41. public void onPlayerMove(PlayerMoveEvent ev) {
    42. Player p = ev.getPlayer();
    43. if(p.getLocation().getWorld().getName() == "world")
    44. {
    45. if(p.hasPermission("powerups.active")||p.isOp()) {
    46. Material block = p.getLocation().getBlock().getRelative(BlockFace.DOWN).getType();
    47.  
    48. if(block == Material.DIAMOND_BLOCK){
    49. PotionEffect diamondEffect = new PotionEffect(PotionEffectType.JUMP, 400, 3);
    50. PotionEffect diamondEffect2 = new PotionEffect(PotionEffectType.REGENERATION, 400, 3);
    51.  
    52. p.sendMessage(ChatColor.AQUA + "You received High Jump + Regeneration from Diamond Block!");
    53. p.addPotionEffect(diamondEffect);
    54. p.addPotionEffect(diamondEffect2);
    55.  
    56. Vector vector = new Vector(1, 1, 0);
    57. p.setVelocity(vector);
    58. }else if(block == Material.EMERALD_BLOCK) {
    59. PotionEffect emeraldEffect = new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 400, 3);
    60. PotionEffect emeraldEffect2 = new PotionEffect(PotionEffectType.NIGHT_VISION, 400, 3);
    61.  
    62. p.sendMessage(ChatColor.GREEN + "You received Strength + Night Vision from Emerald Block!");
    63. p.addPotionEffect(emeraldEffect);
    64. p.addPotionEffect(emeraldEffect2);
    65.  
    66. Vector vector = new Vector(1, 1, 0);
    67. p.setVelocity(vector);
    68. }else if(block == Material.GOLD_BLOCK) {
    69. PotionEffect goldEffect = new PotionEffect(PotionEffectType.SPEED, 400, 3);
    70. PotionEffect goldEffect2 = new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 400, 3);
    71.  
    72. p.sendMessage(ChatColor.YELLOW + "You received Speed + Fire Resistance from Gold Block!");
    73. p.addPotionEffect(goldEffect);
    74. p.addPotionEffect(goldEffect2);
    75.  
    76. Vector vector = new Vector(1, 1, 0);
    77. p.setVelocity(vector);
    78. }else if(block == Material.BEACON) {
    79. PotionEffect beaconEffect = new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 1200, 5);
    80. PotionEffect beaconEffect2 = new PotionEffect(PotionEffectType.BLINDNESS, 600, 5);
    81.  
    82. p.sendMessage(ChatColor.BOLD + "You received Damage Resistance from Beacon, in exchange for 30 seconds of your vision!");
    83. p.addPotionEffect(beaconEffect);
    84. p.addPotionEffect(beaconEffect2);
    85.  
    86. Vector vector = new Vector(1, 1, 0);
    87. p.setVelocity(vector);
    88. }else{}
    89. }
    90. }
    91. if(p.getLocation().getWorld().getName() == "")
    92. {
    93. if(p.hasPermission("powerups.liquid")||p.isOp())
    94. {
    95. Material liquid = p.getLocation().getBlock().getType();
    96. Material liquidPlayerIsIn =p.getLocation().getBlock().getRelative(BlockFace.UP).getType();
    97.  
    98. if((liquid == Material.WATER)||(liquid == Material.STATIONARY_WATER))
    99. {
    100. PotionEffect waterEffect = new PotionEffect(PotionEffectType.CONFUSION, 600, 1);
    101. PotionEffect waterEffect2 = new PotionEffect(PotionEffectType.HUNGER, 200, 1);
    102.  
    103. p.sendMessage(ChatColor.RED + "The water is poisonous!");
    104. p.addPotionEffect(waterEffect);
    105. p.addPotionEffect(waterEffect2);
    106. }else if((liquid == Material.LAVA)||(liquid == Material.STATIONARY_LAVA))
    107. {
    108. PotionEffect lavaEffect = new PotionEffect(PotionEffectType.WEAKNESS, 100, 1);
    109.  
    110. p.sendMessage(ChatColor.RED + "The burning lava weakens you!");
    111. p.addPotionEffect(lavaEffect);
    112. }else{}
    113.  
    114. if((liquidPlayerIsIn == Material.WATER)||(liquidPlayerIsIn == Material.STATIONARY_WATER))
    115. {
    116. p.setRemainingAir(0);
    117. p.sendMessage(ChatColor.BLUE + "The water is too dirty to breathe in!");
    118. }else{}
    119. }
    120. }
    121. }
    122. }
    123.  
    124.  
     
  2. Offline

    Shadowwolf97

    Check that your plugin is being enabled successfully when the server starts.
     
  3. Offline

    XDdrummer

    Shadowwolf97 There are no errors, it simply says it was enabled.
     
  4. Offline

    Zethariel

    Strings should never be checked with == in Java. Use equals();
     
  5. Offline

    Shadowwolf97

    Didn't even catch that! Good find. You could also use equalsIgnorCase(); too.
     
  6. Offline

    XDdrummer

    Thanks! I knew it was related to that world line, as it worked when I removed it. I'll re-add it, in the proper format!
    :D
     
Thread Status:
Not open for further replies.

Share This Page