ソースを参照

BETA: Some misc changes:
* Added source archive for javolution.
* Added custom HashMap - L2HashMap:
* Added IL2EntryProcedure support (Designed for internal iteration key and value)
* Added IL2Procedure support (Designed for internal iteration key only or value only)
* Added custom ArrayList - L2ArrayList:
* Added IL2Procedure support (Designed for internal iteration for value only)
* Simplify logic in DoorTable.
* Removing ejectPlayer method and moving it's content in EjectProcedure.
* Adding registerQuestItems(int... items) method in Quest.

Rumen Nikiforov 12 年 前
コミット
52d2a89921

+ 2 - 2
L2J_Server_BETA/.classpath

@@ -3,7 +3,7 @@
 	<classpathentry kind="src" path="java" />
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" />
 	<classpathentry kind="lib" path="dist/libs/c3p0-0.9.2-pre4.jar" />
-	<classpathentry kind="lib" path="dist/libs/javolution-5.5.1.jar" />
+	<classpathentry kind="lib" path="dist/libs/javolution-5.5.1.jar" sourcepath="dist/libs/javolution-5.5.1-src.zip" />
 	<classpathentry kind="lib" path="dist/libs/jna.jar" />
 	<classpathentry kind="lib" path="dist/libs/jython.jar" />
 	<classpathentry kind="lib" path="dist/libs/jython-engine-2.2.1.jar" />
@@ -15,4 +15,4 @@
 	<classpathentry kind="lib" path="dist/libs/smtp.jar" />
 	<classpathentry kind="lib" path="dist/libs/trove-3.0.3.jar" />
 	<classpathentry kind="output" path="bin" />
-</classpath>
+</classpath>

BIN
L2J_Server_BETA/dist/libs/javolution-5.5.1-src.zip


+ 8 - 24
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/DoorTable.java

@@ -18,9 +18,9 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.logging.Logger;
 
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
@@ -36,11 +36,9 @@ import com.l2jserver.gameserver.pathfinding.AbstractNodeLoc;
 
 public class DoorTable extends DocumentParser
 {
-	private static final Logger _log = Logger.getLogger(DoorTable.class.getName());
-	
 	private final Map<Integer, L2DoorInstance> _doors = new HashMap<>();
 	private static final Map<String, Set<Integer>> _groups = new HashMap<>();
-	private final Map<Integer, Collection<L2DoorInstance>> _regions = new HashMap<>();
+	private final Map<Integer, List<L2DoorInstance>> _regions = new HashMap<>();
 	
 	protected DoorTable()
 	{
@@ -49,16 +47,11 @@ public class DoorTable extends DocumentParser
 	
 	@Override
 	public void load()
-	{
-		parseDatapackFile("data/doorData.xml");
-	}
-	
-	public void reloadAll()
 	{
 		_doors.clear();
 		_groups.clear();
 		_regions.clear();
-		load();
+		parseDatapackFile("data/doors.xml");
 	}
 	
 	@Override
@@ -123,7 +116,7 @@ public class DoorTable extends DocumentParser
 		L2DoorInstance door = new L2DoorInstance(IdFactory.getInstance().getNextId(), template, set);
 		door.setCurrentHp(door.getMaxHp());
 		door.spawnMe(template.posX, template.posY, template.posZ);
-		putDoor(door, MapRegionManager.getInstance().getMapRegionLocId(door.getX(), door.getY()));
+		putDoor(door, MapRegionManager.getInstance().getMapRegionLocId(door));
 	}
 	
 	public L2DoorTemplate getDoorTemplate(int doorId)
@@ -140,16 +133,11 @@ public class DoorTable extends DocumentParser
 	{
 		_doors.put(door.getDoorId(), door);
 		
-		if (_regions.containsKey(region))
+		if (!_regions.containsKey(region))
 		{
-			_regions.get(region).add(door);
-		}
-		else
-		{
-			final ArrayList<L2DoorInstance> list = new ArrayList<>();
-			list.add(door);
-			_regions.put(region, list);
+			_regions.put(region, new ArrayList<L2DoorInstance>());
 		}
+		_regions.get(region).add(door);
 	}
 	
 	public static void addDoorGroup(String groupName, int doorId)
@@ -158,13 +146,9 @@ public class DoorTable extends DocumentParser
 		if (set == null)
 		{
 			set = new HashSet<>();
-			set.add(doorId);
 			_groups.put(groupName, set);
 		}
-		else
-		{
-			set.add(doorId);
-		}
+		set.add(doorId);
 	}
 	
 	public static Set<Integer> getDoorsByGroup(String groupName)

+ 31 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/model/IL2EntryProcedure.java

