Skip to content

Commit

Permalink
Main singleton instead of passing parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
dentych committed Sep 6, 2015
1 parent 9369ce9 commit 261c5b7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/me/tychsen/enchantgui/EshopConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class EshopConfig {
private JavaPlugin plugin;
private FileConfiguration config;

public EshopConfig(JavaPlugin plugin) {
this.plugin = plugin;
public EshopConfig() {
this.plugin = Main.getInstance();
config = plugin.getConfig();
}

Expand Down
4 changes: 2 additions & 2 deletions src/me/tychsen/enchantgui/EshopEventManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class EshopEventManager {
private EshopSystem esys;

/* Constructor */
public EshopEventManager(JavaPlugin plugin) {
esys = new EshopSystem(plugin);
public EshopEventManager() {
esys = new EshopSystem();
}

/* Public methods */
Expand Down
6 changes: 3 additions & 3 deletions src/me/tychsen/enchantgui/EshopSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ public class EshopSystem {
private EshopConfig config;
private EshopVault vault;

public EshopSystem(JavaPlugin plugin) {
public EshopSystem() {
playerNavigation = new HashMap<>();
inventorySize = 36;
enchants = new EshopEnchants();
permsys = new EshopPermissionSys();
config = new EshopConfig(plugin);
vault = new EshopVault(plugin);
config = new EshopConfig();
vault = new EshopVault();
}

public void showMainMenu(Player p) {
Expand Down
4 changes: 2 additions & 2 deletions src/me/tychsen/enchantgui/EshopVault.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class EshopVault {
private Economy econ = null;
private JavaPlugin plugin;

public EshopVault(JavaPlugin plugin) {
this.plugin = plugin;
public EshopVault() {
this.plugin = Main.getInstance();

if (!setupEconomy()) {
plugin.getLogger().severe("Dependency (Vault) not found. Disabling the plugin!");
Expand Down
8 changes: 7 additions & 1 deletion src/me/tychsen/enchantgui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
import java.io.IOException;

public class Main extends JavaPlugin implements Listener {
public static Main instance;
private EshopEventManager eshop;

@Override
public void onEnable() {
instance = this;
getLogger().info("Loading configs and stuff...");

getServer().getPluginManager().registerEvents(this, this);
eshop = new EshopEventManager(this);
eshop = new EshopEventManager();

// Generate config.yml if there is none
saveDefaultConfig();
Expand All @@ -32,6 +34,10 @@ public void onEnable() {
}
}

public static Main getInstance() {
return instance;
}

@EventHandler
public void onInventoryClickEvent(InventoryClickEvent e) {
if (e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR)
Expand Down

0 comments on commit 261c5b7

Please sign in to comment.