فهرست منبع

BETA: Fixes for [4972].
* Implemented method getAllNpcOfClass.
* Implemented method getAllNpcOfAiType.

Zoey76 13 سال پیش
والد
کامیت
238a8ff391

+ 53 - 37
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/NpcTable.java

@@ -21,7 +21,6 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.ResultSet;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
-import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import java.util.logging.Logger;
 
 
@@ -847,43 +846,44 @@ public class NpcTable
 	
 	
 	public L2NpcTemplate getTemplateByName(String name)
 	public L2NpcTemplate getTemplateByName(String name)
 	{
 	{
-		for (Object npcTemplate : _npcs.values())
-			if (((L2NpcTemplate)npcTemplate).name.equalsIgnoreCase(name))
-				return (L2NpcTemplate) npcTemplate;
-		
+		for (L2NpcTemplate npcTemplate : _npcs.valueCollection())
+		{
+			if (npcTemplate.name.equalsIgnoreCase(name))
+				return npcTemplate;
+		}
 		return null;
 		return null;
 	}
 	}
 	
 	
 	public L2NpcTemplate[] getAllOfLevel(int lvl)
 	public L2NpcTemplate[] getAllOfLevel(int lvl)
 	{
 	{
-		List<L2NpcTemplate> list = new FastList<L2NpcTemplate>();
-		
-		for (Object t : _npcs.values())
-			if (((L2NpcTemplate)t).level == lvl)
-				list.add((L2NpcTemplate) t);
-		
+		final List<L2NpcTemplate> list = new FastList<L2NpcTemplate>();
+		for (L2NpcTemplate npcTemplate : _npcs.valueCollection())
+		{
+			if (npcTemplate.level == lvl)
+				list.add(npcTemplate);
+		}
 		return list.toArray(new L2NpcTemplate[list.size()]);
 		return list.toArray(new L2NpcTemplate[list.size()]);
 	}
 	}
 	
 	
 	public L2NpcTemplate[] getAllMonstersOfLevel(int lvl)
 	public L2NpcTemplate[] getAllMonstersOfLevel(int lvl)
 	{
 	{
-		List<L2NpcTemplate> list = new FastList<L2NpcTemplate>();
-		
-		for (Object t : _npcs.values())
-			if (((L2NpcTemplate)t).level == lvl && "L2Monster".equals(((L2NpcTemplate)t).type))
-				list.add((L2NpcTemplate) t);
-		
+		final List<L2NpcTemplate> list = new FastList<L2NpcTemplate>();
+		for (L2NpcTemplate npcTemplate : _npcs.valueCollection())
+		{
+			if (npcTemplate.level == lvl && "L2Monster".equals(npcTemplate.type))
+				list.add(npcTemplate);
+		}
 		return list.toArray(new L2NpcTemplate[list.size()]);
 		return list.toArray(new L2NpcTemplate[list.size()]);
 	}
 	}
 	
 	
 	public L2NpcTemplate[] getAllNpcStartingWith(String letter)
 	public L2NpcTemplate[] getAllNpcStartingWith(String letter)
 	{
 	{
-		List<L2NpcTemplate> list = new FastList<L2NpcTemplate>();
-		
-		for (Object t : _npcs.values())
-			if (((L2NpcTemplate)t).name.startsWith(letter) && "L2Npc".equals(((L2NpcTemplate)t).type))
-				list.add((L2NpcTemplate) t);
-		
+		final List<L2NpcTemplate> list = new FastList<L2NpcTemplate>();
+		for (L2NpcTemplate npcTemplate : _npcs.valueCollection())
+		{
+			if (npcTemplate.name.startsWith(letter) && "L2Npc".equals(npcTemplate.type))
+				list.add(npcTemplate);
+		}
 		return list.toArray(new L2NpcTemplate[list.size()]);
 		return list.toArray(new L2NpcTemplate[list.size()]);
 	}
 	}
 	
 	