@@ -0,0 +1,31 @@
+/*
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.l2jserver.gameserver.model;
+
+/**
+ * @author UnAfraid
+ * @param <K>
+ * @param <V>
+ */
+public interface IL2EntryProcedure<K, V>
+{
+	/**
+	 * Executes this procedure. A false return value indicates that the application executing this procedure should not invoke this procedure again.
+	 * @param key
+	 * @param value
+	 * @return {@code true} if additional invocations of the procedure are allowed.
+	 */
+	public boolean execute(K key, V value);
+}

+ 19 - 28
L2J_Server_BETA/java/com/l2jserver/gameserver/model/entity/Instance.java

@@ -189,28 +189,6 @@ public class Instance
 		}
 	}
 	
-	/**
-	 * Removes the player from the instance by setting InstanceId to 0 and teleporting to nearest town.
-	 * @param objectId
-	 */
-	public void ejectPlayer(int objectId)
-	{
-		L2PcInstance player = L2World.getInstance().getPlayer(objectId);
-		if ((player != null) && (player.getInstanceId() == getId()))
-		{
-			player.setInstanceId(0);
-			player.sendMessage("You were removed from the instance");
-			if (getSpawnLoc() != null)
-			{
-				player.teleToLocation(getSpawnLoc(), true);
-			}
-			else
-			{
-				player.teleToLocation(MapRegionManager.TeleportWhereType.Town);
-			}
-		}
-	}
-	
 	public void addNpc(L2Npc npc)
 	{
 		_npcs.add(npc);
@@ -228,7 +206,7 @@ public class Instance
 	/**
 	 * Adds a door into the instance
 	 * @param doorId - from doorData.xml
-	 * @param set - statset for initializing door
+	 * @param set - StatsSet for initializing door
 	 */
 	private void addDoor(int doorId, StatsSet set)
 	{
@@ -310,7 +288,7 @@ public class Instance
 	
 	public void removePlayers()
 	{
-		_players.forEach(new EjectProcedure());
+		_players.executeForEach(new EjectProcedure());
 		_players.clear();
 	}
 	
@@ -626,7 +604,7 @@ public class Instance
 		}
 		if (cs != null)
 		{
-			_players.forEach(new BroadcastPacket(cs));
+			_players.executeForEach(new BroadcastPacket(cs));
 		}
 		cancelTimer();
 		if (remaining >= 10000)
@@ -677,7 +655,20 @@ public class Instance
 		@Override
 		public boolean execute(Integer objectId)
 		{
-			ejectPlayer(objectId);
+			final L2PcInstance player = L2World.getInstance().getPlayer(objectId);
+			if ((player != null) && (player.getInstanceId() == getId()))
+			{
+				player.setInstanceId(0);
+				player.sendMessage("You were removed from the instance");
+				if (getSpawnLoc() != null)
+				{
+					player.teleToLocation(getSpawnLoc(), true);
+				}
+				else
+				{
+					player.teleToLocation(MapRegionManager.TeleportWhereType.Town);
+				}
+			}
 			return true;
 		}
 	}
@@ -694,8 +685,8 @@ public class Instance
 		@Override
 		public boolean execute(Integer objectId)
 		{
-			L2PcInstance player = L2World.getInstance().getPlayer(objectId);
-			if (player != null && player.getInstanceId() == getId())
+			final L2PcInstance player = L2World.getInstance().getPlayer(objectId);
+			if ((player != null) && (player.getInstanceId() == getId()))
 			{
 				player.sendPacket(_packet);
 			}

+ 9 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/model/quest/Quest.java

@@ -2598,6 +2598,15 @@ public class Quest extends ManagedScript
 		return questItemIds;
 	}
 	
