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 public class Ceta extends JavaPlugin{ @Override public void onEnable() { new SchematicSchedular(this, null); }} Then i have my Delayed task in a Class called "SchematicSchedular" looking like this Code:java public class SchematicSchedular extends BukkitRunnable{ private String SchematicID; public SchematicSchedular(Ceta plugin, String SchematicID) { runTaskLater(plugin, 18000); this.SchematicID = SchematicID; } @Override public void run() { Bukkit.broadcastMessage("Just a test: " + SchematicID); }} And finally i have my problem in my "CityWall" class where i cant "define" plugin Code:java 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 private static Plugin instance; @Overridepublic void onEnable() { instance = this; // ... // This will throw a NullPointerException if you don't have the command defined in your plugin.yml file! getCommand("basic").setExecutor(new MyPluginCommandExecutor()); // ...} public static Plugin getInstance() { return instance;} 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
in your SchematicScheduler do Ceta ceta; then in the Code:java public SchematicSchedular(Ceta plugin, String SchematicID) do ceta = plugin; then you can use ceta.broadcastMessage() and so on!
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 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
Donkaan Try: Code:java Ceta plugin;public SchematicSchedular(Ceta instance, String SchematicID){plugin = instance;}
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
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.
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?
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); }
ZeusAllMighty11 sounds like the solution but i do not understand what to change to make it match my code