@@ -893,31 +893,47 @@ public class NpcTable
 	 */
 	 */
 	public L2NpcTemplate[] getAllNpcOfClassType(String classType)
 	public L2NpcTemplate[] getAllNpcOfClassType(String classType)
 	{
 	{
-		List<L2NpcTemplate> list = new FastList<L2NpcTemplate>();
-		
-		for (Object t : _npcs.values())
-			if (classType.equals(((L2NpcTemplate)t).type))
-				list.add((L2NpcTemplate) t);
-		
+		final List<L2NpcTemplate> list = new FastList<L2NpcTemplate>();
+		for (L2NpcTemplate npcTemplate : _npcs.valueCollection())
+		{
+			if (classType.equals(npcTemplate.type))
+				list.add(npcTemplate);
+		}
 		return list.toArray(new L2NpcTemplate[list.size()]);
 		return list.toArray(new L2NpcTemplate[list.size()]);
 	}
 	}
 
 
 	/**
 	/**
-	 * @param clazz
-	 * @return
+	 * @param clazz the class type to search.
+	 * @return list of all NPC templates with class {@code clazz}.
 	 */
 	 */
-	public Set<Integer> getAllNpcOfL2jClass(Class<?> clazz)
+	public List<L2NpcTemplate> getAllNpcOfClass(Class<?> clazz)
 	{
 	{
-		return null;
+		final List<L2NpcTemplate> list = new FastList<L2NpcTemplate>();
+		for (L2NpcTemplate npcTemplate : _npcs.valueCollection())
+		{
+			if (npcTemplate.type.equals(clazz.getSimpleName()))
+			{
+				list.add(npcTemplate);
+			}
+		}
+		return list;
 	}
 	}
 	
 	
 	/**
 	/**
-	 * @param aiType
-	 * @return
+	 * @param aiType the AI type to search.
+	 * @return list of all NPC templates with AI type {@code aiType}.
 	 */
 	 */
-	public Set<Integer> getAllNpcOfAiType(String aiType)
+	public List<L2NpcTemplate> getAllNpcOfAiType(String aiType)
 	{
 	{
-		return null;
+		final List<L2NpcTemplate> list = new FastList<L2NpcTemplate>();
+		for (L2NpcTemplate npcTemplate : _npcs.valueCollection())
+		{
+			if ((npcTemplate.getAIDataStatic() != null) && npcTemplate.getAIDataStatic().getAiType().name().equals(aiType))
+			{
+				list.add(npcTemplate);
+			}
+		}
+		return list;
 	}
 	}
 	
 	
 	@SuppressWarnings("synthetic-access")
 	@SuppressWarnings("synthetic-access")

+ 9 - 17
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/NpcWalkerRoutesTable.java

@@ -33,18 +33,14 @@ import com.l2jserver.gameserver.model.L2NpcWalkerNode;
 import com.l2jserver.gameserver.network.NpcStringId;
 import com.l2jserver.gameserver.network.NpcStringId;
 
 
 /**
 /**
- * Main Table to Load Npc Walkers Routes and Chat SQL Table.<br>
- * 
- * @author Rayan RPG for L2Emu Project, JIV
- * 
- * @since 927
- *
+ * Main Table to Load Npc Walkers Routes and Chat.<br>
+ * @author Rayan, JIV
  */
  */
 public class NpcWalkerRoutesTable
 public class NpcWalkerRoutesTable
 {
 {
-	private final static Logger _log = Logger.getLogger(SpawnTable.class.getName());
+	private final static Logger _log = Logger.getLogger(NpcWalkerRoutesTable.class.getName());
 	
 	
-	private TIntObjectHashMap<List<L2NpcWalkerNode>> _routes = new TIntObjectHashMap<List<L2NpcWalkerNode>>();
+	private final TIntObjectHashMap<List<L2NpcWalkerNode>> _routes = new TIntObjectHashMap<List<L2NpcWalkerNode>>();
 	
 	
 	public static NpcWalkerRoutesTable getInstance()
 	public static NpcWalkerRoutesTable getInstance()
 	{
 	{
@@ -100,7 +96,9 @@ public class NpcWalkerRoutesTable
 							NpcStringId npcString = null;
 							NpcStringId npcString = null;
 							Node node = attrs.getNamedItem("string");
 							Node node = attrs.getNamedItem("string");
 							if (node != null)
 							if (node != null)
+							{
 								chatString = node.getNodeValue();
 								chatString = node.getNodeValue();
+							}
 							else
 							else
 							{
 							{
 								node = attrs.getNamedItem("npcString");
 								node = attrs.getNamedItem("npcString");
@@ -132,14 +130,13 @@ public class NpcWalkerRoutesTable
 							list.add(new L2NpcWalkerNode(id, npcString, chatString, x, y, z, delay, running));
 							list.add(new L2NpcWalkerNode(id, npcString, chatString, x, y, z, delay, running));
 						}
 						}
 					}
 					}
+					
+					// ArrayList has initial capacity of 10, let's trim them to size before putting it into the map.
+					((ArrayList<L2NpcWalkerNode>) list).trimToSize();
 					_routes.put(npcId, list);
 					_routes.put(npcId, list);
 				}
 				}
 			}
 			}
 		}
 		}
