NEED HELP! Getting multiple listeners to work

Discussion in 'Plugin Development' started by Bust_Open, Aug 31, 2012.

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

    Bust_Open

    Final out come

    onPlayerInteract.java
    Code:
    package info.epscraft;
     
    import org.bukkit.ChatColor;
    import org.bukkit.GameMode;
    import org.bukkit.Material;
    import org.bukkit.entity.Fireball;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
     
    public class onPlayerInteract implements Listener{
        public onPlayerInteract(PlayerInteractEvent event) {
    Player p = event.getPlayer();
            ItemStack item = event.getItem();
            if (Material.BLAZE_ROD.equals(item)) {
          event.getAction().equals(Action.RIGHT_CLICK_AIR);
                item.getType().equals(Material.BLAZE_ROD);
              p.sendMessage(ChatColor.YELLOW+"You fired a fireball, need help? type: /bhelp for help!");
              p.launchProjectile(Fireball.class);
              if (p.getGameMode().equals(GameMode.SURVIVAL)) {
              if (item.getAmount() == 1) {
                            event.getPlayer().getInventory().remove(item);
              } else
                            item.setAmount(item.getAmount() - 1);
                    }
            } else if (Material.PAPER.equals(item)) {
          event.getAction().equals(Action.RIGHT_CLICK_AIR);
    item.getType().equals(Material.PAPER);
    if(p.getHealth()>=19)
    {
    p.sendMessage(ChatColor.AQUA+"I feel much better...");
    p.setHealth(20);
    if (p.getGameMode().equals(GameMode.SURVIVAL)) {
          if (item.getAmount() == 1) {
                      event.getPlayer().getInventory().remove(item);
          } else
                        item.setAmount(item.getAmount() - 1);
                }
    }
    else
    {
    p.setHealth(event.getPlayer().getHealth() + 1);
    p.sendMessage(ChatColor.AQUA+"I feel much better...");
    if (p.getGameMode().equals(GameMode.SURVIVAL)) {
          if (item.getAmount() == 1) {
                      event.getPlayer().getInventory().remove(item);
          } else
                        item.setAmount(item.getAmount() - 1);
                }
    }
    }
    }
        }
    
    How do I register the event? though???

    on the main class "package info.epscraft;

    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    public class Blazewand extends JavaPlugin implements Listener{
    public void onEnable(){
    getServer().getPluginManager().registerEvents(new onPlayerInteract(), this);
    }
    }
    "
    I'm getting a constructor onPlayerInteraction is undefined?
    How do I define it or fix that problem?
     
  2. Offline

    sternmin8or

    You are naming your listener method the same as your constructor. just name it something else. You also might want to look into java naming conventions. Generally classes are capitol (call your class something like ClickListener)
     
  3. Offline

    Bust_Open

    right so changing the class name will solve this issue?
     
  4. Offline

    Courier

    That is one of your problems. You also need to add "@EventHandler" before the method. There might be other problems; didn't look.
     
  5. Offline

    Bust_Open

    this is a constant... you don't need that

    I recommend you read the java documentation before posting unhelpful noobish comments, thanks.
     
  6. Offline

    sternmin8or

    You do realize that you couldnt figure out that you named your constructor the same as one of your listener methods... you arent in any place to be calling someone noobish.

    Edit: in case you didn't notice, i strongly frown upon insulting people who are trying to help you
     
  7. Offline

    Bust_Open

    Frown upon me all that you want, doesn't mean that anythings going to change nor am I even going to care.
     
  8. Offline

    Courier

    This is a constant?
    It is actually a constructor, dumbass. You intended for it to be a method.

    I don't really have any recommendations for you; you cannot be a successful person with that attitude.
     
  9. Offline

    ZeusAllMighty11

    Actually, your remark was quite 'noobish' and 'dumbass'-ey? as well...


    He meant this as in
    PluginManager.registerEvents(this, this);
     
  10. Offline

    Courier

    If he did mean this as in a reference to the current object, then his comment makes no sense in response to mine. My initial post was valid, as far as I can see. I only took that tone in my followup because he was a jerk to sternmin8or and me, and he did not have an attitude open to learning.

    IMHO, you shouldn't ask a question if you don't care to learn.
     
    ZeusAllMighty11 likes this.
  11. Offline

    sternmin8or

    Just because I noticed that I didnt really state it clearly in any of my previous posts. You do need an @EventHandler tag in front of all event methods (unless something has changed that I am unaware of)... It's what marks them as events
     
Thread Status:
Not open for further replies.

Share This Page