Help with a boomstick/thor plugin

Discussion in 'Plugin Development' started by dmoney12321, Nov 26, 2013.

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

    dmoney12321

    Hey guys,
    Trying to make a plugin that will create an explosion at where a block was clicked... But no explosion or lightning happens? Here is the code:
    Code:java
    1. package me.Dmoney12321.Boomstick;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Location;
    5. import org.bukkit.Material;
    6. import org.bukkit.World;
    7. import org.bukkit.block.Block;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.player.PlayerInteractEvent;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class Boomstick extends JavaPlugin implements Listener{
    15. public static Boomstick plugin;
    16.  
    17. @EventHandler
    18. public void onPlayerInteract(PlayerInteractEvent event) {
    19. Player player = event.getPlayer();
    20. if(player.getItemInHand().getType() == Material.STICK);{
    21. Block block = event.getClickedBlock();
    22. Location loc = block.getLocation();
    23. World world = player.getWorld();
    24. world.createExplosion(loc, 5);
    25. player.sendMessage(ChatColor.GOLD + "You used Boomstick!");
    26. }
    27. if(player.getItemInHand().getType() == Material.BONE);{
    28. Block block = event.getClickedBlock();
    29. Location loc = block.getLocation();
    30. World world = player.getWorld();
    31. world.strikeLightning(loc);
    32. player.sendMessage(ChatColor.GOLD + "You used LightStick");
    33. }
    34. }
    35. }
    36.  

    Please help me, but also tell me what i did so i can learn :)
     
  2. Offline

    The_Coder

    Did you register your listener?
     
  3. Offline

    dmoney12321

  4. Offline

    calebbfmv

    dmoney12321
    OK some things:
    Is this your main class?
    If so: You haven't registered the event or even the plugin.
    If not:
    Did you register the event:
    As well as, you don't need to extend JavaPlugin except in the main class, as well as creating a static instance of the plugin.
    Try those and come back if it doesn't work.
     
  5. Offline

    The_Coder

    dmoney12321
    You have to register your listener like so:
    public void onEnable() {
    getServer().getPluginManager().registerEvents(new LoginListener(), this);
    }
     
  6. Offline

    dmoney12321

    calebbfmv
    This is the main class
    Isnt that what the @EventHandler part does? And what do you mean register the plugin?
     
  7. Offline

    The_Coder

  8. Offline

    dmoney12321

    The_Coder
    How do i change it it a block clicked listener instead of login listener?
     
  9. Offline

    The_Coder

    dmoney12321
    @EventHandler tells bukkit that the method is an event. Registering the event tells bukkit that there is an event in your class.
     
  10. Offline

    calebbfmv

    PlayerInteracctEvent and checking if the action == Acction.RIGHT_CLICK_BLOCK
     
Thread Status:
Not open for further replies.

Share This Page