Browse Source

Garbage cleanup in SetZone().

Package reformat.
master
MagicBot 2 years ago
parent
commit
6dd7315786
  1. 338
      src/engine/db/handlers/dbAccountHandler.java
  2. 86
      src/engine/db/handlers/dbBaseClassHandler.java
  3. 36
      src/engine/db/handlers/dbBuildingLocationHandler.java
  4. 204
      src/engine/db/handlers/dbCharacterPowerHandler.java
  5. 132
      src/engine/db/handlers/dbCharacterRuneHandler.java
  6. 4
      src/engine/db/handlers/dbCharacterSkillHandler.java
  7. 2
      src/engine/db/handlers/dbEffectsBaseHandler.java
  8. 32
      src/engine/db/handlers/dbEffectsResourceCostHandler.java
  9. 70
      src/engine/db/handlers/dbEnchantmentHandler.java
  10. 935
      src/engine/db/handlers/dbGuildHandler.java
  11. 835
      src/engine/db/handlers/dbHandlerBase.java
  12. 2
      src/engine/db/handlers/dbItemBaseHandler.java
  13. 724
      src/engine/db/handlers/dbItemHandler.java
  14. 30
      src/engine/db/handlers/dbKitHandler.java
  15. 30
      src/engine/db/handlers/dbMenuHandler.java
  16. 150
      src/engine/db/handlers/dbMineHandler.java
  17. 240
      src/engine/db/handlers/dbMobBaseHandler.java
  18. 316
      src/engine/db/handlers/dbMobHandler.java
  19. 768
      src/engine/db/handlers/dbPlayerCharacterHandler.java
  20. 2
      src/engine/db/handlers/dbPromotionClassHandler.java
  21. 30
      src/engine/db/handlers/dbRuneBaseAttributeHandler.java
  22. 91
      src/engine/db/handlers/dbRuneBaseEffectHandler.java
  23. 224
      src/engine/db/handlers/dbRuneBaseHandler.java
  24. 44
      src/engine/db/handlers/dbShrineHandler.java
  25. 215
      src/engine/db/handlers/dbSkillBaseHandler.java
  26. 36
      src/engine/db/handlers/dbVendorDialogHandler.java
  27. 19
      src/engine/db/handlers/dbZoneHandler.java
  28. 26
      src/engine/gameManager/ZoneManager.java
  29. 265
      src/engine/objects/Zone.java

338
src/engine/db/handlers/dbAccountHandler.java

@ -25,249 +25,249 @@ import java.util.ArrayList; @@ -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<String> GET_TRASH_LIST() {
public ArrayList<String> GET_TRASH_LIST() {
ArrayList<String> machineList = new ArrayList<>();
ArrayList<String> 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<PlayerCharacter> GET_ALL_CHARS_FOR_MACHINE(String machineID) {
public ArrayList<PlayerCharacter> GET_ALL_CHARS_FOR_MACHINE(String machineID) {
ArrayList<PlayerCharacter> trashList = new ArrayList<>();
ArrayList<PlayerCharacter> 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);
}
}
}

86
src/engine/db/handlers/dbBaseClassHandler.java

