.getConfig() in Listener

Discussion in 'Plugin Development' started by DoveDevic, Jul 22, 2013.

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

    DoveDevic

    I've went through many posts about the topic, with the usual code
    Code:
        private <my plugins name> plugin;
        public PlayerListener(<my plugins name> instance){
            plugin = instance;
            }
    but i always get red underlining under PlayerListener to end for the reason of "Return type for the method is missing". Ive tried just using
    Code:
    private <my plugins name> plugin; 
    but when i start the plugin, i get thrown errors... Please help me out here. Here's my classes.
    Listener:
    Code:
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    public class <myPlugin>Listener implements Listener{
        private <myPlugin> plugin;
        public PlayerListener(<myPlugin> instance){
            plugin = instance;
            }
        @EventHandler
        public void join(PlayerJoinEvent event){
            Player p = event.getPlayer();
            if (<myPlugin>.getConfig().contains(p.getName())){
                this.getConfig().createSection(p.getName());
                this.getConfig().createSection(p.getName());
                System.out.println("Registered player: " + p.getName() + " into <myPlugin>'s config!");
               
            }
        }
    Main Class onEnable:
    Code:
        public void onEnable(){
            getServer().getPluginManager().registerEvents(new <myPlugin>Listener(), this);
            System.out.println(ANSI_MAGENTA + "<myPlugin> Enabled" + ANSI_WHITE);
            this.saveDefaultConfig();
            configLoop();
        }
    Let me know if you need any more info. Thanks in advance!
     
  2. Offline

    SnipsRevival

    Use plugin.getConfig(). Also your constructor for <myPlugin>Listener should be <myPlugin>Listener(<myPlugin> instance) not PlayerListener(<myPlugin> instance).

    Edit: also make it <myPlugin>Listener(this) when you register the listener.
     
  3. Offline

    DoveDevic

    Okay i changed what you told me to this...
    Code:
    public class <myPlugin>Listener implements Listener{
        private <myPlugin> plugin;
        public <myPlugin>Listener(<myPlugin> instance){
            plugin = instance;
            }
    However, now in my onEnable, i get an error line under
    Code:
    getServer().getPluginManager().registerEvents(new <myPlugin>Listener(), this);
    for the reason of "The constructor <myPlugin>Listener() is undefined"
     
  4. Offline

    SnipsRevival

    DoveDevic read my edited post. I forgot to mention the part that you are currently having a problem with.
     
  5. Offline

    xTrollxDudex

    DoveDevic
    The new <myPlugin>Listener() would be new <myPlugin>Listener(this)

    Also, <myPlugin> is used analogically, maybe you should replace it with the actual plugin name?

    Edit: ninja'd by SnipsRevival ! GG Mate
     
  6. Offline

    DoveDevic

    SnipsRevival
    I edited the code like you said
    Code:
            getServer().getPluginManager().registerEvents(<myPlugin>Listener(this));
    But i still get an error stating "The method <myPlugin>Listener(<myPlugin>) is undefined for the type <myPlugin>"
    xTrollxDudex
    I am just anal about my plugin's name for some reason. Sorry. :p
     
  7. Offline

    SnipsRevival

    DoveDevic I didn't mean for you to remove the second this after the comma. Make it registerEvents(new <myPlugin>Listener(this), this).
     
  8. Offline

    DoveDevic

    SnipsRevival
    Works like a charm! Thanks a bunch Snips!!!
     
Thread Status:
Not open for further replies.

Share This Page