Skip to content

Commit

Permalink
Implement usage of Bank Addon.
Browse files Browse the repository at this point in the history
Adding new Settings option: use-bank.
Implement all economy part going through bank addon, if use-bank is enabled.
  • Loading branch information
BONNe committed Feb 28, 2022
1 parent d97af9c commit 350b5eb
Show file tree
Hide file tree
Showing 11 changed files with 319 additions and 73 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<spigot.version>1.18-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.20.0</bentobox.version>
<level.version>2.5.0</level.version>
<bank.version>1.4.0</bank.version>
<!-- Panel Utils version -->
<panelutils.version>1.0.0</panelutils.version>
<!-- Vault API version -->
Expand Down Expand Up @@ -167,6 +168,12 @@
<version>${level.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>world.bentobox</groupId>
<artifactId>bank</artifactId>
<version>${bank.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.bukkit.Material;
import org.bukkit.World;

import world.bentobox.bank.Bank;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.configuration.Config;
Expand Down Expand Up @@ -298,6 +299,7 @@ public void allLoaded()

this.findLevel();
this.findVault();
this.findBank();
}


Expand All @@ -318,6 +320,7 @@ private void findVault()
}
else
{
this.log("MagicCobblestoneGenerator Addon hooked into Economy.");
this.vaultHook = vault.get();
}
}
Expand All @@ -335,16 +338,38 @@ private void findLevel()

if (level.isEmpty())
{
this.logWarning("Level add-on not found so Magic Cobblestone Generator, some parts may not work!");
this.levelAddon = null;
}
else
{
this.log("MagicCobblestoneGenerator Addon hooked into Level addon.");
this.levelAddon = (Level) level.get();
}
}


/**
* This is silly method that was introduced to reduce main method complexity, and just reports if bank addon is
* enabled or not.
*/
private void findBank()
{
// Try to find bank addon and if it does not exist, display a warning

Optional<Addon> addon = this.getAddonByName("Bank");

if (addon.isEmpty())
{
this.bankAddon = null;
}
else
{
this.log("MagicCobblestoneGenerator Addon hooked into Bank addon.");
this.bankAddon = (Bank) addon.get();
}
}


/**
* Executes code when disabling the addon.
*/
Expand Down Expand Up @@ -445,16 +470,38 @@ public Level getLevelAddon()


/**
* This method returns the levelProvided object.
* This method returns if the levelAddon object exist.
*
* @return the levelProvided object.
* @return the levelAddon object exist.
*/
public boolean isLevelProvided()
{
return levelAddon != null;
}


/**
* This method returns the bankAddon object.
*
* @return the bankAddon object.
*/
public Bank getBankAddon()
{
return this.bankAddon;
}


/**
* This method returns if the bankAddon object exist.
*
* @return the bankAddon object exist.
*/
public boolean isBankProvided()
{
return bankAddon != null;
}


/**
* This method returns the vaultHook is provided.
*
Expand Down Expand Up @@ -544,7 +591,12 @@ public static StoneGeneratorAddon getInstance()
private Level levelAddon;

/**
* Static addon isntance.
* Bank addon.
*/
private Bank bankAddon;

/**
* Static addon instance.
*/
private static StoneGeneratorAddon instance;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public boolean execute(User user, String label, List<String> args)

if (addonManager.canPurchaseGenerator(user, island, data, generator))
{
addonManager.purchaseGenerator(user, data, generator);
addonManager.purchaseGenerator(user, island, data, generator);
return true;
}
}
Expand Down Expand Up @@ -430,7 +430,7 @@ public boolean execute(User user, String label, List<String> args)
if (activate)
{
// Check before activating.
if (addonManager.canActivateGenerator(user, data, generator))
if (addonManager.canActivateGenerator(user, island, data, generator))
{
addonManager.activateGenerator(user, island, data, generator);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,28 @@ public void setOverwriteOnActive(boolean overwriteOnActive)
}


/**
* Is use bank account boolean.
*
* @return the boolean
*/
public boolean isUseBankAccount()
{
return useBankAccount;
}


/**
* Sets use bank account.
*
* @param useBankAccount the use bank account
*/
public void setUseBankAccount(boolean useBankAccount)
{
this.useBankAccount = useBankAccount;
}


// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------
Expand Down Expand Up @@ -381,6 +403,12 @@ public enum GuiAction
@ConfigEntry(path = "notify-on-unlock")
private boolean notifyUnlockedGenerators = true;

@ConfigComment("")
@ConfigComment("This indicates if all monetary payments should be done via Bank Addon Account.")
@ConfigComment("Requires Bank Addon.")
@ConfigEntry(path = "use-bank-account")
private boolean useBankAccount = false;

@ConfigComment("")
@ConfigComment("This list stores GameModes in which the addon should not work.")
@ConfigComment("To disable addon it is necessary to write its name in new line that starts with -. Example:")
Expand Down

0 comments on commit 350b5eb

Please sign in to comment.