Sfoglia il codice sorgente

BETA: Misc fixes:
* L2DatabaseFactory addressing the Double-Checked Locking problem.
* [http://en.wikipedia.org/wiki/Double-checked_locking#Usage_in_Java Double-checked locking: Usage in Java]
* [http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html Double-Checked Locking]
* SevenSigns writing to static field from instanced method.
* SevenSignsFestival unnecessary Math operation, NPE vulnerability.
* Territory writing to static field from instanced method.
* GeoEditorListener writing to static field from instanced method.
* HandysBlockCheckerManager incorrect lazy initialization.
* MercTicketManager incorrect lazy initialization (double check and lock).
* RaidBossSpawnManager NPE vulnerability.
* TerritoryWarManager unnecessary Math operations.
* WalkingManager NPE vulnerability, shouldn't continue if document couldn't be parsed.
* L2Character:
* Addressing the Double-Checked Locking problem.
* _attackByList
* _chanceSkills
* NPE vulnerability.
* L2ClanHallDoormenInstance addressing the Double-Checked Locking problem.
* L2PcInstance:
* Addressing the Double-Checked Locking problem.
* _teleportWatchdog
* _notifyQuestOfDeathList
* NPE vulnerability.
* Unnecessary Math (should have been removed in [5268]).
* L2TamedBeastInstance writing to static field from instanced method.
* Castle NPE vulnerability.
* L2SkillSummon unnecessary Math.
* L2EffectZone addressing the Double-Checked Locking problem.
* _task
* _skills
* CharacterRestore exception not thrown.
* RequestReplySurrenderPledgeWar NPE vulnerability.
* RequestRestartPoint NPE vulnerability.
* TaskManager implements equals(Object) but not hashCode().
* Point3D if set method is synchronized then get method should be synchronized.
* GameServerRegister NPE vulnerability.
* LanguageControl NPE vulnerability, now using ARM.
* LocalizationParser NPE vulnerability.
* Base64 NPE vulnerability.
* BaseRecievePacket NPE vulnerability.
* [http://blogs.atlassian.com/2007/07/dateformat_objects_and_threads/ DateFormat is not thread-safe]
* ItemAuctionInstance DateFormat shouldn't be static, it's not thread safe.
* FaenorParser DateFormat shouldn't be static, it's not thread safe.
* GMAudit DateFormat shouldn't be static, it's not thread safe.
* '''Note:''' If the performance drops (memory leaks), FastDateFormat from Apache Commons Lang could be used which is thread-safe.

Zoey76 13 anni fa
parent
commit
7acd84e7b8
31 ha cambiato i file con 202 aggiunte e 216 eliminazioni
  1. 1 1
      L2J_Server_BETA/java/com/l2jserver/L2DatabaseFactory.java
  2. 9 9
      L2J_Server_BETA/java/com/l2jserver/gameserver/SevenSigns.java
  3. 5 3
      L2J_Server_BETA/java/com/l2jserver/gameserver/SevenSignsFestival.java
  4. 2 3
      L2J_Server_BETA/java/com/l2jserver/gameserver/Territory.java
  5. 1 1
      L2J_Server_BETA/java/com/l2jserver/gameserver/geoeditorcon/GeoEditorListener.java
  6. 14 33
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/HandysBlockCheckerManager.java
  7. 26 37
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/MercTicketManager.java
  8. 1 1
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/RaidBossSpawnManager.java
  9. 4 4
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/TerritoryWarManager.java
  10. 1 0
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/WalkingManager.java
  11. 37 37
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/L2Character.java
  12. 1 1
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/instance/L2ClanHallDoormenInstance.java
  13. 16 8
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java
  14. 2 2
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/instance/L2TamedBeastInstance.java
  15. 7 4
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/entity/Castle.java
  16. 1 1
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/itemauction/ItemAuctionInstance.java
  17. 1 1
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/skills/l2skills/L2SkillSummon.java
  18. 2 2
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/zone/type/L2EffectZone.java
  19. 1 4
      L2J_Server_BETA/java/com/l2jserver/gameserver/network/clientpackets/CharacterRestore.java
  20. 11 7
      L2J_Server_BETA/java/com/l2jserver/gameserver/network/clientpackets/RequestReplySurrenderPledgeWar.java
  21. 7 5
      L2J_Server_BETA/java/com/l2jserver/gameserver/network/clientpackets/RequestRestartPoint.java
  22. 2 2
      L2J_Server_BETA/java/com/l2jserver/gameserver/script/faenor/FaenorParser.java
  23. 6 0
      L2J_Server_BETA/java/com/l2jserver/gameserver/taskmanager/TaskManager.java
  24. 17 22
      L2J_Server_BETA/java/com/l2jserver/gameserver/util/GMAudit.java
  25. 3 8
      L2J_Server_BETA/java/com/l2jserver/gameserver/util/Point3D.java
  26. 0 1
      L2J_Server_BETA/java/com/l2jserver/tools/gsregistering/GUserInterface.java
  27. 13 10
      L2J_Server_BETA/java/com/l2jserver/tools/gsregistering/GameServerRegister.java
  28. 3 7
      L2J_Server_BETA/java/com/l2jserver/tools/i18n/LanguageControl.java
  29. 1 0
      L2J_Server_BETA/java/com/l2jserver/tools/ngl/LocalizationParser.java
  30. 5 1
      L2J_Server_BETA/java/com/l2jserver/util/Base64.java
  31. 2 1
      L2J_Server_BETA/java/com/l2jserver/util/network/BaseRecievePacket.java

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/L2DatabaseFactory.java

@@ -38,7 +38,7 @@ public class L2DatabaseFactory
 	}
 	
 	private static L2DatabaseFactory _instance;
-	private static ScheduledExecutorService _executor;
+	private static volatile ScheduledExecutorService _executor;
 	private ProviderType _providerType;
 	private ComboPooledDataSource _source;
 	

+ 9 - 9
L2J_Server_BETA/java/com/l2jserver/gameserver/SevenSigns.java

@@ -131,15 +131,15 @@ public class SevenSigns
 	private Map<Integer, Integer> _signsDuskSealTotals;
 	private Map<Integer, Integer> _signsDawnSealTotals;
 	
-	private static AutoSpawnInstance _merchantSpawn;
-	private static AutoSpawnInstance _blacksmithSpawn;
-	private static AutoSpawnInstance _lilithSpawn;
-	private static AutoSpawnInstance _anakimSpawn;
-	private static Map<Integer, AutoSpawnInstance> _crestofdawnspawns;
-	private static Map<Integer, AutoSpawnInstance> _crestofduskspawns;
-	private static Map<Integer, AutoSpawnInstance> _oratorSpawns;
-	private static Map<Integer, AutoSpawnInstance> _preacherSpawns;
-	private static Map<Integer, AutoSpawnInstance> _marketeerSpawns;
+	private AutoSpawnInstance _merchantSpawn;
+	private AutoSpawnInstance _blacksmithSpawn;
+	private AutoSpawnInstance _lilithSpawn;
+	private AutoSpawnInstance _anakimSpawn;
+	private Map<Integer, AutoSpawnInstance> _crestofdawnspawns;
+	private Map<Integer, AutoSpawnInstance> _crestofduskspawns;
+	private Map<Integer, AutoSpawnInstance> _oratorSpawns;
+	private Map<Integer, AutoSpawnInstance> _preacherSpawns;
+	private Map<Integer, AutoSpawnInstance> _marketeerSpawns;
 	
 	private static final String LOAD_DATA =
 		"SELECT charId, cabal, seal, red_stones, green_stones, blue_stones, " +

+ 5 - 3
L2J_Server_BETA/java/com/l2jserver/gameserver/SevenSignsFestival.java

@@ -1281,12 +1281,12 @@ public class SevenSignsFestival implements SpawnListener
 		_nextFestivalStart = System.currentTimeMillis() + milliFromNow;
 	}
 	
