Created
June 7, 2014 19:07
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No u feg, kthxbai