diff --git a/src/engine/db/handlers/dbAccountHandler.java b/src/engine/db/handlers/dbAccountHandler.java index ad790a3b..f34ebe60 100644 --- a/src/engine/db/handlers/dbAccountHandler.java +++ b/src/engine/db/handlers/dbAccountHandler.java @@ -25,249 +25,249 @@ import java.util.ArrayList; public class dbAccountHandler extends dbHandlerBase { - public dbAccountHandler() { - this.localClass = Account.class; - this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); - } + public dbAccountHandler() { + this.localClass = Account.class; + this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); + } - public Account GET_ACCOUNT(int accountID) { + public Account GET_ACCOUNT(int accountID) { - Account account; + Account account; - if (accountID == 0) - return null; + if (accountID == 0) + return null; - account = (Account) DbManager.getFromCache(GameObjectType.Account, accountID); + account = (Account) DbManager.getFromCache(GameObjectType.Account, accountID); - if (account != null) - return account; + if (account != null) + return account; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `obj_account` WHERE `UID`=?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `obj_account` WHERE `UID`=?")) { - preparedStatement.setLong(1, accountID); + preparedStatement.setLong(1, accountID); - ResultSet rs = preparedStatement.executeQuery(); - account = (Account) getObjectFromRs(rs); + ResultSet rs = preparedStatement.executeQuery(); + account = (Account) getObjectFromRs(rs); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - if (account != null) - account.runAfterLoad(); + if (account != null) + account.runAfterLoad(); - return account; - } + return account; + } - public void WRITE_ADMIN_LOG(String adminName, String logEntry) { + public void WRITE_ADMIN_LOG(String adminName, String logEntry) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO dyn_admin_log(`dateTime`, `charName`, `eventString`)" - + " VALUES (?, ?, ?)")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO dyn_admin_log(`dateTime`, `charName`, `eventString`)" + + " VALUES (?, ?, ?)")) { - preparedStatement.setTimestamp(1, new java.sql.Timestamp(System.currentTimeMillis())); - preparedStatement.setString(2, adminName); - preparedStatement.setString(3, logEntry); + preparedStatement.setTimestamp(1, new java.sql.Timestamp(System.currentTimeMillis())); + preparedStatement.setString(2, adminName); + preparedStatement.setString(3, logEntry); - preparedStatement.execute(); + preparedStatement.execute(); - } catch (SQLException e) { - Logger.error(e); - } - } + } catch (SQLException e) { + Logger.error(e); + } + } - public void SET_TRASH(String machineID) { + public void SET_TRASH(String machineID) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO dyn_trash(`machineID`, `count`)" - + " VALUES (?, 1) ON DUPLICATE KEY UPDATE `count` = `count` + 1;")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO dyn_trash(`machineID`, `count`)" + + " VALUES (?, 1) ON DUPLICATE KEY UPDATE `count` = `count` + 1;")) { - preparedStatement.setString(1, machineID); - preparedStatement.execute(); + preparedStatement.setString(1, machineID); + preparedStatement.execute(); - } catch (SQLException e) { - Logger.error(e); - } - } + } catch (SQLException e) { + Logger.error(e); + } + } - public ArrayList GET_TRASH_LIST() { + public ArrayList GET_TRASH_LIST() { - ArrayList machineList = new ArrayList<>(); + ArrayList machineList = new ArrayList<>(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("select `machineID` from `dyn_trash`")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("select `machineID` from `dyn_trash`")) { - ResultSet rs = preparedStatement.executeQuery(); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) - machineList.add(rs.getString(1)); + while (rs.next()) + machineList.add(rs.getString(1)); - } catch (SQLException e) { - Logger.error(e); - } - return machineList; - } + } catch (SQLException e) { + Logger.error(e); + } + return machineList; + } - public void DELETE_VAULT_FOR_ACCOUNT(final int accountID) { + public void DELETE_VAULT_FOR_ACCOUNT(final int accountID) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `parent`=? && `type`='item'")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `parent`=? && `type`='item'")) { - preparedStatement.setLong(1, accountID); - preparedStatement.execute(); + preparedStatement.setLong(1, accountID); + preparedStatement.execute(); - } catch (SQLException e) { - Logger.error(e); - } - } + } catch (SQLException e) { + Logger.error(e); + } + } - public ArrayList GET_ALL_CHARS_FOR_MACHINE(String machineID) { + public ArrayList GET_ALL_CHARS_FOR_MACHINE(String machineID) { - ArrayList trashList = new ArrayList<>(); + ArrayList trashList = new ArrayList<>(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("select DISTINCT UID from object \n" + - "where parent IN (select AccountID from dyn_login_history " + - " WHERE`machineID`=?)")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("select DISTINCT UID from object \n" + + "where parent IN (select AccountID from dyn_login_history " + + " WHERE`machineID`=?)")) { - preparedStatement.setString(1, machineID); - ResultSet rs = preparedStatement.executeQuery(); + preparedStatement.setString(1, machineID); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) { + while (rs.next()) { - PlayerCharacter trashPlayer; - int playerID; + PlayerCharacter trashPlayer; + int playerID; - playerID = rs.getInt(1); - trashPlayer = PlayerCharacter.getPlayerCharacter(playerID); + playerID = rs.getInt(1); + trashPlayer = PlayerCharacter.getPlayerCharacter(playerID); - if (trashPlayer == null) - continue; + if (trashPlayer == null) + continue; - if (trashPlayer.isDeleted() == false) - trashList.add(trashPlayer); - } + if (trashPlayer.isDeleted() == false) + trashList.add(trashPlayer); + } - } catch (SQLException e) { - Logger.error(e); - } - return trashList; - } + } catch (SQLException e) { + Logger.error(e); + } + return trashList; + } - public void CLEAR_TRASH_TABLE() { + public void CLEAR_TRASH_TABLE() { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM dyn_trash")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM dyn_trash")) { - preparedStatement.execute(); + preparedStatement.execute(); - } catch (SQLException e) { - Logger.error(e); - } - } + } catch (SQLException e) { + Logger.error(e); + } + } - public void CREATE_SINGLE(String accountName, String password) { + public void CREATE_SINGLE(String accountName, String password) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("CALL singleAccountCreate(?,?)")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("CALL singleAccountCreate(?,?)")) { - preparedStatement.setString(1, accountName); - preparedStatement.setString(2, password); + preparedStatement.setString(1, accountName); + preparedStatement.setString(2, password); - preparedStatement.execute(); + preparedStatement.execute(); - } catch (SQLException e) { - Logger.error(e); - } - } + } catch (SQLException e) { + Logger.error(e); + } + } - public Account GET_ACCOUNT(String uname) { + public Account GET_ACCOUNT(String uname) { - Account account = null; + Account account = null; - if (Account.AccountsMap.get(uname) != null) - return this.GET_ACCOUNT(Account.AccountsMap.get(uname)); + if (Account.AccountsMap.get(uname) != null) + return this.GET_ACCOUNT(Account.AccountsMap.get(uname)); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `obj_account` WHERE `acct_uname`=?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `obj_account` WHERE `acct_uname`=?")) { - preparedStatement.setString(1, uname); + preparedStatement.setString(1, uname); - ResultSet rs = preparedStatement.executeQuery(); - account = (Account) getObjectFromRs(rs); + ResultSet rs = preparedStatement.executeQuery(); + account = (Account) getObjectFromRs(rs); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - if (account != null) { - account.runAfterLoad(); + if (account != null) { + account.runAfterLoad(); - if (ConfigManager.serverType.equals(Enum.ServerType.LOGINSERVER)) - Account.AccountsMap.put(uname, account.getObjectUUID()); + if (ConfigManager.serverType.equals(Enum.ServerType.LOGINSERVER)) + Account.AccountsMap.put(uname, account.getObjectUUID()); - } - return account; - } + } + return account; + } - public void SET_ACCOUNT_LOGIN(final Account acc, String playerName, final String ip, final String machineID) { + public void SET_ACCOUNT_LOGIN(final Account acc, String playerName, final String ip, final String machineID) { - if (acc.getObjectUUID() == 0 || ip == null || ip.length() == 0) - return; + if (acc.getObjectUUID() == 0 || ip == null || ip.length() == 0) + return; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO dyn_login_history(`AccountID`, `accountName`, `characterName`, `ip`, `machineID`, `timeStamp`)" - + " VALUES (?, ?, ?, ?, ?, ?)")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO dyn_login_history(`AccountID`, `accountName`, `characterName`, `ip`, `machineID`, `timeStamp`)" + + " VALUES (?, ?, ?, ?, ?, ?)")) { - preparedStatement.setInt(1, acc.getObjectUUID()); - preparedStatement.setString(2, acc.getUname()); - preparedStatement.setString(3, playerName); - preparedStatement.setString(4, ip); - preparedStatement.setString(5, machineID); - preparedStatement.setTimestamp(6, new java.sql.Timestamp(System.currentTimeMillis())); + preparedStatement.setInt(1, acc.getObjectUUID()); + preparedStatement.setString(2, acc.getUname()); + preparedStatement.setString(3, playerName); + preparedStatement.setString(4, ip); + preparedStatement.setString(5, machineID); + preparedStatement.setTimestamp(6, new java.sql.Timestamp(System.currentTimeMillis())); - preparedStatement.execute(); + preparedStatement.execute(); - } catch (SQLException e) { - Logger.error(e); - } - } + } catch (SQLException e) { + Logger.error(e); + } + } - public void updateDatabase(final Account acc) { + public void updateDatabase(final Account acc) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_account` SET `acct_passwd`=?, " - + " `acct_lastCharUID`=?, `acct_salt`=?, `discordAccount`=?, " + - " status = ? WHERE `UID`=?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_account` SET `acct_passwd`=?, " + + " `acct_lastCharUID`=?, `acct_salt`=?, `discordAccount`=?, " + + " status = ? WHERE `UID`=?")) { - preparedStatement.setString(1, acc.getPasswd()); - preparedStatement.setInt(2, acc.getLastCharIDUsed()); - preparedStatement.setString(3, acc.getSalt()); - preparedStatement.setString(4, acc.discordAccount); - preparedStatement.setString(5, acc.status.name()); - preparedStatement.setInt(6, acc.getObjectUUID()); + preparedStatement.setString(1, acc.getPasswd()); + preparedStatement.setInt(2, acc.getLastCharIDUsed()); + preparedStatement.setString(3, acc.getSalt()); + preparedStatement.setString(4, acc.discordAccount); + preparedStatement.setString(5, acc.status.name()); + preparedStatement.setInt(6, acc.getObjectUUID()); - preparedStatement.execute(); + preparedStatement.execute(); - } catch (SQLException e) { - Logger.error(e); - } - } + } catch (SQLException e) { + Logger.error(e); + } + } - public void INVALIDATE_LOGIN_CACHE(long accountUID, String objectType) { + public void INVALIDATE_LOGIN_CACHE(long accountUID, String objectType) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("INSERT IGNORE INTO login_cachelist (`UID`, `type`) VALUES(?,?);")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("INSERT IGNORE INTO login_cachelist (`UID`, `type`) VALUES(?,?);")) { - preparedStatement.setLong(1, accountUID); - preparedStatement.setString(2, objectType); + preparedStatement.setLong(1, accountUID); + preparedStatement.setString(2, objectType); - preparedStatement.execute(); + preparedStatement.execute(); - } catch (SQLException e) { - Logger.error(e); - } - } + } catch (SQLException e) { + Logger.error(e); + } + } } diff --git a/src/engine/db/handlers/dbBaseClassHandler.java b/src/engine/db/handlers/dbBaseClassHandler.java index 30f476e6..93f144b5 100644 --- a/src/engine/db/handlers/dbBaseClassHandler.java +++ b/src/engine/db/handlers/dbBaseClassHandler.java @@ -23,69 +23,69 @@ import java.util.ArrayList; public class dbBaseClassHandler extends dbHandlerBase { - public dbBaseClassHandler() { - this.localClass = BaseClass.class; - this.localObjectType = Enum.GameObjectType.BaseClass; - } + public dbBaseClassHandler() { + this.localClass = BaseClass.class; + this.localObjectType = Enum.GameObjectType.BaseClass; + } - public BaseClass GET_BASE_CLASS(final int id) { + public BaseClass GET_BASE_CLASS(final int id) { - if (id == 0) - return null; + if (id == 0) + return null; - BaseClass baseClass = (BaseClass) DbManager.getFromCache(GameObjectType.BaseClass, id); + BaseClass baseClass = (BaseClass) DbManager.getFromCache(GameObjectType.BaseClass, id); - if (baseClass != null) - return baseClass; + if (baseClass != null) + return baseClass; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `obj_account` WHERE `UID`=?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `obj_account` WHERE `UID`=?")) { - preparedStatement.setLong(1, id); + preparedStatement.setLong(1, id); - ResultSet rs = preparedStatement.executeQuery(); - baseClass = (BaseClass) getObjectFromRs(rs); + ResultSet rs = preparedStatement.executeQuery(); + baseClass = (BaseClass) getObjectFromRs(rs); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return baseClass; - } + return baseClass; + } - public ArrayList GET_BASECLASS_FOR_RACE(final int id) { + public ArrayList GET_BASECLASS_FOR_RACE(final int id) { - ArrayList baseClasses = new ArrayList<>(); + ArrayList baseClasses = new ArrayList<>(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT b.* FROM `static_rune_baseclass` b, `static_rune_racebaseclass` r WHERE b.`ID` = r.`BaseClassID` && r.`RaceID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT b.* FROM `static_rune_baseclass` b, `static_rune_racebaseclass` r WHERE b.`ID` = r.`BaseClassID` && r.`RaceID` = ?")) { - preparedStatement.setInt(1, id); + preparedStatement.setInt(1, id); - ResultSet rs = preparedStatement.executeQuery(); - baseClasses = getObjectsFromRs(rs, 20); + ResultSet rs = preparedStatement.executeQuery(); + baseClasses = getObjectsFromRs(rs, 20); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return baseClasses; - } + return baseClasses; + } - public ArrayList GET_ALL_BASE_CLASSES() { + public ArrayList GET_ALL_BASE_CLASSES() { - ArrayList baseClasses = new ArrayList<>(); + ArrayList baseClasses = new ArrayList<>(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_baseclass`;")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_baseclass`;")) { - ResultSet rs = preparedStatement.executeQuery(); - baseClasses = getObjectsFromRs(rs, 20); + ResultSet rs = preparedStatement.executeQuery(); + baseClasses = getObjectsFromRs(rs, 20); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return baseClasses; - } + return baseClasses; + } } diff --git a/src/engine/db/handlers/dbBuildingLocationHandler.java b/src/engine/db/handlers/dbBuildingLocationHandler.java index bd89fad0..b92f2002 100644 --- a/src/engine/db/handlers/dbBuildingLocationHandler.java +++ b/src/engine/db/handlers/dbBuildingLocationHandler.java @@ -21,29 +21,29 @@ import java.util.ArrayList; public class dbBuildingLocationHandler extends dbHandlerBase { - public dbBuildingLocationHandler() { - this.localClass = BuildingLocation.class; + public dbBuildingLocationHandler() { + this.localClass = BuildingLocation.class; this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); - } + } - public ArrayList LOAD_BUILDING_LOCATIONS() { + public ArrayList LOAD_BUILDING_LOCATIONS() { - ArrayList buildingLocations = new ArrayList<>(); + ArrayList buildingLocations = new ArrayList<>(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("select * from static_building_location " + - "where type = 6 or type = 8 " + - "GROUP BY buildingID, slot " + - "ORDER BY buildingID, slot ASC;")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("select * from static_building_location " + + "where type = 6 or type = 8 " + + "GROUP BY buildingID, slot " + + "ORDER BY buildingID, slot ASC;")) { - ResultSet rs = preparedStatement.executeQuery(); - buildingLocations = getObjectsFromRs(rs, 20); + ResultSet rs = preparedStatement.executeQuery(); + buildingLocations = getObjectsFromRs(rs, 20); - } catch (SQLException e) { - Logger.error(e); - return buildingLocations; - } + } catch (SQLException e) { + Logger.error(e); + return buildingLocations; + } - return buildingLocations; - } + return buildingLocations; + } } diff --git a/src/engine/db/handlers/dbCharacterPowerHandler.java b/src/engine/db/handlers/dbCharacterPowerHandler.java index cbed4c38..3a2bbcf8 100644 --- a/src/engine/db/handlers/dbCharacterPowerHandler.java +++ b/src/engine/db/handlers/dbCharacterPowerHandler.java @@ -24,149 +24,149 @@ import java.util.concurrent.ConcurrentHashMap; public class dbCharacterPowerHandler extends dbHandlerBase { - public dbCharacterPowerHandler() { - this.localClass = CharacterPower.class; - this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); - } + public dbCharacterPowerHandler() { + this.localClass = CharacterPower.class; + this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); + } - public CharacterPower ADD_CHARACTER_POWER(CharacterPower toAdd) { + public CharacterPower ADD_CHARACTER_POWER(CharacterPower toAdd) { - CharacterPower characterPower = null; + CharacterPower characterPower = null; - if (CharacterPower.getOwner(toAdd) == null || toAdd.getPower() == null) { - Logger.error("dbCharacterSkillHandler.ADD_Power", toAdd.getObjectUUID() + " missing owner or powersBase"); - return null; - } + if (CharacterPower.getOwner(toAdd) == null || toAdd.getPower() == null) { + Logger.error("dbCharacterSkillHandler.ADD_Power", toAdd.getObjectUUID() + " missing owner or powersBase"); + return null; + } - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_power` (`CharacterID`, `powersBaseToken`, `trains`) VALUES (?, ?, ?);")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_power` (`CharacterID`, `powersBaseToken`, `trains`) VALUES (?, ?, ?);")) { - preparedStatement.setLong(1, CharacterPower.getOwner(toAdd).getObjectUUID()); - preparedStatement.setInt(2, toAdd.getPower().getToken()); - preparedStatement.setInt(3, toAdd.getTrains()); + preparedStatement.setLong(1, CharacterPower.getOwner(toAdd).getObjectUUID()); + preparedStatement.setInt(2, toAdd.getPower().getToken()); + preparedStatement.setInt(3, toAdd.getTrains()); - preparedStatement.executeUpdate(); - ResultSet rs = preparedStatement.getGeneratedKeys(); + preparedStatement.executeUpdate(); + ResultSet rs = preparedStatement.getGeneratedKeys(); - if (rs.next()) - characterPower = GET_CHARACTER_POWER(rs.getInt(1)); + if (rs.next()) + characterPower = GET_CHARACTER_POWER(rs.getInt(1)); - } catch (SQLException e) { - Logger.error(e); - return null; - } - return characterPower; - } + } catch (SQLException e) { + Logger.error(e); + return null; + } + return characterPower; + } - public int DELETE_CHARACTER_POWER(final int objectUUID) { + public int DELETE_CHARACTER_POWER(final int objectUUID) { - int rowCount = 0; + int rowCount = 0; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_power` WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_power` WHERE `UID` = ?")) { - preparedStatement.setLong(1, objectUUID); - rowCount = preparedStatement.executeUpdate(); + preparedStatement.setLong(1, objectUUID); + rowCount = preparedStatement.executeUpdate(); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return rowCount; - } + return rowCount; + } - public CharacterPower GET_CHARACTER_POWER(int objectUUID) { + public CharacterPower GET_CHARACTER_POWER(int objectUUID) { - CharacterPower characterPower = (CharacterPower) DbManager.getFromCache(Enum.GameObjectType.CharacterPower, objectUUID); + CharacterPower characterPower = (CharacterPower) DbManager.getFromCache(Enum.GameObjectType.CharacterPower, objectUUID); - if (characterPower != null) - return characterPower; + if (characterPower != null) + return characterPower; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_power` WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_power` WHERE `UID` = ?")) { - preparedStatement.setLong(1, objectUUID); - ResultSet rs = preparedStatement.executeQuery(); - characterPower = (CharacterPower) getObjectFromRs(rs); + preparedStatement.setLong(1, objectUUID); + ResultSet rs = preparedStatement.executeQuery(); + characterPower = (CharacterPower) getObjectFromRs(rs); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return characterPower; - } + return characterPower; + } - public ConcurrentHashMap GET_POWERS_FOR_CHARACTER(PlayerCharacter pc) { + public ConcurrentHashMap GET_POWERS_FOR_CHARACTER(PlayerCharacter pc) { - ConcurrentHashMap powers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - int objectUUID = pc.getObjectUUID(); + ConcurrentHashMap powers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + int objectUUID = pc.getObjectUUID(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_power` WHERE CharacterID = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_power` WHERE CharacterID = ?")) { - preparedStatement.setLong(1, (long) objectUUID); - ResultSet rs = preparedStatement.executeQuery(); + preparedStatement.setLong(1, objectUUID); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) { - CharacterPower cp = new CharacterPower(rs, pc); - if (cp.getPower() != null) - powers.put(cp.getPower().getToken(), cp); - } + while (rs.next()) { + CharacterPower cp = new CharacterPower(rs, pc); + if (cp.getPower() != null) + powers.put(cp.getPower().getToken(), cp); + } - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return powers; - } + return powers; + } - public void UPDATE_TRAINS(final CharacterPower characterPower) { + public void UPDATE_TRAINS(final CharacterPower characterPower) { - //skip update if nothing changed + //skip update if nothing changed - if (!characterPower.isTrained()) - return; + if (!characterPower.isTrained()) + return; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_power` SET `trains`=? WHERE `UID`=?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_power` SET `trains`=? WHERE `UID`=?")) { - preparedStatement.setShort(1, (short) characterPower.getTrains()); - preparedStatement.setInt(2, characterPower.getObjectUUID()); + preparedStatement.setShort(1, (short) characterPower.getTrains()); + preparedStatement.setInt(2, characterPower.getObjectUUID()); - preparedStatement.execute(); + preparedStatement.execute(); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - characterPower.setTrained(false); - } + characterPower.setTrained(false); + } - public void updateDatabase(final CharacterPower pow) { + public void updateDatabase(final CharacterPower pow) { - if (pow.getPower() == null) { - Logger.error("Failed to find powersBase for Power " + pow.getObjectUUID()); - return; - } + if (pow.getPower() == null) { + Logger.error("Failed to find powersBase for Power " + pow.getObjectUUID()); + return; + } - if (CharacterPower.getOwner(pow) == null) { - Logger.error("Failed to find owner for Power " + pow.getObjectUUID()); - return; - } + if (CharacterPower.getOwner(pow) == null) { + Logger.error("Failed to find owner for Power " + pow.getObjectUUID()); + return; + } - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_power` SET `PowersBaseToken`=?, `CharacterID`=?, `trains`=? WHERE `UID`=?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_power` SET `PowersBaseToken`=?, `CharacterID`=?, `trains`=? WHERE `UID`=?")) { - preparedStatement.setInt(1, pow.getPower().getToken()); - preparedStatement.setInt(2, CharacterPower.getOwner(pow).getObjectUUID()); - preparedStatement.setShort(3, (short) pow.getTrains()); - preparedStatement.setInt(4, pow.getObjectUUID()); - preparedStatement.execute(); + preparedStatement.setInt(1, pow.getPower().getToken()); + preparedStatement.setInt(2, CharacterPower.getOwner(pow).getObjectUUID()); + preparedStatement.setShort(3, (short) pow.getTrains()); + preparedStatement.setInt(4, pow.getObjectUUID()); + preparedStatement.execute(); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - pow.setTrained(false); - } + pow.setTrained(false); + } } diff --git a/src/engine/db/handlers/dbCharacterRuneHandler.java b/src/engine/db/handlers/dbCharacterRuneHandler.java index e708dcea..d63bc6d8 100644 --- a/src/engine/db/handlers/dbCharacterRuneHandler.java +++ b/src/engine/db/handlers/dbCharacterRuneHandler.java @@ -22,103 +22,103 @@ import java.util.ArrayList; public class dbCharacterRuneHandler extends dbHandlerBase { - public dbCharacterRuneHandler() { - this.localClass = CharacterRune.class; - this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); - } + public dbCharacterRuneHandler() { + this.localClass = CharacterRune.class; + this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); + } - public CharacterRune ADD_CHARACTER_RUNE(final CharacterRune toAdd) { + public CharacterRune ADD_CHARACTER_RUNE(final CharacterRune toAdd) { - CharacterRune characterRune = null; + CharacterRune characterRune = null; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_rune` (`CharacterID`, `RuneBaseID`) VALUES (?, ?);")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_rune` (`CharacterID`, `RuneBaseID`) VALUES (?, ?);")) { - preparedStatement.setLong(1, toAdd.getPlayerID()); - preparedStatement.setInt(2, toAdd.getRuneBaseID()); + preparedStatement.setLong(1, toAdd.getPlayerID()); + preparedStatement.setInt(2, toAdd.getRuneBaseID()); - preparedStatement.executeUpdate(); - ResultSet rs = preparedStatement.getGeneratedKeys(); + preparedStatement.executeUpdate(); + ResultSet rs = preparedStatement.getGeneratedKeys(); - if (rs.next()) - characterRune = GET_CHARACTER_RUNE(rs.getInt(1)); + if (rs.next()) + characterRune = GET_CHARACTER_RUNE(rs.getInt(1)); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return characterRune; - } + return characterRune; + } - public CharacterRune GET_CHARACTER_RUNE(int runeID) { + public CharacterRune GET_CHARACTER_RUNE(int runeID) { - CharacterRune characterRune = (CharacterRune) DbManager.getFromCache(Enum.GameObjectType.CharacterRune, runeID); + CharacterRune characterRune = (CharacterRune) DbManager.getFromCache(Enum.GameObjectType.CharacterRune, runeID); - if (characterRune != null) - return characterRune; + if (characterRune != null) + return characterRune; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_rune` WHERE `UID`=?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_rune` WHERE `UID`=?")) { - preparedStatement.setInt(1, runeID); - ResultSet rs = preparedStatement.executeQuery(); + preparedStatement.setInt(1, runeID); + ResultSet rs = preparedStatement.executeQuery(); - characterRune = (CharacterRune) getObjectFromRs(rs); + characterRune = (CharacterRune) getObjectFromRs(rs); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return characterRune; - } + return characterRune; + } - public boolean DELETE_CHARACTER_RUNE(final CharacterRune characterRune) { + public boolean DELETE_CHARACTER_RUNE(final CharacterRune characterRune) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_rune` WHERE `UID`=?;")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_rune` WHERE `UID`=?;")) { - preparedStatement.setLong(1, characterRune.getObjectUUID()); + preparedStatement.setLong(1, characterRune.getObjectUUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public ArrayList GET_RUNES_FOR_CHARACTER(final int characterId) { + public ArrayList GET_RUNES_FOR_CHARACTER(final int characterId) { - ArrayList characterRunes = new ArrayList<>(); + ArrayList characterRunes = new ArrayList<>(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_rune` WHERE `CharacterID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_rune` WHERE `CharacterID` = ?")) { - preparedStatement.setInt(1, characterId); + preparedStatement.setInt(1, characterId); - ResultSet rs = preparedStatement.executeQuery(); - characterRunes = getObjectsFromRs(rs, 10); + ResultSet rs = preparedStatement.executeQuery(); + characterRunes = getObjectsFromRs(rs, 10); - } catch (SQLException e) { - Logger.error(e); - } - return characterRunes; - } + } catch (SQLException e) { + Logger.error(e); + } + return characterRunes; + } - public void updateDatabase(final CharacterRune characterRune) { + public void updateDatabase(final CharacterRune characterRune) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_rune` SET `CharacterID`=?, `RuneBaseID`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_rune` SET `CharacterID`=?, `RuneBaseID`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, characterRune.getPlayerID()); - preparedStatement.setInt(2, characterRune.getRuneBaseID()); - preparedStatement.setLong(3, (long) characterRune.getObjectUUID()); + preparedStatement.setInt(1, characterRune.getPlayerID()); + preparedStatement.setInt(2, characterRune.getRuneBaseID()); + preparedStatement.setLong(3, characterRune.getObjectUUID()); - preparedStatement.execute(); + preparedStatement.execute(); - } catch (SQLException e) { - Logger.error(e); - } - } + } catch (SQLException e) { + Logger.error(e); + } + } } diff --git a/src/engine/db/handlers/dbCharacterSkillHandler.java b/src/engine/db/handlers/dbCharacterSkillHandler.java index c966b77e..fd46d5c5 100644 --- a/src/engine/db/handlers/dbCharacterSkillHandler.java +++ b/src/engine/db/handlers/dbCharacterSkillHandler.java @@ -134,7 +134,7 @@ public class dbCharacterSkillHandler extends dbHandlerBase { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_skill` SET `trains`=? WHERE `UID` = ?")) { preparedStatement.setShort(1, (short) characterSkill.getNumTrains()); - preparedStatement.setLong(2, (long) characterSkill.getObjectUUID()); + preparedStatement.setLong(2, characterSkill.getObjectUUID()); if (preparedStatement.executeUpdate() != 0) characterSkill.syncTrains(); @@ -162,7 +162,7 @@ public class dbCharacterSkillHandler extends dbHandlerBase { preparedStatement.setInt(1, characterSkill.getSkillsBase().getObjectUUID()); preparedStatement.setInt(2, CharacterSkill.GetOwner(characterSkill).getObjectUUID()); preparedStatement.setShort(3, (short) characterSkill.getNumTrains()); - preparedStatement.setLong(4, (long) characterSkill.getObjectUUID()); + preparedStatement.setLong(4, characterSkill.getObjectUUID()); if (preparedStatement.executeUpdate() != 0) characterSkill.syncTrains(); diff --git a/src/engine/db/handlers/dbEffectsBaseHandler.java b/src/engine/db/handlers/dbEffectsBaseHandler.java index 5b030993..de60587c 100644 --- a/src/engine/db/handlers/dbEffectsBaseHandler.java +++ b/src/engine/db/handlers/dbEffectsBaseHandler.java @@ -25,7 +25,7 @@ import java.util.HashSet; public class dbEffectsBaseHandler extends dbHandlerBase { - public dbEffectsBaseHandler() { + public dbEffectsBaseHandler() { } diff --git a/src/engine/db/handlers/dbEffectsResourceCostHandler.java b/src/engine/db/handlers/dbEffectsResourceCostHandler.java index 36e58b35..deae93a9 100644 --- a/src/engine/db/handlers/dbEffectsResourceCostHandler.java +++ b/src/engine/db/handlers/dbEffectsResourceCostHandler.java @@ -21,27 +21,27 @@ import java.util.ArrayList; public class dbEffectsResourceCostHandler extends dbHandlerBase { - public dbEffectsResourceCostHandler() { - this.localClass = EffectsResourceCosts.class; + public dbEffectsResourceCostHandler() { + this.localClass = EffectsResourceCosts.class; this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); - } - - public ArrayList GET_ALL_EFFECT_RESOURCES(String idString) { + } - ArrayList effectsResourceCosts = new ArrayList<>(); + public ArrayList GET_ALL_EFFECT_RESOURCES(String idString) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_power_effectcost` WHERE `IDString` = ?")) { + ArrayList effectsResourceCosts = new ArrayList<>(); - preparedStatement.setString(1, idString); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_power_effectcost` WHERE `IDString` = ?")) { - ResultSet rs = preparedStatement.executeQuery(); - effectsResourceCosts = getObjectsFromRs(rs, 1000); + preparedStatement.setString(1, idString); - } catch (SQLException e) { - Logger.error(e); - } + ResultSet rs = preparedStatement.executeQuery(); + effectsResourceCosts = getObjectsFromRs(rs, 1000); - return effectsResourceCosts; - } + } catch (SQLException e) { + Logger.error(e); + } + + return effectsResourceCosts; + } } diff --git a/src/engine/db/handlers/dbEnchantmentHandler.java b/src/engine/db/handlers/dbEnchantmentHandler.java index 1ba8c316..87e211de 100644 --- a/src/engine/db/handlers/dbEnchantmentHandler.java +++ b/src/engine/db/handlers/dbEnchantmentHandler.java @@ -21,55 +21,55 @@ import java.util.concurrent.ConcurrentHashMap; public class dbEnchantmentHandler extends dbHandlerBase { - public ConcurrentHashMap GET_ENCHANTMENTS_FOR_ITEM(final int id) { + public ConcurrentHashMap GET_ENCHANTMENTS_FOR_ITEM(final int id) { - ConcurrentHashMap enchants = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + ConcurrentHashMap enchants = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_item_enchantment` WHERE `ItemID`=?;")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_item_enchantment` WHERE `ItemID`=?;")) { - preparedStatement.setLong(1, id); + preparedStatement.setLong(1, id); - ResultSet rs = preparedStatement.executeQuery(); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) - enchants.put(rs.getString("powerAction"), rs.getInt("rank")); + while (rs.next()) + enchants.put(rs.getString("powerAction"), rs.getInt("rank")); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return enchants; - } + return enchants; + } - public boolean CREATE_ENCHANTMENT_FOR_ITEM(long itemID, String powerAction, int rank) { + public boolean CREATE_ENCHANTMENT_FOR_ITEM(long itemID, String powerAction, int rank) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_item_enchantment` (`itemID`, `powerAction`, `rank`) VALUES (?, ?, ?);")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_item_enchantment` (`itemID`, `powerAction`, `rank`) VALUES (?, ?, ?);")) { - preparedStatement.setLong(1, itemID); - preparedStatement.setString(2, powerAction); - preparedStatement.setInt(3, rank); + preparedStatement.setLong(1, itemID); + preparedStatement.setString(2, powerAction); + preparedStatement.setInt(3, rank); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean CLEAR_ENCHANTMENTS(long itemID) { + public boolean CLEAR_ENCHANTMENTS(long itemID) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_item_enchantment` WHERE `itemID`=?;")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_item_enchantment` WHERE `itemID`=?;")) { - preparedStatement.setLong(1, itemID); - return (preparedStatement.executeUpdate() > 0); + preparedStatement.setLong(1, itemID); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } } diff --git a/src/engine/db/handlers/dbGuildHandler.java b/src/engine/db/handlers/dbGuildHandler.java index b5a6dc70..d4917eef 100644 --- a/src/engine/db/handlers/dbGuildHandler.java +++ b/src/engine/db/handlers/dbGuildHandler.java @@ -22,679 +22,678 @@ import java.util.ArrayList; public class dbGuildHandler extends dbHandlerBase { - public dbGuildHandler() { - this.localClass = Guild.class; - this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); - } + public dbGuildHandler() { + this.localClass = Guild.class; + this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); + } - public int BANISH_FROM_GUILD_OFFLINE(final int target, boolean sourceIsGuildLeader) { + public static ArrayList GET_GUILD_BANISHED(final int id) { - String queryString; - int rowCount; + return new ArrayList<>(); - // Only a Guild Leader can remove inner council + // Bugfix + // prepareCallable("SELECT * FROM `obj_character`, `dyn_guild_banishlist` WHERE `obj_character.char_isActive` = 1 AND `dyn_guild_banishlist.CharacterID` = `obj_character.UID` AND `obj_character.GuildID`=?"); - if (sourceIsGuildLeader) - queryString = "UPDATE `obj_character` SET `guildUID`=NULL, `guild_isInnerCouncil`=0, `guild_isTaxCollector`=0," - + " `guild_isRecruiter`=0, `guild_isFullMember`=0, `guild_title`=0 WHERE `UID`=?"; - else - queryString = "UPDATE `obj_character` SET `guildUID`=NULL, `guild_isInnerCouncil`=0, `guild_isTaxCollector`=0," - + " `guild_isRecruiter`=0, `guild_isFullMember`=0, `guild_title`=0 WHERE `UID`=? && `guild_isInnerCouncil`=0"; + //prepareCallable("SELECT * FROM `obj_character` `,` `dyn_guild_banishlist` WHERE obj_character.char_isActive = 1 AND dyn_guild_banishlist.CharacterID = obj_character.UID AND dyn_guild_banishlist.GuildID = ?"); + //setLong(1, (long) id); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement(queryString)) { + //return getObjectList(); + } - preparedStatement.setLong(1, target); - rowCount = preparedStatement.executeUpdate(); + public static void LOAD_GUILD_HISTORY_FOR_PLAYER(PlayerCharacter playerCharacter) { - } catch (SQLException e) { - Logger.error(e); - return 0; - } + if (playerCharacter == null) + return; - return rowCount; - } + ArrayList guildList = new ArrayList<>(); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_guild_allianceenemylist` WHERE `GuildID` = ?")) { - public boolean ADD_TO_BANISHED_FROM_GUILDLIST(int target, long characterID) { + preparedStatement.setInt(1, playerCharacter.getObjectUUID()); + ResultSet rs = preparedStatement.executeQuery(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_guild_banishlist` (`GuildID`, `CharacterID`) VALUES (?,?)")) { + while (rs.next()) { + GuildHistory guildEntry = new GuildHistory(rs); + guildList.add(guildEntry); + } - preparedStatement.setLong(1, (long) target); - preparedStatement.setLong(2, characterID); + } catch (SQLException e) { + Logger.error(e); + } - return (preparedStatement.executeUpdate() > 0); + playerCharacter.setGuildHistory(guildList); + } - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + public int BANISH_FROM_GUILD_OFFLINE(final int target, boolean sourceIsGuildLeader) { - public boolean REMOVE_FROM_BANISH_LIST(int target, long characterID) { + String queryString; + int rowCount; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_guild_banishlist` (`GuildID`, `CharacterID`) VALUES (?,?)")) { + // Only a Guild Leader can remove inner council - preparedStatement.setLong(1, (long) target); - preparedStatement.setLong(2, characterID); + if (sourceIsGuildLeader) + queryString = "UPDATE `obj_character` SET `guildUID`=NULL, `guild_isInnerCouncil`=0, `guild_isTaxCollector`=0," + + " `guild_isRecruiter`=0, `guild_isFullMember`=0, `guild_title`=0 WHERE `UID`=?"; + else + queryString = "UPDATE `obj_character` SET `guildUID`=NULL, `guild_isInnerCouncil`=0, `guild_isTaxCollector`=0," + + " `guild_isRecruiter`=0, `guild_isFullMember`=0, `guild_title`=0 WHERE `UID`=? && `guild_isInnerCouncil`=0"; - return (preparedStatement.executeUpdate() > 0); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement(queryString)) { - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + preparedStatement.setLong(1, target); + rowCount = preparedStatement.executeUpdate(); - public boolean ADD_TO_GUILDHISTORY(int target, PlayerCharacter playerCharacter, DateTime historyDate, GuildHistoryType historyType) { + } catch (SQLException e) { + Logger.error(e); + return 0; + } - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_guildhistory` (`GuildID`, `CharacterID`, `historyDate`, `historyType`) VALUES (?,?,?,?)")) { + return rowCount; + } - preparedStatement.setLong(1, target); - preparedStatement.setLong(2, playerCharacter.getObjectUUID()); + public boolean ADD_TO_BANISHED_FROM_GUILDLIST(int target, long characterID) { - if (historyDate == null) - preparedStatement.setNull(3, java.sql.Types.DATE); - else - preparedStatement.setTimestamp(3, new Timestamp(historyDate.getMillis())); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_guild_banishlist` (`GuildID`, `CharacterID`) VALUES (?,?)")) { - preparedStatement.setString(4, historyType.name()); + preparedStatement.setLong(1, target); + preparedStatement.setLong(2, characterID); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - //TODO Need to get this working. - public ArrayList GET_GUILD_HISTORY_OF_PLAYER(final int id) { + public boolean REMOVE_FROM_BANISH_LIST(int target, long characterID) { - ArrayList guildList = null; + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_guild_banishlist` (`GuildID`, `CharacterID`) VALUES (?,?)")) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT g.* FROM `obj_guild` g, `dyn_character_guildhistory` l WHERE g.`UID` = l.`GuildID` && l.`CharacterID` = ?")) { + preparedStatement.setLong(1, target); + preparedStatement.setLong(2, characterID); - preparedStatement.setLong(1, id); + return (preparedStatement.executeUpdate() > 0); - ResultSet rs = preparedStatement.executeQuery(); - guildList = getObjectsFromRs(rs, 20); + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - } catch (SQLException e) { - Logger.error(e); - } + public boolean ADD_TO_GUILDHISTORY(int target, PlayerCharacter playerCharacter, DateTime historyDate, GuildHistoryType historyType) { - return guildList; - } + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_guildhistory` (`GuildID`, `CharacterID`, `historyDate`, `historyType`) VALUES (?,?,?,?)")) { - public ArrayList GET_GUILD_ALLIES(final int id) { + preparedStatement.setLong(1, target); + preparedStatement.setLong(2, playerCharacter.getObjectUUID()); - ArrayList guildList = null; + if (historyDate == null) + preparedStatement.setNull(3, java.sql.Types.DATE); + else + preparedStatement.setTimestamp(3, new Timestamp(historyDate.getMillis())); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT g.* FROM `obj_guild` g, `dyn_guild_allianceenemylist` l " - + "WHERE l.isAlliance = 1 && l.OtherGuildID = g.UID && l.GuildID=?")) { + preparedStatement.setString(4, historyType.name()); - preparedStatement.setLong(1, id); + return (preparedStatement.executeUpdate() > 0); - ResultSet rs = preparedStatement.executeQuery(); - guildList = getObjectsFromRs(rs, 20); + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - } catch (SQLException e) { - Logger.error(e); - } + //TODO Need to get this working. + public ArrayList GET_GUILD_HISTORY_OF_PLAYER(final int id) { - return guildList; + ArrayList guildList = null; - } + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT g.* FROM `obj_guild` g, `dyn_character_guildhistory` l WHERE g.`UID` = l.`GuildID` && l.`CharacterID` = ?")) { - public static ArrayList GET_GUILD_BANISHED(final int id) { + preparedStatement.setLong(1, id); - return new ArrayList<>(); + ResultSet rs = preparedStatement.executeQuery(); + guildList = getObjectsFromRs(rs, 20); - // Bugfix - // prepareCallable("SELECT * FROM `obj_character`, `dyn_guild_banishlist` WHERE `obj_character.char_isActive` = 1 AND `dyn_guild_banishlist.CharacterID` = `obj_character.UID` AND `obj_character.GuildID`=?"); + } catch (SQLException e) { + Logger.error(e); + } - //prepareCallable("SELECT * FROM `obj_character` `,` `dyn_guild_banishlist` WHERE obj_character.char_isActive = 1 AND dyn_guild_banishlist.CharacterID = obj_character.UID AND dyn_guild_banishlist.GuildID = ?"); - //setLong(1, (long) id); + return guildList; + } - //return getObjectList(); - } + public ArrayList GET_GUILD_ALLIES(final int id) { - public ArrayList GET_GUILD_ENEMIES(final int id) { + ArrayList guildList = null; - ArrayList guildList = null; + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT g.* FROM `obj_guild` g, `dyn_guild_allianceenemylist` l " + + "WHERE l.isAlliance = 1 && l.OtherGuildID = g.UID && l.GuildID=?")) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT g.* FROM `obj_guild` g, `dyn_guild_allianceenemylist` l " - + "WHERE l.isAlliance = 0 && l.OtherGuildID = g.UID && l.GuildID=?")) { + preparedStatement.setLong(1, id); - preparedStatement.setLong(1, id); + ResultSet rs = preparedStatement.executeQuery(); + guildList = getObjectsFromRs(rs, 20); - ResultSet rs = preparedStatement.executeQuery(); - guildList = getObjectsFromRs(rs, 20); + } catch (SQLException e) { + Logger.error(e); + } - } catch (SQLException e) { - Logger.error(e); - } + return guildList; - return guildList; + } - } + public ArrayList GET_GUILD_ENEMIES(final int id) { - public ArrayList GET_GUILD_KOS_CHARACTER(final int id) { + ArrayList guildList = null; - ArrayList kosList = null; + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT g.* FROM `obj_guild` g, `dyn_guild_allianceenemylist` l " + + "WHERE l.isAlliance = 0 && l.OtherGuildID = g.UID && l.GuildID=?")) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT c.* FROM `obj_character` c, `dyn_guild_characterkoslist` l WHERE c.`char_isActive` = 1 && l.`KOSCharacterID` = c.`UID` && l.`GuildID`=?")) { + preparedStatement.setLong(1, id); - preparedStatement.setLong(1, id); - ResultSet rs = preparedStatement.executeQuery(); + ResultSet rs = preparedStatement.executeQuery(); + guildList = getObjectsFromRs(rs, 20); - while (rs.next()) { - int playerUUID = rs.getInt(1); - PlayerCharacter kosPlayer = PlayerCharacter.getPlayerCharacter(playerUUID); + } catch (SQLException e) { + Logger.error(e); + } - if (kosPlayer != null) - kosList.add(kosPlayer); - } + return guildList; - } catch (SQLException e) { - Logger.error(e); - } + } - return kosList; - } + public ArrayList GET_GUILD_KOS_CHARACTER(final int id) { - public ArrayList GET_GUILD_KOS_GUILD(final int id) { + ArrayList kosList = null; - ArrayList guildList = null; + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT c.* FROM `obj_character` c, `dyn_guild_characterkoslist` l WHERE c.`char_isActive` = 1 && l.`KOSCharacterID` = c.`UID` && l.`GuildID`=?")) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT g.* FROM `obj_guild` g, `dyn_guild_guildkoslist` l " - + "WHERE l.KOSGuildID = g.UID && l.GuildID = ?")) { + preparedStatement.setLong(1, id); + ResultSet rs = preparedStatement.executeQuery(); - preparedStatement.setLong(1, id); + while (rs.next()) { + int playerUUID = rs.getInt(1); + PlayerCharacter kosPlayer = PlayerCharacter.getPlayerCharacter(playerUUID); - ResultSet rs = preparedStatement.executeQuery(); - guildList = getObjectsFromRs(rs, 20); + if (kosPlayer != null) + kosList.add(kosPlayer); + } - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return guildList; - } + return kosList; + } - public ArrayList GET_SUB_GUILDS(final int guildID) { + public ArrayList GET_GUILD_KOS_GUILD(final int id) { - ArrayList guildList = null; + ArrayList guildList = null; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_guild`.*, `object`.`parent` FROM `object` INNER JOIN `obj_guild` ON `obj_guild`.`UID` = `object`.`UID` WHERE `object`.`parent` = ?;")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT g.* FROM `obj_guild` g, `dyn_guild_guildkoslist` l " + + "WHERE l.KOSGuildID = g.UID && l.GuildID = ?")) { - preparedStatement.setInt(1, guildID); + preparedStatement.setLong(1, id); - ResultSet rs = preparedStatement.executeQuery(); - guildList = getObjectsFromRs(rs, 20); + ResultSet rs = preparedStatement.executeQuery(); + guildList = getObjectsFromRs(rs, 20); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return guildList; - } + return guildList; + } - public Guild GET_GUILD(int id) { + public ArrayList GET_SUB_GUILDS(final int guildID) { - Guild guild = (Guild) DbManager.getFromCache(Enum.GameObjectType.Guild, id); + ArrayList guildList = null; - if (guild != null) - return guild; + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_guild`.*, `object`.`parent` FROM `object` INNER JOIN `obj_guild` ON `obj_guild`.`UID` = `object`.`UID` WHERE `object`.`parent` = ?;")) { - if (id == 0) - return Guild.getErrantGuild(); + preparedStatement.setInt(1, guildID); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_guild`.*, `object`.`parent` FROM `obj_guild` INNER JOIN `object` ON `object`.`UID` = `obj_guild`.`UID` WHERE `object`.`UID`=?")) { + ResultSet rs = preparedStatement.executeQuery(); + guildList = getObjectsFromRs(rs, 20); - preparedStatement.setLong(1, id); + } catch (SQLException e) { + Logger.error(e); + } - ResultSet rs = preparedStatement.executeQuery(); - guild = (Guild) getObjectFromRs(rs); + return guildList; + } - } catch (SQLException e) { - Logger.error(e); - } - return guild; + public Guild GET_GUILD(int id) { - } - - public ArrayList GET_ALL_GUILDS() { + Guild guild = (Guild) DbManager.getFromCache(Enum.GameObjectType.Guild, id); - ArrayList guildList = null; + if (guild != null) + return guild; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_guild`.*, `object`.`parent` FROM `obj_guild` INNER JOIN `object` ON `object`.`UID` = `obj_guild`.`UID`")) { + if (id == 0) + return Guild.getErrantGuild(); - ResultSet rs = preparedStatement.executeQuery(); - guildList = getObjectsFromRs(rs, 20); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_guild`.*, `object`.`parent` FROM `obj_guild` INNER JOIN `object` ON `object`.`UID` = `obj_guild`.`UID` WHERE `object`.`UID`=?")) { - } catch (SQLException e) { - Logger.error(e); - } - return guildList; - } + preparedStatement.setLong(1, id); - public boolean IS_CREST_UNIQUE(final GuildTag gt) { + ResultSet rs = preparedStatement.executeQuery(); + guild = (Guild) getObjectFromRs(rs); - boolean valid = false; - String queryString; + } catch (SQLException e) { + Logger.error(e); + } + return guild; - // Ignore bg symbol if bg color is the same as fg color. + } - if (gt.backgroundColor01 == gt.backgroundColor02) - queryString = "SELECT `name` FROM `obj_guild` WHERE `backgroundColor01`=? && `backgroundColor02`=? && `symbolColor`=? && `symbol`=?;"; - else - queryString = "SELECT `name` FROM `obj_guild` WHERE `backgroundColor01`=? && `backgroundColor02`=? && `symbolColor`=? && `backgroundDesign`=? && `symbol`=?;"; + public ArrayList GET_ALL_GUILDS() { + ArrayList guildList = null; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement(queryString)) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_guild`.*, `object`.`parent` FROM `obj_guild` INNER JOIN `object` ON `object`.`UID` = `obj_guild`.`UID`")) { - if (gt.backgroundColor01 == gt.backgroundColor02) { - preparedStatement.setInt(1, gt.backgroundColor01); - preparedStatement.setInt(2, gt.backgroundColor02); - preparedStatement.setInt(3, gt.symbolColor); - preparedStatement.setInt(4, gt.symbol); - } else { - preparedStatement.setInt(1, gt.backgroundColor01); - preparedStatement.setInt(2, gt.backgroundColor02); - preparedStatement.setInt(3, gt.symbolColor); - preparedStatement.setInt(4, gt.backgroundDesign); - preparedStatement.setInt(5, gt.symbol); - } + ResultSet rs = preparedStatement.executeQuery(); + guildList = getObjectsFromRs(rs, 20); - ResultSet rs = preparedStatement.executeQuery(); + } catch (SQLException e) { + Logger.error(e); + } + return guildList; + } - if (!rs.next()) - valid = true; + public boolean IS_CREST_UNIQUE(final GuildTag gt) { - } catch (SQLException e) { - Logger.error(e); - } + boolean valid = false; + String queryString; - return valid; - } + // Ignore bg symbol if bg color is the same as fg color. - public boolean SET_GUILD_OWNED_CITY(int guildID, int cityID) { + if (gt.backgroundColor01 == gt.backgroundColor02) + queryString = "SELECT `name` FROM `obj_guild` WHERE `backgroundColor01`=? && `backgroundColor02`=? && `symbolColor`=? && `symbol`=?;"; + else + queryString = "SELECT `name` FROM `obj_guild` WHERE `backgroundColor01`=? && `backgroundColor02`=? && `symbolColor`=? && `backgroundDesign`=? && `symbol`=?;"; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_guild` SET `ownedCity`=? WHERE `UID`=?")) { - preparedStatement.setLong(1, cityID); - preparedStatement.setLong(2, guildID); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement(queryString)) { - return (preparedStatement.executeUpdate() > 0); + if (gt.backgroundColor01 == gt.backgroundColor02) { + preparedStatement.setInt(1, gt.backgroundColor01); + preparedStatement.setInt(2, gt.backgroundColor02); + preparedStatement.setInt(3, gt.symbolColor); + preparedStatement.setInt(4, gt.symbol); + } else { + preparedStatement.setInt(1, gt.backgroundColor01); + preparedStatement.setInt(2, gt.backgroundColor02); + preparedStatement.setInt(3, gt.symbolColor); + preparedStatement.setInt(4, gt.backgroundDesign); + preparedStatement.setInt(5, gt.symbol); + } - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + ResultSet rs = preparedStatement.executeQuery(); - public boolean SET_GUILD_LEADER(int objectUUID,int guildID) { + if (!rs.next()) + valid = true; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_guild` SET `leaderUID`=? WHERE `UID`=?")) { + } catch (SQLException e) { + Logger.error(e); + } - preparedStatement.setLong(1, objectUUID); - preparedStatement.setLong(2, guildID); + return valid; + } - return (preparedStatement.executeUpdate() > 0); + public boolean SET_GUILD_OWNED_CITY(int guildID, int cityID) { - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_guild` SET `ownedCity`=? WHERE `UID`=?")) { - public boolean IS_NAME_UNIQUE(final String name) { + preparedStatement.setLong(1, cityID); + preparedStatement.setLong(2, guildID); - boolean valid = false; + return (preparedStatement.executeUpdate() > 0); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `name` FROM `obj_guild` WHERE `name`=?;")) { + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - preparedStatement.setString(1, name); - ResultSet rs = preparedStatement.executeQuery(); + public boolean SET_GUILD_LEADER(int objectUUID, int guildID) { - if (!rs.next()) - valid = true; + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_guild` SET `leaderUID`=? WHERE `UID`=?")) { - } catch (SQLException e) { - Logger.error(e); - } + preparedStatement.setLong(1, objectUUID); + preparedStatement.setLong(2, guildID); - return valid; - } + return (preparedStatement.executeUpdate() > 0); - public Guild SAVE_TO_DATABASE(Guild g) { + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - Guild guild = null; - GuildTag guildTag = g.getGuildTag(); + public boolean IS_NAME_UNIQUE(final String name) { - if (guildTag == null) - return null; + boolean valid = false; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("CALL `guild_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT `name` FROM `obj_guild` WHERE `name`=?;")) { - preparedStatement.setLong(1, MBServerStatics.worldUUID); - preparedStatement.setLong(2, g.getGuildLeaderUUID()); - preparedStatement.setString(3, g.getName()); - preparedStatement.setInt(4, guildTag.backgroundColor01); - preparedStatement.setInt(5, guildTag.backgroundColor02); - preparedStatement.setInt(6, guildTag.symbolColor); - preparedStatement.setInt(7, guildTag.backgroundDesign); - preparedStatement.setInt(8, guildTag.symbol); - preparedStatement.setInt(9, g.getCharter()); - preparedStatement.setString(10, g.getLeadershipType()); - preparedStatement.setString(11, g.getMotto()); + preparedStatement.setString(1, name); + ResultSet rs = preparedStatement.executeQuery(); - ResultSet rs = preparedStatement.executeQuery(); + if (!rs.next()) + valid = true; - int objectUUID = (int) rs.getLong("UID"); + } catch (SQLException e) { + Logger.error(e); + } - if (objectUUID > 0) - guild = GET_GUILD(objectUUID); + return valid; + } - } catch (SQLException e) { - Logger.error(e); - } - return guild; - } + public Guild SAVE_TO_DATABASE(Guild g) { - public boolean UPDATE_GUILD_RANK_OFFLINE(int target, int newRank, int guildId) { + Guild guild = null; + GuildTag guildTag = g.getGuildTag(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_title`=? WHERE `UID`=? && `guildUID`=?")) { + if (guildTag == null) + return null; - preparedStatement.setInt(1, newRank); - preparedStatement.setInt(2, target); - preparedStatement.setInt(3, guildId); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("CALL `guild_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) { - return (preparedStatement.executeUpdate() > 0); + preparedStatement.setLong(1, MBServerStatics.worldUUID); + preparedStatement.setLong(2, g.getGuildLeaderUUID()); + preparedStatement.setString(3, g.getName()); + preparedStatement.setInt(4, guildTag.backgroundColor01); + preparedStatement.setInt(5, guildTag.backgroundColor02); + preparedStatement.setInt(6, guildTag.symbolColor); + preparedStatement.setInt(7, guildTag.backgroundDesign); + preparedStatement.setInt(8, guildTag.symbol); + preparedStatement.setInt(9, g.getCharter()); + preparedStatement.setString(10, g.getLeadershipType()); + preparedStatement.setString(11, g.getMotto()); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + ResultSet rs = preparedStatement.executeQuery(); - public boolean UPDATE_PARENT(int guildUID, int parentUID) { + int objectUUID = (int) rs.getLong("UID"); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `object` SET `parent`=? WHERE `UID`=?")) { + if (objectUUID > 0) + guild = GET_GUILD(objectUUID); - preparedStatement.setInt(1, parentUID); - preparedStatement.setInt(2, guildUID); + } catch (SQLException e) { + Logger.error(e); + } + return guild; + } - return (preparedStatement.executeUpdate() > 0); + public boolean UPDATE_GUILD_RANK_OFFLINE(int target, int newRank, int guildId) { - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_title`=? WHERE `UID`=? && `guildUID`=?")) { - public int DELETE_GUILD(final Guild guild) { + preparedStatement.setInt(1, newRank); + preparedStatement.setInt(2, target); + preparedStatement.setInt(3, guildId); - int row_count = 0; + return (preparedStatement.executeUpdate() > 0); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `UID` = ?")) { + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - preparedStatement.setLong(1, guild.getObjectUUID()); - row_count = preparedStatement.executeUpdate(); + public boolean UPDATE_PARENT(int guildUID, int parentUID) { - } catch (SQLException e) { - Logger.error(e); - } - return row_count; - } + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `object` SET `parent`=? WHERE `UID`=?")) { - public boolean UPDATE_MINETIME(int guildUID, int mineTime) { + preparedStatement.setInt(1, parentUID); + preparedStatement.setInt(2, guildUID); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_guild` SET `mineTime`=? WHERE `UID`=?")) { + return (preparedStatement.executeUpdate() > 0); - preparedStatement.setInt(1, mineTime); - preparedStatement.setInt(2, guildUID); + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - return (preparedStatement.executeUpdate() > 0); + public int DELETE_GUILD(final Guild guild) { - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + int row_count = 0; - public int UPDATE_GUILD_STATUS_OFFLINE(int target, boolean isInnerCouncil, boolean isRecruiter, boolean isTaxCollector, int guildId) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `UID` = ?")) { - int updateMask = 0; - int row_count = 0; + preparedStatement.setLong(1, guild.getObjectUUID()); + row_count = preparedStatement.executeUpdate(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `guild_isInnerCouncil`, `guild_isTaxCollector`, `guild_isRecruiter` FROM `obj_character` WHERE `UID`=? && `guildUID`=?")) { + } catch (SQLException e) { + Logger.error(e); + } + return row_count; + } - preparedStatement.setLong(1, target); - preparedStatement.setLong(2, guildId); + public boolean UPDATE_MINETIME(int guildUID, int mineTime) { - ResultSet rs = preparedStatement.executeQuery(); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_guild` SET `mineTime`=? WHERE `UID`=?")) { - //If the first query had no results, neither will the second + preparedStatement.setInt(1, mineTime); + preparedStatement.setInt(2, guildUID); - //Determine what is different + return (preparedStatement.executeUpdate() > 0); - if (rs.first()) { - if (rs.getBoolean("guild_isInnerCouncil") != isInnerCouncil) - updateMask |= 4; - if (rs.getBoolean("guild_isRecruiter") != isRecruiter) - updateMask |= 2; - if (rs.getBoolean("guild_isTaxCollector") != isTaxCollector) - updateMask |= 1; - } - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isInnerCouncil`=?, `guild_isTaxCollector`=?, `guild_isRecruiter`=?, `guild_isFullMember`=? WHERE `UID`=? && `guildUID`=?")) { - preparedStatement.setBoolean(1, isInnerCouncil); - preparedStatement.setBoolean(2, isRecruiter); - preparedStatement.setBoolean(3, isTaxCollector); - preparedStatement.setBoolean(4, ((updateMask > 0))); //If you are becoming an officer, or where an officer, your a full member... - preparedStatement.setLong(5, target); - preparedStatement.setLong(6, guildId); + // *** Refactor: Why are we saving tags/charter in update? + // It's not like this shit ever changes. - row_count = preparedStatement.executeUpdate(); + public int UPDATE_GUILD_STATUS_OFFLINE(int target, boolean isInnerCouncil, boolean isRecruiter, boolean isTaxCollector, int guildId) { - } catch (SQLException e) { - Logger.error(e); - } - return row_count; - } + int updateMask = 0; + int row_count = 0; + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT `guild_isInnerCouncil`, `guild_isTaxCollector`, `guild_isRecruiter` FROM `obj_character` WHERE `UID`=? && `guildUID`=?")) { - // *** Refactor: Why are we saving tags/charter in update? - // It's not like this shit ever changes. + preparedStatement.setLong(1, target); + preparedStatement.setLong(2, guildId); - public boolean updateDatabase(final Guild g) { + ResultSet rs = preparedStatement.executeQuery(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_guild` SET `name`=?, `backgroundColor01`=?, `backgroundColor02`=?, `symbolColor`=?, `backgroundDesign`=?, `symbol`=?, `charter`=?, `motd`=?, `icMotd`=?, `nationMotd`=?, `leaderUID`=? WHERE `UID`=?")) { + //If the first query had no results, neither will the second - preparedStatement.setString(1, g.getName()); - preparedStatement.setInt(2, g.getGuildTag().backgroundColor01); - preparedStatement.setInt(3, g.getGuildTag().backgroundColor02); - preparedStatement.setInt(4, g.getGuildTag().symbolColor); - preparedStatement.setInt(5, g.getGuildTag().backgroundDesign); - preparedStatement.setInt(6, g.getGuildTag().symbol); - preparedStatement.setInt(7, g.getCharter()); - preparedStatement.setString(8, g.getMOTD()); - preparedStatement.setString(9, g.getICMOTD()); - preparedStatement.setString(10, ""); - preparedStatement.setInt(11, g.getGuildLeaderUUID()); - preparedStatement.setLong(12, (long) g.getObjectUUID()); + //Determine what is different - return (preparedStatement.executeUpdate() > 0); + if (rs.first()) { + if (rs.getBoolean("guild_isInnerCouncil") != isInnerCouncil) + updateMask |= 4; + if (rs.getBoolean("guild_isRecruiter") != isRecruiter) + updateMask |= 2; + if (rs.getBoolean("guild_isTaxCollector") != isTaxCollector) + updateMask |= 1; + } + } catch (SQLException e) { + Logger.error(e); + } - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isInnerCouncil`=?, `guild_isTaxCollector`=?, `guild_isRecruiter`=?, `guild_isFullMember`=? WHERE `UID`=? && `guildUID`=?")) { - public boolean ADD_TO_ALLIANCE_LIST(final long sourceGuildID, final long targetGuildID, boolean isRecommended, boolean isAlly, String recommender) { + preparedStatement.setBoolean(1, isInnerCouncil); + preparedStatement.setBoolean(2, isRecruiter); + preparedStatement.setBoolean(3, isTaxCollector); + preparedStatement.setBoolean(4, ((updateMask > 0))); //If you are becoming an officer, or where an officer, your a full member... + preparedStatement.setLong(5, target); + preparedStatement.setLong(6, guildId); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_guild_allianceenemylist` (`GuildID`, `OtherGuildID`,`isRecommended`, `isAlliance`, `recommender`) VALUES (?,?,?,?,?)")) { + row_count = preparedStatement.executeUpdate(); - preparedStatement.setLong(1, sourceGuildID); - preparedStatement.setLong(2, targetGuildID); - preparedStatement.setBoolean(3, isRecommended); - preparedStatement.setBoolean(4, isAlly); - preparedStatement.setString(5, recommender); + } catch (SQLException e) { + Logger.error(e); + } + return row_count; + } - return (preparedStatement.executeUpdate() > 0); + public boolean updateDatabase(final Guild g) { - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_guild` SET `name`=?, `backgroundColor01`=?, `backgroundColor02`=?, `symbolColor`=?, `backgroundDesign`=?, `symbol`=?, `charter`=?, `motd`=?, `icMotd`=?, `nationMotd`=?, `leaderUID`=? WHERE `UID`=?")) { - public boolean REMOVE_FROM_ALLIANCE_LIST(final long sourceGuildID, long targetGuildID) { + preparedStatement.setString(1, g.getName()); + preparedStatement.setInt(2, g.getGuildTag().backgroundColor01); + preparedStatement.setInt(3, g.getGuildTag().backgroundColor02); + preparedStatement.setInt(4, g.getGuildTag().symbolColor); + preparedStatement.setInt(5, g.getGuildTag().backgroundDesign); + preparedStatement.setInt(6, g.getGuildTag().symbol); + preparedStatement.setInt(7, g.getCharter()); + preparedStatement.setString(8, g.getMOTD()); + preparedStatement.setString(9, g.getICMOTD()); + preparedStatement.setString(10, ""); + preparedStatement.setInt(11, g.getGuildLeaderUUID()); + preparedStatement.setLong(12, g.getObjectUUID()); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_guild_allianceenemylist` WHERE `GuildID`=? AND `OtherGuildID`=?")) { + return (preparedStatement.executeUpdate() > 0); - preparedStatement.setLong(1, sourceGuildID); - preparedStatement.setLong(2, targetGuildID); + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - return (preparedStatement.executeUpdate() > 0); + public boolean ADD_TO_ALLIANCE_LIST(final long sourceGuildID, final long targetGuildID, boolean isRecommended, boolean isAlly, String recommender) { - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_guild_allianceenemylist` (`GuildID`, `OtherGuildID`,`isRecommended`, `isAlliance`, `recommender`) VALUES (?,?,?,?,?)")) { - public boolean UPDATE_RECOMMENDED(final long sourceGuildID, long targetGuildID) { + preparedStatement.setLong(1, sourceGuildID); + preparedStatement.setLong(2, targetGuildID); + preparedStatement.setBoolean(3, isRecommended); + preparedStatement.setBoolean(4, isAlly); + preparedStatement.setString(5, recommender); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_guild_allianceenemylist` SET `isRecommended` = ? WHERE `GuildID`=? AND `OtherGuildID`=?")) { + return (preparedStatement.executeUpdate() > 0); - preparedStatement.setLong(1, sourceGuildID); - preparedStatement.setLong(2, targetGuildID); + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - return (preparedStatement.executeUpdate() > 0); + public boolean REMOVE_FROM_ALLIANCE_LIST(final long sourceGuildID, long targetGuildID) { - } catch (SQLException e) { - Logger.error(e); - return false; - } - } + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_guild_allianceenemylist` WHERE `GuildID`=? AND `OtherGuildID`=?")) { - public boolean UPDATE_ALLIANCE(final long sourceGuildID, long targetGuildID, boolean isAlly) { + preparedStatement.setLong(1, sourceGuildID); + preparedStatement.setLong(2, targetGuildID); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_guild_allianceenemylist` SET `isAlliance` = ? WHERE `GuildID`=? AND `OtherGuildID`=?")) { + return (preparedStatement.executeUpdate() > 0); - preparedStatement.setLong(1, sourceGuildID); - preparedStatement.setLong(2, targetGuildID); + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - return (preparedStatement.executeUpdate() > 0); + public boolean UPDATE_RECOMMENDED(final long sourceGuildID, long targetGuildID) { - } catch (SQLException e) { - Logger.error(e); - return false; - } - } + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_guild_allianceenemylist` SET `isRecommended` = ? WHERE `GuildID`=? AND `OtherGuildID`=?")) { - public boolean UPDATE_ALLIANCE_AND_RECOMMENDED(final long sourceGuildID, long targetGuildID, boolean isAlly) { + preparedStatement.setLong(1, sourceGuildID); + preparedStatement.setLong(2, targetGuildID); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_guild_allianceenemylist` SET `isRecommended` = ?, `isAlliance` = ? WHERE `GuildID`=? AND `OtherGuildID`=?")) { + return (preparedStatement.executeUpdate() > 0); - preparedStatement.setByte(1, (byte) 0); - preparedStatement.setBoolean(2, isAlly); - preparedStatement.setLong(3, sourceGuildID); - preparedStatement.setLong(4, targetGuildID); + } catch (SQLException e) { + Logger.error(e); + return false; + } + } - return (preparedStatement.executeUpdate() > 0); + public boolean UPDATE_ALLIANCE(final long sourceGuildID, long targetGuildID, boolean isAlly) { - } catch (SQLException e) { - Logger.error(e); - return false; - } + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_guild_allianceenemylist` SET `isAlliance` = ? WHERE `GuildID`=? AND `OtherGuildID`=?")) { - } + preparedStatement.setLong(1, sourceGuildID); + preparedStatement.setLong(2, targetGuildID); - public void LOAD_ALL_ALLIANCES_FOR_GUILD(Guild guild) { + return (preparedStatement.executeUpdate() > 0); - if (guild == null) - return; + } catch (SQLException e) { + Logger.error(e); + return false; + } + } - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_guild_allianceenemylist` WHERE `GuildID` = ?")) { + public boolean UPDATE_ALLIANCE_AND_RECOMMENDED(final long sourceGuildID, long targetGuildID, boolean isAlly) { - preparedStatement.setInt(1, guild.getObjectUUID()); - ResultSet rs = preparedStatement.executeQuery(); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_guild_allianceenemylist` SET `isRecommended` = ?, `isAlliance` = ? WHERE `GuildID`=? AND `OtherGuildID`=?")) { - while (rs.next()) { - GuildAlliances guildAlliance = new GuildAlliances(rs); - guild.guildAlliances.put(guildAlliance.getAllianceGuild(), guildAlliance); - } + preparedStatement.setByte(1, (byte) 0); + preparedStatement.setBoolean(2, isAlly); + preparedStatement.setLong(3, sourceGuildID); + preparedStatement.setLong(4, targetGuildID); - } catch (SQLException e) { - Logger.error(e); - } - } + return (preparedStatement.executeUpdate() > 0); - public static void LOAD_GUILD_HISTORY_FOR_PLAYER(PlayerCharacter playerCharacter) { + } catch (SQLException e) { + Logger.error(e); + return false; + } - if (playerCharacter == null) - return; + } - ArrayList guildList = new ArrayList<>(); + public void LOAD_ALL_ALLIANCES_FOR_GUILD(Guild guild) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_guild_allianceenemylist` WHERE `GuildID` = ?")) { + if (guild == null) + return; - preparedStatement.setInt(1, playerCharacter.getObjectUUID()); - ResultSet rs = preparedStatement.executeQuery(); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_guild_allianceenemylist` WHERE `GuildID` = ?")) { - while (rs.next()) { - GuildHistory guildEntry = new GuildHistory(rs); - guildList.add(guildEntry); - } + preparedStatement.setInt(1, guild.getObjectUUID()); + ResultSet rs = preparedStatement.executeQuery(); - } catch (SQLException e) { - Logger.error(e); - } + while (rs.next()) { + GuildAlliances guildAlliance = new GuildAlliances(rs); + guild.guildAlliances.put(guildAlliance.getAllianceGuild(), guildAlliance); + } - playerCharacter.setGuildHistory(guildList); - } - - //TODO uncomment this when finished with guild history warehouse integration + } catch (SQLException e) { + Logger.error(e); + } + } + + //TODO uncomment this when finished with guild history warehouse integration // public HashMap GET_WAREHOUSE_GUILD_HISTORY(){ // // HashMap tempMap = new HashMap<>(); diff --git a/src/engine/db/handlers/dbHandlerBase.java b/src/engine/db/handlers/dbHandlerBase.java index 53eea3c2..8de040d2 100644 --- a/src/engine/db/handlers/dbHandlerBase.java +++ b/src/engine/db/handlers/dbHandlerBase.java @@ -25,455 +25,456 @@ import java.util.HashSet; public abstract class dbHandlerBase { - /* - * CallableStatements handled below this line! - */ - protected Class localClass = null; - protected GameObjectType localObjectType; - protected final ThreadLocal callableStatement = new ThreadLocal<>(); - protected final ThreadLocal connection = new ThreadLocal<>(); - - protected final void prepareCallable(final String sql) { - try { - this.connection.set(DbManager.getConnection()); - this.callableStatement.set(this.connection.get().prepareCall(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)); - } catch (SQLException e) { - Logger.error("DbManager.getConn", e); - Logger.error("SQL Error number: " + e.getErrorCode()); - } - } - - protected final void setInt(int parameterIndex, int value) { - try { - this.callableStatement.get().setInt(parameterIndex, value); - } catch (SQLException e) { - Logger.error("SQL Error number: " + e.getErrorCode()); - } - } - - protected final void setLong(int parameterIndex, long value) { - try { - this.callableStatement.get().setLong(parameterIndex, value); - } catch (SQLException e) { - Logger.error("SQL Error number: " + e.getErrorCode()); - } - } - - protected final void setFloat(int parameterIndex, float value) { - try { - this.callableStatement.get().setFloat(parameterIndex, value); - } catch (SQLException e) { - Logger.error("SQL Error number: " + e.getErrorCode()); - } - } - - protected final void setShort(int parameterIndex, short value) { - try { - this.callableStatement.get().setShort(parameterIndex, value); - } catch (SQLException e) { - Logger.error("SQL Error number: " + e.getErrorCode()); - } - } - - protected final void setString(int parameterIndex, String value) { - try { - this.callableStatement.get().setString(parameterIndex, value); - } catch (SQLException e) { - Logger.error("SQL Error number: " + e.getErrorCode()); - } - } - - protected final void setByte(int parameterIndex, byte value) { - try { - this.callableStatement.get().setByte(parameterIndex, value); - } catch (SQLException e) { - Logger.error("SQL Error number: " + e.getErrorCode()); - } - } - - protected final void setBoolean(int parameterIndex, boolean value) { - try { - this.callableStatement.get().setBoolean(parameterIndex, value); - } catch (SQLException e) { - Logger.error("SQL Error number: " + e.getErrorCode()); - } - } - - protected final void setNULL(int parameterIndex, int type) { - try { - this.callableStatement.get().setNull(parameterIndex, type); - } catch (SQLException e) { - Logger.error("SQL Error number: " + e.getErrorCode()); - } - } - - protected final void setLocalDateTime(int parameterIndex, LocalDateTime localDateTime) { - - try { - this.callableStatement.get().setTimestamp(parameterIndex, Timestamp.valueOf(localDateTime)); - } catch (SQLException e) { - Logger.error("SQL Error number: " + e.getErrorCode()); - } - } - - protected final void setTimeStamp(int parameterIndex, long time) { - try { - this.callableStatement.get().setTimestamp(parameterIndex, new java.sql.Timestamp(time)); - } catch (SQLException e) { - Logger.error("SQL Error number: " + e.getErrorCode()); - } - } - - protected final boolean execute() { - try { - return this.callableStatement.get().execute(); - } catch (SQLException e) { - Logger.error("SQL Error number: " + e.getErrorCode()); - logSQLCommand(); - } - return false; - } - - protected final ResultSet executeQuery() { - try { - return this.callableStatement.get().executeQuery(); - } catch (SQLException e) { - Logger.error("SQL Error number: " + e.getErrorCode()); - logSQLCommand(); - } - return null; - } - - protected final int executeUpdate() { - return executeUpdate(true); - } - - protected final int executeUpdate(boolean close) { - try { - return this.callableStatement.get().executeUpdate(); - } catch (SQLException e) { - Logger.error("SQL Error number: " + e.getErrorCode()); - logSQLCommand(); - } finally { - if (close) - closeCallable(); - } - return 0; - } - - protected final void logSQLCommand() { - try { - Logger.error("Failed SQL Command: " + this.callableStatement.get().toString()); - } catch (Exception e) { - - } - } - - // Common return values from the database when calling stored procedures, abstracted to this layer - protected final String getResult(){ - try { - ResultSet rs = this.executeQuery(); - if (rs.next() && !isError(rs)) - return rs.getString("result"); - } catch (SQLException e) { - Logger.error(e); - logSQLCommand(); - } finally { - closeCallable(); - } - return null; - } - - // Used for Stored procedures that return true when they succeed. - protected final boolean worked() { - try { - ResultSet rs = this.executeQuery(); - if (rs.next() && !isError(rs)) - return rs.getBoolean("result"); - } catch (SQLException e) { - Logger.error(e); - logSQLCommand(); - } finally { - closeCallable(); - } - return false; - } - - // Common return values from the database when calling stored procedures, abstracted to this layer - protected final long getUUID(){ - try { - ResultSet rs = this.executeQuery(); - if (rs.next() && !isError(rs)) - return rs.getLong("UID"); - } catch (SQLException e) { - Logger.error(e); - logSQLCommand(); - } finally { - closeCallable(); - } - return -1; - } - - protected final String getString(String field) { - try { - ResultSet rs = this.executeQuery(); - if (rs.next()) - return rs.getString(field); - } catch (SQLException e) { - Logger.error(e); - logSQLCommand(); - } finally { - closeCallable(); - } - return ""; - } - - protected final long getLong(String field) { - try { - ResultSet rs = this.executeQuery(); - if (rs.next()) - return rs.getLong(field); - } catch (SQLException e) { - Logger.error(e); - logSQLCommand(); - } finally { - closeCallable(); - } - return 0L; - } - - protected final int getInt(String field) { - try { - ResultSet rs = this.executeQuery(); - if (rs.next()) - return rs.getInt(field); - } catch (SQLException e) { - Logger.error(e); - logSQLCommand(); - } finally { - closeCallable(); - } - return 0; - } - - protected final int insertGetUUID() { - int key = 0; - try { - this.callableStatement.get().executeUpdate(); - ResultSet rs = this.callableStatement.get().getGeneratedKeys(); - if (rs.next()) - key = rs.getInt(1); - } catch (SQLException e) { - Logger.error(e); - logSQLCommand(); - } finally { - closeCallable(); - } - return key; - } - - protected final boolean isError(ResultSet rs) throws SQLException { - ResultSetMetaData rsmd = rs.getMetaData(); - if (rsmd.getColumnCount() > 0 && !rsmd.getColumnName(1).equals("errorno")) - return false; - printError(rs); - return true; - } - - protected final void printError(ResultSet rs) { - try { - int errorNum = rs.getInt("errorno"); - String errorMsg = rs.getString("errormsg"); - Logger.error("SQLError: errorNum: " + errorNum + ", errorMsg: " + errorMsg); - logSQLCommand(); - } catch (SQLException e) { - } - } - - protected AbstractGameObject getObjectFromRs(ResultSet rs) { - - AbstractGameObject abstractGameObject = null; - - try { - if (rs.next()) { - abstractGameObject = localClass.getConstructor(ResultSet.class).newInstance(rs); - - DbManager.addToCache(abstractGameObject); - } - } catch (Exception e) { - Logger.error(e); - } - - return abstractGameObject; - } - - protected ArrayList getObjectsFromRs(ResultSet rs, int listSize) { - - ArrayList objectList = new ArrayList<>(listSize); - - try { - while (rs.next()) { - - int id = rs.getInt(1); - - if (DbManager.inCache(localObjectType, id)) { - objectList.add((T) DbManager.getFromCache(localObjectType, id)); - } else { - AbstractGameObject toAdd = localClass.getConstructor(ResultSet.class).newInstance(rs); - DbManager.addToCache(toAdd); - objectList.add((T) toAdd); - - if (toAdd != null && toAdd instanceof AbstractWorldObject) - ((AbstractWorldObject) toAdd).runAfterLoad(); - } - } - } catch (Exception e) { - Logger.error(e); - } - return objectList; - - } - - protected AbstractGameObject getObjectSingle(int id) { - return getObjectSingle(id, false, true); - } - - protected AbstractGameObject getObjectSingle(int id, boolean forceFromDB, boolean storeInCache) { - - if (callableStatement.get() == null) { - return null; - } - - if (!forceFromDB) { - if (DbManager.inCache(localObjectType, id)) { - closeCallable(); - return DbManager.getFromCache(localObjectType, id); - } - } - - AbstractGameObject out = null; + protected final ThreadLocal callableStatement = new ThreadLocal<>(); + protected final ThreadLocal connection = new ThreadLocal<>(); + /* + * CallableStatements handled below this line! + */ + protected Class localClass = null; + protected GameObjectType localObjectType; + + protected final void prepareCallable(final String sql) { + try { + this.connection.set(DbManager.getConnection()); + this.callableStatement.set(this.connection.get().prepareCall(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)); + } catch (SQLException e) { + Logger.error("DbManager.getConn", e); + Logger.error("SQL Error number: " + e.getErrorCode()); + } + } + + protected final void setInt(int parameterIndex, int value) { + try { + this.callableStatement.get().setInt(parameterIndex, value); + } catch (SQLException e) { + Logger.error("SQL Error number: " + e.getErrorCode()); + } + } + + protected final void setLong(int parameterIndex, long value) { + try { + this.callableStatement.get().setLong(parameterIndex, value); + } catch (SQLException e) { + Logger.error("SQL Error number: " + e.getErrorCode()); + } + } + + protected final void setFloat(int parameterIndex, float value) { + try { + this.callableStatement.get().setFloat(parameterIndex, value); + } catch (SQLException e) { + Logger.error("SQL Error number: " + e.getErrorCode()); + } + } + + protected final void setShort(int parameterIndex, short value) { + try { + this.callableStatement.get().setShort(parameterIndex, value); + } catch (SQLException e) { + Logger.error("SQL Error number: " + e.getErrorCode()); + } + } + + protected final void setString(int parameterIndex, String value) { + try { + this.callableStatement.get().setString(parameterIndex, value); + } catch (SQLException e) { + Logger.error("SQL Error number: " + e.getErrorCode()); + } + } + + protected final void setByte(int parameterIndex, byte value) { + try { + this.callableStatement.get().setByte(parameterIndex, value); + } catch (SQLException e) { + Logger.error("SQL Error number: " + e.getErrorCode()); + } + } + + protected final void setBoolean(int parameterIndex, boolean value) { + try { + this.callableStatement.get().setBoolean(parameterIndex, value); + } catch (SQLException e) { + Logger.error("SQL Error number: " + e.getErrorCode()); + } + } + + protected final void setNULL(int parameterIndex, int type) { + try { + this.callableStatement.get().setNull(parameterIndex, type); + } catch (SQLException e) { + Logger.error("SQL Error number: " + e.getErrorCode()); + } + } + + protected final void setLocalDateTime(int parameterIndex, LocalDateTime localDateTime) { + + try { + this.callableStatement.get().setTimestamp(parameterIndex, Timestamp.valueOf(localDateTime)); + } catch (SQLException e) { + Logger.error("SQL Error number: " + e.getErrorCode()); + } + } + + protected final void setTimeStamp(int parameterIndex, long time) { + try { + this.callableStatement.get().setTimestamp(parameterIndex, new java.sql.Timestamp(time)); + } catch (SQLException e) { + Logger.error("SQL Error number: " + e.getErrorCode()); + } + } + + protected final boolean execute() { + try { + return this.callableStatement.get().execute(); + } catch (SQLException e) { + Logger.error("SQL Error number: " + e.getErrorCode()); + logSQLCommand(); + } + return false; + } + + protected final ResultSet executeQuery() { + try { + return this.callableStatement.get().executeQuery(); + } catch (SQLException e) { + Logger.error("SQL Error number: " + e.getErrorCode()); + logSQLCommand(); + } + return null; + } + + protected final int executeUpdate() { + return executeUpdate(true); + } + + protected final int executeUpdate(boolean close) { + try { + return this.callableStatement.get().executeUpdate(); + } catch (SQLException e) { + Logger.error("SQL Error number: " + e.getErrorCode()); + logSQLCommand(); + } finally { + if (close) + closeCallable(); + } + return 0; + } + + protected final void logSQLCommand() { + try { + Logger.error("Failed SQL Command: " + this.callableStatement.get().toString()); + } catch (Exception e) { + + } + } + + // Common return values from the database when calling stored procedures, abstracted to this layer + protected final String getResult() { + try { + ResultSet rs = this.executeQuery(); + if (rs.next() && !isError(rs)) + return rs.getString("result"); + } catch (SQLException e) { + Logger.error(e); + logSQLCommand(); + } finally { + closeCallable(); + } + return null; + } + + // Used for Stored procedures that return true when they succeed. + protected final boolean worked() { + try { + ResultSet rs = this.executeQuery(); + if (rs.next() && !isError(rs)) + return rs.getBoolean("result"); + } catch (SQLException e) { + Logger.error(e); + logSQLCommand(); + } finally { + closeCallable(); + } + return false; + } + + // Common return values from the database when calling stored procedures, abstracted to this layer + protected final long getUUID() { + try { + ResultSet rs = this.executeQuery(); + if (rs.next() && !isError(rs)) + return rs.getLong("UID"); + } catch (SQLException e) { + Logger.error(e); + logSQLCommand(); + } finally { + closeCallable(); + } + return -1; + } + + protected final String getString(String field) { + try { + ResultSet rs = this.executeQuery(); + if (rs.next()) + return rs.getString(field); + } catch (SQLException e) { + Logger.error(e); + logSQLCommand(); + } finally { + closeCallable(); + } + return ""; + } + + protected final long getLong(String field) { + try { + ResultSet rs = this.executeQuery(); + if (rs.next()) + return rs.getLong(field); + } catch (SQLException e) { + Logger.error(e); + logSQLCommand(); + } finally { + closeCallable(); + } + return 0L; + } + + protected final int getInt(String field) { + try { + ResultSet rs = this.executeQuery(); + if (rs.next()) + return rs.getInt(field); + } catch (SQLException e) { + Logger.error(e); + logSQLCommand(); + } finally { + closeCallable(); + } + return 0; + } + + protected final int insertGetUUID() { + int key = 0; + try { + this.callableStatement.get().executeUpdate(); + ResultSet rs = this.callableStatement.get().getGeneratedKeys(); + if (rs.next()) + key = rs.getInt(1); + } catch (SQLException e) { + Logger.error(e); + logSQLCommand(); + } finally { + closeCallable(); + } + return key; + } + + protected final boolean isError(ResultSet rs) throws SQLException { + ResultSetMetaData rsmd = rs.getMetaData(); + if (rsmd.getColumnCount() > 0 && !rsmd.getColumnName(1).equals("errorno")) + return false; + printError(rs); + return true; + } + + protected final void printError(ResultSet rs) { + try { + int errorNum = rs.getInt("errorno"); + String errorMsg = rs.getString("errormsg"); + Logger.error("SQLError: errorNum: " + errorNum + ", errorMsg: " + errorMsg); + logSQLCommand(); + } catch (SQLException e) { + } + } + + protected AbstractGameObject getObjectFromRs(ResultSet rs) { + + AbstractGameObject abstractGameObject = null; + + try { + if (rs.next()) { + abstractGameObject = localClass.getConstructor(ResultSet.class).newInstance(rs); + + DbManager.addToCache(abstractGameObject); + } + } catch (Exception e) { + Logger.error(e); + } + + return abstractGameObject; + } + + protected ArrayList getObjectsFromRs(ResultSet rs, int listSize) { + + ArrayList objectList = new ArrayList<>(listSize); + + try { + while (rs.next()) { + + int id = rs.getInt(1); + + if (DbManager.inCache(localObjectType, id)) { + objectList.add((T) DbManager.getFromCache(localObjectType, id)); + } else { + AbstractGameObject toAdd = localClass.getConstructor(ResultSet.class).newInstance(rs); + DbManager.addToCache(toAdd); + objectList.add((T) toAdd); + + if (toAdd != null && toAdd instanceof AbstractWorldObject) + ((AbstractWorldObject) toAdd).runAfterLoad(); + } + } + } catch (Exception e) { + Logger.error(e); + } + return objectList; + + } + + protected AbstractGameObject getObjectSingle(int id) { + return getObjectSingle(id, false, true); + } + + protected AbstractGameObject getObjectSingle(int id, boolean forceFromDB, boolean storeInCache) { + + if (callableStatement.get() == null) { + return null; + } + + if (!forceFromDB) { + if (DbManager.inCache(localObjectType, id)) { + closeCallable(); + return DbManager.getFromCache(localObjectType, id); + } + } + + AbstractGameObject out = null; + + try { + if (MBServerStatics.DB_ENABLE_QUERY_OUTPUT) + Logger.info("[GetObjectList] Executing query:" + callableStatement.get().toString()); - try { - if (MBServerStatics.DB_ENABLE_QUERY_OUTPUT) - Logger.info("[GetObjectList] Executing query:" + callableStatement.get().toString()); + ResultSet rs = callableStatement.get().executeQuery(); - ResultSet rs = callableStatement.get().executeQuery(); + if (rs.next()) { + out = localClass.getConstructor(ResultSet.class).newInstance(rs); - if (rs.next()) { - out = localClass.getConstructor(ResultSet.class).newInstance(rs); + if (storeInCache) + DbManager.addToCache(out); + } - if (storeInCache) - DbManager.addToCache(out); - } + rs.close(); - rs.close(); + } catch (Exception e) { + Logger.error("AbstractGameObject", e); + out = null; + } finally { + closeCallable(); + } - } catch (Exception e) { - Logger.error("AbstractGameObject", e); - out = null; - } finally { - closeCallable(); - } + // Only call runAfterLoad() for objects instanced on the world server - // Only call runAfterLoad() for objects instanced on the world server + if ((out != null && out instanceof AbstractWorldObject) && + (ConfigManager.serverType.equals(Enum.ServerType.WORLDSERVER) || + (out.getObjectType() == GameObjectType.Guild))) + ((AbstractWorldObject) out).runAfterLoad(); - if ((out != null && out instanceof AbstractWorldObject) && - (ConfigManager.serverType.equals(Enum.ServerType.WORLDSERVER) || - (out.getObjectType() == GameObjectType.Guild))) - ((AbstractWorldObject)out).runAfterLoad(); + return out; + } - return out; - } + protected void closeCallable() { + try { + if (this.callableStatement.get() != null) + this.callableStatement.get().close(); - protected void closeCallable() { - try { - if (this.callableStatement.get() != null) - this.callableStatement.get().close(); + this.connection.get().close(); - this.connection.get().close(); + } catch (SQLException e) { + } + } - } catch (SQLException e) {} - } + protected ArrayList getObjectList() { + return getObjectList(20, false); + } - protected ArrayList getObjectList() { - return getObjectList(20, false); - } + protected ArrayList getLargeObjectList() { + return getObjectList(2000, false); + } - protected ArrayList getLargeObjectList() { - return getObjectList(2000, false); - } + @SuppressWarnings("unchecked") + protected ArrayList getObjectList(int listSize, boolean forceFromDB) { - @SuppressWarnings("unchecked") - protected ArrayList getObjectList(int listSize, boolean forceFromDB) { + String query = "No Callable Statement accessable."; - String query = "No Callable Statement accessable."; + ArrayList out = new ArrayList<>(listSize); - ArrayList out = new ArrayList<>(listSize); + if (this.callableStatement.get() == null) + return out; - if (this.callableStatement.get() == null) - return out; + try { - try { + CallableStatement css = this.callableStatement.get(); - CallableStatement css = this.callableStatement.get(); + if (css != null) + query = this.callableStatement.get().toString(); - if (css != null) - query = this.callableStatement.get().toString(); + if (MBServerStatics.DB_ENABLE_QUERY_OUTPUT) + Logger.info("[GetObjectList] Executing query:" + query); - if (MBServerStatics.DB_ENABLE_QUERY_OUTPUT) - Logger.info( "[GetObjectList] Executing query:" + query); + ResultSet rs = this.callableStatement.get().executeQuery(); - ResultSet rs = this.callableStatement.get().executeQuery(); + while (rs.next()) { - while (rs.next()) { + int id = rs.getInt(1); - int id = rs.getInt(1); + if (!forceFromDB && DbManager.inCache(localObjectType, id)) { + out.add((T) DbManager.getFromCache(localObjectType, id)); + } else { + AbstractGameObject toAdd = localClass.getConstructor(ResultSet.class).newInstance(rs); + DbManager.addToCache(toAdd); + out.add((T) toAdd); - if (!forceFromDB && DbManager.inCache(localObjectType, id)) { - out.add((T) DbManager.getFromCache(localObjectType, id)); - } else { - AbstractGameObject toAdd = localClass.getConstructor(ResultSet.class).newInstance(rs); - DbManager.addToCache(toAdd); - out.add((T) toAdd); + if (toAdd != null && toAdd instanceof AbstractWorldObject) + ((AbstractWorldObject) toAdd).runAfterLoad(); - if (toAdd != null && toAdd instanceof AbstractWorldObject) - ((AbstractWorldObject)toAdd).runAfterLoad(); + } + } + rs.close(); + } catch (Exception e) { + Logger.error(localClass.getCanonicalName(), "List Failure: " + query, e); + e.printStackTrace(); + return new ArrayList<>(); // Do we want a null return on error? + } finally { + closeCallable(); + } - } - } - rs.close(); - } catch (Exception e) { - Logger.error(localClass.getCanonicalName(), "List Failure: " + query, e); - e.printStackTrace(); - return new ArrayList<>(); // Do we want a null return on error? - } finally { - closeCallable(); - } + return out; + } - return out; - } + /* Prepared Statements handled below this line */ - /* Prepared Statements handled below this line */ + protected HashSet getIntegerList(final int columnNumber) { - protected HashSet getIntegerList(final int columnNumber) { + if (MBServerStatics.DB_ENABLE_QUERY_OUTPUT) + Logger.info("[GetIntegerList] Executing query:" + this.callableStatement); - if (MBServerStatics.DB_ENABLE_QUERY_OUTPUT) - Logger.info("[GetIntegerList] Executing query:" + this.callableStatement.toString()); + HashSet out = new HashSet<>(); - HashSet out = new HashSet<>(); + try { + ResultSet rs = executeQuery(); - try { - ResultSet rs = executeQuery(); - - while (rs.next()) { - out.add(rs.getInt(columnNumber)); - } - rs.close(); - } catch (SQLException e) { - Logger.error("SQL Error number: " + e.getErrorCode()); - } finally { - closeCallable(); - } - return out; - } + while (rs.next()) { + out.add(rs.getInt(columnNumber)); + } + rs.close(); + } catch (SQLException e) { + Logger.error("SQL Error number: " + e.getErrorCode()); + } finally { + closeCallable(); + } + return out; + } } diff --git a/src/engine/db/handlers/dbItemBaseHandler.java b/src/engine/db/handlers/dbItemBaseHandler.java index ac824efc..61ebfdc5 100644 --- a/src/engine/db/handlers/dbItemBaseHandler.java +++ b/src/engine/db/handlers/dbItemBaseHandler.java @@ -23,7 +23,7 @@ import java.util.HashMap; public class dbItemBaseHandler extends dbHandlerBase { - public dbItemBaseHandler() { + public dbItemBaseHandler() { } diff --git a/src/engine/db/handlers/dbItemHandler.java b/src/engine/db/handlers/dbItemHandler.java index 49f7f828..5b21c257 100644 --- a/src/engine/db/handlers/dbItemHandler.java +++ b/src/engine/db/handlers/dbItemHandler.java @@ -27,491 +27,491 @@ import java.util.HashSet; public class dbItemHandler extends dbHandlerBase { - public dbItemHandler() { - this.localClass = Item.class; - this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); - } - - public Item ADD_ITEM(Item toAdd) { - - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("CALL `item_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?,?);")) { - - preparedStatement.setInt(1, toAdd.getOwnerID()); - preparedStatement.setInt(2, toAdd.getItemBaseID()); - preparedStatement.setInt(3, toAdd.getChargesRemaining()); - preparedStatement.setInt(4, toAdd.getDurabilityCurrent()); - preparedStatement.setInt(5, toAdd.getDurabilityMax()); - - if (toAdd.getNumOfItems() < 1) - preparedStatement.setInt(6, 1); - else - preparedStatement.setInt(6, toAdd.getNumOfItems()); - - switch (toAdd.containerType) { - case INVENTORY: - preparedStatement.setString(7, "inventory"); - break; - case EQUIPPED: - preparedStatement.setString(7, "equip"); - break; - case BANK: - preparedStatement.setString(7, "bank"); - break; - case VAULT: - preparedStatement.setString(7, "vault"); - break; - case FORGE: - preparedStatement.setString(7, "forge"); - break; - default: - preparedStatement.setString(7, "none"); //Shouldn't be here - break; - } + public dbItemHandler() { + this.localClass = Item.class; + this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); + } + + private static String formatTradeString(HashSet list) { + int size = list.size(); + + String ret = ""; + + if (size == 0) + return ret; + + boolean start = true; - preparedStatement.setByte(8, toAdd.getEquipSlot()); - preparedStatement.setInt(9, toAdd.getFlags()); - preparedStatement.setString(10, toAdd.getCustomName()); + for (int i : list) { + if (start) { + ret += i; + start = false; + } else + ret += "," + i; + } + return ret; + } + + public Item ADD_ITEM(Item toAdd) { + + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("CALL `item_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?,?);")) { + + preparedStatement.setInt(1, toAdd.getOwnerID()); + preparedStatement.setInt(2, toAdd.getItemBaseID()); + preparedStatement.setInt(3, toAdd.getChargesRemaining()); + preparedStatement.setInt(4, toAdd.getDurabilityCurrent()); + preparedStatement.setInt(5, toAdd.getDurabilityMax()); + + if (toAdd.getNumOfItems() < 1) + preparedStatement.setInt(6, 1); + else + preparedStatement.setInt(6, toAdd.getNumOfItems()); - ResultSet rs = preparedStatement.executeQuery(); + switch (toAdd.containerType) { + case INVENTORY: + preparedStatement.setString(7, "inventory"); + break; + case EQUIPPED: + preparedStatement.setString(7, "equip"); + break; + case BANK: + preparedStatement.setString(7, "bank"); + break; + case VAULT: + preparedStatement.setString(7, "vault"); + break; + case FORGE: + preparedStatement.setString(7, "forge"); + break; + default: + preparedStatement.setString(7, "none"); //Shouldn't be here + break; + } - int objectUUID = (int) rs.getLong("UID"); + preparedStatement.setByte(8, toAdd.getEquipSlot()); + preparedStatement.setInt(9, toAdd.getFlags()); + preparedStatement.setString(10, toAdd.getCustomName()); - if (objectUUID > 0) - return GET_ITEM(objectUUID); + ResultSet rs = preparedStatement.executeQuery(); - } catch (SQLException e) { - Logger.error(e); - } + int objectUUID = (int) rs.getLong("UID"); - return null; - } + if (objectUUID > 0) + return GET_ITEM(objectUUID); - public String GET_OWNER(int ownerID) { + } catch (SQLException e) { + Logger.error(e); + } - String ownerType; + return null; + } - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `type` FROM `object` WHERE `UID`=?")) { + public String GET_OWNER(int ownerID) { - preparedStatement.setInt(1, ownerID); - ResultSet rs = preparedStatement.executeQuery(); + String ownerType; - ownerType = rs.getString("type"); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT `type` FROM `object` WHERE `UID`=?")) { - } catch (SQLException e) { - Logger.error(e); - return ""; - } + preparedStatement.setInt(1, ownerID); + ResultSet rs = preparedStatement.executeQuery(); - return ownerType; - } + ownerType = rs.getString("type"); - public boolean DO_TRADE(HashSet from1, HashSet from2, - CharacterItemManager man1, CharacterItemManager man2, - Item inventoryGold1, Item inventoryGold2, int goldFrom1, int goldFrom2) { + } catch (SQLException e) { + Logger.error(e); + return ""; + } - AbstractCharacter ac1 = man1.getOwner(); - AbstractCharacter ac2 = man2.getOwner(); - boolean worked = false; + return ownerType; + } - if (ac1 == null || ac2 == null || inventoryGold1 == null || inventoryGold2 == null) - return false; + public boolean DO_TRADE(HashSet from1, HashSet from2, + CharacterItemManager man1, CharacterItemManager man2, + Item inventoryGold1, Item inventoryGold2, int goldFrom1, int goldFrom2) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("CALL `item_TRADE`(?, ?, ?, ?, ?, ?, ?, ?)")) { + AbstractCharacter ac1 = man1.getOwner(); + AbstractCharacter ac2 = man2.getOwner(); + boolean worked = false; - preparedStatement.setString(1, formatTradeString(from1)); - preparedStatement.setLong(2, (long) ac1.getObjectUUID()); - preparedStatement.setString(3, formatTradeString(from2)); - preparedStatement.setLong(4, (long) ac2.getObjectUUID()); - preparedStatement.setInt(5, goldFrom1); - preparedStatement.setLong(6, (long) inventoryGold1.getObjectUUID()); - preparedStatement.setInt(7, goldFrom2); - preparedStatement.setLong(8, (long) inventoryGold2.getObjectUUID()); + if (ac1 == null || ac2 == null || inventoryGold1 == null || inventoryGold2 == null) + return false; - ResultSet rs = preparedStatement.executeQuery(); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("CALL `item_TRADE`(?, ?, ?, ?, ?, ?, ?, ?)")) { - if (rs.next()) - worked = rs.getBoolean("result"); + preparedStatement.setString(1, formatTradeString(from1)); + preparedStatement.setLong(2, ac1.getObjectUUID()); + preparedStatement.setString(3, formatTradeString(from2)); + preparedStatement.setLong(4, ac2.getObjectUUID()); + preparedStatement.setInt(5, goldFrom1); + preparedStatement.setLong(6, inventoryGold1.getObjectUUID()); + preparedStatement.setInt(7, goldFrom2); + preparedStatement.setLong(8, inventoryGold2.getObjectUUID()); - } catch (SQLException e) { - Logger.error(e); - } - return worked; - } + ResultSet rs = preparedStatement.executeQuery(); - private static String formatTradeString(HashSet list) { - int size = list.size(); + if (rs.next()) + worked = rs.getBoolean("result"); - String ret = ""; + } catch (SQLException e) { + Logger.error(e); + } + return worked; + } - if (size == 0) - return ret; + public ArrayList GET_EQUIPPED_ITEMS(final int targetId) { - boolean start = true; + ArrayList itemList; - for (int i : list) { - if (start) { - ret += i; - start = false; - } else - ret += "," + i; - } - return ret; - } + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_item`.*, `object`.`parent`, `object`.`type` FROM `object` INNER JOIN `obj_item` ON `object`.`UID` = `obj_item`.`UID` WHERE `object`.`parent`=? && `obj_item`.`item_container`='equip';")) { - public ArrayList GET_EQUIPPED_ITEMS(final int targetId) { + preparedStatement.setLong(1, targetId); + ResultSet rs = preparedStatement.executeQuery(); - ArrayList itemList; + itemList = getObjectsFromRs(rs, 10); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_item`.*, `object`.`parent`, `object`.`type` FROM `object` INNER JOIN `obj_item` ON `object`.`UID` = `obj_item`.`UID` WHERE `object`.`parent`=? && `obj_item`.`item_container`='equip';")) { + } catch (SQLException e) { + Logger.error(e); + return null; + } - preparedStatement.setLong(1, (long) targetId); - ResultSet rs = preparedStatement.executeQuery(); + return itemList; + } - itemList = getObjectsFromRs(rs, 10); + public Item GET_ITEM(final int itemUUID) { - } catch (SQLException e) { - Logger.error(e); - return null; - } + Item item; - return itemList; - } + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_item`.*, `object`.`parent`, `object`.`type` FROM `object` INNER JOIN `obj_item` ON `object`.`UID` = `obj_item`.`UID` WHERE `object`.`UID`=?;")) { - public Item GET_ITEM(final int itemUUID) { + preparedStatement.setLong(1, itemUUID); + ResultSet rs = preparedStatement.executeQuery(); - Item item; + item = (Item) getObjectFromRs(rs); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_item`.*, `object`.`parent`, `object`.`type` FROM `object` INNER JOIN `obj_item` ON `object`.`UID` = `obj_item`.`UID` WHERE `object`.`UID`=?;")) { + } catch (SQLException e) { + Logger.error(e); + return null; + } + return item; + } - preparedStatement.setLong(1, itemUUID); - ResultSet rs = preparedStatement.executeQuery(); + public ArrayList GET_ITEMS_FOR_ACCOUNT(final int accountId) { - item = (Item) getObjectFromRs(rs); + ArrayList itemList; - } catch (SQLException e) { - Logger.error(e); - return null; - } - return item; - } + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_item`.*, `object`.`parent`, `object`.`type` FROM `object` INNER JOIN `obj_item` ON `object`.`UID` = `obj_item`.`UID` WHERE `object`.`parent`=?;")) { - public ArrayList GET_ITEMS_FOR_ACCOUNT(final int accountId) { + preparedStatement.setLong(1, accountId); + ResultSet rs = preparedStatement.executeQuery(); - ArrayList itemList; + itemList = getObjectsFromRs(rs, 100); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_item`.*, `object`.`parent`, `object`.`type` FROM `object` INNER JOIN `obj_item` ON `object`.`UID` = `obj_item`.`UID` WHERE `object`.`parent`=?;")) { + } catch (SQLException e) { + Logger.error(e); + return null; + } + return itemList; + } - preparedStatement.setLong(1, (long) accountId); - ResultSet rs = preparedStatement.executeQuery(); + public ArrayList GET_ITEMS_FOR_NPC(final int npcId) { - itemList = getObjectsFromRs(rs, 100); + ArrayList itemList; - } catch (SQLException e) { - Logger.error(e); - return null; - } - return itemList; - } + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_item`.*, `object`.`parent`, `object`.`type` FROM `object` INNER JOIN `obj_item` ON `object`.`UID` = `obj_item`.`UID` WHERE `object`.`parent`=?;")) { - public ArrayList GET_ITEMS_FOR_NPC(final int npcId) { + preparedStatement.setLong(1, npcId); + ResultSet rs = preparedStatement.executeQuery(); - ArrayList itemList; + itemList = getObjectsFromRs(rs, 20); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_item`.*, `object`.`parent`, `object`.`type` FROM `object` INNER JOIN `obj_item` ON `object`.`UID` = `obj_item`.`UID` WHERE `object`.`parent`=?;")) { + } catch (SQLException e) { + Logger.error(e); + return null; + } + return itemList; + } - preparedStatement.setLong(1, npcId); - ResultSet rs = preparedStatement.executeQuery(); + public ArrayList GET_ITEMS_FOR_PC(final int id) { - itemList = getObjectsFromRs(rs, 20); + ArrayList itemList; - } catch (SQLException e) { - Logger.error(e); - return null; - } - return itemList; - } + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_item`.*, `object`.`parent`, `object`.`type` FROM `object` INNER JOIN `obj_item` ON `object`.`UID` = `obj_item`.`UID` WHERE `object`.`parent`=?")) { - public ArrayList GET_ITEMS_FOR_PC(final int id) { + preparedStatement.setLong(1, id); + ResultSet rs = preparedStatement.executeQuery(); - ArrayList itemList; + itemList = getObjectsFromRs(rs, 100); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_item`.*, `object`.`parent`, `object`.`type` FROM `object` INNER JOIN `obj_item` ON `object`.`UID` = `obj_item`.`UID` WHERE `object`.`parent`=?")) { + } catch (SQLException e) { + Logger.error(e); + return null; + } + return itemList; + } - preparedStatement.setLong(1, (long) id); - ResultSet rs = preparedStatement.executeQuery(); + public boolean MOVE_GOLD(final Item from, final Item to, final int amt) { - itemList = getObjectsFromRs(rs, 100); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_numberOfItems` = CASE WHEN `UID`=? THEN ? WHEN `UID`=? THEN ? END WHERE `UID` IN (?, ?);")) { - } catch (SQLException e) { - Logger.error(e); - return null; - } - return itemList; - } + int newFromAmt = from.getNumOfItems() - amt; + int newToAmt = to.getNumOfItems() + amt; - public boolean MOVE_GOLD(final Item from, final Item to, final int amt) { + preparedStatement.setLong(1, from.getObjectUUID()); + preparedStatement.setInt(2, newFromAmt); + preparedStatement.setLong(3, to.getObjectUUID()); + preparedStatement.setInt(4, newToAmt); + preparedStatement.setLong(5, from.getObjectUUID()); + preparedStatement.setLong(6, to.getObjectUUID()); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_numberOfItems` = CASE WHEN `UID`=? THEN ? WHEN `UID`=? THEN ? END WHERE `UID` IN (?, ?);")) { + return (preparedStatement.executeUpdate() > 0); - int newFromAmt = from.getNumOfItems() - amt; - int newToAmt = to.getNumOfItems() + amt; + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - preparedStatement.setLong(1, (long) from.getObjectUUID()); - preparedStatement.setInt(2, newFromAmt); - preparedStatement.setLong(3, (long) to.getObjectUUID()); - preparedStatement.setInt(4, newToAmt); - preparedStatement.setLong(5, (long) from.getObjectUUID()); - preparedStatement.setLong(6, (long) to.getObjectUUID()); + public boolean ORPHAN_INVENTORY(final HashSet inventory) { - return (preparedStatement.executeUpdate() > 0); + boolean worked = true; - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + for (Item item : inventory) { - public boolean ORPHAN_INVENTORY(final HashSet inventory) { + if (item.getItemBase().getType().equals(ItemType.GOLD)) + continue; - boolean worked = true; + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` LEFT JOIN `object` ON `object`.`UID` = `obj_item`.`UID` SET `object`.`parent`=NULL, `obj_item`.`item_container`='none' WHERE `object`.`UID`=?;")) { - for (Item item : inventory) { + preparedStatement.setLong(1, item.getObjectUUID()); + worked = (preparedStatement.executeUpdate() > 0); - if (item.getItemBase().getType().equals(ItemType.GOLD)) - continue; + if (worked) + item.zeroItem(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` LEFT JOIN `object` ON `object`.`UID` = `obj_item`.`UID` SET `object`.`parent`=NULL, `obj_item`.`item_container`='none' WHERE `object`.`UID`=?;")) { + } catch (SQLException e) { + Logger.error(e); + return false; + } + } + return worked; + } - preparedStatement.setLong(1, (long) item.getObjectUUID()); - worked = (preparedStatement.executeUpdate() > 0); + public HashSet GET_ITEMS_FOR_VENDOR(final int vendorID) { - if (worked) - item.zeroItem(); + HashSet itemSet = new HashSet<>(); - } catch (SQLException e) { - Logger.error(e); - return false; - } - } - return worked; - } + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT ID FROM static_itembase WHERE vendorType = ?")) { - public HashSet GET_ITEMS_FOR_VENDOR(final int vendorID) { + preparedStatement.setInt(1, vendorID); - HashSet itemSet = new HashSet<>(); + ResultSet rs = preparedStatement.executeQuery(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT ID FROM static_itembase WHERE vendorType = ?")) { + while (rs.next()) + itemSet.add(rs.getInt(1)); - preparedStatement.setInt(1, vendorID); + } catch (SQLException e) { + Logger.error(e); + return itemSet; + } - ResultSet rs = preparedStatement.executeQuery(); + return itemSet; + } - while (rs.next()) - itemSet.add(rs.getInt(1)); + //Used to transfer a single item between owners or equip or vault or bank or inventory + public boolean UPDATE_OWNER(final Item item, int newOwnerID, boolean ownerNPC, boolean ownerPlayer, + boolean ownerAccount, ItemContainerType containerType, int slot) { - } catch (SQLException e) { - Logger.error(e); - return itemSet; - } + boolean worked = false; - return itemSet; - } + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("CALL `item_TRANSFER_OWNER`(?, ?, ?, ? )")) { - //Used to transfer a single item between owners or equip or vault or bank or inventory - public boolean UPDATE_OWNER(final Item item, int newOwnerID, boolean ownerNPC, boolean ownerPlayer, - boolean ownerAccount, ItemContainerType containerType, int slot) { + preparedStatement.setLong(1, item.getObjectUUID()); - boolean worked = false; + if (newOwnerID != 0) + preparedStatement.setLong(2, newOwnerID); + else + preparedStatement.setNull(2, java.sql.Types.BIGINT); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("CALL `item_TRANSFER_OWNER`(?, ?, ?, ? )")) { + switch (containerType) { + case INVENTORY: + preparedStatement.setString(3, "inventory"); + break; + case EQUIPPED: + preparedStatement.setString(3, "equip"); + break; + case BANK: + preparedStatement.setString(3, "bank"); + break; + case VAULT: + preparedStatement.setString(3, "vault"); + break; + case FORGE: + preparedStatement.setString(3, "forge"); + break; + default: + preparedStatement.setString(3, "none"); //Shouldn't be here + break; + } + preparedStatement.setInt(4, slot); + ResultSet rs = preparedStatement.executeQuery(); - preparedStatement.setLong(1, item.getObjectUUID()); + if (rs.next()) + worked = rs.getBoolean("result"); - if (newOwnerID != 0) - preparedStatement.setLong(2, newOwnerID); - else - preparedStatement.setNull(2, java.sql.Types.BIGINT); + } catch (SQLException e) { + Logger.error(e); + return false; + } + return worked; + } - switch (containerType) { - case INVENTORY: - preparedStatement.setString(3, "inventory"); - break; - case EQUIPPED: - preparedStatement.setString(3, "equip"); - break; - case BANK: - preparedStatement.setString(3, "bank"); - break; - case VAULT: - preparedStatement.setString(3, "vault"); - break; - case FORGE: - preparedStatement.setString(3, "forge"); - break; - default: - preparedStatement.setString(3, "none"); //Shouldn't be here - break; - } - preparedStatement.setInt(4, slot); - ResultSet rs = preparedStatement.executeQuery(); + public boolean SET_DURABILITY(final Item item, int value) { - if (rs.next()) - worked = rs.getBoolean("result"); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_durabilityCurrent`=? WHERE `UID`=? AND `item_durabilityCurrent`=?")) { - } catch (SQLException e) { - Logger.error(e); - return false; - } - return worked; - } + preparedStatement.setInt(1, value); + preparedStatement.setLong(2, item.getObjectUUID()); + preparedStatement.setInt(3, item.getDurabilityCurrent()); - public boolean SET_DURABILITY(final Item item, int value) { + return (preparedStatement.executeUpdate() > 0); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_durabilityCurrent`=? WHERE `UID`=? AND `item_durabilityCurrent`=?")) { + } catch (SQLException e) { + Logger.error(e); + return false; + } + } - preparedStatement.setInt(1, value); - preparedStatement.setLong(2, (long) item.getObjectUUID()); - preparedStatement.setInt(3, (int) item.getDurabilityCurrent()); + public boolean UPDATE_FORGE_TO_INVENTORY(final Item item) { - return (preparedStatement.executeUpdate() > 0); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_container` = ? WHERE `UID` = ? AND `item_container` = 'forge';")) { - } catch (SQLException e) { - Logger.error(e); - return false; - } - } + preparedStatement.setString(1, "inventory"); + preparedStatement.setLong(2, item.getObjectUUID()); - public boolean UPDATE_FORGE_TO_INVENTORY(final Item item) { + return (preparedStatement.executeUpdate() > 0); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_container` = ? WHERE `UID` = ? AND `item_container` = 'forge';")) { + } catch (SQLException e) { + Logger.error(e); + return false; + } - preparedStatement.setString(1, "inventory"); - preparedStatement.setLong(2, (long) item.getObjectUUID()); + } - return (preparedStatement.executeUpdate() > 0); + /** + * Attempts to update the quantity of this gold item + * + * @param value New quantity of gold + * @return True on success + */ + public boolean UPDATE_GOLD(final Item item, int value) { + if (item == null) + return false; + return UPDATE_GOLD(item, value, item.getNumOfItems()); + } - } catch (SQLException e) { - Logger.error(e); - return false; - } + /** + * Attempts to update the quantity of this gold item using CAS + * + * @return True on success + */ + public boolean UPDATE_GOLD(final Item item, int newValue, int oldValue) { - } + if (!item.getItemBase().getType().equals(ItemType.GOLD)) + return false; - /** - * Attempts to update the quantity of this gold item - * - * @param value New quantity of gold - * @return True on success - */ - public boolean UPDATE_GOLD(final Item item, int value) { - if (item == null) - return false; - return UPDATE_GOLD(item, value, item.getNumOfItems()); - } + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_numberOfItems`=? WHERE `UID`=?")) { - /** - * Attempts to update the quantity of this gold item using CAS - * - * @return True on success - */ - public boolean UPDATE_GOLD(final Item item, int newValue, int oldValue) { + preparedStatement.setInt(1, newValue); + preparedStatement.setLong(2, item.getObjectUUID()); - if (!item.getItemBase().getType().equals(ItemType.GOLD)) - return false; + return (preparedStatement.executeUpdate() > 0); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_numberOfItems`=? WHERE `UID`=?")) { + } catch (SQLException e) { + Logger.error(e); + return false; + } - preparedStatement.setInt(1, newValue); - preparedStatement.setLong(2, (long) item.getObjectUUID()); + } - return (preparedStatement.executeUpdate() > 0); + public boolean UPDATE_REMAINING_CHARGES(final Item item) { - } catch (SQLException e) { - Logger.error(e); - return false; - } + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_chargesRemaining` = ? WHERE `UID` = ?")) { - } + preparedStatement.setInt(1, item.getChargesRemaining()); + preparedStatement.setLong(2, item.getObjectUUID()); - public boolean UPDATE_REMAINING_CHARGES(final Item item) { + return (preparedStatement.executeUpdate() > 0); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_chargesRemaining` = ? WHERE `UID` = ?")) { + } catch (SQLException e) { + Logger.error(e); + return false; + } - preparedStatement.setInt(1, item.getChargesRemaining()); - preparedStatement.setLong(2, (long) item.getObjectUUID()); + } - return (preparedStatement.executeUpdate() > 0); + // This is necessary because default number of items is 1. + // When we create gold, we want it to start at 0 quantity. - } catch (SQLException e) { - Logger.error(e); - return false; - } + public boolean ZERO_ITEM_STACK(Item item) { - } + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_numberOfItems`=0 WHERE `UID` = ?")) { - // This is necessary because default number of items is 1. - // When we create gold, we want it to start at 0 quantity. + preparedStatement.setLong(1, item.getObjectUUID()); - public boolean ZERO_ITEM_STACK(Item item) { + return (preparedStatement.executeUpdate() > 0); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_numberOfItems`=0 WHERE `UID` = ?")) { + } catch (SQLException e) { + Logger.error(e); + return false; + } + } - preparedStatement.setLong(1, (long) item.getObjectUUID()); + public boolean UPDATE_FLAGS(Item item) { - return (preparedStatement.executeUpdate() > 0); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_flags`=? WHERE `UID` = ?")) { - } catch (SQLException e) { - Logger.error(e); - return false; - } - } + preparedStatement.setInt(1, item.getFlags()); + preparedStatement.setLong(2, item.getObjectUUID()); - public boolean UPDATE_FLAGS(Item item) { + return (preparedStatement.executeUpdate() > 0); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_flags`=? WHERE `UID` = ?")) { + } catch (SQLException e) { + Logger.error(e); + return false; + } + } - preparedStatement.setInt(1, item.getFlags()); - preparedStatement.setLong(2, (long) item.getObjectUUID()); + public boolean UPDATE_VALUE(Item item, int value) { - return (preparedStatement.executeUpdate() > 0); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_value`=? WHERE `UID` = ?")) { - } catch (SQLException e) { - Logger.error(e); - return false; - } - } + preparedStatement.setInt(1, value); + preparedStatement.setLong(2, item.getObjectUUID()); - public boolean UPDATE_VALUE(Item item,int value) { + return (preparedStatement.executeUpdate() > 0); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_value`=? WHERE `UID` = ?")) { - - preparedStatement.setInt(1, value); - preparedStatement.setLong(2, (long) item.getObjectUUID()); - - return (preparedStatement.executeUpdate() > 0); - - } catch (SQLException e) { - Logger.error(e); - return false; - } - } + } catch (SQLException e) { + Logger.error(e); + return false; + } + } } diff --git a/src/engine/db/handlers/dbKitHandler.java b/src/engine/db/handlers/dbKitHandler.java index c1c0be74..b23e94a6 100644 --- a/src/engine/db/handlers/dbKitHandler.java +++ b/src/engine/db/handlers/dbKitHandler.java @@ -21,25 +21,25 @@ import java.util.ArrayList; public class dbKitHandler extends dbHandlerBase { - public dbKitHandler() { - this.localClass = Kit.class; - this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); - } + public dbKitHandler() { + this.localClass = Kit.class; + this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); + } - public ArrayList GET_ALL_KITS() { + public ArrayList GET_ALL_KITS() { - ArrayList kitList = new ArrayList<>(); + ArrayList kitList = new ArrayList<>(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_validkit`")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_validkit`")) { - ResultSet rs = preparedStatement.executeQuery(); - kitList = getObjectsFromRs(rs, 20); + ResultSet rs = preparedStatement.executeQuery(); + kitList = getObjectsFromRs(rs, 20); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return kitList; - } + return kitList; + } } diff --git a/src/engine/db/handlers/dbMenuHandler.java b/src/engine/db/handlers/dbMenuHandler.java index fcf7bfd4..959b0e23 100644 --- a/src/engine/db/handlers/dbMenuHandler.java +++ b/src/engine/db/handlers/dbMenuHandler.java @@ -21,27 +21,27 @@ import java.util.ArrayList; public class dbMenuHandler extends dbHandlerBase { - public dbMenuHandler() { - this.localClass = MenuOption.class; + public dbMenuHandler() { + this.localClass = MenuOption.class; this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); - } + } - public ArrayList GET_MENU_OPTIONS(final int id) { + public ArrayList GET_MENU_OPTIONS(final int id) { - ArrayList menuOptions = new ArrayList<>(); + ArrayList menuOptions = new ArrayList<>(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_menuoption` WHERE menuID = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_menuoption` WHERE menuID = ?")) { - preparedStatement.setInt(1, id); + preparedStatement.setInt(1, id); - ResultSet rs = preparedStatement.executeQuery(); - menuOptions = getObjectsFromRs(rs, 1000); + ResultSet rs = preparedStatement.executeQuery(); + menuOptions = getObjectsFromRs(rs, 1000); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return menuOptions; - } + return menuOptions; + } } diff --git a/src/engine/db/handlers/dbMineHandler.java b/src/engine/db/handlers/dbMineHandler.java index 2c527de9..da722779 100644 --- a/src/engine/db/handlers/dbMineHandler.java +++ b/src/engine/db/handlers/dbMineHandler.java @@ -23,113 +23,113 @@ import java.util.ArrayList; public class dbMineHandler extends dbHandlerBase { - public dbMineHandler() { - this.localClass = Mine.class; - this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); - } + public dbMineHandler() { + this.localClass = Mine.class; + this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); + } - public Mine GET_MINE(int id) { + public Mine GET_MINE(int id) { - if (id == 0) - return null; + if (id == 0) + return null; - Mine mine = (Mine) DbManager.getFromCache(Enum.GameObjectType.Mine, id); + Mine mine = (Mine) DbManager.getFromCache(Enum.GameObjectType.Mine, id); - if (mine != null) - return mine; + if (mine != null) + return mine; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_building`.*, `object`.`parent` FROM `object` INNER JOIN `obj_building` ON `obj_building`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_building`.*, `object`.`parent` FROM `object` INNER JOIN `obj_building` ON `obj_building`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;")) { - preparedStatement.setLong(1, id); + preparedStatement.setLong(1, id); - ResultSet rs = preparedStatement.executeQuery(); - mine = (Mine) getObjectFromRs(rs); + ResultSet rs = preparedStatement.executeQuery(); + mine = (Mine) getObjectFromRs(rs); - } catch (SQLException e) { - Logger.error(e); - } - return mine; - } + } catch (SQLException e) { + Logger.error(e); + } + return mine; + } - public ArrayList GET_ALL_MINES_FOR_SERVER() { + public ArrayList GET_ALL_MINES_FOR_SERVER() { - ArrayList mines = new ArrayList<>(); + ArrayList mines = new ArrayList<>(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_mine`.*, `object`.`parent` FROM `object` INNER JOIN `obj_mine` ON `obj_mine`.`UID` = `object`.`UID`")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_mine`.*, `object`.`parent` FROM `object` INNER JOIN `obj_mine` ON `obj_mine`.`UID` = `object`.`UID`")) { - ResultSet rs = preparedStatement.executeQuery(); - mines = getObjectsFromRs(rs, 1000); + ResultSet rs = preparedStatement.executeQuery(); + mines = getObjectsFromRs(rs, 1000); - } catch (SQLException e) { - Logger.error(e); - } - return mines; - } + } catch (SQLException e) { + Logger.error(e); + } + return mines; + } - public boolean CHANGE_OWNER(Mine mine, int playerUID) { + public boolean CHANGE_OWNER(Mine mine, int playerUID) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `mine_ownerUID`=? WHERE `UID`=?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `mine_ownerUID`=? WHERE `UID`=?")) { - preparedStatement.setInt(1, playerUID); - preparedStatement.setLong(2, mine.getObjectUUID()); + preparedStatement.setInt(1, playerUID); + preparedStatement.setLong(2, mine.getObjectUUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean CHANGE_RESOURCE(Mine mine, Resource resource) { + public boolean CHANGE_RESOURCE(Mine mine, Resource resource) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `mine_resource`=? WHERE `UID`=?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `mine_resource`=? WHERE `UID`=?")) { - preparedStatement.setString(1, resource.name()); - preparedStatement.setLong(2, mine.getObjectUUID()); + preparedStatement.setString(1, resource.name()); + preparedStatement.setLong(2, mine.getObjectUUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean CHANGE_TYPE(Mine mine, MineProduction productionType) { + public boolean CHANGE_TYPE(Mine mine, MineProduction productionType) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `mine_type`=? WHERE `UID`=?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `mine_type`=? WHERE `UID`=?")) { - preparedStatement.setString(1, productionType.name()); - preparedStatement.setLong(2, mine.getObjectUUID()); + preparedStatement.setString(1, productionType.name()); + preparedStatement.setLong(2, mine.getObjectUUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean SET_FLAGS(Mine mine, int newFlags) { + public boolean SET_FLAGS(Mine mine, int newFlags) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `flags`=? WHERE `UID`=?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `flags`=? WHERE `UID`=?")) { - preparedStatement.setInt(1, newFlags); - preparedStatement.setLong(2, mine.getObjectUUID()); + preparedStatement.setInt(1, newFlags); + preparedStatement.setLong(2, mine.getObjectUUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } } diff --git a/src/engine/db/handlers/dbMobBaseHandler.java b/src/engine/db/handlers/dbMobBaseHandler.java index 2c278492..7ef95c6d 100644 --- a/src/engine/db/handlers/dbMobBaseHandler.java +++ b/src/engine/db/handlers/dbMobBaseHandler.java @@ -26,173 +26,173 @@ import java.util.HashMap; public class dbMobBaseHandler extends dbHandlerBase { - public dbMobBaseHandler() { - this.localClass = MobBase.class; - this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); - } + public dbMobBaseHandler() { + this.localClass = MobBase.class; + this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); + } - public MobBase GET_MOBBASE(int id) { + public MobBase GET_MOBBASE(int id) { - if (id == 0) - return null; + if (id == 0) + return null; - MobBase mobBase = (MobBase) DbManager.getFromCache(GameObjectType.MobBase, id); + MobBase mobBase = (MobBase) DbManager.getFromCache(GameObjectType.MobBase, id); - if (mobBase != null) - return mobBase; + if (mobBase != null) + return mobBase; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase` WHERE `ID`=?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase` WHERE `ID`=?")) { - preparedStatement.setInt(1, id); + preparedStatement.setInt(1, id); - ResultSet rs = preparedStatement.executeQuery(); - mobBase = (MobBase) getObjectFromRs(rs); + ResultSet rs = preparedStatement.executeQuery(); + mobBase = (MobBase) getObjectFromRs(rs); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return mobBase; - } + return mobBase; + } - public ArrayList GET_ALL_MOBBASES() { + public ArrayList GET_ALL_MOBBASES() { - ArrayList mobbaseList = new ArrayList<>(); + ArrayList mobbaseList = new ArrayList<>(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase`;")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase`;")) { - ResultSet rs = preparedStatement.executeQuery(); - mobbaseList = getObjectsFromRs(rs, 1000); + ResultSet rs = preparedStatement.executeQuery(); + mobbaseList = getObjectsFromRs(rs, 1000); - } catch (SQLException e) { - Logger.error(e); - } - return mobbaseList; - } + } catch (SQLException e) { + Logger.error(e); + } + return mobbaseList; + } - public void SET_AI_DEFAULTS() { + public void SET_AI_DEFAULTS() { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_ai_defaults`")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_ai_defaults`")) { - ResultSet rs = preparedStatement.executeQuery(); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) { - MBServerStatics.AI_BASE_AGGRO_RANGE = rs.getInt("aggro_range"); - MBServerStatics.AI_PATROL_DIVISOR = rs.getInt("patrol_chance"); - MBServerStatics.AI_DROP_AGGRO_RANGE = rs.getInt("drop_aggro_range"); - MBServerStatics.AI_POWER_DIVISOR = rs.getInt("cast_chance"); - MBServerStatics.AI_RECALL_RANGE = rs.getInt("recall_range"); - MBServerStatics.AI_PET_HEEL_DISTANCE = rs.getInt("pet_heel_distance"); - } - } catch (SQLException e) { - Logger.error(e); - } - } + while (rs.next()) { + MBServerStatics.AI_BASE_AGGRO_RANGE = rs.getInt("aggro_range"); + MBServerStatics.AI_PATROL_DIVISOR = rs.getInt("patrol_chance"); + MBServerStatics.AI_DROP_AGGRO_RANGE = rs.getInt("drop_aggro_range"); + MBServerStatics.AI_POWER_DIVISOR = rs.getInt("cast_chance"); + MBServerStatics.AI_RECALL_RANGE = rs.getInt("recall_range"); + MBServerStatics.AI_PET_HEEL_DISTANCE = rs.getInt("pet_heel_distance"); + } + } catch (SQLException e) { + Logger.error(e); + } + } - public boolean UPDATE_AI_DEFAULTS() { + public boolean UPDATE_AI_DEFAULTS() { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `static_ai_defaults` SET `aggro_range` = ?,`patrol_chance`= ?,`drop_aggro_range`= ?,`cast_chance`= ?,`recall_range`= ? WHERE `ID` = 1")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `static_ai_defaults` SET `aggro_range` = ?,`patrol_chance`= ?,`drop_aggro_range`= ?,`cast_chance`= ?,`recall_range`= ? WHERE `ID` = 1")) { - preparedStatement.setInt(1, MBServerStatics.AI_BASE_AGGRO_RANGE); - preparedStatement.setInt(2, MBServerStatics.AI_PATROL_DIVISOR); - preparedStatement.setInt(3, MBServerStatics.AI_DROP_AGGRO_RANGE); - preparedStatement.setInt(4, MBServerStatics.AI_POWER_DIVISOR); - preparedStatement.setInt(5, MBServerStatics.AI_RECALL_RANGE); + preparedStatement.setInt(1, MBServerStatics.AI_BASE_AGGRO_RANGE); + preparedStatement.setInt(2, MBServerStatics.AI_PATROL_DIVISOR); + preparedStatement.setInt(3, MBServerStatics.AI_DROP_AGGRO_RANGE); + preparedStatement.setInt(4, MBServerStatics.AI_POWER_DIVISOR); + preparedStatement.setInt(5, MBServerStatics.AI_RECALL_RANGE); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public HashMap LOAD_STATIC_POWERS(int mobBaseUUID) { + public HashMap LOAD_STATIC_POWERS(int mobBaseUUID) { - HashMap powersList = new HashMap<>(); + HashMap powersList = new HashMap<>(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase_powers` WHERE `mobbaseUUID`=?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase_powers` WHERE `mobbaseUUID`=?")) { - preparedStatement.setInt(1, mobBaseUUID); - ResultSet rs = preparedStatement.executeQuery(); + preparedStatement.setInt(1, mobBaseUUID); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) - powersList.put(rs.getInt("token"), rs.getInt("rank")); + while (rs.next()) + powersList.put(rs.getInt("token"), rs.getInt("rank")); - } catch (SQLException e) { - Logger.error(e); - } - return powersList; - } + } catch (SQLException e) { + Logger.error(e); + } + return powersList; + } - public ArrayList GET_RUNEBASE_EFFECTS(int runeID) { + public ArrayList GET_RUNEBASE_EFFECTS(int runeID) { - ArrayList effectsList = new ArrayList<>(); + ArrayList effectsList = new ArrayList<>(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase_effects` WHERE `mobbaseUUID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase_effects` WHERE `mobbaseUUID` = ?")) { - preparedStatement.setInt(1, runeID); - ResultSet rs = preparedStatement.executeQuery(); + preparedStatement.setInt(1, runeID); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) { - MobBaseEffects mbs = new MobBaseEffects(rs); - effectsList.add(mbs); - } + while (rs.next()) { + MobBaseEffects mbs = new MobBaseEffects(rs); + effectsList.add(mbs); + } - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return effectsList; - } + return effectsList; + } - public MobBaseStats LOAD_STATS(int mobBaseUUID) { + public MobBaseStats LOAD_STATS(int mobBaseUUID) { - MobBaseStats mobBaseStats = MobBaseStats.GetGenericStats(); + MobBaseStats mobBaseStats = MobBaseStats.GetGenericStats(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase_stats` WHERE `mobbaseUUID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase_stats` WHERE `mobbaseUUID` = ?")) { - preparedStatement.setInt(1, mobBaseUUID); - ResultSet rs = preparedStatement.executeQuery(); + preparedStatement.setInt(1, mobBaseUUID); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) - mobBaseStats = new MobBaseStats(rs); + while (rs.next()) + mobBaseStats = new MobBaseStats(rs); - } catch (SQLException e) { - Logger.error(e); - } - return mobBaseStats; - } + } catch (SQLException e) { + Logger.error(e); + } + return mobBaseStats; + } - public void LOAD_ALL_MOBBASE_SPEEDS(MobBase mobBase) { + public void LOAD_ALL_MOBBASE_SPEEDS(MobBase mobBase) { - if (mobBase.getLoadID() == 0) - return; + if (mobBase.getLoadID() == 0) + return; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase_race` WHERE `mobbaseID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase_race` WHERE `mobbaseID` = ?")) { - preparedStatement.setInt(1, mobBase.getLoadID()); - ResultSet rs = preparedStatement.executeQuery(); + preparedStatement.setInt(1, mobBase.getLoadID()); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) { - float walk = rs.getFloat("walkStandard"); - float walkCombat = rs.getFloat("walkCombat"); - float run = rs.getFloat("runStandard"); - float runCombat = rs.getFloat("runCombat"); - mobBase.updateSpeeds(walk, walkCombat, run, runCombat); - } + while (rs.next()) { + float walk = rs.getFloat("walkStandard"); + float walkCombat = rs.getFloat("walkCombat"); + float run = rs.getFloat("runStandard"); + float runCombat = rs.getFloat("runCombat"); + mobBase.updateSpeeds(walk, walkCombat, run, runCombat); + } - } catch (SQLException e) { - Logger.error(e); - } - } + } catch (SQLException e) { + Logger.error(e); + } + } } diff --git a/src/engine/db/handlers/dbMobHandler.java b/src/engine/db/handlers/dbMobHandler.java index c94d57a4..eeeb8439 100644 --- a/src/engine/db/handlers/dbMobHandler.java +++ b/src/engine/db/handlers/dbMobHandler.java @@ -24,225 +24,225 @@ import java.util.ArrayList; public class dbMobHandler extends dbHandlerBase { - public dbMobHandler() { - this.localClass = Mob.class; - this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); - } + public dbMobHandler() { + this.localClass = Mob.class; + this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); + } - public Mob ADD_MOB(Mob toAdd) { + public Mob ADD_MOB(Mob toAdd) { - Mob mobile = null; + Mob mobile = null; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("CALL `mob_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("CALL `mob_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")) { - preparedStatement.setLong(1, toAdd.getParentZoneID()); - preparedStatement.setInt(2, toAdd.getMobBaseID()); - preparedStatement.setInt(3, toAdd.getGuildUUID()); - preparedStatement.setFloat(4, toAdd.getSpawnX()); - preparedStatement.setFloat(5, toAdd.getSpawnY()); - preparedStatement.setFloat(6, toAdd.getSpawnZ()); - preparedStatement.setInt(7, 0); - preparedStatement.setFloat(8, toAdd.getSpawnRadius()); - preparedStatement.setInt(9, toAdd.getTrueSpawnTime()); + preparedStatement.setLong(1, toAdd.getParentZoneID()); + preparedStatement.setInt(2, toAdd.getMobBaseID()); + preparedStatement.setInt(3, toAdd.getGuildUUID()); + preparedStatement.setFloat(4, toAdd.getSpawnX()); + preparedStatement.setFloat(5, toAdd.getSpawnY()); + preparedStatement.setFloat(6, toAdd.getSpawnZ()); + preparedStatement.setInt(7, 0); + preparedStatement.setFloat(8, toAdd.getSpawnRadius()); + preparedStatement.setInt(9, toAdd.getTrueSpawnTime()); - if (toAdd.getContract() != null) - preparedStatement.setInt(10, toAdd.getContract().getContractID()); - else - preparedStatement.setInt(10, 0); + if (toAdd.getContract() != null) + preparedStatement.setInt(10, toAdd.getContract().getContractID()); + else + preparedStatement.setInt(10, 0); - preparedStatement.setInt(11, toAdd.getBuildingID()); - preparedStatement.setInt(12, toAdd.getLevel()); - preparedStatement.setString(13, toAdd.getFirstName()); + preparedStatement.setInt(11, toAdd.getBuildingID()); + preparedStatement.setInt(12, toAdd.getLevel()); + preparedStatement.setString(13, toAdd.getFirstName()); - ResultSet rs = preparedStatement.executeQuery(); + ResultSet rs = preparedStatement.executeQuery(); - int objectUUID = (int) rs.getLong("UID"); + int objectUUID = (int) rs.getLong("UID"); - if (objectUUID > 0) - mobile = GET_MOB(objectUUID); + if (objectUUID > 0) + mobile = GET_MOB(objectUUID); - } catch (SQLException e) { - throw new RuntimeException(e); - } - return mobile; - } + } catch (SQLException e) { + throw new RuntimeException(e); + } + return mobile; + } - public boolean updateUpgradeTime(Mob mob, DateTime upgradeDateTime) { + public boolean updateUpgradeTime(Mob mob, DateTime upgradeDateTime) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE obj_mob SET upgradeDate=? " - + "WHERE UID = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE obj_mob SET upgradeDate=? " + + "WHERE UID = ?")) { - if (upgradeDateTime == null) - preparedStatement.setNull(1, java.sql.Types.DATE); - else - preparedStatement.setTimestamp(1, new java.sql.Timestamp(upgradeDateTime.getMillis())); + if (upgradeDateTime == null) + preparedStatement.setNull(1, java.sql.Types.DATE); + else + preparedStatement.setTimestamp(1, new java.sql.Timestamp(upgradeDateTime.getMillis())); - preparedStatement.setInt(2, mob.getObjectUUID()); + preparedStatement.setInt(2, mob.getObjectUUID()); - preparedStatement.execute(); - return true; - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + preparedStatement.execute(); + return true; + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public int DELETE_MOB(final Mob mob) { + public int DELETE_MOB(final Mob mob) { - int row_count = 0; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `UID` = ?")) { + int row_count = 0; + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `UID` = ?")) { - preparedStatement.setLong(1, mob.getDBID()); - row_count = preparedStatement.executeUpdate(); + preparedStatement.setLong(1, mob.getDBID()); + row_count = preparedStatement.executeUpdate(); - } catch (SQLException e) { - Logger.error(e); + } catch (SQLException e) { + Logger.error(e); - } - return row_count; - } + } + return row_count; + } - public void LOAD_PATROL_POINTS(Mob captain) { + public void LOAD_PATROL_POINTS(Mob captain) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_guards` WHERE `captainUID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_guards` WHERE `captainUID` = ?")) { - preparedStatement.setInt(1, captain.getObjectUUID()); - ResultSet rs = preparedStatement.executeQuery(); + preparedStatement.setInt(1, captain.getObjectUUID()); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) { - String name = rs.getString("name"); - Mob toCreate = Mob.createGuardMob(captain, captain.getGuild(), captain.getParentZone(), captain.building.getLoc(), captain.getLevel(), name); + while (rs.next()) { + String name = rs.getString("name"); + Mob toCreate = Mob.createGuardMob(captain, captain.getGuild(), captain.getParentZone(), captain.building.getLoc(), captain.getLevel(), name); - if (toCreate == null) - return; + if (toCreate == null) + return; - if (toCreate != null) { - toCreate.setTimeToSpawnSiege(System.currentTimeMillis() + MBServerStatics.FIFTEEN_MINUTES); - toCreate.setDeathTime(System.currentTimeMillis()); - } - } + if (toCreate != null) { + toCreate.setTimeToSpawnSiege(System.currentTimeMillis() + MBServerStatics.FIFTEEN_MINUTES); + toCreate.setDeathTime(System.currentTimeMillis()); + } + } - } catch (SQLException e) { - Logger.error(e); - } - } + } catch (SQLException e) { + Logger.error(e); + } + } - public boolean ADD_TO_GUARDS(final long captainUID, final int mobBaseID, final String name, final int slot) { + public boolean ADD_TO_GUARDS(final long captainUID, final int mobBaseID, final String name, final int slot) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_guards` (`captainUID`, `mobBaseID`,`name`, `slot`) VALUES (?,?,?,?)")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_guards` (`captainUID`, `mobBaseID`,`name`, `slot`) VALUES (?,?,?,?)")) { - preparedStatement.setLong(1, captainUID); - preparedStatement.setInt(2, mobBaseID); - preparedStatement.setString(3, name); - preparedStatement.setInt(4, slot); + preparedStatement.setLong(1, captainUID); + preparedStatement.setInt(2, mobBaseID); + preparedStatement.setString(3, name); + preparedStatement.setInt(4, slot); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - return false; - } - } + } catch (SQLException e) { + Logger.error(e); + return false; + } + } - public boolean REMOVE_FROM_GUARDS(final long captainUID, final int mobBaseID, final int slot) { + public boolean REMOVE_FROM_GUARDS(final long captainUID, final int mobBaseID, final int slot) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_guards` WHERE `captainUID`=? AND `mobBaseID`=? AND `slot` =?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_guards` WHERE `captainUID`=? AND `mobBaseID`=? AND `slot` =?")) { - preparedStatement.setLong(1, captainUID); - preparedStatement.setInt(2, mobBaseID); - preparedStatement.setInt(3, slot); + preparedStatement.setLong(1, captainUID); + preparedStatement.setInt(2, mobBaseID); + preparedStatement.setInt(3, slot); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - return false; - } - } + } catch (SQLException e) { + Logger.error(e); + return false; + } + } - public ArrayList GET_ALL_MOBS_FOR_ZONE(Zone zone) { + public ArrayList GET_ALL_MOBS_FOR_ZONE(Zone zone) { - ArrayList mobileList = new ArrayList<>(); + ArrayList mobileList = new ArrayList<>(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_mob`.*, `object`.`parent` FROM `object` INNER JOIN `obj_mob` ON `obj_mob`.`UID` = `object`.`UID` WHERE `object`.`parent` = ?;")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_mob`.*, `object`.`parent` FROM `object` INNER JOIN `obj_mob` ON `obj_mob`.`UID` = `object`.`UID` WHERE `object`.`parent` = ?;")) { - preparedStatement.setLong(1, zone.getObjectUUID()); + preparedStatement.setLong(1, zone.getObjectUUID()); - ResultSet rs = preparedStatement.executeQuery(); - mobileList = getObjectsFromRs(rs, 1000); + ResultSet rs = preparedStatement.executeQuery(); + mobileList = getObjectsFromRs(rs, 1000); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return mobileList; - } + return mobileList; + } - public Mob GET_MOB(final int objectUUID) { + public Mob GET_MOB(final int objectUUID) { - Mob mobile = null; + Mob mobile = null; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_mob`.*, `object`.`parent` FROM `object` INNER JOIN `obj_mob` ON `obj_mob`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_mob`.*, `object`.`parent` FROM `object` INNER JOIN `obj_mob` ON `obj_mob`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;")) { - preparedStatement.setLong(1, objectUUID); - ResultSet rs = preparedStatement.executeQuery(); - mobile = (Mob) getObjectFromRs(rs); + preparedStatement.setLong(1, objectUUID); + ResultSet rs = preparedStatement.executeQuery(); + mobile = (Mob) getObjectFromRs(rs); - } catch (SQLException e) { - Logger.error(e); - } - return mobile; - } + } catch (SQLException e) { + Logger.error(e); + } + return mobile; + } - public int MOVE_MOB(long mobID, long parentID, float locX, float locY, float locZ) { + public int MOVE_MOB(long mobID, long parentID, float locX, float locY, float locZ) { - int row_count = 0; + int row_count = 0; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `object` INNER JOIN `obj_mob` On `object`.`UID` = `obj_mob`.`UID` SET `object`.`parent`=?, `obj_mob`.`mob_spawnX`=?, `obj_mob`.`mob_spawnY`=?, `obj_mob`.`mob_spawnZ`=? WHERE `obj_mob`.`UID`=?;")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `object` INNER JOIN `obj_mob` On `object`.`UID` = `obj_mob`.`UID` SET `object`.`parent`=?, `obj_mob`.`mob_spawnX`=?, `obj_mob`.`mob_spawnY`=?, `obj_mob`.`mob_spawnZ`=? WHERE `obj_mob`.`UID`=?;")) { - preparedStatement.setLong(1, parentID); - preparedStatement.setFloat(2, locX); - preparedStatement.setFloat(3, locY); - preparedStatement.setFloat(4, locZ); - preparedStatement.setLong(5, mobID); + preparedStatement.setLong(1, parentID); + preparedStatement.setFloat(2, locX); + preparedStatement.setFloat(3, locY); + preparedStatement.setFloat(4, locZ); + preparedStatement.setLong(5, mobID); - ResultSet rs = preparedStatement.executeQuery(); - row_count = preparedStatement.executeUpdate(); + ResultSet rs = preparedStatement.executeQuery(); + row_count = preparedStatement.executeUpdate(); - } catch (SQLException e) { - Logger.error(e); - } - return row_count; - } + } catch (SQLException e) { + Logger.error(e); + } + return row_count; + } - public String SET_PROPERTY(final Mob m, String name, Object new_value) { + public String SET_PROPERTY(final Mob m, String name, Object new_value) { - String result = ""; + String result = ""; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("CALL mob_SETPROP(?,?,?)")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("CALL mob_SETPROP(?,?,?)")) { - preparedStatement.setLong(1, m.getObjectUUID()); - preparedStatement.setString(2, name); - preparedStatement.setString(3, String.valueOf(new_value)); + preparedStatement.setLong(1, m.getObjectUUID()); + preparedStatement.setString(2, name); + preparedStatement.setString(3, String.valueOf(new_value)); - ResultSet rs = preparedStatement.executeQuery(); - result = rs.getString("result"); + ResultSet rs = preparedStatement.executeQuery(); + result = rs.getString("result"); - } catch (SQLException e) { - Logger.error(e); - } - return result; - } + } catch (SQLException e) { + Logger.error(e); + } + return result; + } } diff --git a/src/engine/db/handlers/dbPlayerCharacterHandler.java b/src/engine/db/handlers/dbPlayerCharacterHandler.java index f74e3d49..a716f05a 100644 --- a/src/engine/db/handlers/dbPlayerCharacterHandler.java +++ b/src/engine/db/handlers/dbPlayerCharacterHandler.java @@ -27,546 +27,542 @@ import java.util.concurrent.ConcurrentHashMap; public class dbPlayerCharacterHandler extends dbHandlerBase { - public dbPlayerCharacterHandler() { - this.localClass = PlayerCharacter.class; - this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); - } + public dbPlayerCharacterHandler() { + this.localClass = PlayerCharacter.class; + this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); + } - public PlayerCharacter ADD_PLAYER_CHARACTER(final PlayerCharacter toAdd) { + public PlayerCharacter ADD_PLAYER_CHARACTER(final PlayerCharacter toAdd) { - PlayerCharacter playerCharacter = null; + PlayerCharacter playerCharacter = null; - if (toAdd.getAccount() == null) - return null; + if (toAdd.getAccount() == null) + return null; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("CALL `character_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("CALL `character_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")) { - preparedStatement.setLong(1, toAdd.getAccount().getObjectUUID()); - preparedStatement.setString(2, toAdd.getFirstName()); - preparedStatement.setString(3, toAdd.getLastName()); - preparedStatement.setInt(4, toAdd.getRace().getRaceRuneID()); - preparedStatement.setInt(5, toAdd.getBaseClass().getObjectUUID()); - preparedStatement.setInt(6, toAdd.getStrMod()); - preparedStatement.setInt(7, toAdd.getDexMod()); - preparedStatement.setInt(8, toAdd.getConMod()); - preparedStatement.setInt(9, toAdd.getIntMod()); - preparedStatement.setInt(10, toAdd.getSpiMod()); - preparedStatement.setInt(11, toAdd.getExp()); - preparedStatement.setInt(12, toAdd.getSkinColor()); - preparedStatement.setInt(13, toAdd.getHairColor()); - preparedStatement.setByte(14, toAdd.getHairStyle()); - preparedStatement.setInt(15, toAdd.getBeardColor()); - preparedStatement.setByte(16, toAdd.getBeardStyle()); + preparedStatement.setLong(1, toAdd.getAccount().getObjectUUID()); + preparedStatement.setString(2, toAdd.getFirstName()); + preparedStatement.setString(3, toAdd.getLastName()); + preparedStatement.setInt(4, toAdd.getRace().getRaceRuneID()); + preparedStatement.setInt(5, toAdd.getBaseClass().getObjectUUID()); + preparedStatement.setInt(6, toAdd.getStrMod()); + preparedStatement.setInt(7, toAdd.getDexMod()); + preparedStatement.setInt(8, toAdd.getConMod()); + preparedStatement.setInt(9, toAdd.getIntMod()); + preparedStatement.setInt(10, toAdd.getSpiMod()); + preparedStatement.setInt(11, toAdd.getExp()); + preparedStatement.setInt(12, toAdd.getSkinColor()); + preparedStatement.setInt(13, toAdd.getHairColor()); + preparedStatement.setByte(14, toAdd.getHairStyle()); + preparedStatement.setInt(15, toAdd.getBeardColor()); + preparedStatement.setByte(16, toAdd.getBeardStyle()); - ResultSet rs = preparedStatement.executeQuery(); + ResultSet rs = preparedStatement.executeQuery(); - int objectUUID = (int) rs.getLong("UID"); + int objectUUID = (int) rs.getLong("UID"); - if (objectUUID > 0) - playerCharacter = GET_PLAYER_CHARACTER(objectUUID); + if (objectUUID > 0) + playerCharacter = GET_PLAYER_CHARACTER(objectUUID); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return playerCharacter; - } + return playerCharacter; + } - public boolean SET_IGNORE_LIST(int sourceID, int targetID, boolean toIgnore, String charName) { + public boolean SET_IGNORE_LIST(int sourceID, int targetID, boolean toIgnore, String charName) { - String queryString = ""; + String queryString = ""; - if (toIgnore) - queryString = "INSERT INTO `dyn_character_ignore` (`accountUID`, `ignoringUID`, `characterName`) VALUES (?, ?, ?)"; - else - queryString = "DELETE FROM `dyn_character_ignore` WHERE `accountUID` = ? && `ignoringUID` = ?"; + if (toIgnore) + queryString = "INSERT INTO `dyn_character_ignore` (`accountUID`, `ignoringUID`, `characterName`) VALUES (?, ?, ?)"; + else + queryString = "DELETE FROM `dyn_character_ignore` WHERE `accountUID` = ? && `ignoringUID` = ?"; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement(queryString)) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement(queryString)) { - preparedStatement.setLong(1, sourceID); - preparedStatement.setLong(2, targetID); + preparedStatement.setLong(1, sourceID); + preparedStatement.setLong(2, targetID); - if (toIgnore) - preparedStatement.setString(3, charName); + if (toIgnore) + preparedStatement.setString(3, charName); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public ArrayList GET_CHARACTERS_FOR_ACCOUNT(final int id) { + public ArrayList GET_CHARACTERS_FOR_ACCOUNT(final int id) { - ArrayList characterList = new ArrayList<>(); + ArrayList characterList = new ArrayList<>(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_character`.*, `object`.`parent` FROM `object` INNER JOIN `obj_character` ON `obj_character`.`UID` = `object`.`UID` WHERE `object`.`parent`=? && `obj_character`.`char_isActive`='1';")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_character`.*, `object`.`parent` FROM `object` INNER JOIN `obj_character` ON `obj_character`.`UID` = `object`.`UID` WHERE `object`.`parent`=? && `obj_character`.`char_isActive`='1';")) { - preparedStatement.setLong(1, (long) id); - ResultSet rs = preparedStatement.executeQuery(); - characterList = getObjectsFromRs(rs, 10); + preparedStatement.setLong(1, id); + ResultSet rs = preparedStatement.executeQuery(); + characterList = getObjectsFromRs(rs, 10); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return characterList; - } + return characterList; + } - public ArrayList GET_ALL_CHARACTERS() { + public ArrayList GET_ALL_CHARACTERS() { - ArrayList characterList = new ArrayList<>(); + ArrayList characterList = new ArrayList<>(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_character`.*, `object`.`parent` FROM `object` INNER JOIN `obj_character` ON `obj_character`.`UID` = `object`.`UID` WHERE `obj_character`.`char_isActive`='1';")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_character`.*, `object`.`parent` FROM `object` INNER JOIN `obj_character` ON `obj_character`.`UID` = `object`.`UID` WHERE `obj_character`.`char_isActive`='1';")) { - ResultSet rs = preparedStatement.executeQuery(); - characterList = getObjectsFromRs(rs, 2000); + ResultSet rs = preparedStatement.executeQuery(); + characterList = getObjectsFromRs(rs, 2000); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return characterList; - } + return characterList; + } - /** - * - * getFirstName looks up the first name of a PlayerCharacter by - * first checking the GOM cache and then querying the database. - * PlayerCharacter objects that are not already cached won't be instantiated - * and cached. - * - */ + /** + * getFirstName looks up the first name of a PlayerCharacter by + * first checking the GOM cache and then querying the database. + * PlayerCharacter objects that are not already cached won't be instantiated + * and cached. + */ - public ConcurrentHashMap GET_IGNORE_LIST(final int objectUUID, final boolean skipActiveCheck) { + public ConcurrentHashMap GET_IGNORE_LIST(final int objectUUID, final boolean skipActiveCheck) { - ConcurrentHashMap ignoreList = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + ConcurrentHashMap ignoreList = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_ignore` WHERE `accountUID` = ?;")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_ignore` WHERE `accountUID` = ?;")) { - preparedStatement.setLong(1, objectUUID); + preparedStatement.setLong(1, objectUUID); - ResultSet rs = preparedStatement.executeQuery(); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) { - int ignoreCharacterID = rs.getInt("ignoringUID"); + while (rs.next()) { + int ignoreCharacterID = rs.getInt("ignoringUID"); - if (ignoreCharacterID == 0) - continue; + if (ignoreCharacterID == 0) + continue; - String name = rs.getString("characterName"); - ignoreList.put(ignoreCharacterID, name); - } + String name = rs.getString("characterName"); + ignoreList.put(ignoreCharacterID, name); + } - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return ignoreList; - } + return ignoreList; + } - public PlayerCharacter GET_PLAYER_CHARACTER(final int objectUUID) { + public PlayerCharacter GET_PLAYER_CHARACTER(final int objectUUID) { - if (objectUUID == 0) - return null; + if (objectUUID == 0) + return null; - PlayerCharacter playerCharacter = (PlayerCharacter) DbManager.getFromCache(Enum.GameObjectType.PlayerCharacter, objectUUID); + PlayerCharacter playerCharacter = (PlayerCharacter) DbManager.getFromCache(Enum.GameObjectType.PlayerCharacter, objectUUID); - if (playerCharacter != null) - return playerCharacter; + if (playerCharacter != null) + return playerCharacter; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_character`.*, `object`.`parent` FROM `object` INNER JOIN `obj_character` ON `obj_character`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_character`.*, `object`.`parent` FROM `object` INNER JOIN `obj_character` ON `obj_character`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?")) { - preparedStatement.setLong(1, objectUUID); + preparedStatement.setLong(1, objectUUID); - ResultSet rs = preparedStatement.executeQuery(); - playerCharacter = (PlayerCharacter) getObjectFromRs(rs); + ResultSet rs = preparedStatement.executeQuery(); + playerCharacter = (PlayerCharacter) getObjectFromRs(rs); - } catch (SQLException e) { - Logger.error(e); - } - ; - return playerCharacter; - } + } catch (SQLException e) { + Logger.error(e); + } + return playerCharacter; + } - public boolean IS_CHARACTER_NAME_UNIQUE(final String firstName) { + public boolean IS_CHARACTER_NAME_UNIQUE(final String firstName) { - boolean unique = true; + boolean unique = true; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `char_firstname` FROM `obj_character` WHERE `char_isActive`=1 && `char_firstname`=?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT `char_firstname` FROM `obj_character` WHERE `char_isActive`=1 && `char_firstname`=?")) { - preparedStatement.setString(1, firstName); + preparedStatement.setString(1, firstName); - ResultSet rs = preparedStatement.executeQuery(); + ResultSet rs = preparedStatement.executeQuery(); - if (rs.next()) - unique = false; + if (rs.next()) + unique = false; - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return unique; - } + return unique; + } - public boolean UPDATE_NAME(String oldFirstName, String newFirstName, String newLastName) { + public boolean UPDATE_NAME(String oldFirstName, String newFirstName, String newLastName) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_firstname`=?, `char_lastname`=? WHERE `char_firstname`=? AND `char_isActive`='1'")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_firstname`=?, `char_lastname`=? WHERE `char_firstname`=? AND `char_isActive`='1'")) { - preparedStatement.setString(1, newFirstName); - preparedStatement.setString(2, newLastName); - preparedStatement.setString(3, oldFirstName); + preparedStatement.setString(1, newFirstName); + preparedStatement.setString(2, newLastName); + preparedStatement.setString(3, oldFirstName); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean SET_DELETED(final PlayerCharacter pc) { + public boolean SET_DELETED(final PlayerCharacter pc) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_isActive`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_isActive`=? WHERE `UID` = ?")) { - preparedStatement.setBoolean(1, !pc.isDeleted()); - preparedStatement.setLong(2, pc.getObjectUUID()); + preparedStatement.setBoolean(1, !pc.isDeleted()); + preparedStatement.setLong(2, pc.getObjectUUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean SET_ACTIVE(final PlayerCharacter pc, boolean status) { + public boolean SET_ACTIVE(final PlayerCharacter pc, boolean status) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_isActive`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_isActive`=? WHERE `UID` = ?")) { - preparedStatement.setBoolean(1, status); - preparedStatement.setLong(2, (long) pc.getObjectUUID()); + preparedStatement.setBoolean(1, status); + preparedStatement.setLong(2, pc.getObjectUUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean SET_BIND_BUILDING(final PlayerCharacter pc, int bindBuildingID) { + public boolean SET_BIND_BUILDING(final PlayerCharacter pc, int bindBuildingID) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_bindBuilding`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_bindBuilding`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, bindBuildingID); - preparedStatement.setLong(2, (long) pc.getObjectUUID()); + preparedStatement.setInt(1, bindBuildingID); + preparedStatement.setLong(2, pc.getObjectUUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean SET_ANNIVERSERY(final PlayerCharacter pc, boolean flag) { + public boolean SET_ANNIVERSERY(final PlayerCharacter pc, boolean flag) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `anniversery`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `anniversery`=? WHERE `UID` = ?")) { - preparedStatement.setBoolean(1, flag); - preparedStatement.setLong(2, (long) pc.getObjectUUID()); + preparedStatement.setBoolean(1, flag); + preparedStatement.setLong(2, pc.getObjectUUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - public boolean UPDATE_CHARACTER_EXPERIENCE(final PlayerCharacter pc) { + public boolean UPDATE_CHARACTER_EXPERIENCE(final PlayerCharacter pc) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_experience`=? WHERE `UID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_experience`=? WHERE `UID` = ?")) { - preparedStatement.setInt(1, pc.getExp()); - preparedStatement.setLong(2, (long) pc.getObjectUUID()); + preparedStatement.setInt(1, pc.getExp()); + preparedStatement.setLong(2, pc.getObjectUUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } - - public boolean UPDATE_GUILD(final PlayerCharacter pc, int guildUUID) { + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guildUID`=? WHERE `UID` = ?")) { + public boolean UPDATE_GUILD(final PlayerCharacter pc, int guildUUID) { - preparedStatement.setInt(1, guildUUID); - preparedStatement.setLong(2, (long) pc.getObjectUUID()); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guildUID`=? WHERE `UID` = ?")) { - return (preparedStatement.executeUpdate() > 0); + preparedStatement.setInt(1, guildUUID); + preparedStatement.setLong(2, pc.getObjectUUID()); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + return (preparedStatement.executeUpdate() > 0); - public boolean UPDATE_CHARACTER_STATS(final PlayerCharacter pc) { + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_strMod`=?, `char_dexMod`=?, `char_conMod`=?, `char_intMod`=?, `char_spiMod`=? WHERE `UID`=?")) { + public boolean UPDATE_CHARACTER_STATS(final PlayerCharacter pc) { - preparedStatement.setInt(1, pc.getStrMod()); - preparedStatement.setInt(2, pc.getDexMod()); - preparedStatement.setInt(3, pc.getConMod()); - preparedStatement.setInt(4, pc.getIntMod()); - preparedStatement.setInt(5, pc.getSpiMod()); - preparedStatement.setLong(6, (long) pc.getObjectUUID()); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_strMod`=?, `char_dexMod`=?, `char_conMod`=?, `char_intMod`=?, `char_spiMod`=? WHERE `UID`=?")) { - return (preparedStatement.executeUpdate() > 0); + preparedStatement.setInt(1, pc.getStrMod()); + preparedStatement.setInt(2, pc.getDexMod()); + preparedStatement.setInt(3, pc.getConMod()); + preparedStatement.setInt(4, pc.getIntMod()); + preparedStatement.setInt(5, pc.getSpiMod()); + preparedStatement.setLong(6, pc.getObjectUUID()); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + return (preparedStatement.executeUpdate() > 0); - public String SET_PROPERTY(final PlayerCharacter playerCharacter, String name, Object new_value) { + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - String result = ""; + public String SET_PROPERTY(final PlayerCharacter playerCharacter, String name, Object new_value) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("CALL character_SETPROP(?,?,?)")) { + String result = ""; - preparedStatement.setLong(1, playerCharacter.getObjectUUID()); - preparedStatement.setString(2, name); - ; - preparedStatement.setString(3, String.valueOf(new_value)); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("CALL character_SETPROP(?,?,?)")) { - ResultSet rs = preparedStatement.executeQuery(); - result = rs.getString("result"); + preparedStatement.setLong(1, playerCharacter.getObjectUUID()); + preparedStatement.setString(2, name); + preparedStatement.setString(3, String.valueOf(new_value)); - } catch (SQLException e) { - Logger.error(e); - } - return result; - } + ResultSet rs = preparedStatement.executeQuery(); + result = rs.getString("result"); - public boolean SET_PROMOTION_CLASS(PlayerCharacter player, int promotionClassID) { + } catch (SQLException e) { + Logger.error(e); + } + return result; + } - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_promotionClassID`=? WHERE `UID`=?;")) { + public boolean SET_PROMOTION_CLASS(PlayerCharacter player, int promotionClassID) { - preparedStatement.setInt(1, promotionClassID); - preparedStatement.setInt(2, player.getObjectUUID()); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_promotionClassID`=? WHERE `UID`=?;")) { - return (preparedStatement.executeUpdate() > 0); + preparedStatement.setInt(1, promotionClassID); + preparedStatement.setInt(2, player.getObjectUUID()); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } - - public boolean SET_INNERCOUNCIL(PlayerCharacter player, boolean isInnerCouncil) { + return (preparedStatement.executeUpdate() > 0); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isInnerCouncil`=? WHERE `UID`=?;")) { + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - preparedStatement.setBoolean(1, isInnerCouncil); - preparedStatement.setInt(2, player.getObjectUUID()); + public boolean SET_INNERCOUNCIL(PlayerCharacter player, boolean isInnerCouncil) { - return (preparedStatement.executeUpdate() > 0); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isInnerCouncil`=? WHERE `UID`=?;")) { - } catch (SQLException e) { - Logger.error(e); - } - return false; - } - - public boolean SET_FULL_MEMBER(PlayerCharacter player, boolean isFullMember) { + preparedStatement.setBoolean(1, isInnerCouncil); + preparedStatement.setInt(2, player.getObjectUUID()); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isFullMember`=? WHERE `UID`=?;")) { + return (preparedStatement.executeUpdate() > 0); - preparedStatement.setBoolean(1, isFullMember); - preparedStatement.setInt(2, player.getObjectUUID()); + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - return (preparedStatement.executeUpdate() > 0); + public boolean SET_FULL_MEMBER(PlayerCharacter player, boolean isFullMember) { - } catch (SQLException e) { - Logger.error(e); - } - return false; - } - - public boolean SET_TAX_COLLECTOR(PlayerCharacter player, boolean isTaxCollector) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isFullMember`=? WHERE `UID`=?;")) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isTaxCollector`=? WHERE `UID`=?;")) { + preparedStatement.setBoolean(1, isFullMember); + preparedStatement.setInt(2, player.getObjectUUID()); - preparedStatement.setBoolean(1, isTaxCollector); - preparedStatement.setInt(2, player.getObjectUUID()); + return (preparedStatement.executeUpdate() > 0); - return (preparedStatement.executeUpdate() > 0); + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - } catch (SQLException e) { - Logger.error(e); - } - return false; - } - - public boolean SET_RECRUITER(PlayerCharacter player, boolean isRecruiter) { + public boolean SET_TAX_COLLECTOR(PlayerCharacter player, boolean isTaxCollector) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isRecruiter`=? WHERE `UID`=?;")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isTaxCollector`=? WHERE `UID`=?;")) { - preparedStatement.setBoolean(1, isRecruiter); - preparedStatement.setInt(2, player.getObjectUUID()); + preparedStatement.setBoolean(1, isTaxCollector); + preparedStatement.setInt(2, player.getObjectUUID()); - return (preparedStatement.executeUpdate() > 0); + return (preparedStatement.executeUpdate() > 0); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } - - public boolean SET_GUILD_TITLE(PlayerCharacter player, int title) { + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_title`=? WHERE `UID`=?;")) { + public boolean SET_RECRUITER(PlayerCharacter player, boolean isRecruiter) { - preparedStatement.setInt(1, title); - preparedStatement.setInt(2, player.getObjectUUID()); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isRecruiter`=? WHERE `UID`=?;")) { - return (preparedStatement.executeUpdate() > 0); + preparedStatement.setBoolean(1, isRecruiter); + preparedStatement.setInt(2, player.getObjectUUID()); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } + return (preparedStatement.executeUpdate() > 0); - public boolean ADD_FRIEND(int source, long friend) { + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_friends` (`playerUID`, `friendUID`) VALUES (?, ?)")) { + public boolean SET_GUILD_TITLE(PlayerCharacter player, int title) { - preparedStatement.setLong(1, source); - preparedStatement.setLong(2, friend); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_title`=? WHERE `UID`=?;")) { - return (preparedStatement.executeUpdate() > 0); + preparedStatement.setInt(1, title); + preparedStatement.setInt(2, player.getObjectUUID()); - } catch (SQLException e) { - Logger.error(e); - } - return false; - } - - public boolean REMOVE_FRIEND(int source, int friend) { + return (preparedStatement.executeUpdate() > 0); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_friends` WHERE (`playerUID`=?) AND (`friendUID`=?)")) { + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - preparedStatement.setLong(1, source); - preparedStatement.setLong(2, friend); + public boolean ADD_FRIEND(int source, long friend) { - return (preparedStatement.executeUpdate() > 0); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_friends` (`playerUID`, `friendUID`) VALUES (?, ?)")) { - } catch (SQLException e) { - Logger.error(e); - } - return false; - } - - public void LOAD_PLAYER_FRIENDS() { + preparedStatement.setLong(1, source); + preparedStatement.setLong(2, friend); - PlayerFriends playerFriend; + return (preparedStatement.executeUpdate() > 0); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM dyn_character_friends")) { + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - ResultSet rs = preparedStatement.executeQuery(); + public boolean REMOVE_FRIEND(int source, int friend) { - while (rs.next()) - playerFriend = new PlayerFriends(rs); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_friends` WHERE (`playerUID`=?) AND (`friendUID`=?)")) { - } catch (SQLException e) { - Logger.error(e); - } + preparedStatement.setLong(1, source); + preparedStatement.setLong(2, friend); - prepareCallable("SELECT * FROM dyn_character_friends"); - } - - public boolean ADD_HERALDY(int source, AbstractWorldObject character) { + return (preparedStatement.executeUpdate() > 0); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_heraldy` (`playerUID`, `characterUID`,`characterType`) VALUES (?, ?,?)")) { + } catch (SQLException e) { + Logger.error(e); + } + return false; + } - preparedStatement.setLong(1, source); - preparedStatement.setLong(2, character.getObjectUUID()); - preparedStatement.setInt(3, character.getObjectType().ordinal()); + public void LOAD_PLAYER_FRIENDS() { - return (preparedStatement.executeUpdate() > 0); + PlayerFriends playerFriend; - } catch (SQLException e) { - Logger.error(e); - } - return false; - } - - public boolean REMOVE_HERALDY(int source, int characterUID) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM dyn_character_friends")) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_heraldy` WHERE (`playerUID`=?) AND (`characterUID`=?)")) { + ResultSet rs = preparedStatement.executeQuery(); - preparedStatement.setLong(1, source); - preparedStatement.setLong(2, characterUID); + while (rs.next()) + playerFriend = new PlayerFriends(rs); - return (preparedStatement.executeUpdate() > 0); + } catch (SQLException e) { + Logger.error(e); + } - } catch (SQLException e) { - Logger.error(e); - } - return false; - } - - public void LOAD_HERALDY() { + prepareCallable("SELECT * FROM dyn_character_friends"); + } - Heraldry heraldy; + public boolean ADD_HERALDY(int source, AbstractWorldObject character) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM dyn_character_heraldy")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_heraldy` (`playerUID`, `characterUID`,`characterType`) VALUES (?, ?,?)")) { - ResultSet rs = preparedStatement.executeQuery(); + preparedStatement.setLong(1, source); + preparedStatement.setLong(2, character.getObjectUUID()); + preparedStatement.setInt(3, character.getObjectType().ordinal()); - while (rs.next()) - heraldy = new Heraldry(rs); + return (preparedStatement.executeUpdate() > 0); + + } catch (SQLException e) { + Logger.error(e); + } + return false; + } + + public boolean REMOVE_HERALDY(int source, int characterUID) { + + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_heraldy` WHERE (`playerUID`=?) AND (`characterUID`=?)")) { + + preparedStatement.setLong(1, source); + preparedStatement.setLong(2, characterUID); + + return (preparedStatement.executeUpdate() > 0); + + } catch (SQLException e) { + Logger.error(e); + } + return false; + } + + public void LOAD_HERALDY() { + + Heraldry heraldy; + + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM dyn_character_heraldy")) { + + ResultSet rs = preparedStatement.executeQuery(); + + while (rs.next()) + heraldy = new Heraldry(rs); + + } catch (SQLException e) { + Logger.error(e); + } + } - } catch (SQLException e) { - Logger.error(e); - } - } - } diff --git a/src/engine/db/handlers/dbPromotionClassHandler.java b/src/engine/db/handlers/dbPromotionClassHandler.java index fed00a7a..aef9af8e 100644 --- a/src/engine/db/handlers/dbPromotionClassHandler.java +++ b/src/engine/db/handlers/dbPromotionClassHandler.java @@ -65,7 +65,7 @@ public class dbPromotionClassHandler extends dbHandlerBase { return promotionClass; } - + public ArrayList GET_ALL_PROMOTIONS() { ArrayList promotionList = new ArrayList<>(); diff --git a/src/engine/db/handlers/dbRuneBaseAttributeHandler.java b/src/engine/db/handlers/dbRuneBaseAttributeHandler.java index 923385b1..536addb5 100644 --- a/src/engine/db/handlers/dbRuneBaseAttributeHandler.java +++ b/src/engine/db/handlers/dbRuneBaseAttributeHandler.java @@ -21,27 +21,27 @@ import java.util.ArrayList; public class dbRuneBaseAttributeHandler extends dbHandlerBase { - public dbRuneBaseAttributeHandler() { - this.localClass = RuneBaseAttribute.class; - this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); - } + public dbRuneBaseAttributeHandler() { + this.localClass = RuneBaseAttribute.class; + this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); + } - public ArrayList GET_ATTRIBUTES_FOR_RUNEBASE() { + public ArrayList GET_ATTRIBUTES_FOR_RUNEBASE() { - ArrayList runeBaseAttributesList = new ArrayList<>(); + ArrayList runeBaseAttributesList = new ArrayList<>(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runebaseattribute`")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runebaseattribute`")) { - ResultSet rs = preparedStatement.executeQuery(); - runeBaseAttributesList = getObjectsFromRs(rs, 10); + ResultSet rs = preparedStatement.executeQuery(); + runeBaseAttributesList = getObjectsFromRs(rs, 10); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return runeBaseAttributesList; - } + return runeBaseAttributesList; + } } diff --git a/src/engine/db/handlers/dbRuneBaseEffectHandler.java b/src/engine/db/handlers/dbRuneBaseEffectHandler.java index c8b790a1..def0f204 100644 --- a/src/engine/db/handlers/dbRuneBaseEffectHandler.java +++ b/src/engine/db/handlers/dbRuneBaseEffectHandler.java @@ -24,69 +24,68 @@ import java.util.HashMap; public class dbRuneBaseEffectHandler extends dbHandlerBase { - public dbRuneBaseEffectHandler() { - this.localClass = RuneBaseEffect.class; - this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); - } + public dbRuneBaseEffectHandler() { + this.localClass = RuneBaseEffect.class; + this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); + } - public ArrayList GET_EFFECTS_FOR_RUNEBASE(int id) { + public ArrayList GET_EFFECTS_FOR_RUNEBASE(int id) { - ArrayList runeBaseEffectsList = new ArrayList<>(); + ArrayList runeBaseEffectsList = new ArrayList<>(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_baseeffect` WHERE `runeID`=?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_baseeffect` WHERE `runeID`=?")) { - preparedStatement.setInt(1, id); + preparedStatement.setInt(1, id); - ResultSet rs = preparedStatement.executeQuery(); - runeBaseEffectsList = getObjectsFromRs(rs, 250); + ResultSet rs = preparedStatement.executeQuery(); + runeBaseEffectsList = getObjectsFromRs(rs, 250); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return runeBaseEffectsList; - } + return runeBaseEffectsList; + } - public ArrayList GET_ALL_RUNEBASE_EFFECTS() { + public ArrayList GET_ALL_RUNEBASE_EFFECTS() { - ArrayList runeBaseEffectsList = new ArrayList<>(); + ArrayList runeBaseEffectsList = new ArrayList<>(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_baseeffect`;")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_baseeffect`;")) { - ResultSet rs = preparedStatement.executeQuery(); - runeBaseEffectsList = getObjectsFromRs(rs, 250); + ResultSet rs = preparedStatement.executeQuery(); + runeBaseEffectsList = getObjectsFromRs(rs, 250); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return runeBaseEffectsList; - } + return runeBaseEffectsList; + } - //This calls from cache only. Call this AFTER caching all runebase effects; + //This calls from cache only. Call this AFTER caching all runebase effects; - public HashMap> LOAD_BASEEFFECTS_FOR_RUNEBASE() { + public HashMap> LOAD_BASEEFFECTS_FOR_RUNEBASE() { - HashMap> runeBaseEffectSet; - runeBaseEffectSet = new HashMap<>(); + HashMap> runeBaseEffectSet; + runeBaseEffectSet = new HashMap<>(); - for (AbstractGameObject runeBaseEffect:DbManager.getList(GameObjectType.RuneBaseEffect)){ + for (AbstractGameObject runeBaseEffect : DbManager.getList(GameObjectType.RuneBaseEffect)) { - int runeBaseID = ((RuneBaseEffect)runeBaseEffect).getRuneBaseID(); - if (runeBaseEffectSet.get(runeBaseID) == null){ - ArrayList runeBaseEffectList = new ArrayList<>(); - runeBaseEffectList.add((RuneBaseEffect)runeBaseEffect); - runeBaseEffectSet.put(runeBaseID, runeBaseEffectList); - } - else{ - ArrayListruneBaseEffectList = runeBaseEffectSet.get(runeBaseID); - runeBaseEffectList.add((RuneBaseEffect)runeBaseEffect); - runeBaseEffectSet.put(runeBaseID, runeBaseEffectList); - } - } - return runeBaseEffectSet; - } + int runeBaseID = ((RuneBaseEffect) runeBaseEffect).getRuneBaseID(); + if (runeBaseEffectSet.get(runeBaseID) == null) { + ArrayList runeBaseEffectList = new ArrayList<>(); + runeBaseEffectList.add((RuneBaseEffect) runeBaseEffect); + runeBaseEffectSet.put(runeBaseID, runeBaseEffectList); + } else { + ArrayList runeBaseEffectList = runeBaseEffectSet.get(runeBaseID); + runeBaseEffectList.add((RuneBaseEffect) runeBaseEffect); + runeBaseEffectSet.put(runeBaseID, runeBaseEffectList); + } + } + return runeBaseEffectSet; + } } diff --git a/src/engine/db/handlers/dbRuneBaseHandler.java b/src/engine/db/handlers/dbRuneBaseHandler.java index 235f96a9..af66b036 100644 --- a/src/engine/db/handlers/dbRuneBaseHandler.java +++ b/src/engine/db/handlers/dbRuneBaseHandler.java @@ -22,158 +22,158 @@ import java.util.HashMap; public class dbRuneBaseHandler extends dbHandlerBase { - public dbRuneBaseHandler() { - this.localClass = RuneBase.class; - this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); - } + public dbRuneBaseHandler() { + this.localClass = RuneBase.class; + this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); + } - public void GET_RUNE_REQS(final RuneBase rb) { + public void GET_RUNE_REQS(final RuneBase rb) { - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runereq` WHERE `runeID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runereq` WHERE `runeID` = ?")) { - preparedStatement.setInt(1, rb.getObjectUUID()); + preparedStatement.setInt(1, rb.getObjectUUID()); - ResultSet rs = preparedStatement.executeQuery(); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) { - int type = rs.getInt("type"); + while (rs.next()) { + int type = rs.getInt("type"); - switch (type) { - case 1: - rb.getRace().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed")); - break; - case 2: - rb.getBaseClass().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed")); - break; - case 3: - rb.getPromotionClass().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed")); - break; - case 4: - rb.getDiscipline().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed")); - break; - case 5: - rb.getOverwrite().add(rs.getInt("requiredRuneID")); - break; - case 6: - rb.setLevelRequired(rs.getInt("requiredRuneID")); - break; - } - } + switch (type) { + case 1: + rb.getRace().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed")); + break; + case 2: + rb.getBaseClass().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed")); + break; + case 3: + rb.getPromotionClass().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed")); + break; + case 4: + rb.getDiscipline().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed")); + break; + case 5: + rb.getOverwrite().add(rs.getInt("requiredRuneID")); + break; + case 6: + rb.setLevelRequired(rs.getInt("requiredRuneID")); + break; + } + } - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - } + } - public RuneBase GET_RUNEBASE(final int id) { + public RuneBase GET_RUNEBASE(final int id) { - RuneBase runeBase = null; + RuneBase runeBase = null; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runebase` WHERE `ID` = ?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runebase` WHERE `ID` = ?")) { - preparedStatement.setInt(1, id); + preparedStatement.setInt(1, id); - ResultSet rs = preparedStatement.executeQuery(); - runeBase = (RuneBase) getObjectFromRs(rs); + ResultSet rs = preparedStatement.executeQuery(); + runeBase = (RuneBase) getObjectFromRs(rs); - } catch (SQLException e) { - Logger.error(e); - } - return runeBase; - } + } catch (SQLException e) { + Logger.error(e); + } + return runeBase; + } - public ArrayList LOAD_ALL_RUNEBASES() { + public ArrayList LOAD_ALL_RUNEBASES() { - ArrayList runeBasesList = new ArrayList<>(); + ArrayList runeBasesList = new ArrayList<>(); - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runebase`;")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runebase`;")) { - ResultSet rs = preparedStatement.executeQuery(); - runeBasesList = getObjectsFromRs(rs, 1000); + ResultSet rs = preparedStatement.executeQuery(); + runeBasesList = getObjectsFromRs(rs, 1000); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return runeBasesList; - } + return runeBasesList; + } - public HashMap> LOAD_ALLOWED_STARTING_RUNES_FOR_BASECLASS() { + public HashMap> LOAD_ALLOWED_STARTING_RUNES_FOR_BASECLASS() { - HashMap> runeSets = new HashMap<>(); + HashMap> runeSets = new HashMap<>(); - int recordsRead = 0; + int recordsRead = 0; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_rune_baseclassrune")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_rune_baseclassrune")) { - ResultSet rs = preparedStatement.executeQuery(); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) { + while (rs.next()) { - recordsRead++; + recordsRead++; - int baseClassID = rs.getInt("BaseClassesID"); - int runeBaseID = rs.getInt("RuneBaseID"); + int baseClassID = rs.getInt("BaseClassesID"); + int runeBaseID = rs.getInt("RuneBaseID"); - if (runeSets.get(baseClassID) == null) { - ArrayList runeList = new ArrayList<>(); - runeList.add(runeBaseID); - runeSets.put(baseClassID, runeList); - } else { - ArrayList runeList = runeSets.get(baseClassID); - runeList.add(runeBaseID); - runeSets.put(baseClassID, runeList); - } - } + if (runeSets.get(baseClassID) == null) { + ArrayList runeList = new ArrayList<>(); + runeList.add(runeBaseID); + runeSets.put(baseClassID, runeList); + } else { + ArrayList runeList = runeSets.get(baseClassID); + runeList.add(runeBaseID); + runeSets.put(baseClassID, runeList); + } + } - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - Logger.info("read: " + recordsRead + " cached: " + runeSets.size()); + Logger.info("read: " + recordsRead + " cached: " + runeSets.size()); - return runeSets; - } + return runeSets; + } - public HashMap> LOAD_ALLOWED_STARTING_RUNES_FOR_RACE() { + public HashMap> LOAD_ALLOWED_STARTING_RUNES_FOR_RACE() { - HashMap> runeSets; + HashMap> runeSets; - runeSets = new HashMap<>(); - int recordsRead = 0; + runeSets = new HashMap<>(); + int recordsRead = 0; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_rune_racerune")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_rune_racerune")) { - ResultSet rs = preparedStatement.executeQuery(); + ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) { + while (rs.next()) { - recordsRead++; + recordsRead++; - int raceID = rs.getInt("RaceID"); - int runeBaseID = rs.getInt("RuneBaseID"); + int raceID = rs.getInt("RaceID"); + int runeBaseID = rs.getInt("RuneBaseID"); - if (runeSets.get(raceID) == null) { - ArrayList runeList = new ArrayList<>(); - runeList.add(runeBaseID); - runeSets.put(raceID, runeList); - } else { - ArrayList runeList = runeSets.get(raceID); - runeList.add(runeBaseID); - runeSets.put(raceID, runeList); - } - } - } catch (SQLException e) { - Logger.error(e); - } + if (runeSets.get(raceID) == null) { + ArrayList runeList = new ArrayList<>(); + runeList.add(runeBaseID); + runeSets.put(raceID, runeList); + } else { + ArrayList runeList = runeSets.get(raceID); + runeList.add(runeBaseID); + runeSets.put(raceID, runeList); + } + } + } catch (SQLException e) { + Logger.error(e); + } - Logger.info("read: " + recordsRead + " cached: " + runeSets.size()); - return runeSets; - } + Logger.info("read: " + recordsRead + " cached: " + runeSets.size()); + return runeSets; + } } diff --git a/src/engine/db/handlers/dbShrineHandler.java b/src/engine/db/handlers/dbShrineHandler.java index 2dc1289e..5857372a 100644 --- a/src/engine/db/handlers/dbShrineHandler.java +++ b/src/engine/db/handlers/dbShrineHandler.java @@ -31,10 +31,28 @@ public class dbShrineHandler extends dbHandlerBase { this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); } - public ArrayList CREATE_SHRINE( int parentZoneID, int OwnerUUID, String name, int meshUUID, - Vector3fImmutable location, float meshScale, int currentHP, - ProtectionState protectionState, int currentGold, int rank, - DateTime upgradeDate, int blueprintUUID, float w, float rotY, String shrineType) { + public static void addObject(ArrayList list, ResultSet rs) throws SQLException { + + String type = rs.getString("type"); + + switch (type) { + case "building": + Building building = new Building(rs); + DbManager.addToCache(building); + list.add(building); + break; + case "shrine": + Shrine shrine = new Shrine(rs); + DbManager.addToCache(shrine); + list.add(shrine); + break; + } + } + + public ArrayList CREATE_SHRINE(int parentZoneID, int OwnerUUID, String name, int meshUUID, + Vector3fImmutable location, float meshScale, int currentHP, + ProtectionState protectionState, int currentGold, int rank, + DateTime upgradeDate, int blueprintUUID, float w, float rotY, String shrineType) { ArrayList shrineList = new ArrayList<>(); @@ -103,24 +121,6 @@ public class dbShrineHandler extends dbHandlerBase { } - public static void addObject(ArrayList list, ResultSet rs) throws SQLException { - - String type = rs.getString("type"); - - switch (type) { - case "building": - Building building = new Building(rs); - DbManager.addToCache(building); - list.add(building); - break; - case "shrine": - Shrine shrine = new Shrine(rs); - DbManager.addToCache(shrine); - list.add(shrine); - break; - } - } - public void LOAD_ALL_SHRINES() { Shrine shrine; diff --git a/src/engine/db/handlers/dbSkillBaseHandler.java b/src/engine/db/handlers/dbSkillBaseHandler.java index 0811c3a2..77e55fdf 100644 --- a/src/engine/db/handlers/dbSkillBaseHandler.java +++ b/src/engine/db/handlers/dbSkillBaseHandler.java @@ -26,113 +26,112 @@ import java.util.HashMap; public class dbSkillBaseHandler extends dbHandlerBase { - public dbSkillBaseHandler() { - this.localClass = SkillsBase.class; - this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); - } - - public SkillsBase GET_BASE(final int objectUUID) { - - SkillsBase skillsBase = (SkillsBase) DbManager.getFromCache(GameObjectType.SkillsBase, objectUUID); - if (skillsBase != null) - return skillsBase; - prepareCallable("SELECT * FROM static_skill_skillsbase WHERE ID = ?"); - setInt(1, objectUUID); - SkillsBase sb; - sb = (SkillsBase) getObjectSingle(objectUUID); - SkillsBase.putInCache(sb); - return sb; - } - - public SkillsBase GET_BASE_BY_NAME(String name) { - SkillsBase sb = SkillsBase.getFromCache(name); - if (sb != null) { - return sb; - } - prepareCallable("SELECT * FROM static_skill_skillsbase WHERE name = ?"); - setString(1, name); - ArrayList result = getObjectList(); - if (result.size() > 0) { - sb = (SkillsBase) result.get(0); - SkillsBase.putInCache(sb); - return sb; - } else { - return null; - } - } - - public SkillsBase GET_BASE_BY_TOKEN(final int token) { - SkillsBase sb = SkillsBase.getFromCache(token); - if (sb != null) { - return sb; - } - - prepareCallable("SELECT * FROM static_skill_skillsbase WHERE token = ?"); - setInt(1, token); - ArrayList result = getObjectList(); - if (result.size() > 0) { - sb = (SkillsBase) result.get(0); - SkillsBase.putInCache(sb); - return sb; - } else { - return null; - } - } - - public void LOAD_ALL_MAX_SKILLS_FOR_CONTRACT() { - - prepareCallable("SELECT * FROM `static_rune_maxskills`"); - - - try { - ResultSet rs = executeQuery(); - - //shrines cached in rs for easy cache on creation. - while (rs.next()) { - - MaxSkills maxSKills = new MaxSkills(rs); - if (MaxSkills.MaxSkillsSet.get(maxSKills.getRuneID()) == null){ - ArrayList newMaxSkillsList = new ArrayList<>(); - newMaxSkillsList.add(maxSKills); - MaxSkills.MaxSkillsSet.put(maxSKills.getRuneID(), newMaxSkillsList); - }else - MaxSkills.MaxSkillsSet.get(maxSKills.getRuneID()).add(maxSKills); - - } - - - - } catch (SQLException e) { - Logger.error( e.getErrorCode() + ' ' + e.getMessage(), e); - } finally { - closeCallable(); - } - - } - - public void LOAD_ALL_RUNE_SKILLS() { - - - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_skill_skillsgranted`")) { - - ResultSet rs = preparedStatement.executeQuery(); - - while (rs.next()) { - - int runeID = rs.getInt("runeID"); - int token = rs.getInt("token"); - int amount = rs.getInt("amount"); - - if (SkillsBase.runeSkillsCache.get(runeID) == null) - SkillsBase.runeSkillsCache.put(runeID, new HashMap<>()); - - SkillsBase.runeSkillsCache.get(runeID).put(token, amount); - } - - } catch (SQLException e) { - Logger.error(e); - } - } + public dbSkillBaseHandler() { + this.localClass = SkillsBase.class; + this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); + } + + public SkillsBase GET_BASE(final int objectUUID) { + + SkillsBase skillsBase = (SkillsBase) DbManager.getFromCache(GameObjectType.SkillsBase, objectUUID); + if (skillsBase != null) + return skillsBase; + prepareCallable("SELECT * FROM static_skill_skillsbase WHERE ID = ?"); + setInt(1, objectUUID); + SkillsBase sb; + sb = (SkillsBase) getObjectSingle(objectUUID); + SkillsBase.putInCache(sb); + return sb; + } + + public SkillsBase GET_BASE_BY_NAME(String name) { + SkillsBase sb = SkillsBase.getFromCache(name); + if (sb != null) { + return sb; + } + prepareCallable("SELECT * FROM static_skill_skillsbase WHERE name = ?"); + setString(1, name); + ArrayList result = getObjectList(); + if (result.size() > 0) { + sb = (SkillsBase) result.get(0); + SkillsBase.putInCache(sb); + return sb; + } else { + return null; + } + } + + public SkillsBase GET_BASE_BY_TOKEN(final int token) { + SkillsBase sb = SkillsBase.getFromCache(token); + if (sb != null) { + return sb; + } + + prepareCallable("SELECT * FROM static_skill_skillsbase WHERE token = ?"); + setInt(1, token); + ArrayList result = getObjectList(); + if (result.size() > 0) { + sb = (SkillsBase) result.get(0); + SkillsBase.putInCache(sb); + return sb; + } else { + return null; + } + } + + public void LOAD_ALL_MAX_SKILLS_FOR_CONTRACT() { + + prepareCallable("SELECT * FROM `static_rune_maxskills`"); + + + try { + ResultSet rs = executeQuery(); + + //shrines cached in rs for easy cache on creation. + while (rs.next()) { + + MaxSkills maxSKills = new MaxSkills(rs); + if (MaxSkills.MaxSkillsSet.get(maxSKills.getRuneID()) == null) { + ArrayList newMaxSkillsList = new ArrayList<>(); + newMaxSkillsList.add(maxSKills); + MaxSkills.MaxSkillsSet.put(maxSKills.getRuneID(), newMaxSkillsList); + } else + MaxSkills.MaxSkillsSet.get(maxSKills.getRuneID()).add(maxSKills); + + } + + + } catch (SQLException e) { + Logger.error(e.getErrorCode() + ' ' + e.getMessage(), e); + } finally { + closeCallable(); + } + + } + + public void LOAD_ALL_RUNE_SKILLS() { + + + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_skill_skillsgranted`")) { + + ResultSet rs = preparedStatement.executeQuery(); + + while (rs.next()) { + + int runeID = rs.getInt("runeID"); + int token = rs.getInt("token"); + int amount = rs.getInt("amount"); + + if (SkillsBase.runeSkillsCache.get(runeID) == null) + SkillsBase.runeSkillsCache.put(runeID, new HashMap<>()); + + SkillsBase.runeSkillsCache.get(runeID).put(token, amount); + } + + } catch (SQLException e) { + Logger.error(e); + } + } } diff --git a/src/engine/db/handlers/dbVendorDialogHandler.java b/src/engine/db/handlers/dbVendorDialogHandler.java index eb6a1c92..8bcc40ee 100644 --- a/src/engine/db/handlers/dbVendorDialogHandler.java +++ b/src/engine/db/handlers/dbVendorDialogHandler.java @@ -21,30 +21,30 @@ import java.sql.SQLException; public class dbVendorDialogHandler extends dbHandlerBase { - public dbVendorDialogHandler() { - this.localClass = VendorDialog.class; - this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); - } + public dbVendorDialogHandler() { + this.localClass = VendorDialog.class; + this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); + } - public VendorDialog GET_VENDORDIALOG(final int objectUUID) { + public VendorDialog GET_VENDORDIALOG(final int objectUUID) { - VendorDialog vendorDialog = (VendorDialog) DbManager.getFromCache(Enum.GameObjectType.VendorDialog, objectUUID); + VendorDialog vendorDialog = (VendorDialog) DbManager.getFromCache(Enum.GameObjectType.VendorDialog, objectUUID); - if (vendorDialog != null) - return vendorDialog; + if (vendorDialog != null) + return vendorDialog; - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_vendordialog` WHERE `ID`=?")) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_vendordialog` WHERE `ID`=?")) { - preparedStatement.setInt(1, objectUUID); + preparedStatement.setInt(1, objectUUID); - ResultSet rs = preparedStatement.executeQuery(); - vendorDialog = (VendorDialog) getObjectFromRs(rs); + ResultSet rs = preparedStatement.executeQuery(); + vendorDialog = (VendorDialog) getObjectFromRs(rs); - } catch (SQLException e) { - Logger.error(e); - } + } catch (SQLException e) { + Logger.error(e); + } - return vendorDialog; - } + return vendorDialog; + } } diff --git a/src/engine/db/handlers/dbZoneHandler.java b/src/engine/db/handlers/dbZoneHandler.java index 9950f31f..8b6b603f 100644 --- a/src/engine/db/handlers/dbZoneHandler.java +++ b/src/engine/db/handlers/dbZoneHandler.java @@ -11,6 +11,8 @@ package engine.db.handlers; import engine.Enum; import engine.gameManager.DbManager; +import engine.gameManager.ZoneManager; +import engine.math.Vector2f; import engine.objects.Zone; import org.pmw.tinylog.Logger; @@ -77,7 +79,7 @@ public class dbZoneHandler extends dbHandlerBase { try (Connection connection = DbManager.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_zone`.*, `object`.`parent` FROM `object` INNER JOIN `obj_zone` ON `obj_zone`.`UID` = `object`.`UID` WHERE `object`.`parent` = ?;")) { - preparedStatement.setLong(1, (long) objectUUID); + preparedStatement.setLong(1, objectUUID); ResultSet rs = preparedStatement.executeQuery(); zoneList = getObjectsFromRs(rs, 2000); @@ -89,19 +91,24 @@ public class dbZoneHandler extends dbHandlerBase { return zoneList; } - public ResultSet GET_ZONE_EXTENTS(final int loadNum) { + public void LOAD_ZONE_EXTENTS() { try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_zone_size` WHERE `loadNum`=?;")) { + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_zone_size`;")) { - preparedStatement.setInt(1, loadNum); + ResultSet rs = preparedStatement.executeQuery(); - return preparedStatement.executeQuery(); + while (rs.next()) { + Vector2f zoneSize = new Vector2f(); + int loadNum = rs.getInt("loadNum"); + zoneSize.x = rs.getFloat("xRadius"); + zoneSize.y = rs.getFloat("zRadius"); + ZoneManager._zone_size_data.put(loadNum, zoneSize); + } } catch (SQLException e) { Logger.error(e); } - return null; } public boolean DELETE_ZONE(final Zone zone) { diff --git a/src/engine/gameManager/ZoneManager.java b/src/engine/gameManager/ZoneManager.java index f4e2f434..896c8fd1 100644 --- a/src/engine/gameManager/ZoneManager.java +++ b/src/engine/gameManager/ZoneManager.java @@ -24,10 +24,7 @@ import org.pmw.tinylog.Logger; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Set; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ThreadLocalRandom; @@ -39,17 +36,18 @@ public enum ZoneManager { ZONEMANAGER; - public static Instant hotZoneLastUpdate; - /* Instance variables */ - private static Zone seaFloor = null; - public static Zone hotZone = null; - public static int hotZoneCycle = 0; // Used with HOTZONE_DURATION from config. + public static final Set macroZones = Collections.newSetFromMap(new ConcurrentHashMap<>()); private static final ConcurrentHashMap zonesByID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD); private static final ConcurrentHashMap zonesByUUID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD); private static final ConcurrentHashMap zonesByName = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD); - public static final Set macroZones = Collections.newSetFromMap(new ConcurrentHashMap<>()); private static final Set npcCityZones = Collections.newSetFromMap(new ConcurrentHashMap<>()); private static final Set playerCityZones = Collections.newSetFromMap(new ConcurrentHashMap<>()); + public static Instant hotZoneLastUpdate; + public static Zone hotZone = null; + public static int hotZoneCycle = 0; // Used with HOTZONE_DURATION from config. + public static HashMap _zone_size_data = new HashMap<>(); + /* Instance variables */ + private static Zone seaFloor = null; // Find all zones coordinates fit into, starting with Sea Floor @@ -170,14 +168,14 @@ public enum ZoneManager { return (Bounds.collide(loc, ZoneManager.hotZone.getBounds()) == true); } - public static void setSeaFloor(final Zone value) { - ZoneManager.seaFloor = value; - } - public static Zone getSeaFloor() { return ZoneManager.seaFloor; } + public static void setSeaFloor(final Zone value) { + ZoneManager.seaFloor = value; + } + public static final void populateWorldZones(final Zone zone) { int loadNum = zone.getLoadNum(); diff --git a/src/engine/objects/Zone.java b/src/engine/objects/Zone.java index 5f04cc74..8fddf5d5 100644 --- a/src/engine/objects/Zone.java +++ b/src/engine/objects/Zone.java @@ -30,19 +30,25 @@ import java.util.concurrent.ConcurrentHashMap; public class Zone extends AbstractGameObject { + public final Set zoneBuildingSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); + public final Set zoneNPCSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); + public final Set zoneMobSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); private final int playerCityID; private final String zoneName; private final float xCoord; private final float zCoord; private final float yCoord; - public float absX = 0.0f; - public float absY = 0.0f; - public float absZ = 0.0f; private final int loadNum; private final byte safeZone; private final String Icon1; private final String Icon2; private final String Icon3; + public float absX = 0.0f; + public float absY = 0.0f; + public float absZ = 0.0f; + public int minLvl; + public int maxLvl; + public boolean hasBeenHotzone = false; private ArrayList nodes = null; private int parentZoneID; private Zone parent = null; @@ -50,16 +56,9 @@ public class Zone extends AbstractGameObject { private boolean isNPCCity = false; private boolean isPlayerCity = false; private String hash; - public int minLvl; - public int maxLvl; - private float worldAltitude = 0; - private float seaLevel = 0; - public final Set zoneBuildingSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); - public final Set zoneNPCSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); - public final Set zoneMobSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); - public boolean hasBeenHotzone = false; + /** * ResultSet Constructor */ @@ -87,7 +86,7 @@ public class Zone extends AbstractGameObject { this.setParent(parentZone); - if (this.minLvl == 0 && parentZone != null){ + if (this.minLvl == 0 && parentZone != null) { this.minLvl = parentZone.minLvl; this.maxLvl = parentZone.maxLvl; } @@ -99,10 +98,63 @@ public class Zone extends AbstractGameObject { if (hash == null) setHash(); - + } + public static void serializeForClientMsg(Zone zone, ByteBufferWriter writer) { + + if (zone.loadNum == 0 && zone.playerCityID == 0) + Logger.warn("Warning! WorldServerMap with ID " + zone.getObjectUUID() + " has a loadnum of 0 (player city) and no city linked. This will probably crash the client!"); + + // Player City Terraform values serialized here. + + if (zone.playerCityID > 0) { + writer.put((byte) 1); // Player City - True + writer.putFloat(Enum.CityBoundsType.ZONE.extents); + writer.putFloat(Enum.CityBoundsType.ZONE.extents); + } else + writer.put((byte) 0); // Player City - False + + writer.putFloat(zone.xCoord); + writer.putFloat(zone.zCoord); + writer.putFloat(zone.yCoord); + + writer.putInt(0); + writer.putInt(0); + writer.putInt(zone.loadNum); + + if (zone.playerCityID > 0) { + City k = City.getCity(zone.playerCityID); + + if (k != null) { + writer.putInt(k.getObjectType().ordinal()); + writer.putInt(k.getObjectUUID()); + } else + writer.putLong(0x0); + } else { + writer.putInt(zone.getObjectType().ordinal()); + writer.putInt(zone.getObjectUUID()); + } + writer.putInt(zone.nodes.size()); + + City city = City.getCity(zone.playerCityID); + + if (city != null) + writer.putString(city.getCityName()); + else + writer.putString(zone.zoneName); + writer.put(zone.safeZone); + writer.putString(zone.Icon1); + writer.putString(zone.Icon2); + writer.putString(zone.Icon3); + writer.put((byte) 0); // Pad + + for (Zone child : zone.nodes) { + Zone.serializeForClientMsg(child, writer); + } + } + /* Method sets a default value for player cities * otherwise using values derived from the loadnum * field in the obj_zone database table. @@ -123,38 +175,18 @@ public class Zone extends AbstractGameObject { return; } - // All other zones have bounding boxes loaded from database - ResultSet rs = DbManager.ZoneQueries.GET_ZONE_EXTENTS(this.loadNum); - boolean loaded = false; - - if (rs != null) - try { - if (rs.next()) { - halfExtentX = rs.getFloat("xRadius"); - halfExtentY = rs.getFloat("zRadius"); - this.bounds.setBounds(new Vector2f(this.absX, this.absZ), new Vector2f(halfExtentX, halfExtentY), 0.0f); - loaded = true; - } + Vector2f zoneSize = ZoneManager._zone_size_data.get(this.loadNum); - } catch (SQLException e) { - Logger.error("SQLException: " + e.getMessage()); - } - - if (!loaded) { - - // Default to Citygrid size on error + // Default to player zone size on error? Maybe log this + if (zoneSize != null) + this.bounds.setBounds(new Vector2f(this.absX, this.absZ), zoneSize, 0.0f); + else bounds.setBounds(new Vector2f(this.absX, this.absZ), new Vector2f(Enum.CityBoundsType.ZONE.extents, Enum.CityBoundsType.ZONE.extents), 0.0f); - } } - /* - * Getters - */ public int getPlayerCityUUID() { - if (this.playerCityID == 0) - return 0; return this.playerCityID; } @@ -178,10 +210,6 @@ public class Zone extends AbstractGameObject { return loadNum; } - public int getLoadNumClient() { - return loadNum; - } - public byte getSafeZone() { return safeZone; } @@ -190,45 +218,9 @@ public class Zone extends AbstractGameObject { return Icon1; } - public String getIcon2() { - return Icon2; - } - - public String getIcon3() { - return Icon3; - } + public void generateWorldAltitude() { - public void setParent(final Zone value) { - - this.parent = value; - this.parentZoneID = (this.parent != null) ? this.parent.getObjectUUID() : 0; - - if (this.parent != null) { - this.absX = this.xCoord + parent.absX; - this.absY = this.yCoord + parent.absY; - this.absZ = this.zCoord + parent.absZ; - - if (this.minLvl == 0 || this.maxLvl == 0){ - this.minLvl = this.parent.minLvl; - this.maxLvl = this.parent.maxLvl; - } - } else { //only the Sea Floor zone does not have a parent - this.absX = this.xCoord; - this.absY = MBServerStatics.SEA_FLOOR_ALTITUDE; - this.absZ = this.zCoord; - } - - // Zone AABB is set here as it's coordinate space is world requiring a parent. - this.setBounds(); - - if (this.getHeightMap() != null && this.getHeightMap().getSeaLevel() != 0) - this.seaLevel = this.getHeightMap().getSeaLevel(); - - } - - public void generateWorldAltitude(){ - - if (ZoneManager.getSeaFloor().getObjectUUID() == this.getObjectUUID()){ + if (ZoneManager.getSeaFloor().getObjectUUID() == this.getObjectUUID()) { this.worldAltitude = MBServerStatics.SEA_FLOOR_ALTITUDE; return; } @@ -240,9 +232,9 @@ public class Zone extends AbstractGameObject { //seafloor only zone with null parent; - while(parentZone != ZoneManager.getSeaFloor()){ + while (parentZone != ZoneManager.getSeaFloor()) { - if(parentZone.getHeightMap() != null){ + if (parentZone.getHeightMap() != null) { Vector2f zoneLoc = ZoneManager.worldToZoneSpace(currentZone.getLoc(), parentZone); altitude += parentZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc); @@ -258,14 +250,14 @@ public class Zone extends AbstractGameObject { if (ZoneManager.getSeaFloor().equals(this)) this.seaLevel = 0; else if - (this.getHeightMap() != null && this.getHeightMap().getSeaLevel() == 0){ - this.seaLevel = this.parent.seaLevel; + (this.getHeightMap() != null && this.getHeightMap().getSeaLevel() == 0) { + this.seaLevel = this.parent.seaLevel; - }else if (this.getHeightMap() != null){ + } else if (this.getHeightMap() != null) { this.seaLevel = this.worldAltitude + this.getHeightMap().getSeaLevel(); - }else { - this.seaLevel = this.parent.seaLevel; - } + } else { + this.seaLevel = this.parent.seaLevel; + } } @@ -273,6 +265,34 @@ public class Zone extends AbstractGameObject { return this.parent; } + public void setParent(final Zone value) { + + this.parent = value; + this.parentZoneID = (this.parent != null) ? this.parent.getObjectUUID() : 0; + + if (this.parent != null) { + this.absX = this.xCoord + parent.absX; + this.absY = this.yCoord + parent.absY; + this.absZ = this.zCoord + parent.absZ; + + if (this.minLvl == 0 || this.maxLvl == 0) { + this.minLvl = this.parent.minLvl; + this.maxLvl = this.parent.maxLvl; + } + } else { //only the Sea Floor zone does not have a parent + this.absX = this.xCoord; + this.absY = MBServerStatics.SEA_FLOOR_ALTITUDE; + this.absZ = this.zCoord; + } + + // Zone AABB is set here as it's coordinate space is world requiring a parent. + this.setBounds(); + + if (this.getHeightMap() != null && this.getHeightMap().getSeaLevel() != 0) + this.seaLevel = this.getHeightMap().getSeaLevel(); + + } + public float getAbsX() { return this.absX; } @@ -302,14 +322,14 @@ public class Zone extends AbstractGameObject { return this.isNPCCity; } - public boolean isPlayerCity() { - return this.isPlayerCity; - } - public void setNPCCity(boolean value) { this.isNPCCity = value; } + public boolean isPlayerCity() { + return this.isPlayerCity; + } + public void setPlayerCity(boolean value) { this.isPlayerCity = value; } @@ -336,67 +356,12 @@ public class Zone extends AbstractGameObject { return nodes; } - public void addNode(Zone child) { - this.nodes.add(child); - } - /* * Serializing */ - - public static void serializeForClientMsg(Zone zone,ByteBufferWriter writer) { - - if (zone.loadNum == 0 && zone.playerCityID == 0) - Logger.warn( "Warning! WorldServerMap with ID " + zone.getObjectUUID() + " has a loadnum of 0 (player city) and no city linked. This will probably crash the client!"); - - // Player City Terraform values serialized here. - - if (zone.playerCityID > 0) { - writer.put((byte) 1); // Player City - True - writer.putFloat(Enum.CityBoundsType.ZONE.extents); - writer.putFloat(Enum.CityBoundsType.ZONE.extents); - } else - writer.put((byte) 0); // Player City - False - - writer.putFloat(zone.xCoord); - writer.putFloat(zone.zCoord); - writer.putFloat(zone.yCoord); - - writer.putInt(0); - writer.putInt(0); - writer.putInt(zone.loadNum); - - if (zone.playerCityID > 0) { - City k = City.getCity(zone.playerCityID); - - if (k != null) { - writer.putInt(k.getObjectType().ordinal()); - writer.putInt(k.getObjectUUID()); - } - else - writer.putLong(0x0); - } else { - writer.putInt(zone.getObjectType().ordinal()); - writer.putInt(zone.getObjectUUID()); - } - writer.putInt(zone.nodes.size()); - - City city = City.getCity(zone.playerCityID); - - if (city != null) - writer.putString(city.getCityName()); - else - writer.putString(zone.zoneName); - writer.put(zone.safeZone); - writer.putString(zone.Icon1); - writer.putString(zone.Icon2); - writer.putString(zone.Icon3); - writer.put((byte) 0); // Pad - - for (Zone child : zone.nodes) { - Zone.serializeForClientMsg(child,writer); - } + public void addNode(Zone child) { + this.nodes.add(child); } @Override @@ -442,7 +407,7 @@ public class Zone extends AbstractGameObject { // Return heightmap for this Zone. public HeightMap getHeightMap() { - + if (this.isPlayerCity) return HeightMap.PlayerCityHeightMap;