Registering Events

Discussion in 'Plugin Development' started by King_Amun_Ra, Mar 28, 2014.

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

    King_Amun_Ra

    I'm having problems with registering events in another class. I've never let another class implement the main and now its not letting me just normally register events for the class.
    Below is my event class and bellow that is my on enable


    Code:java
    1. public class event implements Listener{
    2.  
    3. public main plugin;
    4.  
    5. public event(main plugin)
    6. {
    7. this.plugin = plugin;
    8. }
    9.  
    10.  
    11. //For batarang
    12. public static ArrayList<String> BatThrow = new ArrayList<String>();
    13.  
    14. @EventHandler
    15. public void onPlayerUseofBatarang(PlayerInteractEvent e){
    16. final Player p = (Player) e.getPlayer();
    17.  
    18. if (!(e.getAction() == Action.RIGHT_CLICK_AIR)) return;
    19. if (!(e.getItem().getType() == Material.NETHER_STAR)) return;
    20.  
    21. new BukkitRunnable(){
    22. @Override
    23. public void run(){
    24. if (!(BatThrow.contains(p))){
    25. BatThrow.remove(p.getName());
    26. }
    27. }
    28. }.runTaskLater(plugin, 3 * 20);
    29.  
    30. //Run for checks
    31. if (BatThrow.contains(p.getName())) return;
    32. //if (!(p.getLocation().getWorld().getName().equalsIgnoreCase("empty2"))) return;
    33.  
    34. p.launchProjectile(Snowball.class);
    35.  
    36. p.playEffect(p.getLocation(), Effect.BLAZE_SHOOT, 2);
    37. BatThrow.add(p.getName());
    38. p.getInventory().clear();
    39. }
    40.  
    41. //End of Batarang
    42. }




    Code:
     public void onEnable(){
           
            new event (this);
           
              settings.setup(this);
           
              if (!setupEconomy() ) {
                  getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
                  getServer().getPluginManager().disablePlugin(this);
                  return;
              }
             
              Bukkit.getServer().getPluginManager().registerEvents(new signs(), this);
              //Bukkit.getServer().getPluginManager().registerEvents(new event(), this);
              new event (this);
             
        }
     
  2. Offline

    Gater12

    King_Amun_Ra
    You added a constructer to accept your class's instance. So you need to pass your main class's instance when creating a new event class.
     
  3. Offline

    King_Amun_Ra

    @Gater12
    Can you show me a example? I have a idea of what to do just want to make sure
     
  4. Offline

    Azubuso

    King_Amun_Ra
    Code:java
    1. public void onEnable() {
    2. Bukkit.getPluginManager().registerEvents(new event(this), this);
    3. }
     
  5. Offline

    King_Amun_Ra

    Azubuso
    That does not work look at the original post above
     
  6. Offline

    Azubuso

    King_Amun_Ra
    What? You passed an instance of your main class to your "event" class, therefor in your registering it must be "new event(THIS), this", or am I missing something?
     
  7. Offline

    King_Amun_Ra

    Azubuso
    I did do that and still nothing I also added this

    Code:
     event events = event.getInstance();
    as Gater12 suggested and still didn't work

    Does anyone know how to do this???

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page