Event not activating

Discussion in 'Spigot Plugin Development' started by TheGamerPlayz, May 26, 2016.

  1. I have registered the event and everything, button when I activate the event it is not activating anyone see why?

    Code (Java):

    public class Main extends JavaPlugin{
        public static Plugin pl;
        AllPlayers ap = new AllPlayers();
        data d = new data(this);
        public void onEnable(){
            pl = this;
        public static void registerEvents(org.bukkit.plugin.Plugin plugin, Listener... listeners) {
            for (Listener listener : listeners){
                Bukkit.getServer().getPluginManager().registerEvents(listener, plugin);
        public void registerCommands(){
            getCommand("arena").setExecutor(new arena(this));
        public void config(){
            File file = new File(getDataFolder(), "config.yml");
    Code (Java):

    public class ButtonPress implements Listener{
        Main pl;
        public ButtonPress(Main pl){
            this.pl = pl;
        public void buttonClick(PlayerInteractEvent event){
            if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
                    Block bttn = event.getClickedBlock();
                    Player p = event.getPlayer();
                    data d = new data(pl);
                    FileConfiguration data = d.getConfig();
                    String button1 = data.getString("button1");
                    String[] b1 = button1.split(", ");
                    String button2 = data.getString("button1");
                    String[] b2 = button2.split(", ");
                    String button3 = data.getString("button1");
                    String[] b3 = button3.split(", ");
                    String button4 = data.getString("button1");
                    String[] b4 = button4.split(", ");
                    String button5 = data.getString("button1");
                    String[] b5 = button5.split(", ");
                    String button6 = data.getString("button1");
                    String[] b6 = button6.split(", ");
                        List<String> list = new ArrayList<String>();
                        if(bttn.getX() == Integer.parseInt(b1[0]) &&
                                bttn.getY() == Integer.parseInt(b1[1]) && bttn.getX() == Integer.parseInt(b1[2])){
                            for(PotionEffect e : p.getActivePotionEffects()){
                            p.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1));
                            p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 1));
                            data.set("Assassin.players", list);
                            p.sendMessage(ChatColor.GOLD + "You chose the Assasin Class!");
                        } else if(bttn.getX() == Integer.parseInt(b2[0]) &&
                                bttn.getY() == Integer.parseInt(b2[1]) && bttn.getX() == Integer.parseInt(b2[2])){
                        } else if(bttn.getX() == Integer.parseInt(b3[0]) &&
                                bttn.getY() == Integer.parseInt(b3[1]) && bttn.getX() == Integer.parseInt(b3[2])){
                        } else if(bttn.getX() == Integer.parseInt(b4[0]) &&
                                bttn.getY() == Integer.parseInt(b4[1]) && bttn.getX() == Integer.parseInt(b4[2])){
                        } else if(bttn.getX() == Integer.parseInt(b5[0]) &&
                                bttn.getY() == Integer.parseInt(b5[1]) && bttn.getX() == Integer.parseInt(b5[2])){
                        } else if(bttn.getX() == Integer.parseInt(b6[0]) &&
                                bttn.getY() == Integer.parseInt(b6[1]) && bttn.getX() == Integer.parseInt(b6[2])){
  2. missing listeners in this code ?

    Code (Java):
    registerEvents(this, listeners);
    and add some @EventHandler quotation before the event so that it would work.
  3. I added an EventHandler, but it is still not working also it is being registered in the for loop in the main
  4. any error ?
  5. annotation*

    You aren't using your #registerEvents method correctly, you aren't passing any instances of Listener's into the method itself, which, along with the msising annotation, is why your events aren't running. If you copied the method from somewhere else, register them the basic way until you can figure out how to work the ... array syntax.
  6. Thanks for correcting and thanks for more infos.
    • Friendly Friendly x 1
  7. I have been making them this same way for about 2 months, so how can this be the problem?
  8. try changing it to this at your registerEvents method

    (MainClass plugin)
  9. You only pass your Main plugin instance, you don't pass any listeners along into the method. There's no way that everything worked properly if you were calling them exactly this way every time you have done them.
  10. The for loop gets all classes that implements Listener so its not that
    • Optimistic Optimistic x 1
  11. Are you getting any red line in the registering for the class listener you made for the event? I think your registering ways doing this problem.
  12. No. It doesn't.
    • Agree Agree x 2
  13. Just do
    Code (Text):
    Bukkit.getServer().registerEvents(this, Listener);
    It's way more simple and works evry tiem.
  14. public static void registerEvents(org.bukkit.plugin.Plugin plugin, Listener... listeners){
    for(Listener listener : listeners){
    Bukkit.getServer().getPluginManager().registerEvents(listener, plugin);

    Why why why why.. And may I ask from who you are learning Java/Spigot etc? This code gives me a headache.
    • Agree Agree x 1
  15. Don't think the static will give any problems in this context though. However I do agree with you that people who don't know what they're doing often also start using it at places where it would cause problems. But I agree, it looks like shit.
  16. Yeah I agree but to be honest, his code gives me a alot of headache.
    • Agree Agree x 1
  17. Everyone's coding style is different. Yes, it may give you headaches, but no need to fret.
    For example, you might code like this:
    Code (Text):
    public static Player getPlayer()
    return Player;
    While I might.
    Code (Text):
    public static Player getPlayer() {
    return Player;
    It all depends on whats easier for you.
  18. Code style is something entirely different than illogical confusing code that starters will use to teach their selves something even worse.
  19. That code wasn't illogical, or confusing. He isn't using it correctly, he took someone else's and tried using it for himself, incorrectly. Listener... is a way of writing an array to where you pass in arguments, without creating the array yourself. It's not confusing, it may be a less widely used method, but it's not hard to comprehend.
    • Agree Agree x 1
  20. "This code looks like shit"
    "Do you even know Java"
    "This code gives me headaches"
    Well if you don't want me coding like this then actually do something and tell me whats wrong and how to fix it don't just complain.
    • Friendly Friendly x 1