+	/**
+	 * Registers all items that have to be destroyed in case player abort the quest or finish it.
+	 * @param items
+	 */
+	public void registerQuestItems(int...items)
+	{
+		questItemIds = items;
+	}
+	
 	@Override
 	public String getScriptName()
 	{

+ 66 - 0
L2J_Server_BETA/java/com/l2jserver/util/L2ArrayList.java

@@ -0,0 +1,66 @@
+/*
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.l2jserver.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import com.l2jserver.gameserver.model.IL2Procedure;
+
+/**
+ * A custom version of ArrayList: Extension for iterating without using temporary collection<br>
+ * Note that this implementation is not synchronized. If multiple threads access a array list concurrently, and at least one of the threads modifies the list structurally, it must be synchronized externally. This is typically accomplished by synchronizing on some object that naturally encapsulates
+ * the list. If no such object exists, the list should be "wrapped" using the {@link L2FastList}. This is best done at creation time, to prevent accidental unsynchronized access.
+ * @author UnAfraid
+ * @param <T>
+ */
+public class L2ArrayList<T> extends ArrayList<T>
+{
+	private static final long serialVersionUID = 8354641653178203420L;
+	
+	public L2ArrayList()
+	{
+		super();
+	}
+	
+	public L2ArrayList(Collection<? extends T> c)
+	{
+		super(c);
+	}
+	
+	public L2ArrayList(int initialCapacity)
+	{
+		super(initialCapacity);
+	}
+	
+	/**
+	 * Public method that iterate entire collection.<br>
+	 * <br>
+	 * @param proc - a class method that must be executed on every element of collection.<br>
+	 * @return - returns true if entire collection is iterated, false if it`s been interrupted by<br>
+	 *         check method (IL2Procedure.execute(T))<br>
+	 */
+	public boolean executeForEach(IL2Procedure<T> proc)
+	{
+		for (T e : this)
+		{
+			if (!proc.execute(e))
+			{
+				return false;
+			}
+		}
+		return true;
+	}
+}

+ 23 - 8
L2J_Server_BETA/java/com/l2jserver/util/L2FastList.java

@@ -14,7 +14,7 @@
  */
 package com.l2jserver.util;
 
-import java.util.List;
+import java.util.Collection;
 
 import javolution.util.FastList;
 
@@ -22,7 +22,7 @@ import com.l2jserver.gameserver.model.IL2Procedure;
 
 /**
  * A custom version of FastList with extension for iterating without using temporary collection<br>
- * It`s provide synchronization lock when iterating if needed<br>
+ * It's provide synchronization lock when iterating if needed<br>
  * <br>
  * @author Julian
  * @version 1.0.1 (2008-02-07)<br>
@@ -33,7 +33,7 @@ import com.l2jserver.gameserver.model.IL2Procedure;
  *          1.0.2 - Using IL2Procedure instead of IForEach.
  * @param <T>
  */
-public class L2FastList<T extends Object> extends FastList<T>
+public class L2FastList<T> extends FastList<T>
 {
 	private static final long serialVersionUID = 8354641653178203420L;
 	
@@ -42,22 +42,37 @@ public class L2FastList<T extends Object> extends FastList<T>
 		this(false);
 	}
 	
+	public L2FastList(int initialCapacity)
+	{
+		this(initialCapacity, false);
+	}
+	
+	public L2FastList(Collection<? extends T> c)
+	{
+		this(c, false);
+	}
+	
 	public L2FastList(boolean shared)
 	{
+		super();
 		if (shared)
 		{
 			shared();
 		}
 	}
 	
-	public L2FastList(List<? extends T> list)
+	public L2FastList(int initialCapacity, boolean shared)
 	{
-		this(list, false);
+		super(initialCapacity);
+		if (shared)
+		{
+			shared();
+		}
 	}
 	
-	public L2FastList(List<? extends T> list, boolean shared)
+	public L2FastList(Collection<? extends T> c, boolean shared)
 	{
-		super(list);
+		super(c);
 		if (shared)
 		{
 			shared();
@@ -71,7 +86,7 @@ public class L2FastList<T extends Object> extends FastList<T>
 	 * @return - returns true if entire collection is iterated, false if it`s been interrupted by<br>
 	 *         check method (IL2Procedure.execute(T))<br>
 	 */
-	public boolean forEach(IL2Procedure<T> proc)
+	public boolean executeForEach(IL2Procedure<T> proc)
 	{
 		for (T e : this)
 		{

+ 27 - 22
L2J_Server_BETA/java/com/l2jserver/util/L2FastMap.java

@@ -18,11 +18,12 @@ import java.util.Map;
 
 import javolution.util.FastMap;
 
+import com.l2jserver.gameserver.model.IL2EntryProcedure;
 import com.l2jserver.gameserver.model.IL2Procedure;
 
 /**
  * A custom version of FastMap with extension for iterating without using temporary collection<br>
- * <br>
+ * It's provide synchronization lock when iterating if needed<br>
  * @author Julian
  * @version 1.0.1 (2008-02-07)<br>
  *          Changes:<br>
@@ -34,7 +35,7 @@ import com.l2jserver.gameserver.model.IL2Procedure;
  * @param <K>
  * @param <V>
  */
-public class L2FastMap<K extends Object, V extends Object> extends FastMap<K, V>
+public class L2FastMap<K, V> extends FastMap<K, V>
 {
 	private static final long serialVersionUID = 8503855490858805336L;
 	
@@ -43,20 +44,26 @@ public class L2FastMap<K extends Object, V extends Object> extends FastMap<K, V>
 		this(false);
 	}
 	
+	public L2FastMap(Map<? extends K, ? extends V> map)
+	{
+		this(map, false);
+	}
+	
+	public L2FastMap(int initialCapacity)
+	{
+		this(initialCapacity, false);
+	}
+	
 	public L2FastMap(boolean shared)
 	{
+		super();
 		if (shared)
 		{
 			shared();
 		}
 	}
 	
-	public L2FastMap(Map<K, V> map)
-	{
-		this(map, false);
-	}
-	
-	public L2FastMap(Map<K, V> map, boolean shared)
+	public L2FastMap(Map<? extends K, ? extends V> map, boolean shared)
 	{
 		super(map);
 		if (shared)
@@ -65,29 +72,27 @@ public class L2FastMap<K extends Object, V extends Object> extends FastMap<K, V>
 		}
 	}
 	
-	/**
-	 * Public inner interface used by ForEach iterations<br>
-	 * @author Julian
-	 * @param <K>
-	 * @param <V>
-	 */
-	public interface I2ForEach<K, V>
+	public L2FastMap(int initialCapacity, boolean shared)
 	{
-		public boolean forEach(K key, V val);
+		super(initialCapacity);
+		if (shared)
+		{
+			shared();
+		}
 	}
 	
 	/**
 	 * Public method that iterate entire collection.<br>
 	 * <br>
-	 * @param func - a class method that must be executed on every element of collection.<br>
+	 * @param proc - a class method that must be executed on every element of collection.<br>
 	 * @return - returns true if entire collection is iterated, false if it`s been interrupted by<br>
-	 *         check method (I2ForEach.forEach())<br>
+	 *         check method (IL2EntryProcedure.execute())<br>
 	 */
-	public boolean ForEach(I2ForEach<K, V> func)
+	public boolean executeForEachEntry(IL2EntryProcedure<K, V> proc)
 	{
 		for (Map.Entry<K, V> e : entrySet())
 		{
-			if (!func.forEach(e.getKey(), e.getValue()))
+			if (!proc.execute(e.getKey(), e.getValue()))
 			{
 				return false;
 			}
@@ -95,7 +100,7 @@ public class L2FastMap<K extends Object, V extends Object> extends FastMap<K, V>
 		return true;
 	}
 	
-	public boolean ForEachKey(IL2Procedure<K> proc)
+	public boolean executeForEachKey(IL2Procedure<K> proc)
 	{
 		for (K k : keySet())
 		{
@@ -107,7 +112,7 @@ public class L2FastMap<K extends Object, V extends Object> extends FastMap<K, V>
 		return true;
 	}
 	
-	public boolean ForEachValue(IL2Procedure<V> proc)
+	public boolean executeForEachValue(IL2Procedure<V> proc)
 	{
 		for (V v : values())
 		{

+ 98 - 0
L2J_Server_BETA/java/com/l2jserver/util/L2HashMap.java

@@ -0,0 +1,98 @@
+/*
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.l2jserver.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.l2jserver.gameserver.model.IL2EntryProcedure;
+import com.l2jserver.gameserver.model.IL2Procedure;
+
+/**
+ * A custom version of HashMap: Extension for iterating without using temporary collection<br>
+ * Note that this implementation is not synchronized. If multiple threads access a hash map concurrently, and at least one of the threads modifies the map structurally, it must be synchronized externally. This is typically accomplished by synchronizing on some object that naturally encapsulates the
+ * map. If no such object exists, the map should be "wrapped" using the {@link L2FastMap}. This is best done at creation time, to prevent accidental unsynchronized access.
+ * @author UnAfraid
+ * @param <K>
+ * @param <V>
+ */
+public class L2HashMap<K, V> extends HashMap<K, V>
+{
+	private static final long serialVersionUID = 8503855490858805336L;
+	
+	private static final float DEFAULT_LOAD_FACTOR = 0.75f;
+	
+	public L2HashMap()
+	{
+		super();
+	}
+	
+	public L2HashMap(Map<? extends K, ? extends V> map)
+	{
+		super(map);
+	}
+	
+	public L2HashMap(int initialCapacity)
+	{
+		this(initialCapacity, DEFAULT_LOAD_FACTOR);
+	}
+	
+	public L2HashMap(int initialCapacity, float loadFactor)
+	{
+		super(initialCapacity, loadFactor);
+	}
+	
+	/**
+	 * Public method that iterate entire collection.<br>
+	 * @param proc - a class method that must be executed on every element of collection.<br>
+	 * @return - returns true if entire collection is iterated, false if it`s been interrupted by<br>
+	 *         check method (IL2EntryProcedure.execute())<br>
+	 */
+	public boolean executeForEachEntry(IL2EntryProcedure<K, V> proc)
+	{
+		for (Map.Entry<K, V> e : entrySet())
+		{
+			if (!proc.execute(e.getKey(), e.getValue()))
+			{
+				return false;
+			}
+		}
+		return true;
+	}
+	
+	public boolean executeForEachKey(IL2Procedure<K> proc)
+	{
+		for (K k : keySet())
+		{
+			if (!proc.execute(k))
+			{
+				return false;
+			}
+		}
+		return true;
+	}
+	
+	public boolean executeForEachValue(IL2Procedure<V> proc)
+	{
+		for (V v : values())
+		{
+			if (!proc.execute(v))
+			{
+				return false;
+			}
+		}
+		return true;
+	}
+}