SignChangeEvent isn't registered

Discussion in 'Plugin Development' started by x3Undercoverx3, Dec 11, 2014.

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

    x3Undercoverx3

    I'm working on a SignShop Class for my Economy plugin but it doesn't register the Event...

    Here is the main class:

    Code:
    package me.F3M0.Economy;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Economy extends JavaPlugin {
    
       @Override
       public void onEnable() {
         System.out.println("[Econony] wird aktiviert...");
         registerCommands();
         registerEvents();
         System.out.println("[Economy] aktiviert!");
       }
    
       @Override
       public void onDisable() {
         System.out.println("Deaktiviere Economy!");
       }
    
       public void registerCommands() {
         EconomySystem cES = new EconomySystem(this);
         this.getCommand("money").setExecutor(cES);
       }
    
       public void registerEvents() {
         new ShopSigns(this);
       }
    
    }
    
    Here is the listener class:

    Code:
    package me.F3M0.Economy;
    
    import org.bukkit.Bukkit;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.SignChangeEvent;
    
    public class ShopSigns implements Listener {
    
       @SuppressWarnings("unused")
       private Economy plugin;
    
       public ShopSigns(Economy plugin) {
         this.plugin = plugin;
         Bukkit.getPluginManager().registerEvents(this, plugin);
       }
    
       @EventHandler
       public void onSignChangeBuy(SignChangeEvent e) {
         if(e.getLine(0).equalsIgnoreCase("[Buy]")) {
           e.setLine(0, "§1[Buy]");
         }
       }
    
    }
    
     
  2. @x3Undercoverx3 1. You do not need to print message in onEnable and onDisable, Bukkit does this for you.
    2. You should fix the package name - convention is to be in all lowercase.
    3. Try debugging the code - put a println statement as the first line in your event and see if it prints.
     
  3. Offline

    mine-care

    public void registerEvents() {
    new ShopSigns(this);
    }
    Hmm... try getServer().getPluginManager().registerEvents(new ShopSigns());
    ( thats what youre already doing but just try it :3 even if it makes no sense xD)
     
  4. These types of 'solutions' aren't really solutions and aren't helpful. Relevant quote:

     
    Rocoty likes this.
  5. @x3Undercoverx3 you are gonna need to make a "private Sign sign" and instead of "if(e.getLine(0).equalsIgnoreCase("[Buy]")){" use "if(sign.getLine(0).equalsIgnoreCase("[Buy]")){" after the setLine make sign.update();

    :D

    @x3Undercoverx3

    Here is what I mean:

    Code:
    package me.F3M0.Economy;
    
    import org.bukkit.Bukkit;
    import org.bukkit.block.Sign;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.SignChangeEvent;
    
    public class ShopSigns implements Listener {
    
        private Sign sign;
       
        @SuppressWarnings("unused")
           private Economy plugin;
        
           public ShopSigns(Economy plugin) {
             this.plugin = plugin;
             Bukkit.getPluginManager().registerEvents(this, plugin);
           }
        
           @EventHandler
           public void onSignChangeBuy(SignChangeEvent e) {
             if(sign.getLine(0).equalsIgnoreCase("[Buy]")) {
               sign.setLine(0, "§1[Buy]");
               sign.update();
             }
        
        }
    }
    
    You can also Enable the Listeners without using the registerCommands() and registerEvents()
    Also you are gonna need a Command Class which you can do all the commands on it!

    Here this will help you a lot:

    Code:
    package me.F3M0.Economy;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Economy extends JavaPlugin {
    
        @Override
           public void onEnable() {
             System.out.println("[Econony] wird aktiviert...");
             getCommand("money").setExecutor(new COMMANDCLASS()); //make sure to put your command class here!
             getServer().getPluginManager().registerEvents(new ShopSigns(), this);
             System.out.println("[Economy] aktiviert!");
           }
        
           @Override
           public void onDisable() {
             System.out.println("Deaktiviere Economy!");
           }
    }
    
     
    Last edited by a moderator: Dec 11, 2014
  6. @MrGriefer_HGTech Why on earth wouldn't you be able to get the sign text from the event? I'd say your one is less likely to work.

    As for the command and event registration... yes he could do it that way, but he doesn't have to do it that way.
     
    mythbusterma likes this.
  7. @AdamQpzm For me I use my method because it take less time and much easier! Well he can get the sign text from the event but he needs to update it.
     
  8. Offline

    mythbusterma

    @x3Undercoverx3

    For the sake of everyone here, please don't listen to @MrGriefer_HGTech , I don't think he knows how Java works.

    Anyway, your code looks okay thus far, other than the items Adam mentioned. Are you certain the plugin is being loaded on the server?
     
    AdamQpzm likes this.
  9. Offline

    mine-care

    @AdamQpzm Τrue dat but as i read few weeks ago on a thread, a guy actualy solved his prob this way :3 it makes 0 sense to me but.. what i know =)
     
  10. Offline

    mythbusterma

    @mine-care

    Regardless of whether or not it "worked," it's still not all correct and will cause later issues. Why in the world would a Sign be a property of an EventHandler? That doesn't make any sense (at least, not in this context).
     
    mine-care likes this.
  11. okay MR. @mythbusterma can you help me with my problem I posted it but no one helped me so can you help me!
    Here!
     
  12. @mine-care As I said, before, this is one of the problem with "false solutions". Because one accidentally fixes it with an unrelated change, one might go on to pose it as a real solution, when it's not, wasting everybody's time :)
     
    mythbusterma likes this.
  13. Offline

    mine-care

    AdamQpzm likes this.
  14. Offline

    Rocoty

    Your solution is destined to throw an NPE...How that is easier I cannot fathom.
     
    mythbusterma likes this.
Thread Status:
Not open for further replies.

Share This Page