.launchProjectile() Help

Discussion in 'Plugin Development' started by weirdo16, Jun 23, 2014.

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

    weirdo16

    Hi!

    I'm new to plugin development, and I'm trying to make a simple plugin that fires an arrow when you right click with a fishing rod. In Eclipse, I don't get any errors, it seems to compile into a .jar just fine, and it logs that it's enabled, but it doesn't work. Here's the code for the main class:

    Code:java
    1. package com.gmail.CENSORED.arrowgun;
    2.  
    3. import org.bukkit.plugin.java.JavaPlugin;
    4. //extra imports
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.Material;
    7. import org.bukkit.entity.Projectile;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.EventPriority;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.player.PlayerInteractEvent;
    13. import org.bukkit.entity.Arrow;
    14.  
    15. public final class arrowgun extends JavaPlugin {
    16. @Override
    17. public void onEnable() {
    18. getLogger().info("arrowgun is enabled!");
    19. }
    20. @Override
    21. public void onDisable() {
    22. getLogger().info("arrowgun is dead. :( ");
    23. }
    24. @EventHandler
    25. public void onPlayerInteractBlock(PlayerInteractEvent event) {
    26. Player player = event.getPlayer();
    27. if (player.getItemInHand().getType() == Material.FISHING_ROD) {
    28. player.launchProjectile(Arrow.class);
    29. }
    30. }
    31. }


    Anyone have any ideas as to why this isn't working? Thanks!
     
  2. Offline

    Bavestry

    weirdo16 Looks like your class doesn't implement the Listener interface:

    Code:java
    1. public final class arrowgun extends JavaPlugin implements Listener
    2. //this will allow you to listen for events in this class :p


    You also forgot to register your events in the onEnable method:

    Code:java
    1. getServer().getPluginManager().registerEvents(this, this);
    2. //this will register the events in this class, so the server knows where to find them!


    If you don't register your events, they won't be listened for, and you can't listen for events unless you've implemented the Listener interface. Check out the Event API Reference on the BukkitWiki for more information on this!
     
  3. Offline

    weirdo16

Thread Status:
Not open for further replies.

Share This Page