L2JMobius

Fafurion Clan privilege

Edoo · 5 · 12075

Offline Edoo

  • Baron
  • *****
    • Posts: 224
Clan privilege saving error fix:

Code: [Select]
diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/clan/Clan.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/clan/Clan.java
index 313f2da..549d623 100644
--- a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/clan/Clan.java
+++ b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/clan/Clan.java
@@ -92,8 +92,8 @@
  private static final Logger LOGGER = Logger.getLogger(Clan.class.getName());
 
  // SQL queries
- private static final String INSERT_CLAN_DATA = "INSERT INTO clan_data (clan_id,clan_name,clan_level,hasCastle,blood_alliance_count,blood_oath_count,ally_id,ally_name,leader_id,crest_id,crest_large_id,ally_crest_id,new_leader_id) values (?,?,?,?,?,?,?,?,?,?,?,?,?)";
- private static final String SELECT_CLAN_DATA = "SELECT * FROM clan_data where clan_id=?";
+ private static final String INSERT_CLAN_DATA = "INSERT INTO `clan_data` (`clan_id`, `clan_name`, `clan_level`, `hasCastle`, `blood_alliance_count`, `blood_oath_count`, `ally_id`, `ally_name`, `leader_id`, `crest_id`, `crest_large_id`, `ally_crest_id`, `new_leader_id`) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+ private static final String SELECT_CLAN_DATA = "SELECT * FROM `clan_data` where `clan_id` = ?";
 
  // Ally Penalty Types
  /** Clan leaved ally */
