Sfoglia il codice sorgente

BETA: Rework of Macro/Macro List, rework of BlockList and proper use of ARM for database connections (Java 7 feature).
* Unhardcoding connection close time using existing configuration option.
* Removing deprecated L2DatabaseFactory#close() method.

Zoey76 12 anni fa
parent
commit
b4249ad9f1
18 ha cambiato i file con 1065 aggiunte e 1097 eliminazioni
  1. 1 24
      L2J_Server_BETA/java/com/l2jserver/L2DatabaseFactory.java
  2. 14 15
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/AutoSpawnHandler.java
  3. 13 16
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/BlockList.java
  4. 22 27
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/CursedWeapon.java
  5. 128 155
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/L2Clan.java
  6. 17 20
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/L2ClanMember.java
  7. 0 74
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/L2Macro.java
  8. 80 0
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/Macro.java
  9. 66 0
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/MacroCmd.java
  10. 70 86
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/MacroList.java
  11. 17 26
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/ShortCuts.java
  12. 179 203
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java
  13. 47 52
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/instance/L2PetInstance.java
  14. 34 33
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/entity/Castle.java
  15. 229 245
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/entity/Hero.java
  16. 118 95
      L2J_Server_BETA/java/com/l2jserver/gameserver/network/L2GameClient.java
  17. 13 10
      L2J_Server_BETA/java/com/l2jserver/gameserver/network/clientpackets/RequestMakeMacro.java
  18. 17 16
      L2J_Server_BETA/java/com/l2jserver/gameserver/network/serverpackets/SendMacroList.java

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

@@ -274,7 +274,7 @@ public class L2DatabaseFactory
 				}
 				else
 				{
-					getExecutor().schedule(new ConnectionCloser(con, new RuntimeException()), 60, TimeUnit.SECONDS);
+					getExecutor().schedule(new ConnectionCloser(con, new RuntimeException()), Config.CONNECTION_CLOSE_TIME, TimeUnit.SECONDS);
 				}
 			}
 			catch (SQLException e)
@@ -326,29 +326,6 @@ public class L2DatabaseFactory
 		}
 	}
 	
-	/**
-	 * Close the connection.
-	 * @param con the con the connection
-	 * @deprecated now database connections are closed using try-with-resource.
-	 */
-	@Deprecated
-	public static void close(Connection con)
-	{
-		if (con == null)
-		{
-			return;
-		}
-		
-		try
-		{
-			con.close();
-		}
-		catch (SQLException e)
-		{
-			_log.log(Level.WARNING, "Failed to close database connection!", e);
-		}
-	}
-	
 	/**
 	 * Gets the executor.
 	 * @return the executor

+ 14 - 15
L2J_Server_BETA/java/com/l2jserver/gameserver/model/AutoSpawnHandler.java

@@ -21,6 +21,7 @@ package com.l2jserver.gameserver.model;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.Statement;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ScheduledFuture;
@@ -118,12 +119,12 @@ public class AutoSpawnHandler
 	
 	private void restoreSpawnData()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement s = con.createStatement();
+			ResultSet rs = s.executeQuery("SELECT * FROM random_spawn ORDER BY groupId ASC");
+			PreparedStatement ps = con.prepareStatement("SELECT * FROM random_spawn_loc WHERE groupId=?"))
 		{
 			// Restore spawn group data, then the location data.
-			PreparedStatement statement = con.prepareStatement("SELECT * FROM random_spawn ORDER BY groupId ASC");
-			ResultSet rs = statement.executeQuery();
-			PreparedStatement statement2 = con.prepareStatement("SELECT * FROM random_spawn_loc WHERE groupId=?");
 			while (rs.next())
 			{
 				// Register random spawn group, set various options on the
@@ -135,20 +136,18 @@ public class AutoSpawnHandler
 				spawnInst.setRandomSpawn(rs.getBoolean("randomSpawn"));
 				
 				// Restore the spawn locations for this spawn group/instance.
-				statement2.setInt(1, rs.getInt("groupId"));
-				ResultSet rs2 = statement2.executeQuery();
-				statement2.clearParameters();
-				
-				while (rs2.next())
+				ps.setInt(1, rs.getInt("groupId"));
+				try (ResultSet rs2 = ps.executeQuery())
 				{
-					// Add each location to the spawn group/instance.
-					spawnInst.addSpawnLocation(rs2.getInt("x"), rs2.getInt("y"), rs2.getInt("z"), rs2.getInt("heading"));
+					ps.clearParameters();
+					
+					while (rs2.next())
+					{
+						// Add each location to the spawn group/instance.
+						spawnInst.addSpawnLocation(rs2.getInt("x"), rs2.getInt("y"), rs2.getInt("z"), rs2.getInt("heading"));
+					}
 				}
-				rs2.close();
 			}
-			statement2.close();
-			rs.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{

+ 13 - 16
L2J_Server_BETA/java/com/l2jserver/gameserver/model/BlockList.java

@@ -21,12 +21,12 @@ package com.l2jserver.gameserver.model;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import javolution.util.FastList;
 import javolution.util.FastMap;
 
 import com.l2jserver.L2DatabaseFactory;
@@ -76,27 +76,24 @@ public class BlockList
 	
 	private static List<Integer> loadList(int ObjId)
 	{
-		List<Integer> list = new FastList<>();
-		
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		List<Integer> list = new ArrayList<>();
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement statement = con.prepareStatement("SELECT friendId FROM character_friends WHERE charId=? AND relation=1"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT friendId FROM character_friends WHERE charId=? AND relation=1");
 			statement.setInt(1, ObjId);
-			ResultSet rset = statement.executeQuery();
-			
-			int friendId;
-			while (rset.next())
+			try (ResultSet rset = statement.executeQuery())
 			{
-				friendId = rset.getInt("friendId");
-				if (friendId == ObjId)
+				int friendId;
+				while (rset.next())
 				{
-					continue;
+					friendId = rset.getInt("friendId");
+					if (friendId == ObjId)
+					{
+						continue;
+					}
+					list.add(friendId);
 				}
-				list.add(friendId);
 			}
-			
-			rset.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{

+ 22 - 27
L2J_Server_BETA/java/com/l2jserver/gameserver/model/CursedWeapon.java

@@ -145,29 +145,26 @@ public class CursedWeapon
 				// Remove from Db
 				_log.info(_name + " being removed offline.");
 				
-				try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+				try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+					PreparedStatement del = con.prepareStatement("DELETE FROM items WHERE owner_id=? AND item_id=?");
+					PreparedStatement ps = con.prepareStatement("UPDATE characters SET karma=?, pkkills=? WHERE charId=?"))
 				{
 					// Delete the item
-					PreparedStatement statement = con.prepareStatement("DELETE FROM items WHERE owner_id=? AND item_id=?");
-					statement.setInt(1, _playerId);
-					statement.setInt(2, _itemId);
-					if (statement.executeUpdate() != 1)
+					del.setInt(1, _playerId);
+					del.setInt(2, _itemId);
+					if (del.executeUpdate() != 1)
 					{
 						_log.warning("Error while deleting itemId " + _itemId + " from userId " + _playerId);
 					}
-					statement.close();
 					
 					// Restore the karma
-					statement = con.prepareStatement("UPDATE characters SET karma=?, pkkills=? WHERE charId=?");
-					statement.setInt(1, _playerKarma);
-					statement.setInt(2, _playerPkKills);
-					statement.setInt(3, _playerId);
-					if (statement.executeUpdate() != 1)
+					ps.setInt(1, _playerKarma);
+					ps.setInt(2, _playerPkKills);
+					ps.setInt(3, _playerId);
+					if (ps.executeUpdate() != 1)
 					{
 						_log.warning("Error while updating karma & pkkills for userId " + _playerId);
 					}
-					
-					statement.close();
 				}
 				catch (Exception e)
 				{
@@ -508,25 +505,23 @@ public class CursedWeapon
 			_log.info("CursedWeapon: Saving data to disk.");
 		}
 		
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement del = con.prepareStatement("DELETE FROM cursed_weapons WHERE itemId = ?");
+			PreparedStatement ps = con.prepareStatement("INSERT INTO cursed_weapons (itemId, charId, playerKarma, playerPkKills, nbKills, endTime) VALUES (?, ?, ?, ?, ?, ?)"))
 		{
 			// Delete previous datas
-			PreparedStatement statement = con.prepareStatement("DELETE FROM cursed_weapons WHERE itemId = ?");
-			statement.setInt(1, _itemId);
-			statement.executeUpdate();
-			statement.close();
+			del.setInt(1, _itemId);
+			del.executeUpdate();
 			
 			if (_isActivated)
 			{
-				statement = con.prepareStatement("INSERT INTO cursed_weapons (itemId, charId, playerKarma, playerPkKills, nbKills, endTime) VALUES (?, ?, ?, ?, ?, ?)");
-				statement.setInt(1, _itemId);
-				statement.setInt(2, _playerId);
-				statement.setInt(3, _playerKarma);
-				statement.setInt(4, _playerPkKills);
-				statement.setInt(5, _nbKills);
-				statement.setLong(6, _endTime);
-				statement.executeUpdate();
-				statement.close();
+				ps.setInt(1, _itemId);
+				ps.setInt(2, _playerId);
+				ps.setInt(3, _playerKarma);
+				ps.setInt(4, _playerPkKills);
+				ps.setInt(5, _nbKills);
+				ps.setLong(6, _endTime);
+				ps.executeUpdate();
 			}
 		}
 		catch (SQLException e)

+ 128 - 155
L2J_Server_BETA/java/com/l2jserver/gameserver/model/L2Clan.java

@@ -285,11 +285,11 @@ public class L2Clan
 		else
 		{
 			try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-				PreparedStatement statement = con.prepareStatement("UPDATE characters SET clan_privs = ? WHERE charId = ?"))
+				PreparedStatement ps = con.prepareStatement("UPDATE characters SET clan_privs = ? WHERE charId = ?"))
 			{
-				statement.setInt(1, L2Clan.CP_NOTHING);
-				statement.setInt(2, getLeaderId());
-				statement.execute();
+				ps.setInt(1, L2Clan.CP_NOTHING);
+				ps.setInt(2, getLeaderId());
+				ps.execute();
 			}
 			catch (Exception e)
 			{
@@ -325,11 +325,11 @@ public class L2Clan
 		else
 		{
 			try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-				PreparedStatement statement = con.prepareStatement("UPDATE characters SET clan_privs = ? WHERE charId = ?"))
+				PreparedStatement ps = con.prepareStatement("UPDATE characters SET clan_privs = ? WHERE charId = ?"))
 			{
-				statement.setInt(1, L2Clan.CP_ALL);
-				statement.setInt(2, getLeaderId());
-				statement.execute();
+				ps.setInt(1, L2Clan.CP_ALL);
+				ps.setInt(2, getLeaderId());
+				ps.execute();
 			}
 			catch (Exception e)
 			{
@@ -892,11 +892,11 @@ public class L2Clan
 	public void updateBloodAllianceCountInDB()
 	{
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET blood_alliance_count=? WHERE clan_id=?"))
+			PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET blood_alliance_count=? WHERE clan_id=?"))
 		{
-			statement.setInt(1, getBloodAllianceCount());
-			statement.setInt(2, getClanId());
-			statement.execute();
+			ps.setInt(1, getBloodAllianceCount());
+			ps.setInt(2, getClanId());
+			ps.execute();
 		}
 		catch (Exception e)
 		{
@@ -954,11 +954,11 @@ public class L2Clan
 	public void updateClanScoreInDB()
 	{
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET reputation_score=? WHERE clan_id=?"))
+			PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET reputation_score=? WHERE clan_id=?"))
 		{
-			statement.setInt(1, getReputationScore());
-			statement.setInt(2, getClanId());
-			statement.execute();
+			ps.setInt(1, getReputationScore());
+			ps.setInt(2, getClanId());
+			ps.execute();
 		}
 		catch (Exception e)
 		{
@@ -982,21 +982,20 @@ public class L2Clan
 	 */
 	public void updateClanInDB()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