-		
-		for (Object list : _routes.values())
-			((ArrayList<?>)list).trimToSize();
-		
 		_log.info("WalkerRoutesTable: Loaded " + _routes.size() + " Npc Walker Routes.");
 		_log.info("WalkerRoutesTable: Loaded " + _routes.size() + " Npc Walker Routes.");
 	}
 	}
 	
 	
@@ -153,9 +150,4 @@ public class NpcWalkerRoutesTable
 	{
 	{
 		protected static final NpcWalkerRoutesTable _instance = new NpcWalkerRoutesTable();
 		protected static final NpcWalkerRoutesTable _instance = new NpcWalkerRoutesTable();
 	}
 	}
-	
-	public static void main(String... arg)
-	{
-		getInstance().load();
-	}
 }
 }

+ 12 - 13
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/SummonItemsData.java

@@ -12,13 +12,6 @@
  * You should have received a copy of the GNU General Public License along with
  * You should have received a copy of the GNU General Public License along with
  * this program. If not, see <http://www.gnu.org/licenses/>.
  * this program. If not, see <http://www.gnu.org/licenses/>.
  */
  */
-
-/**
- *
- * @author FBIagent
- *
- */
-
 package com.l2jserver.gameserver.datatables;
 package com.l2jserver.gameserver.datatables;
 
 
 import gnu.trove.map.hash.TIntObjectHashMap;
 import gnu.trove.map.hash.TIntObjectHashMap;
@@ -30,10 +23,13 @@ import java.util.logging.Logger;
 import com.l2jserver.Config;
 import com.l2jserver.Config;
 import com.l2jserver.gameserver.model.L2SummonItem;
 import com.l2jserver.gameserver.model.L2SummonItem;
 
 
