Parcourir la source

BETA: Some minor cleanup by jurchiks, thanks.

Zoey76 il y a 14 ans
Parent
commit
4026cfbc92

+ 7 - 19
L2J_Server_BETA/java/com/l2jserver/L2DatabaseFactory.java

@@ -31,19 +31,14 @@ public class L2DatabaseFactory
 	
 	public static enum ProviderType
 	{
-		MySql,
-		MsSql
+		MySql, MsSql
 	}
 	
-	// =========================================================
-	// Data Field
 	private static L2DatabaseFactory _instance;
 	private static ScheduledExecutorService _executor;
 	private ProviderType _providerType;
 	private ComboPooledDataSource _source;
 	
-	// =========================================================
-	// Constructor
 	public L2DatabaseFactory() throws SQLException
 	{
 		try
@@ -74,7 +69,7 @@ public class L2DatabaseFactory
 			_source.setAutomaticTestTable("connection_test_table");
 			_source.setTestConnectionOnCheckin(false);
 			
-			// testing OnCheckin used with IdleConnectionTestPeriod is faster than  testing on checkout
+			// testing OnCheckin used with IdleConnectionTestPeriod is faster than testing on checkout
 			
 			_source.setIdleConnectionTestPeriod(3600); // test idle connection every 60 sec
 			_source.setMaxIdleTime(Config.DATABASE_MAX_IDLE_TIME); // 0 = idle connections never expire
@@ -82,7 +77,7 @@ public class L2DatabaseFactory
 			// but I prefer to disconnect all connections not used
 			// for more than 1 hour
 			
-			// enables statement caching,  there is a "semi-bug" in c3p0 0.9.0 but in 0.9.0.2 and later it's fixed
+			// enables statement caching, there is a "semi-bug" in c3p0 0.9.0 but in 0.9.0.2 and later it's fixed
 			_source.setMaxStatementsPerConnection(100);
 			
 			_source.setBreakAfterAcquireFailure(false); // never fail if any way possible
@@ -122,8 +117,6 @@ public class L2DatabaseFactory
 		}
 	}
 	
-	// =========================================================
-	// Method - Public
 	public final String prepQuerySelect(String[] fields, String tableName, String whereClause, boolean returnOnlyTopRecord)
 	{
 		String msSqlTop1 = "";
@@ -200,8 +193,6 @@ public class L2DatabaseFactory
 		return sbResult.toString();
 	}
 	
-	// =========================================================
-	// Property - Public
 	public static L2DatabaseFactory getInstance() throws SQLException
 	{
 		synchronized (L2DatabaseFactory.class)
@@ -214,7 +205,7 @@ public class L2DatabaseFactory
 		return _instance;
 	}
 	
