Solved Help?

Discussion in 'Plugin Development' started by superj, Jun 29, 2015.

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

    superj

    I am new to coding for bukkit and I can not figure out why this is not working?? All i want is for when a player rightclicks with a blazerod it shoots an arrow out of their inventory.

    Code:
    package me.superj.wand2;
    
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.Material;
    import org.bukkit.event.block.Action;
    import org.bukkit.entity.Arrow;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerInteractEvent;
    
    public class Main extends JavaPlugin {
      
        public void onEnable() {
            System.out.println("Wand has been enabled.");}
        public void onPlayerUse(PlayerInteractEvent event) {
            final Player player = event.getPlayer();
               if (player.getItemInHand().getType() == Material.BLAZE_ROD && event.getAction() == Action.RIGHT_CLICK_AIR) {
        if(player.getInventory().contains(Material.ARROW)) {
            player.launchProjectile(Arrow.class);
    }
    }
    }
    }
    [​IMG]
     
  2. @FisheyLP And he forgot about indentation and what final means.
     
  3. @bwfcwalshy final wouldn't cause any issues here, though. It's just not really necessary.
     
    Konato_K and KingFaris11 like this.
  4. Offline

    superj

    So all I need to do it put in the
    @EventHandler

    Code:
    getServer().getPluginManager().registerEvents(Listener, Plugin);
    I am confused on how to add a listener plugin?
     
  5. You need to make your class implement Listener, e.g.
    Code:
    public class Main extends JavaPlugin implements Listener {
    
    Then you do:
    Code:
    this.getServer().getPluginManager().registerEvents(this, this);
    In onEnable().

    Why does this work? Because the first parameter asks for a Listener, which is your Main class instance (as it implements Listener), and the second parameter asks for a Plugin, which is your Main class instance too (as it extends JavaPlugin which extends PluginBase which implements Plugin).
     
  6. Offline

    tytwining

    @superj I think the best advice I can give you is to look up Java and Bukkit tutorials. With your current knowledge we will have to basically write out all of the code for you and most of the users here will not and should not do that.
     
  7. Offline

    superj

    alright, will do. Thanks for the hep everyone.
     
  8. Offline

    Tecno_Wizard

    @superj Please mark this as solved.
     
Thread Status:
Not open for further replies.

Share This Page