Auction Blacklist System

This commit is contained in:
Kam committed 2026-01-24 16:03:54 -05:00
1 parent b85804af98
commit fe998ea31c
10 files changed
+756 -240

No files matched your search

@@ -13,6 +13,7 @@ public class ConfigMarket {
public final static String CURRENCY = "Market.Currency";
public final static String AUCTION = "Market.Auction";
public final static String AUCTION_BLACKLIST = "Market.Auction.Blacklist";
public final static String AUCTION_LOGGING = "Market.Auction.Logging";
// Max trades grid = 9x5 = 45 slots
@@ -41,6 +42,14 @@ public class ConfigMarket {
public static double MinBidIncrementPercent = 0.05;
public static double CancellationPenaltyPercent = 0.10;
// =========================================
// Auction Blacklist Settings
// =========================================
public static boolean BlacklistEnabled = true;
public static String[] BlacklistedItems = new String[]{};
public static String[] BlacklistedMods = new String[]{};
public static String[] BlacklistedNBTTags = new String[]{};
// =========================================
// Auction Logging Settings
// =========================================
@@ -113,6 +122,45 @@ public class ConfigMarket {
CancellationPenaltyPercent = config.get(AUCTION, "Cancellation Penalty Percent", 0.10,
"Percentage of current bid taken as penalty when seller cancels an auction with bids (0.10 = 10%)").getDouble(0.10);
// =========================================
// Auction Blacklist Settings
// =========================================
config.setCategoryComment(AUCTION_BLACKLIST,
"Item Blacklist settings for the Auction House.\n" +
"Prevents specific items, mods, or items with certain NBT tags from being listed.\n\n" +
"ITEM FORMAT: Use 'modid:itemname' format (e.g., 'minecraft:bedrock', 'customnpcs:npcWand')\n" +
"WILDCARDS: Use * for wildcards (e.g., 'customnpcs:npc*' blocks all items starting with 'npc')\n" +
"MOD FORMAT: Use just the mod ID (e.g., 'projecte' blocks all items from that mod)\n" +
"NBT FORMAT: Use the NBT tag key name (e.g., 'AdminOnly' blocks items with that tag)");
BlacklistEnabled = config.get(AUCTION_BLACKLIST, "Enable Blacklist", true,
"Enable item blacklist checking when creating listings").getBoolean(true);
BlacklistedItems = config.get(AUCTION_BLACKLIST, "Blacklisted Items", new String[]{
"minecraft:bedrock",
"minecraft:command_block",
"customnpcs:npcWand",
"customnpcs:npcMobCloner",
"customnpcs:npcScripter",
"customnpcs:npcMovingPath",
"customnpcs:npcMounter",
"customnpcs:npcTeleporter",
"customnpcs:npcTool",
"customnpcs:npcSoulstoneFilled"
},
"Items that cannot be listed on the Auction House.\n" +
"Format: modid:itemname (supports * wildcards)\n" +
"Example: 'minecraft:diamond_sword' or 'customnpcs:npc*'").getStringList();
BlacklistedMods = config.get(AUCTION_BLACKLIST, "Blacklisted Mods", new String[]{},
"All items from these mods are blocked from the Auction House.\n" +
"Format: modid (e.g., 'projecte', 'thaumcraft')").getStringList();
BlacklistedNBTTags = config.get(AUCTION_BLACKLIST, "Blacklisted NBT Tags", new String[]{},
"Items containing any of these NBT tag keys are blocked.\n" +
"Checks the root level of the item's NBT compound.\n" +
"Example: 'AdminOnly', 'CreativeMode'").getStringList();
// =========================================
// Auction Logging Settings
// =========================================
@@ -163,6 +211,13 @@ public class ConfigMarket {
"Cancellation Penalty Percent"
)));
config.setCategoryPropertyOrder(AUCTION_BLACKLIST, new ArrayList<>(Arrays.asList(
"Enable Blacklist",
"Blacklisted Items",
"Blacklisted Mods",
"Blacklisted NBT Tags"
)));
config.setCategoryPropertyOrder(AUCTION_LOGGING, new ArrayList<>(Arrays.asList(
"Enable Auction Logging",
"Log Created",
@@ -21,6 +21,7 @@ import noppes.npcs.constants.EnumAuctionSort;
import noppes.npcs.constants.EnumAuctionStatus;
import noppes.npcs.constants.EnumClaimType;
import noppes.npcs.constants.EnumNotificationType;
import noppes.npcs.controllers.data.AuctionBlacklist;
import noppes.npcs.controllers.data.AuctionClaim;
import noppes.npcs.controllers.data.AuctionFilter;
import noppes.npcs.controllers.data.AuctionListing;
@@ -86,6 +87,7 @@ public class AuctionController implements IAuctionHandler {
public AuctionController() {
Instance = this;
AuctionBlacklist.reload();
load();
}
@@ -241,6 +243,11 @@ public class AuctionController implements IAuctionHandler {
return "Auction is disabled.";
}
// Check blacklist (with bypass for admins)
if (AuctionBlacklist.isBlacklistedForPlayer(item, player)) {
return "This item cannot be listed on the Auction House.";
}
// Validate minimum price
if (startingPrice < ConfigMarket.MinimumListingPrice) {
return "Starting price must be at least " + ConfigMarket.MinimumListingPrice + " " + ConfigMarket.CurrencyName + ".";
@@ -1414,4 +1421,18 @@ public class AuctionController implements IAuctionHandler {
AuctionListing listing = listings.get(listingId);
return listing != null && listing.isSeller(playerUUID);
}
/**
* Reload the item blacklist from config.
*/
public void reloadBlacklist() {
AuctionBlacklist.reload();
}
/**
* Check if an item is blacklisted.
*/
public boolean isItemBlacklisted(ItemStack item) {
return AuctionBlacklist.isBlacklisted(item);
}
}
@@ -0,0 +1,237 @@
package noppes.npcs.controllers.data;
import cpw.mods.fml.common.registry.GameRegistry;
import kamkeel.npcs.util.AttributeItemUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.CustomNpcsPermissions;
import noppes.npcs.config.ConfigMarket;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
public class AuctionBlacklist {
private static Set<String> blacklistedItems = new HashSet<>();
private static Set<Pattern> wildcardPatterns = new HashSet<>();
private static Set<String> blacklistedMods = new HashSet<>();
private static Set<String> blacklistedNBTTags = new HashSet<>();
// Built-in bound item requirement keys (always blocked)
private static final String SOULBIND_KEY = "cnpc_soulbind";
private static final String PROFILE_SLOT_KEY = "cnpc_profile_slot";
// Bypass permission
private static final String BYPASS_PERMISSION = "customnpcs.auction.blacklist.bypass";
public static void reload() {
blacklistedItems.clear();
wildcardPatterns.clear();
blacklistedMods.clear();
blacklistedNBTTags.clear();
// Load blacklisted items
for (String item : ConfigMarket.BlacklistedItems) {
if (item == null || item.isEmpty()) continue;
item = item.toLowerCase().trim();
if (item.contains("*")) {
String regex = "^" + item.replace(".", "\\.").replace("*", ".*") + "$";
wildcardPatterns.add(Pattern.compile(regex));
} else {
blacklistedItems.add(item);
}
}
// Load blacklisted mods
for (String mod : ConfigMarket.BlacklistedMods) {
if (mod == null || mod.isEmpty()) continue;
blacklistedMods.add(mod.toLowerCase().trim());
}
// Load blacklisted NBT tags
for (String tag : ConfigMarket.BlacklistedNBTTags) {
if (tag == null || tag.isEmpty()) continue;
blacklistedNBTTags.add(tag.trim());
}
}
/**
* Check if player can bypass the blacklist (OP or has permission)
*/
public static boolean canBypass(EntityPlayer player) {
if (player == null) return false;
// Check OP status
if (player.canCommandSenderUseCommand(2, BYPASS_PERMISSION)) {
return true;
}
// Check custom permission
return CustomNpcsPermissions.hasCustomPermission(player, BYPASS_PERMISSION);
}
/**
* Check if item is blacklisted (without bypass check)
*/
public static boolean isBlacklisted(ItemStack item) {
if (!ConfigMarket.BlacklistEnabled) return false;
if (item == null || item.getItem() == null) return true;
// Check bound items (always blocked, even if blacklist is "disabled")
if (hasBoundRequirement(item)) {
return true;
}
// Get registry name
GameRegistry.UniqueIdentifier uid = GameRegistry.findUniqueIdentifierFor(item.getItem());
if (uid == null) return true;
String registryName = (uid.modId + ":" + uid.name).toLowerCase();
String modId = uid.modId.toLowerCase();
// Check exact item match
if (blacklistedItems.contains(registryName)) {
return true;
}
// Check wildcard patterns
for (Pattern pattern : wildcardPatterns) {
if (pattern.matcher(registryName).matches()) {
return true;
}
}
// Check mod blacklist
if (blacklistedMods.contains(modId)) {
return true;
}
// Check NBT tags
if (item.hasTagCompound() && !blacklistedNBTTags.isEmpty()) {
NBTTagCompound tag = item.getTagCompound();
for (String nbtKey : blacklistedNBTTags) {
if (tag.hasKey(nbtKey)) {
return true;
}
}
}
return false;
}
/**
* Check if item is blacklisted for a specific player (with bypass check)
*/
public static boolean isBlacklistedForPlayer(ItemStack item, EntityPlayer player) {
if (canBypass(player)) return false;
return isBlacklisted(item);
}
/**
* Get the registry name of an item
*/
public static String getRegistryName(ItemStack item) {
if (item == null || item.getItem() == null) return null;
GameRegistry.UniqueIdentifier uid = GameRegistry.findUniqueIdentifierFor(item.getItem());
if (uid == null) return null;
return uid.modId + ":" + uid.name;
}
// =========================================
// Bound Item Checking (RPGCore/Requirements)
// =========================================
/**
* Check if item has soulbind or profile slot requirement.
* Requirements are stored under: item.stackTagCompound/RPGCore/Requirements
*/
private static boolean hasBoundRequirement(ItemStack item) {
if (item == null || !item.hasTagCompound()) return false;
NBTTagCompound root = item.getTagCompound();
if (!root.hasKey(AttributeItemUtil.TAG_RPGCORE)) return false;
NBTTagCompound rpgCore = root.getCompoundTag(AttributeItemUtil.TAG_RPGCORE);
if (!rpgCore.hasKey(AttributeItemUtil.TAG_REQUIREMENTS)) return false;
NBTTagCompound requirements = rpgCore.getCompoundTag(AttributeItemUtil.TAG_REQUIREMENTS);
return requirements.hasKey(SOULBIND_KEY) || requirements.hasKey(PROFILE_SLOT_KEY);
}
// =========================================
// Runtime Blacklist Management
// =========================================
public static boolean addItem(String registryName) {
if (registryName == null || registryName.isEmpty()) return false;
registryName = registryName.toLowerCase().trim();
if (registryName.contains("*")) {
String regex = "^" + registryName.replace(".", "\\.").replace("*", ".*") + "$";
wildcardPatterns.add(Pattern.compile(regex));
} else {
blacklistedItems.add(registryName);
}
return true;
}
public static boolean removeItem(String registryName) {
if (registryName == null || registryName.isEmpty()) return false;
registryName = registryName.toLowerCase().trim();
if (registryName.contains("*")) {
String regex = "^" + registryName.replace(".", "\\.").replace("*", ".*") + "$";
return wildcardPatterns.removeIf(p -> p.pattern().equals(regex));
} else {
return blacklistedItems.remove(registryName);
}
}
public static boolean addMod(String modId) {
if (modId == null || modId.isEmpty()) return false;
return blacklistedMods.add(modId.toLowerCase().trim());
}
public static boolean removeMod(String modId) {
if (modId == null || modId.isEmpty()) return false;
return blacklistedMods.remove(modId.toLowerCase().trim());
}
public static boolean addNBTTag(String tag) {
if (tag == null || tag.isEmpty()) return false;
return blacklistedNBTTags.add(tag.trim());
}
public static boolean removeNBTTag(String tag) {
if (tag == null || tag.isEmpty()) return false;
return blacklistedNBTTags.remove(tag.trim());
}
// =========================================
// Getters for listing
// =========================================
public static List<String> getBlacklistedItems() {
List<String> result = new ArrayList<>(blacklistedItems);
for (Pattern p : wildcardPatterns) {
// Convert regex back to wildcard format
String pattern = p.pattern();
pattern = pattern.substring(1, pattern.length() - 1); // Remove ^ and $
pattern = pattern.replace("\\.", ".").replace(".*", "*");
result.add(pattern);
}
return result;
}
public static List<String> getBlacklistedMods() {
return new ArrayList<>(blacklistedMods);
}
public static List<String> getBlacklistedNBTTags() {
return new ArrayList<>(blacklistedNBTTags);
}
}