-	public final int getMinsToNextCycle()
+	public final long getMinsToNextCycle()
 	{
 		if (SevenSigns.getInstance().isSealValidationPeriod())
 			return -1;
 		
-		return Math.round((_nextFestivalCycleStart - System.currentTimeMillis()) / 60000);
+		return (_nextFestivalCycleStart - System.currentTimeMillis()) / 60000;
 	}
 	
 	public final int getMinsToNextFestival()
@@ -1294,7 +1294,7 @@ public class SevenSignsFestival implements SpawnListener
 		if (SevenSigns.getInstance().isSealValidationPeriod())
 			return -1;
 		
-		return Math.round((_nextFestivalStart - System.currentTimeMillis()) / 60000) + 1;
+		return (int) (((_nextFestivalStart - System.currentTimeMillis()) / 60000) + 1);
 	}
 	
 	public final String getTimeToNextFestivalStr()
@@ -2266,6 +2266,8 @@ public class SevenSignsFestival implements SpawnListener
 				case 3:
 					_npcSpawns = (_cabal == SevenSigns.CABAL_DAWN) ? FESTIVAL_DAWN_CHEST_SPAWNS[_levelRange] : FESTIVAL_DUSK_CHEST_SPAWNS[_levelRange];
 					break;
+				default:
+					return;
 			}
 			
 			for (int i = 0; i < _npcSpawns.length; i++)

+ 2 - 3
L2J_Server_BETA/java/com/l2jserver/gameserver/Territory.java

