Refactored out duplicate db interface.
This commit is contained in:
@@ -15,12 +15,13 @@ import engine.math.Vector3fImmutable;
|
||||
import engine.objects.AbstractCharacter;
|
||||
import engine.objects.AbstractWorldObject;
|
||||
import engine.objects.Item;
|
||||
import engine.objects.PreparedStatementShared;
|
||||
import engine.powers.ActionsBase;
|
||||
import engine.powers.EffectsBase;
|
||||
import engine.powers.PowersBase;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
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) {
|
||||
PreparedStatementShared ps = null;
|
||||
try {
|
||||
ps = new PreparedStatementShared("SELECT * FROM static_power_poweraction");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_power_poweraction")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
String IDString, type;
|
||||
|
||||
while (rs.next()) {
|
||||
AbstractPowerAction apa;
|
||||
type = rs.getString("type");
|
||||
@@ -185,45 +189,14 @@ public abstract class AbstractPowerAction {
|
||||
rs.close();
|
||||
} catch (Exception e) {
|
||||
Logger.error(e.toString());
|
||||
} finally {
|
||||
ps.release();
|
||||
}
|
||||
|
||||
|
||||
//Add OpenGatePowerAction
|
||||
AbstractPowerAction openGateAction = new OpenGatePowerAction(5000, "OPENGATE", "OpenGate", false, 0);
|
||||
powerActions.put("OPENGATE", 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) {
|
||||
this._startAction(source, awo, targetLoc, numTrains, ab, pb);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user