Skip to content

Instantly share code, notes, and snippets.

@DarkSeraphim
Created June 7, 2014 19:07
Show Gist options
  • Save DarkSeraphim/1f54da73a72a34eccd91 to your computer and use it in GitHub Desktop.
Save DarkSeraphim/1f54da73a72a34eccd91 to your computer and use it in GitHub Desktop.
Smart Bukkit statics. The nice trick to have static access without spoiling the fun with memory management.
public class AnyClass
{
private final MainClass plugin;
public AnyClass(MainClass plugin)
{
this.plugin = plugin;
}
public static String getSomething()
{
return getInstance().plugin.getConfig().getString("something");
}
private static AnyClass getInstance()
{
// Just have an instance of AnyClass in the main class
// with an appropiate getter method (or <3 Lombok and use @Getter :P)
return JavaPlugin.getPlugin(MainClass.class).getAnyClass();
}
}
@zackpollard
Copy link

No u feg, kthxbai

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment