Browse Source

Refactored out duplicate db interface.

combat-2
MagicBot 8 months ago
parent
commit
f2d28fd7af
  1. 31
      src/engine/db/handlers/dbPowerHandler.java
  2. 16
      src/engine/objects/AbstractGameObject.java
  3. 71
      src/engine/objects/LevelDefault.java
  4. 28
      src/engine/objects/PowerGrant.java
  5. 19
      src/engine/objects/PowerReq.java
  6. 1261
      src/engine/objects/PreparedStatementShared.java
  7. 21
      src/engine/powers/ActionsBase.java
  8. 23
      src/engine/powers/EffectsBase.java
  9. 118
      src/engine/powers/FailCondition.java
  10. 17
      src/engine/powers/PowerPrereq.java
  11. 45
      src/engine/powers/poweractions/AbstractPowerAction.java
  12. 6
      src/engine/server/login/LoginServer.java
  13. 6
      src/engine/server/world/WorldServer.java

31
src/engine/db/handlers/dbPowerHandler.java

@ -13,10 +13,11 @@ import engine.Enum;
import engine.gameManager.DbManager; import engine.gameManager.DbManager;
import engine.gameManager.PowersManager; import engine.gameManager.PowersManager;
import engine.objects.Mob; import engine.objects.Mob;
import engine.objects.PreparedStatementShared;
import engine.powers.EffectsBase; import engine.powers.EffectsBase;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.util.HashSet; import java.util.HashSet;
@ -28,16 +29,17 @@ public class dbPowerHandler extends dbHandlerBase {
} }
public static void addAllSourceTypes() { public static void addAllSourceTypes() {
PreparedStatementShared ps = null;
try { try (Connection connection = DbManager.getConnection();
ps = new PreparedStatementShared("SELECT * FROM static_power_sourcetype"); PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_power_sourcetype")) {
ResultSet rs = ps.executeQuery();
ResultSet rs = preparedStatement.executeQuery();
String IDString, source; String IDString, source;
while (rs.next()) { while (rs.next()) {
IDString = rs.getString("IDString"); IDString = rs.getString("IDString");
int token = DbManager.hasher.SBStringHash(IDString); int token = DbManager.hasher.SBStringHash(IDString);
source = rs.getString("source").replace("-", "").trim(); source = rs.getString("source").replace("-", "").trim();
Enum.EffectSourceType effectSourceType = Enum.EffectSourceType.GetEffectSourceType(source); Enum.EffectSourceType effectSourceType = Enum.EffectSourceType.GetEffectSourceType(source);
@ -46,19 +48,18 @@ public class dbPowerHandler extends dbHandlerBase {
EffectsBase.effectSourceTypeMap.get(token).add(effectSourceType); EffectsBase.effectSourceTypeMap.get(token).add(effectSourceType);
} }
rs.close();
} catch (Exception e) { } catch (Exception e) {
Logger.error(e); Logger.error(e);
} finally {
ps.release();
} }
} }
public static void addAllAnimationOverrides() { public static void addAllAnimationOverrides() {
PreparedStatementShared ps = null;
try { try (Connection connection = DbManager.getConnection();
ps = new PreparedStatementShared("SELECT * FROM static_power_animation_override"); PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_power_animation_override")) {
ResultSet rs = ps.executeQuery();
ResultSet rs = preparedStatement.executeQuery();
String IDString; String IDString;
int animation; int animation;
while (rs.next()) { while (rs.next()) {
@ -72,12 +73,10 @@ public class dbPowerHandler extends dbHandlerBase {
PowersManager.AnimationOverrides.put(IDString, animation); PowersManager.AnimationOverrides.put(IDString, animation);
} }
rs.close();
} catch (Exception e) { } catch (Exception e) {
Logger.error(e); Logger.error(e);
} finally {
ps.release();
} }
} }
} }

16
src/engine/objects/AbstractGameObject.java

@ -84,22 +84,6 @@ public abstract class AbstractGameObject {
return GameObjectType.values()[ordinal]; return GameObjectType.values()[ordinal];
} }
/**
* Generates a {@link PreparedStatementShared} based on the specified query.
* <p>
* If {@link AbstractGameObject} Database functions will properly release
* the PreparedStatementShared upon completion. If these functions are not
* used, then {@link PreparedStatementShared#release release()} must be
* called when finished with this object.
*
* @param sql The SQL string used to generate the PreparedStatementShared
* @return {@link PreparedStatementShared}
* @throws {@link SQLException}
**/
protected static PreparedStatementShared prepareStatement(String sql) throws SQLException {
return new PreparedStatementShared(sql);
}
public static AbstractGameObject getFromTypeAndID(long compositeID) { public static AbstractGameObject getFromTypeAndID(long compositeID) {
int objectTypeID = extractTypeOrdinal(compositeID); int objectTypeID = extractTypeOrdinal(compositeID);
int tableID = extractTableID(objectTypeID, compositeID); int tableID = extractTableID(objectTypeID, compositeID);

71
src/engine/objects/LevelDefault.java

@ -1,71 +0,0 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.objects;
import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.concurrent.ConcurrentHashMap;
public class LevelDefault {
public static ConcurrentHashMap<Byte, LevelDefault> defaults = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
public final int level;
public final float health;
public final float mana;
public final float stamina;
public final float atr;
public final float def;
public final float minDamage;
public final float maxDamage;
public final int goldMin;
public final int goldMax;
/**
* ResultSet Constructor
*/
public LevelDefault(ResultSet rs) throws SQLException {
super();
this.level = rs.getInt("level");
this.health = rs.getFloat("health");
this.mana = (float) rs.getInt("mana");
this.stamina = (float) rs.getInt("stamina");
this.atr = (float) rs.getInt("atr");
this.def = (float) rs.getInt("def");
this.minDamage = (float) rs.getInt("minDamage");
this.maxDamage = (float) rs.getInt("maxDamage");
this.goldMin = rs.getInt("goldMin");
this.goldMax = rs.getInt("goldMax");
}
public static LevelDefault getLevelDefault(byte level) {
LevelDefault ret = null;
if (LevelDefault.defaults.containsKey(level))
return LevelDefault.defaults.get(level);
PreparedStatementShared ps = null;
try {
ps = new PreparedStatementShared("SELECT * FROM `static_npc_level_defaults` WHERE level = ?;");
ps.setInt(1, (int) level);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
ret = new LevelDefault(rs);
LevelDefault.defaults.put(level, ret);
}
} catch (SQLException e) {
Logger.error("SQL Error number: " + e.getErrorCode() + ' ' + e.getMessage());
} finally {
ps.release();
}
return ret;
}
}

28
src/engine/objects/PowerGrant.java

@ -9,9 +9,12 @@
package engine.objects; package engine.objects;
import engine.gameManager.DbManager;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
@ -86,18 +89,26 @@ public class PowerGrant extends AbstractGameObject {
} }
public static void fillGrantedPowers() { public static void fillGrantedPowers() {
PowerGrant.grantedPowers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); PowerGrant.grantedPowers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
PreparedStatementShared ps = null;
try { try (Connection connection = DbManager.getConnection();
ps = prepareStatement("SELECT * FROM static_power_powergrant"); PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_power_powergrant")) {
ResultSet rs = ps.executeQuery();
ResultSet rs = preparedStatement.executeQuery();
if (PowerGrant.grantedPowers.size() > 0) { if (PowerGrant.grantedPowers.size() > 0) {
rs.close(); rs.close();
return; return;
} }
while (rs.next()) { while (rs.next()) {
int token = rs.getInt("powerToken"); int token = rs.getInt("powerToken");
PowerGrant pg = null;
PowerGrant pg;
if (PowerGrant.grantedPowers.containsKey(token)) { if (PowerGrant.grantedPowers.containsKey(token)) {
pg = PowerGrant.grantedPowers.get(token); pg = PowerGrant.grantedPowers.get(token);
pg.addRuneGrant(rs.getInt("runeID"), rs.getShort("grantAmount")); pg.addRuneGrant(rs.getInt("runeID"), rs.getShort("grantAmount"));
@ -109,16 +120,9 @@ public class PowerGrant extends AbstractGameObject {
rs.close(); rs.close();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error("SQL Error number: " + e.getErrorCode(), e); Logger.error("SQL Error number: " + e.getErrorCode(), e);
} finally {
ps.release();
} }
} }
public ConcurrentHashMap<Integer, Short> getRuneGrants() {
return this.runeGrants;
}
/* /*
* Database * Database
*/ */

19
src/engine/objects/PowerReq.java

@ -9,11 +9,14 @@
package engine.objects; package engine.objects;
import engine.gameManager.DbManager;
import engine.gameManager.PowersManager; import engine.gameManager.PowersManager;
import engine.powers.PowersBase; import engine.powers.PowersBase;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
@ -87,15 +90,18 @@ public class PowerReq extends AbstractGameObject implements Comparable<PowerReq>
} }
public static ConcurrentHashMap<Integer, ArrayList<PowerReq>> fillRunePowers() { public static ConcurrentHashMap<Integer, ArrayList<PowerReq>> fillRunePowers() {
PowerReq.runePowers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); PowerReq.runePowers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
PreparedStatementShared ps = null;
try { try (Connection connection = DbManager.getConnection();
ps = prepareStatement("SELECT * FROM static_power_powerrequirement"); PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_power_powerrequirement")) {
ResultSet rs = ps.executeQuery();
ResultSet rs = preparedStatement.executeQuery();
if (PowerReq.runePowers.size() > 0) { if (PowerReq.runePowers.size() > 0) {
rs.close();
return PowerReq.runePowers; return PowerReq.runePowers;
} }
while (rs.next()) { while (rs.next()) {
ArrayList<PowerReq> runePR = null; ArrayList<PowerReq> runePR = null;
int runeID = rs.getInt("runeID"); int runeID = rs.getInt("runeID");
@ -130,9 +136,8 @@ public class PowerReq extends AbstractGameObject implements Comparable<PowerReq>
} }
} catch (SQLException e) { } catch (SQLException e) {
Logger.error("SQL Error number: " + e.getErrorCode(), e); Logger.error("SQL Error number: " + e.getErrorCode(), e);
} finally {
ps.release();
} }
return PowerReq.runePowers; return PowerReq.runePowers;
} }

1261
src/engine/objects/PreparedStatementShared.java

File diff suppressed because it is too large Load Diff

21
src/engine/powers/ActionsBase.java

@ -12,11 +12,17 @@ package engine.powers;
import engine.Enum.ModType; import engine.Enum.ModType;
import engine.Enum.SourceType; import engine.Enum.SourceType;
import engine.Enum.StackType; import engine.Enum.StackType;
import engine.gameManager.DbManager;
import engine.gameManager.PowersManager; import engine.gameManager.PowersManager;
import engine.objects.*; import engine.objects.AbstractCharacter;
import engine.objects.AbstractWorldObject;
import engine.objects.PlayerBonuses;
import engine.objects.Runegate;
import engine.powers.poweractions.AbstractPowerAction; import engine.powers.poweractions.AbstractPowerAction;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
@ -133,13 +139,15 @@ public class ActionsBase {
// } // }
public static void getActionsBase(HashMap<String, PowersBase> powers, HashMap<String, AbstractPowerAction> apa) { public static void getActionsBase(HashMap<String, PowersBase> powers, HashMap<String, AbstractPowerAction> apa) {
PreparedStatementShared ps = null;
try { try (Connection connection = DbManager.getConnection();
ps = new PreparedStatementShared("SELECT * FROM static_power_action"); PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_power_action")) {
ResultSet rs = ps.executeQuery();
ResultSet rs = preparedStatement.executeQuery();
String IDString; String IDString;
ActionsBase toAdd; ActionsBase toAdd;
PowersBase pb; PowersBase pb;
while (rs.next()) { while (rs.next()) {
IDString = rs.getString("powerID"); IDString = rs.getString("powerID");
pb = powers.get(IDString); pb = powers.get(IDString);
@ -151,11 +159,10 @@ public class ActionsBase {
rs.close(); rs.close();
} catch (Exception e) { } catch (Exception e) {
Logger.error(e.toString()); Logger.error(e.toString());
} finally {
ps.release();
} }
int gateID = 5000; int gateID = 5000;
for (String IDString : Runegate.GetAllOpenGateIDStrings()) { for (String IDString : Runegate.GetAllOpenGateIDStrings()) {
gateID++; gateID++;
ActionsBase openGateActionBase = new ActionsBase(gateID, "OPENGATE", 5, 9999, 0, 0, true, "IgnoreStack", 0, true, false, false, PowersManager.getPowerActionByIDString("OPENGATE")); ActionsBase openGateActionBase = new ActionsBase(gateID, "OPENGATE", 5, 9999, 0, 0, true, "IgnoreStack", 0, true, false, false, PowersManager.getPowerActionByIDString("OPENGATE"));

23
src/engine/powers/EffectsBase.java

@ -29,6 +29,8 @@ import engine.powers.effectmodifiers.AbstractEffectModifier;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
@ -169,21 +171,21 @@ public class EffectsBase {
} }
public static void getFailConditions(HashMap<String, EffectsBase> effects) { public static void getFailConditions(HashMap<String, EffectsBase> effects) {
PreparedStatementShared ps = null;
try {
ps = new PreparedStatementShared("SELECT * FROM static_power_failcondition WHERE powerOrEffect = 'Effect';");
ResultSet rs = ps.executeQuery(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_power_failcondition WHERE powerOrEffect = 'Effect';")) {
ResultSet rs = preparedStatement.executeQuery();
PowerFailCondition failCondition = null; PowerFailCondition failCondition = null;
Object value;
while (rs.next()) { while (rs.next()) {
String fail = rs.getString("type"); String fail = rs.getString("type");
String IDString = rs.getString("IDString"); String IDString = rs.getString("IDString");
int token = DbManager.hasher.SBStringHash(IDString);
failCondition = PowerFailCondition.valueOf(fail); failCondition = PowerFailCondition.valueOf(fail);
if (failCondition == null) { if (failCondition == null) {
Logger.error("Couldn't Find FailCondition " + fail + " for " + IDString); Logger.error("Couldn't Find FailCondition " + fail + " for " + IDString);
continue; continue;
@ -200,11 +202,10 @@ public class EffectsBase {
case TakeDamage: case TakeDamage:
// dont go any further. // dont go any further.
if (eb == null) {
if (eb == null)
break; break;
}
eb.cancelOnTakeDamage = true; eb.cancelOnTakeDamage = true;
@ -217,7 +218,6 @@ public class EffectsBase {
String damageType2 = rs.getString("damageType2"); String damageType2 = rs.getString("damageType2");
String damageType3 = rs.getString("damageType3"); String damageType3 = rs.getString("damageType3");
if (damageType1.isEmpty() && damageType2.isEmpty() && damageType3.isEmpty()) if (damageType1.isEmpty() && damageType2.isEmpty() && damageType3.isEmpty())
break; break;
@ -274,10 +274,7 @@ public class EffectsBase {
rs.close(); rs.close();
} catch (Exception e) { } catch (Exception e) {
Logger.error(e); Logger.error(e);
} finally {
ps.release();
} }
} }
private static Enum.SourceType getDamageType(String name) { private static Enum.SourceType getDamageType(String name) {

118
src/engine/powers/FailCondition.java

@ -1,118 +0,0 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.powers;
import engine.objects.PreparedStatementShared;
import org.pmw.tinylog.Logger;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
public class FailCondition {
private String IDString;
private Boolean forPower;
private String type;
private float amount;
private float ramp;
private boolean rampAdd;
// private String damageType1;
// private String damageType2;
// private String damageType3;
/**
* No Table ID Constructor
*/
public FailCondition() {
}
/**
* ResultSet Constructor
*/
public FailCondition(ResultSet rs) throws SQLException {
this.IDString = rs.getString("IDString");
this.forPower = (rs.getString("powerOrEffect").equals("Power")) ? true : false;
this.type = rs.getString("type");
this.amount = rs.getFloat("amount");
this.ramp = rs.getFloat("ramp");
this.rampAdd = (rs.getInt("useAddFormula") == 1) ? true : false;
// this.damageType1 = rs.getString("damageType1");
// this.damageType2 = rs.getString("damageType2");
// this.damageType3 = rs.getString("damageType3");
}
public static ArrayList<FailCondition> getAllFailConditions() {
PreparedStatementShared ps = null;
ArrayList<FailCondition> out = new ArrayList<>();
try {
ps = new PreparedStatementShared("SELECT * FROM failconditions");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
FailCondition toAdd = new FailCondition(rs);
out.add(toAdd);
}
rs.close();
} catch (Exception e) {
Logger.error(e);
} finally {
ps.release();
}
return out;
}
public String getIDString() {
return this.IDString;
}
public String getType() {
return this.type;
}
public boolean forPower() {
return this.forPower;
}
public float getAmount() {
return this.amount;
}
public float getRamp() {
return this.ramp;
}
public float getAmountForTrains(float trains) {
if (this.rampAdd)
return this.amount + (this.ramp * trains);
else
return this.amount * (1 + (this.ramp * trains));
}
public boolean useRampAdd() {
return this.rampAdd;
}
// public String getDamageType1() {
// return this.damageType1;
// }
// public String getDamageType2() {
// return this.damageType2;
// }
// public String getDamageType3() {
// return this.damageType3;
// }
}

17
src/engine/powers/PowerPrereq.java

@ -9,9 +9,11 @@
package engine.powers; package engine.powers;
import engine.objects.PreparedStatementShared; import engine.gameManager.DbManager;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
@ -60,14 +62,17 @@ public class PowerPrereq {
} }
public static void getAllPowerPrereqs(HashMap<String, PowersBase> powers) { public static void getAllPowerPrereqs(HashMap<String, PowersBase> powers) {
PreparedStatementShared ps = null;
try { try (Connection connection = DbManager.getConnection();
ps = new PreparedStatementShared("SELECT * FROM static_power_powercastprereq"); PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_power_powercastprereq\"")) {
ResultSet rs = ps.executeQuery();
ResultSet rs = preparedStatement.executeQuery();
int type; int type;
String IDString; String IDString;
PowerPrereq toAdd; PowerPrereq toAdd;
PowersBase pb; PowersBase pb;
while (rs.next()) { while (rs.next()) {
IDString = rs.getString("IDString"); IDString = rs.getString("IDString");
pb = powers.get(IDString); pb = powers.get(IDString);
@ -85,8 +90,6 @@ public class PowerPrereq {
rs.close(); rs.close();
} catch (Exception e) { } catch (Exception e) {
Logger.error(e.toString()); Logger.error(e.toString());
} finally {
ps.release();
} }
} }

45
src/engine/powers/poweractions/AbstractPowerAction.java

@ -15,12 +15,13 @@ import engine.math.Vector3fImmutable;
import engine.objects.AbstractCharacter; import engine.objects.AbstractCharacter;
import engine.objects.AbstractWorldObject; import engine.objects.AbstractWorldObject;
import engine.objects.Item; import engine.objects.Item;
import engine.objects.PreparedStatementShared;
import engine.powers.ActionsBase; import engine.powers.ActionsBase;
import engine.powers.EffectsBase; import engine.powers.EffectsBase;
import engine.powers.PowersBase; import engine.powers.PowersBase;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
@ -64,11 +65,14 @@ public abstract class AbstractPowerAction {
} }
public static void getAllPowerActions(HashMap<String, AbstractPowerAction> powerActions, HashMap<Integer, AbstractPowerAction> powerActionsByID, HashMap<String, EffectsBase> effects) { public static void getAllPowerActions(HashMap<String, AbstractPowerAction> powerActions, HashMap<Integer, AbstractPowerAction> powerActionsByID, HashMap<String, EffectsBase> effects) {
PreparedStatementShared ps = null;
try {
ps = new PreparedStatementShared("SELECT * FROM static_power_poweraction"); try (Connection connection = DbManager.getConnection();
ResultSet rs = ps.executeQuery(); PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_power_poweraction")) {
ResultSet rs = preparedStatement.executeQuery();
String IDString, type; String IDString, type;
while (rs.next()) { while (rs.next()) {
AbstractPowerAction apa; AbstractPowerAction apa;
type = rs.getString("type"); type = rs.getString("type");
@ -185,45 +189,14 @@ public abstract class AbstractPowerAction {
rs.close(); rs.close();
} catch (Exception e) { } catch (Exception e) {
Logger.error(e.toString()); Logger.error(e.toString());
} finally {
ps.release();
} }
//Add OpenGatePowerAction //Add OpenGatePowerAction
AbstractPowerAction openGateAction = new OpenGatePowerAction(5000, "OPENGATE", "OpenGate", false, 0); AbstractPowerAction openGateAction = new OpenGatePowerAction(5000, "OPENGATE", "OpenGate", false, 0);
powerActions.put("OPENGATE", openGateAction); powerActions.put("OPENGATE", openGateAction);
powerActionsByID.put(openGateAction.UUID, openGateAction); powerActionsByID.put(openGateAction.UUID, openGateAction);
} }
public static void loadValidItemFlags(HashMap<String, AbstractPowerAction> powerActions) {
PreparedStatementShared ps = null;
try {
ps = new PreparedStatementShared("SELECT * FROM `static_power_effect_allowed_item`");
ResultSet rs = ps.executeQuery();
String IDS;
long flags;
while (rs.next()) {
AbstractPowerAction apa;
flags = rs.getLong("flags");
IDS = rs.getString("IDString");
if (powerActions.containsKey(IDS)) {
apa = powerActions.get(IDS);
apa.validItemFlags = flags;
} else {
Logger.error("Unable to find PowerAction " + IDS);
continue;
}
}
rs.close();
} catch (Exception e) {
Logger.error(e.toString());
} finally {
ps.release();
}
}
public void startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int numTrains, ActionsBase ab, PowersBase pb) { public void startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int numTrains, ActionsBase ab, PowersBase pb) {
this._startAction(source, awo, targetLoc, numTrains, ab, pb); this._startAction(source, awo, targetLoc, numTrains, ab, pb);
} }

6
src/engine/server/login/LoginServer.java

@ -311,12 +311,6 @@ public class LoginServer {
return false; return false;
} }
PreparedStatementShared.submitPreparedStatementsCleaningJob();
if (MBServerStatics.DB_DEBUGGING_ON_BY_DEFAULT) {
PreparedStatementShared.enableDebugging();
}
return true; return true;
} }

6
src/engine/server/world/WorldServer.java

@ -534,12 +534,6 @@ public class WorldServer {
return false; return false;
} }
PreparedStatementShared.submitPreparedStatementsCleaningJob();
if (MBServerStatics.DB_DEBUGGING_ON_BY_DEFAULT) {
PreparedStatementShared.enableDebugging();
}
return true; return true;
} }

Loading…
Cancel
Save