-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Took 17 minutes
- Loading branch information
Showing
6 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
51 changes: 51 additions & 0 deletions
51
src/main/java/ca/tweetzy/markets/impl/currency/EcoBitsCurrency.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package ca.tweetzy.markets.impl.currency; | ||
|
||
import ca.tweetzy.flight.comp.enums.CompMaterial; | ||
import ca.tweetzy.markets.api.currency.IconableCurrency; | ||
import com.willfp.ecobits.currencies.Currencies; | ||
import com.willfp.ecobits.currencies.Currency; | ||
import com.willfp.ecobits.currencies.CurrencyUtils; | ||
import org.bukkit.OfflinePlayer; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public final class EcoBitsCurrency extends IconableCurrency { | ||
|
||
private final Currency currency; | ||
|
||
public EcoBitsCurrency(String currencyName) { | ||
super("EcoBits", currencyName, "", CompMaterial.PAPER.parseItem()); | ||
this.currency = Currencies.getByID(currencyName.toLowerCase()); | ||
|
||
if (this.currency != null) { | ||
setDisplayName(this.currency.getName()); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean has(OfflinePlayer player, double amount) { | ||
if (this.currency == null) | ||
return false; | ||
|
||
return CurrencyUtils.getBalance(player, currency).doubleValue() >= amount; | ||
} | ||
|
||
@Override | ||
public boolean withdraw(OfflinePlayer player, double amount) { | ||
if (this.currency == null) | ||
return false; | ||
|
||
CurrencyUtils.setBalance(player, currency, BigDecimal.valueOf(CurrencyUtils.getBalance(player, currency).doubleValue() - amount)); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean deposit(OfflinePlayer player, double amount) { | ||
if (this.currency == null) | ||
return false; | ||
|
||
CurrencyUtils.setBalance(player, currency, BigDecimal.valueOf(CurrencyUtils.getBalance(player, currency).doubleValue() + amount)); | ||
return true; | ||
} | ||
} | ||
|
43 changes: 43 additions & 0 deletions
43
src/main/java/ca/tweetzy/markets/model/currency/EcoBitsEconomyLoader.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package ca.tweetzy.markets.model.currency; | ||
|
||
import ca.tweetzy.markets.api.currency.AbstractCurrency; | ||
import ca.tweetzy.markets.impl.currency.EcoBitsCurrency; | ||
import ca.tweetzy.markets.settings.Settings; | ||
import com.willfp.ecobits.currencies.Currencies; | ||
import com.willfp.ecobits.currencies.Currency; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public final class EcoBitsEconomyLoader extends CurrencyLoader { | ||
|
||
public EcoBitsEconomyLoader() { | ||
super("EcoBits"); | ||
} | ||
|
||
|
||
@Override | ||
public List<AbstractCurrency> getCurrencies() { | ||
final List<AbstractCurrency> currencies = new ArrayList<>(); | ||
|
||
for (Currency currency : Currencies.values()) { | ||
boolean blackListed = false; | ||
|
||
for (String blacklisted : Settings.CURRENCY_BLACKLISTED.getStringList()) { | ||
final String[] blacklistSplit = blacklisted.split(":"); | ||
|
||
if (blacklistSplit.length != 2) continue; | ||
if (!blacklistSplit[0].equalsIgnoreCase(this.owningPlugin)) continue; | ||
|
||
if (blacklistSplit[1].equalsIgnoreCase(currency.getName())) | ||
blackListed = true; | ||
|
||
} | ||
|
||
if (!blackListed) | ||
currencies.add(new EcoBitsCurrency(currency.getId())); | ||
} | ||
|
||
return currencies; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ api-version: 1.16 | |
softdepend: | ||
- PlaceholderAPI | ||
- Vault | ||
- EcoBits | ||
|
||
|
||
libraries: | ||
|