Merge remote-tracking branch 'origin/syntax-highlighter-unified' into syntax-highlighter-unified

This commit is contained in:
bigguy345 committed 2026-02-25 17:14:12 +02:00
commit f9f1cb760c
66 files changed
+1471 -610

No files matched your search

+5 -2
View File
@@ -26,6 +26,7 @@ import kamkeel.npcs.controllers.AttributeController;
import kamkeel.npcs.controllers.ProfileController;
import kamkeel.npcs.controllers.SyncController;
import kamkeel.npcs.controllers.TelegraphController;
import kamkeel.npcs.controllers.data.energycharge.EnergyChargeTracker;
import kamkeel.npcs.controllers.data.profile.CNPCData;
import kamkeel.npcs.developer.Developer;
import kamkeel.npcs.entity.EntityAbilityBarrier;
@@ -37,6 +38,7 @@ import kamkeel.npcs.entity.EntityAbilityPanel;
import kamkeel.npcs.entity.EntityAbilitySweeper;
import kamkeel.npcs.entity.EntityAbilityZone;
import kamkeel.npcs.entity.EntityAbilityDome;
import kamkeel.npcs.entity.EntityEnergyProjectile;
import kamkeel.npcs.entity.EntityEnergySlicer;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.util.BukkitUtil;
@@ -122,7 +124,7 @@ import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;
@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.11-beta9")
@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.11-beta10")
public class CustomNpcs {
@SidedProxy(clientSide = "noppes.npcs.client.ClientProxy", serverSide = "noppes.npcs.CommonProxy")
@@ -430,8 +432,9 @@ public class CustomNpcs {
AuctionController.Instance.save();
}
kamkeel.npcs.entity.EntityEnergyProjectile.clearAllProjectiles();
EntityEnergyProjectile.clearAllProjectiles();
EntityAbilityBarrier.clearAllBarriers();
EnergyChargeTracker.Instance.clear();
if (FMLCommonHandler.instance().getSide().isClient())
clientJaninoCompiler = null;
@@ -147,10 +147,7 @@ public class ScriptPlayerEventHandler {
EntityPlayerMP mp = (EntityPlayerMP) player;
SyncController.syncEffects(mp);
SyncController.syncAbilityCooldowns(mp);
if (playerData.abilityData.needsSync) {
PlayerAbilitySyncPacket.sendToPlayer(mp);
playerData.abilityData.needsSync = false;
}
PlayerAbilitySyncPacket.sendToPlayer(mp);
playerData.abilityData.ensureLockStateClear();
}
@@ -4,6 +4,7 @@ import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import kamkeel.npcs.controllers.SyncController;
import kamkeel.npcs.controllers.data.energycharge.EnergyChargeTracker;
import kamkeel.npcs.entity.EntityAbilityBarrier;
import kamkeel.npcs.entity.EntityAbilityDome;
import kamkeel.npcs.network.PacketHandler;
@@ -300,6 +301,7 @@ public class ServerEventsHandler {
public void invoke(LivingDeathEvent event) {
if (event.entityLiving.worldObj.isRemote)
return;
EnergyChargeTracker.Instance.removeAllForCaster(event.entityLiving.getEntityId());
if (event.source.getEntity() != null) {
if (event.source.getEntity() instanceof EntityPlayer) {
doExcalibur((EntityPlayer) event.source.getEntity(), event.entityLiving);
@@ -535,7 +537,19 @@ public class ServerEventsHandler {
@SubscribeEvent
public void playerTracking(PlayerEvent.StartTracking event) {
if (!(event.target instanceof EntityPlayerMP || event.target instanceof EntityNPCInterface) || event.target.worldObj.isRemote)
if (event.target.worldObj.isRemote) return;
// Energy charge visuals: send active charges for newly tracked entity
if (event.target instanceof EntityLivingBase
&& event.entityPlayer instanceof EntityPlayerMP) {
EnergyChargeTracker.Instance.sendToPlayer(
event.target.getEntityId(),
(EntityPlayerMP) event.entityPlayer,
(int) event.target.worldObj.getTotalWorldTime()
);
}
if (!(event.target instanceof EntityPlayerMP || event.target instanceof EntityNPCInterface))
return;
AnimationData animationData = AnimationData.getData(event.target);
@@ -25,9 +25,6 @@ import java.util.Map;
import java.util.Set;
public class FlyPathFinder extends PathFinder {
private static final float STRAIGHT_COST = 1.0F;
private static final float DIAGONAL_2D_COST = 1.4142135F;
private static final float DIAGONAL_3D_COST = 1.7320508F;
/**
* Used to find obstacles
*/
@@ -144,7 +141,7 @@ public class FlyPathFinder extends PathFinder {
private NPCPath addToPath(Entity p_75861_1_, NPCPathPoint p_75861_2_, NPCPathPoint p_75861_3_, NPCPathPoint p_75861_4_, float p_75861_5_) {
p_75861_2_.totalPathDistance = 0.0F;
p_75861_2_.distanceToNext = this.estimateCostToTarget(p_75861_2_, p_75861_3_);
p_75861_2_.distanceToNext = p_75861_2_.distanceToSquared(p_75861_3_);
p_75861_2_.distanceToTarget = p_75861_2_.distanceToNext;
this.path.clearPath();
this.path.addPoint(p_75861_2_);
@@ -164,7 +161,7 @@ public class FlyPathFinder extends PathFinder {
return this.createEntityPath(p_75861_2_, p_75861_3_);
}
if (this.estimateCostToTarget(pathpoint4, p_75861_3_) < this.estimateCostToTarget(pathpoint3, p_75861_3_)) {
if (pathpoint4.distanceToSquared(p_75861_3_) < pathpoint3.distanceToSquared(p_75861_3_)) {
pathpoint3 = pathpoint4;
}
@@ -173,13 +170,12 @@ public class FlyPathFinder extends PathFinder {
for (int j = 0; j < i; ++j) {
NPCPathPoint pathpoint5 = this.pathOptions[j];
float f1 = pathpoint4.totalPathDistance + this.getTraversalCost(pathpoint4, pathpoint5)
+ this.getDirectionalPenalty(pathpoint4, pathpoint5, p_75861_3_);
float f1 = pathpoint4.totalPathDistance + pathpoint4.distanceToSquared(pathpoint5);
if (!pathpoint5.isAssigned() || f1 < pathpoint5.totalPathDistance) {
pathpoint5.previous = pathpoint4;
pathpoint5.totalPathDistance = f1;
pathpoint5.distanceToNext = this.estimateCostToTarget(pathpoint5, p_75861_3_);
pathpoint5.distanceToNext = pathpoint5.distanceToSquared(p_75861_3_);
if (pathpoint5.isAssigned()) {
this.path.changeDistance(pathpoint5, pathpoint5.totalPathDistance + pathpoint5.distanceToNext);
@@ -198,50 +194,6 @@ public class FlyPathFinder extends PathFinder {
}
}
private float getTraversalCost(NPCPathPoint from, NPCPathPoint to) {
int dx = Math.abs(to.xCoord - from.xCoord);
int dy = Math.abs(to.yCoord - from.yCoord);
int dz = Math.abs(to.zCoord - from.zCoord);
int changedAxes = dx + dy + dz;
if (changedAxes <= 1) {
return STRAIGHT_COST;
}
if (changedAxes == 2) {
return DIAGONAL_2D_COST;
}
return DIAGONAL_3D_COST;
}
private float getDirectionalPenalty(NPCPathPoint from, NPCPathPoint to, NPCPathPoint goal) {
int stepX = to.xCoord - from.xCoord;
int stepY = to.yCoord - from.yCoord;
int stepZ = to.zCoord - from.zCoord;
int goalX = goal.xCoord - from.xCoord;
int goalY = goal.yCoord - from.yCoord;
int goalZ = goal.zCoord - from.zCoord;
int stepLen = Math.abs(stepX) + Math.abs(stepY) + Math.abs(stepZ);
int goalLen = Math.abs(goalX) + Math.abs(goalY) + Math.abs(goalZ);
if (stepLen == 0 || goalLen == 0) {
return 0.0F;
}
float alignment = (float) (stepX * goalX + stepY * goalY + stepZ * goalZ) / (float) (stepLen * goalLen);
return (1.0F - alignment) * 0.04F;
}
private float estimateCostToTarget(NPCPathPoint from, NPCPathPoint to) {
float dx = Math.abs(to.xCoord - from.xCoord);
float dy = Math.abs(to.yCoord - from.yCoord);
float dz = Math.abs(to.zCoord - from.zCoord);
float max = Math.max(dx, Math.max(dy, dz));
float min = Math.min(dx, Math.min(dy, dz));
float mid = dx + dy + dz - max - min;
return DIAGONAL_3D_COST * min + DIAGONAL_2D_COST * (mid - min) + STRAIGHT_COST * (max - mid);
}
/**
* populates pathOptions with available points and returns the number of options found (args: unused1, currentPoint,
* unused2, targetPoint, maxDistance)
@@ -7,8 +7,6 @@ import noppes.npcs.entity.EntityNPCFlying;
import noppes.npcs.entity.EntityNPCInterface;
public class FlyingMoveHelper extends EntityMoveHelper {
private static final double CLOSE_ENOUGH_SQ = 0.01D;
private static final float MAX_TURN_PER_TICK = 35.0F;
private final EntityNPCInterface entity;
private double posX;
@@ -40,24 +38,22 @@ public class FlyingMoveHelper extends EntityMoveHelper {
double d5 = MathHelper.sqrt_double(d4);
speed = Math.min(d5 / 5.0D, speed);
if (d4 > CLOSE_ENOUGH_SQ && d5 > 1.0E-4D) {
double targetMotionX = speed * (d0 / d5);
double targetMotionZ = speed * (d2 / d5);
double horizontalLerp = Math.min(1.0D, Math.max(0.12D, speed * 0.6D));
this.entity.motionX += (targetMotionX - this.entity.motionX) * horizontalLerp;
this.entity.motionZ += (targetMotionZ - this.entity.motionZ) * horizontalLerp;
// its here louis!
// This is the hurt time that stuns the NPC!!!!!!
// if (this.entity.hurtTime == 0 && d4 > 0.5D) {
if (d4 >= 0.5D) {
this.entity.motionX += (speed * (d0 / d5) - this.entity.motionX) * speed;
this.entity.motionZ += (speed * (d2 / d5) - this.entity.motionZ) * speed;
if (((EntityNPCFlying) this.entity).flyLimitAllow || !this.entity.ais.hasFlyLimit) {
double targetMotionY = verticalSpeed * (d1 / d5);
if (targetMotionY > 0.0D) {
targetMotionY += 0.05D;
this.entity.motionY = verticalSpeed * (d1 / d5);
if (this.entity.motionY > 0) {
this.entity.motionY += 0.1D;
}
double verticalLerp = Math.min(1.0D, Math.max(0.15D, verticalSpeed * 0.85D));
this.entity.motionY += (targetMotionY - this.entity.motionY) * verticalLerp;
}
this.entity.velocityChanged = true;
this.entity.rotationYaw = this.limitAngle(this.entity.rotationYaw, (float) ((Math.atan2(-d0, -d2) + Math.PI) * -(180F / Math.PI)), MAX_TURN_PER_TICK);
this.entity.rotationYaw = this.limitAngle(this.entity.rotationYaw, (float) ((Math.atan2(-d0, -d2) + Math.PI) * -(180F / Math.PI)), 20.0F);
}
}
}
@@ -21,10 +21,6 @@ import noppes.npcs.entity.EntityNPCInterface;
import javax.annotation.Nullable;
public class PathNavigateFlying extends PathNavigate {
private static final long MIN_REPATH_INTERVAL_TICKS = 8L;
private static final long MAX_REPATH_INTERVAL_TICKS = 30L;
private static final int PATH_REUSE_TARGET_DELTA_SQ = 2;
private static final int FINAL_NODE_REUSE_DELTA_SQ = 3;
private EntityNPCInterface theEntity;
private World worldObj;
@@ -87,21 +83,16 @@ public class PathNavigateFlying extends PathNavigate {
}
public void updatePath() {
if (this.targetPos == null) {
this.tryUpdatePath = false;
return;
}
long now = this.worldObj.getTotalWorldTime();
if (now - this.lastTimeUpdated < this.getAdaptiveRepathInterval()) {
if (this.worldObj.getTotalWorldTime() - this.lastTimeUpdated > 20L) {
if (this.targetPos != null) {
this.currentPath = null;
this.currentPath = this.getPathToXYZ(this.targetPos.getX(), this.targetPos.getY(), this.targetPos.getZ());
this.lastTimeUpdated = this.worldObj.getTotalWorldTime();
this.tryUpdatePath = false;
}
} else {
this.tryUpdatePath = true;
return;
}
this.currentPath = null;
this.currentPath = this.getPathToXYZ(this.targetPos.getX(), this.targetPos.getY(), this.targetPos.getZ());
this.lastTimeUpdated = now;
this.tryUpdatePath = false;
}
public void setAvoidsWater(boolean p_75491_1_) {
@@ -165,8 +156,7 @@ public class PathNavigateFlying extends PathNavigate {
BlockPos pos = new BlockPos(x, y, z);
if (!this.canNavigate()) {
return null;
} else if (this.canReuseCurrentPath(pos)) {
this.targetPos = pos;
} else if (this.currentPath != null && !this.currentPath.isFinished() && pos.equals(this.targetPos)) {
return this.currentPath;
} else {
this.targetPos = pos;
@@ -190,8 +180,7 @@ public class PathNavigateFlying extends PathNavigate {
return null;
} else {
BlockPos blockpos = new BlockPos(entity);
if (this.canReuseCurrentPath(blockpos)) {
this.targetPos = blockpos;
if (this.currentPath != null && !this.currentPath.isFinished() && blockpos.equals(this.targetPos)) {
return this.currentPath;
} else {
this.targetPos = blockpos;
@@ -226,8 +215,6 @@ public class PathNavigateFlying extends PathNavigate {
this.removeSunnyPath();
}
this.smoothCurrentPath();
if (this.currentPath.getCurrentPathLength() == 0) {
return false;
} else {
@@ -255,72 +242,6 @@ public class PathNavigateFlying extends PathNavigate {
return !this.isInLiquid() || (this.canSwim && this.isInLiquid());
}
private long getAdaptiveRepathInterval() {
if (this.targetPos == null) {
return MAX_REPATH_INTERVAL_TICKS;
}
double distance = this.theEntity.getDistance(this.targetPos.getX() + 0.5D, this.targetPos.getY(), this.targetPos.getZ() + 0.5D);
return (long) MathHelper.clamp_double(distance * 0.6D, MIN_REPATH_INTERVAL_TICKS, MAX_REPATH_INTERVAL_TICKS);
}
private boolean canReuseCurrentPath(BlockPos newTarget) {
if (this.currentPath == null || this.currentPath.isFinished() || this.targetPos == null) {
return false;
}
if (this.getBlockDistanceSq(this.targetPos, newTarget) <= PATH_REUSE_TARGET_DELTA_SQ) {
return true;
}
NPCPathPoint finalPoint = this.currentPath.getFinalPathPoint();
return finalPoint != null && this.getPointDistanceSq(finalPoint, newTarget) <= FINAL_NODE_REUSE_DELTA_SQ;
}
private int getBlockDistanceSq(BlockPos a, BlockPos b) {
int dx = a.getX() - b.getX();
int dy = a.getY() - b.getY();
int dz = a.getZ() - b.getZ();
return dx * dx + dy * dy + dz * dz;
}
private int getPointDistanceSq(NPCPathPoint point, BlockPos blockPos) {
int dx = point.xCoord - blockPos.getX();
int dy = point.yCoord - blockPos.getY();
int dz = point.zCoord - blockPos.getZ();
return dx * dx + dy * dy + dz * dz;
}
private void smoothCurrentPath() {
if (this.currentPath == null) {
return;
}
int pathLength = this.currentPath.getCurrentPathLength();
if (pathLength < 3) {
return;
}
int width = MathHelper.ceiling_double_int(this.theEntity.width);
int height = MathHelper.ceiling_double_int(this.theEntity.height + 1.0F);
NPCPathPoint[] points = this.currentPath.points;
int writeIndex = 1;
int anchorIndex = 0;
for (int readIndex = 2; readIndex < pathLength; readIndex++) {
Vec3 anchor = this.currentPath.getVectorFromIndex(this.theEntity, anchorIndex);
Vec3 probe = this.currentPath.getVectorFromIndex(this.theEntity, readIndex);
if (!this.isDirectPathBetweenPoints(anchor, probe, width, height)) {
points[writeIndex++] = points[readIndex - 1];
anchorIndex = readIndex - 1;
}
}
points[writeIndex++] = points[pathLength - 1];
this.currentPath.setCurrentPathLength(writeIndex);
if (this.currentPath.getCurrentPathIndex() >= writeIndex) {
this.currentPath.setCurrentPathIndex(Math.max(0, writeIndex - 1));
}
}
public void onUpdateNavigation() {
++this.totalTicks;
@@ -6,6 +6,7 @@ import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import kamkeel.npcs.addon.client.DBCClient;
import kamkeel.npcs.client.command.CommandCNPCDebugger;
import kamkeel.npcs.client.renderer.RenderAbilityBeam;
import kamkeel.npcs.client.renderer.RenderAbilityDisc;
import kamkeel.npcs.client.renderer.RenderAbilityLaser;
@@ -53,6 +54,7 @@ import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ReportedException;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.FakePlayer;
@@ -362,6 +364,9 @@ public class ClientProxy extends CommonProxy {
ClientTagMapController.Instance = new ClientTagMapController();
MinecraftForge.EVENT_BUS.register(new ClientEventHandler());
// Debug commands
ClientCommandHandler.instance.registerCommand(new CommandCNPCDebugger());
// Telegraph rendering system
TelegraphManager.initClient();
MinecraftForge.EVENT_BUS.register(new TelegraphRenderer());
@@ -419,7 +424,8 @@ public class ClientProxy extends CommonProxy {
@Override
public PlayerData getPlayerData(EntityPlayer player) {
if (player.getUniqueID() == Minecraft.getMinecraft().thePlayer.getUniqueID()) {
EntityPlayer local = Minecraft.getMinecraft().thePlayer;
if (local != null && player.getUniqueID().equals(local.getUniqueID())) {
if (ClientCacheHandler.playerData != null) {
if (ClientCacheHandler.playerData.player != player) {
ClientCacheHandler.playerData.player = player;
@@ -28,7 +28,7 @@ public class GuiNpcPather extends GuiNPCInterface implements IGuiData {
drawDefaultBackground = false;
xSize = 176;
title = "Npc Pather";
setBackground("smallbg.png");
setBackground("menubg.png");
ai = npc.ais;
PacketClient.sendClient(new MovingPathGetPacket());
}
@@ -13,7 +13,7 @@ public class SubGuiAnimationFrame extends SubGuiInterface implements ITextfieldL
public SubGuiAnimationFrame(Frame editingFrame) {
this.editingFrame = editingFrame;
setBackground("smallbg.png");
setBackground("menubg.png");
}
@Override
@@ -11,7 +11,7 @@ public class SubGuiAnimationOptions extends SubGuiInterface {
public SubGuiAnimationOptions(Animation animation) {
this.animation = animation;
setBackground("smallbg.png");
setBackground("menubg.png");
}
@Override
@@ -11,7 +11,7 @@ public class SubGuiEditText extends SubGuiInterface {
public SubGuiEditText(String text) {
this.text = text;
setBackground("extrasmallbg.png");
setBackground("menubg.png");
closeOnEsc = true;
xSize = 176;
ySize = 71;
@@ -220,7 +220,7 @@ public class GuiFieldBuilder {
float fVal = def.getValue() instanceof Number ? ((Number) def.getValue()).floatValue() : 0f;
GuiNpcTextField tf = new GuiNpcTextField(widgetId, parent, fontRenderer, fieldX, y, fieldW, 20, String.valueOf(fVal));
tf.setFloatsOnly();
if (def.hasRange()) tf.setMinMaxDefaultFloat(def.getMin(), def.getMax(), fVal);
tf.setMinMaxDefaultFloat(def.getMin(), def.getMax(), fVal);
if (!def.isEnabled()) tf.setEnabled(false);
if (hover != null) tf.setHoverText(hover);
sw.addTextField(tf);
@@ -233,7 +233,7 @@ public class GuiFieldBuilder {
int iVal = def.getValue() instanceof Number ? ((Number) def.getValue()).intValue() : 0;
GuiNpcTextField tf = new GuiNpcTextField(widgetId, parent, fontRenderer, fieldX, y, fieldW, 20, String.valueOf(iVal));
tf.setIntegersOnly();
if (def.hasRange()) tf.setMinMaxDefault((int) def.getMin(), (int) def.getMax(), iVal);
tf.setMinMaxDefault((int) def.getMin(), (int) def.getMax(), iVal);
if (!def.isEnabled()) tf.setEnabled(false);
if (hover != null) tf.setHoverText(hover);
sw.addTextField(tf);
@@ -411,6 +411,9 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollData
}
if (subgui instanceof SubGuiNpcDialog) {
saveType(true);
if (dialog != null && dialog.id >= 0) {
setPrevDialogName(dialog.title);
}
}
}
@@ -401,6 +401,9 @@ public class GuiNPCManageQuest extends GuiNPCInterface2 implements IScrollData,
}
if (subgui instanceof SubGuiNpcQuest) {
saveType(true);
if (quest != null && quest.id >= 0) {
setPrevQuestName(quest.title);
}
}
}
@@ -15,7 +15,7 @@ import org.lwjgl.opengl.GL11;
public class GuiQuestCompletion extends GuiNPCInterface implements ITopButtonListener {
private Quest quest;
private final ResourceLocation resource = new ResourceLocation("customnpcs", "textures/gui/smallbg.png");
private final ResourceLocation resource = new ResourceLocation("customnpcs", "textures/gui/menubg.png");
public GuiQuestCompletion(Quest quest) {
super();
@@ -20,7 +20,7 @@ import java.util.Vector;
public class GuiTransportSelection extends GuiNPCInterface implements ITopButtonListener, IScrollData {
private final ResourceLocation resource = new ResourceLocation("customnpcs", "textures/gui/smallbg.png");
private final ResourceLocation resource = new ResourceLocation("customnpcs", "textures/gui/menubg.png");
protected int xSize;
protected int guiLeft;
protected int guiTop;
@@ -16,7 +16,7 @@ import org.lwjgl.opengl.GL11;
import java.util.HashMap;
public class GuiScriptGlobal extends GuiNPCInterface implements IGuiData {
private final ResourceLocation resource = new ResourceLocation("customnpcs", "textures/gui/smallbg.png");
private final ResourceLocation resource = new ResourceLocation("customnpcs", "textures/gui/menubg.png");
private HashMap<Integer, Class<?>> scriptGuiClasses = new HashMap<>();
public GuiScriptGlobal() {
@@ -15,7 +15,7 @@ public class SubGuiNpcCooldownPicker extends SubGuiInterface implements ITextfie
public SubGuiNpcCooldownPicker(boolean isMCCustom, long currentCooldown) {
this.isMCCustom = isMCCustom;
this.cooldownValue = currentCooldown;
setBackground("smallbg.png");
setBackground("menubg.png");
xSize = 220;
ySize = 222;
closeOnEsc = true;
@@ -289,7 +289,15 @@ public class AuctionController implements IAuctionHandler {
// Global claims are not tied to a single player.
claim.playerUUID = null;
claim.playerName = "Global";
globalClaims.add(claim);
synchronized (globalClaims) {
// Prevent duplicate claim IDs
for (AuctionClaim existing : globalClaims) {
if (existing.id.equals(claim.id)) {
return;
}
}
globalClaims.add(claim);
}
markDirty();
}
@@ -305,19 +313,23 @@ public class AuctionController implements IAuctionHandler {
private AuctionClaim getGlobalClaimInternal(String claimId) {
if (claimId == null || claimId.isEmpty()) return null;
for (AuctionClaim claim : globalClaims) {
if (claim != null && !claim.claimed && claimId.equals(claim.id)) {
return claim;
synchronized (globalClaims) {
for (AuctionClaim claim : globalClaims) {
if (claim != null && !claim.claimed && claimId.equals(claim.id)) {
return claim;
}
}
}
return null;
}
private boolean claimAndRemoveGlobal(String claimId) {
AuctionClaim claim = getGlobalClaimInternal(claimId);
if (claim == null) return false;
claim.claimed = true;
return globalClaims.remove(claim);
synchronized (globalClaims) {
AuctionClaim claim = getGlobalClaimInternal(claimId);
if (claim == null) return false;
claim.claimed = true;
return globalClaims.remove(claim);
}
}
/**
@@ -358,15 +370,27 @@ public class AuctionController implements IAuctionHandler {
return "This item cannot be listed on the Auction House.";
}
// Validate minimum price
// Validate prices
if (startingPrice <= 0) {
return "Starting price must be positive.";
}
if (startingPrice < ConfigMarket.MinimumListingPrice) {
return "Starting price must be at least " + ConfigMarket.MinimumListingPrice + " " + ConfigMarket.CurrencyName + ".";
}
if (startingPrice > ConfigMarket.MaxBalance) {
return "Starting price exceeds maximum allowed value.";
}
// Validate buyout price if set
if (buyoutPrice < 0) {
return "Buyout price cannot be negative.";
}
if (buyoutPrice > 0 && buyoutPrice < startingPrice) {
return "Buyout price must be higher than starting price.";
}
if (buyoutPrice > ConfigMarket.MaxBalance) {
return "Buyout price exceeds maximum allowed value.";
}
UUID playerUUID = player.getUniqueID();
String playerName = player.getCommandSenderName();
@@ -386,7 +410,7 @@ public class AuctionController implements IAuctionHandler {
PlayerTradeData currency = playerData.tradeData;
long fee = ConfigMarket.ListingFee;
if (!currency.canAfford(fee)) {
if (fee > 0 && !currency.canAfford(fee)) {
return "You cannot afford the listing fee (" + fee + " " + ConfigMarket.CurrencyName + ").";
}
@@ -400,7 +424,7 @@ public class AuctionController implements IAuctionHandler {
}
// Deduct fee
if (!currency.withdraw(fee)) {
if (fee > 0 && !currency.withdraw(fee)) {
return "Failed to deduct listing fee.";
}
@@ -435,9 +459,16 @@ public class AuctionController implements IAuctionHandler {
return "No item provided.";
}
// Validate prices
if (startingPrice <= 0) {
return "Starting price must be positive.";
}
if (startingPrice < ConfigMarket.MinimumListingPrice) {
return "Starting price must be at least " + ConfigMarket.MinimumListingPrice + " " + ConfigMarket.CurrencyName + ".";
}
if (buyoutPrice < 0) {
return "Buyout price cannot be negative.";
}
if (buyoutPrice > 0 && buyoutPrice < startingPrice) {
return "Buyout price must be higher than starting price.";
}
@@ -514,7 +545,13 @@ public class AuctionController implements IAuctionHandler {
if (penalty > 0) {
PlayerData sellerData = PlayerDataController.Instance.getData(listing.sellerUUID);
if (sellerData != null) {
sellerData.tradeData.withdraw(penalty);
if (!sellerData.tradeData.withdraw(penalty)) {
// Withdraw whatever they have if they can't cover the full penalty
long available = sellerData.tradeData.getBalance();
if (available > 0) {
sellerData.tradeData.withdraw(available);
}
}
sellerData.save();
}
}
@@ -551,6 +588,11 @@ public class AuctionController implements IAuctionHandler {
return "Auction is disabled.";
}
// Validate bid amount
if (bidAmount <= 0) {
return "Bid amount must be positive.";
}
UUID playerUUID = player.getUniqueID();
String playerName = player.getCommandSenderName();
@@ -641,14 +683,14 @@ public class AuctionController implements IAuctionHandler {
listing.highBidderName = playerName;
listing.currentBid = bidAmount;
listing.bidCount++;
// Add to new bidder's active bids
addToPlayerBids(playerUUID, listing.id);
// Snipe protection (must be inside sync to prevent race with endAuction)
listing.extendForSnipeProtection(ConfigMarket.SnipeProtectionMinutes);
}
// Add to new bidder's active bids
addToPlayerBids(playerUUID, listing.id);
// Snipe protection
listing.extendForSnipeProtection(ConfigMarket.SnipeProtectionMinutes);
markDirty();
logAuction(EnumAuctionLogAction.BID, playerName, listing.item.getDisplayName(), bidAmount,
@@ -834,26 +876,36 @@ public class AuctionController implements IAuctionHandler {
}
public String claimGlobalItem(String claimId, EntityPlayer player) {
AuctionClaim claim = getGlobalClaimInternal(claimId);
if (claim == null) {
return "Global claim not found.";
}
if (!claim.type.isItem()) {
return "This global claim is not an item claim.";
}
if (claim.item == null) {
return "Item data is missing.";
}
String listingId;
String itemName;
synchronized (globalClaims) {
AuctionClaim claim = getGlobalClaimInternal(claimId);
if (claim == null) {
return "Global claim not found.";
}
if (!claim.type.isItem()) {
return "This global claim is not an item claim.";
}
if (claim.item == null) {
return "Item data is missing.";
}
if (!player.inventory.addItemStackToInventory(claim.item.copy())) {
return "Your inventory is full.";
}
// Check inventory space before adding (addItemStackToInventory mutates even on partial add)
if (!canFitInInventory(player, claim.item)) {
return "Not enough inventory space to claim this item.";
}
claimAndRemoveGlobal(claim.id);
cleanupListingIfComplete(claim.listingId);
// Add to inventory (safe - we verified space above)
player.inventory.addItemStackToInventory(claim.item.copy());
listingId = claim.listingId;
itemName = claim.item.getDisplayName();
claimAndRemoveGlobal(claim.id);
}
cleanupListingIfComplete(listingId);
markDirty();
logAuction(EnumAuctionLogAction.CLAIMED, player.getCommandSenderName(), claim.item.getDisplayName(), 0,
logAuction(EnumAuctionLogAction.CLAIMED, player.getCommandSenderName(), itemName, 0,
"Global item claim");
return null;
}
@@ -862,19 +914,25 @@ public class AuctionController implements IAuctionHandler {
* Global currency claims are acknowledged/cleared and do not alter player balances.
*/
public String claimGlobalCurrency(String claimId, EntityPlayer player) {
AuctionClaim claim = getGlobalClaimInternal(claimId);
if (claim == null) {
return "Global claim not found.";
}
if (!claim.type.isCurrency()) {
return "This global claim is not a currency claim.";
}
String listingId;
long currency;
synchronized (globalClaims) {
AuctionClaim claim = getGlobalClaimInternal(claimId);
if (claim == null) {
return "Global claim not found.";
}
if (!claim.type.isCurrency()) {
return "This global claim is not a currency claim.";
}
claimAndRemoveGlobal(claim.id);
cleanupListingIfComplete(claim.listingId);
listingId = claim.listingId;
currency = claim.currency;
claimAndRemoveGlobal(claim.id);
}
cleanupListingIfComplete(listingId);
markDirty();
logAuction(EnumAuctionLogAction.CLAIMED, player.getCommandSenderName(), ConfigMarket.CurrencyName, claim.currency,
logAuction(EnumAuctionLogAction.CLAIMED, player.getCommandSenderName(), ConfigMarket.CurrencyName, currency,
"Global currency claim acknowledged (no balance change)");
return null;
}
@@ -910,11 +968,14 @@ public class AuctionController implements IAuctionHandler {
return "Claim was prevented.";
}
// Check inventory space
if (!player.inventory.addItemStackToInventory(claim.item.copy())) {
return "Your inventory is full.";
// Check inventory space before adding (addItemStackToInventory mutates even on partial add)
if (!canFitInInventory(player, claim.item)) {
return "Not enough inventory space to claim this item.";
}
// Add to inventory (safe - we verified space above)
player.inventory.addItemStackToInventory(claim.item.copy());
// Remove claim from player's auction data
playerData.tradeData.claimAndRemove(claimId);
playerData.updateClient = true;
@@ -973,6 +1034,34 @@ public class AuctionController implements IAuctionHandler {
return null; // Success
}
/**
* Check if a player's inventory can fit the entire ItemStack without partial adds.
* Unlike addItemStackToInventory, this does NOT mutate the inventory.
*/
private boolean canFitInInventory(EntityPlayer player, ItemStack stack) {
int remaining = stack.stackSize;
int maxStack = stack.getMaxStackSize();
ItemStack[] mainInventory = player.inventory.mainInventory;
for (int i = 0; i < mainInventory.length; i++) {
if (remaining <= 0) return true;
ItemStack slot = mainInventory[i];
if (slot == null) {
remaining -= Math.min(remaining, maxStack);
} else if (slot.getItem() == stack.getItem()
&& slot.getItemDamage() == stack.getItemDamage()
&& ItemStack.areItemStackTagsEqual(slot, stack)) {
int spaceInSlot = maxStack - slot.stackSize;
if (spaceInSlot > 0) {
remaining -= Math.min(remaining, spaceInSlot);
}
}
}
return remaining <= 0;
}
/**
* Clean up a listing if it's ended and no longer needed.
* Now just removes ended listings after some delay since claims are in PlayerData.
@@ -1019,6 +1108,7 @@ public class AuctionController implements IAuctionHandler {
for (AuctionListing listing : listings.values()) {
if (listing.status != EnumAuctionStatus.ACTIVE) continue;
if (listing.isExpired()) continue;
// Apply search filter (searches item name AND seller name)
if (filter.hasSearchText()) {
@@ -1069,6 +1159,7 @@ public class AuctionController implements IAuctionHandler {
int count = 0;
for (AuctionListing listing : listings.values()) {
if (listing.status != EnumAuctionStatus.ACTIVE) continue;
if (listing.isExpired()) continue;
if (filter.hasSearchText()) {
String itemName = listing.item != null ? listing.item.getDisplayName() : "";
String sellerName = listing.sellerName != null ? listing.sellerName : "";
@@ -1755,20 +1846,12 @@ public class AuctionController implements IAuctionHandler {
String itemName = listing.item != null ? listing.item.getDisplayName() : "Unknown Item";
// Return active highest bid.
// Return active highest bid - always refund to the actual bidder
if (listing.hasBids() && listing.highBidderUUID != null) {
AuctionClaim refundClaim;
if (cancelCompletely) {
refundClaim = AuctionClaim.createRefundClaim(
null, "Global", listing.id, listing.currentBid, itemName,
listing.highBidderName, null);
addGlobalClaim(refundClaim);
} else {
refundClaim = AuctionClaim.createRefundClaim(
listing.highBidderUUID, listing.highBidderName, listing.id, listing.currentBid, itemName,
listing.sellerName, null);
addClaimToPlayer(listing.highBidderUUID, refundClaim);
}
AuctionClaim refundClaim = AuctionClaim.createRefundClaim(
listing.highBidderUUID, listing.highBidderName, listing.id, listing.currentBid, itemName,
listing.sellerName, null);
addClaimToPlayer(listing.highBidderUUID, refundClaim);
removeFromPlayerBids(listing.highBidderUUID, listing.id);
}
@@ -5,6 +5,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.api.handler.ILinkedItemHandler;
import noppes.npcs.api.handler.data.ILinkedItem;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.controllers.data.IScriptHandler;
@@ -21,7 +22,7 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.zip.GZIPInputStream;
public class LinkedItemController {
public class LinkedItemController implements ILinkedItemHandler {
private static LinkedItemController Instance;
private int lastUsedID = 0;
@@ -40,25 +41,28 @@ public class LinkedItemController {
return Instance;
}
public LinkedItem createItem(String name) {
@Override
public ILinkedItem createItem(String name) {
return new LinkedItem(name);
}
@Override
public IItemStack createItemStack(int id) {
LinkedItem linkedItem = this.get(id);
LinkedItem linkedItem = (LinkedItem) this.get(id);
if (linkedItem != null) {
return linkedItem.createStack();
}
return null;
}
public void add(LinkedItem linkedItem) {
@Override
public void add(ILinkedItem linkedItem) {
if (linkedItem != null) {
String name = linkedItem.getName();
if (name != null && !name.isEmpty()) {
int linkedItemId = linkedItem.getId();
int id = this.linkedItems.containsKey(linkedItemId) ? linkedItemId : this.getUnusedId();
this.linkedItems.put(id, linkedItem);
this.linkedItems.put(id, (LinkedItem) linkedItem);
linkedItem.setId(id);
this.addScript(id);
}
@@ -69,6 +73,7 @@ public class LinkedItemController {
this.linkedItemsScripts.put(id, new LinkedItemScript());
}
@Override
public LinkedItem remove(int id) {
this.removeScript(id);
return this.linkedItems.remove(id);
@@ -78,16 +83,19 @@ public class LinkedItemController {
this.linkedItemsScripts.remove(id);
}
@Override
public LinkedItem get(int id) {
return this.linkedItems.get(id);
return (LinkedItem) this.linkedItems.get(id);
}
@Override
public boolean contains(int id) {
return this.linkedItems.containsKey(id);
}
public boolean contains(LinkedItem linkedItem) {
return this.linkedItems.containsValue(linkedItem);
@Override
public boolean contains(ILinkedItem linkedItem) {
return this.linkedItems.containsValue((LinkedItem) linkedItem);
}
public IScriptHandler getScriptHandler(int id) {
@@ -219,7 +227,7 @@ public class LinkedItemController {
}
public void delete(int id) {
LinkedItem linkedItem = get(id);
LinkedItem linkedItem = (LinkedItem) get(id);
if (linkedItem != null) {
LinkedItem foundItem = remove(id);
if (foundItem != null && foundItem.name != null) {
@@ -91,14 +91,6 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
*/
private transient byte lastSyncedFlags = 0;
/**
* Dirty flag: set when ability data changes (unlock/lock/select/toggle).
* Checked by the periodic 10-tick sync handler, which sends an ability
* data packet and clears the flag. Avoids scattering sync calls across
* every mutation method.
*/
public transient boolean needsSync = false;
/**
* World time when the last ability was activated (for double-press cancel detection).
*/
@@ -497,7 +489,6 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
@Override
protected void onToggleStateChanged(String key, boolean active, int state) {
needsSync = true;
}
@Override
@@ -534,20 +525,17 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
public void setSelectedIndex(int index) {
if (index == -1 || (index >= 0 && index < unlockedAbilities.size())) {
this.selectedIndex = index;
needsSync = true;
}
}
public void selectNext() {
if (unlockedAbilities.isEmpty()) return;
selectedIndex = (selectedIndex + 1) % unlockedAbilities.size();
needsSync = true;
}
public void selectPrevious() {
if (unlockedAbilities.isEmpty()) return;
selectedIndex = (selectedIndex - 1 + unlockedAbilities.size()) % unlockedAbilities.size();
needsSync = true;
}
public String getSelectedAbilityKey() {
@@ -576,13 +564,11 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
if (selectedIndex >= unlockedAbilities.size()) {
selectedIndex = Math.max(0, unlockedAbilities.size() - 1);
}
needsSync = true;
}
public void unlockAbility(String key) {
if (key != null && !key.isEmpty() && !unlockedAbilities.contains(key)) {
unlockedAbilities.add(key);
needsSync = true;
}
}
@@ -591,7 +577,6 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
if (selectedIndex >= unlockedAbilities.size()) {
selectedIndex = Math.max(0, unlockedAbilities.size() - 1);
}
needsSync = true;
}
public boolean hasUnlockedAbility(String key) {
@@ -837,7 +822,6 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
// Reset sync tracking so next sync sends fresh state
lastSyncedFlags = 0;
needsSync = true;
}
/**
@@ -245,8 +245,14 @@ public class PlayerTradeData implements IPlayerTradeData {
* Add a claim to this player's pending claims.
* Thread-safe - can be called from any thread.
*/
public void addClaim(AuctionClaim claim) {
public synchronized void addClaim(AuctionClaim claim) {
if (claim != null && !claim.claimed) {
// Prevent duplicate claim IDs
for (AuctionClaim existing : claims) {
if (existing.id.equals(claim.id)) {
return;
}
}
claims.add(claim);
}
}
@@ -276,8 +282,9 @@ public class PlayerTradeData implements IPlayerTradeData {
/**
* Get a specific claim by ID (internal use).
* Synchronized to pair with claimAndRemove for thread safety.
*/
public AuctionClaim getClaimInternal(String claimId) {
public synchronized AuctionClaim getClaimInternal(String claimId) {
for (AuctionClaim claim : claims) {
if (claim.id.equals(claimId) && !claim.claimed) {
return claim;
@@ -296,8 +303,9 @@ public class PlayerTradeData implements IPlayerTradeData {
/**
* Mark a claim as claimed and remove it.
* Synchronized to prevent double-claim from concurrent threads.
*/
public boolean claimAndRemove(String claimId) {
public synchronized boolean claimAndRemove(String claimId) {
for (AuctionClaim claim : claims) {
if (claim.id.equals(claimId) && !claim.claimed) {
claim.claimed = true;
@@ -91,13 +91,11 @@ public abstract class EntityNPCFlying extends EntityNPCInterface {
this.prevLimbSwingAmount = this.limbSwingAmount;
double distanceX = this.posX - this.prevPosX;
double distanceZ = this.posZ - this.prevPosZ;
float distance = MathHelper.sqrt_double(distanceX * distanceX + distanceZ * distanceZ);
float swingScale = this.getNavigator().noPath() ? 0.35F : 0.9F;
distance *= swingScale;
float distance = MathHelper.sqrt_double(distanceX * distanceX + distanceZ * distanceZ) * 4.0F;
if (distance > 1.0F) {
distance = 1.0F;
}
this.limbSwingAmount += (distance - this.limbSwingAmount) * 0.18F;
this.limbSwingAmount += (distance - this.limbSwingAmount) * 0.4F;
this.limbSwing += this.limbSwingAmount;
}
@@ -33,7 +33,7 @@ public class ItemLinked extends ItemCustomizable {
IItemStack itemStack = NpcAPI.Instance().getIItemStack(stack);
if (itemStack instanceof ScriptLinkedItem) {
ScriptLinkedItem scriptLinkedItem = (ScriptLinkedItem) itemStack;
LinkedItem linkedItem = LinkedItemController.getInstance().get(scriptLinkedItem.linkedItem.getId());
LinkedItem linkedItem = (LinkedItem) LinkedItemController.getInstance().get(scriptLinkedItem.linkedItem.getId());
int prevVersion = scriptLinkedItem.linkedVersion;
if (linkedItem != null && scriptLinkedItem.linkedVersion != linkedItem.version) {
scriptLinkedItem.linkedItem = linkedItem.clone();
+6 -34
View File
@@ -71,24 +71,7 @@ import noppes.npcs.api.entity.ICustomNpc;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.gui.ICustomGui;
import noppes.npcs.api.handler.IAbilityHandler;
import noppes.npcs.api.handler.IActionManager;
import noppes.npcs.api.handler.IAnimationHandler;
import noppes.npcs.api.handler.IAttributeHandler;
import noppes.npcs.api.handler.IAuctionHandler;
import noppes.npcs.api.handler.ICloneHandler;
import noppes.npcs.api.handler.ICustomEffectHandler;
import noppes.npcs.api.handler.IDialogHandler;
import noppes.npcs.api.handler.IFactionHandler;
import noppes.npcs.api.handler.IMagicHandler;
import noppes.npcs.api.handler.INaturalSpawnsHandler;
import noppes.npcs.api.handler.IPartyHandler;
import noppes.npcs.api.handler.IProfileHandler;
import noppes.npcs.api.handler.IQuestHandler;
import noppes.npcs.api.handler.IRecipeHandler;
import noppes.npcs.api.handler.IScriptHookHandler;
import noppes.npcs.api.handler.ITelegraphHandler;
import noppes.npcs.api.handler.ITransportHandler;
import noppes.npcs.api.handler.*;
import noppes.npcs.api.handler.data.IAnimation;
import noppes.npcs.api.handler.data.IFrame;
import noppes.npcs.api.handler.data.IFramePart;
@@ -99,22 +82,7 @@ import noppes.npcs.compat.PixelmonHelper;
import noppes.npcs.config.ConfigScript;
import noppes.npcs.constants.EnumAnimationPart;
import noppes.npcs.containers.ContainerNpcInterface;
import noppes.npcs.controllers.AnimationController;
import noppes.npcs.controllers.AuctionController;
import noppes.npcs.controllers.ChunkController;
import noppes.npcs.controllers.CustomEffectController;
import noppes.npcs.controllers.DialogController;
import noppes.npcs.controllers.FactionController;
import noppes.npcs.controllers.MagicController;
import noppes.npcs.controllers.PartyController;
import noppes.npcs.controllers.QuestController;
import noppes.npcs.controllers.RecipeController;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.controllers.ScriptEntityData;
import noppes.npcs.controllers.ScriptHookController;
import noppes.npcs.controllers.ServerCloneController;
import noppes.npcs.controllers.SpawnController;
import noppes.npcs.controllers.TransportController;
import noppes.npcs.controllers.*;
import noppes.npcs.controllers.data.Animation;
import noppes.npcs.controllers.data.Frame;
import noppes.npcs.controllers.data.FramePart;
@@ -383,6 +351,10 @@ public class NpcAPI extends AbstractNpcAPI {
return AnimationController.Instance;
}
public ILinkedItemHandler getLinkedItems() {
return LinkedItemController.getInstance();
}
public IScriptHookHandler getScriptHooks() {
return ScriptHookController.Instance;
}
@@ -45,12 +45,12 @@ public class ScriptEnergyLaser<T extends EntityAbilityLaser> extends ScriptEnerg
entity.setExpansionSpeed(speed);
}
public int getLingerTicks() {
return entity.getLingerTicks();
public float getMaxLength() {
return entity.getMaxLength();
}
public void setLingerTicks(int ticks) {
entity.setLingerTicks(ticks);
public void setMaxLength(float maxLength) {
entity.setMaxLength(maxLength);
}
public float getCurrentLength() {
@@ -89,18 +89,6 @@ public class ScriptEnergyLaser<T extends EntityAbilityLaser> extends ScriptEnerg
return entity.getEndZ();
}
public float getLingerAlpha() {
return entity.getLingerAlpha();
}
public boolean isLockVerticalDirection() {
return entity.isLockVerticalDirection();
}
public void setLockVerticalDirection(boolean lock) {
entity.setLockVerticalDirection(lock);
}
// ==================== FIRE ====================
@Override
@@ -18,6 +18,7 @@ import noppes.npcs.scripted.NpcAPI;
public class AbilityEvent extends NpcEvent implements IAbilityEvent {
protected final Ability ability;
protected final IEntityLivingBase target;
private transient IAbility abilityCopy;
public AbilityEvent(ICustomNpc npc, Ability ability, EntityLivingBase target) {
super(npc);
@@ -27,7 +28,10 @@ public class AbilityEvent extends NpcEvent implements IAbilityEvent {
@Override
public IAbility getAbility() {
return ability;
if (abilityCopy == null && ability != null) {
abilityCopy = ability.deepCopy();
}
return abilityCopy;
}
@Override
@@ -18,6 +18,7 @@ import noppes.npcs.scripted.NpcAPI;
public class PlayerAbilityEvent extends PlayerEvent implements IPlayerAbilityEvent {
protected final Ability ability;
protected final IEntityLivingBase target;
private transient IAbility abilityCopy;
public PlayerAbilityEvent(IPlayer player, Ability ability, EntityLivingBase target) {
super(player);
@@ -27,7 +28,10 @@ public class PlayerAbilityEvent extends PlayerEvent implements IPlayerAbilityEve
@Override
public IAbility getAbility() {
return ability;
if (abilityCopy == null && ability != null) {
abilityCopy = ability.deepCopy();
}
return abilityCopy;
}
@Override
@@ -36,7 +36,12 @@ public class ScriptDataAbilities implements IDataAbilities {
@Override
public IAbility[] getAbilities() {
return data.getAbilities().toArray(new IAbility[0]);
List<Ability> live = data.getAbilities();
IAbility[] copies = new IAbility[live.size()];
for (int i = 0; i < live.size(); i++) {
copies[i] = live.get(i).deepCopy();
}
return copies;
}
@Override
@@ -73,7 +78,8 @@ public class ScriptDataAbilities implements IDataAbilities {
@Override
public IAbility getAbility(String abilityId) {
return data.getAbility(abilityId);
Ability a = data.getAbility(abilityId);
return a != null ? a.deepCopy() : null;
}
@Override
@@ -115,6 +121,17 @@ public class ScriptDataAbilities implements IDataAbilities {
@Override
public IAbility getCurrentAbility() {
Ability a = data.getCurrentAbility();
return a != null ? a.deepCopy() : null;
}
@Override
public IAbility getSourceAbility(String abilityId) {
return data.getAbility(abilityId);
}
@Override
public IAbility getSourceCurrentAbility() {
return data.getCurrentAbility();
}
@@ -85,7 +85,8 @@ public class ScriptPlayerAbilityData implements IPlayerAbilityData {
@Override
public IAbility getCurrentAbility() {
return data.getCurrentAbility();
Ability a = data.getCurrentAbility();
return a != null ? a.deepCopy() : null;
}
@Override