Defining plugin

Discussion in 'Plugin Development' started by Donkaan, May 11, 2014.

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

    Donkaan

    Hey guys.

    I have a very simple question that i was hoping you guys can help me with. I am trying to define "plugin" in my subclass but no matter what i try it just wont let me.

    So my main file is like this

    Code:java
    1. public class Ceta extends JavaPlugin
    2. {
    3. @Override
    4. public void onEnable()
    5. {
    6. new SchematicSchedular(this, null);
    7. }
    8. }


    Then i have my Delayed task in a Class called "SchematicSchedular" looking like this

    Code:java
    1. public class SchematicSchedular extends BukkitRunnable
    2. {
    3. private String SchematicID;
    4.  
    5. public SchematicSchedular(Ceta plugin, String SchematicID)
    6. {
    7. runTaskLater(plugin, 18000);
    8. this.SchematicID = SchematicID;
    9. }
    10. @Override
    11. public void run()
    12. {
    13. Bukkit.broadcastMessage("Just a test: " + SchematicID);
    14. }
    15. }


    And finally i have my problem in my "CityWall" class where i cant "define" plugin

    Code:java
    1. SchematicSchedular(plugin, CityWallID);


    I have tried all sorts of crazy things and now i just feel that i am looking blind at it. Here is some of my tries:

    private plugin = Ceta.getInstance();
    SchematicSchedular(Ceta, CityWallID);
    SchematicSchedular(this, CityWallID);

    and i could keep on going. Even tried bukkits example but that mixed non-static and static:
    Code:java
    1. private static Plugin instance;
    2.  
    3. @Override
    4. public void onEnable() {
    5. instance = this;
    6. // ...
    7.  
    8. // This will throw a NullPointerException if you don't have the command defined in your plugin.yml file!
    9. getCommand("basic").setExecutor(new MyPluginCommandExecutor());
    10.  
    11. // ...
    12. }
    13.  
    14. public static Plugin getInstance() {
    15. return instance;
    16. }


    Know the feeling when something very simple all the suddent is a huge problem? -,-
    Well i hope one of you have the great answer. That would help alot. Thanks
     
  2. Offline

    tryy3

    in your SchematicScheduler
    do
    Ceta ceta;
    then in the
    Code:java
    1. public SchematicSchedular(Ceta plugin, String SchematicID)

    do
    ceta = plugin;
    then you can use ceta.broadcastMessage() and so on!
     
  3. Offline

    Donkaan

    Im not sure if you misunderstood or if its me that cant figure out what i should change.
    The problem is that in the class CityWalls i am trying to execute my delayed task.

    i need to pass the methode that i want to execute together with the plugin and the id

    So it should be:

    Code:java
    1. SchematicSchedular(plugin, CityWallID);


    But since i havnt defined what plugin is then it gives the error:
    plugin cannot be resolved to a variable

    i just cant remember how i do define that plugin is Ceta
     
  4. Offline

    hubeb

    Donkaan Try:
    Code:java
    1. Ceta plugin;
    2. public SchematicSchedular(Ceta instance, String SchematicID){
    3. plugin = instance;
    4. }
     
  5. Offline

    Donkaan

    It is still not in that class i have the issue?
     
  6. Donkaan I can tell you don't really understand what your code is doing. You should make the effort to learn more about Java first. :)

    Hint: You'd want to do the same in CityWalls as you do in SchematicSchedular
     
  7. Offline

    Donkaan

    ehm not at all. im just simply trying to execute the SchematicSchedular from CityWall.

    Its very simple.

    I have the delayed task in a seperate class so that i can call it from several methods.
    I am trying to execute the delayed task from a method but i have to define that plugin = my plugin
    And that is my question

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  8. Donkaan *sigh* You use plugin in SchematicSchedular. How do you do that? Why would it be different if you wanted to use plugin in CityWall?
     
  9. Offline

    ZeusAllMighty11

    You need to pass an instance of your main class (the one which inherits from JavaPlugin) to the scheduler.

    Code:
    private ReferencingClass class1;
     
    public MyClass(ReferencingClass class1) { this.class1 = class1; }
     
    public void stuff()
    {
        someScheduler.schedele(new CoolInterface()
        {
            @Override
            public void run()
            {
                 // stuff
            }
        }, class1);
    }
     
  10. Offline

    Donkaan

    ZeusAllMighty11 sounds like the solution but i do not understand what to change to make it match my code
     
Thread Status:
Not open for further replies.

Share This Page