Skip to content

Commit

Permalink
💎 ecobits support for multicurrency
Browse files Browse the repository at this point in the history
Took 17 minutes
  • Loading branch information
kiranhart committed Sep 6, 2024
1 parent cfd7637 commit 94bbb4a
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package ca.tweetzy.markets.gui.shared.view;

import ca.tweetzy.flight.comp.enums.CompMaterial;
import ca.tweetzy.flight.gui.Gui;
import ca.tweetzy.flight.gui.events.GuiClickEvent;
import ca.tweetzy.flight.gui.helper.InventoryBorder;
import ca.tweetzy.flight.settings.TranslationManager;
import ca.tweetzy.flight.utils.Common;
import ca.tweetzy.flight.utils.QuickItem;
import ca.tweetzy.flight.utils.input.TitleInput;
import ca.tweetzy.flight.utils.profiles.builder.XSkull;
import ca.tweetzy.markets.Markets;
import ca.tweetzy.markets.api.market.MarketSortType;
import ca.tweetzy.markets.api.market.core.Market;
Expand All @@ -21,6 +23,7 @@
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;

import java.util.ArrayList;
import java.util.Comparator;
Expand Down Expand Up @@ -58,7 +61,7 @@ protected void prePopulate() {

@Override
protected ItemStack makeDisplayItem(Market market) {
return QuickItem
ItemStack item = QuickItem
.of(Bukkit.getOfflinePlayer(market.getOwnerUUID()))
.name(market.getDisplayName())
.lore(market.getDescription())
Expand All @@ -68,6 +71,8 @@ protected ItemStack makeDisplayItem(Market market) {
"market_ratings_stars", StringUtils.repeat("★", (int) market.getReviewAvg())
))
.make();

return item;
}

@Override
Expand Down
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;
}
}

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ca.tweetzy.markets.api.manager.ListManager;
import ca.tweetzy.markets.impl.currency.ItemCurrency;
import ca.tweetzy.markets.impl.currency.VaultCurrency;
import ca.tweetzy.markets.model.currency.EcoBitsEconomyLoader;
import ca.tweetzy.markets.model.currency.FundsEconomyLoader;
import ca.tweetzy.markets.model.currency.UltraEconomyLoader;
import ca.tweetzy.markets.settings.Settings;
Expand Down Expand Up @@ -80,5 +81,8 @@ public void load() {

if (Bukkit.getServer().getPluginManager().isPluginEnabled("Funds"))
new FundsEconomyLoader().getCurrencies().forEach(this::add);

if (Bukkit.getServer().getPluginManager().isPluginEnabled("EcoBits"))
new EcoBitsEconomyLoader().getCurrencies().forEach(this::add);
}
}
1 change: 1 addition & 0 deletions src/main/java/ca/tweetzy/markets/settings/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public final class Settings extends FlightSettings {
public static ConfigEntry GUI_NEW_RATING_ITEMS_MSG_ITEM = create("gui.new rating.message.item", CompMaterial.DARK_OAK_SIGN.name());

public static ConfigEntry GUI_ALL_MARKETS_BACKGROUND = create("gui.all markets.items.background", CompMaterial.BLACK_STAINED_GLASS_PANE.name());
public static ConfigEntry GUI_ALL_MARKETS_ITEMS_MARKET_ITEM = create("gui.all markets.items.market.item", CompMaterial.NETHER_STAR.name());
public static ConfigEntry GUI_ALL_MARKETS_ITEMS_SEARCH_ITEM = create("gui.all markets.items.search.item", CompMaterial.DARK_OAK_SIGN.name());
public static ConfigEntry GUI_ALL_MARKETS_ITEMS_FILTER_ITEM = create("gui.all markets.items.filter.item", CompMaterial.REPEATER.name());
public static ConfigEntry GUI_REQUEST_BACKGROUND = create("gui.request.items.background", CompMaterial.BLACK_STAINED_GLASS_PANE.name());
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ api-version: 1.16
softdepend:
- PlaceholderAPI
- Vault
- EcoBits


libraries:
Expand Down

0 comments on commit 94bbb4a

Please sign in to comment.