@@ -29,7 +29,7 @@ public class Territory
 {
 	private static Logger _log = Logger.getLogger(Territory.class.getName());
 	
-	private static Map<Integer, L2Territory> _territory;
+	private static final Map<Integer, L2Territory> _territory = new FastMap<>();
 	
 	public static Territory getInstance()
 	{
@@ -54,8 +54,7 @@ public class Territory
 	
 	public void reload_data()
 	{
-		_territory = new FastMap<Integer, L2Territory>();
-		
+		_territory.clear();
 		Integer[][] point = SqlUtils.get2DIntArray(new String[] { "loc_id", "loc_x", "loc_y", "loc_zmin", "loc_zmax", "proc" }, "locations", "loc_id > 0");
 		for (Integer[] row : point)
 		{

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/geoeditorcon/GeoEditorListener.java

@@ -29,7 +29,7 @@ public class GeoEditorListener extends Thread
 	private static final int PORT = 9011;
 	private static Logger _log = Logger.getLogger(GeoEditorListener.class.getName());
 	private ServerSocket _serverSocket;
-	private static GeoEditorThread _geoEditor;
+	private GeoEditorThread _geoEditor;
 	
 	public static GeoEditorListener getInstance()
 	{

+ 14 - 33
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/HandysBlockCheckerManager.java

@@ -14,14 +14,10 @@
  */
 package com.l2jserver.gameserver.instancemanager;
 
-import gnu.trove.map.hash.TIntIntHashMap;
-
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
-import java.util.logging.Logger;
-
-import javolution.util.FastList;
-import javolution.util.FastMap;
+import java.util.Map;
 
 import com.l2jserver.Config;
 import com.l2jserver.gameserver.ThreadPoolManager;
@@ -39,26 +35,23 @@ import com.l2jserver.gameserver.network.serverpackets.L2GameServerPacket;
 import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
 
 /**
- * This class manage the player add/remove, team change and<br>
- * event arena status, as the clearance of the participants<br>
- * list or liberate the arena.
+ * This class manage the player add/remove, team change and event arena status,<br>
+ * as the clearance of the participants list or liberate the arena.
  * @author BiggBoss
  */
 public final class HandysBlockCheckerManager 
 {
-	private static final Logger _log = Logger.getLogger(HandysBlockCheckerManager.class.getName());
-	
 	// All the participants and their team classified by arena
-	private static ArenaParticipantsHolder[] _arenaPlayers = new ArenaParticipantsHolder[4];
+	private static final ArenaParticipantsHolder[] _arenaPlayers = new ArenaParticipantsHolder[4];
 	
 	// Arena votes to start the game
-	private static TIntIntHashMap _arenaVotes = new TIntIntHashMap();
+	private static final Map<Integer, Integer> _arenaVotes = new HashMap<>();
 	
 	// Arena Status, True = is being used, otherwise, False
-	private static FastMap<Integer, Boolean> _arenaStatus;
+	private static final Map<Integer, Boolean> _arenaStatus = new HashMap<>();
 	
 	// Registration request penalty (10 seconds)
-	private static FastList<Integer> _registrationPenalty = new FastList<Integer>();
+	private static List<Integer> _registrationPenalty = new ArrayList<>();
 	
 	/**
 	 * Return the number of event-start votes for the specified
@@ -109,14 +102,10 @@ public final class HandysBlockCheckerManager
 	private HandysBlockCheckerManager()
 	{
 		// Initialize arena status
-		if(_arenaStatus == null)
-		{
-			_arenaStatus = new FastMap<Integer, Boolean>();
-			_arenaStatus.put(0, false);
-			_arenaStatus.put(1, false);
-			_arenaStatus.put(2, false);
-			_arenaStatus.put(3, false);			
-		}
+		_arenaStatus.put(0, false);
+		_arenaStatus.put(1, false);
+		_arenaStatus.put(2, false);
+		_arenaStatus.put(3, false);
 	}
 	
 	/**
@@ -498,8 +487,7 @@ public final class HandysBlockCheckerManager
 	
 	private class PenaltyRemove implements Runnable
 	{
-		Integer objectId;
-		
+		private final Integer objectId;
 		public PenaltyRemove(Integer id)
 		{
 			objectId = id;
@@ -508,14 +496,7 @@ public final class HandysBlockCheckerManager
 		@Override
 		public void run()
 		{
-			try
-			{
-				_registrationPenalty.remove(objectId);
-			}
-			catch(Exception e)
-			{
-				_log.warning(getClass().getSimpleName() + ": " + e.getMessage());
-			}
+			_registrationPenalty.remove(objectId);
 		}
 	}
 }

+ 26 - 37
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/MercTicketManager.java

@@ -36,30 +36,17 @@ import com.l2jserver.gameserver.model.entity.Castle;
 import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
 
 /**
- * @author yellowperil & Fulminus
- * This class is similar to the SiegeGuardManager, except it handles
- * the loading of the mercenary tickets that are dropped on castle floors
- * by the castle lords.
- * These tickets (aka badges) need to be readded after each server reboot
- * except when the server crashed in the middle of an ongoig siege.
- * In addition, this class keeps track of the added tickets, in order to
- * properly limit the number of mercenaries in each castle and the
- * number of mercenaries from each mercenary type.
- * Finally, we provide auxilary functions to identify the castle in
- * which each item (and its corresponding NPC) belong to, in order to
- * help avoid mixing them up.
- *
+ * This class is similar to the SiegeGuardManager, except it handles the loading of the mercenary tickets that are dropped on castle floors by the castle lords.<br>
+ * These tickets (a.k.a. badges) need to be read after each server reboot except when the server crashed in the middle of an ongoing siege.<br>
+ * In addition, this class keeps track of the added tickets, in order to properly limit the number of mercenaries in each castle and the number of mercenaries from each mercenary type.<br>
+ * Finally, we provide auxiliary functions to identify the castle in which each item (and its corresponding NPC) belong to, in order to help avoid mixing them up.
+ * @author yellowperil, Fulminus
  */
 public class MercTicketManager
 {
-	protected static final Logger _log = Logger.getLogger(MercTicketManager.class.getName());
+	private static final Logger _log = Logger.getLogger(MercTicketManager.class.getName());
 	
-	public static final MercTicketManager getInstance()
-	{
-		return SingletonHolder._instance;
-	}
-	
-	private List<L2ItemInstance> _droppedTickets; // to keep track of items on the ground
+	private static final FastList<L2ItemInstance> _droppedTickets = new FastList<>();
 	
 	//TODO move all these values into siege.properties
 	// max tickets per merc type = 10 + (castleid * 2)?
@@ -116,7 +103,8 @@ public class MercTicketManager
 	
 	private MercTicketManager()
 	{
-		_log.info("Initializing MercTicketManager");
+		_log.info("Initializing MercTicketManager.");
+		_droppedTickets.shared();
 		load();
 	}
 	
@@ -137,14 +125,16 @@ public class MercTicketManager
 	
 	public void reload()
 	{
-		getDroppedTickets().clear();
+		_droppedTickets.clear();
 		load();
 	}
 	
+	/**
+	 * Load merc tickets into the world.
+	 */
 	private final void load()
 	{
 		Connection con = null;
-		// load merc tickets into the world
 		try
 		{
 			con = L2DatabaseFactory.getInstance().getConnection();
@@ -188,9 +178,9 @@ public class MercTicketManager
 							L2ItemInstance dropticket = new L2ItemInstance(IdFactory.getInstance().getNextId(), itemId);
 							dropticket.setLocation(L2ItemInstance.ItemLocation.VOID);
 							dropticket.dropMe(null, x, y, z);
-							dropticket.setDropTime(0); //avoids it from beeing removed by the auto item destroyer
+							dropticket.setDropTime(0); //avoids it from being removed by the auto item destroyer
 							L2World.getInstance().storeObject(dropticket);
-							getDroppedTickets().add(dropticket);
+							_droppedTickets.add(dropticket);
 						}
 						break;
 					}
@@ -198,7 +188,7 @@ public class MercTicketManager
 			rs.close();
 			statement.close();
 			
-			_log.info("Loaded: " + getDroppedTickets().size() + " Mercenary Tickets");
+			_log.info("Loaded: " + _droppedTickets.size() + " Mercenary Tickets");
 		}
 		catch (Exception e)
 		{
@@ -231,7 +221,7 @@ public class MercTicketManager
 			return true;
 		
 		int count = 0;
-		for (L2ItemInstance ticket : getDroppedTickets())
+		for (L2ItemInstance ticket : _droppedTickets)
 		{
 			if (ticket != null && ticket.getItemId() == itemId)
 				count++;
@@ -257,7 +247,7 @@ public class MercTicketManager
 			return true;
 		
 		int count = 0;
-		for (L2ItemInstance ticket : getDroppedTickets())
+		for (L2ItemInstance ticket : _droppedTickets)
 		{
 			if ((ticket != null) && (getTicketCastleId(ticket.getItemId()) == castleId))
 				count++;
@@ -274,7 +264,7 @@ public class MercTicketManager
 	
 	public boolean isTooCloseToAnotherTicket(int x, int y, int z)
 	{
-		for (L2ItemInstance item : getDroppedTickets())
+		for (L2ItemInstance item : _droppedTickets)
 		{
 			double dx = x - item.getX();
 			double dy = y - item.getY();
@@ -358,7 +348,7 @@ public class MercTicketManager
 	 */
 	public void deleteTickets(int castleId)
 	{
-		Iterator<L2ItemInstance> it = getDroppedTickets().iterator();
+		Iterator<L2ItemInstance> it = _droppedTickets.iterator();
 		while (it.hasNext())
 		{
 			L2ItemInstance item = it.next();
@@ -396,7 +386,7 @@ public class MercTicketManager
 			(new SiegeGuardManager(castle)).removeMerc(npcId, item.getX(), item.getY(), item.getZ());
 		}
 		
-		getDroppedTickets().remove(item);
+		_droppedTickets.remove(item);
 	}
 	
 	public int[] getItemIds()
@@ -406,15 +396,14 @@ public class MercTicketManager
 	
 	public final List<L2ItemInstance> getDroppedTickets()
 	{
-		if (_droppedTickets == null)
-			synchronized (this)
-			{
-				if (_droppedTickets == null)
-					_droppedTickets = new FastList<L2ItemInstance>();
-			}
 		return _droppedTickets;
 	}
 	
+	public static final MercTicketManager getInstance()
+	{
+		return SingletonHolder._instance;
+	}
+	
 	@SuppressWarnings("synthetic-access")
 	private static class SingletonHolder
 	{

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/RaidBossSpawnManager.java

@@ -508,9 +508,9 @@ public class RaidBossSpawnManager
 				ScheduledFuture<?> f = _schedules.get(bossId);
 				f.cancel(true);
 			}
+			_schedules.clear();
 		}
 		
-		_schedules.clear();
 		_storedInfo.clear();
 		_spawns.clear();
 	}

+ 4 - 4
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/TerritoryWarManager.java

@@ -1210,28 +1210,28 @@ public class TerritoryWarManager implements Siegable
 				else if ((timeRemaining <= 3600000) && (timeRemaining > 600000))
 				{
 					SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.THE_TERRITORY_WAR_WILL_END_IN_S1_MINUTES);
-					sm.addNumber(Math.round(timeRemaining / 60000));
+					sm.addNumber((int) (timeRemaining / 60000));
 					announceToParticipants(sm, 0, 0);
 					_scheduledEndTWTask = ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleEndTWTask(), timeRemaining - 600000); // Prepare task for 10 minute left.
 				}
 				else if ((timeRemaining <= 600000) && (timeRemaining > 300000))
 				{
 					SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.THE_TERRITORY_WAR_WILL_END_IN_S1_MINUTES);
-					sm.addNumber(Math.round(timeRemaining / 60000));
+					sm.addNumber((int) (timeRemaining / 60000));
 					announceToParticipants(sm, 0, 0);
 					_scheduledEndTWTask = ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleEndTWTask(), timeRemaining - 300000); // Prepare task for 5 minute left.
 				}
 				else if ((timeRemaining <= 300000) && (timeRemaining > 10000))
 				{
 					SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.THE_TERRITORY_WAR_WILL_END_IN_S1_MINUTES);
-					sm.addNumber(Math.round(timeRemaining / 60000));
+					sm.addNumber((int) (timeRemaining / 60000));
 					announceToParticipants(sm, 0, 0);
 					_scheduledEndTWTask = ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleEndTWTask(), timeRemaining - 10000); // Prepare task for 10 seconds count down
 				}
 				else if ((timeRemaining <= 10000) && (timeRemaining > 0))
 				{
 					SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_SECONDS_TO_THE_END_OF_TERRITORY_WAR);
-					sm.addNumber(Math.round(timeRemaining / 1000));
+					sm.addNumber((int) (timeRemaining / 1000));
 					announceToParticipants(sm, 0, 0);
 					_scheduledEndTWTask = ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleEndTWTask(), timeRemaining); // Prepare task for second count down
 				}

+ 1 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/WalkingManager.java

@@ -113,6 +113,7 @@ public class WalkingManager
 			catch (Exception e)
 			{
 				_log.log(Level.WARNING, "Could not parse Routes.xml file: " + e.getMessage(), e);
+				return;
 			}
 			
 			Node n = doc.getFirstChild();

+ 37 - 37
L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/L2Character.java

@@ -159,7 +159,7 @@ public abstract class L2Character extends L2Object
 	private static FastList<SkillUseListener> globalSkillUseListeners = new FastList<SkillUseListener>().shared();
 	private FastList<SkillUseListener> skillUseListeners = new FastList<SkillUseListener>().shared();
 	
-	private Set<L2Character> _attackByList;
+	private volatile Set<L2Character> _attackByList;
 	private volatile boolean _isCastingNow = false;
 	private volatile boolean _isCastingSimultaneouslyNow = false;
 	private L2Skill _lastSkillCast;
@@ -200,7 +200,7 @@ public abstract class L2Character extends L2Object
 	private FastMap<Integer, SkillHolder> _customSkills;
 	
 	/** FastMap containing the active chance skills on this character */
-	private ChanceSkillList _chanceSkills;
+	private volatile ChanceSkillList _chanceSkills;
 	
 	/** Current force buff this caster is casting to a target */
 	protected FusionSkill _fusionSkill;
@@ -2528,13 +2528,15 @@ public abstract class L2Character extends L2Object
 	 */
 	public final Set<L2Character> getAttackByList()
 	{
-		if (_attackByList != null)
-			return _attackByList;
-		
-		synchronized (this)
+		if (_attackByList == null)
 		{
-			if (_attackByList == null)
-				_attackByList = new WeakFastSet<L2Character>(true);
+			synchronized (this)
+			{
+				if (_attackByList == null)
+				{
+					_attackByList = new WeakFastSet<L2Character>(true);
+				}
+			}
 		}
 		return _attackByList;
 	}
@@ -3933,13 +3935,10 @@ public abstract class L2Character extends L2Object
 	
 	private int _castInterruptTime;
 	
-	/** Table of calculators containing all standard NPC calculator (ex : ACCURACY_COMBAT, EVASION_RATE */
-	private static final Calculator[] NPC_STD_CALCULATOR;
-	
-	static
-	{
-		NPC_STD_CALCULATOR = Formulas.getStdNPCCalculators();
-	}
+	/**
+	 * Table of calculators containing all standard NPC calculator (ex : ACCURACY_COMBAT, EVASION_RATE)
+	 */
+	private static final Calculator[] NPC_STD_CALCULATOR = Formulas.getStdNPCCalculators();
 	
 	protected L2CharacterAI _ai;
 	
@@ -7704,35 +7703,36 @@ public abstract class L2Character extends L2Object
 				{
 					t[f + i] = targets[f];
 				}
-			}
-			if (targets.length > 0)
-			{
-				SkillUseEvent event = new SkillUseEvent();
-				event.setCaster(this);
-				event.setSkill(skill);
-				event.setTargets(t);
-				for (SkillUseListener listener : skillUseListeners)
+				
+				if (targets.length > 0)
 				{
-					int skillId = skill.getId();
-					if (listener.getSkillId() == -1 || skillId == listener.getSkillId())
+					SkillUseEvent event = new SkillUseEvent();
+					event.setCaster(this);
+					event.setSkill(skill);
+					event.setTargets(t);
+					for (SkillUseListener listener : skillUseListeners)
 					{
-						if (!listener.onSkillUse(event))
+						int skillId = skill.getId();
+						if (listener.getSkillId() == -1 || skillId == listener.getSkillId())
 						{
-							return false;
+							if (!listener.onSkillUse(event))
+							{
+								return false;
+							}
 						}
 					}
-				}
-				for (SkillUseListener listener : globalSkillUseListeners)
-				{
-					int npcId = listener.getNpcId();
-					int skillId = listener.getSkillId();
-					boolean skillOk = skillId == -1 || skillId == skill.getId();
-					boolean charOk = (npcId == -1 && this instanceof L2NpcInstance) || (npcId == -2 && this instanceof L2PcInstance) || npcId == -3 || (this instanceof L2NpcInstance && ((L2NpcInstance) this).getNpcId() == npcId);
-					if (skillOk && charOk)
+					for (SkillUseListener listener : globalSkillUseListeners)
 					{
-						if (!listener.onSkillUse(event))
+						int npcId = listener.getNpcId();
+						int skillId = listener.getSkillId();
+						boolean skillOk = skillId == -1 || skillId == skill.getId();
+						boolean charOk = (npcId == -1 && this instanceof L2NpcInstance) || (npcId == -2 && this instanceof L2PcInstance) || npcId == -3 || (this instanceof L2NpcInstance && ((L2NpcInstance) this).getNpcId() == npcId);
+						if (skillOk && charOk)
 						{
-							return false;
+							if (!listener.onSkillUse(event))
+							{
+								return false;
+							}
 						}
 					}
 				}

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/instance/L2ClanHallDoormenInstance.java

@@ -28,7 +28,7 @@ import com.l2jserver.gameserver.util.Evolve;
 
 public class L2ClanHallDoormenInstance extends L2DoormenInstance
 {
-	private boolean _init = false;
+	private volatile boolean _init = false;
 	private ClanHall _clanHall = null;
 	private boolean _hasEvolve = false;
 	

+ 16 - 8
L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java

@@ -97,12 +97,12 @@ import com.l2jserver.gameserver.instancemanager.TerritoryWarManager;
 import com.l2jserver.gameserver.instancemanager.ZoneManager;
 import com.l2jserver.gameserver.model.BlockList;
 import com.l2jserver.gameserver.model.CharEffectList;
-import com.l2jserver.gameserver.model.L2Fish;
 import com.l2jserver.gameserver.model.L2AccessLevel;
 import com.l2jserver.gameserver.model.L2Clan;
 import com.l2jserver.gameserver.model.L2ClanMember;
 import com.l2jserver.gameserver.model.L2ContactList;
 import com.l2jserver.gameserver.model.L2EnchantSkillLearn;
+import com.l2jserver.gameserver.model.L2Fish;
 import com.l2jserver.gameserver.model.L2Fishing;
 import com.l2jserver.gameserver.model.L2Macro;
 import com.l2jserver.gameserver.model.L2ManufactureItem;
@@ -465,7 +465,7 @@ public final class L2PcInstance extends L2Playable
 	/** Vitality recovery task */
 	private ScheduledFuture<?> _vitalityTask;
 	
-	private ScheduledFuture<?> _teleportWatchdog;
+	private volatile ScheduledFuture<?> _teleportWatchdog;
 	
 	/** The Siege state of the L2PcInstance */
 	private byte _siegeState = 0;
@@ -1389,11 +1389,14 @@ public final class L2PcInstance extends L2Playable
 	public L2CharacterAI getAI()
 	{
 		L2CharacterAI ai = _ai; // copy handle
-		if (ai == null)
+		if (_ai == null)
 		{
 			synchronized(this)
 			{
-				if (_ai == null) _ai = new L2PlayerAI(new L2PcInstance.AIAccessor());
+				if (_ai == null)
+				{
+					_ai = new L2PlayerAI(new L2PcInstance.AIAccessor());
+				}
 				return _ai;
 			}
 		}
@@ -1843,7 +1846,7 @@ public final class L2PcInstance extends L2Playable
 	}
 	
 	/** List of all QuestState instance that needs to be notified of this L2PcInstance's or its pet's death */
-	private List<QuestState> _notifyQuestOfDeathList;
+	private volatile List<QuestState> _notifyQuestOfDeathList;
 	
 	/**
 	 * Add QuestState instance that is to be notified of L2PcInstance's death.<BR><BR>
@@ -7465,6 +7468,11 @@ public final class L2PcInstance extends L2Playable
 			rset.close();
 			statement.close();
 			
+			if (player == null)
+			{
+				return null;
+			}
+			
 			// Set Hero status if it applies
 			if (Hero.getInstance().isHero(objectId))
 			{
@@ -12374,11 +12382,11 @@ public final class L2PcInstance extends L2Playable
 				isNoob = _fish.getFishGrade() == 0;
 				isUpperGrade = _fish.getFishGrade() == 2;
 				if (lureid == 6519 || lureid == 6522 || lureid == 6525 || lureid == 8505 || lureid == 8508 || lureid == 8511) //low grade
-					checkDelay = Math.round(_fish.getGutsCheckTime() * (133));
+					checkDelay = _fish.getGutsCheckTime() * 133;
 				else if (lureid == 6520 || lureid == 6523 || lureid == 6526 || (lureid >= 8505 && lureid <= 8513) || (lureid >= 7610 && lureid <= 7613) || (lureid >= 7807 && lureid <= 7809) || (lureid >= 8484 && lureid <= 8486)) //medium grade, beginner, prize-winning & quest special bait
-					checkDelay = Math.round(_fish.getGutsCheckTime() * (100));
+					checkDelay = _fish.getGutsCheckTime() * 100;
 				else if (lureid == 6521 || lureid == 6524 || lureid == 6527 || lureid == 8507 || lureid == 8510 || lureid == 8513) //high grade
-					checkDelay = Math.round(_fish.getGutsCheckTime() * (66));
+					checkDelay = _fish.getGutsCheckTime() * 66;
 			}
 			_taskforfish = ThreadPoolManager.getInstance().scheduleEffectAtFixedRate(new LookingForFishTask(_fish.getStartCombatTime(), _fish.getFishGuts(), _fish.getFishGroup(), isNoob, isUpperGrade), 10000, checkDelay);
 		}

+ 2 - 2
L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/instance/L2TamedBeastInstance.java

@@ -59,7 +59,7 @@ public final class L2TamedBeastInstance extends L2FeedableBeastInstance
 	private L2PcInstance _owner;
 	private Future<?> _buffTask = null;
 	private Future<?> _durationCheckTask = null;
-	private static boolean _isFreyaBeast;
+	private boolean _isFreyaBeast;
 	private List<L2Skill> _beastSkills = null;
 	
 	public L2TamedBeastInstance(int objectId, L2NpcTemplate template)
@@ -404,7 +404,7 @@ public final class L2TamedBeastInstance extends L2FeedableBeastInstance
 			L2PcInstance owner = _tamedBeast.getOwner();
 			
 			L2ItemInstance item = null;
-			if (_isFreyaBeast)
+			if (_tamedBeast._isFreyaBeast)
 			{
 				item = owner.getInventory().getItemByItemId(foodTypeSkillId);
 				if (item != null && item.getCount() >= 1)

+ 7 - 4
L2J_Server_BETA/java/com/l2jserver/gameserver/model/entity/Castle.java

@@ -556,7 +556,7 @@ public class Castle
 		setShowNpcCrest(false);
 		
 		// if clan have fortress, remove it
-		if (clan.getFortId() > 0)
+		if ((clan != null) && clan.getFortId() > 0)
 			FortManager.getInstance().getFortByOwner(clan).removeOwner(true);
 		
 		if (getSiege().getIsInProgress()) // If siege in progress
@@ -564,10 +564,13 @@ public class Castle
 			
 		TerritoryWarManager.getInstance().getTerritory(_castleId).setOwnerClan(clan);
 		
-		for (L2PcInstance member : clan.getOnlineMembers(0))
+		if (clan != null)
 		{
-			giveResidentialSkills(member);
-			member.sendSkillList();
+			for (L2PcInstance member : clan.getOnlineMembers(0))
+			{
+				giveResidentialSkills(member);
+				member.sendSkillList();
+			}
 		}
 	}
 	

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/model/itemauction/ItemAuctionInstance.java

@@ -51,7 +51,7 @@ import com.l2jserver.util.Rnd;
 public final class ItemAuctionInstance
 {
 	static final Logger _log = Logger.getLogger(ItemAuctionInstance.class.getName());
-	private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("HH:mm:ss dd.MM.yy");
+	private final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("HH:mm:ss dd.MM.yy");
 	
 	private static final long START_TIME_SPACE = TimeUnit.MILLISECONDS.convert(1, TimeUnit.MINUTES);
 	private static final long FINISH_TIME_SPACE = TimeUnit.MILLISECONDS.convert(10, TimeUnit.MINUTES);

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/model/skills/l2skills/L2SkillSummon.java

@@ -152,7 +152,7 @@ public class L2SkillSummon extends L2Skill
 			int _cubicSkillLevel = getLevel();
 			if (_cubicSkillLevel > 100)
 			{
-				_cubicSkillLevel = Math.round(((getLevel()-100)/7)+8);
+				_cubicSkillLevel = ((getLevel()-100) / 7) + 8;
 			}
 			
 			if (targets.length > 1) // Mass cubic skill

+ 2 - 2
L2J_Server_BETA/java/com/l2jserver/gameserver/model/zone/type/L2EffectZone.java

@@ -41,8 +41,8 @@ public class L2EffectZone extends L2ZoneType
 	private boolean _enabled;
 	private boolean _bypassConditions;
 	private boolean _isShowDangerIcon;
-	private Future<?> _task;
-	private FastMap<Integer, Integer> _skills;
+	private volatile Future<?> _task;
+	private volatile FastMap<Integer, Integer> _skills;
 	
 	public L2EffectZone(int id)
 	{

+ 1 - 4
L2J_Server_BETA/java/com/l2jserver/gameserver/network/clientpackets/CharacterRestore.java

@@ -40,10 +40,7 @@ public final class CharacterRestore extends L2GameClientPacket
 		if (!getClient().getFloodProtectors().getCharacterSelect().tryPerformAction("CharacterRestore"))
 			return;
 		
-		try
-		{
-			getClient().markRestoredChar(_charSlot);
-		} catch (Exception e){}
+		getClient().markRestoredChar(_charSlot);
 		CharSelectionInfo cl = new CharSelectionInfo(getClient().getAccountName(), getClient().getSessionId().playOkID1, 0);
 		sendPacket(cl);
 		getClient().setCharSelection(cl.getCharInfo());

+ 11 - 7
L2J_Server_BETA/java/com/l2jserver/gameserver/network/clientpackets/RequestReplySurrenderPledgeWar.java

@@ -21,24 +21,29 @@ public final class RequestReplySurrenderPledgeWar extends L2GameClientPacket
 {
 	private static final String _C__08_REQUESTREPLYSURRENDERPLEDGEWAR = "[C] 08 RequestReplySurrenderPledgeWar";
 	
+	private String _reqName;
 	private int _answer;
 	
 	@Override
 	protected void readImpl()
 	{
-		@SuppressWarnings("unused") String _reqName = readS();
-		_answer  = readD();
+		_reqName = readS();
+		_answer = readD();
 	}
 	
 	@Override
 	protected void runImpl()
 	{
-		L2PcInstance activeChar = getClient().getActiveChar();
+		final L2PcInstance activeChar = getActiveChar();
 		if (activeChar == null)
+		{
 			return;
-		L2PcInstance requestor = activeChar.getActiveRequester();
+		}
+		final L2PcInstance requestor = activeChar.getActiveRequester();
 		if (requestor == null)
+		{
 			return;
+		}
 		
 		if (_answer == 1)
 		{
@@ -47,10 +52,9 @@ public final class RequestReplySurrenderPledgeWar extends L2GameClientPacket
 		}
 		else
 		{
-			//TODO: is there something missing?
+			_log.info(getClass().getSimpleName() + ": Missing implementation for answer: " + _answer + " and name: " + _reqName + "!");
 		}
-		
-		activeChar.onTransactionRequest(null);
+		activeChar.onTransactionRequest(requestor);
 	}
 	
 	@Override

+ 7 - 5
L2J_Server_BETA/java/com/l2jserver/gameserver/network/clientpackets/RequestRestartPoint.java

@@ -236,11 +236,13 @@ public final class RequestRestartPoint extends L2GameClientPacket
 		}
 		
 		// Teleport and revive
-		activeChar.setInstanceId(instanceId);
-		activeChar.setIsIn7sDungeon(false);
-		activeChar.setIsPendingRevive(true);
-		activeChar.teleToLocation(loc, true);
-
+		if (loc != null)
+		{
+			activeChar.setInstanceId(instanceId);
+			activeChar.setIsIn7sDungeon(false);
+			activeChar.setIsPendingRevive(true);
+			activeChar.teleToLocation(loc, true);
+		}
 	}
 	
 	@Override

+ 2 - 2
L2J_Server_BETA/java/com/l2jserver/gameserver/script/faenor/FaenorParser.java

@@ -34,7 +34,7 @@ import com.l2jserver.gameserver.script.Parser;
 public abstract class FaenorParser extends Parser
 {
 	protected static FaenorInterface _bridge = FaenorInterface.getInstance();
-	protected static final DateFormat DATE_FORMAT = new SimpleDateFormat("dd MMM yyyy", Locale.US);
+	protected final DateFormat DATE_FORMAT = new SimpleDateFormat("dd MMM yyyy", Locale.US);
 	
 	public final static boolean DEBUG = true;
 	
@@ -92,7 +92,7 @@ public abstract class FaenorParser extends Parser
 		return node.getNodeName().equalsIgnoreCase(name);
 	}
 	
-	public static Date getDate(String date) throws ParseException
+	public Date getDate(String date) throws ParseException
 	{
 		return DATE_FORMAT.parse(date);
 	}

+ 6 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/taskmanager/TaskManager.java

@@ -125,6 +125,12 @@ public final class TaskManager
 			return object == null ? false : id == ((ExecutedTask) object).id;
 		}
 		
+		@Override
+		public int hashCode()
+		{
+			return id;
+		}
+		
 		public Task getTask()
 		{
 			return task;

+ 17 - 22
L2J_Server_BETA/java/com/l2jserver/gameserver/util/GMAudit.java

@@ -24,7 +24,6 @@ import java.util.logging.Logger;
 
 import com.l2jserver.util.lib.Log;
 
-
 public class GMAudit
 {
 	static
@@ -33,37 +32,33 @@ public class GMAudit
 	}
 	
 	private static final Logger _log = Logger.getLogger(Log.class.getName());
-	private static final SimpleDateFormat _formatter = new SimpleDateFormat("dd/MM/yyyy H:mm:ss");
 	
+	/**
+	 * @param gmName
+	 * @param action
+	 * @param target
+	 * @param params
+	 */
 	public static void auditGMAction(String gmName, String action, String target, String params)
 	{
-		String today = _formatter.format(new Date());
-		
-		FileWriter save = null;
-		try
+		final File file = new File("log/GMAudit/" + gmName + ".txt");
+		final SimpleDateFormat _formatter = new SimpleDateFormat("dd/MM/yyyy H:mm:ss");
+		try (FileWriter save = new FileWriter(file, true))
 		{
-			File file = new File("log/GMAudit/" + gmName + ".txt");
-			save = new FileWriter(file, true);
-			
-			String out = (today + ">" + gmName + ">" + action + ">" + target + ">" + params + "\r\n");
-			save.write(out);
+			save.write(_formatter.format(new Date()) + ">" + gmName + ">" + action + ">" + target + ">" + params + "\r\n");
 		}
 		catch (IOException e)
 		{
-			_log.log(Level.SEVERE, "GMAudit for GM " + gmName +" could not be saved: ", e);
-		}
-		finally
-		{
-			try
-			{
-				save.close();
-			}
-			catch (Exception e)
-			{
-			}
+			_log.log(Level.SEVERE, "GMAudit for GM " + gmName + " could not be saved: ", e);
 		}
 	}
 	
+	/**
+	 * Wrapper method.
+	 * @param gmName
+	 * @param action
+	 * @param target
+	 */
 	public static void auditGMAction(String gmName, String action, String target)
 	{
 		auditGMAction(gmName, action, target, "");

+ 3 - 8
L2J_Server_BETA/java/com/l2jserver/gameserver/util/Point3D.java

@@ -28,7 +28,6 @@ public class Point3D implements Serializable
 	 */
 	private static final long serialVersionUID = 4638345252031872576L;
 	
-	/* since using volatile vars, removing all synchronizations */
 	private volatile int _x, _y, _z;
 	
 	public Point3D(int pX, int pY, int pZ)
@@ -112,7 +111,7 @@ public class Point3D implements Serializable
 		return distanceSquared(point1, point2) < distance * distance;
 	}
 	
-	public int getX()
+	public synchronized int getX()
 	{
 		return _x;
 	}
@@ -122,7 +121,7 @@ public class Point3D implements Serializable
 		_x = pX;
 	}
 	
-	public int getY()
+	public synchronized int getY()
 	{
 		return _y;
 	}
@@ -132,7 +131,7 @@ public class Point3D implements Serializable
 		_y = pY;
 	}
 	
