help me with plugin.

Discussion in 'Plugin Development' started by MoseMister, Dec 5, 2013.

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

    MoseMister

    hey im new to java, but i understand the raw basics, however i have been stuck on this for 2 days now, just wanted to know how to fix it.

    the problem im having is the 'plugin' text gets underlined, eclipse says 'plugin cannot be resolved to a type'

    has bukkit change the 'plugin' to something else?


    Code:java
    1. if(plugin.getConfig().getBoolean("Wood_Planks") == true) {
    2. MyPlugin.put(Integer.valueOf(5), Boolean.valueOf(true));
    3. getLogger().info("Wooden Planks has been enabled");
    4. }
    5. if(plugin.getConfig().getBoolean("Wood_Planks") == false) {
    6. getLogger().info("Wooden Planks has been disabled");
    7. }


    seeing that colour (yes its colour not color) code i feel like im missing some code somewhere, if you could tell me what the problem is and what i need to do to fix it, that would be awesome
     
  2. Offline

    Pizza371

    MoseMister what variable is that? Where do you initialize it?
     
  3. Offline

    Zughy

    MoseMister
    Have you declared plugin like this, before the onEnable on your main class?
    Code:java
    1. private static nameOfYourMainClass plugin;


    If the answer is 'yes', are you trying to execute that code in another class?
     
  4. You need to define variables before using them.

    Use the "this" keyword in this case. "this" points the object itself.

    You can simply use
    Code:java
    1.  
    2. if(this.getConfig().getBoolean("Wood_Planks"){
    3. //do something
    4. }else{
    5. getLogger().info("Wooden planks is disabled");
    6. }
    7.  

    the if(booleanValue==true) is not needed
     
    Zughy likes this.
  5. Offline

    MoseMister

  6. Offline

    shawshark

    MoseMister
    Code:
    16:35:44 Caused by: java.lang.IllegalArgumentException: File cannot be null
    so add this to your onenable
    Code:java
    1. saveDefaultConfig();
     
  7. Offline

    durpnhard

    where are you running this code from? Assuming this is being ran from whichever class you are extending "JavaPlugin" I would make sure that your plugin variable is not only created but instantiated. To do this (putting together a few of the things others have said as well)


    Code:
    private static nameOfYourMainClass plugin;
     
    @Override
    public void onEnable() {
      plugin = this;
      // ... all your other code
    }
    This will allow you to continue using your exact code you already have, as long as you saveDefaultConfig() as shawshark suggested.
     
  8. Offline

    MoseMister

  9. Offline

    shawshark

    MoseMister
    Line 17 of that error as I said before.

    Check if there is there a config generating?
     
  10. Offline

    MoseMister

    i have added that, thats the error that came with it.
    heres the code inside the onenable
    Code:java
    1. public void onEnable()
    2. {
    3. plugin = this;
    4. Object blok = null;
    5.  
    6. PluginManager PM = getServer().getPluginManager();
    7. PM.registerEvents(new ShipsListener(), this);
    8.  
    9. PluginDescriptionFile p = this.getDescription();
    10. this.log.info(p.getName() + " V" + p.getVersion() + " only tested on 2940 and 2935");
    11.  
    12. ShipsSettings.LoadSettings();
    13.  
    14. getConfig().options().copyDefaults(true);
    15. saveDefaultConfig();
    16. reloadConfig();


    could it be that its thinking the inside the jar file is not the default config?
     
  11. Offline

    fireblast709

    MoseMister Post your main class. You are probably trying to use getConfig() before onEnable().
     
  12. Offline

    MoseMister

    sorry guys got it working thx to a friend of mine
     
Thread Status:
Not open for further replies.

Share This Page