-	public Connection getConnection() //throws SQLException
+	public Connection getConnection()
 	{
 		Connection con = null;
 		
@@ -238,17 +229,15 @@ public class L2DatabaseFactory
 	
 	private static class ConnectionCloser implements Runnable
 	{
-		private Connection c ;
-		private RuntimeException exp;
+		private final Connection c;
+		private final RuntimeException exp;
 		
 		public ConnectionCloser(Connection con, RuntimeException e)
 		{
 			c = con;
 			exp = e;
 		}
-		/* (non-Javadoc)
-		 * @see java.lang.Runnable#run()
-		 */
+		
 		@Override
 		public void run()
 		{
@@ -263,7 +252,6 @@ public class L2DatabaseFactory
 			{
 				_log.log(Level.WARNING, "", e);
 			}
-			
 		}
 	}
 	

+ 7 - 12
L2J_Server_BETA/java/com/l2jserver/gameserver/network/serverpackets/Attack.java

@@ -18,7 +18,6 @@ import com.l2jserver.gameserver.model.L2Object;
 import com.l2jserver.gameserver.model.actor.L2Character;
 import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
 
-
 /**
  * sample
  * 06 8f19904b 2522d04b 00000000 80 950c0000 4af50000 08f2ffff 0000    - 0 damage (missed 0x80)
@@ -26,8 +25,6 @@ import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
 
  * format
  * dddc dddh (ddc)
- *
- * @version $Revision: 1.3.2.1.2.4 $ $Date: 2005/03/27 15:29:39 $
  */
 public class Attack extends L2GameServerPacket
 {
@@ -52,11 +49,11 @@ public class Attack extends L2GameServerPacket
 				return;
 			}
 			if (soulshot)
-				_flags = HITFLAG_USESS | Attack.this._ssGrade;
+				_flags = HITFLAG_USESS | _ssGrade;
 			if (crit)
 				_flags |= HITFLAG_CRIT;
 			// dirty fix for lags on olympiad
-			if (shld > 0 && !(target instanceof L2PcInstance && ((L2PcInstance)target).isInOlympiadMode()))
+			if (shld > 0 && !(target instanceof L2PcInstance && ((L2PcInstance) target).isInOlympiadMode()))
 				_flags |= HITFLAG_SHLD;
 			//			if (shld > 0)
 			//				_flags |= HITFLAG_SHLD;
@@ -98,7 +95,7 @@ public class Attack extends L2GameServerPacket
 	
 	public Hit createHit(L2Object target, int damage, boolean miss, boolean crit, byte shld)
 	{
-		return new Hit( target, damage, miss, crit, shld );
+		return new Hit(target, damage, miss, crit, shld);
 	}
 	
 	public void hit(Hit... hits)
@@ -140,14 +137,12 @@ public class Attack extends L2GameServerPacket
 		writeH(_hits.length - 1);
 		// prevent sending useless packet while there is only one target.
 		if (_hits.length > 1)
-		{
-			for (int i = 1; i < _hits.length; i++)
+			for (Hit hit : _hits)
 			{
-				writeD(_hits[i]._targetId);
-				writeD(_hits[i]._damage);
-				writeC(_hits[i]._flags);
+				writeD(hit._targetId);
+				writeD(hit._damage);
+				writeC(hit._flags);
 			}
-		}
 		
 		writeD(_tx);
 		writeD(_ty);

+ 12 - 16
L2J_Server_BETA/java/com/l2jserver/gameserver/network/serverpackets/NpcSay.java

@@ -25,9 +25,9 @@ public final class NpcSay extends L2GameServerPacket
 {
 	// cddddS
 	private static final String _S__30_NPCSAY = "[S] 30 NpcSay";
-	private int _objectId;
-	private int _textType;
-	private int _npcId;
+	private final int _objectId;
+	private final int _textType;
+	private final int _npcId;
 	private String _text;
 	private int _npcString;
 	private List<String> _parameters;
@@ -39,7 +39,7 @@ public final class NpcSay extends L2GameServerPacket
 	{
 		_objectId = objectId;
 		_textType = messageType;
-		_npcId = 1000000+npcId;
+		_npcId = 1000000 + npcId;
 		_npcString = -1;
 		_text = text;
 	}
@@ -48,19 +48,20 @@ public final class NpcSay extends L2GameServerPacket
 	{
 		_objectId = objectId;
 		_textType = messageType;
-		_npcId = 1000000+npcId;
+		_npcId = 1000000 + npcId;
 		_npcString = npcString;
 	}
 	
 	/**
-	 * String parameter for argument S1,S2,.. in npcstring-e.dat
-	 * @param text
+	 * @param text - parameter for argument S1,S2 etc of an npcstring
+	 * @return this NpcSay packet object
 	 */
-	public void addStringParameter(String text)
+	public NpcSay addStringParameter(String text)
 	{
 		if (_parameters == null)
 			_parameters = new ArrayList<String>();
 		_parameters.add(text);
+		return this;
 	}
 	
 	@Override
@@ -73,14 +74,9 @@ public final class NpcSay extends L2GameServerPacket
 		writeD(_npcString);
 		if (_npcString == -1)
 			writeS(_text);
-		else
-		{
-			if (_parameters != null)
-			{
-				for (String s : _parameters)
-					writeS(s);
-			}
-		}
+		else if (_parameters != null)
+			for (String s : _parameters)
+				writeS(s);
 	}
 	
 	/* (non-Javadoc)