@ -23,69 +23,69 @@ import java.util.ArrayList; @@ -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<BaseClass> GET_BASECLASS_FOR_RACE(final int id) {
public ArrayList<BaseClass> GET_BASECLASS_FOR_RACE(final int id) {
ArrayList<BaseClass> baseClasses = new ArrayList<>();
ArrayList<BaseClass> 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<BaseClass> GET_ALL_BASE_CLASSES() {
public ArrayList<BaseClass> GET_ALL_BASE_CLASSES() {
ArrayList<BaseClass> baseClasses = new ArrayList<>();
ArrayList<BaseClass> 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;
}
}

36
src/engine/db/handlers/dbBuildingLocationHandler.java

@ -21,29 +21,29 @@ import java.util.ArrayList; @@ -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<BuildingLocation> LOAD_BUILDING_LOCATIONS() {
public ArrayList<BuildingLocation> LOAD_BUILDING_LOCATIONS() {
ArrayList<BuildingLocation> buildingLocations = new ArrayList<>();
ArrayList<BuildingLocation> 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;
}
}

204
src/engine/db/handlers/dbCharacterPowerHandler.java

@ -24,149 +24,149 @@ import java.util.concurrent.ConcurrentHashMap; @@ -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<Integer, CharacterPower> GET_POWERS_FOR_CHARACTER(PlayerCharacter pc) {
public ConcurrentHashMap<Integer, CharacterPower> GET_POWERS_FOR_CHARACTER(PlayerCharacter pc) {
ConcurrentHashMap<Integer, CharacterPower> powers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
int objectUUID = pc.getObjectUUID();
ConcurrentHashMap<Integer, CharacterPower> 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);
}
}

132
src/engine/db/handlers/dbCharacterRuneHandler.java

@ -22,103 +22,103 @@ import java.util.ArrayList; @@ -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<CharacterRune> GET_RUNES_FOR_CHARACTER(final int characterId) {
public ArrayList<CharacterRune> GET_RUNES_FOR_CHARACTER(final int characterId) {
ArrayList<CharacterRune> characterRunes = new ArrayList<>();
ArrayList<CharacterRune> 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);
}
}
}

4
src/engine/db/handlers/dbCharacterSkillHandler.java

