There is multiple way.
You can do such as Ferrybig's said: Pass the instance of the JavaPlugin's into the constructor.
Make the class into the JavaPlugin's one. Here, You put the class below the JavaPlugin's, but you can do like this:
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
public class (class name spot) extends JavaPlugin implements Listener {
@Override
public void onEnable() {
getLogger().warning("Server started.");
FirstFunction first = new FirstFunction();
first.onEnable();
getLogger().info("Nice try!"); // check point
}
class FirstFunction implements Listener {
void onEnable() {
String abcd = "abc";
getLogger().info(abcd);
}
}
}
- You can create a singleton (What it is ?) of your JavaPlugin object: save the instance of it to get it everywhere, like that:
public class ClassNameSpot extends JavaPlugin implements Listener {
private static ClassNameSpot instance;
public static ClassNameSpot getInstance() {
return instance;
}
@Override
public void onEnable() {
instance = this; // set the instance
getLogger().warning("Server started.");
FirstFunction first = new FirstFunction();
first.onEnable();
getLogger().info("Nice try!"); // check point
}
}
class first_function implements Listener {
void onEnable() {
String abcd = "abc";
ClassNameSpot.getInstance().getLogger().info(abcd); // I want to use getLogger(bukkit's).
}
}
This solution is better if you have lot of class (instead of create a variable everywhere)
BONUS: You seems to use implements Listener
but never register them. I don't know if it's intentionate or not, but don't forget to, in your onEnable
's method, call: getServer().getPluginManager().registerEvents(first, this);
.