+/**
+ * @author FBIagent
+ */
 public class SummonItemsData
 public class SummonItemsData
 {
 {
 	protected static final Logger _log = Logger.getLogger(SummonItemsData.class.getName());
 	protected static final Logger _log = Logger.getLogger(SummonItemsData.class.getName());
-	private TIntObjectHashMap<L2SummonItem> _summonitems;
+	private final TIntObjectHashMap<L2SummonItem> _summonitems = new TIntObjectHashMap<L2SummonItem>();
 	
 	
 	public static SummonItemsData getInstance()
 	public static SummonItemsData getInstance()
 	{
 	{
@@ -42,10 +38,7 @@ public class SummonItemsData
 	
 	
 	private SummonItemsData()
 	private SummonItemsData()
 	{
 	{
-		_summonitems = new TIntObjectHashMap<L2SummonItem>();
-		
 		Scanner s;
 		Scanner s;
-		
 		try
 		try
 		{
 		{
 			s = new Scanner(new File(Config.DATAPACK_ROOT + "/data/summon_items.csv"));
 			s = new Scanner(new File(Config.DATAPACK_ROOT + "/data/summon_items.csv"));
@@ -69,7 +62,9 @@ public class SummonItemsData
 				continue;
 				continue;
 			}
 			}
 			else if (line.isEmpty())
 			else if (line.isEmpty())
+			{
 				continue;
 				continue;
+			}
 			
 			
 			String[] lineSplit = line.split(";");
 			String[] lineSplit = line.split(";");
 			boolean ok = true;
 			boolean ok = true;
@@ -83,7 +78,9 @@ public class SummonItemsData
 				npcID = Integer.parseInt(lineSplit[1]);
 				npcID = Integer.parseInt(lineSplit[1]);
 				summonType = Byte.parseByte(lineSplit[2]);
 				summonType = Byte.parseByte(lineSplit[2]);
 				if (summonType == 0)
 				if (summonType == 0)
+				{
 					despawn = Integer.parseInt(lineSplit[3]);
 					despawn = Integer.parseInt(lineSplit[3]);
+				}
 			}
 			}
 			catch (Exception e)
 			catch (Exception e)
 			{
 			{
@@ -93,7 +90,9 @@ public class SummonItemsData
 			}
 			}
 			
 			
 			if (!ok)
 			if (!ok)
+			{
 				continue;
 				continue;
+			}
 			
 			
 			L2SummonItem summonitem = new L2SummonItem(itemID, npcID, summonType, despawn);
 			L2SummonItem summonitem = new L2SummonItem(itemID, npcID, summonType, despawn);
 			_summonitems.put(itemID, summonitem);
 			_summonitems.put(itemID, summonitem);
@@ -112,9 +111,9 @@ public class SummonItemsData
 		int size = _summonitems.size();
 		int size = _summonitems.size();
 		int[] result = new int[size];
 		int[] result = new int[size];
 		int i = 0;
 		int i = 0;
-		for (Object si : _summonitems.values())
+		for (L2SummonItem si : _summonitems.valueCollection())
 		{
 		{
-			result[i++] = ((L2SummonItem) si).getItemId();
+			result[i++] = si.getItemId();
 		}
 		}
 		return result;
 		return result;
 	}
 	}

+ 6 - 6
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/DimensionalRiftManager.java

@@ -55,7 +55,7 @@ import com.l2jserver.util.Rnd;
 public class DimensionalRiftManager
 public class DimensionalRiftManager
 {
 {
 	private static Logger _log = Logger.getLogger(DimensionalRiftManager.class.getName());
 	private static Logger _log = Logger.getLogger(DimensionalRiftManager.class.getName());
-	private TByteObjectHashMap<TByteObjectHashMap<DimensionalRiftRoom>> _rooms = new TByteObjectHashMap<TByteObjectHashMap<DimensionalRiftRoom>>(7);
+	private final TByteObjectHashMap<TByteObjectHashMap<DimensionalRiftRoom>> _rooms = new TByteObjectHashMap<TByteObjectHashMap<DimensionalRiftRoom>>(7);
 	private final int DIMENSIONAL_FRAGMENT_ITEM_ID = 7079;
 	private final int DIMENSIONAL_FRAGMENT_ITEM_ID = 7079;
 	
 	
 	public static DimensionalRiftManager getInstance()
 	public static DimensionalRiftManager getInstance()
@@ -540,9 +540,9 @@ public class DimensionalRiftManager
 	public boolean isAllowedEnter(byte type)
 	public boolean isAllowedEnter(byte type)
 	{
 	{
 		int count = 0;
 		int count = 0;
-		for (Object room : _rooms.get(type).values())
+		for (DimensionalRiftRoom room : _rooms.get(type).valueCollection())
 		{
 		{
-			if (((DimensionalRiftRoom) room).ispartyInside())
+			if (room.ispartyInside())
 				count++;
 				count++;
 		}
 		}
 		return (count < (_rooms.get(type).size() - 1));
 		return (count < (_rooms.get(type).size() - 1));
@@ -551,10 +551,10 @@ public class DimensionalRiftManager
 	public FastList<Byte> getFreeRooms(byte type)
 	public FastList<Byte> getFreeRooms(byte type)
 	{
 	{
 		FastList<Byte> list = new FastList<Byte>();
 		FastList<Byte> list = new FastList<Byte>();
-		for (Object room : _rooms.get(type).values())
+		for (DimensionalRiftRoom room : _rooms.get(type).valueCollection())
 		{
 		{
-			if (!((DimensionalRiftRoom) room).ispartyInside())
-				list.add(((DimensionalRiftRoom) room)._room);
+			if (!room.ispartyInside())
+				list.add(room._room);
 		}
 		}
 		return list;
 		return list;
 	}
 	}