mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 02:59:42 +00:00
Large Auction Cleanup + Auction Events
- Auction Enums - Better Notification Handling - Auction Cancelation Events - Lang Key Cleanup
This commit is contained in:
1 parent
0512588a7a
commit
4510b3bbd1
31 files changed
+889
-578
No files matched your search
@@ -13,12 +13,13 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.Iterator;
|
||||
|
||||
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<>();
|
||||
private static volatile Set<String> blacklistedItems = new HashSet<>();
|
||||
private static volatile Set<Pattern> wildcardPatterns = new HashSet<>();
|
||||
private static volatile Set<String> blacklistedMods = new HashSet<>();
|
||||
private static volatile Set<String> blacklistedNBTTags = new HashSet<>();
|
||||
|
||||
// Built-in bound item requirement keys (always blocked)
|
||||
private static final String SOULBIND_KEY = "cnpc_soulbind";
|
||||
@@ -28,10 +29,10 @@ public class AuctionBlacklist {
|
||||
private static final String BYPASS_PERMISSION = "customnpcs.auction.blacklist.bypass";
|
||||
|
||||
public static void reload() {
|
||||
blacklistedItems.clear();
|
||||
wildcardPatterns.clear();
|
||||
blacklistedMods.clear();
|
||||
blacklistedNBTTags.clear();
|
||||
Set<String> newItems = new HashSet<>();
|
||||
Set<Pattern> newWildcards = new HashSet<>();
|
||||
Set<String> newMods = new HashSet<>();
|
||||
Set<String> newNBTTags = new HashSet<>();
|
||||
|
||||
// Load blacklisted items
|
||||
for (String item : ConfigMarket.BlacklistedItems) {
|
||||
@@ -40,23 +41,29 @@ public class AuctionBlacklist {
|
||||
|
||||
if (item.contains("*")) {
|
||||
String regex = "^" + item.replace(".", "\\.").replace("*", ".*") + "$";
|
||||
wildcardPatterns.add(Pattern.compile(regex));
|
||||
newWildcards.add(Pattern.compile(regex));
|
||||
} else {
|
||||
blacklistedItems.add(item);
|
||||
newItems.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
// Load blacklisted mods
|
||||
for (String mod : ConfigMarket.BlacklistedMods) {
|
||||
if (mod == null || mod.isEmpty()) continue;
|
||||
blacklistedMods.add(mod.toLowerCase().trim());
|
||||
newMods.add(mod.toLowerCase().trim());
|
||||
}
|
||||
|
||||
// Load blacklisted NBT tags
|
||||
for (String tag : ConfigMarket.BlacklistedNBTTags) {
|
||||
if (tag == null || tag.isEmpty()) continue;
|
||||
blacklistedNBTTags.add(tag.trim());
|
||||
newNBTTags.add(tag.trim());
|
||||
}
|
||||
|
||||
// Atomic swap
|
||||
blacklistedItems = newItems;
|
||||
wildcardPatterns = newWildcards;
|
||||
blacklistedMods = newMods;
|
||||
blacklistedNBTTags = newNBTTags;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,7 +85,6 @@ public class AuctionBlacklist {
|
||||
* 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")
|
||||
@@ -86,6 +92,8 @@ public class AuctionBlacklist {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!ConfigMarket.BlacklistEnabled) return false;
|
||||
|
||||
// Get registry name
|
||||
GameRegistry.UniqueIdentifier uid = GameRegistry.findUniqueIdentifierFor(item.getItem());
|
||||
if (uid == null) return true;
|
||||
@@ -172,9 +180,13 @@ public class AuctionBlacklist {
|
||||
|
||||
if (registryName.contains("*")) {
|
||||
String regex = "^" + registryName.replace(".", "\\.").replace("*", ".*") + "$";
|
||||
wildcardPatterns.add(Pattern.compile(regex));
|
||||
Set<Pattern> newWildcards = new HashSet<>(wildcardPatterns);
|
||||
newWildcards.add(Pattern.compile(regex));
|
||||
wildcardPatterns = newWildcards;
|
||||
} else {
|
||||
blacklistedItems.add(registryName);
|
||||
Set<String> newItems = new HashSet<>(blacklistedItems);
|
||||
newItems.add(registryName);
|
||||
blacklistedItems = newItems;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -185,30 +197,55 @@ public class AuctionBlacklist {
|
||||
|
||||
if (registryName.contains("*")) {
|
||||
String regex = "^" + registryName.replace(".", "\\.").replace("*", ".*") + "$";
|
||||
return wildcardPatterns.removeIf(p -> p.pattern().equals(regex));
|
||||
Set<Pattern> newWildcards = new HashSet<>(wildcardPatterns);
|
||||
boolean removed = false;
|
||||
Iterator<Pattern> it = newWildcards.iterator();
|
||||
while (it.hasNext()) {
|
||||
if (it.next().pattern().equals(regex)) {
|
||||
it.remove();
|
||||
removed = true;
|
||||
}
|
||||
}
|
||||
wildcardPatterns = newWildcards;
|
||||
return removed;
|
||||
} else {
|
||||
return blacklistedItems.remove(registryName);
|
||||
Set<String> newItems = new HashSet<>(blacklistedItems);
|
||||
boolean removed = newItems.remove(registryName);
|
||||
blacklistedItems = newItems;
|
||||
return removed;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean addMod(String modId) {
|
||||
if (modId == null || modId.isEmpty()) return false;
|
||||
return blacklistedMods.add(modId.toLowerCase().trim());
|
||||
Set<String> newMods = new HashSet<>(blacklistedMods);
|
||||
boolean added = newMods.add(modId.toLowerCase().trim());
|
||||
blacklistedMods = newMods;
|
||||
return added;
|
||||
}
|
||||
|
||||
public static boolean removeMod(String modId) {
|
||||
if (modId == null || modId.isEmpty()) return false;
|
||||
return blacklistedMods.remove(modId.toLowerCase().trim());
|
||||
Set<String> newMods = new HashSet<>(blacklistedMods);
|
||||
boolean removed = newMods.remove(modId.toLowerCase().trim());
|
||||
blacklistedMods = newMods;
|
||||
return removed;
|
||||
}
|
||||
|
||||
public static boolean addNBTTag(String tag) {
|
||||
if (tag == null || tag.isEmpty()) return false;
|
||||
return blacklistedNBTTags.add(tag.trim());
|
||||
Set<String> newTags = new HashSet<>(blacklistedNBTTags);
|
||||
boolean added = newTags.add(tag.trim());
|
||||
blacklistedNBTTags = newTags;
|
||||
return added;
|
||||
}
|
||||
|
||||
public static boolean removeNBTTag(String tag) {
|
||||
if (tag == null || tag.isEmpty()) return false;
|
||||
return blacklistedNBTTags.remove(tag.trim());
|
||||
Set<String> newTags = new HashSet<>(blacklistedNBTTags);
|
||||
boolean removed = newTags.remove(tag.trim());
|
||||
blacklistedNBTTags = newTags;
|
||||
return removed;
|
||||
}
|
||||
|
||||
// =========================================
|
||||
|
||||
@@ -140,7 +140,7 @@ public class AuctionClaim implements IAuctionClaim {
|
||||
|
||||
@Override
|
||||
public boolean isCurrencyClaim() {
|
||||
return type == EnumClaimType.CURRENCY;
|
||||
return type.isCurrency();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,16 +4,12 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import noppes.npcs.constants.EnumAuctionSort;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Filter for auction listings.
|
||||
* Supports search by item name or seller name and sorting options.
|
||||
*/
|
||||
public class AuctionFilter {
|
||||
private static final Pattern COLOR_CODE_PATTERN = Pattern.compile("§[0-9a-fk-or]", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
public String searchText;
|
||||
private String searchText;
|
||||
public EnumAuctionSort sortBy;
|
||||
|
||||
// Cached normalized search for efficiency
|
||||
@@ -32,9 +28,8 @@ public class AuctionFilter {
|
||||
/** Normalize string for search (strip colors, lowercase, trim) */
|
||||
public static String normalizeForSearch(String input) {
|
||||
if (input == null || input.isEmpty()) return "";
|
||||
String stripped = COLOR_CODE_PATTERN.matcher(input).replaceAll("");
|
||||
stripped = EnumChatFormatting.getTextWithoutFormattingCodes(stripped);
|
||||
return stripped.toLowerCase().trim();
|
||||
String stripped = EnumChatFormatting.getTextWithoutFormattingCodes(input);
|
||||
return stripped != null ? stripped.toLowerCase().trim() : input.toLowerCase().trim();
|
||||
}
|
||||
|
||||
/** Check if item name or seller name matches search text */
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.constants.EnumNotificationType;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class AuctionNotification {
|
||||
public String id;
|
||||
public UUID playerUUID;
|
||||
public EnumNotificationType type;
|
||||
public String listingId;
|
||||
public String message;
|
||||
public long timestamp;
|
||||
public boolean sent;
|
||||
|
||||
public AuctionNotification() {
|
||||
this.id = UUID.randomUUID().toString();
|
||||
this.timestamp = System.currentTimeMillis();
|
||||
this.sent = false;
|
||||
}
|
||||
|
||||
public AuctionNotification(UUID playerUUID, EnumNotificationType type, String listingId, String message) {
|
||||
this();
|
||||
this.playerUUID = playerUUID;
|
||||
this.type = type;
|
||||
this.listingId = listingId;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public boolean isForPlayer(UUID uuid) {
|
||||
return playerUUID != null && playerUUID.equals(uuid);
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
compound.setString("ID", id);
|
||||
compound.setString("PlayerUUID", playerUUID != null ? playerUUID.toString() : "");
|
||||
compound.setInteger("Type", type.ordinal());
|
||||
compound.setString("ListingID", listingId != null ? listingId : "");
|
||||
compound.setString("Message", message != null ? message : "");
|
||||
compound.setLong("Timestamp", timestamp);
|
||||
compound.setBoolean("Sent", sent);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
id = compound.getString("ID");
|
||||
|
||||
String playerUUIDStr = compound.getString("PlayerUUID");
|
||||
playerUUID = playerUUIDStr.isEmpty() ? null : UUID.fromString(playerUUIDStr);
|
||||
|
||||
type = EnumNotificationType.fromOrdinal(compound.getInteger("Type"));
|
||||
listingId = compound.getString("ListingID");
|
||||
message = compound.getString("Message");
|
||||
timestamp = compound.getLong("Timestamp");
|
||||
sent = compound.getBoolean("Sent");
|
||||
}
|
||||
|
||||
public static AuctionNotification fromNBT(NBTTagCompound compound) {
|
||||
AuctionNotification notification = new AuctionNotification();
|
||||
notification.readFromNBT(compound);
|
||||
return notification;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import noppes.npcs.api.handler.data.IAuctionClaim;
|
||||
import noppes.npcs.config.ConfigMarket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
@@ -129,12 +128,13 @@ public class PlayerTradeData implements IPlayerTradeData {
|
||||
|
||||
// Built-in currency
|
||||
long newBalance = this.balance + amount;
|
||||
if (newBalance > ConfigMarket.MaxBalance) {
|
||||
return false;
|
||||
}
|
||||
// Overflow protection
|
||||
if (newBalance < this.balance) {
|
||||
// Overflow protection
|
||||
return false;
|
||||
newBalance = ConfigMarket.MaxBalance;
|
||||
}
|
||||
// Cap at MaxBalance instead of rejecting
|
||||
if (newBalance > ConfigMarket.MaxBalance) {
|
||||
newBalance = ConfigMarket.MaxBalance;
|
||||
}
|
||||
this.balance = newBalance;
|
||||
this.lifetimeEarned += amount;
|
||||
@@ -341,18 +341,16 @@ public class PlayerTradeData implements IPlayerTradeData {
|
||||
*/
|
||||
public int processExpiredClaims() {
|
||||
int expirationDays = ConfigMarket.ClaimExpirationDays;
|
||||
int removed = 0;
|
||||
|
||||
Iterator<AuctionClaim> iterator = claims.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
AuctionClaim claim = iterator.next();
|
||||
List<AuctionClaim> expired = new ArrayList<>();
|
||||
for (AuctionClaim claim : claims) {
|
||||
if (!claim.claimed && claim.isExpired(expirationDays)) {
|
||||
claims.remove(claim);
|
||||
removed++;
|
||||
expired.add(claim);
|
||||
}
|
||||
}
|
||||
|
||||
return removed;
|
||||
if (!expired.isEmpty()) {
|
||||
claims.removeAll(expired);
|
||||
}
|
||||
return expired.size();
|
||||
}
|
||||
|
||||
// =========================================
|
||||
|
||||
Reference in new issue
Block a user