From 12fa0e8e6ba83e63ef89769ca6ba60bae81ca638 Mon Sep 17 00:00:00 2001 From: MobiusDevelopment <8391001+MobiusDevelopment@users.noreply.github.com> Date: Tue, 23 Jun 2020 22:16:51 +0000 Subject: [PATCH] Siege guard boxing preventions. --- .../data/scripts/ai/others/SiegeGuards.java | 54 ++++++++++++------- .../data/scripts/ai/others/SiegeGuards.java | 54 ++++++++++++------- .../data/scripts/ai/others/SiegeGuards.java | 54 ++++++++++++------- .../data/scripts/ai/others/SiegeGuards.java | 54 ++++++++++++------- .../data/scripts/ai/others/SiegeGuards.java | 54 ++++++++++++------- .../data/scripts/ai/others/SiegeGuards.java | 54 ++++++++++++------- .../data/scripts/ai/others/SiegeGuards.java | 54 ++++++++++++------- .../data/scripts/ai/others/SiegeGuards.java | 54 ++++++++++++------- .../data/scripts/ai/others/SiegeGuards.java | 54 ++++++++++++------- .../data/scripts/ai/others/SiegeGuards.java | 54 ++++++++++++------- .../data/scripts/ai/others/SiegeGuards.java | 51 ++++++++++++------ .../data/scripts/ai/others/SiegeGuards.java | 51 ++++++++++++------ .../data/scripts/ai/others/SiegeGuards.java | 51 ++++++++++++------ .../data/scripts/ai/others/SiegeGuards.java | 51 ++++++++++++------ .../data/scripts/ai/others/SiegeGuards.java | 51 ++++++++++++------ .../data/scripts/ai/others/SiegeGuards.java | 51 ++++++++++++------ .../data/scripts/ai/others/SiegeGuards.java | 51 ++++++++++++------ 17 files changed, 588 insertions(+), 309 deletions(-) diff --git a/L2J_Mobius_1.0_Ertheia/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_1.0_Ertheia/dist/game/data/scripts/ai/others/SiegeGuards.java index ef065f0f07..61df383afa 100644 --- a/L2J_Mobius_1.0_Ertheia/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_1.0_Ertheia/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,9 +16,8 @@ */ package ai.others; -import java.util.HashMap; +import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -92,8 +91,8 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on - private static final Map> RESIDENCE_GUARD_MAP = new HashMap<>(); - private static final Map RESIDENCE_WORKING = new HashMap<>(); + private static final Object[] RESIDENCE_GUARD_MAP = new Object[122]; + private static final boolean[] RESIDENCE_WORKING = new boolean[122]; public SiegeGuards() { @@ -110,17 +109,17 @@ public class SiegeGuards extends AbstractNpcAI addKillId(MERCENARIES); addKillId(STATIONARY_MERCENARIES); + Arrays.fill(RESIDENCE_WORKING, false); + // Start task for unknown residences. - RESIDENCE_GUARD_MAP.put(0, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(0, false); + RESIDENCE_GUARD_MAP[0] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(0), 0, 3000); // Start tasks for castles. for (Castle castle : CastleManager.getInstance().getCastles()) { final int residenceId = castle.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), residenceId * 100, 3000); } @@ -128,8 +127,7 @@ public class SiegeGuards extends AbstractNpcAI for (Fort fort : FortManager.getInstance().getForts()) { final int residenceId = fort.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), 900 + ((residenceId - 100) * 100), 3000); } } @@ -146,13 +144,17 @@ public class SiegeGuards extends AbstractNpcAI @Override public void run() { - if (RESIDENCE_WORKING.get(_residenceId)) + synchronized (RESIDENCE_WORKING) { - return; + if (RESIDENCE_WORKING[_residenceId]) + { + return; + } + RESIDENCE_WORKING[_residenceId] = true; } - RESIDENCE_WORKING.put(_residenceId, true); - final List guards = RESIDENCE_GUARD_MAP.get(_residenceId); + @SuppressWarnings("unchecked") + final List guards = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[_residenceId]; for (Npc guard : guards) { if (guard == null) @@ -196,7 +198,10 @@ public class SiegeGuards extends AbstractNpcAI } } - RESIDENCE_WORKING.put(_residenceId, false); + synchronized (RESIDENCE_WORKING) + { + RESIDENCE_WORKING[_residenceId] = false; + } } } @@ -212,14 +217,24 @@ public class SiegeGuards extends AbstractNpcAI } @Override + @SuppressWarnings("unchecked") public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) { final int residenceId = npc.getScriptValue(); - RESIDENCE_GUARD_MAP.get(RESIDENCE_GUARD_MAP.containsKey(residenceId) ? residenceId : 0).remove(npc); + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) + { + guardList.remove(npc); + } + else + { + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).remove(npc); + } return super.onKill(npc, killer, isSummon); } @Override + @SuppressWarnings("unchecked") public String onSpawn(Npc npc) { npc.setRandomWalking(false); @@ -232,13 +247,14 @@ public class SiegeGuards extends AbstractNpcAI final Fort fortress = npc.getFort(); final int residenceId = fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0); npc.setScriptValue(residenceId); - if (RESIDENCE_GUARD_MAP.containsKey(residenceId)) + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) { - RESIDENCE_GUARD_MAP.get(residenceId).add(npc); + guardList.add(npc); } else // Residence id not found. { - RESIDENCE_GUARD_MAP.get(0).add(npc); + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).add(npc); } return super.onSpawn(npc); diff --git a/L2J_Mobius_2.5_Underground/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_2.5_Underground/dist/game/data/scripts/ai/others/SiegeGuards.java index ef065f0f07..61df383afa 100644 --- a/L2J_Mobius_2.5_Underground/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_2.5_Underground/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,9 +16,8 @@ */ package ai.others; -import java.util.HashMap; +import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -92,8 +91,8 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on - private static final Map> RESIDENCE_GUARD_MAP = new HashMap<>(); - private static final Map RESIDENCE_WORKING = new HashMap<>(); + private static final Object[] RESIDENCE_GUARD_MAP = new Object[122]; + private static final boolean[] RESIDENCE_WORKING = new boolean[122]; public SiegeGuards() { @@ -110,17 +109,17 @@ public class SiegeGuards extends AbstractNpcAI addKillId(MERCENARIES); addKillId(STATIONARY_MERCENARIES); + Arrays.fill(RESIDENCE_WORKING, false); + // Start task for unknown residences. - RESIDENCE_GUARD_MAP.put(0, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(0, false); + RESIDENCE_GUARD_MAP[0] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(0), 0, 3000); // Start tasks for castles. for (Castle castle : CastleManager.getInstance().getCastles()) { final int residenceId = castle.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), residenceId * 100, 3000); } @@ -128,8 +127,7 @@ public class SiegeGuards extends AbstractNpcAI for (Fort fort : FortManager.getInstance().getForts()) { final int residenceId = fort.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), 900 + ((residenceId - 100) * 100), 3000); } } @@ -146,13 +144,17 @@ public class SiegeGuards extends AbstractNpcAI @Override public void run() { - if (RESIDENCE_WORKING.get(_residenceId)) + synchronized (RESIDENCE_WORKING) { - return; + if (RESIDENCE_WORKING[_residenceId]) + { + return; + } + RESIDENCE_WORKING[_residenceId] = true; } - RESIDENCE_WORKING.put(_residenceId, true); - final List guards = RESIDENCE_GUARD_MAP.get(_residenceId); + @SuppressWarnings("unchecked") + final List guards = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[_residenceId]; for (Npc guard : guards) { if (guard == null) @@ -196,7 +198,10 @@ public class SiegeGuards extends AbstractNpcAI } } - RESIDENCE_WORKING.put(_residenceId, false); + synchronized (RESIDENCE_WORKING) + { + RESIDENCE_WORKING[_residenceId] = false; + } } } @@ -212,14 +217,24 @@ public class SiegeGuards extends AbstractNpcAI } @Override + @SuppressWarnings("unchecked") public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) { final int residenceId = npc.getScriptValue(); - RESIDENCE_GUARD_MAP.get(RESIDENCE_GUARD_MAP.containsKey(residenceId) ? residenceId : 0).remove(npc); + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) + { + guardList.remove(npc); + } + else + { + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).remove(npc); + } return super.onKill(npc, killer, isSummon); } @Override + @SuppressWarnings("unchecked") public String onSpawn(Npc npc) { npc.setRandomWalking(false); @@ -232,13 +247,14 @@ public class SiegeGuards extends AbstractNpcAI final Fort fortress = npc.getFort(); final int residenceId = fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0); npc.setScriptValue(residenceId); - if (RESIDENCE_GUARD_MAP.containsKey(residenceId)) + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) { - RESIDENCE_GUARD_MAP.get(residenceId).add(npc); + guardList.add(npc); } else // Residence id not found. { - RESIDENCE_GUARD_MAP.get(0).add(npc); + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).add(npc); } return super.onSpawn(npc); diff --git a/L2J_Mobius_3.0_Helios/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_3.0_Helios/dist/game/data/scripts/ai/others/SiegeGuards.java index ef065f0f07..61df383afa 100644 --- a/L2J_Mobius_3.0_Helios/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_3.0_Helios/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,9 +16,8 @@ */ package ai.others; -import java.util.HashMap; +import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -92,8 +91,8 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on - private static final Map> RESIDENCE_GUARD_MAP = new HashMap<>(); - private static final Map RESIDENCE_WORKING = new HashMap<>(); + private static final Object[] RESIDENCE_GUARD_MAP = new Object[122]; + private static final boolean[] RESIDENCE_WORKING = new boolean[122]; public SiegeGuards() { @@ -110,17 +109,17 @@ public class SiegeGuards extends AbstractNpcAI addKillId(MERCENARIES); addKillId(STATIONARY_MERCENARIES); + Arrays.fill(RESIDENCE_WORKING, false); + // Start task for unknown residences. - RESIDENCE_GUARD_MAP.put(0, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(0, false); + RESIDENCE_GUARD_MAP[0] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(0), 0, 3000); // Start tasks for castles. for (Castle castle : CastleManager.getInstance().getCastles()) { final int residenceId = castle.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), residenceId * 100, 3000); } @@ -128,8 +127,7 @@ public class SiegeGuards extends AbstractNpcAI for (Fort fort : FortManager.getInstance().getForts()) { final int residenceId = fort.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), 900 + ((residenceId - 100) * 100), 3000); } } @@ -146,13 +144,17 @@ public class SiegeGuards extends AbstractNpcAI @Override public void run() { - if (RESIDENCE_WORKING.get(_residenceId)) + synchronized (RESIDENCE_WORKING) { - return; + if (RESIDENCE_WORKING[_residenceId]) + { + return; + } + RESIDENCE_WORKING[_residenceId] = true; } - RESIDENCE_WORKING.put(_residenceId, true); - final List guards = RESIDENCE_GUARD_MAP.get(_residenceId); + @SuppressWarnings("unchecked") + final List guards = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[_residenceId]; for (Npc guard : guards) { if (guard == null) @@ -196,7 +198,10 @@ public class SiegeGuards extends AbstractNpcAI } } - RESIDENCE_WORKING.put(_residenceId, false); + synchronized (RESIDENCE_WORKING) + { + RESIDENCE_WORKING[_residenceId] = false; + } } } @@ -212,14 +217,24 @@ public class SiegeGuards extends AbstractNpcAI } @Override + @SuppressWarnings("unchecked") public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) { final int residenceId = npc.getScriptValue(); - RESIDENCE_GUARD_MAP.get(RESIDENCE_GUARD_MAP.containsKey(residenceId) ? residenceId : 0).remove(npc); + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) + { + guardList.remove(npc); + } + else + { + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).remove(npc); + } return super.onKill(npc, killer, isSummon); } @Override + @SuppressWarnings("unchecked") public String onSpawn(Npc npc) { npc.setRandomWalking(false); @@ -232,13 +247,14 @@ public class SiegeGuards extends AbstractNpcAI final Fort fortress = npc.getFort(); final int residenceId = fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0); npc.setScriptValue(residenceId); - if (RESIDENCE_GUARD_MAP.containsKey(residenceId)) + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) { - RESIDENCE_GUARD_MAP.get(residenceId).add(npc); + guardList.add(npc); } else // Residence id not found. { - RESIDENCE_GUARD_MAP.get(0).add(npc); + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).add(npc); } return super.onSpawn(npc); diff --git a/L2J_Mobius_4.0_GrandCrusade/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_4.0_GrandCrusade/dist/game/data/scripts/ai/others/SiegeGuards.java index ef065f0f07..61df383afa 100644 --- a/L2J_Mobius_4.0_GrandCrusade/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_4.0_GrandCrusade/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,9 +16,8 @@ */ package ai.others; -import java.util.HashMap; +import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -92,8 +91,8 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on - private static final Map> RESIDENCE_GUARD_MAP = new HashMap<>(); - private static final Map RESIDENCE_WORKING = new HashMap<>(); + private static final Object[] RESIDENCE_GUARD_MAP = new Object[122]; + private static final boolean[] RESIDENCE_WORKING = new boolean[122]; public SiegeGuards() { @@ -110,17 +109,17 @@ public class SiegeGuards extends AbstractNpcAI addKillId(MERCENARIES); addKillId(STATIONARY_MERCENARIES); + Arrays.fill(RESIDENCE_WORKING, false); + // Start task for unknown residences. - RESIDENCE_GUARD_MAP.put(0, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(0, false); + RESIDENCE_GUARD_MAP[0] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(0), 0, 3000); // Start tasks for castles. for (Castle castle : CastleManager.getInstance().getCastles()) { final int residenceId = castle.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), residenceId * 100, 3000); } @@ -128,8 +127,7 @@ public class SiegeGuards extends AbstractNpcAI for (Fort fort : FortManager.getInstance().getForts()) { final int residenceId = fort.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), 900 + ((residenceId - 100) * 100), 3000); } } @@ -146,13 +144,17 @@ public class SiegeGuards extends AbstractNpcAI @Override public void run() { - if (RESIDENCE_WORKING.get(_residenceId)) + synchronized (RESIDENCE_WORKING) { - return; + if (RESIDENCE_WORKING[_residenceId]) + { + return; + } + RESIDENCE_WORKING[_residenceId] = true; } - RESIDENCE_WORKING.put(_residenceId, true); - final List guards = RESIDENCE_GUARD_MAP.get(_residenceId); + @SuppressWarnings("unchecked") + final List guards = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[_residenceId]; for (Npc guard : guards) { if (guard == null) @@ -196,7 +198,10 @@ public class SiegeGuards extends AbstractNpcAI } } - RESIDENCE_WORKING.put(_residenceId, false); + synchronized (RESIDENCE_WORKING) + { + RESIDENCE_WORKING[_residenceId] = false; + } } } @@ -212,14 +217,24 @@ public class SiegeGuards extends AbstractNpcAI } @Override + @SuppressWarnings("unchecked") public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) { final int residenceId = npc.getScriptValue(); - RESIDENCE_GUARD_MAP.get(RESIDENCE_GUARD_MAP.containsKey(residenceId) ? residenceId : 0).remove(npc); + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) + { + guardList.remove(npc); + } + else + { + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).remove(npc); + } return super.onKill(npc, killer, isSummon); } @Override + @SuppressWarnings("unchecked") public String onSpawn(Npc npc) { npc.setRandomWalking(false); @@ -232,13 +247,14 @@ public class SiegeGuards extends AbstractNpcAI final Fort fortress = npc.getFort(); final int residenceId = fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0); npc.setScriptValue(residenceId); - if (RESIDENCE_GUARD_MAP.containsKey(residenceId)) + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) { - RESIDENCE_GUARD_MAP.get(residenceId).add(npc); + guardList.add(npc); } else // Residence id not found. { - RESIDENCE_GUARD_MAP.get(0).add(npc); + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).add(npc); } return super.onSpawn(npc); diff --git a/L2J_Mobius_5.0_Salvation/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_5.0_Salvation/dist/game/data/scripts/ai/others/SiegeGuards.java index ef065f0f07..61df383afa 100644 --- a/L2J_Mobius_5.0_Salvation/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_5.0_Salvation/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,9 +16,8 @@ */ package ai.others; -import java.util.HashMap; +import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -92,8 +91,8 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on - private static final Map> RESIDENCE_GUARD_MAP = new HashMap<>(); - private static final Map RESIDENCE_WORKING = new HashMap<>(); + private static final Object[] RESIDENCE_GUARD_MAP = new Object[122]; + private static final boolean[] RESIDENCE_WORKING = new boolean[122]; public SiegeGuards() { @@ -110,17 +109,17 @@ public class SiegeGuards extends AbstractNpcAI addKillId(MERCENARIES); addKillId(STATIONARY_MERCENARIES); + Arrays.fill(RESIDENCE_WORKING, false); + // Start task for unknown residences. - RESIDENCE_GUARD_MAP.put(0, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(0, false); + RESIDENCE_GUARD_MAP[0] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(0), 0, 3000); // Start tasks for castles. for (Castle castle : CastleManager.getInstance().getCastles()) { final int residenceId = castle.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), residenceId * 100, 3000); } @@ -128,8 +127,7 @@ public class SiegeGuards extends AbstractNpcAI for (Fort fort : FortManager.getInstance().getForts()) { final int residenceId = fort.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), 900 + ((residenceId - 100) * 100), 3000); } } @@ -146,13 +144,17 @@ public class SiegeGuards extends AbstractNpcAI @Override public void run() { - if (RESIDENCE_WORKING.get(_residenceId)) + synchronized (RESIDENCE_WORKING) { - return; + if (RESIDENCE_WORKING[_residenceId]) + { + return; + } + RESIDENCE_WORKING[_residenceId] = true; } - RESIDENCE_WORKING.put(_residenceId, true); - final List guards = RESIDENCE_GUARD_MAP.get(_residenceId); + @SuppressWarnings("unchecked") + final List guards = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[_residenceId]; for (Npc guard : guards) { if (guard == null) @@ -196,7 +198,10 @@ public class SiegeGuards extends AbstractNpcAI } } - RESIDENCE_WORKING.put(_residenceId, false); + synchronized (RESIDENCE_WORKING) + { + RESIDENCE_WORKING[_residenceId] = false; + } } } @@ -212,14 +217,24 @@ public class SiegeGuards extends AbstractNpcAI } @Override + @SuppressWarnings("unchecked") public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) { final int residenceId = npc.getScriptValue(); - RESIDENCE_GUARD_MAP.get(RESIDENCE_GUARD_MAP.containsKey(residenceId) ? residenceId : 0).remove(npc); + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) + { + guardList.remove(npc); + } + else + { + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).remove(npc); + } return super.onKill(npc, killer, isSummon); } @Override + @SuppressWarnings("unchecked") public String onSpawn(Npc npc) { npc.setRandomWalking(false); @@ -232,13 +247,14 @@ public class SiegeGuards extends AbstractNpcAI final Fort fortress = npc.getFort(); final int residenceId = fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0); npc.setScriptValue(residenceId); - if (RESIDENCE_GUARD_MAP.containsKey(residenceId)) + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) { - RESIDENCE_GUARD_MAP.get(residenceId).add(npc); + guardList.add(npc); } else // Residence id not found. { - RESIDENCE_GUARD_MAP.get(0).add(npc); + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).add(npc); } return super.onSpawn(npc); diff --git a/L2J_Mobius_5.5_EtinasFate/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_5.5_EtinasFate/dist/game/data/scripts/ai/others/SiegeGuards.java index ef065f0f07..61df383afa 100644 --- a/L2J_Mobius_5.5_EtinasFate/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_5.5_EtinasFate/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,9 +16,8 @@ */ package ai.others; -import java.util.HashMap; +import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -92,8 +91,8 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on - private static final Map> RESIDENCE_GUARD_MAP = new HashMap<>(); - private static final Map RESIDENCE_WORKING = new HashMap<>(); + private static final Object[] RESIDENCE_GUARD_MAP = new Object[122]; + private static final boolean[] RESIDENCE_WORKING = new boolean[122]; public SiegeGuards() { @@ -110,17 +109,17 @@ public class SiegeGuards extends AbstractNpcAI addKillId(MERCENARIES); addKillId(STATIONARY_MERCENARIES); + Arrays.fill(RESIDENCE_WORKING, false); + // Start task for unknown residences. - RESIDENCE_GUARD_MAP.put(0, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(0, false); + RESIDENCE_GUARD_MAP[0] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(0), 0, 3000); // Start tasks for castles. for (Castle castle : CastleManager.getInstance().getCastles()) { final int residenceId = castle.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), residenceId * 100, 3000); } @@ -128,8 +127,7 @@ public class SiegeGuards extends AbstractNpcAI for (Fort fort : FortManager.getInstance().getForts()) { final int residenceId = fort.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), 900 + ((residenceId - 100) * 100), 3000); } } @@ -146,13 +144,17 @@ public class SiegeGuards extends AbstractNpcAI @Override public void run() { - if (RESIDENCE_WORKING.get(_residenceId)) + synchronized (RESIDENCE_WORKING) { - return; + if (RESIDENCE_WORKING[_residenceId]) + { + return; + } + RESIDENCE_WORKING[_residenceId] = true; } - RESIDENCE_WORKING.put(_residenceId, true); - final List guards = RESIDENCE_GUARD_MAP.get(_residenceId); + @SuppressWarnings("unchecked") + final List guards = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[_residenceId]; for (Npc guard : guards) { if (guard == null) @@ -196,7 +198,10 @@ public class SiegeGuards extends AbstractNpcAI } } - RESIDENCE_WORKING.put(_residenceId, false); + synchronized (RESIDENCE_WORKING) + { + RESIDENCE_WORKING[_residenceId] = false; + } } } @@ -212,14 +217,24 @@ public class SiegeGuards extends AbstractNpcAI } @Override + @SuppressWarnings("unchecked") public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) { final int residenceId = npc.getScriptValue(); - RESIDENCE_GUARD_MAP.get(RESIDENCE_GUARD_MAP.containsKey(residenceId) ? residenceId : 0).remove(npc); + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) + { + guardList.remove(npc); + } + else + { + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).remove(npc); + } return super.onKill(npc, killer, isSummon); } @Override + @SuppressWarnings("unchecked") public String onSpawn(Npc npc) { npc.setRandomWalking(false); @@ -232,13 +247,14 @@ public class SiegeGuards extends AbstractNpcAI final Fort fortress = npc.getFort(); final int residenceId = fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0); npc.setScriptValue(residenceId); - if (RESIDENCE_GUARD_MAP.containsKey(residenceId)) + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) { - RESIDENCE_GUARD_MAP.get(residenceId).add(npc); + guardList.add(npc); } else // Residence id not found. { - RESIDENCE_GUARD_MAP.get(0).add(npc); + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).add(npc); } return super.onSpawn(npc); diff --git a/L2J_Mobius_6.0_Fafurion/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_6.0_Fafurion/dist/game/data/scripts/ai/others/SiegeGuards.java index ef065f0f07..61df383afa 100644 --- a/L2J_Mobius_6.0_Fafurion/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_6.0_Fafurion/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,9 +16,8 @@ */ package ai.others; -import java.util.HashMap; +import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -92,8 +91,8 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on - private static final Map> RESIDENCE_GUARD_MAP = new HashMap<>(); - private static final Map RESIDENCE_WORKING = new HashMap<>(); + private static final Object[] RESIDENCE_GUARD_MAP = new Object[122]; + private static final boolean[] RESIDENCE_WORKING = new boolean[122]; public SiegeGuards() { @@ -110,17 +109,17 @@ public class SiegeGuards extends AbstractNpcAI addKillId(MERCENARIES); addKillId(STATIONARY_MERCENARIES); + Arrays.fill(RESIDENCE_WORKING, false); + // Start task for unknown residences. - RESIDENCE_GUARD_MAP.put(0, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(0, false); + RESIDENCE_GUARD_MAP[0] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(0), 0, 3000); // Start tasks for castles. for (Castle castle : CastleManager.getInstance().getCastles()) { final int residenceId = castle.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), residenceId * 100, 3000); } @@ -128,8 +127,7 @@ public class SiegeGuards extends AbstractNpcAI for (Fort fort : FortManager.getInstance().getForts()) { final int residenceId = fort.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), 900 + ((residenceId - 100) * 100), 3000); } } @@ -146,13 +144,17 @@ public class SiegeGuards extends AbstractNpcAI @Override public void run() { - if (RESIDENCE_WORKING.get(_residenceId)) + synchronized (RESIDENCE_WORKING) { - return; + if (RESIDENCE_WORKING[_residenceId]) + { + return; + } + RESIDENCE_WORKING[_residenceId] = true; } - RESIDENCE_WORKING.put(_residenceId, true); - final List guards = RESIDENCE_GUARD_MAP.get(_residenceId); + @SuppressWarnings("unchecked") + final List guards = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[_residenceId]; for (Npc guard : guards) { if (guard == null) @@ -196,7 +198,10 @@ public class SiegeGuards extends AbstractNpcAI } } - RESIDENCE_WORKING.put(_residenceId, false); + synchronized (RESIDENCE_WORKING) + { + RESIDENCE_WORKING[_residenceId] = false; + } } } @@ -212,14 +217,24 @@ public class SiegeGuards extends AbstractNpcAI } @Override + @SuppressWarnings("unchecked") public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) { final int residenceId = npc.getScriptValue(); - RESIDENCE_GUARD_MAP.get(RESIDENCE_GUARD_MAP.containsKey(residenceId) ? residenceId : 0).remove(npc); + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) + { + guardList.remove(npc); + } + else + { + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).remove(npc); + } return super.onKill(npc, killer, isSummon); } @Override + @SuppressWarnings("unchecked") public String onSpawn(Npc npc) { npc.setRandomWalking(false); @@ -232,13 +247,14 @@ public class SiegeGuards extends AbstractNpcAI final Fort fortress = npc.getFort(); final int residenceId = fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0); npc.setScriptValue(residenceId); - if (RESIDENCE_GUARD_MAP.containsKey(residenceId)) + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) { - RESIDENCE_GUARD_MAP.get(residenceId).add(npc); + guardList.add(npc); } else // Residence id not found. { - RESIDENCE_GUARD_MAP.get(0).add(npc); + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).add(npc); } return super.onSpawn(npc); diff --git a/L2J_Mobius_7.0_PreludeOfWar/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_7.0_PreludeOfWar/dist/game/data/scripts/ai/others/SiegeGuards.java index ef065f0f07..61df383afa 100644 --- a/L2J_Mobius_7.0_PreludeOfWar/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_7.0_PreludeOfWar/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,9 +16,8 @@ */ package ai.others; -import java.util.HashMap; +import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -92,8 +91,8 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on - private static final Map> RESIDENCE_GUARD_MAP = new HashMap<>(); - private static final Map RESIDENCE_WORKING = new HashMap<>(); + private static final Object[] RESIDENCE_GUARD_MAP = new Object[122]; + private static final boolean[] RESIDENCE_WORKING = new boolean[122]; public SiegeGuards() { @@ -110,17 +109,17 @@ public class SiegeGuards extends AbstractNpcAI addKillId(MERCENARIES); addKillId(STATIONARY_MERCENARIES); + Arrays.fill(RESIDENCE_WORKING, false); + // Start task for unknown residences. - RESIDENCE_GUARD_MAP.put(0, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(0, false); + RESIDENCE_GUARD_MAP[0] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(0), 0, 3000); // Start tasks for castles. for (Castle castle : CastleManager.getInstance().getCastles()) { final int residenceId = castle.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), residenceId * 100, 3000); } @@ -128,8 +127,7 @@ public class SiegeGuards extends AbstractNpcAI for (Fort fort : FortManager.getInstance().getForts()) { final int residenceId = fort.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), 900 + ((residenceId - 100) * 100), 3000); } } @@ -146,13 +144,17 @@ public class SiegeGuards extends AbstractNpcAI @Override public void run() { - if (RESIDENCE_WORKING.get(_residenceId)) + synchronized (RESIDENCE_WORKING) { - return; + if (RESIDENCE_WORKING[_residenceId]) + { + return; + } + RESIDENCE_WORKING[_residenceId] = true; } - RESIDENCE_WORKING.put(_residenceId, true); - final List guards = RESIDENCE_GUARD_MAP.get(_residenceId); + @SuppressWarnings("unchecked") + final List guards = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[_residenceId]; for (Npc guard : guards) { if (guard == null) @@ -196,7 +198,10 @@ public class SiegeGuards extends AbstractNpcAI } } - RESIDENCE_WORKING.put(_residenceId, false); + synchronized (RESIDENCE_WORKING) + { + RESIDENCE_WORKING[_residenceId] = false; + } } } @@ -212,14 +217,24 @@ public class SiegeGuards extends AbstractNpcAI } @Override + @SuppressWarnings("unchecked") public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) { final int residenceId = npc.getScriptValue(); - RESIDENCE_GUARD_MAP.get(RESIDENCE_GUARD_MAP.containsKey(residenceId) ? residenceId : 0).remove(npc); + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) + { + guardList.remove(npc); + } + else + { + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).remove(npc); + } return super.onKill(npc, killer, isSummon); } @Override + @SuppressWarnings("unchecked") public String onSpawn(Npc npc) { npc.setRandomWalking(false); @@ -232,13 +247,14 @@ public class SiegeGuards extends AbstractNpcAI final Fort fortress = npc.getFort(); final int residenceId = fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0); npc.setScriptValue(residenceId); - if (RESIDENCE_GUARD_MAP.containsKey(residenceId)) + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) { - RESIDENCE_GUARD_MAP.get(residenceId).add(npc); + guardList.add(npc); } else // Residence id not found. { - RESIDENCE_GUARD_MAP.get(0).add(npc); + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).add(npc); } return super.onSpawn(npc); diff --git a/L2J_Mobius_CT_2.4_Epilogue/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_CT_2.4_Epilogue/dist/game/data/scripts/ai/others/SiegeGuards.java index 3e8b42affd..6b7ecbde81 100644 --- a/L2J_Mobius_CT_2.4_Epilogue/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_CT_2.4_Epilogue/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,9 +16,8 @@ */ package ai.others; -import java.util.HashMap; +import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -92,8 +91,8 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on - private static final Map> RESIDENCE_GUARD_MAP = new HashMap<>(); - private static final Map RESIDENCE_WORKING = new HashMap<>(); + private static final Object[] RESIDENCE_GUARD_MAP = new Object[122]; + private static final boolean[] RESIDENCE_WORKING = new boolean[122]; public SiegeGuards() { @@ -110,17 +109,17 @@ public class SiegeGuards extends AbstractNpcAI addKillId(MERCENARIES); addKillId(STATIONARY_MERCENARIES); + Arrays.fill(RESIDENCE_WORKING, false); + // Start task for unknown residences. - RESIDENCE_GUARD_MAP.put(0, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(0, false); + RESIDENCE_GUARD_MAP[0] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(0), 0, 3000); // Start tasks for castles. for (Castle castle : CastleManager.getInstance().getCastles()) { final int residenceId = castle.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), residenceId * 100, 3000); } @@ -128,8 +127,7 @@ public class SiegeGuards extends AbstractNpcAI for (Fort fort : FortManager.getInstance().getForts()) { final int residenceId = fort.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), 900 + ((residenceId - 100) * 100), 3000); } } @@ -146,13 +144,17 @@ public class SiegeGuards extends AbstractNpcAI @Override public void run() { - if (RESIDENCE_WORKING.get(_residenceId)) + synchronized (RESIDENCE_WORKING) { - return; + if (RESIDENCE_WORKING[_residenceId]) + { + return; + } + RESIDENCE_WORKING[_residenceId] = true; } - RESIDENCE_WORKING.put(_residenceId, true); - final List guards = RESIDENCE_GUARD_MAP.get(_residenceId); + @SuppressWarnings("unchecked") + final List guards = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[_residenceId]; for (Npc guard : guards) { if (guard == null) @@ -196,7 +198,10 @@ public class SiegeGuards extends AbstractNpcAI } } - RESIDENCE_WORKING.put(_residenceId, false); + synchronized (RESIDENCE_WORKING) + { + RESIDENCE_WORKING[_residenceId] = false; + } } } @@ -212,14 +217,24 @@ public class SiegeGuards extends AbstractNpcAI } @Override + @SuppressWarnings("unchecked") public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) { final int residenceId = npc.getScriptValue(); - RESIDENCE_GUARD_MAP.get(RESIDENCE_GUARD_MAP.containsKey(residenceId) ? residenceId : 0).remove(npc); + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) + { + guardList.remove(npc); + } + else + { + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).remove(npc); + } return super.onKill(npc, killer, isSummon); } @Override + @SuppressWarnings("unchecked") public String onSpawn(Npc npc) { npc.setRandomWalking(false); @@ -232,13 +247,14 @@ public class SiegeGuards extends AbstractNpcAI final Fort fortress = npc.getFort(); final int residenceId = fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0); npc.setScriptValue(residenceId); - if (RESIDENCE_GUARD_MAP.containsKey(residenceId)) + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) { - RESIDENCE_GUARD_MAP.get(residenceId).add(npc); + guardList.add(npc); } else // Residence id not found. { - RESIDENCE_GUARD_MAP.get(0).add(npc); + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).add(npc); } return super.onSpawn(npc); diff --git a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/others/SiegeGuards.java index 3e8b42affd..6b7ecbde81 100644 --- a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,9 +16,8 @@ */ package ai.others; -import java.util.HashMap; +import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -92,8 +91,8 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on - private static final Map> RESIDENCE_GUARD_MAP = new HashMap<>(); - private static final Map RESIDENCE_WORKING = new HashMap<>(); + private static final Object[] RESIDENCE_GUARD_MAP = new Object[122]; + private static final boolean[] RESIDENCE_WORKING = new boolean[122]; public SiegeGuards() { @@ -110,17 +109,17 @@ public class SiegeGuards extends AbstractNpcAI addKillId(MERCENARIES); addKillId(STATIONARY_MERCENARIES); + Arrays.fill(RESIDENCE_WORKING, false); + // Start task for unknown residences. - RESIDENCE_GUARD_MAP.put(0, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(0, false); + RESIDENCE_GUARD_MAP[0] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(0), 0, 3000); // Start tasks for castles. for (Castle castle : CastleManager.getInstance().getCastles()) { final int residenceId = castle.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), residenceId * 100, 3000); } @@ -128,8 +127,7 @@ public class SiegeGuards extends AbstractNpcAI for (Fort fort : FortManager.getInstance().getForts()) { final int residenceId = fort.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), 900 + ((residenceId - 100) * 100), 3000); } } @@ -146,13 +144,17 @@ public class SiegeGuards extends AbstractNpcAI @Override public void run() { - if (RESIDENCE_WORKING.get(_residenceId)) + synchronized (RESIDENCE_WORKING) { - return; + if (RESIDENCE_WORKING[_residenceId]) + { + return; + } + RESIDENCE_WORKING[_residenceId] = true; } - RESIDENCE_WORKING.put(_residenceId, true); - final List guards = RESIDENCE_GUARD_MAP.get(_residenceId); + @SuppressWarnings("unchecked") + final List guards = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[_residenceId]; for (Npc guard : guards) { if (guard == null) @@ -196,7 +198,10 @@ public class SiegeGuards extends AbstractNpcAI } } - RESIDENCE_WORKING.put(_residenceId, false); + synchronized (RESIDENCE_WORKING) + { + RESIDENCE_WORKING[_residenceId] = false; + } } } @@ -212,14 +217,24 @@ public class SiegeGuards extends AbstractNpcAI } @Override + @SuppressWarnings("unchecked") public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) { final int residenceId = npc.getScriptValue(); - RESIDENCE_GUARD_MAP.get(RESIDENCE_GUARD_MAP.containsKey(residenceId) ? residenceId : 0).remove(npc); + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) + { + guardList.remove(npc); + } + else + { + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).remove(npc); + } return super.onKill(npc, killer, isSummon); } @Override + @SuppressWarnings("unchecked") public String onSpawn(Npc npc) { npc.setRandomWalking(false); @@ -232,13 +247,14 @@ public class SiegeGuards extends AbstractNpcAI final Fort fortress = npc.getFort(); final int residenceId = fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0); npc.setScriptValue(residenceId); - if (RESIDENCE_GUARD_MAP.containsKey(residenceId)) + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) { - RESIDENCE_GUARD_MAP.get(residenceId).add(npc); + guardList.add(npc); } else // Residence id not found. { - RESIDENCE_GUARD_MAP.get(0).add(npc); + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).add(npc); } return super.onSpawn(npc); diff --git a/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/ai/others/SiegeGuards.java index 3f3260f955..bf0454138b 100644 --- a/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,9 +16,8 @@ */ package ai.others; -import java.util.HashMap; +import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -67,8 +66,8 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on - private static final Map> RESIDENCE_GUARD_MAP = new HashMap<>(); - private static final Map RESIDENCE_WORKING = new HashMap<>(); + private static final Object[] RESIDENCE_GUARD_MAP = new Object[122]; + private static final boolean[] RESIDENCE_WORKING = new boolean[122]; public SiegeGuards() { @@ -82,17 +81,17 @@ public class SiegeGuards extends AbstractNpcAI addKillId(MERCENARIES); addKillId(STATIONARY_MERCENARIES); + Arrays.fill(RESIDENCE_WORKING, false); + // Start task for unknown residences. - RESIDENCE_GUARD_MAP.put(0, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(0, false); + RESIDENCE_GUARD_MAP[0] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(0), 0, 3000); // Start tasks for castles. for (Castle castle : CastleManager.getInstance().getCastles()) { final int residenceId = castle.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), residenceId * 100, 3000); } } @@ -109,13 +108,17 @@ public class SiegeGuards extends AbstractNpcAI @Override public void run() { - if (RESIDENCE_WORKING.get(_residenceId)) + synchronized (RESIDENCE_WORKING) { - return; + if (RESIDENCE_WORKING[_residenceId]) + { + return; + } + RESIDENCE_WORKING[_residenceId] = true; } - RESIDENCE_WORKING.put(_residenceId, true); - final List guards = RESIDENCE_GUARD_MAP.get(_residenceId); + @SuppressWarnings("unchecked") + final List guards = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[_residenceId]; for (Npc guard : guards) { if (guard == null) @@ -159,7 +162,10 @@ public class SiegeGuards extends AbstractNpcAI } } - RESIDENCE_WORKING.put(_residenceId, false); + synchronized (RESIDENCE_WORKING) + { + RESIDENCE_WORKING[_residenceId] = false; + } } } @@ -175,14 +181,24 @@ public class SiegeGuards extends AbstractNpcAI } @Override + @SuppressWarnings("unchecked") public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) { final int residenceId = npc.getScriptValue(); - RESIDENCE_GUARD_MAP.get(RESIDENCE_GUARD_MAP.containsKey(residenceId) ? residenceId : 0).remove(npc); + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) + { + guardList.remove(npc); + } + else + { + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).remove(npc); + } return super.onKill(npc, killer, isSummon); } @Override + @SuppressWarnings("unchecked") public String onSpawn(Npc npc) { npc.setRandomWalking(false); @@ -195,13 +211,14 @@ public class SiegeGuards extends AbstractNpcAI final Fort fortress = npc.getFort(); final int residenceId = fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0); npc.setScriptValue(residenceId); - if (RESIDENCE_GUARD_MAP.containsKey(residenceId)) + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) { - RESIDENCE_GUARD_MAP.get(residenceId).add(npc); + guardList.add(npc); } else // Residence id not found. { - RESIDENCE_GUARD_MAP.get(0).add(npc); + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).add(npc); } return super.onSpawn(npc); diff --git a/L2J_Mobius_Classic_2.1_Zaken/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_Classic_2.1_Zaken/dist/game/data/scripts/ai/others/SiegeGuards.java index 3f3260f955..bf0454138b 100644 --- a/L2J_Mobius_Classic_2.1_Zaken/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_Classic_2.1_Zaken/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,9 +16,8 @@ */ package ai.others; -import java.util.HashMap; +import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -67,8 +66,8 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on - private static final Map> RESIDENCE_GUARD_MAP = new HashMap<>(); - private static final Map RESIDENCE_WORKING = new HashMap<>(); + private static final Object[] RESIDENCE_GUARD_MAP = new Object[122]; + private static final boolean[] RESIDENCE_WORKING = new boolean[122]; public SiegeGuards() { @@ -82,17 +81,17 @@ public class SiegeGuards extends AbstractNpcAI addKillId(MERCENARIES); addKillId(STATIONARY_MERCENARIES); + Arrays.fill(RESIDENCE_WORKING, false); + // Start task for unknown residences. - RESIDENCE_GUARD_MAP.put(0, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(0, false); + RESIDENCE_GUARD_MAP[0] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(0), 0, 3000); // Start tasks for castles. for (Castle castle : CastleManager.getInstance().getCastles()) { final int residenceId = castle.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), residenceId * 100, 3000); } } @@ -109,13 +108,17 @@ public class SiegeGuards extends AbstractNpcAI @Override public void run() { - if (RESIDENCE_WORKING.get(_residenceId)) + synchronized (RESIDENCE_WORKING) { - return; + if (RESIDENCE_WORKING[_residenceId]) + { + return; + } + RESIDENCE_WORKING[_residenceId] = true; } - RESIDENCE_WORKING.put(_residenceId, true); - final List guards = RESIDENCE_GUARD_MAP.get(_residenceId); + @SuppressWarnings("unchecked") + final List guards = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[_residenceId]; for (Npc guard : guards) { if (guard == null) @@ -159,7 +162,10 @@ public class SiegeGuards extends AbstractNpcAI } } - RESIDENCE_WORKING.put(_residenceId, false); + synchronized (RESIDENCE_WORKING) + { + RESIDENCE_WORKING[_residenceId] = false; + } } } @@ -175,14 +181,24 @@ public class SiegeGuards extends AbstractNpcAI } @Override + @SuppressWarnings("unchecked") public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) { final int residenceId = npc.getScriptValue(); - RESIDENCE_GUARD_MAP.get(RESIDENCE_GUARD_MAP.containsKey(residenceId) ? residenceId : 0).remove(npc); + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) + { + guardList.remove(npc); + } + else + { + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).remove(npc); + } return super.onKill(npc, killer, isSummon); } @Override + @SuppressWarnings("unchecked") public String onSpawn(Npc npc) { npc.setRandomWalking(false); @@ -195,13 +211,14 @@ public class SiegeGuards extends AbstractNpcAI final Fort fortress = npc.getFort(); final int residenceId = fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0); npc.setScriptValue(residenceId); - if (RESIDENCE_GUARD_MAP.containsKey(residenceId)) + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) { - RESIDENCE_GUARD_MAP.get(residenceId).add(npc); + guardList.add(npc); } else // Residence id not found. { - RESIDENCE_GUARD_MAP.get(0).add(npc); + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).add(npc); } return super.onSpawn(npc); diff --git a/L2J_Mobius_Classic_2.2_Antharas/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_Classic_2.2_Antharas/dist/game/data/scripts/ai/others/SiegeGuards.java index 3f3260f955..bf0454138b 100644 --- a/L2J_Mobius_Classic_2.2_Antharas/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_Classic_2.2_Antharas/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,9 +16,8 @@ */ package ai.others; -import java.util.HashMap; +import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -67,8 +66,8 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on - private static final Map> RESIDENCE_GUARD_MAP = new HashMap<>(); - private static final Map RESIDENCE_WORKING = new HashMap<>(); + private static final Object[] RESIDENCE_GUARD_MAP = new Object[122]; + private static final boolean[] RESIDENCE_WORKING = new boolean[122]; public SiegeGuards() { @@ -82,17 +81,17 @@ public class SiegeGuards extends AbstractNpcAI addKillId(MERCENARIES); addKillId(STATIONARY_MERCENARIES); + Arrays.fill(RESIDENCE_WORKING, false); + // Start task for unknown residences. - RESIDENCE_GUARD_MAP.put(0, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(0, false); + RESIDENCE_GUARD_MAP[0] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(0), 0, 3000); // Start tasks for castles. for (Castle castle : CastleManager.getInstance().getCastles()) { final int residenceId = castle.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), residenceId * 100, 3000); } } @@ -109,13 +108,17 @@ public class SiegeGuards extends AbstractNpcAI @Override public void run() { - if (RESIDENCE_WORKING.get(_residenceId)) + synchronized (RESIDENCE_WORKING) { - return; + if (RESIDENCE_WORKING[_residenceId]) + { + return; + } + RESIDENCE_WORKING[_residenceId] = true; } - RESIDENCE_WORKING.put(_residenceId, true); - final List guards = RESIDENCE_GUARD_MAP.get(_residenceId); + @SuppressWarnings("unchecked") + final List guards = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[_residenceId]; for (Npc guard : guards) { if (guard == null) @@ -159,7 +162,10 @@ public class SiegeGuards extends AbstractNpcAI } } - RESIDENCE_WORKING.put(_residenceId, false); + synchronized (RESIDENCE_WORKING) + { + RESIDENCE_WORKING[_residenceId] = false; + } } } @@ -175,14 +181,24 @@ public class SiegeGuards extends AbstractNpcAI } @Override + @SuppressWarnings("unchecked") public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) { final int residenceId = npc.getScriptValue(); - RESIDENCE_GUARD_MAP.get(RESIDENCE_GUARD_MAP.containsKey(residenceId) ? residenceId : 0).remove(npc); + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) + { + guardList.remove(npc); + } + else + { + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).remove(npc); + } return super.onKill(npc, killer, isSummon); } @Override + @SuppressWarnings("unchecked") public String onSpawn(Npc npc) { npc.setRandomWalking(false); @@ -195,13 +211,14 @@ public class SiegeGuards extends AbstractNpcAI final Fort fortress = npc.getFort(); final int residenceId = fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0); npc.setScriptValue(residenceId); - if (RESIDENCE_GUARD_MAP.containsKey(residenceId)) + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) { - RESIDENCE_GUARD_MAP.get(residenceId).add(npc); + guardList.add(npc); } else // Residence id not found. { - RESIDENCE_GUARD_MAP.get(0).add(npc); + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).add(npc); } return super.onSpawn(npc); diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_Classic_2.3_SevenSigns/dist/game/data/scripts/ai/others/SiegeGuards.java index 3f3260f955..bf0454138b 100644 --- a/L2J_Mobius_Classic_2.3_SevenSigns/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_Classic_2.3_SevenSigns/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,9 +16,8 @@ */ package ai.others; -import java.util.HashMap; +import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -67,8 +66,8 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on - private static final Map> RESIDENCE_GUARD_MAP = new HashMap<>(); - private static final Map RESIDENCE_WORKING = new HashMap<>(); + private static final Object[] RESIDENCE_GUARD_MAP = new Object[122]; + private static final boolean[] RESIDENCE_WORKING = new boolean[122]; public SiegeGuards() { @@ -82,17 +81,17 @@ public class SiegeGuards extends AbstractNpcAI addKillId(MERCENARIES); addKillId(STATIONARY_MERCENARIES); + Arrays.fill(RESIDENCE_WORKING, false); + // Start task for unknown residences. - RESIDENCE_GUARD_MAP.put(0, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(0, false); + RESIDENCE_GUARD_MAP[0] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(0), 0, 3000); // Start tasks for castles. for (Castle castle : CastleManager.getInstance().getCastles()) { final int residenceId = castle.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), residenceId * 100, 3000); } } @@ -109,13 +108,17 @@ public class SiegeGuards extends AbstractNpcAI @Override public void run() { - if (RESIDENCE_WORKING.get(_residenceId)) + synchronized (RESIDENCE_WORKING) { - return; + if (RESIDENCE_WORKING[_residenceId]) + { + return; + } + RESIDENCE_WORKING[_residenceId] = true; } - RESIDENCE_WORKING.put(_residenceId, true); - final List guards = RESIDENCE_GUARD_MAP.get(_residenceId); + @SuppressWarnings("unchecked") + final List guards = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[_residenceId]; for (Npc guard : guards) { if (guard == null) @@ -159,7 +162,10 @@ public class SiegeGuards extends AbstractNpcAI } } - RESIDENCE_WORKING.put(_residenceId, false); + synchronized (RESIDENCE_WORKING) + { + RESIDENCE_WORKING[_residenceId] = false; + } } } @@ -175,14 +181,24 @@ public class SiegeGuards extends AbstractNpcAI } @Override + @SuppressWarnings("unchecked") public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) { final int residenceId = npc.getScriptValue(); - RESIDENCE_GUARD_MAP.get(RESIDENCE_GUARD_MAP.containsKey(residenceId) ? residenceId : 0).remove(npc); + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) + { + guardList.remove(npc); + } + else + { + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).remove(npc); + } return super.onKill(npc, killer, isSummon); } @Override + @SuppressWarnings("unchecked") public String onSpawn(Npc npc) { npc.setRandomWalking(false); @@ -195,13 +211,14 @@ public class SiegeGuards extends AbstractNpcAI final Fort fortress = npc.getFort(); final int residenceId = fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0); npc.setScriptValue(residenceId); - if (RESIDENCE_GUARD_MAP.containsKey(residenceId)) + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) { - RESIDENCE_GUARD_MAP.get(residenceId).add(npc); + guardList.add(npc); } else // Residence id not found. { - RESIDENCE_GUARD_MAP.get(0).add(npc); + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).add(npc); } return super.onSpawn(npc); diff --git a/L2J_Mobius_Classic_2.4_SecretOfEmpire/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_Classic_2.4_SecretOfEmpire/dist/game/data/scripts/ai/others/SiegeGuards.java index 3f3260f955..bf0454138b 100644 --- a/L2J_Mobius_Classic_2.4_SecretOfEmpire/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_Classic_2.4_SecretOfEmpire/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,9 +16,8 @@ */ package ai.others; -import java.util.HashMap; +import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -67,8 +66,8 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on - private static final Map> RESIDENCE_GUARD_MAP = new HashMap<>(); - private static final Map RESIDENCE_WORKING = new HashMap<>(); + private static final Object[] RESIDENCE_GUARD_MAP = new Object[122]; + private static final boolean[] RESIDENCE_WORKING = new boolean[122]; public SiegeGuards() { @@ -82,17 +81,17 @@ public class SiegeGuards extends AbstractNpcAI addKillId(MERCENARIES); addKillId(STATIONARY_MERCENARIES); + Arrays.fill(RESIDENCE_WORKING, false); + // Start task for unknown residences. - RESIDENCE_GUARD_MAP.put(0, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(0, false); + RESIDENCE_GUARD_MAP[0] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(0), 0, 3000); // Start tasks for castles. for (Castle castle : CastleManager.getInstance().getCastles()) { final int residenceId = castle.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), residenceId * 100, 3000); } } @@ -109,13 +108,17 @@ public class SiegeGuards extends AbstractNpcAI @Override public void run() { - if (RESIDENCE_WORKING.get(_residenceId)) + synchronized (RESIDENCE_WORKING) { - return; + if (RESIDENCE_WORKING[_residenceId]) + { + return; + } + RESIDENCE_WORKING[_residenceId] = true; } - RESIDENCE_WORKING.put(_residenceId, true); - final List guards = RESIDENCE_GUARD_MAP.get(_residenceId); + @SuppressWarnings("unchecked") + final List guards = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[_residenceId]; for (Npc guard : guards) { if (guard == null) @@ -159,7 +162,10 @@ public class SiegeGuards extends AbstractNpcAI } } - RESIDENCE_WORKING.put(_residenceId, false); + synchronized (RESIDENCE_WORKING) + { + RESIDENCE_WORKING[_residenceId] = false; + } } } @@ -175,14 +181,24 @@ public class SiegeGuards extends AbstractNpcAI } @Override + @SuppressWarnings("unchecked") public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) { final int residenceId = npc.getScriptValue(); - RESIDENCE_GUARD_MAP.get(RESIDENCE_GUARD_MAP.containsKey(residenceId) ? residenceId : 0).remove(npc); + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) + { + guardList.remove(npc); + } + else + { + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).remove(npc); + } return super.onKill(npc, killer, isSummon); } @Override + @SuppressWarnings("unchecked") public String onSpawn(Npc npc) { npc.setRandomWalking(false); @@ -195,13 +211,14 @@ public class SiegeGuards extends AbstractNpcAI final Fort fortress = npc.getFort(); final int residenceId = fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0); npc.setScriptValue(residenceId); - if (RESIDENCE_GUARD_MAP.containsKey(residenceId)) + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) { - RESIDENCE_GUARD_MAP.get(residenceId).add(npc); + guardList.add(npc); } else // Residence id not found. { - RESIDENCE_GUARD_MAP.get(0).add(npc); + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).add(npc); } return super.onSpawn(npc); diff --git a/L2J_Mobius_Classic_3.0_TheKamael/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_Classic_3.0_TheKamael/dist/game/data/scripts/ai/others/SiegeGuards.java index 3f3260f955..bf0454138b 100644 --- a/L2J_Mobius_Classic_3.0_TheKamael/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_Classic_3.0_TheKamael/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,9 +16,8 @@ */ package ai.others; -import java.util.HashMap; +import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -67,8 +66,8 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on - private static final Map> RESIDENCE_GUARD_MAP = new HashMap<>(); - private static final Map RESIDENCE_WORKING = new HashMap<>(); + private static final Object[] RESIDENCE_GUARD_MAP = new Object[122]; + private static final boolean[] RESIDENCE_WORKING = new boolean[122]; public SiegeGuards() { @@ -82,17 +81,17 @@ public class SiegeGuards extends AbstractNpcAI addKillId(MERCENARIES); addKillId(STATIONARY_MERCENARIES); + Arrays.fill(RESIDENCE_WORKING, false); + // Start task for unknown residences. - RESIDENCE_GUARD_MAP.put(0, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(0, false); + RESIDENCE_GUARD_MAP[0] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(0), 0, 3000); // Start tasks for castles. for (Castle castle : CastleManager.getInstance().getCastles()) { final int residenceId = castle.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), residenceId * 100, 3000); } } @@ -109,13 +108,17 @@ public class SiegeGuards extends AbstractNpcAI @Override public void run() { - if (RESIDENCE_WORKING.get(_residenceId)) + synchronized (RESIDENCE_WORKING) { - return; + if (RESIDENCE_WORKING[_residenceId]) + { + return; + } + RESIDENCE_WORKING[_residenceId] = true; } - RESIDENCE_WORKING.put(_residenceId, true); - final List guards = RESIDENCE_GUARD_MAP.get(_residenceId); + @SuppressWarnings("unchecked") + final List guards = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[_residenceId]; for (Npc guard : guards) { if (guard == null) @@ -159,7 +162,10 @@ public class SiegeGuards extends AbstractNpcAI } } - RESIDENCE_WORKING.put(_residenceId, false); + synchronized (RESIDENCE_WORKING) + { + RESIDENCE_WORKING[_residenceId] = false; + } } } @@ -175,14 +181,24 @@ public class SiegeGuards extends AbstractNpcAI } @Override + @SuppressWarnings("unchecked") public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) { final int residenceId = npc.getScriptValue(); - RESIDENCE_GUARD_MAP.get(RESIDENCE_GUARD_MAP.containsKey(residenceId) ? residenceId : 0).remove(npc); + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) + { + guardList.remove(npc); + } + else + { + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).remove(npc); + } return super.onKill(npc, killer, isSummon); } @Override + @SuppressWarnings("unchecked") public String onSpawn(Npc npc) { npc.setRandomWalking(false); @@ -195,13 +211,14 @@ public class SiegeGuards extends AbstractNpcAI final Fort fortress = npc.getFort(); final int residenceId = fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0); npc.setScriptValue(residenceId); - if (RESIDENCE_GUARD_MAP.containsKey(residenceId)) + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) { - RESIDENCE_GUARD_MAP.get(residenceId).add(npc); + guardList.add(npc); } else // Residence id not found. { - RESIDENCE_GUARD_MAP.get(0).add(npc); + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).add(npc); } return super.onSpawn(npc); diff --git a/L2J_Mobius_Classic_Interlude/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_Classic_Interlude/dist/game/data/scripts/ai/others/SiegeGuards.java index 3f3260f955..bf0454138b 100644 --- a/L2J_Mobius_Classic_Interlude/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_Classic_Interlude/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,9 +16,8 @@ */ package ai.others; -import java.util.HashMap; +import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import org.l2jmobius.commons.concurrent.ThreadPool; @@ -67,8 +66,8 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on - private static final Map> RESIDENCE_GUARD_MAP = new HashMap<>(); - private static final Map RESIDENCE_WORKING = new HashMap<>(); + private static final Object[] RESIDENCE_GUARD_MAP = new Object[122]; + private static final boolean[] RESIDENCE_WORKING = new boolean[122]; public SiegeGuards() { @@ -82,17 +81,17 @@ public class SiegeGuards extends AbstractNpcAI addKillId(MERCENARIES); addKillId(STATIONARY_MERCENARIES); + Arrays.fill(RESIDENCE_WORKING, false); + // Start task for unknown residences. - RESIDENCE_GUARD_MAP.put(0, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(0, false); + RESIDENCE_GUARD_MAP[0] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(0), 0, 3000); // Start tasks for castles. for (Castle castle : CastleManager.getInstance().getCastles()) { final int residenceId = castle.getResidenceId(); - RESIDENCE_GUARD_MAP.put(residenceId, new CopyOnWriteArrayList<>()); - RESIDENCE_WORKING.put(residenceId, false); + RESIDENCE_GUARD_MAP[residenceId] = new CopyOnWriteArrayList<>(); ThreadPool.scheduleAtFixedRate(new AggroCheckTask(residenceId), residenceId * 100, 3000); } } @@ -109,13 +108,17 @@ public class SiegeGuards extends AbstractNpcAI @Override public void run() { - if (RESIDENCE_WORKING.get(_residenceId)) + synchronized (RESIDENCE_WORKING) { - return; + if (RESIDENCE_WORKING[_residenceId]) + { + return; + } + RESIDENCE_WORKING[_residenceId] = true; } - RESIDENCE_WORKING.put(_residenceId, true); - final List guards = RESIDENCE_GUARD_MAP.get(_residenceId); + @SuppressWarnings("unchecked") + final List guards = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[_residenceId]; for (Npc guard : guards) { if (guard == null) @@ -159,7 +162,10 @@ public class SiegeGuards extends AbstractNpcAI } } - RESIDENCE_WORKING.put(_residenceId, false); + synchronized (RESIDENCE_WORKING) + { + RESIDENCE_WORKING[_residenceId] = false; + } } } @@ -175,14 +181,24 @@ public class SiegeGuards extends AbstractNpcAI } @Override + @SuppressWarnings("unchecked") public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) { final int residenceId = npc.getScriptValue(); - RESIDENCE_GUARD_MAP.get(RESIDENCE_GUARD_MAP.containsKey(residenceId) ? residenceId : 0).remove(npc); + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) + { + guardList.remove(npc); + } + else + { + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).remove(npc); + } return super.onKill(npc, killer, isSummon); } @Override + @SuppressWarnings("unchecked") public String onSpawn(Npc npc) { npc.setRandomWalking(false); @@ -195,13 +211,14 @@ public class SiegeGuards extends AbstractNpcAI final Fort fortress = npc.getFort(); final int residenceId = fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0); npc.setScriptValue(residenceId); - if (RESIDENCE_GUARD_MAP.containsKey(residenceId)) + final List guardList = (CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[residenceId]; + if (guardList != null) { - RESIDENCE_GUARD_MAP.get(residenceId).add(npc); + guardList.add(npc); } else // Residence id not found. { - RESIDENCE_GUARD_MAP.get(0).add(npc); + ((CopyOnWriteArrayList) RESIDENCE_GUARD_MAP[0]).add(npc); } return super.onSpawn(npc);