-	public int getZ()
+	public synchronized int getZ()
 	{
 		return _z;
 	}
@@ -148,8 +147,4 @@ public class Point3D implements Serializable
 		_y = pY;
 		_z = pZ;
 	}
-	
-	/* note by Deedlit: we are using volatile variable types here. We dont need to additionally 
-	 * use synchronized, cause volatile vars are synced vars. Removed all, please test if all is ok. Need to
-	 * look through code and remove similar pointless lockings if any more there. */
 }

+ 0 - 1
L2J_Server_BETA/java/com/l2jserver/tools/gsregistering/GUserInterface.java

@@ -165,7 +165,6 @@ public class GUserInterface extends BaseGameServerRegister implements ActionList
 	@Override
 	public void load()
 	{
-		
 		SwingUtilities.invokeLater
 		(
 				new Runnable()

+ 13 - 10
L2J_Server_BETA/java/com/l2jserver/tools/gsregistering/GameServerRegister.java

@@ -206,17 +206,20 @@ public class GameServerRegister extends BaseGameServerRegister
 			System.out.print(this.getBundle().getString("yourChoice")+' ');
 			String choice;
 			choice = _in.readLine();
-			if (choice.equals("1"))
+			if (choice != null)
 			{
-				return true;
-			}
-			else if (choice.equals("2"))
-			{
-				return false;
-			}
-			else
-			{
-				System.out.printf(this.getBundle().getString("invalidChoice")+'\n', choice);
+				if (choice.equals("1"))
+				{
+					return true;
+				}
+				else if (choice.equals("2"))
+				{
+					return false;
+				}
+				else
+				{
+					System.out.printf(this.getBundle().getString("invalidChoice")+'\n', choice);
+				}
 			}
 		}
 		while (true);

+ 3 - 7
L2J_Server_BETA/java/com/l2jserver/tools/i18n/LanguageControl.java

@@ -53,16 +53,12 @@ public class LanguageControl extends Control
 			format = "properties";
 			String bundleName = toBundleName(baseName, locale);
 			String resourceName = LANGUAGES_DIRECTORY + toResourceName(bundleName, format);
-			BufferedInputStream bis = null;
-			try
+			
+			try (FileInputStream fis = new FileInputStream(resourceName);
+				BufferedInputStream bis = new BufferedInputStream(fis))
 			{
-				bis = new BufferedInputStream(new FileInputStream(resourceName));
 				bundle = new PropertyResourceBundle(bis);
 			}
-			finally
-			{
-				bis.close();
-			}
 		}
 		return bundle;
 	}

