Skip to content

Commit

Permalink
⬛ blocked_items config section now supports model data. Ex: PAPER:5 m…
Browse files Browse the repository at this point in the history
…eans if the paper has a model data of 5 its blocked.

Took 10 minutes
  • Loading branch information
kiranhart committed Sep 9, 2024
1 parent fc06ad7 commit f27857e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
21 changes: 18 additions & 3 deletions src/main/java/ca/tweetzy/auctionhouse/api/AuctionAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import ca.tweetzy.auctionhouse.auction.enums.PaymentReason;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.compatibility.XMaterial;
import ca.tweetzy.core.utils.NumberUtils;
import ca.tweetzy.flight.comp.enums.ServerVersion;
import ca.tweetzy.flight.nbtapi.NBT;
import ca.tweetzy.flight.utils.QuickItem;
Expand Down Expand Up @@ -793,12 +794,26 @@ public boolean meetsListingRequirements(Player player, ItemStack itemStack) {
return false;
}
} else {
if (Settings.BLOCKED_ITEMS.getStringList().contains(itemStack.getType().name())) {
AuctionHouse.getInstance().getLocale().getMessage("general.blockeditem").processPlaceholder("item", itemStack.getType().name()).sendPrefixedMessage(player);
return false;
for (String item : Settings.BLOCKED_ITEMS.getStringList()) {
final String[] split = item.split(":");

if (split.length == 1) {
if (split[0].contains(itemStack.getType().name())) {
AuctionHouse.getInstance().getLocale().getMessage("general.blockeditem").processPlaceholder("item", itemStack.getType().name()).sendPrefixedMessage(player);
return false;
}
}

if (split.length == 2 && NumberUtils.isInt(split[1]) && ServerVersion.isServerVersionAtLeast(ServerVersion.V1_14)) {
if (split[0].contains(itemStack.getType().name()) && itemStack.getItemMeta() != null && itemStack.getItemMeta().getCustomModelData() == Integer.parseInt(split[1])) {
AuctionHouse.getInstance().getLocale().getMessage("general.blockeditem").processPlaceholder("item", itemStack.getType().name()).sendPrefixedMessage(player);
return false;
}
}
}
}


// Check NBT tags
for (String nbtTag : Settings.BLOCKED_NBT_TAGS.getStringList()) {
if (NBT.get(itemStack, nbt -> (boolean) nbt.hasTag(nbtTag))) {
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/ca/tweetzy/auctionhouse/impl/AuctionAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@

public final class AuctionAPI implements AuctionHouseAPI {

private String replaceLastDecimal(String input) {
int lastComma = input.lastIndexOf(",00");
int lastDot = input.lastIndexOf(".00");

int lastIndex = Math.max(lastComma, lastDot);

if (lastIndex != -1) {
return input.substring(0, lastIndex) + input.substring(lastIndex + 3);
}

return input;
}

@Override
public String getNumberAsCurrency(double number, boolean hideSymbol) {

Expand All @@ -48,7 +61,13 @@ public String getNumberAsCurrency(double number, boolean hideSymbol) {
decimalFormat.setDecimalFormatSymbols(symbols);
}

return currencyFormatter.format(number);
String formatted = currencyFormatter.format(number);

if (Settings.CURRENCY_STRIP_ENDING_ZEROES.getBoolean()) {
formatted = replaceLastDecimal(formatted);
}

return formatted;
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public class Settings {
public static final ConfigSetting CURRENCY_FORMAT_LANGUAGE = new ConfigSetting(config, "economy.currency.format.language", "en", "An ISO 639 alpha-2 or alpha-3 language code.");
public static final ConfigSetting CURRENCY_FORMAT_COUNTRY = new ConfigSetting(config, "economy.currency.format.country", "US", "An ISO 3166 alpha-2 country code or a UN M.49 numeric-3 area code.");
public static final ConfigSetting CURRENCY_ABBREVIATE_NUMBERS = new ConfigSetting(config, "economy.currency.abbreviate numbers", false, "Should numbers be abbreviated?. Example: 123,000 will become 123k ");

public static final ConfigSetting CURRENCY_STRIP_ENDING_ZEROES = new ConfigSetting(config, "economy.currency.strip ending zeroes", false, "If the number ends with 00, should it be stripped. EX 123.00 becomes 123");

public static final ConfigSetting CMD_ALIAS_MAIN = new ConfigSetting(config, "command aliases.main", Arrays.asList("ah", "auctions", "auctionhouses", "ahgui", "auctiongui"), "Command aliases for the main command");
public static final ConfigSetting CMD_ALIAS_SUB_ACTIVE = new ConfigSetting(config, "command aliases.subcommands.active", Collections.singletonList("active"), "Command aliases for the active command");
public static final ConfigSetting CMD_ALIAS_SUB_ADMIN = new ConfigSetting(config, "command aliases.subcommands.admin", Collections.singletonList("admin"), "Command aliases for the admin command");
Expand Down

0 comments on commit f27857e

Please sign in to comment.