mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-27 02:42:55 +00:00
Scripting Ability Handling Improvement and Copy Data
This commit is contained in:
1 parent
50fd3c1856
commit
90735e6866
14 files changed
+71
-30
No files matched your search
@@ -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
|
||||
|
||||
Reference in new issue
Block a user