@ -134,7 +134,7 @@ public class dbCharacterSkillHandler extends dbHandlerBase { @@ -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 { @@ -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();

2
src/engine/db/handlers/dbEffectsBaseHandler.java

@ -25,7 +25,7 @@ import java.util.HashSet; @@ -25,7 +25,7 @@ import java.util.HashSet;
public class dbEffectsBaseHandler extends dbHandlerBase {
public dbEffectsBaseHandler() {
public dbEffectsBaseHandler() {
}

32
src/engine/db/handlers/dbEffectsResourceCostHandler.java

@ -21,27 +21,27 @@ import java.util.ArrayList; @@ -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<EffectsResourceCosts> GET_ALL_EFFECT_RESOURCES(String idString) {
}
ArrayList<EffectsResourceCosts> effectsResourceCosts = new ArrayList<>();
public ArrayList<EffectsResourceCosts> GET_ALL_EFFECT_RESOURCES(String idString) {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_power_effectcost` WHERE `IDString` = ?")) {
ArrayList<EffectsResourceCosts> 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;
}
}

70
src/engine/db/handlers/dbEnchantmentHandler.java

@ -21,55 +21,55 @@ import java.util.concurrent.ConcurrentHashMap; @@ -21,55 +21,55 @@ import java.util.concurrent.ConcurrentHashMap;
public class dbEnchantmentHandler extends dbHandlerBase {
public ConcurrentHashMap<String, Integer> GET_ENCHANTMENTS_FOR_ITEM(final int id) {
public ConcurrentHashMap<String, Integer> GET_ENCHANTMENTS_FOR_ITEM(final int id) {
ConcurrentHashMap<String, Integer> enchants = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
ConcurrentHashMap<String, Integer> 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;
}
}

935
src/engine/db/handlers/dbGuildHandler.java

File diff suppressed because it is too large Load Diff

835
src/engine/db/handlers/dbHandlerBase.java

@ -25,455 +25,456 @@ import java.util.HashSet; @@ -25,455 +25,456 @@ import java.util.HashSet;
public abstract class dbHandlerBase {
/*
* CallableStatements handled below this line!
*/
protected Class<? extends AbstractGameObject> localClass = null;
protected GameObjectType localObjectType;
protected final ThreadLocal<CallableStatement> callableStatement = new ThreadLocal<>();
protected final ThreadLocal<Connection> 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 <T extends AbstractGameObject> 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 <T extends AbstractGameObject> ArrayList<T> getObjectsFromRs(ResultSet rs, int listSize) {
ArrayList<T> 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 <T extends AbstractGameObject> AbstractGameObject getObjectSingle(int id) {
return getObjectSingle(id, false, true);
}
protected <T extends AbstractGameObject> 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> callableStatement = new ThreadLocal<>();
protected final ThreadLocal<Connection> connection = new ThreadLocal<>();
/*
* CallableStatements handled below this line!
*/
protected Class<? extends AbstractGameObject> 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 <T extends AbstractGameObject> 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 <T extends AbstractGameObject> ArrayList<T> getObjectsFromRs(ResultSet rs, int listSize) {
ArrayList<T> 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 <T extends AbstractGameObject> AbstractGameObject getObjectSingle(int id) {
return getObjectSingle(id, false, true);
}
protected <T extends AbstractGameObject> 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 <T extends AbstractGameObject> ArrayList<T> getObjectList() {
return getObjectList(20, false);
}
protected <T extends AbstractGameObject> ArrayList<T> getObjectList() {
return getObjectList(20, false);
}
protected <T extends AbstractGameObject> ArrayList<T> getLargeObjectList() {
return getObjectList(2000, false);
}
protected <T extends AbstractGameObject> ArrayList<T> getLargeObjectList() {
return getObjectList(2000, false);
}
@SuppressWarnings("unchecked")
protected <T extends AbstractGameObject> ArrayList<T> getObjectList(int listSize, boolean forceFromDB) {
@SuppressWarnings("unchecked")
protected <T extends AbstractGameObject> ArrayList<T> getObjectList(int listSize, boolean forceFromDB) {
String query = "No Callable Statement accessable.";
String query = "No Callable Statement accessable.";
ArrayList<T> out = new ArrayList<>(listSize);
ArrayList<T> 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<Integer> getIntegerList(final int columnNumber) {
protected HashSet<Integer> 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<Integer> out = new HashSet<>();
HashSet<Integer> 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;
}
}

2
src/engine/db/handlers/dbItemBaseHandler.java

@ -23,7 +23,7 @@ import java.util.HashMap; @@ -23,7 +23,7 @@ import java.util.HashMap;
public class dbItemBaseHandler extends dbHandlerBase {
public dbItemBaseHandler() {
public dbItemBaseHandler() {
}

724
src/engine/db/handlers/dbItemHandler.java

@ -27,491 +27,491 @@ import java.util.HashSet; @@ -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<Integer> 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<Integer> from1, HashSet<Integer> 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<Integer> from1, HashSet<Integer> 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<Integer> 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<Item> GET_EQUIPPED_ITEMS(final int targetId) {
boolean start = true;
ArrayList<Item> 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<Item> GET_EQUIPPED_ITEMS(final int targetId) {
preparedStatement.setLong(1, targetId);
ResultSet rs = preparedStatement.executeQuery();
ArrayList<Item> 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<Item> GET_ITEMS_FOR_ACCOUNT(final int accountId) {
item = (Item) getObjectFromRs(rs);
ArrayList<Item> 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<Item> GET_ITEMS_FOR_ACCOUNT(final int accountId) {
preparedStatement.setLong(1, accountId);
ResultSet rs = preparedStatement.executeQuery();
ArrayList<Item> 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<Item> GET_ITEMS_FOR_NPC(final int npcId) {
itemList = getObjectsFromRs(rs, 100);
ArrayList<Item> 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<Item> GET_ITEMS_FOR_NPC(final int npcId) {
preparedStatement.setLong(1, npcId);
ResultSet rs = preparedStatement.executeQuery();
ArrayList<Item> 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<Item> GET_ITEMS_FOR_PC(final int id) {
itemList = getObjectsFromRs(rs, 20);
ArrayList<Item> 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<Item> GET_ITEMS_FOR_PC(final int id) {
preparedStatement.setLong(1, id);
ResultSet rs = preparedStatement.executeQuery();
ArrayList<Item> 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<Item> 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<Item> 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<Integer> GET_ITEMS_FOR_VENDOR(final int vendorID) {
if (worked)
item.zeroItem();
HashSet<Integer> 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<Integer> GET_ITEMS_FOR_VENDOR(final int vendorID) {
preparedStatement.setInt(1, vendorID);
HashSet<Integer> 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;
}
}
}

30
src/engine/db/handlers/dbKitHandler.java

@ -21,25 +21,25 @@ import java.util.ArrayList; @@ -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<Kit> GET_ALL_KITS() {
public ArrayList<Kit> GET_ALL_KITS() {
ArrayList<Kit> kitList = new ArrayList<>();
ArrayList<Kit> 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;
}
}

30
src/engine/db/handlers/dbMenuHandler.java

@ -21,27 +21,27 @@ import java.util.ArrayList; @@ -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<MenuOption> GET_MENU_OPTIONS(final int id) {
public ArrayList<MenuOption> GET_MENU_OPTIONS(final int id) {
ArrayList<MenuOption> menuOptions = new ArrayList<>();
ArrayList<MenuOption> 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;
}
}

150
src/engine/db/handlers/dbMineHandler.java

@ -23,113 +23,113 @@ import java.util.ArrayList; @@ -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<Mine> GET_ALL_MINES_FOR_SERVER() {
public ArrayList<Mine> GET_ALL_MINES_FOR_SERVER() {
ArrayList<Mine> mines = new ArrayList<>();
ArrayList<Mine> 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;
}
}

240
src/engine/db/handlers/dbMobBaseHandler.java

@ -26,173 +26,173 @@ import java.util.HashMap; @@ -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<MobBase> GET_ALL_MOBBASES() {
public ArrayList<MobBase> GET_ALL_MOBBASES() {
ArrayList<MobBase> mobbaseList = new ArrayList<>();
ArrayList<MobBase> 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<Integer, Integer> LOAD_STATIC_POWERS(int mobBaseUUID) {
public HashMap<Integer, Integer> LOAD_STATIC_POWERS(int mobBaseUUID) {
HashMap<Integer, Integer> powersList = new HashMap<>();
HashMap<Integer, Integer> 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<MobBaseEffects> GET_RUNEBASE_EFFECTS(int runeID) {
public ArrayList<MobBaseEffects> GET_RUNEBASE_EFFECTS(int runeID) {
ArrayList<MobBaseEffects> effectsList = new ArrayList<>();
ArrayList<MobBaseEffects> 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);
}
}
}

316
src/engine/db/handlers/dbMobHandler.java

@ -24,225 +24,225 @@ import java.util.ArrayList; @@ -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<Mob> GET_ALL_MOBS_FOR_ZONE(Zone zone) {
public ArrayList<Mob> GET_ALL_MOBS_FOR_ZONE(Zone zone) {
ArrayList<Mob> mobileList = new ArrayList<>();
ArrayList<Mob> 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;
}
}

768
src/engine/db/handlers/dbPlayerCharacterHandler.java

@ -27,546 +27,542 @@ import java.util.concurrent.ConcurrentHashMap; @@ -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<PlayerCharacter> GET_CHARACTERS_FOR_ACCOUNT(final int id) {
public ArrayList<PlayerCharacter> GET_CHARACTERS_FOR_ACCOUNT(final int id) {
ArrayList<PlayerCharacter> characterList = new ArrayList<>();
ArrayList<PlayerCharacter> 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<PlayerCharacter> GET_ALL_CHARACTERS() {
public ArrayList<PlayerCharacter> GET_ALL_CHARACTERS() {
ArrayList<PlayerCharacter> characterList = new ArrayList<>();
ArrayList<PlayerCharacter> 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;
}
/**
*
* <code>getFirstName</code> 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.
*
*/
/**
* <code>getFirstName</code> 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<Integer, String> GET_IGNORE_LIST(final int objectUUID, final boolean skipActiveCheck) {
public ConcurrentHashMap<Integer, String> GET_IGNORE_LIST(final int objectUUID, final boolean skipActiveCheck) {
ConcurrentHashMap<Integer, String> ignoreList = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
ConcurrentHashMap<Integer, String> 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);
}
}
}

2
src/engine/db/handlers/dbPromotionClassHandler.java

@ -65,7 +65,7 @@ public class dbPromotionClassHandler extends dbHandlerBase { @@ -65,7 +65,7 @@ public class dbPromotionClassHandler extends dbHandlerBase {
return promotionClass;
}
public ArrayList<PromotionClass> GET_ALL_PROMOTIONS() {
ArrayList<PromotionClass> promotionList = new ArrayList<>();

30
src/engine/db/handlers/dbRuneBaseAttributeHandler.java

@ -21,27 +21,27 @@ import java.util.ArrayList; @@ -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<RuneBaseAttribute> GET_ATTRIBUTES_FOR_RUNEBASE() {
public ArrayList<RuneBaseAttribute> GET_ATTRIBUTES_FOR_RUNEBASE() {
ArrayList<RuneBaseAttribute> runeBaseAttributesList = new ArrayList<>();
ArrayList<RuneBaseAttribute> 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;
}
}

91
src/engine/db/handlers/dbRuneBaseEffectHandler.java

@ -24,69 +24,68 @@ import java.util.HashMap; @@ -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<RuneBaseEffect> GET_EFFECTS_FOR_RUNEBASE(int id) {
public ArrayList<RuneBaseEffect> GET_EFFECTS_FOR_RUNEBASE(int id) {
ArrayList<RuneBaseEffect> runeBaseEffectsList = new ArrayList<>();
ArrayList<RuneBaseEffect> 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<RuneBaseEffect> GET_ALL_RUNEBASE_EFFECTS() {
public ArrayList<RuneBaseEffect> GET_ALL_RUNEBASE_EFFECTS() {
ArrayList<RuneBaseEffect> runeBaseEffectsList = new ArrayList<>();
ArrayList<RuneBaseEffect> 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<Integer, ArrayList<RuneBaseEffect>> LOAD_BASEEFFECTS_FOR_RUNEBASE() {
public HashMap<Integer, ArrayList<RuneBaseEffect>> LOAD_BASEEFFECTS_FOR_RUNEBASE() {
HashMap<Integer, ArrayList<RuneBaseEffect>> runeBaseEffectSet;
runeBaseEffectSet = new HashMap<>();
HashMap<Integer, ArrayList<RuneBaseEffect>> 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<RuneBaseEffect> runeBaseEffectList = new ArrayList<>();
runeBaseEffectList.add((RuneBaseEffect)runeBaseEffect);
runeBaseEffectSet.put(runeBaseID, runeBaseEffectList);
}
else{
ArrayList<RuneBaseEffect>runeBaseEffectList = runeBaseEffectSet.get(runeBaseID);
runeBaseEffectList.add((RuneBaseEffect)runeBaseEffect);
runeBaseEffectSet.put(runeBaseID, runeBaseEffectList);
}
}
return runeBaseEffectSet;
}
int runeBaseID = ((RuneBaseEffect) runeBaseEffect).getRuneBaseID();
if (runeBaseEffectSet.get(runeBaseID) == null) {
ArrayList<RuneBaseEffect> runeBaseEffectList = new ArrayList<>();
runeBaseEffectList.add((RuneBaseEffect) runeBaseEffect);
runeBaseEffectSet.put(runeBaseID, runeBaseEffectList);
} else {
ArrayList<RuneBaseEffect> runeBaseEffectList = runeBaseEffectSet.get(runeBaseID);
runeBaseEffectList.add((RuneBaseEffect) runeBaseEffect);
runeBaseEffectSet.put(runeBaseID, runeBaseEffectList);
}
}
return runeBaseEffectSet;
}
}

224
src/engine/db/handlers/dbRuneBaseHandler.java

@ -22,158 +22,158 @@ import java.util.HashMap; @@ -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<RuneBase> LOAD_ALL_RUNEBASES() {
public ArrayList<RuneBase> LOAD_ALL_RUNEBASES() {
ArrayList<RuneBase> runeBasesList = new ArrayList<>();
ArrayList<RuneBase> 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<Integer, ArrayList<Integer>> LOAD_ALLOWED_STARTING_RUNES_FOR_BASECLASS() {
public HashMap<Integer, ArrayList<Integer>> LOAD_ALLOWED_STARTING_RUNES_FOR_BASECLASS() {
HashMap<Integer, ArrayList<Integer>> runeSets = new HashMap<>();
HashMap<Integer, ArrayList<Integer>> 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<Integer> runeList = new ArrayList<>();
runeList.add(runeBaseID);
runeSets.put(baseClassID, runeList);
} else {
ArrayList<Integer> runeList = runeSets.get(baseClassID);
runeList.add(runeBaseID);
runeSets.put(baseClassID, runeList);
}
}
if (runeSets.get(baseClassID) == null) {
ArrayList<Integer> runeList = new ArrayList<>();
runeList.add(runeBaseID);
runeSets.put(baseClassID, runeList);
} else {
ArrayList<Integer> 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<Integer, ArrayList<Integer>> LOAD_ALLOWED_STARTING_RUNES_FOR_RACE() {
public HashMap<Integer, ArrayList<Integer>> LOAD_ALLOWED_STARTING_RUNES_FOR_RACE() {
HashMap<Integer, ArrayList<Integer>> runeSets;
HashMap<Integer, ArrayList<Integer>> 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<Integer> runeList = new ArrayList<>();
runeList.add(runeBaseID);
runeSets.put(raceID, runeList);
} else {
ArrayList<Integer> runeList = runeSets.get(raceID);
runeList.add(runeBaseID);
runeSets.put(raceID, runeList);
}
}
} catch (SQLException e) {
Logger.error(e);
}
if (runeSets.get(raceID) == null) {
ArrayList<Integer> runeList = new ArrayList<>();
runeList.add(runeBaseID);
runeSets.put(raceID, runeList);
} else {
ArrayList<Integer> 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;
}
}

44
src/engine/db/handlers/dbShrineHandler.java

@ -31,10 +31,28 @@ public class dbShrineHandler extends dbHandlerBase { @@ -31,10 +31,28 @@ public class dbShrineHandler extends dbHandlerBase {
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
}
public ArrayList<AbstractGameObject> 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<AbstractGameObject> 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<AbstractGameObject> 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<AbstractGameObject> shrineList = new ArrayList<>();
@ -103,24 +121,6 @@ public class dbShrineHandler extends dbHandlerBase { @@ -103,24 +121,6 @@ public class dbShrineHandler extends dbHandlerBase {
}
public static void addObject(ArrayList<AbstractGameObject> 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;

215
src/engine/db/handlers/dbSkillBaseHandler.java

@ -26,113 +26,112 @@ import java.util.HashMap; @@ -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<AbstractGameObject> 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<AbstractGameObject> 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<MaxSkills> 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<AbstractGameObject> 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<AbstractGameObject> 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<MaxSkills> 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);
}
}
}

36
src/engine/db/handlers/dbVendorDialogHandler.java

@ -21,30 +21,30 @@ import java.sql.SQLException; @@ -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;
}
}

19
src/engine/db/handlers/dbZoneHandler.java

@ -11,6 +11,8 @@ package engine.db.handlers; @@ -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 { @@ -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 { @@ -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) {

26
src/engine/gameManager/ZoneManager.java

@ -24,10 +24,7 @@ import org.pmw.tinylog.Logger; @@ -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 { @@ -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<Zone> macroZones = Collections.newSetFromMap(new ConcurrentHashMap<>());
private static final ConcurrentHashMap<Integer, Zone> zonesByID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD);
private static final ConcurrentHashMap<Integer, Zone> zonesByUUID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD);
private static final ConcurrentHashMap<String, Zone> zonesByName = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD);
public static final Set<Zone> macroZones = Collections.newSetFromMap(new ConcurrentHashMap<>());
private static final Set<Zone> npcCityZones = Collections.newSetFromMap(new ConcurrentHashMap<>());
private static final Set<Zone> 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<Integer, Vector2f> _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 { @@ -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();

265
src/engine/objects/Zone.java

@ -30,19 +30,25 @@ import java.util.concurrent.ConcurrentHashMap; @@ -30,19 +30,25 @@ import java.util.concurrent.ConcurrentHashMap;
public class Zone extends AbstractGameObject {
public final Set<Building> zoneBuildingSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
public final Set<NPC> zoneNPCSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
public final Set<Mob> 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<Zone> nodes = null;
private int parentZoneID;
private Zone parent = null;
@ -50,16 +56,9 @@ public class Zone extends AbstractGameObject { @@ -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<Building> zoneBuildingSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
public final Set<NPC> zoneNPCSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
public final Set<Mob> zoneMobSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
public boolean hasBeenHotzone = false;
/**
* ResultSet Constructor
*/
@ -87,7 +86,7 @@ public class Zone extends AbstractGameObject { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -442,7 +407,7 @@ public class Zone extends AbstractGameObject {
// Return heightmap for this Zone.
public HeightMap getHeightMap() {
if (this.isPlayerCity)
return HeightMap.PlayerCityHeightMap;

Loading…
Cancel
Save