Solved if statements not working

Discussion in 'Plugin Development' started by Ghilliedrone, Jul 24, 2013.

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

    Ghilliedrone

    Everything here looks okay but it will never execute. I've tried different kinds of ifs but they never seem to work.
    Code:java
    1. public class lightningwand extends JavaPlugin{
    2. public static lightningwand plugin;
    3.  
    4. public void onEnable(){
    5. getLogger().info("Lightning wand has been enabled!");
    6. }
    7. public void onDisable(){
    8. getLogger().info("Lightning wand has been disabled!");
    9. }
    10.  
    11. @EventHandler
    12. public void onPlayerInteract(PlayerInteractEvent event){
    13.  
    14. Player player = event.getPlayer();
    15. Block targetblock = player.getTargetBlock(null, 200);
    16. Location location = targetblock.getLocation();
    17. World world = player.getWorld();
    18. Action action = event.getAction();
    19.  
    20. if( action==Action.RIGHT_CLICK_AIR || action==Action.RIGHT_CLICK_BLOCK){
    21. if(player.getItemInHand().getType() == Material.BLAZE_ROD ){
    22. player.getInventory().getItemInHand().setAmount(player.getInventory().getItemInHand().getAmount()-1);
    23. world.strikeLightning(location);
    24. world.createExplosion(location, 3);
    25. }
    26. }
    27. }
    28. }

    Any help would be great
     
  2. Offline

    kabbage

    You have to register the class as a Listener.

    Make it implement Listener
    Code:
    public class lightningwand extends JavaPlugin implements Listener {
    and register the listener in onEnable
    Code:
    Bukkit.getServer().getPluginManager().registerEvents(this, this);
     
  3. Offline

    Ghilliedrone

    Thanks a lot!:)It works now
     
Thread Status:
Not open for further replies.

Share This Page