mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-21 06:52:21 +00:00
Merge branch 'dev' into syntax-highlighter-unified
This commit is contained in:
commit
df6beb4f15
207 files changed
+10330
-2705
No files matched your search
@@ -10,15 +10,16 @@ import noppes.npcs.config.ConfigMarket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
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<>();
|
||||
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;
|
||||
}
|
||||
|
||||
// =========================================
|
||||
|
||||
@@ -33,7 +33,9 @@ public class AuctionClaim implements IAuctionClaim {
|
||||
this.otherPlayerName = "";
|
||||
}
|
||||
|
||||
/** Create claim for winning an item (buyer won auction or buyout) */
|
||||
/**
|
||||
* Create claim for winning an item (buyer won auction or buyout)
|
||||
*/
|
||||
public static AuctionClaim createItemWonClaim(UUID playerUUID, String playerName, String listingId, ItemStack item) {
|
||||
AuctionClaim claim = new AuctionClaim();
|
||||
claim.playerUUID = playerUUID;
|
||||
@@ -46,7 +48,9 @@ public class AuctionClaim implements IAuctionClaim {
|
||||
return claim;
|
||||
}
|
||||
|
||||
/** Create claim for returned item (seller's expired/cancelled listing) */
|
||||
/**
|
||||
* Create claim for returned item (seller's expired/cancelled listing)
|
||||
*/
|
||||
public static AuctionClaim createItemReturnedClaim(UUID playerUUID, String playerName, String listingId, ItemStack item) {
|
||||
AuctionClaim claim = new AuctionClaim();
|
||||
claim.playerUUID = playerUUID;
|
||||
@@ -59,7 +63,9 @@ public class AuctionClaim implements IAuctionClaim {
|
||||
return claim;
|
||||
}
|
||||
|
||||
/** Create claim for seller's proceeds (stores item name for tooltip, not full item) */
|
||||
/**
|
||||
* Create claim for seller's proceeds (stores item name for tooltip, not full item)
|
||||
*/
|
||||
public static AuctionClaim createCurrencyClaim(UUID playerUUID, String playerName, String listingId, long currency, String itemName, String buyerName) {
|
||||
AuctionClaim claim = new AuctionClaim();
|
||||
claim.playerUUID = playerUUID;
|
||||
@@ -74,7 +80,9 @@ public class AuctionClaim implements IAuctionClaim {
|
||||
return claim;
|
||||
}
|
||||
|
||||
/** Create claim for outbid refund (stores item for display and rebid option) */
|
||||
/**
|
||||
* Create claim for outbid refund (stores item for display and rebid option)
|
||||
*/
|
||||
public static AuctionClaim createRefundClaim(UUID playerUUID, String playerName, String listingId, long currency, String itemName, String outbidderName, ItemStack item) {
|
||||
AuctionClaim claim = new AuctionClaim();
|
||||
claim.playerUUID = playerUUID;
|
||||
@@ -140,7 +148,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
|
||||
@@ -29,15 +25,18 @@ public class AuctionFilter {
|
||||
return searchText != null && !searchText.trim().isEmpty();
|
||||
}
|
||||
|
||||
/** Normalize string for search (strip colors, lowercase, trim) */
|
||||
/**
|
||||
* 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 */
|
||||
/**
|
||||
* Check if item name or seller name matches search text
|
||||
*/
|
||||
public boolean matchesSearch(String itemName, String sellerName) {
|
||||
if (!hasSearchText()) return true;
|
||||
String normalizedItem = normalizeForSearch(itemName);
|
||||
@@ -46,12 +45,16 @@ public class AuctionFilter {
|
||||
return normalizedItem.contains(normalizedSearch) || normalizedSeller.contains(normalizedSearch);
|
||||
}
|
||||
|
||||
/** Legacy method - only checks item name */
|
||||
/**
|
||||
* Legacy method - only checks item name
|
||||
*/
|
||||
public boolean matchesSearch(String itemName) {
|
||||
return matchesSearch(itemName, "");
|
||||
}
|
||||
|
||||
/** Advanced search - all words must be present in item name OR seller name */
|
||||
/**
|
||||
* Advanced search - all words must be present in item name OR seller name
|
||||
*/
|
||||
public boolean matchesSearchAdvanced(String itemName, String sellerName) {
|
||||
if (!hasSearchText()) return true;
|
||||
String normalizedItem = normalizeForSearch(itemName);
|
||||
@@ -68,7 +71,9 @@ public class AuctionFilter {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Legacy method - only checks item name */
|
||||
/**
|
||||
* Legacy method - only checks item name
|
||||
*/
|
||||
public boolean matchesSearchAdvanced(String itemName) {
|
||||
return matchesSearchAdvanced(itemName, "");
|
||||
}
|
||||
@@ -106,13 +111,20 @@ public class AuctionFilter {
|
||||
}
|
||||
|
||||
// Getters and setters
|
||||
public String getSearchText() { return searchText; }
|
||||
public String getSearchText() {
|
||||
return searchText;
|
||||
}
|
||||
|
||||
public void setSearchText(String searchText) {
|
||||
this.searchText = searchText;
|
||||
this.normalizedSearch = normalizeForSearch(searchText);
|
||||
}
|
||||
|
||||
public EnumAuctionSort getSortBy() { return sortBy; }
|
||||
public void setSortBy(EnumAuctionSort sortBy) { this.sortBy = sortBy; }
|
||||
public EnumAuctionSort getSortBy() {
|
||||
return sortBy;
|
||||
}
|
||||
|
||||
public void setSortBy(EnumAuctionSort sortBy) {
|
||||
this.sortBy = sortBy;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ public class BuiltInAnimation extends Animation {
|
||||
|
||||
/**
|
||||
* Built-in animations cannot be saved.
|
||||
*
|
||||
* @return this animation unchanged
|
||||
*/
|
||||
@Override
|
||||
@@ -33,6 +34,7 @@ public class BuiltInAnimation extends Animation {
|
||||
|
||||
/**
|
||||
* Built-in animations have no valid ID.
|
||||
*
|
||||
* @return always -1
|
||||
*/
|
||||
@Override
|
||||
@@ -50,6 +52,7 @@ public class BuiltInAnimation extends Animation {
|
||||
|
||||
/**
|
||||
* Check if this is a built-in animation.
|
||||
*
|
||||
* @return always true for BuiltInAnimation
|
||||
*/
|
||||
public boolean isBuiltIn() {
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityPhase;
|
||||
import kamkeel.npcs.controllers.data.ability.ChainedAbility;
|
||||
import kamkeel.npcs.controllers.data.ability.IAbilityAction;
|
||||
import kamkeel.npcs.controllers.data.ability.ToggleEntry;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityGuard;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.network.packets.data.ability.PlayerAbilityStatePacket;
|
||||
import kamkeel.npcs.network.packets.data.ability.PlayerAbilitySyncPacket;
|
||||
import kamkeel.npcs.network.packets.data.telegraph.TelegraphRemovePacket;
|
||||
import kamkeel.npcs.network.packets.data.telegraph.TelegraphSpawnPacket;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
@@ -15,22 +20,18 @@ import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import noppes.npcs.AbstractDataAbilities;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.api.ability.IPlayerAbilityData;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.controllers.AnimationController;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.event.player.PlayerAbilityEvent;
|
||||
|
||||
import kamkeel.npcs.network.packets.data.ability.PlayerAbilityStatePacket;
|
||||
import kamkeel.npcs.network.packets.data.ability.PlayerAbilitySyncPacket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Manages player ability data - unlocked abilities, selection, cooldowns, and execution.
|
||||
@@ -152,7 +153,7 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
|
||||
@Override
|
||||
protected void fireInterruptEvent(Ability ability, EntityLivingBase target,
|
||||
DamageSource source, float damage) {
|
||||
DamageSource source, float damage) {
|
||||
EntityPlayer player = playerData.player;
|
||||
if (ScriptController.Instance == null || player == null) return;
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
|
||||
@@ -229,6 +230,11 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void rollChainCooldown(ChainedAbility chain) {
|
||||
cooldownEndTime = getWorldTime() + chain.getCooldownTicks();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAbilityComplete() {
|
||||
currentAbility = null;
|
||||
@@ -263,7 +269,10 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentAbility != null && currentAbility.isExecuting()) {
|
||||
// Tick active toggles (independent of currentAbility)
|
||||
tickActiveToggles();
|
||||
|
||||
if (chainDelayRemaining > 0 || (currentAbility != null && currentAbility.isExecuting())) {
|
||||
tickCurrentAbility();
|
||||
|
||||
// Apply rotation and position locks after ability tick
|
||||
@@ -303,10 +312,27 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate a specific ability by key.
|
||||
* Prefix used to identify chained ability keys in the unlocked list.
|
||||
*/
|
||||
public static final String CHAIN_PREFIX = "chain:";
|
||||
|
||||
/**
|
||||
* Resolve an action key to an IAbilityAction.
|
||||
* Handles "chain:" prefix for chained abilities, otherwise resolves from AbilityController.
|
||||
*/
|
||||
private IAbilityAction resolveActionKey(String key) {
|
||||
if (key.startsWith(CHAIN_PREFIX)) {
|
||||
return AbilityController.Instance.resolveChainedAbility(key.substring(CHAIN_PREFIX.length()));
|
||||
}
|
||||
return AbilityController.Instance.resolveAbility(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate a specific ability by key. Keys prefixed with "chain:" are
|
||||
* treated as chained abilities and resolved from {@link AbilityController}.
|
||||
*
|
||||
* @param player The player
|
||||
* @param key The ability key (built-in or preset name)
|
||||
* @param key The ability key (built-in or preset name), or "chain:name" for chains
|
||||
* @return true if the ability was started
|
||||
*/
|
||||
public boolean activateAbility(EntityPlayer player, String key) {
|
||||
@@ -314,20 +340,32 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
|
||||
// Can't activate if already executing
|
||||
if (currentAbility != null && currentAbility.isExecuting()) return false;
|
||||
if (isExecutingChain()) return false;
|
||||
|
||||
// Resolve ability from controller
|
||||
if (AbilityController.Instance == null) return false;
|
||||
Ability ability = AbilityController.Instance.resolveAbility(key);
|
||||
if (ability == null) return false;
|
||||
// Resolve via unified resolver
|
||||
IAbilityAction action = resolveActionKey(key);
|
||||
if (action == null) return false;
|
||||
|
||||
// Check user type allows player
|
||||
if (!ability.getAllowedBy().allowsPlayer()) return false;
|
||||
|
||||
// Check universal cooldown
|
||||
if (!ability.isIgnoreCooldown() && isOnCooldown()) return false;
|
||||
if (!action.getAllowedBy().allowsPlayer()) return false;
|
||||
|
||||
// Check conditions (skip target-requiring ones)
|
||||
if (!ability.checkConditionsForPlayer(player)) return false;
|
||||
if (!action.checkConditionsForPlayer(player)) return false;
|
||||
|
||||
// Dispatch: chain vs ability
|
||||
if (action.isChain()) {
|
||||
if (isOnCooldown()) return false;
|
||||
|
||||
currentAbilityKey = key;
|
||||
currentTarget = null;
|
||||
return startChain((ChainedAbility) action, null);
|
||||
}
|
||||
|
||||
// Regular ability activation
|
||||
Ability ability = (Ability) action;
|
||||
|
||||
// Check universal cooldown (abilities can optionally ignore it)
|
||||
if (!ability.isIgnoreCooldown() && isOnCooldown()) return false;
|
||||
|
||||
// Fire extender start hook (e.g., resource cost checks)
|
||||
if (!AbilityController.Instance.fireOnAbilityStart(ability, player, null)) {
|
||||
@@ -385,6 +423,34 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onToggleStateChanged(String key, boolean active, int state) {
|
||||
syncToClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean fireToggleEvent(Ability ability, int oldState, int newState) {
|
||||
EntityPlayer player = playerData.player;
|
||||
if (ScriptController.Instance == null || player == null) return false;
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
|
||||
if (handler == null) return false;
|
||||
IPlayer iPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
|
||||
PlayerAbilityEvent.ToggleEvent event = new PlayerAbilityEvent.ToggleEvent(iPlayer, ability, oldState, newState);
|
||||
return EventHooks.onPlayerAbilityToggle(handler, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean fireToggleUpdateEvent(Ability ability, int tick, int state) {
|
||||
EntityPlayer player = playerData.player;
|
||||
if (ScriptController.Instance == null || player == null) return true;
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
|
||||
if (handler == null) return true;
|
||||
IPlayer iPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
|
||||
PlayerAbilityEvent.ToggleUpdateEvent event = new PlayerAbilityEvent.ToggleUpdateEvent(iPlayer, ability, tick, state);
|
||||
EventHooks.onPlayerAbilityToggleUpdate(handler, event);
|
||||
return event.isEnabled();
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// SELECTION
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -540,6 +606,51 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
interruptCurrentAbility(null, 0);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// DIMENSION CHANGE RESET
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Fully reset ability state when changing dimensions.
|
||||
* Unlike interruptCurrentAbility(), this does NOT roll any cooldowns
|
||||
* and ensures the player can immediately use abilities in the new dimension.
|
||||
* Also re-syncs to client since the entity may be re-created.
|
||||
*/
|
||||
public void resetOnDimensionChange() {
|
||||
// Clean up any executing ability without rolling cooldowns
|
||||
if (currentAbility != null && currentAbility.isExecuting()) {
|
||||
removeTelegraph(currentAbility);
|
||||
currentAbility.cleanup();
|
||||
currentAbility.interrupt();
|
||||
stopAbilityAnimation();
|
||||
releaseRotationControl();
|
||||
releaseLockedPosition();
|
||||
}
|
||||
|
||||
// Clear chain state
|
||||
currentChain = null;
|
||||
chainEntryIndex = -1;
|
||||
chainDelayRemaining = -1;
|
||||
|
||||
// Clear all transient state
|
||||
currentAbility = null;
|
||||
currentAbilityKey = null;
|
||||
currentTarget = null;
|
||||
|
||||
// Reset cooldowns completely
|
||||
cooldownEndTime = 0;
|
||||
interruptCooldownRolled = false;
|
||||
|
||||
// Sync cleared state to client
|
||||
EntityPlayer player = playerData.player;
|
||||
if (player != null) {
|
||||
syncAbilityStateClear(player);
|
||||
}
|
||||
|
||||
// Re-sync ability data (unlocked list, selection) to client
|
||||
syncToClient();
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// DAMAGE HANDLING
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -750,6 +861,16 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
compound.setTag("PlayerAbilities", list);
|
||||
compound.setInteger("PlayerAbilitySelected", selectedIndex);
|
||||
compound.setBoolean("AbilityAnimating", playingAbilityAnimation);
|
||||
|
||||
// Active toggles (compound format with state)
|
||||
NBTTagList toggleList = new NBTTagList();
|
||||
for (Map.Entry<String, ToggleEntry> entry : activeToggles.entrySet()) {
|
||||
NBTTagCompound toggleNbt = new NBTTagCompound();
|
||||
toggleNbt.setString("Key", entry.getKey());
|
||||
toggleNbt.setInteger("State", entry.getValue().getState());
|
||||
toggleList.appendTag(toggleNbt);
|
||||
}
|
||||
compound.setTag("ActiveToggles", toggleList);
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
@@ -772,11 +893,24 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
selectedIndex = Math.max(0, unlockedAbilities.size() - 1);
|
||||
}
|
||||
playingAbilityAnimation = compound.getBoolean("AbilityAnimating");
|
||||
|
||||
// Active toggles - restore state directly (no onToggleOn callback during load)
|
||||
activeToggles.clear();
|
||||
if (compound.hasKey("ActiveToggles")) {
|
||||
NBTTagList toggleNbt = compound.getTagList("ActiveToggles", 10); // 10 = TAG_COMPOUND
|
||||
for (int i = 0; i < toggleNbt.tagCount(); i++) {
|
||||
NBTTagCompound entry = toggleNbt.getCompoundTagAt(i);
|
||||
String key = entry.getString("Key");
|
||||
int state = entry.hasKey("State") ? entry.getInteger("State") : 1;
|
||||
setToggleEntryDirect(key, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove any unlocked ability keys that can no longer be resolved.
|
||||
* Called during load to clean up references to deleted abilities.
|
||||
* Supports both regular ability keys and "chain:" prefixed chained ability keys.
|
||||
*/
|
||||
private void validateUnlockedAbilities() {
|
||||
if (AbilityController.Instance == null) return;
|
||||
@@ -784,7 +918,8 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
Iterator<String> it = unlockedAbilities.iterator();
|
||||
while (it.hasNext()) {
|
||||
String key = it.next();
|
||||
if (!AbilityController.Instance.canResolveAbility(key)) {
|
||||
IAbilityAction resolved = resolveActionKey(key);
|
||||
if (resolved == null) {
|
||||
it.remove();
|
||||
LogWriter.info("Removed invalid ability reference from player data: " + key);
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@ import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.api.ability.IPlayerAbilityData;
|
||||
import noppes.npcs.api.entity.ICustomNpc;
|
||||
import noppes.npcs.api.handler.IPlayerBankData;
|
||||
import noppes.npcs.api.handler.IPlayerTradeData;
|
||||
import noppes.npcs.api.handler.IPlayerData;
|
||||
import noppes.npcs.api.handler.IPlayerDialogData;
|
||||
import noppes.npcs.api.handler.IPlayerFactionData;
|
||||
import noppes.npcs.api.handler.IPlayerItemGiverData;
|
||||
import noppes.npcs.api.handler.IPlayerMailData;
|
||||
import noppes.npcs.api.handler.IPlayerQuestData;
|
||||
import noppes.npcs.api.handler.IPlayerTradeData;
|
||||
import noppes.npcs.api.handler.IPlayerTransportData;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.constants.EnumRoleType;
|
||||
@@ -47,8 +47,6 @@ import java.io.FileOutputStream;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import static noppes.npcs.util.CustomNPCsThreader.customNPCThread;
|
||||
|
||||
public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
public PlayerDialogData dialogData = new PlayerDialogData(this);
|
||||
public PlayerBankData bankData = new PlayerBankData(this);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
// =========================================
|
||||
|
||||
@@ -345,10 +345,10 @@ public class Action implements IAction {
|
||||
try {
|
||||
onStart.accept(this);
|
||||
} catch (Throwable t) {
|
||||
String err = "IAction" + getName() + " onStart threw an exception:";
|
||||
String err = "IAction" + getName() + " onStart threw an exception:";
|
||||
if (reportTo != null)
|
||||
reportTo.appendConsole(err + "\n" + ExceptionUtils.getStackTrace(t));
|
||||
|
||||
|
||||
manager.LOGGER.error("onStart Task of " + this + " threw an exception:", t);
|
||||
}
|
||||
|
||||
@@ -384,7 +384,7 @@ public class Action implements IAction {
|
||||
try {
|
||||
onDone.accept(this);
|
||||
} catch (Throwable t) {
|
||||
String err = "IAction" + getName() + " onDone threw an exception:";
|
||||
String err = "IAction" + getName() + " onDone threw an exception:";
|
||||
if (reportTo != null)
|
||||
reportTo.appendConsole(err + "\n" + ExceptionUtils.getStackTrace(t));
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ public class ConditionalAction extends Action implements IConditionalAction {
|
||||
String err = "IConditionalAction '" + getName() + "' threw an exception:";
|
||||
if (reportTo != null)
|
||||
reportTo.appendConsole(err + "\n" + ExceptionUtils.getStackTrace(t));
|
||||
|
||||
|
||||
manager.LOGGER.error("Task of " + this + " threw an exception:", t);
|
||||
markDone();
|
||||
}
|
||||
@@ -151,7 +151,7 @@ public class ConditionalAction extends Action implements IConditionalAction {
|
||||
try {
|
||||
onTermination.accept(this);
|
||||
} catch (Throwable t) {
|
||||
String err = "IConditionalAction" + getName() + " onTermination threw an exception:";
|
||||
String err = "IConditionalAction" + getName() + " onTermination threw an exception:";
|
||||
if (reportTo != null)
|
||||
reportTo.appendConsole(err + "\n" + ExceptionUtils.getStackTrace(t));
|
||||
|
||||
|
||||
Reference in new issue
Block a user