+ 1 - 0
L2J_Server_BETA/java/com/l2jserver/tools/ngl/LocalizationParser.java

@@ -91,6 +91,7 @@ public class LocalizationParser
 			catch (Exception e)
 			{
 				_log.log(Level.WARNING, "Could not load localization file");
+				return;
 			}
 			
 			Node n = doc.getFirstChild();

+ 5 - 1
L2J_Server_BETA/java/com/l2jserver/util/Base64.java

@@ -89,7 +89,11 @@ public class Base64
 	{
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		System.out.print("Enter String to encode: ");
-		System.out.println(Base64.encodeBytes(bf.readLine().getBytes()));
+		final String line = bf.readLine();
+		if (line != null)
+		{
+			System.out.println(Base64.encodeBytes(line.getBytes()));
+		}
 	}
 	
 	/** Determine which ALPHABET to use. */

+ 2 - 1
L2J_Server_BETA/java/com/l2jserver/util/network/BaseRecievePacket.java

@@ -76,12 +76,13 @@ public abstract class BaseRecievePacket
 		{
 			result = new String(_decrypt,_off,_decrypt.length-_off, "UTF-16LE");
 			result = result.substring(0, result.indexOf(0x00));
+			_off += result.length()*2 + 2;
 		}
 		catch (Exception e)
 		{
 			_log.warning(getClass().getSimpleName() + ": " + e.getMessage());
 		}
-		_off += result.length()*2 + 2;
+		
 		return result;
 	}