@@ -310,11 +310,12 @@
  else
  {
  try (Connection con = DatabaseFactory.getConnection();
- PreparedStatement ps = con.prepareStatement("UPDATE characters SET clan_privs = ? WHERE charId = ?"))
+ PreparedStatement ps = con.prepareStatement("UPDATE `characters` SET `clan_privs` = ? WHERE `charId` = ?"))
  {
  ps.setInt(1, 0);
  ps.setInt(2, getLeaderId());
  ps.execute();
+ ps.close();
  }
  catch (Exception e)
  {
@@ -350,11 +351,12 @@
  else
  {
  try (Connection con = DatabaseFactory.getConnection();
- PreparedStatement ps = con.prepareStatement("UPDATE characters SET clan_privs = ? WHERE charId = ?"))
+ PreparedStatement ps = con.prepareStatement("UPDATE `characters` SET `clan_privs` = ? WHERE `charId` = ?"))
  {
  ps.setInt(1, EnumIntBitmask.getAllBitmask(ClanPrivilege.class));
  ps.setInt(2, getLeaderId());
  ps.execute();
+ ps.close();
  }
  catch (Exception e)
  {
@@ -830,11 +832,12 @@
  public void updateBloodAllianceCountInDB()
  {
  try (Connection con = DatabaseFactory.getConnection();
- PreparedStatement ps = 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` = ?"))
  {
  ps.setInt(1, _bloodAllianceCount);
  ps.setInt(2, _clanId);
  ps.execute();
+ ps.close();
  }
  catch (Exception e)
  {
@@ -874,11 +877,12 @@
  public void updateBloodOathCountInDB()
  {
  try (Connection con = DatabaseFactory.getConnection();
- PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET blood_oath_count=? WHERE clan_id=?"))
+ PreparedStatement ps = con.prepareStatement("UPDATE `clan_data` SET `blood_oath_count` = ? WHERE `clan_id` = ?"))
  {
  ps.setInt(1, _bloodOathCount);
  ps.setInt(2, _clanId);
  ps.execute();
+ ps.close();
  }
  catch (Exception e)
  {
@@ -890,11 +894,12 @@
  {
  // Update reputation
  try (Connection con = DatabaseFactory.getConnection();
- PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET reputation_score=? WHERE clan_id=?"))
+ PreparedStatement ps = con.prepareStatement("UPDATE `clan_data` SET `reputation_score` = ? WHERE `clan_id` = ?"))
  {
  ps.setInt(1, _reputationScore);
  ps.setInt(2, _clanId);
  ps.execute();
+ ps.close();
  }
  catch (Exception e)
  {
@@ -925,7 +930,7 @@
  public void updateClanInDB()
  {
  try (Connection con = DatabaseFactory.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=?"))
+ 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, _allyId);
@@ -938,6 +943,7 @@
  ps.setInt(9, _newLeaderId);
  ps.setInt(10, _clanId);
  ps.execute();
+ ps.close();
  }
  catch (Exception e)
  {
@@ -994,21 +1000,24 @@
  private void removeMemberInDatabase(ClanMember member, long clanJoinExpiryTime, long clanCreateExpiryTime)
  {
  try (Connection con = DatabaseFactory.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=?"))
+ 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();
+ ps1.close();
  // Remove apprentice.
  ps2.setInt(1, member.getObjectId());
  ps2.execute();
+ ps2.close();
  // Remove sponsor.
  ps3.setInt(1, member.getObjectId());
  ps3.execute();
+ ps3.close();
  }
  catch (Exception e)
  {
@@ -1057,7 +1066,7 @@
 
  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=?"))
+ try (PreparedStatement select = con.prepareStatement("SELECT `char_name`, `level`, `classid`, `charId`, `title`, `power_grade`, `subpledge`, `apprentice`, `sponsor`, `sex`, `race` FROM `characters` WHERE `clanid` = ?"))
  {
  select.setInt(1, _clanId);
  try (ResultSet clanMember = select.executeQuery())
@@ -1075,10 +1084,14 @@
  addClanMember(member);
  }
  }
+ clanMember.close();
  }
+ select.close();
  }
  }
+ clanData.close();
  }
+ ps.close();
 
  restoreSubPledges();
  restoreRankPrivs();
@@ -1094,7 +1107,7 @@
  private void restoreNotice()
  {
  try (Connection con = DatabaseFactory.getConnection();
- PreparedStatement ps = con.prepareStatement("SELECT enabled,notice FROM clan_notices WHERE clan_id=?"))
+ PreparedStatement ps = con.prepareStatement("SELECT `enabled`, `notice` FROM `clan_notices` WHERE `clan_id` = ?"))
  {
  ps.setInt(1, _clanId);
  try (ResultSet noticeData = ps.executeQuery())
@@ -1104,7 +1117,9 @@
  _noticeEnabled = noticeData.getBoolean("enabled");
  _notice = noticeData.getString("notice");
  }
+ noticeData.close();
  }
+ ps.close();
  }
  catch (Exception e)
  {
@@ -1125,7 +1140,7 @@
  }
 
  try (Connection con = DatabaseFactory.getConnection();
- PreparedStatement ps = 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` = ?"))
  {
  ps.setInt(1, _clanId);
  ps.setString(2, notice);
@@ -1147,6 +1162,7 @@
  ps.setString(5, "false");
  }
  ps.execute();
+ ps.close();
  }
  catch (Exception e)
  {
@@ -1184,7 +1200,7 @@
  private void restoreSkills()
  {
  try (Connection con = DatabaseFactory.getConnection();
- PreparedStatement ps = 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 PlayerInstance from the database
  ps.setInt(1, _clanId);
@@ -1221,7 +1237,9 @@
  }
  }
  }
+ rset.close();
  }
+ ps.close();
  }
  catch (Exception e)
  {
@@ -1310,17 +1328,18 @@
  {
  if (oldSkill != null)
  {
- try (PreparedStatement ps = 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` = ?"))
  {
  ps.setInt(1, newSkill.getLevel());
  ps.setInt(2, oldSkill.getId());
  ps.setInt(3, _clanId);
  ps.execute();
+ ps.close();
  }
  }
  else
  {
- try (PreparedStatement ps = 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 (?, ?, ?, ?, ?)"))
  {
  ps.setInt(1, _clanId);
  ps.setInt(2, newSkill.getId());
@@ -1328,6 +1347,7 @@
  ps.setString(4, newSkill.getName());
  ps.setInt(5, subType);
  ps.execute();
+ ps.close();
  }
  }
  }
@@ -1744,7 +1764,7 @@
  private void restoreSubPledges()
  {
  try (Connection con = DatabaseFactory.getConnection();
- PreparedStatement ps = 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
  ps.setInt(1, _clanId);
@@ -1824,13 +1844,14 @@
  SubPledge subPledge = null;
 
  try (Connection con = DatabaseFactory.getConnection();
- PreparedStatement ps = 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 (?, ?, ?, ?)"))
  {
  ps.setInt(1, _clanId);
  ps.setInt(2, pledgeType);
  ps.setString(3, subPledgeName);
  ps.setInt(4, _leader.getObjectId());
  ps.execute();
+ ps.close();
 
  subPledge = new SubPledge(pledgeType, subPledgeName, _leader.getObjectId());
  _subPledges.put(pledgeType, subPledge);
@@ -1848,13 +1869,14 @@
  public void updateSubPledgeInDB(int pledgeType)
  {
  try (Connection con = DatabaseFactory.getConnection();
- PreparedStatement ps = 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` = ?"))
  {
  ps.setInt(1, getSubPledge(pledgeType).getLeaderId());
  ps.setString(2, getSubPledge(pledgeType).getName());
  ps.setInt(3, _clanId);
  ps.setInt(4, pledgeType);
  ps.execute();
+ ps.close();
  }
  catch (Exception e)
  {
@@ -1865,18 +1887,19 @@
  private void restoreRankPrivs()
  {
  try (Connection con = DatabaseFactory.getConnection();
- PreparedStatement ps = con.prepareStatement("SELECT privs,rank,party FROM clan_privs WHERE clan_id=?"))
+ PreparedStatement ps = con.prepareStatement("SELECT `rank`, `party`, `privs` FROM `clan_privs` WHERE `clan_id` = ?"))
  {
  // Retrieve all skills of this PlayerInstance from the database
  ps.setInt(1, _clanId);
- // LOGGER.warning("clanPrivs restore for ClanId : "+getClanId());
+ // LOGGER.warning("clanPrivs restore for ClanId: " + getId());
+
  try (ResultSet rset = ps.executeQuery())
  {
  // Go though the recordset of this SQL query
  while (rset.next())
  {
  final int rank = rset.getInt("rank");
- // int party = rset.getInt("party");
+ final int party = rset.getInt("party");
  final int privileges = rset.getInt("privs");
  // Create a SubPledge object for each record
  if (rank == -1)
@@ -1884,7 +1907,7 @@
  continue;
  }
 
- _privs.get(rank).setPrivs(privileges);
+ _privs.put(rank, new RankPrivs(rank, party, privileges)).setPrivs(privileges);
  }
  }
  }
@@ -1914,7 +1937,7 @@
  _privs.get(rank).setPrivs(privs);
 
  try (Connection con = DatabaseFactory.getConnection();
- PreparedStatement ps = 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 PlayerInstance from the database
  ps.setInt(1, _clanId);
@@ -1923,6 +1946,7 @@
  ps.setInt(4, privs);
  ps.setInt(5, privs);
  ps.execute();
+ ps.close();
  }
  catch (Exception e)
  {
@@ -1950,7 +1974,7 @@
  _privs.put(rank, new RankPrivs(rank, 0, privs));
 
  try (Connection con = DatabaseFactory.getConnection();
- PreparedStatement ps = 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 PlayerInstance from the database
  ps.setInt(1, _clanId);
@@ -1958,6 +1982,7 @@
  ps.setInt(3, 0);
  ps.setInt(4, privs);
  ps.execute();
+ ps.close();
  }
  catch (Exception e)
  {
@@ -2069,11 +2094,12 @@
  if (storeInDb)
  {
  try (Connection con = DatabaseFactory.getConnection();
- PreparedStatement ps = 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` = ?"))
  {
  ps.setInt(1, id);
  ps.setInt(2, _clanId);
  ps.execute();
+ ps.close();
  }
  catch (Exception e)
  {
@@ -2416,11 +2442,12 @@
  public void changeLevel(int level)
  {
  try (Connection con = DatabaseFactory.getConnection();
- PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET clan_level = ? WHERE clan_id = ?"))
+ PreparedStatement ps = con.prepareStatement("UPDATE `clan_data` SET `clan_level` = ? WHERE `clan_id` = ?"))
  {
  ps.setInt(1, level);
  ps.setInt(2, _clanId);
  ps.execute();
+ ps.close();
  }
  catch (Exception e)
  {
@@ -2462,7 +2489,7 @@
  setCrestId(crestId);
 
  try (Connection con = DatabaseFactory.getConnection();
- PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET crest_id = ? WHERE clan_id = ?"))
+ PreparedStatement ps = con.prepareStatement("UPDATE `clan_data` SET `crest_id` = ? WHERE `clan_id` = ?"))
  {
  ps.setInt(1, crestId);
  ps.setInt(2, _clanId);
@@ -2486,7 +2513,7 @@
  */
  public void changeAllyCrest(int crestId, boolean onlyThisClan)
  {
- String sqlStatement = "UPDATE clan_data SET ally_crest_id = ? WHERE clan_id = ?";
+ String sqlStatement = "UPDATE `clan_data` SET `ally_crest_id` = ? WHERE `clan_id` = ?";
  int allyId = _clanId;
  if (!onlyThisClan)
  {
@@ -2494,7 +2521,7 @@
  {
  CrestTable.getInstance().removeCrest(getAllyCrestId());
  }
- sqlStatement = "UPDATE clan_data SET ally_crest_id = ? WHERE ally_id = ?";
+ sqlStatement = "UPDATE `clan_data` SET `ally_crest_id` = ? WHERE `ally_id` = ?";
  allyId = _allyId;
  }
 
@@ -2504,6 +2531,7 @@
  ps.setInt(1, crestId);
  ps.setInt(2, allyId);
  ps.executeUpdate();
+ ps.close();
  }
  catch (SQLException e)
  {


Online Mobius

  • Distinguished King
  • *****
    • Posts: 16013
As mentioned at https://l2jmobius.org/forum/index.php?topic=3861.15 it is already fixed.

Also use Shares/Contributions section to share.
Moved.


Offline Edoo

  • Baron
  • *****
    • Posts: 224
mentioned, but never recovered. The error is in all your builds. Even in the new ones that you just posted ... My fix works 100%, why not apply it to all assemblies? Or do you leave the opportunity to modify others?


Online Mobius

  • Distinguished King
  • *****
    • Posts: 16013
Because the one just shared is not the latest existing version?
Because I do not use MySQL 8 on my guides?

Never the less, it is fixed on all branches.
Also, for this fix, only `rank` needs quotes.