-		{
-			final PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET leader_id=?,ally_id=?,ally_name=?,reputation_score=?,ally_penalty_expiry_time=?,ally_penalty_type=?,char_penalty_expiry_time=?,dissolving_expiry_time=?,new_leader_id=? WHERE clan_id=?");
-			statement.setInt(1, getLeaderId());
-			statement.setInt(2, getAllyId());
-			statement.setString(3, getAllyName());
-			statement.setInt(4, getReputationScore());
-			statement.setLong(5, getAllyPenaltyExpiryTime());
-			statement.setInt(6, getAllyPenaltyType());
-			statement.setLong(7, getCharPenaltyExpiryTime());
-			statement.setLong(8, getDissolvingExpiryTime());
-			statement.setInt(9, getNewLeaderId());
-			statement.setInt(10, getClanId());
-			statement.execute();
-			statement.close();
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET leader_id=?,ally_id=?,ally_name=?,reputation_score=?,ally_penalty_expiry_time=?,ally_penalty_type=?,char_penalty_expiry_time=?,dissolving_expiry_time=?,new_leader_id=? WHERE clan_id=?"))
+		{
+			ps.setInt(1, getLeaderId());
+			ps.setInt(2, getAllyId());
+			ps.setString(3, getAllyName());
+			ps.setInt(4, getReputationScore());
+			ps.setLong(5, getAllyPenaltyExpiryTime());
+			ps.setInt(6, getAllyPenaltyType());
+			ps.setLong(7, getCharPenaltyExpiryTime());
+			ps.setLong(8, getDissolvingExpiryTime());
+			ps.setInt(9, getNewLeaderId());
+			ps.setInt(10, getClanId());
+			ps.execute();
 			if (Config.DEBUG)
 			{
 				_log.fine("New clan leader saved in db: " + getClanId());
@@ -1060,29 +1059,26 @@ public class L2Clan
 	 */
 	private void removeMemberInDatabase(L2ClanMember member, long clanJoinExpiryTime, long clanCreateExpiryTime)
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
-		{
-			PreparedStatement statement = con.prepareStatement("UPDATE characters SET clanid=0, title=?, clan_join_expiry_time=?, clan_create_expiry_time=?, clan_privs=0, wantspeace=0, subpledge=0, lvl_joined_academy=0, apprentice=0, sponsor=0 WHERE charId=?");
-			statement.setString(1, "");
-			statement.setLong(2, clanJoinExpiryTime);
-			statement.setLong(3, clanCreateExpiryTime);
-			statement.setInt(4, member.getObjectId());
-			statement.execute();
-			statement.close();
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps1 = con.prepareStatement("UPDATE characters SET clanid=0, title=?, clan_join_expiry_time=?, clan_create_expiry_time=?, clan_privs=0, wantspeace=0, subpledge=0, lvl_joined_academy=0, apprentice=0, sponsor=0 WHERE charId=?");
+			PreparedStatement ps2 = con.prepareStatement("UPDATE characters SET apprentice=0 WHERE apprentice=?");
+			PreparedStatement ps3 = con.prepareStatement("UPDATE characters SET sponsor=0 WHERE sponsor=?"))
+		{
+			ps1.setString(1, "");
+			ps1.setLong(2, clanJoinExpiryTime);
+			ps1.setLong(3, clanCreateExpiryTime);
+			ps1.setInt(4, member.getObjectId());
+			ps1.execute();
 			if (Config.DEBUG)
 			{
 				_log.fine("clan member removed in db: " + getClanId());
 			}
-			
-			statement = con.prepareStatement("UPDATE characters SET apprentice=0 WHERE apprentice=?");
-			statement.setInt(1, member.getObjectId());
-			statement.execute();
-			statement.close();
-			
-			statement = con.prepareStatement("UPDATE characters SET sponsor=0 WHERE sponsor=?");
-			statement.setInt(1, member.getObjectId());
-			statement.execute();
-			statement.close();
+			// Remove apprentice.
+			ps2.setInt(1, member.getObjectId());
+			ps2.execute();
+			// Remove sponsor.
+			ps3.setInt(1, member.getObjectId());
+			ps3.execute();
 		}
 		catch (Exception e)
 		{
@@ -1090,29 +1086,13 @@ public class L2Clan
 		}
 	}
 	
-	@SuppressWarnings("unused")
-	private void updateWarsInDB()
-	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
-		{
-			final PreparedStatement statement = con.prepareStatement("UPDATE clan_wars SET wantspeace1=? WHERE clan1=?");
-			statement.setInt(1, 0);
-			statement.setInt(2, 0);
-			statement.close();
-		}
-		catch (Exception e)
-		{
-			_log.log(Level.SEVERE, "Error updating clan wars data: " + e.getMessage(), e);
-		}
-	}
-	
 	private void restore()
 	{
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = con.prepareStatement(SELECT_CLAN_DATA))
+			PreparedStatement ps = con.prepareStatement(SELECT_CLAN_DATA))
 		{
-			statement.setInt(1, getClanId());
-			try (ResultSet clanData = statement.executeQuery())
+			ps.setInt(1, getClanId());
+			try (ResultSet clanData = ps.executeQuery())
 			{
 				if (clanData.next())
 				{
@@ -1145,7 +1125,7 @@ public class L2Clan
 					
 					final int leaderId = (clanData.getInt("leader_id"));
 					
-					statement.clearParameters();
+					ps.clearParameters();
 					
 					try (PreparedStatement select = con.prepareStatement("SELECT char_name,level,classid,charId,title,power_grade,subpledge,apprentice,sponsor,sex,race FROM characters WHERE clanid=?"))
 					{
@@ -1189,10 +1169,10 @@ public class L2Clan
 	private void restoreNotice()
 	{
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = con.prepareStatement("SELECT enabled,notice FROM clan_notices WHERE clan_id=?"))
+			PreparedStatement ps = con.prepareStatement("SELECT enabled,notice FROM clan_notices WHERE clan_id=?"))
 		{
-			statement.setInt(1, getClanId());
-			try (ResultSet noticeData = statement.executeQuery())
+			ps.setInt(1, getClanId());
+			try (ResultSet noticeData = ps.executeQuery())
 			{
 				while (noticeData.next())
 				{
@@ -1220,28 +1200,28 @@ public class L2Clan
 		}
 		
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = con.prepareStatement("INSERT INTO clan_notices (clan_id,notice,enabled) values (?,?,?) ON DUPLICATE KEY UPDATE notice=?,enabled=?"))
+			PreparedStatement ps = con.prepareStatement("INSERT INTO clan_notices (clan_id,notice,enabled) values (?,?,?) ON DUPLICATE KEY UPDATE notice=?,enabled=?"))
 		{
-			statement.setInt(1, getClanId());
-			statement.setString(2, notice);
+			ps.setInt(1, getClanId());
+			ps.setString(2, notice);
 			if (enabled)
 			{
-				statement.setString(3, "true");
+				ps.setString(3, "true");
 			}
 			else
 			{
-				statement.setString(3, "false");
+				ps.setString(3, "false");
 			}
-			statement.setString(4, notice);
+			ps.setString(4, notice);
 			if (enabled)
 			{
-				statement.setString(5, "true");
+				ps.setString(5, "true");
 			}
 			else
 			{
-				statement.setString(5, "false");
+				ps.setString(5, "false");
 			}
-			statement.execute();
+			ps.execute();
 		}
 		catch (Exception e)
 		{
@@ -1279,11 +1259,11 @@ public class L2Clan
 	private void restoreSkills()
 	{
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = con.prepareStatement("SELECT skill_id,skill_level,sub_pledge_id FROM clan_skills WHERE clan_id=?"))
+			PreparedStatement ps = con.prepareStatement("SELECT skill_id,skill_level,sub_pledge_id FROM clan_skills WHERE clan_id=?"))
 		{
 			// Retrieve all skills of this L2PcInstance from the database
-			statement.setInt(1, getClanId());
-			try (ResultSet rset = statement.executeQuery())
+			ps.setInt(1, getClanId());
+			try (ResultSet rset = ps.executeQuery())
 			{
 				// Go though the recordset of this SQL query
 				while (rset.next())
@@ -1406,24 +1386,24 @@ public class L2Clan
 			{
 				if (oldSkill != null)
 				{
-					try (PreparedStatement statement = con.prepareStatement("UPDATE clan_skills SET skill_level=? WHERE skill_id=? AND clan_id=?"))
+					try (PreparedStatement ps = con.prepareStatement("UPDATE clan_skills SET skill_level=? WHERE skill_id=? AND clan_id=?"))
 					{
-						statement.setInt(1, newSkill.getLevel());
-						statement.setInt(2, oldSkill.getId());
-						statement.setInt(3, getClanId());
-						statement.execute();
+						ps.setInt(1, newSkill.getLevel());
+						ps.setInt(2, oldSkill.getId());
+						ps.setInt(3, getClanId());
+						ps.execute();
 					}
 				}
 				else
 				{
-					try (PreparedStatement statement = con.prepareStatement("INSERT INTO clan_skills (clan_id,skill_id,skill_level,skill_name,sub_pledge_id) VALUES (?,?,?,?,?)"))
+					try (PreparedStatement ps = con.prepareStatement("INSERT INTO clan_skills (clan_id,skill_id,skill_level,skill_name,sub_pledge_id) VALUES (?,?,?,?,?)"))
 					{
-						statement.setInt(1, getClanId());
-						statement.setInt(2, newSkill.getId());
-						statement.setInt(3, newSkill.getLevel());
-						statement.setString(4, newSkill.getName());
-						statement.setInt(5, subType);
-						statement.execute();
+						ps.setInt(1, getClanId());
+						ps.setInt(2, newSkill.getId());
+						ps.setInt(3, newSkill.getLevel());
+						ps.setString(4, newSkill.getName());
+						ps.setInt(5, subType);
+						ps.execute();
 					}
 				}
 			}
@@ -1873,11 +1853,11 @@ public class L2Clan
 	private void restoreSubPledges()
 	{
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = con.prepareStatement("SELECT sub_pledge_id,name,leader_id FROM clan_subpledges WHERE clan_id=?"))
+			PreparedStatement ps = con.prepareStatement("SELECT sub_pledge_id,name,leader_id FROM clan_subpledges WHERE clan_id=?"))
 		{
 			// Retrieve all subpledges of this clan from the database
-			statement.setInt(1, getClanId());
-			try (ResultSet rset = statement.executeQuery())
+			ps.setInt(1, getClanId());
+			try (ResultSet rset = ps.executeQuery())
 			{
 				while (rset.next())
 				{
@@ -1978,20 +1958,13 @@ public class L2Clan
 		}
 		
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = con.prepareStatement("INSERT INTO clan_subpledges (clan_id,sub_pledge_id,name,leader_id) values (?,?,?,?)"))
+			PreparedStatement ps = con.prepareStatement("INSERT INTO clan_subpledges (clan_id,sub_pledge_id,name,leader_id) values (?,?,?,?)"))
 		{
-			statement.setInt(1, getClanId());
-			statement.setInt(2, pledgeType);
-			statement.setString(3, subPledgeName);
-			if (pledgeType != -1)
-			{
-				statement.setInt(4, leaderId);
-			}
-			else
-			{
-				statement.setInt(4, 0);
-			}
-			statement.execute();
+			ps.setInt(1, getClanId());
+			ps.setInt(2, pledgeType);
+			ps.setString(3, subPledgeName);
+			ps.setInt(4, pledgeType != -1 ? leaderId : 0);
+			ps.execute();
 			
 			subPledge = new SubPledge(pledgeType, subPledgeName, leaderId);
 			_subPledges.put(pledgeType, subPledge);
@@ -2059,13 +2032,13 @@ public class L2Clan
 	public void updateSubPledgeInDB(int pledgeType)
 	{
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = con.prepareStatement("UPDATE clan_subpledges SET leader_id=?, name=? WHERE clan_id=? AND sub_pledge_id=?"))
+			PreparedStatement ps = con.prepareStatement("UPDATE clan_subpledges SET leader_id=?, name=? WHERE clan_id=? AND sub_pledge_id=?"))
 		{
-			statement.setInt(1, getSubPledge(pledgeType).getLeaderId());
-			statement.setString(2, getSubPledge(pledgeType).getName());
-			statement.setInt(3, getClanId());
-			statement.setInt(4, pledgeType);
-			statement.execute();
+			ps.setInt(1, getSubPledge(pledgeType).getLeaderId());
+			ps.setString(2, getSubPledge(pledgeType).getName());
+			ps.setInt(3, getClanId());
+			ps.setInt(4, pledgeType);
+			ps.execute();
 			if (Config.DEBUG)
 			{
 				_log.fine("Subpledge updated in db: " + getClanId());
@@ -2080,12 +2053,12 @@ public class L2Clan
 	private void restoreRankPrivs()
 	{
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = con.prepareStatement("SELECT privs,rank,party FROM clan_privs WHERE clan_id=?"))
+			PreparedStatement ps = con.prepareStatement("SELECT privs,rank,party FROM clan_privs WHERE clan_id=?"))
 		{
 			// Retrieve all skills of this L2PcInstance from the database
-			statement.setInt(1, getClanId());
+			ps.setInt(1, getClanId());
 			// _log.warning("clanPrivs restore for ClanId : "+getClanId());
-			try (ResultSet rset = statement.executeQuery())
+			try (ResultSet rset = ps.executeQuery())
 			{
 				// Go though the recordset of this SQL query
 				while (rset.next())
@@ -2135,15 +2108,15 @@ public class L2Clan
 			_privs.get(rank).setPrivs(privs);
 			
 			try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-				PreparedStatement statement = con.prepareStatement("INSERT INTO clan_privs (clan_id,rank,party,privs) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE privs = ?"))
+				PreparedStatement ps = con.prepareStatement("INSERT INTO clan_privs (clan_id,rank,party,privs) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE privs = ?"))
 			{
 				// Retrieve all skills of this L2PcInstance from the database
-				statement.setInt(1, getClanId());
-				statement.setInt(2, rank);
-				statement.setInt(3, 0);
-				statement.setInt(4, privs);
-				statement.setInt(5, privs);
-				statement.execute();
+				ps.setInt(1, getClanId());
+				ps.setInt(2, rank);
+				ps.setInt(3, 0);
+				ps.setInt(4, privs);
+				ps.setInt(5, privs);
+				ps.execute();
 			}
 			catch (Exception e)
 			{
@@ -2172,14 +2145,14 @@ public class L2Clan
 			_privs.put(rank, new RankPrivs(rank, 0, privs));
 			
 			try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-				PreparedStatement statement = con.prepareStatement("INSERT INTO clan_privs (clan_id,rank,party,privs) VALUES (?,?,?,?)"))
+				PreparedStatement ps = con.prepareStatement("INSERT INTO clan_privs (clan_id,rank,party,privs) VALUES (?,?,?,?)"))
 			{
 				// Retrieve all skills of this L2PcInstance from the database
-				statement.setInt(1, getClanId());
-				statement.setInt(2, rank);
-				statement.setInt(3, 0);
-				statement.setInt(4, privs);
-				statement.execute();
+				ps.setInt(1, getClanId());
+				ps.setInt(2, rank);
+				ps.setInt(3, 0);
+				ps.setInt(4, privs);
+				ps.execute();
 			}
 			catch (Exception e)
 			{
@@ -2296,11 +2269,11 @@ public class L2Clan
 		if (storeInDb)
 		{
 			try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-				PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET auction_bid_at=? WHERE clan_id=?"))
+				PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET auction_bid_at=? WHERE clan_id=?"))
 			{
-				statement.setInt(1, id);
-				statement.setInt(2, getClanId());
-				statement.execute();
+				ps.setInt(1, id);
+				ps.setInt(2, getClanId());
+				ps.execute();
 			}
 			catch (Exception e)
 			{
@@ -2872,11 +2845,11 @@ public class L2Clan
 	public void changeLevel(int level)
 	{
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET clan_level = ? WHERE clan_id = ?"))
+			PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET clan_level = ? WHERE clan_id = ?"))
 		{
-			statement.setInt(1, level);
-			statement.setInt(2, getClanId());
-			statement.execute();
+			ps.setInt(1, level);
+			ps.setInt(2, getClanId());
+			ps.execute();
 		}
 		catch (Exception e)
 		{
@@ -2926,11 +2899,11 @@ public class L2Clan
 		setCrestId(crestId);
 		
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET crest_id = ? WHERE clan_id = ?"))
+			PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET crest_id = ? WHERE clan_id = ?"))
 		{
-			statement.setInt(1, crestId);
-			statement.setInt(2, getClanId());
-			statement.executeUpdate();
+			ps.setInt(1, crestId);
+			ps.setInt(2, getClanId());
+			ps.executeUpdate();
 		}
 		catch (SQLException e)
 		{
@@ -2963,11 +2936,11 @@ public class L2Clan
 		}
 		
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = con.prepareStatement(sqlStatement))
+			PreparedStatement ps = con.prepareStatement(sqlStatement))
 		{
-			statement.setInt(1, crestId);
-			statement.setInt(2, allyId);
-			statement.executeUpdate();
+			ps.setInt(1, crestId);
+			ps.setInt(2, allyId);
+			ps.executeUpdate();
 		}
 		catch (SQLException e)
 		{
@@ -3009,11 +2982,11 @@ public class L2Clan
 		setCrestLargeId(crestId);
 		
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET crest_large_id = ? WHERE clan_id = ?"))
+			PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET crest_large_id = ? WHERE clan_id = ?"))
 		{
-			statement.setInt(1, crestId);
-			statement.setInt(2, getClanId());
-			statement.executeUpdate();
+			ps.setInt(1, crestId);
+			ps.setInt(2, getClanId());
+			ps.executeUpdate();
 		}
 		catch (SQLException e)
 		{

+ 17 - 20
L2J_Server_BETA/java/com/l2jserver/gameserver/model/L2ClanMember.java

@@ -270,13 +270,12 @@ public class L2ClanMember
 	 */
 	public void updatePledgeType()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("UPDATE characters SET subpledge=? WHERE charId=?"))
 		{
-			PreparedStatement statement = con.prepareStatement("UPDATE characters SET subpledge=? WHERE charId=?");
-			statement.setLong(1, _pledgeType);
-			statement.setInt(2, getObjectId());
-			statement.execute();
-			statement.close();
+			ps.setLong(1, _pledgeType);
+			ps.setInt(2, getObjectId());
+			ps.execute();
 		}
 		catch (Exception e)
 		{
@@ -320,13 +319,12 @@ public class L2ClanMember
 	 */
 	public void updatePowerGrade()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("UPDATE characters SET power_grade=? WHERE charId=?"))
 		{
-			PreparedStatement statement = con.prepareStatement("UPDATE characters SET power_grade=? WHERE charId=?");
-			statement.setLong(1, _powerGrade);
-			statement.setInt(2, getObjectId());
-			statement.execute();
-			statement.close();
+			ps.setLong(1, _powerGrade);
+			ps.setInt(2, getObjectId());
+			ps.execute();
 		}
 		catch (Exception e)
 		{
@@ -750,14 +748,13 @@ public class L2ClanMember
 	 */
 	public void saveApprenticeAndSponsor(int apprentice, int sponsor)
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
-		{
-			PreparedStatement statement = con.prepareStatement("UPDATE characters SET apprentice=?,sponsor=? WHERE charId=?");
-			statement.setInt(1, apprentice);
-			statement.setInt(2, sponsor);
-			statement.setInt(3, getObjectId());
-			statement.execute();
-			statement.close();
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("UPDATE characters SET apprentice=?,sponsor=? WHERE charId=?"))
+		{
+			ps.setInt(1, apprentice);
+			ps.setInt(2, sponsor);
+			ps.setInt(3, getObjectId());
+			ps.execute();
 		}
 		catch (SQLException e)
 		{

+ 0 - 74
L2J_Server_BETA/java/com/l2jserver/gameserver/model/L2Macro.java

@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2004-2013 L2J Server
- * 
- * This file is part of L2J Server.
- * 
- * L2J Server 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.
- * 
- * L2J Server 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;
-
-/**
- * This class ...
- * @version $Revision: 1.3 $ $Date: 2004/10/23 22:12:44 $
- */
-public class L2Macro
-{
-	public static final int CMD_TYPE_SKILL = 1;
-	public static final int CMD_TYPE_ACTION = 3;
-	public static final int CMD_TYPE_SHORTCUT = 4;
-	
-	public int id;
-	public final int icon;
-	public final String name;
-	public final String descr;
-	public final String acronym;
-	public final L2MacroCmd[] commands;
-	
-	public static class L2MacroCmd
-	{
-		public final int entry;
-		public final int type;
-		public final int d1; // skill_id or page for shortcuts
-		public final int d2; // shortcut
-		public final String cmd;
-		
-		public L2MacroCmd(int pEntry, int pType, int pD1, int pD2, String pCmd)
-		{
-			entry = pEntry;
-			type = pType;
-			d1 = pD1;
-			d2 = pD2;
-			cmd = pCmd;
-		}
-	}
-	
-	/**
-	 * @param pId
-	 * @param pIcon
-	 * @param pName
-	 * @param pDescr
-	 * @param pAcronym
-	 * @param pCommands
-	 */
-	public L2Macro(int pId, int pIcon, String pName, String pDescr, String pAcronym, L2MacroCmd[] pCommands)
-	{
-		id = pId;
-		icon = pIcon;
-		name = pName;
-		descr = pDescr;
-		acronym = pAcronym;
-		commands = pCommands;
-	}
-	
-}

+ 80 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/model/Macro.java

@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2004-2013 L2J Server
+ * 
+ * This file is part of L2J Server.
+ * 
+ * L2J Server 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.
+ * 
+ * L2J Server 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;
+
+import java.util.List;
+
+public class Macro
+{
+	public static final int CMD_TYPE_SKILL = 1;
+	public static final int CMD_TYPE_ACTION = 3;
+	public static final int CMD_TYPE_SHORTCUT = 4;
+	
+	private int _id;
+	private final int _icon;
+	private final String _name;
+	private final String _descr;
+	private final String _acronym;
+	private final List<MacroCmd> _commands;
+	
+	public Macro(int id, int icon, String name, String descr, String acronym, List<MacroCmd> list)
+	{
+		setId(id);
+		_icon = icon;
+		_name = name;
+		_descr = descr;
+		_acronym = acronym;
+		_commands = list;
+	}
+	
+	public int getId()
+	{
+		return _id;
+	}
+	
+	public void setId(int _id)
+	{
+		this._id = _id;
+	}
+	
+	public int getIcon()
+	{
+		return _icon;
+	}
+	
+	public String getName()
+	{
+		return _name;
+	}
+	
+	public String getDescr()
+	{
+		return _descr;
+	}
+	
+	public String getAcronym()
+	{
+		return _acronym;
+	}
+	
+	public List<MacroCmd> getCommands()
+	{
+		return _commands;
+	}
+}

+ 66 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/model/MacroCmd.java

@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2004-2013 L2J Server
+ * 
+ * This file is part of L2J Server.
+ * 
+ * L2J Server 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.
+ * 
+ * L2J Server 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;
+
+/**
+ * Macro Cmd data transfer object.
+ * @author Zoey76
+ */
+public class MacroCmd
+{
+	private final int _entry;
+	private final int _type;
+	private final int _d1; // skill_id or page for shortcuts
+	private final int _d2; // shortcut
+	private final String _cmd;
+	
+	public MacroCmd(int entry, int type, int d1, int d2, String cmd)
+	{
+		_entry = entry;
+		_type = type;
+		_d1 = d1;
+		_d2 = d2;
+		_cmd = cmd;
+	}
+	
+	public int getEntry()
+	{
+		return _entry;
+	}
+	
+	public int getType()
+	{
+		return _type;
+	}
+	
+	public int getD1()
+	{
+		return _d1;
+	}
+	
+	public int getD2()
+	{
+		return _d2;
+	}
+	
+	public String getCmd()
+	{
+		return _cmd;
+	}
+}

+ 70 - 86
L2J_Server_BETA/java/com/l2jserver/gameserver/model/MacroList.java

@@ -21,33 +21,28 @@ package com.l2jserver.gameserver.model;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.StringTokenizer;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import javolution.util.FastList;
-import javolution.util.FastMap;
-
 import com.l2jserver.L2DatabaseFactory;
-import com.l2jserver.gameserver.model.L2Macro.L2MacroCmd;
 import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
 import com.l2jserver.gameserver.network.serverpackets.SendMacroList;
 import com.l2jserver.util.StringUtil;
 
-/**
- * This class ...
- * @version $Revision: 1.1.2.1.2.2 $ $Date: 2005/03/02 15:38:41 $
- */
 public class MacroList
 {
-	private static Logger _log = Logger.getLogger(MacroList.class.getName());
+	private static final Logger _log = Logger.getLogger(MacroList.class.getName());
 	
 	private final L2PcInstance _owner;
 	private int _revision;
 	private int _macroId;
-	private final Map<Integer, L2Macro> _macroses = new FastMap<>();
+	private final Map<Integer, Macro> _macroses = new ConcurrentHashMap<>();
 	
 	public MacroList(L2PcInstance owner)
 	{
@@ -61,31 +56,31 @@ public class MacroList
 		return _revision;
 	}
 	
-	public L2Macro[] getAllMacroses()
+	public Collection<Macro> getAllMacroses()
 	{
-		return _macroses.values().toArray(new L2Macro[_macroses.size()]);
+		return _macroses.values();
 	}
 	
-	public L2Macro getMacro(int id)
+	public Macro getMacro(int id)
 	{
 		return _macroses.get(id - 1);
 	}
 	
-	public void registerMacro(L2Macro macro)
+	public void registerMacro(Macro macro)
 	{
-		if (macro.id == 0)
+		if (macro.getId() == 0)
 		{
-			macro.id = _macroId++;
-			while (_macroses.get(macro.id) != null)
+			macro.setId(_macroId++);
+			while (_macroses.containsKey(macro.getId()))
 			{
-				macro.id = _macroId++;
+				macro.setId(_macroId++);
 			}
-			_macroses.put(macro.id, macro);
+			_macroses.put(macro.getId(), macro);
 			registerMacroInDb(macro);
 		}
 		else
 		{
-			L2Macro old = _macroses.put(macro.id, macro);
+			final Macro old = _macroses.put(macro.getId(), macro);
 			if (old != null)
 			{
 				deleteMacroFromDb(old);
@@ -97,7 +92,7 @@ public class MacroList
 	
 	public void deleteMacro(int id)
 	{
-		L2Macro toRemove = _macroses.get(id);
+		Macro toRemove = _macroses.get(id);
 		if (toRemove != null)
 		{
 			deleteMacroFromDb(toRemove);
@@ -119,41 +114,39 @@ public class MacroList
 	public void sendUpdate()
 	{
 		_revision++;
-		L2Macro[] all = getAllMacroses();
-		if (all.length == 0)
+		Collection<Macro> all = getAllMacroses();
+		if (all.isEmpty())
 		{
-			_owner.sendPacket(new SendMacroList(_revision, all.length, null));
+			_owner.sendPacket(new SendMacroList(_revision, 0, null));
 		}
 		else
 		{
-			for (L2Macro m : all)
+			for (Macro m : all)
 			{
-				_owner.sendPacket(new SendMacroList(_revision, all.length, m));
+				_owner.sendPacket(new SendMacroList(_revision, all.size(), m));
 			}
 		}
 	}
 	
-	private void registerMacroInDb(L2Macro macro)
+	private void registerMacroInDb(Macro macro)
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("INSERT INTO character_macroses (charId,id,icon,name,descr,acronym,commands) values(?,?,?,?,?,?,?)"))
 		{
-			PreparedStatement statement = con.prepareStatement("INSERT INTO character_macroses (charId,id,icon,name,descr,acronym,commands) values(?,?,?,?,?,?,?)");
-			statement.setInt(1, _owner.getObjectId());
-			statement.setInt(2, macro.id);
-			statement.setInt(3, macro.icon);
-			statement.setString(4, macro.name);
-			statement.setString(5, macro.descr);
-			statement.setString(6, macro.acronym);
+			ps.setInt(1, _owner.getObjectId());
+			ps.setInt(2, macro.getId());
+			ps.setInt(3, macro.getIcon());
+			ps.setString(4, macro.getName());
+			ps.setString(5, macro.getDescr());
+			ps.setString(6, macro.getAcronym());
 			final StringBuilder sb = new StringBuilder(300);
-			for (L2MacroCmd cmd : macro.commands)
+			for (MacroCmd cmd : macro.getCommands())
 			{
-				StringUtil.append(sb, String.valueOf(cmd.type), ",", String.valueOf(cmd.d1), ",", String.valueOf(cmd.d2));
-				
-				if ((cmd.cmd != null) && (cmd.cmd.length() > 0))
+				StringUtil.append(sb, String.valueOf(cmd.getType()), ",", String.valueOf(cmd.getD1()), ",", String.valueOf(cmd.getD2()));
+				if ((cmd.getCmd() != null) && (cmd.getCmd().length() > 0))
 				{
-					StringUtil.append(sb, ",", cmd.cmd);
+					StringUtil.append(sb, ",", cmd.getCmd());
 				}
-				
 				sb.append(';');
 			}
 			
@@ -162,9 +155,8 @@ public class MacroList
 				sb.setLength(255);
 			}
 			
-			statement.setString(7, sb.toString());
-			statement.execute();
-			statement.close();
+			ps.setString(7, sb.toString());
+			ps.execute();
 		}
 		catch (Exception e)
 		{
@@ -172,18 +164,14 @@ public class MacroList
 		}
 	}
 	
-	/**
-	 * @param macro
-	 */
-	private void deleteMacroFromDb(L2Macro macro)
+	private void deleteMacroFromDb(Macro macro)
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("DELETE FROM character_macroses WHERE charId=? AND id=?"))
 		{
-			PreparedStatement statement = con.prepareStatement("DELETE FROM character_macroses WHERE charId=? AND id=?");
-			statement.setInt(1, _owner.getObjectId());
-			statement.setInt(2, macro.id);
-			statement.execute();
-			statement.close();
+			ps.setInt(1, _owner.getObjectId());
+			ps.setInt(2, macro.getId());
+			ps.execute();
 		}
 		catch (Exception e)
 		{
@@ -194,45 +182,41 @@ public class MacroList
 	public void restore()
 	{
 		_macroses.clear();
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("SELECT charId, id, icon, name, descr, acronym, commands FROM character_macroses WHERE charId=?"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT charId, id, icon, name, descr, acronym, commands FROM character_macroses WHERE charId=?");
-			statement.setInt(1, _owner.getObjectId());
-			ResultSet rset = statement.executeQuery();
-			while (rset.next())
+			ps.setInt(1, _owner.getObjectId());
+			try (ResultSet rset = ps.executeQuery())
 			{
-				int id = rset.getInt("id");
-				int icon = rset.getInt("icon");
-				String name = rset.getString("name");
-				String descr = rset.getString("descr");
-				String acronym = rset.getString("acronym");
-				List<L2MacroCmd> commands = FastList.newInstance();
-				StringTokenizer st1 = new StringTokenizer(rset.getString("commands"), ";");
-				while (st1.hasMoreTokens())
+				while (rset.next())
 				{
-					StringTokenizer st = new StringTokenizer(st1.nextToken(), ",");
-					if (st.countTokens() < 3)
-					{
-						continue;
-					}
-					int type = Integer.parseInt(st.nextToken());
-					int d1 = Integer.parseInt(st.nextToken());
-					int d2 = Integer.parseInt(st.nextToken());
-					String cmd = "";
-					if (st.hasMoreTokens())
+					int id = rset.getInt("id");
+					int icon = rset.getInt("icon");
+					String name = rset.getString("name");
+					String descr = rset.getString("descr");
+					String acronym = rset.getString("acronym");
+					List<MacroCmd> commands = new ArrayList<>();
+					StringTokenizer st1 = new StringTokenizer(rset.getString("commands"), ";");
+					while (st1.hasMoreTokens())
 					{
-						cmd = st.nextToken();
+						StringTokenizer st = new StringTokenizer(st1.nextToken(), ",");
+						if (st.countTokens() < 3)
+						{
+							continue;
+						}
+						int type = Integer.parseInt(st.nextToken());
+						int d1 = Integer.parseInt(st.nextToken());
+						int d2 = Integer.parseInt(st.nextToken());
+						String cmd = "";
+						if (st.hasMoreTokens())
+						{
+							cmd = st.nextToken();
+						}
+						commands.add(new MacroCmd(commands.size(), type, d1, d2, cmd));
 					}
-					L2MacroCmd mcmd = new L2MacroCmd(commands.size(), type, d1, d2, cmd);
-					commands.add(mcmd);
+					_macroses.put(id, new Macro(id, icon, name, descr, acronym, commands));
 				}
-				
-				L2Macro m = new L2Macro(id, icon, name, descr, acronym, commands.toArray(new L2MacroCmd[commands.size()]));
-				FastList.recycle((FastList<?>) commands);
-				_macroses.put(m.id, m);
 			}
-			rset.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{

+ 17 - 26
L2J_Server_BETA/java/com/l2jserver/gameserver/model/ShortCuts.java

@@ -34,10 +34,6 @@ import com.l2jserver.gameserver.network.serverpackets.ExAutoSoulShot;
 import com.l2jserver.gameserver.network.serverpackets.ShortCutInit;
 import com.l2jserver.gameserver.network.serverpackets.ShortCutRegister;
 
-/**
- * This class ...
- * @version $Revision: 1.1.2.1.2.3 $ $Date: 2005/03/27 15:29:33 $
- */
 public class ShortCuts
 {
 	private static Logger _log = Logger.getLogger(ShortCuts.class.getName());
@@ -93,9 +89,9 @@ public class ShortCuts
 			deleteShortCutFromDb(oldShortCut);
 		}
 		
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement statement = con.prepareStatement("REPLACE INTO character_shortcuts (charId,slot,page,type,shortcut_id,level,class_index) values(?,?,?,?,?,?,?)"))
 		{
-			PreparedStatement statement = con.prepareStatement("REPLACE INTO character_shortcuts (charId,slot,page,type,shortcut_id,level,class_index) values(?,?,?,?,?,?,?)");
 			statement.setInt(1, _owner.getObjectId());
 			statement.setInt(2, shortcut.getSlot());
 			statement.setInt(3, shortcut.getPage());
@@ -104,7 +100,6 @@ public class ShortCuts
 			statement.setInt(6, shortcut.getLevel());
 			statement.setInt(7, _owner.getClassIndex());
 			statement.execute();
-			statement.close();
 		}
 		catch (Exception e)
 		{
@@ -162,15 +157,14 @@ public class ShortCuts
 	 */
 	private void deleteShortCutFromDb(L2ShortCut shortcut)
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement statement = con.prepareStatement("DELETE FROM character_shortcuts WHERE charId=? AND slot=? AND page=? AND class_index=?"))
 		{
-			PreparedStatement statement = con.prepareStatement("DELETE FROM character_shortcuts WHERE charId=? AND slot=? AND page=? AND class_index=?");
 			statement.setInt(1, _owner.getObjectId());
 			statement.setInt(2, shortcut.getSlot());
 			statement.setInt(3, shortcut.getPage());
 			statement.setInt(4, _owner.getClassIndex());
 			statement.execute();
-			statement.close();
 		}
 		catch (Exception e)
 		{
@@ -181,28 +175,25 @@ public class ShortCuts
 	public void restore()
 	{
 		_shortCuts.clear();
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement statement = con.prepareStatement("SELECT charId, slot, page, type, shortcut_id, level FROM character_shortcuts WHERE charId=? AND class_index=?"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT charId, slot, page, type, shortcut_id, level FROM character_shortcuts WHERE charId=? AND class_index=?");
 			statement.setInt(1, _owner.getObjectId());
 			statement.setInt(2, _owner.getClassIndex());
 			
-			ResultSet rset = statement.executeQuery();
-			
-			while (rset.next())
+			try (ResultSet rset = statement.executeQuery())
 			{
-				int slot = rset.getInt("slot");
-				int page = rset.getInt("page");
-				int type = rset.getInt("type");
-				int id = rset.getInt("shortcut_id");
-				int level = rset.getInt("level");
-				
-				L2ShortCut sc = new L2ShortCut(slot, page, type, id, level, 1);
-				_shortCuts.put(slot + (page * MAX_SHORTCUTS_PER_BAR), sc);
+				while (rset.next())
+				{
+					int slot = rset.getInt("slot");
+					int page = rset.getInt("page");
+					int type = rset.getInt("type");
+					int id = rset.getInt("shortcut_id");
+					int level = rset.getInt("level");
+					
+					_shortCuts.put(slot + (page * MAX_SHORTCUTS_PER_BAR), new L2ShortCut(slot, page, type, id, level, 1));
+				}
 			}
-			
-			rset.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{

+ 179 - 203
L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java

@@ -112,7 +112,7 @@ 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.L2Macro;
+import com.l2jserver.gameserver.model.Macro;
 import com.l2jserver.gameserver.model.L2ManufactureItem;
 import com.l2jserver.gameserver.model.L2Object;
 import com.l2jserver.gameserver.model.L2Party;
@@ -1809,7 +1809,7 @@ public final class L2PcInstance extends L2Playable
 	/**
 	 * @param macro the macro to add to this L2PcInstance.
 	 */
-	public void registerMacro(L2Macro macro)
+	public void registerMacro(Macro macro)
 	{
 		_macros.registerMacro(macro);
 	}
@@ -7743,46 +7743,45 @@ public final class L2PcInstance extends L2Playable
 	 */
 	private void restoreRecipeBook(boolean loadCommon)
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		final String sql = loadCommon ? "SELECT id, type, classIndex FROM character_recipebook WHERE charId=?" : "SELECT id FROM character_recipebook WHERE charId=? AND classIndex=? AND type = 1";
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement statement = con.prepareStatement(sql))
 		{
-			String sql = loadCommon ? "SELECT id, type, classIndex FROM character_recipebook WHERE charId=?" : "SELECT id FROM character_recipebook WHERE charId=? AND classIndex=? AND type = 1";
-			PreparedStatement statement = con.prepareStatement(sql);
 			statement.setInt(1, getObjectId());
 			if (!loadCommon)
 			{
 				statement.setInt(2, _classIndex);
 			}
-			ResultSet rset = statement.executeQuery();
-			
-			_dwarvenRecipeBook.clear();
 			
-			L2RecipeList recipe;
-			RecipeData rd = RecipeData.getInstance();
-			while (rset.next())
+			try (ResultSet rset = statement.executeQuery())
 			{
-				recipe = rd.getRecipeList(rset.getInt("id"));
-				if (loadCommon)
+				_dwarvenRecipeBook.clear();
+				
+				L2RecipeList recipe;
+				RecipeData rd = RecipeData.getInstance();
+				while (rset.next())
 				{
-					if (rset.getInt(2) == 1)
+					recipe = rd.getRecipeList(rset.getInt("id"));
+					if (loadCommon)
 					{
-						if (rset.getInt(3) == _classIndex)
+						if (rset.getInt(2) == 1)
 						{
-							registerDwarvenRecipeList(recipe, false);
+							if (rset.getInt(3) == _classIndex)
+							{
+								registerDwarvenRecipeList(recipe, false);
+							}
+						}
+						else
+						{
+							registerCommonRecipeList(recipe, false);
 						}
 					}
 					else
 					{
-						registerCommonRecipeList(recipe, false);
+						registerDwarvenRecipeList(recipe, false);
 					}
 				}
-				else
-				{
-					registerDwarvenRecipeList(recipe, false);
-				}
 			}
-			
-			rset.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{
@@ -7797,22 +7796,22 @@ public final class L2PcInstance extends L2Playable
 	
 	private void loadPremiumItemList()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		final String sql = "SELECT itemNum, itemId, itemCount, itemSender FROM character_premium_items WHERE charId=?";
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement statement = con.prepareStatement(sql))
 		{
-			String sql = "SELECT itemNum, itemId, itemCount, itemSender FROM character_premium_items WHERE charId=?";
-			PreparedStatement statement = con.prepareStatement(sql);
 			statement.setInt(1, getObjectId());
-			ResultSet rset = statement.executeQuery();
-			while (rset.next())
+			try (ResultSet rset = statement.executeQuery())
 			{
-				int itemNum = rset.getInt("itemNum");
-				int itemId = rset.getInt("itemId");
-				long itemCount = rset.getLong("itemCount");
-				String itemSender = rset.getString("itemSender");
-				_premiumItems.put(itemNum, new L2PremiumItem(itemId, itemCount, itemSender));
+				while (rset.next())
+				{
+					int itemNum = rset.getInt("itemNum");
+					int itemId = rset.getInt("itemId");
+					long itemCount = rset.getLong("itemCount");
+					String itemSender = rset.getString("itemSender");
+					_premiumItems.put(itemNum, new L2PremiumItem(itemId, itemCount, itemSender));
+				}
 			}
-			rset.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{
@@ -7891,16 +7890,13 @@ public final class L2PcInstance extends L2Playable
 	
 	private void storeCharBase()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		// Get the exp, level, and sp of base class to store in base table
+		long exp = getStat().getBaseExp();
+		int level = getStat().getBaseLevel();
+		int sp = getStat().getBaseSp();
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement statement = con.prepareStatement(UPDATE_CHARACTER))
 		{
-			// Get the exp, level, and sp of base class to store in base table
-			long exp = getStat().getBaseExp();
-			int level = getStat().getBaseLevel();
-			int sp = getStat().getBaseSp();
-			
-			// Update base class
-			PreparedStatement statement = con.prepareStatement(UPDATE_CHARACTER);
-			
 			statement.setInt(1, level);
 			statement.setInt(2, getMaxHp());
 			statement.setDouble(3, getCurrentHp());
@@ -7937,7 +7933,6 @@ public final class L2PcInstance extends L2Playable
 			statement.setInt(34, getBaseClass());
 			
 			long totalOnlineTime = _onlineTime;
-			
 			if (_onlineBeginTime > 0)
 			{
 				totalOnlineTime += (System.currentTimeMillis() - _onlineBeginTime) / 1000;
@@ -7961,7 +7956,6 @@ public final class L2PcInstance extends L2Playable
 			statement.setInt(50, getObjectId());
 			
 			statement.execute();
-			statement.close();
 		}
 		catch (Exception e)
 		{
@@ -8006,24 +8000,20 @@ public final class L2PcInstance extends L2Playable
 			return;
 		}
 		
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement delete = con.prepareStatement(DELETE_SKILL_SAVE);
+			PreparedStatement statement = con.prepareStatement(ADD_SKILL_SAVE);)
 		{
 			// Delete all current stored effects for char to avoid dupe
-			PreparedStatement statement = con.prepareStatement(DELETE_SKILL_SAVE);
-			
-			statement.setInt(1, getObjectId());
-			statement.setInt(2, getClassIndex());
-			statement.execute();
-			statement.close();
+			delete.setInt(1, getObjectId());
+			delete.setInt(2, getClassIndex());
+			delete.execute();
 			
 			int buff_index = 0;
-			
 			final List<Integer> storedSkills = new ArrayList<>();
 			
 			// Store all effect data along with calulated remaining
 			// reuse delays for matching skills. 'restore_type'= 0.
-			statement = con.prepareStatement(ADD_SKILL_SAVE);
-			
 			if (storeEffects)
 			{
 				for (L2Effect effect : getAllEffects())
@@ -8112,7 +8102,6 @@ public final class L2PcInstance extends L2Playable
 					statement.execute();
 				}
 			}
-			statement.close();
 		}
 		catch (Exception e)
 		{
@@ -8315,39 +8304,38 @@ public final class L2PcInstance extends L2Playable
 			// Retrieve all skills of this L2PcInstance from the database
 			statement.setInt(1, getObjectId());
 			statement.setInt(2, getClassIndex());
-			final ResultSet rset = statement.executeQuery();
-			
-			// Go though the recordset of this SQL query
-			while (rset.next())
+			try (ResultSet rset = statement.executeQuery())
 			{
-				final int id = rset.getInt("skill_id");
-				final int level = rset.getInt("skill_level");
-				
-				// Create a L2Skill object for each record
-				final L2Skill skill = SkillTable.getInstance().getInfo(id, level);
-				
-				if (skill == null)
-				{
-					_log.warning("Skipped null skill Id: " + id + " Level: " + level + " while restoring player skills for playerObjId: " + getObjectId());
-					continue;
-				}
-				
-				// Add the L2Skill object to the L2Character _skills and its Func objects to the calculator set of the L2Character
-				addSkill(skill);
-				
-				if (Config.SKILL_CHECK_ENABLE && (!canOverrideCond(PcCondOverride.SKILL_CONDITIONS) || Config.SKILL_CHECK_GM))
+				while (rset.next())
 				{
-					if (!SkillTreesData.getInstance().isSkillAllowed(this, skill))
+					final int id = rset.getInt("skill_id");
+					final int level = rset.getInt("skill_level");
+					
+					// Create a L2Skill object for each record
+					final L2Skill skill = SkillTable.getInstance().getInfo(id, level);
+					
+					if (skill == null)
+					{
+						_log.warning("Skipped null skill Id: " + id + " Level: " + level + " while restoring player skills for playerObjId: " + getObjectId());
+						continue;
+					}
+					
+					// Add the L2Skill object to the L2Character _skills and its Func objects to the calculator set of the L2Character
+					addSkill(skill);
+					
+					if (Config.SKILL_CHECK_ENABLE && (!canOverrideCond(PcCondOverride.SKILL_CONDITIONS) || Config.SKILL_CHECK_GM))
 					{
-						Util.handleIllegalPlayerAction(this, "Player " + getName() + " has invalid skill " + skill.getName() + " (" + skill.getId() + "/" + skill.getLevel() + "), class:" + ClassListData.getInstance().getClass(getClassId()).getClassName(), 1);
-						if (Config.SKILL_CHECK_REMOVE)
+						if (!SkillTreesData.getInstance().isSkillAllowed(this, skill))
 						{
-							removeSkill(skill);
+							Util.handleIllegalPlayerAction(this, "Player " + getName() + " has invalid skill " + skill.getName() + " (" + skill.getId() + "/" + skill.getLevel() + "), class:" + ClassListData.getInstance().getClass(getClassId()).getClassName(), 1);
+							if (Config.SKILL_CHECK_REMOVE)
+							{
+								removeSkill(skill);
+							}
 						}
 					}
 				}
 			}
-			rset.close();
 		}
 		catch (Exception e)
 		{
@@ -8425,11 +8413,11 @@ public final class L2PcInstance extends L2Playable
 				}
 			}
 			// Remove previously restored skills
-			try (PreparedStatement del = con.prepareStatement(DELETE_SKILL_SAVE))
+			try (PreparedStatement delelete = con.prepareStatement(DELETE_SKILL_SAVE))
 			{
-				del.setInt(1, getObjectId());
-				del.setInt(2, getClassIndex());
-				del.executeUpdate();
+				delelete.setInt(1, getObjectId());
+				delelete.setInt(2, getClassIndex());
+				delelete.executeUpdate();
 			}
 		}
 		catch (Exception e)
@@ -8443,61 +8431,60 @@ public final class L2PcInstance extends L2Playable
 	 */
 	private void restoreItemReuse()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
-		{
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
 			PreparedStatement statement = con.prepareStatement(RESTORE_ITEM_REUSE_SAVE);
+			PreparedStatement delelete = con.prepareStatement(DELETE_ITEM_REUSE_SAVE);)
+		{
 			statement.setInt(1, getObjectId());
-			final ResultSet rset = statement.executeQuery();
-			int itemId;
-			@SuppressWarnings("unused")
-			int itemObjId;
-			long reuseDelay;
-			long systime;
-			boolean isInInventory;
-			long remainingTime;
-			while (rset.next())
-			{
-				itemId = rset.getInt("itemId");
-				itemObjId = rset.getInt("itemObjId");
-				reuseDelay = rset.getLong("reuseDelay");
-				systime = rset.getLong("systime");
-				isInInventory = true;
-				
-				// Using item Id
-				L2ItemInstance item = getInventory().getItemByItemId(itemId);
-				if (item == null)
-				{
-					item = getWarehouse().getItemByItemId(itemId);
-					isInInventory = false;
-				}
-				
-				if ((item != null) && (item.getItemId() == itemId) && (item.getReuseDelay() > 0))
+			try (ResultSet rset = statement.executeQuery())
+			{
+				int itemId;
+				@SuppressWarnings("unused")
+				int itemObjId;
+				long reuseDelay;
+				long systime;
+				boolean isInInventory;
+				long remainingTime;
+				while (rset.next())
 				{
-					remainingTime = systime - System.currentTimeMillis();
-					// Hardcoded to 10 seconds.
-					if (remainingTime > 10)
+					itemId = rset.getInt("itemId");
+					itemObjId = rset.getInt("itemObjId");
+					reuseDelay = rset.getLong("reuseDelay");
+					systime = rset.getLong("systime");
+					isInInventory = true;
+					
+					// Using item Id
+					L2ItemInstance item = getInventory().getItemByItemId(itemId);
+					if (item == null)
 					{
-						addTimeStampItem(item, reuseDelay, systime);
-						
-						if (isInInventory && item.isEtcItem())
+						item = getWarehouse().getItemByItemId(itemId);
+						isInInventory = false;
+					}
+					
+					if ((item != null) && (item.getItemId() == itemId) && (item.getReuseDelay() > 0))
+					{
+						remainingTime = systime - System.currentTimeMillis();
+						// Hardcoded to 10 seconds.
+						if (remainingTime > 10)
 						{
-							final int group = item.getSharedReuseGroup();
-							if (group > 0)
+							addTimeStampItem(item, reuseDelay, systime);
+							
+							if (isInInventory && item.isEtcItem())
 							{
-								sendPacket(new ExUseSharedGroupItem(itemId, group, (int) remainingTime, (int) reuseDelay));
+								final int group = item.getSharedReuseGroup();
+								if (group > 0)
+								{
+									sendPacket(new ExUseSharedGroupItem(itemId, group, (int) remainingTime, (int) reuseDelay));
+								}
 							}
 						}
 					}
 				}
 			}
 			
-			rset.close();
-			statement.close();
-			
-			statement = con.prepareStatement(DELETE_ITEM_REUSE_SAVE);
-			statement.setInt(1, getObjectId());
-			statement.executeUpdate();
-			statement.close();
+			// Delete item reuse.
+			delelete.setInt(1, getObjectId());
+			delelete.executeUpdate();
 		}
 		catch (Exception e)
 		{
@@ -8510,45 +8497,43 @@ public final class L2PcInstance extends L2Playable
 	 */
 	private void restoreHenna()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		for (int i = 0; i < 3; i++)
+		{
+			_henna[i] = null;
+		}
+		
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement statement = con.prepareStatement(RESTORE_CHAR_HENNAS))
 		{
-			PreparedStatement statement = con.prepareStatement(RESTORE_CHAR_HENNAS);
 			statement.setInt(1, getObjectId());
 			statement.setInt(2, getClassIndex());
-			ResultSet rset = statement.executeQuery();
-			
-			for (int i = 0; i < 3; i++)
-			{
-				_henna[i] = null;
-			}
-			
-			int slot;
-			int symbolId;
-			while (rset.next())
+			try (ResultSet rset = statement.executeQuery())
 			{
-				slot = rset.getInt("slot");
-				if ((slot < 1) || (slot > 3))
-				{
-					continue;
-				}
-				
-				symbolId = rset.getInt("symbol_id");
-				if (symbolId == 0)
+				int slot;
+				int symbolId;
+				while (rset.next())
 				{
-					continue;
+					slot = rset.getInt("slot");
+					if ((slot < 1) || (slot > 3))
+					{
+						continue;
+					}
+					
+					symbolId = rset.getInt("symbol_id");
+					if (symbolId == 0)
+					{
+						continue;
+					}
+					_henna[slot - 1] = HennaData.getInstance().getHenna(symbolId);
 				}
-				_henna[slot - 1] = HennaData.getInstance().getHenna(symbolId);
 			}
-			
-			rset.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{
 			_log.log(Level.SEVERE, "Failed restoing character " + this + " hennas.", e);
 		}
 		
-		// Calculate Henna modifiers of this L2PcInstance
+		// Calculate henna modifiers of this player.
 		recalcHennaStats();
 	}
 	
@@ -10654,12 +10639,12 @@ public final class L2PcInstance extends L2Playable
 	}
 	
 	/**
-	 * 1. Completely erase all existance of the subClass linked to the classIndex.<BR>
-	 * 2. Send over the newClassId to addSubClass()to create a new instance on this classIndex.<BR>
-	 * 3. Upon Exception, revert the player to their BaseClass to avoid further problems.<BR>
-	 * @param classIndex
-	 * @param newClassId
-	 * @return boolean subclassAdded
+	 * 1. Completely erase all existance of the subClass linked to the classIndex.<br>
+	 * 2. Send over the newClassId to addSubClass() to create a new instance on this classIndex.<br>
+	 * 3. Upon Exception, revert the player to their BaseClass to avoid further problems.
+	 * @param classIndex the class index to delete
+	 * @param newClassId the new class Id
+	 * @return {@code true} if the sub-class was modified, {@code false} otherwise
 	 */
 	public boolean modifySubClass(int classIndex, int newClassId)
 	{
@@ -10670,42 +10655,37 @@ public final class L2PcInstance extends L2Playable
 		
 		try
 		{
-			try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+			try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+				PreparedStatement deleteHennas = con.prepareStatement(DELETE_CHAR_HENNAS);
+				PreparedStatement deleteShortcuts = con.prepareStatement(DELETE_CHAR_SHORTCUTS);
+				PreparedStatement deleteSkillReuse = con.prepareStatement(DELETE_SKILL_SAVE);
+				PreparedStatement deleteSkills = con.prepareStatement(DELETE_CHAR_SKILLS);
+				PreparedStatement deleteSubclass = con.prepareStatement(DELETE_CHAR_SUBCLASS))
 			{
 				// Remove all henna info stored for this sub-class.
-				PreparedStatement statement = con.prepareStatement(DELETE_CHAR_HENNAS);
-				statement.setInt(1, getObjectId());
-				statement.setInt(2, classIndex);
-				statement.execute();
-				statement.close();
+				deleteHennas.setInt(1, getObjectId());
+				deleteHennas.setInt(2, classIndex);
+				deleteHennas.execute();
 				
 				// Remove all shortcuts info stored for this sub-class.
-				statement = con.prepareStatement(DELETE_CHAR_SHORTCUTS);
-				statement.setInt(1, getObjectId());
-				statement.setInt(2, classIndex);
-				statement.execute();
-				statement.close();
+				deleteShortcuts.setInt(1, getObjectId());
+				deleteShortcuts.setInt(2, classIndex);
+				deleteShortcuts.execute();
 				
 				// Remove all effects info stored for this sub-class.
-				statement = con.prepareStatement(DELETE_SKILL_SAVE);
-				statement.setInt(1, getObjectId());
-				statement.setInt(2, classIndex);
-				statement.execute();
-				statement.close();
+				deleteSkillReuse.setInt(1, getObjectId());
+				deleteSkillReuse.setInt(2, classIndex);
+				deleteSkillReuse.execute();
 				
 				// Remove all skill info stored for this sub-class.
-				statement = con.prepareStatement(DELETE_CHAR_SKILLS);
-				statement.setInt(1, getObjectId());
-				statement.setInt(2, classIndex);
-				statement.execute();
-				statement.close();
+				deleteSkills.setInt(1, getObjectId());
+				deleteSkills.setInt(2, classIndex);
+				deleteSkills.execute();
 				
 				// Remove all basic info stored about this sub-class.
-				statement = con.prepareStatement(DELETE_CHAR_SUBCLASS);
-				statement.setInt(1, getObjectId());
-				statement.setInt(2, classIndex);
-				statement.execute();
-				statement.close();
+				deleteSubclass.setInt(1, getObjectId());
+				deleteSubclass.setInt(2, classIndex);
+				deleteSubclass.execute();
 			}
 			catch (Exception e)
 			{
@@ -10715,7 +10695,6 @@ public final class L2PcInstance extends L2Playable
 				getSubClasses().remove(classIndex);
 				return false;
 			}
-			
 			getSubClasses().remove(classIndex);
 		}
 		finally
@@ -14069,26 +14048,23 @@ public final class L2PcInstance extends L2Playable
 	{
 		_friendList.clear();
 		
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		final String sqlQuery = "SELECT friendId FROM character_friends WHERE charId=? AND relation=0";
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement statement = con.prepareStatement(sqlQuery))
 		{
-			String sqlQuery = "SELECT friendId FROM character_friends WHERE charId=? AND relation=0";
-			PreparedStatement statement = con.prepareStatement(sqlQuery);
 			statement.setInt(1, getObjectId());
-			ResultSet rset = statement.executeQuery();
-			
-			int friendId;
-			while (rset.next())
+			try (ResultSet rset = statement.executeQuery())
 			{
-				friendId = rset.getInt("friendId");
-				if (friendId == getObjectId())
+				while (rset.next())
 				{
-					continue;
+					int friendId = rset.getInt("friendId");
+					if (friendId == getObjectId())
+					{
+						continue;
+					}
+					_friendList.add(friendId);
 				}
-				_friendList.add(friendId);
 			}
-			
-			rset.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{

+ 47 - 52
L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/instance/L2PetInstance.java

@@ -894,66 +894,62 @@ public class L2PetInstance extends L2Summon
 	
 	private static L2PetInstance restore(L2ItemInstance control, L2NpcTemplate template, L2PcInstance owner)
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement statement = con.prepareStatement("SELECT item_obj_id, name, level, curHp, curMp, exp, sp, fed FROM pets WHERE item_obj_id=?"))
 		{
 			L2PetInstance pet;
-			PreparedStatement statement = con.prepareStatement("SELECT item_obj_id, name, level, curHp, curMp, exp, sp, fed FROM pets WHERE item_obj_id=?");
 			statement.setInt(1, control.getObjectId());
-			ResultSet rset = statement.executeQuery();
-			final int id = IdFactory.getInstance().getNextId();
-			if (!rset.next())
+			try (ResultSet rset = statement.executeQuery())
 			{
+				final int id = IdFactory.getInstance().getNextId();
+				if (!rset.next())
+				{
+					if (template.isType("L2BabyPet"))
+					{
+						pet = new L2BabyPetInstance(id, template, owner, control);
+					}
+					else
+					{
+						pet = new L2PetInstance(id, template, owner, control);
+					}
+					return pet;
+				}
+				
 				if (template.isType("L2BabyPet"))
 				{
-					pet = new L2BabyPetInstance(id, template, owner, control);
+					pet = new L2BabyPetInstance(id, template, owner, control, rset.getByte("level"));
 				}
 				else
 				{
-					pet = new L2PetInstance(id, template, owner, control);
+					pet = new L2PetInstance(id, template, owner, control, rset.getByte("level"));
 				}
 				
-				rset.close();
-				statement.close();
-				return pet;
-			}
-			
-			if (template.isType("L2BabyPet"))
-			{
-				pet = new L2BabyPetInstance(id, template, owner, control, rset.getByte("level"));
-			}
-			else
-			{
-				pet = new L2PetInstance(id, template, owner, control, rset.getByte("level"));
-			}
-			
-			pet._respawned = true;
-			pet.setName(rset.getString("name"));
-			
-			long exp = rset.getLong("exp");
-			L2PetLevelData info = PetDataTable.getInstance().getPetLevelData(pet.getNpcId(), pet.getLevel());
-			// DS: update experience based by level
-			// Avoiding pet delevels due to exp per level values changed.
-			if ((info != null) && (exp < info.getPetMaxExp()))
-			{
-				exp = info.getPetMaxExp();
-			}
-			
-			pet.getStat().setExp(exp);
-			pet.getStat().setSp(rset.getInt("sp"));
-			
-			pet.getStatus().setCurrentHp(rset.getInt("curHp"));
-			pet.getStatus().setCurrentMp(rset.getInt("curMp"));
-			pet.getStatus().setCurrentCp(pet.getMaxCp());
-			if (rset.getDouble("curHp") < 1)
-			{
-				pet.setIsDead(true);
-				pet.stopHpMpRegeneration();
+				pet._respawned = true;
+				pet.setName(rset.getString("name"));
+				
+				long exp = rset.getLong("exp");
+				L2PetLevelData info = PetDataTable.getInstance().getPetLevelData(pet.getNpcId(), pet.getLevel());
+				// DS: update experience based by level
+				// Avoiding pet delevels due to exp per level values changed.
+				if ((info != null) && (exp < info.getPetMaxExp()))
+				{
+					exp = info.getPetMaxExp();
+				}
+				
+				pet.getStat().setExp(exp);
+				pet.getStat().setSp(rset.getInt("sp"));
+				
+				pet.getStatus().setCurrentHp(rset.getInt("curHp"));
+				pet.getStatus().setCurrentMp(rset.getInt("curMp"));
+				pet.getStatus().setCurrentCp(pet.getMaxCp());
+				if (rset.getDouble("curHp") < 1)
+				{
+					pet.setIsDead(true);
+					pet.stopHpMpRegeneration();
+				}
+				
+				pet.setCurrentFed(rset.getInt("fed"));
 			}
-			
-			pet.setCurrentFed(rset.getInt("fed"));
-			
-			rset.close();
-			statement.close();
 			return pet;
 		}
 		catch (Exception e)
@@ -1010,9 +1006,9 @@ public class L2PetInstance extends L2Summon
 			req = "UPDATE pets SET name=?,level=?,curHp=?,curMp=?,exp=?,sp=?,fed=?,ownerId=?,restore=? " + "WHERE item_obj_id = ?";
 		}
 		
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement statement = con.prepareStatement(req))
 		{
-			PreparedStatement statement = con.prepareStatement(req);
 			statement.setString(1, getName());
 			statement.setInt(2, getStat().getLevel());
 			statement.setDouble(3, getStatus().getCurrentHp());
@@ -1023,9 +1019,8 @@ public class L2PetInstance extends L2Summon
 			statement.setInt(8, getOwner().getObjectId());
 			statement.setString(9, String.valueOf(_restoreSummon)); // True restores pet on login
 			statement.setInt(10, getControlObjectId());
-			
 			statement.executeUpdate();
-			statement.close();
+			
 			_respawned = true;
 			
 			if (_restoreSummon)

+ 34 - 33
L2J_Server_BETA/java/com/l2jserver/gameserver/model/entity/Castle.java

@@ -915,18 +915,19 @@ public class Castle
 		
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			// NEED TO REMOVE HAS CASTLE FLAG FROM CLAN_DATA
-			// SHOULD BE CHECKED FROM CASTLE TABLE
-			PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET hasCastle = 0 WHERE hasCastle = ?");
-			statement.setInt(1, getCastleId());
-			statement.execute();
-			statement.close();
+			// Need to remove has castle flag from clan_data, should be checked from castle table.
+			try (PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET hasCastle = 0 WHERE hasCastle = ?"))
+			{
+				ps.setInt(1, getCastleId());
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("UPDATE clan_data SET hasCastle = ? WHERE clan_id = ?");
-			statement.setInt(1, getCastleId());
-			statement.setInt(2, getOwnerId());
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET hasCastle = ? WHERE clan_id = ?"))
+			{
+				ps.setInt(1, getCastleId());
+				ps.setInt(2, getOwnerId());
+				ps.execute();
+			}
 			
 			// Announce to clan members
 			if (clan != null)
@@ -1202,13 +1203,12 @@ public class Castle
 	// save manor production data for specified period
 	public void saveSeedData(int period)
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement(CASTLE_MANOR_DELETE_PRODUCTION_PERIOD))
 		{
-			PreparedStatement statement = con.prepareStatement(CASTLE_MANOR_DELETE_PRODUCTION_PERIOD);
-			statement.setInt(1, getCastleId());
-			statement.setInt(2, period);
-			statement.execute();
-			statement.close();
+			ps.setInt(1, getCastleId());
+			ps.setInt(2, period);
+			ps.execute();
 			
 			List<SeedProduction> prod = null;
 			prod = getSeedProduction(period);
@@ -1230,9 +1230,10 @@ public class Castle
 					{
 						query.append(',').append(values[i]);
 					}
-					statement = con.prepareStatement(query.toString());
-					statement.execute();
-					statement.close();
+					try (PreparedStatement insert = con.prepareStatement(query.toString()))
+					{
+						insert.execute();
+					}
 				}
 			}
 		}
@@ -1309,13 +1310,12 @@ public class Castle
 	// save crop procure data for specified period
 	public void saveCropData(int period)
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement(CASTLE_MANOR_DELETE_PROCURE_PERIOD))
 		{
-			PreparedStatement statement = con.prepareStatement(CASTLE_MANOR_DELETE_PROCURE_PERIOD);
-			statement.setInt(1, getCastleId());
-			statement.setInt(2, period);
-			statement.execute();
-			statement.close();
+			ps.setInt(1, getCastleId());
+			ps.setInt(2, period);
+			ps.execute();
 			
 			List<CropProcure> proc = null;
 			proc = getCropProcure(period);
@@ -1339,9 +1339,10 @@ public class Castle
 						query.append(',');
 						query.append(values[i]);
 					}
-					statement = con.prepareStatement(query.toString());
-					statement.execute();
-					statement.close();
+					try (PreparedStatement insert = con.prepareStatement(query.toString()))
+					{
+						insert.execute();
+					}
 				}
 			}
 		}
@@ -1544,11 +1545,11 @@ public class Castle
 		_ticketBuyCount = count;
 		
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = con.prepareStatement("UPDATE castle SET ticketBuyCount = ? WHERE id = ?"))
+			PreparedStatement ps = con.prepareStatement("UPDATE castle SET ticketBuyCount = ? WHERE id = ?"))
 		{
-			statement.setInt(1, _ticketBuyCount);
-			statement.setInt(2, _castleId);
-			statement.execute();
+			ps.setInt(1, _ticketBuyCount);
+			ps.setInt(2, _castleId);
+			ps.execute();
 		}
 		catch (Exception e)
 		{

+ 229 - 245
L2J_Server_BETA/java/com/l2jserver/gameserver/model/entity/Hero.java

@@ -22,6 +22,7 @@ import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Statement;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Collections;
@@ -115,12 +116,12 @@ public class Hero
 		_herodiary.clear();
 		_heroMessage.clear();
 		
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement s = con.createStatement();
+			ResultSet rset = s.executeQuery(GET_HEROES);
+			PreparedStatement ps = con.prepareStatement(GET_CLAN_ALLY);
+			ResultSet rset2 = s.executeQuery(GET_ALL_HEROES))
 		{
-			PreparedStatement statement = con.prepareStatement(GET_HEROES);
-			ResultSet rset = statement.executeQuery();
-			PreparedStatement statement2 = con.prepareStatement(GET_CLAN_ALLY);
-			
 			while (rset.next())
 			{
 				StatsSet hero = new StatsSet();
@@ -134,34 +135,24 @@ public class Hero
 				loadDiary(charId);
 				loadMessage(charId);
 				
-				processHeros(statement2, charId, hero);
+				processHeros(ps, charId, hero);
 				
 				_heroes.put(charId, hero);
 			}
 			
-			rset.close();
-			statement.close();
-			
-			statement = con.prepareStatement(GET_ALL_HEROES);
-			rset = statement.executeQuery();
-			
-			while (rset.next())
+			while (rset2.next())
 			{
 				StatsSet hero = new StatsSet();
-				int charId = rset.getInt(Olympiad.CHAR_ID);
-				hero.set(Olympiad.CHAR_NAME, rset.getString(Olympiad.CHAR_NAME));
-				hero.set(Olympiad.CLASS_ID, rset.getInt(Olympiad.CLASS_ID));
-				hero.set(COUNT, rset.getInt(COUNT));
-				hero.set(PLAYED, rset.getInt(PLAYED));
+				int charId = rset2.getInt(Olympiad.CHAR_ID);
+				hero.set(Olympiad.CHAR_NAME, rset2.getString(Olympiad.CHAR_NAME));
+				hero.set(Olympiad.CLASS_ID, rset2.getInt(Olympiad.CLASS_ID));
+				hero.set(COUNT, rset2.getInt(COUNT));
+				hero.set(PLAYED, rset2.getInt(PLAYED));
 				
-				processHeros(statement2, charId, hero);
+				processHeros(ps, charId, hero);
 				
 				_completeHeroes.put(charId, hero);
 			}
-			
-			statement2.close();
-			rset.close();
-			statement.close();
 		}
 		catch (SQLException e)
 		{
@@ -175,32 +166,33 @@ public class Hero
 	private void processHeros(PreparedStatement ps, int charId, StatsSet hero) throws SQLException
 	{
 		ps.setInt(1, charId);
-		ResultSet rs = ps.executeQuery();
-		if (rs.next())
+		try (ResultSet rs = ps.executeQuery())
 		{
-			int clanId = rs.getInt("clanid");
-			int allyId = rs.getInt("allyId");
-			String clanName = "";
-			String allyName = "";
-			int clanCrest = 0;
-			int allyCrest = 0;
-			if (clanId > 0)
+			if (rs.next())
 			{
-				clanName = ClanTable.getInstance().getClan(clanId).getName();
-				clanCrest = ClanTable.getInstance().getClan(clanId).getCrestId();
-				if (allyId > 0)
+				int clanId = rs.getInt("clanid");
+				int allyId = rs.getInt("allyId");
+				String clanName = "";
+				String allyName = "";
+				int clanCrest = 0;
+				int allyCrest = 0;
+				if (clanId > 0)
 				{
-					allyName = ClanTable.getInstance().getClan(clanId).getAllyName();
-					allyCrest = ClanTable.getInstance().getClan(clanId).getAllyCrestId();
+					clanName = ClanTable.getInstance().getClan(clanId).getName();
+					clanCrest = ClanTable.getInstance().getClan(clanId).getCrestId();
+					if (allyId > 0)
+					{
+						allyName = ClanTable.getInstance().getClan(clanId).getAllyName();
+						allyCrest = ClanTable.getInstance().getClan(clanId).getAllyCrestId();
+					}
 				}
+				hero.set(CLAN_CREST, clanCrest);
+				hero.set(CLAN_NAME, clanName);
+				hero.set(ALLY_CREST, allyCrest);
+				hero.set(ALLY_NAME, allyName);
 			}
-			hero.set(CLAN_CREST, clanCrest);
-			hero.set(CLAN_NAME, clanName);
-			hero.set(ALLY_CREST, allyCrest);
-			hero.set(ALLY_NAME, allyName);
+			ps.clearParameters();
 		}
-		rs.close();
-		ps.clearParameters();
 	}
 	
 	private String calcFightTime(long FightTime)
@@ -219,17 +211,17 @@ public class Hero
 	 */
 	public void loadMessage(int charId)
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement statement = con.prepareStatement("SELECT message FROM heroes WHERE charId=?"))
 		{
-			String message = null;
-			PreparedStatement statement = con.prepareStatement("SELECT message FROM heroes WHERE charId=?");
 			statement.setInt(1, charId);
-			ResultSet rset = statement.executeQuery();
-			rset.next();
-			message = rset.getString("message");
-			_heroMessage.put(charId, message);
-			rset.close();
-			statement.close();
+			try (ResultSet rset = statement.executeQuery())
+			{
+				if (rset.next())
+				{
+					_heroMessage.put(charId, rset.getString("message"));
+				}
+			}
 		}
 		catch (SQLException e)
 		{
@@ -241,49 +233,47 @@ public class Hero
 	{
 		final List<StatsSet> _diary = new FastList<>();
 		int diaryentries = 0;
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement statement = con.prepareStatement("SELECT * FROM  heroes_diary WHERE charId=? ORDER BY time ASC"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT * FROM  heroes_diary WHERE charId=? ORDER BY time ASC");
 			statement.setInt(1, charId);
-			ResultSet rset = statement.executeQuery();
-			
-			while (rset.next())
+			try (ResultSet rset = statement.executeQuery())
 			{
-				StatsSet _diaryentry = new StatsSet();
-				
-				long time = rset.getLong("time");
-				int action = rset.getInt("action");
-				int param = rset.getInt("param");
-				
-				String date = (new SimpleDateFormat("yyyy-MM-dd HH")).format(new Date(time));
-				_diaryentry.set("date", date);
-				
-				if (action == ACTION_RAID_KILLED)
+				while (rset.next())
 				{
-					L2NpcTemplate template = NpcTable.getInstance().getTemplate(param);
-					if (template != null)
+					StatsSet _diaryentry = new StatsSet();
+					
+					long time = rset.getLong("time");
+					int action = rset.getInt("action");
+					int param = rset.getInt("param");
+					
+					String date = (new SimpleDateFormat("yyyy-MM-dd HH")).format(new Date(time));
+					_diaryentry.set("date", date);
+					
+					if (action == ACTION_RAID_KILLED)
 					{
-						_diaryentry.set("action", template.getName() + " was defeated");
+						L2NpcTemplate template = NpcTable.getInstance().getTemplate(param);
+						if (template != null)
+						{
+							_diaryentry.set("action", template.getName() + " was defeated");
+						}
 					}
-				}
-				else if (action == ACTION_HERO_GAINED)
-				{
-					_diaryentry.set("action", "Gained Hero status");
-				}
-				else if (action == ACTION_CASTLE_TAKEN)
-				{
-					Castle castle = CastleManager.getInstance().getCastleById(param);
-					if (castle != null)
+					else if (action == ACTION_HERO_GAINED)
 					{
-						_diaryentry.set("action", castle.getName() + " Castle was successfuly taken");
+						_diaryentry.set("action", "Gained Hero status");
 					}
+					else if (action == ACTION_CASTLE_TAKEN)
+					{
+						Castle castle = CastleManager.getInstance().getCastleById(param);
+						if (castle != null)
+						{
+							_diaryentry.set("action", castle.getName() + " Castle was successfuly taken");
+						}
+					}
+					_diary.add(_diaryentry);
+					diaryentries++;
 				}
-				_diary.add(_diaryentry);
-				diaryentries++;
 			}
-			rset.close();
-			statement.close();
-			
 			_herodiary.put(charId, _diary);
 			
 			_log.info("Hero System: Loaded " + diaryentries + " diary entries for Hero: " + CharNameTable.getInstance().getNameById(charId));
@@ -310,108 +300,107 @@ public class Hero
 		int _losses = 0;
 		int _draws = 0;
 		
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement statement = con.prepareStatement("SELECT * FROM olympiad_fights WHERE (charOneId=? OR charTwoId=?) AND start<? ORDER BY start ASC"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT * FROM olympiad_fights WHERE (charOneId=? OR charTwoId=?) AND start<? ORDER BY start ASC");
 			statement.setInt(1, charId);
 			statement.setInt(2, charId);
 			statement.setLong(3, from);
-			ResultSet rset = statement.executeQuery();
-			
-			int charOneId;
-			int charOneClass;
-			int charTwoId;
-			int charTwoClass;
-			int winner;
-			long start;
-			int time;
-			int classed;
-			while (rset.next())
+			try (ResultSet rset = statement.executeQuery())
 			{
-				charOneId = rset.getInt("charOneId");
-				charOneClass = rset.getInt("charOneClass");
-				charTwoId = rset.getInt("charTwoId");
-				charTwoClass = rset.getInt("charTwoClass");
-				winner = rset.getInt("winner");
-				start = rset.getLong("start");
-				time = rset.getInt("time");
-				classed = rset.getInt("classed");
-				
-				if (charId == charOneId)
+				int charOneId;
+				int charOneClass;
+				int charTwoId;
+				int charTwoClass;
+				int winner;
+				long start;
+				int time;
+				int classed;
+				while (rset.next())
 				{
-					String name = CharNameTable.getInstance().getNameById(charTwoId);
-					String cls = ClassListData.getInstance().getClass(charTwoClass).getClientCode();
-					if ((name != null) && (cls != null))
+					charOneId = rset.getInt("charOneId");
+					charOneClass = rset.getInt("charOneClass");
+					charTwoId = rset.getInt("charTwoId");
+					charTwoClass = rset.getInt("charTwoClass");
+					winner = rset.getInt("winner");
+					start = rset.getLong("start");
+					time = rset.getInt("time");
+					classed = rset.getInt("classed");
+					
+					if (charId == charOneId)
 					{
-						StatsSet fight = new StatsSet();
-						fight.set("oponent", name);
-						fight.set("oponentclass", cls);
-						
-						fight.set("time", calcFightTime(time));
-						String date = (new SimpleDateFormat("yyyy-MM-dd HH:mm")).format(new Date(start));
-						fight.set("start", date);
-						
-						fight.set("classed", classed);
-						if (winner == 1)
+						String name = CharNameTable.getInstance().getNameById(charTwoId);
+						String cls = ClassListData.getInstance().getClass(charTwoClass).getClientCode();
+						if ((name != null) && (cls != null))
 						{
-							fight.set("result", "<font color=\"00ff00\">victory</font>");
-							_victorys++;
-						}
-						else if (winner == 2)
-						{
-							fight.set("result", "<font color=\"ff0000\">loss</font>");
-							_losses++;
-						}
-						else if (winner == 0)
-						{
-							fight.set("result", "<font color=\"ffff00\">draw</font>");
-							_draws++;
+							StatsSet fight = new StatsSet();
+							fight.set("oponent", name);
+							fight.set("oponentclass", cls);
+							
+							fight.set("time", calcFightTime(time));
+							String date = (new SimpleDateFormat("yyyy-MM-dd HH:mm")).format(new Date(start));
+							fight.set("start", date);
+							
+							fight.set("classed", classed);
+							if (winner == 1)
+							{
+								fight.set("result", "<font color=\"00ff00\">victory</font>");
+								_victorys++;
+							}
+							else if (winner == 2)
+							{
+								fight.set("result", "<font color=\"ff0000\">loss</font>");
+								_losses++;
+							}
+							else if (winner == 0)
+							{
+								fight.set("result", "<font color=\"ffff00\">draw</font>");
+								_draws++;
+							}
+							
+							_fights.add(fight);
+							
+							numberoffights++;
 						}
-						
-						_fights.add(fight);
-						
-						numberoffights++;
 					}
-				}
-				else if (charId == charTwoId)
-				{
-					String name = CharNameTable.getInstance().getNameById(charOneId);
-					String cls = ClassListData.getInstance().getClass(charOneClass).getClientCode();
-					if ((name != null) && (cls != null))
+					else if (charId == charTwoId)
 					{
-						StatsSet fight = new StatsSet();
-						fight.set("oponent", name);
-						fight.set("oponentclass", cls);
-						
-						fight.set("time", calcFightTime(time));
-						String date = (new SimpleDateFormat("yyyy-MM-dd HH:mm")).format(new Date(start));
-						fight.set("start", date);
-						
-						fight.set("classed", classed);
-						if (winner == 1)
-						{
-							fight.set("result", "<font color=\"ff0000\">loss</font>");
-							_losses++;
-						}
-						else if (winner == 2)
+						String name = CharNameTable.getInstance().getNameById(charOneId);
+						String cls = ClassListData.getInstance().getClass(charOneClass).getClientCode();
+						if ((name != null) && (cls != null))
 						{
-							fight.set("result", "<font color=\"00ff00\">victory</font>");
-							_victorys++;
-						}
-						else if (winner == 0)
-						{
-							fight.set("result", "<font color=\"ffff00\">draw</font>");
-							_draws++;
+							StatsSet fight = new StatsSet();
+							fight.set("oponent", name);
+							fight.set("oponentclass", cls);
+							
+							fight.set("time", calcFightTime(time));
+							String date = (new SimpleDateFormat("yyyy-MM-dd HH:mm")).format(new Date(start));
+							fight.set("start", date);
+							
+							fight.set("classed", classed);
+							if (winner == 1)
+							{
+								fight.set("result", "<font color=\"ff0000\">loss</font>");
+								_losses++;
+							}
+							else if (winner == 2)
+							{
+								fight.set("result", "<font color=\"00ff00\">victory</font>");
+								_victorys++;
+							}
+							else if (winner == 0)
+							{
+								fight.set("result", "<font color=\"ffff00\">draw</font>");
+								_draws++;
+							}
+							
+							_fights.add(fight);
+							
+							numberoffights++;
 						}
-						
-						_fights.add(fight);
-						
-						numberoffights++;
 					}
 				}
 			}
-			rset.close();
-			statement.close();
 			
 			_herocountdata.set("victory", _victorys);
 			_herocountdata.set("draw", _draws);
@@ -756,30 +745,29 @@ public class Hero
 				loadDiary(charId);
 				_heroMessage.put(charId, "");
 				
-				try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+				try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+					PreparedStatement statement = con.prepareStatement(GET_CLAN_NAME))
 				{
-					PreparedStatement statement = con.prepareStatement(GET_CLAN_NAME);
 					statement.setInt(1, charId);
-					ResultSet rset = statement.executeQuery();
-					if (rset.next())
+					try (ResultSet rset = statement.executeQuery())
 					{
-						String clanName = rset.getString("clan_name");
-						if (clanName != null)
+						if (rset.next())
 						{
-							L2Clan clan = ClanTable.getInstance().getClanByName(clanName);
-							if (clan != null)
+							String clanName = rset.getString("clan_name");
+							if (clanName != null)
 							{
-								clan.addReputationScore(Config.HERO_POINTS, true);
-								SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.CLAN_MEMBER_C1_BECAME_HERO_AND_GAINED_S2_REPUTATION_POINTS);
-								sm.addString(CharNameTable.getInstance().getNameById(charId));
-								sm.addNumber(Config.HERO_POINTS);
-								clan.broadcastToOnlineMembers(sm);
+								L2Clan clan = ClanTable.getInstance().getClanByName(clanName);
+								if (clan != null)
+								{
+									clan.addReputationScore(Config.HERO_POINTS, true);
+									SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.CLAN_MEMBER_C1_BECAME_HERO_AND_GAINED_S2_REPUTATION_POINTS);
+									sm.addString(CharNameTable.getInstance().getNameById(charId));
+									sm.addNumber(Config.HERO_POINTS);
+									clan.broadcastToOnlineMembers(sm);
+								}
 							}
 						}
 					}
-					
-					rset.close();
-					statement.close();
 				}
 				catch (Exception e)
 				{
@@ -791,17 +779,14 @@ public class Hero
 	
 	public void updateHeroes(boolean setDefault)
 	{
-		// _herofights = new FastMap<Integer, List<StatsSet>>();
-		// _herocounts = new FastMap<Integer, StatsSet>();
-		
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			PreparedStatement statement;
 			if (setDefault)
 			{
-				statement = con.prepareStatement(UPDATE_ALL);
-				statement.execute();
-				statement.close();
+				try (PreparedStatement update_all = con.prepareStatement(UPDATE_ALL))
+				{
+					update_all.execute();
+				}
 			}
 			else
 			{
@@ -813,49 +798,50 @@ public class Hero
 					heroId = entry.getKey();
 					if (_completeHeroes.isEmpty() || !_completeHeroes.containsKey(heroId))
 					{
-						statement = con.prepareStatement(INSERT_HERO);
-						statement.setInt(1, heroId);
-						statement.setInt(2, hero.getInteger(Olympiad.CLASS_ID));
-						statement.setInt(3, hero.getInteger(COUNT));
-						statement.setInt(4, hero.getInteger(PLAYED));
-						statement.execute();
-						statement.close();
-						
-						statement = con.prepareStatement(GET_CLAN_ALLY);
-						statement.setInt(1, heroId);
-						ResultSet rset = statement.executeQuery();
+						try (PreparedStatement insert = con.prepareStatement(INSERT_HERO))
+						{
+							insert.setInt(1, heroId);
+							insert.setInt(2, hero.getInteger(Olympiad.CLASS_ID));
+							insert.setInt(3, hero.getInteger(COUNT));
+							insert.setInt(4, hero.getInteger(PLAYED));
+							insert.execute();
+							insert.close();
+						}
 						
-						if (rset.next())
+						try (PreparedStatement statement = con.prepareStatement(GET_CLAN_ALLY))
 						{
-							int clanId = rset.getInt("clanid");
-							int allyId = rset.getInt("allyId");
-							
-							String clanName = "";
-							String allyName = "";
-							int clanCrest = 0;
-							int allyCrest = 0;
-							
-							if (clanId > 0)
+							statement.setInt(1, heroId);
+							try (ResultSet rset = statement.executeQuery())
 							{
-								clanName = ClanTable.getInstance().getClan(clanId).getName();
-								clanCrest = ClanTable.getInstance().getClan(clanId).getCrestId();
-								
-								if (allyId > 0)
+								if (rset.next())
 								{
-									allyName = ClanTable.getInstance().getClan(clanId).getAllyName();
-									allyCrest = ClanTable.getInstance().getClan(clanId).getAllyCrestId();
+									int clanId = rset.getInt("clanid");
+									int allyId = rset.getInt("allyId");
+									
+									String clanName = "";
+									String allyName = "";
+									int clanCrest = 0;
+									int allyCrest = 0;
+									
+									if (clanId > 0)
+									{
+										clanName = ClanTable.getInstance().getClan(clanId).getName();
+										clanCrest = ClanTable.getInstance().getClan(clanId).getCrestId();
+										
+										if (allyId > 0)
+										{
+											allyName = ClanTable.getInstance().getClan(clanId).getAllyName();
+											allyCrest = ClanTable.getInstance().getClan(clanId).getAllyCrestId();
+										}
+									}
+									
+									hero.set(CLAN_CREST, clanCrest);
+									hero.set(CLAN_NAME, clanName);
+									hero.set(ALLY_CREST, allyCrest);
+									hero.set(ALLY_NAME, allyName);
 								}
 							}
-							
-							hero.set(CLAN_CREST, clanCrest);
-							hero.set(CLAN_NAME, clanName);
-							hero.set(ALLY_CREST, allyCrest);
-							hero.set(ALLY_NAME, allyName);
 						}
-						
-						rset.close();
-						statement.close();
-						
 						_heroes.remove(heroId);
 						_heroes.put(heroId, hero);
 						
@@ -863,12 +849,13 @@ public class Hero
 					}
 					else
 					{
-						statement = con.prepareStatement(UPDATE_HERO);
-						statement.setInt(1, hero.getInteger(COUNT));
-						statement.setInt(2, hero.getInteger(PLAYED));
-						statement.setInt(3, heroId);
-						statement.execute();
-						statement.close();
+						try (PreparedStatement statement = con.prepareStatement(UPDATE_HERO))
+						{
+							statement.setInt(1, hero.getInteger(COUNT));
+							statement.setInt(2, hero.getInteger(PLAYED));
+							statement.setInt(3, heroId);
+							statement.execute();
+						}
 					}
 				}
 			}
@@ -933,15 +920,14 @@ public class Hero
 	
 	public void setDiaryData(int charId, int action, int param)
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement statement = con.prepareStatement("INSERT INTO heroes_diary (charId, time, action, param) values(?,?,?,?)"))
 		{
-			PreparedStatement statement = con.prepareStatement("INSERT INTO heroes_diary (charId, time, action, param) values(?,?,?,?)");
 			statement.setInt(1, charId);
 			statement.setLong(2, System.currentTimeMillis());
 			statement.setInt(3, action);
 			statement.setInt(4, param);
 			statement.execute();
-			statement.close();
 		}
 		catch (SQLException e)
 		{
@@ -977,13 +963,12 @@ public class Hero
 			return;
 		}
 		
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement statement = con.prepareStatement("UPDATE heroes SET message=? WHERE charId=?;"))
 		{
-			PreparedStatement statement = con.prepareStatement("UPDATE heroes SET message=? WHERE charId=?;");
 			statement.setString(1, _heroMessage.get(charId));
 			statement.setInt(2, charId);
 			statement.execute();
-			statement.close();
 		}
 		catch (SQLException e)
 		{
@@ -993,11 +978,10 @@ public class Hero
 	
 	private void deleteItemsInDb()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement statement = con.prepareStatement(DELETE_ITEMS))
 		{
-			PreparedStatement statement = con.prepareStatement(DELETE_ITEMS);
 			statement.execute();
-			statement.close();
 		}
 		catch (SQLException e)
 		{

+ 118 - 95
L2J_Server_BETA/java/com/l2jserver/gameserver/network/L2GameClient.java

@@ -426,125 +426,148 @@ public final class L2GameClient extends MMOClient<MMOConnection<L2GameClient>> i
 		
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			PreparedStatement statement = con.prepareStatement("DELETE FROM character_contacts WHERE charId=? OR contactId=?");
-			statement.setInt(1, objid);
-			statement.setInt(2, objid);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM character_contacts WHERE charId=? OR contactId=?"))
+			{
+				ps.setInt(1, objid);
+				ps.setInt(2, objid);
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM character_friends WHERE charId=? OR friendId=?");
-			statement.setInt(1, objid);
-			statement.setInt(2, objid);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM character_friends WHERE charId=? OR friendId=?"))
+			{
+				ps.setInt(1, objid);
+				ps.setInt(2, objid);
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM character_hennas WHERE charId=?");
-			statement.setInt(1, objid);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM character_hennas WHERE charId=?"))
+			{
+				ps.setInt(1, objid);
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM character_macroses WHERE charId=?");
-			statement.setInt(1, objid);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM character_macroses WHERE charId=?"))
+			{
+				ps.setInt(1, objid);
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM character_quests WHERE charId=?");
-			statement.setInt(1, objid);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM character_quests WHERE charId=?"))
+			{
+				ps.setInt(1, objid);
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM character_quest_global_data WHERE charId=?");
-			statement.setInt(1, objid);
-			statement.executeUpdate();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM character_quest_global_data WHERE charId=?"))
+			{
+				ps.setInt(1, objid);
+				ps.executeUpdate();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM character_recipebook WHERE charId=?");
-			statement.setInt(1, objid);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM character_recipebook WHERE charId=?"))
+			{
+				ps.setInt(1, objid);
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM character_shortcuts WHERE charId=?");
-			statement.setInt(1, objid);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM character_shortcuts WHERE charId=?"))
+			{
+				ps.setInt(1, objid);
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM character_skills WHERE charId=?");
-			statement.setInt(1, objid);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM character_skills WHERE charId=?"))
+			{
+				ps.setInt(1, objid);
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM character_skills_save WHERE charId=?");
-			statement.setInt(1, objid);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM character_skills_save WHERE charId=?"))
+			{
+				ps.setInt(1, objid);
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM character_subclasses WHERE charId=?");
-			statement.setInt(1, objid);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM character_subclasses WHERE charId=?"))
+			{
+				ps.setInt(1, objid);
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM heroes WHERE charId=?");
-			statement.setInt(1, objid);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM heroes WHERE charId=?"))
+			{
+				ps.setInt(1, objid);
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM olympiad_nobles WHERE charId=?");
-			statement.setInt(1, objid);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM olympiad_nobles WHERE charId=?"))
+			{
+				ps.setInt(1, objid);
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM seven_signs WHERE charId=?");
-			statement.setInt(1, objid);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM seven_signs WHERE charId=?"))
+			{
+				ps.setInt(1, objid);
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM pets WHERE item_obj_id IN (SELECT object_id FROM items WHERE items.owner_id=?)");
-			statement.setInt(1, objid);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM pets WHERE item_obj_id IN (SELECT object_id FROM items WHERE items.owner_id=?)"))
+			{
+				ps.setInt(1, objid);
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM item_attributes WHERE itemId IN (SELECT object_id FROM items WHERE items.owner_id=?)");
-			statement.setInt(1, objid);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM item_attributes WHERE itemId IN (SELECT object_id FROM items WHERE items.owner_id=?)"))
+			{
+				ps.setInt(1, objid);
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM items WHERE owner_id=?");
-			statement.setInt(1, objid);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM items WHERE owner_id=?"))
+			{
+				ps.setInt(1, objid);
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM merchant_lease WHERE player_id=?");
-			statement.setInt(1, objid);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM merchant_lease WHERE player_id=?"))
+			{
+				ps.setInt(1, objid);
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM character_raid_points WHERE charId=?");
-			statement.setInt(1, objid);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM character_raid_points WHERE charId=?"))
+			{
+				ps.setInt(1, objid);
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM character_reco_bonus WHERE charId=?");
-			statement.setInt(1, objid);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM character_reco_bonus WHERE charId=?"))
+			{
+				ps.setInt(1, objid);
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM character_instance_time WHERE charId=?");
-			statement.setInt(1, objid);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM character_instance_time WHERE charId=?"))
+			{
+				ps.setInt(1, objid);
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM characters WHERE charId=?");
-			statement.setInt(1, objid);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM characters WHERE charId=?"))
+			{
+				ps.setInt(1, objid);
+				ps.execute();
+			}
 			
 			if (Config.L2JMOD_ALLOW_WEDDING)
 			{
-				statement = con.prepareStatement("DELETE FROM mods_wedding WHERE player1Id = ? OR player2Id = ?");
-				statement.setInt(1, objid);
-				statement.setInt(2, objid);
-				statement.execute();
-				statement.close();
+				try (PreparedStatement ps = con.prepareStatement("DELETE FROM mods_wedding WHERE player1Id = ? OR player2Id = ?"))
+				{
+					ps.setInt(1, objid);
+					ps.setInt(2, objid);
+					ps.execute();
+				}
 			}
 		}
 		catch (Exception e)

+ 13 - 10
L2J_Server_BETA/java/com/l2jserver/gameserver/network/clientpackets/RequestMakeMacro.java

@@ -18,9 +18,12 @@
  */
 package com.l2jserver.gameserver.network.clientpackets;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import com.l2jserver.Config;
-import com.l2jserver.gameserver.model.L2Macro;
-import com.l2jserver.gameserver.model.L2Macro.L2MacroCmd;
+import com.l2jserver.gameserver.model.Macro;
+import com.l2jserver.gameserver.model.MacroCmd;
 import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
 import com.l2jserver.gameserver.network.SystemMessageId;
 
@@ -31,7 +34,7 @@ public final class RequestMakeMacro extends L2GameClientPacket
 {
 	private static final String _C__CD_REQUESTMAKEMACRO = "[C] CD RequestMakeMacro";
 	
-	private L2Macro _macro;
+	private Macro _macro;
 	private int _commandsLenght = 0;
 	
 	private static final int MAX_MACRO_LENGTH = 12;
@@ -50,12 +53,12 @@ public final class RequestMakeMacro extends L2GameClientPacket
 			_count = MAX_MACRO_LENGTH;
 		}
 		
-		L2MacroCmd[] commands = new L2MacroCmd[_count];
-		
 		if (Config.DEBUG)
 		{
 			_log.info("Make macro id:" + _id + "\tname:" + _name + "\tdesc:" + _desc + "\tacronym:" + _acronym + "\ticon:" + _icon + "\tcount:" + _count);
 		}
+		
+		final List<MacroCmd> commands = new ArrayList<>(_count);
 		for (int i = 0; i < _count; i++)
 		{
 			int entry = readC();
@@ -64,13 +67,13 @@ public final class RequestMakeMacro extends L2GameClientPacket
 			int d2 = readC();
 			String command = readS();
 			_commandsLenght += command.length();
-			commands[i] = new L2MacroCmd(entry, type, d1, d2, command);
+			commands.add(new MacroCmd(entry, type, d1, d2, command));
 			if (Config.DEBUG)
 			{
 				_log.info("entry:" + entry + "\ttype:" + type + "\td1:" + d1 + "\td2:" + d2 + "\tcommand:" + command);
 			}
 		}
-		_macro = new L2Macro(_id, _icon, _name, _desc, _acronym, commands);
+		_macro = new Macro(_id, _icon, _name, _desc, _acronym, commands);
 	}
 	
 	@Override
@@ -87,19 +90,19 @@ public final class RequestMakeMacro extends L2GameClientPacket
 			player.sendPacket(SystemMessageId.INVALID_MACRO);
 			return;
 		}
-		if (player.getMacros().getAllMacroses().length > 48)
+		if (player.getMacros().getAllMacroses().size() > 48)
 		{
 			// You may create up to 48 macros.
 			player.sendPacket(SystemMessageId.YOU_MAY_CREATE_UP_TO_48_MACROS);
 			return;
 		}
-		if (_macro.name.isEmpty())
+		if (_macro.getName().isEmpty())
 		{
 			// Enter the name of the macro.
 			player.sendPacket(SystemMessageId.ENTER_THE_MACRO_NAME);
 			return;
 		}
-		if (_macro.descr.length() > 32)
+		if (_macro.getDescr().length() > 32)
 		{
 			// Macro descriptions may contain up to 32 characters.
 			player.sendPacket(SystemMessageId.MACRO_DESCRIPTION_MAX_32_CHARS);

+ 17 - 16
L2J_Server_BETA/java/com/l2jserver/gameserver/network/serverpackets/SendMacroList.java

@@ -18,15 +18,16 @@
  */
 package com.l2jserver.gameserver.network.serverpackets;
 
-import com.l2jserver.gameserver.model.L2Macro;
+import com.l2jserver.gameserver.model.Macro;
+import com.l2jserver.gameserver.model.MacroCmd;
 
 public class SendMacroList extends L2GameServerPacket
 {
 	private final int _rev;
 	private final int _count;
-	private final L2Macro _macro;
+	private final Macro _macro;
 	
-	public SendMacroList(int rev, int count, L2Macro macro)
+	public SendMacroList(int rev, int count, Macro macro)
 	{
 		_rev = rev;
 		_count = count;
@@ -45,22 +46,22 @@ public class SendMacroList extends L2GameServerPacket
 		
 		if (_macro != null)
 		{
-			writeD(_macro.id); // Macro ID
-			writeS(_macro.name); // Macro Name
-			writeS(_macro.descr); // Desc
-			writeS(_macro.acronym); // acronym
-			writeC(_macro.icon); // icon
+			writeD(_macro.getId()); // Macro ID
+			writeS(_macro.getName()); // Macro Name
+			writeS(_macro.getDescr()); // Desc
+			writeS(_macro.getAcronym()); // acronym
+			writeC(_macro.getIcon()); // icon
 			
-			writeC(_macro.commands.length); // count
+			writeC(_macro.getCommands().size()); // count
 			
-			for (int i = 0; i < _macro.commands.length; i++)
+			int i = 1;
+			for (MacroCmd cmd : _macro.getCommands())
 			{
-				L2Macro.L2MacroCmd cmd = _macro.commands[i];
-				writeC(i + 1); // i of count
-				writeC(cmd.type); // type 1 = skill, 3 = action, 4 = shortcut
-				writeD(cmd.d1); // skill id
-				writeC(cmd.d2); // shortcut id
-				writeS(cmd.cmd); // command name
+				writeC(i++); // command count
+				writeC(cmd.getType()); // type 1 = skill, 3 = action, 4 = shortcut
+				writeD(cmd.getD1()); // skill id
+				writeC(cmd.getD2()); // shortcut id
+				writeS(cmd.getCmd()); // command name
 			}
 		}
 	}