Skip to content

Commit

Permalink
Create VisitAddonManager class.
Browse files Browse the repository at this point in the history
Collect all GameMode addons where VisitAddon is enabled.
  • Loading branch information
BONNe committed Jun 16, 2020
1 parent f1af549 commit 6f56b0b
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/main/java/world/bentobox/visit/VisitAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import world.bentobox.visit.commands.admin.VisitSettingsCommand;
import world.bentobox.visit.commands.player.VisitPlayerCommand;
import world.bentobox.visit.configs.Settings;
import world.bentobox.visit.managers.VisitAddonManager;


/**
Expand All @@ -29,6 +30,11 @@ public class VisitAddon extends Addon
*/
private Settings settings;

/**
* Stores addon manager.
*/
private VisitAddonManager addonManager;

/**
* Local variable that stores if vaultHook is present.
*/
Expand Down Expand Up @@ -117,6 +123,8 @@ public void onEnable()
return;
}

this.addonManager = new VisitAddonManager(this);

// If your addon wants to hook into other GameModes, f.e. use flags, then you should
// hook these flags into each GameMode.

Expand Down Expand Up @@ -144,6 +152,9 @@ public void onEnable()

gameModeAddon.getPlayerCommand().ifPresent(
playerCommand -> new VisitPlayerCommand(this, playerCommand));

// Add gamemode to enabled addon list. Used in GUIs.
this.addonManager.addGameMode(gameModeAddon);
}
});

Expand Down Expand Up @@ -178,6 +189,8 @@ public void onReload()

this.settings = new Config<>(this, Settings.class).loadConfigObject();

// TODO: check and readd disabled addon list in addon manager.

if (this.settings == null)
{
// If we failed to load Settings then we should not enable addon.
Expand Down Expand Up @@ -212,4 +225,24 @@ public VaultHook getVaultHook()
{
return this.vaultHook.orElse(null);
}


/**
* This method returns the settings value.
* @return the value of settings.
*/
public Settings getSettings()
{
return this.settings;
}


/**
* This method returns the addonManager value.
* @return the value of addonManager.
*/
public VisitAddonManager getAddonManager()
{
return this.addonManager;
}
}
78 changes: 78 additions & 0 deletions src/main/java/world/bentobox/visit/managers/VisitAddonManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package world.bentobox.visit.managers;


import java.util.ArrayList;
import java.util.List;

import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.visit.VisitAddon;


/**
* This class manages data handling and option processing for Visit Addon.
*/
public class VisitAddonManager
{
// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------

/**
* Local variable that stores all GameMode addons where current addon is enabled.
*/
private final List<GameModeAddon> enabledAddonList;

/**
* Reference to main addon class.
*/
private final VisitAddon addon;

// ---------------------------------------------------------------------
// Section: Constructors
// ---------------------------------------------------------------------


/**
* Constructor VisitAddonManager creates a new VisitAddonManager instance.
*
* @param addon of type VisitAddon
*/
public VisitAddonManager(VisitAddon addon)
{
this.addon = addon;
this.enabledAddonList = new ArrayList<>(5);
}


// ---------------------------------------------------------------------
// Section: Methods
// ---------------------------------------------------------------------


/**
* This method adds given gamemode to the enabled addon list.
* @param addon Addon that must be added to enabled addon list.
*/
public void addGameMode(GameModeAddon addon)
{
this.enabledAddonList.add(addon);
}


/**
* This method returns the enabledAddonList value.
* @return the value of enabledAddonList.
*/
public List<GameModeAddon> getEnabledAddonList()
{
return enabledAddonList;
}


// ---------------------------------------------------------------------
// Section: Database methods
// ---------------------------------------------------------------------



}

0 comments on commit 6f56b0b

Please sign in to comment.