mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2025-08-17 17:15:47 +00:00
cooldowns saved to database
This commit is contained in:
parent
9499d36482
commit
86bf26535e
8
pom.xml
8
pom.xml
@ -103,6 +103,14 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>9</source>
|
||||||
|
<target>9</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package me.SuperRonanCraft.BetterRTP.player.rtp;
|
package me.SuperRonanCraft.BetterRTP.player.rtp;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import me.SuperRonanCraft.BetterRTP.references.database.DatabaseCooldowns;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
|
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
|
||||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
@ -9,29 +10,32 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class RTPCooldown {
|
public class RTPCooldown {
|
||||||
|
|
||||||
private final HashMap<UUID, Long> cooldowns = new HashMap<>(); //Cooldown timer for each player
|
private final HashMap<UUID, Long> cooldowns = new HashMap<>(); //Cooldown timer for each player
|
||||||
private HashMap<UUID, Integer> locked = null; //Players locked from rtp'ing ever again
|
private HashMap<UUID, Integer> uses = null; //Players locked from rtp'ing ever again
|
||||||
|
private final DatabaseCooldowns database = new DatabaseCooldowns();
|
||||||
@Getter boolean enabled;
|
@Getter boolean enabled;
|
||||||
private int
|
private int
|
||||||
timer, //Cooldown timer
|
timer, //Cooldown timer
|
||||||
lockedAfter; //Rtp's before being locked
|
lockedAfter; //Rtp's before being locked
|
||||||
|
|
||||||
public void load() {
|
public void load() {
|
||||||
configfile = new File(BetterRTP.getInstance().getDataFolder(), "data/cooldowns.yml");
|
database.load();
|
||||||
|
//configfile = new File(BetterRTP.getInstance().getDataFolder(), "data/cooldowns.yml");
|
||||||
cooldowns.clear();
|
cooldowns.clear();
|
||||||
if (locked != null)
|
if (uses != null)
|
||||||
locked.clear();
|
uses.clear();
|
||||||
FileBasics.FILETYPE config = FileBasics.FILETYPE.CONFIG;
|
FileBasics.FILETYPE config = FileBasics.FILETYPE.CONFIG;
|
||||||
enabled = config.getBoolean("Settings.Cooldown.Enabled");
|
enabled = config.getBoolean("Settings.Cooldown.Enabled");
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
timer = config.getInt("Settings.Cooldown.Time");
|
timer = config.getInt("Settings.Cooldown.Time");
|
||||||
lockedAfter = config.getInt("Settings.Cooldown.LockAfter");
|
lockedAfter = config.getInt("Settings.Cooldown.LockAfter");
|
||||||
if (lockedAfter > 0)
|
if (lockedAfter > 0)
|
||||||
locked = new HashMap<>();
|
uses = new HashMap<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,11 +43,11 @@ public class RTPCooldown {
|
|||||||
if (!enabled) return;
|
if (!enabled) return;
|
||||||
cooldowns.put(id, System.currentTimeMillis());
|
cooldowns.put(id, System.currentTimeMillis());
|
||||||
if (lockedAfter > 0) {
|
if (lockedAfter > 0) {
|
||||||
if (locked.containsKey(id))
|
if (uses.containsKey(id))
|
||||||
locked.put(id, locked.get(id) + 1);
|
uses.put(id, uses.get(id) + 1);
|
||||||
else
|
else
|
||||||
locked.put(id, 1);
|
uses.put(id, 1);
|
||||||
savePlayer(id, true, cooldowns.get(id), locked.get(id));
|
savePlayer(id, true, cooldowns.get(id), uses.get(id));
|
||||||
} else
|
} else
|
||||||
savePlayer(id, true, cooldowns.get(id), 0);
|
savePlayer(id, true, cooldowns.get(id), 0);
|
||||||
}
|
}
|
||||||
@ -58,19 +62,19 @@ public class RTPCooldown {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean locked(UUID id) {
|
public boolean locked(UUID id) {
|
||||||
if (locked != null && locked.containsKey(id))
|
if (uses != null && uses.containsKey(id))
|
||||||
return locked.get(id) >= lockedAfter;
|
return uses.get(id) >= lockedAfter;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeCooldown(UUID id) {
|
public void removeCooldown(UUID id) {
|
||||||
if (!enabled) return;
|
if (!enabled) return;
|
||||||
if (lockedAfter > 0) {
|
if (lockedAfter > 0) {
|
||||||
locked.put(id, locked.getOrDefault(id, 1) - 1);
|
uses.put(id, uses.getOrDefault(id, 1) - 1);
|
||||||
if (locked.get(id) <= 0) { //Remove from file as well
|
if (uses.get(id) <= 0) { //Remove from file as well
|
||||||
savePlayer(id, false, 0L, 0);
|
savePlayer(id, false, 0L, 0);
|
||||||
} else { //Keep the player cached
|
} else { //Keep the player cached
|
||||||
savePlayer(id, false, cooldowns.get(id), locked.get(id));
|
savePlayer(id, false, cooldowns.get(id), uses.get(id));
|
||||||
}
|
}
|
||||||
cooldowns.remove(id);
|
cooldowns.remove(id);
|
||||||
} else { //Remove completely
|
} else { //Remove completely
|
||||||
@ -79,8 +83,13 @@ public class RTPCooldown {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void savePlayer(UUID id, boolean adding, long time, int attempts) {
|
private void savePlayer(UUID uuid, boolean adding, long time, int attempts) {
|
||||||
YamlConfiguration config = getFile();
|
if (adding) {
|
||||||
|
database.setCooldown(uuid, time, attempts);
|
||||||
|
} else {
|
||||||
|
database.removePlayer(uuid);
|
||||||
|
}
|
||||||
|
/*YamlConfiguration config = getFile();
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
BetterRTP.getInstance().getLogger().severe("Unabled to save cooldown for the players UUID " + id
|
BetterRTP.getInstance().getLogger().severe("Unabled to save cooldown for the players UUID " + id
|
||||||
+ ". Cooldown file might have been compromised!");
|
+ ". Cooldown file might have been compromised!");
|
||||||
@ -97,12 +106,12 @@ public class RTPCooldown {
|
|||||||
config.save(configfile);
|
config.save(configfile);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private File configfile;
|
/*private File configfile;
|
||||||
|
|
||||||
private YamlConfiguration getFile() {
|
/*private YamlConfiguration getFile() {
|
||||||
if (!configfile.exists()) {
|
if (!configfile.exists()) {
|
||||||
try {
|
try {
|
||||||
configfile.getParentFile().mkdir();
|
configfile.getParentFile().mkdir();
|
||||||
@ -119,11 +128,16 @@ public class RTPCooldown {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public void loadPlayer(UUID uuid) {
|
public void loadPlayer(UUID uuid) {
|
||||||
if (isEnabled()) {
|
if (isEnabled()) {
|
||||||
String id = uuid.toString();
|
List<Object> data = database.getCooldown(uuid);
|
||||||
|
if (data != null) {
|
||||||
|
cooldowns.put(uuid, (Long) data.get(0));
|
||||||
|
uses.put(uuid, (int) data.get(1));
|
||||||
|
}
|
||||||
|
/*String id = uuid.toString();
|
||||||
YamlConfiguration config = getFile();
|
YamlConfiguration config = getFile();
|
||||||
if (config != null && config.isConfigurationSection(id))
|
if (config != null && config.isConfigurationSection(id))
|
||||||
try {
|
try {
|
||||||
@ -131,18 +145,18 @@ public class RTPCooldown {
|
|||||||
cooldowns.put(uuid, time);
|
cooldowns.put(uuid, time);
|
||||||
if (lockedAfter > 0) {
|
if (lockedAfter > 0) {
|
||||||
int attempts = config.getInt(id + ".Attempts");
|
int attempts = config.getInt(id + ".Attempts");
|
||||||
locked.put(uuid, attempts);
|
uses.put(uuid, attempts);
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
BetterRTP.getInstance().getLogger().info("UUID of `" + id + "` is invalid, please delete this!");
|
BetterRTP.getInstance().getLogger().info("UUID of `" + id + "` is invalid, please delete this!");
|
||||||
//Bad uuid
|
//Bad uuid
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unloadPlayer(UUID uuid) {
|
public void unloadPlayer(UUID uuid) {
|
||||||
cooldowns.remove(uuid);
|
cooldowns.remove(uuid);
|
||||||
if (locked != null)
|
if (uses != null)
|
||||||
locked.remove(uuid);
|
uses.remove(uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,14 @@
|
|||||||
package me.SuperRonanCraft.BetterRTP.references.database;
|
package me.SuperRonanCraft.BetterRTP.references.database;
|
||||||
|
|
||||||
import me.ronancraft.AmethystGear.AmethystGear;
|
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||||
import me.ronancraft.AmethystGear.resources.gear.ELEMENT_TYPE;
|
|
||||||
import me.ronancraft.AmethystGear.resources.gear.GEAR_TIER;
|
|
||||||
import me.ronancraft.AmethystGear.resources.gear.GEAR_TYPE;
|
|
||||||
import me.ronancraft.AmethystGear.resources.gear.catalysts.Catalyst;
|
|
||||||
import me.ronancraft.AmethystGear.resources.gear.gear.GearBaseInfo;
|
|
||||||
import me.ronancraft.AmethystGear.resources.gear.gear.GearData;
|
|
||||||
import me.ronancraft.AmethystGear.resources.helpers.HelperDate;
|
|
||||||
import me.ronancraft.AmethystGear.resources.helpers.HelperJsonConverter;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class DatabaseCooldowns extends SQLite {
|
public class DatabaseCooldowns extends SQLite {
|
||||||
@ -24,22 +18,10 @@ public class DatabaseCooldowns extends SQLite {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum COLUMNS {
|
public enum COLUMNS {
|
||||||
INDEX("id", "integer PRIMARY KEY AUTOINCREMENT"),
|
UUID("uuid", "varchar(32) PRIMARY KEY"),
|
||||||
UUID("owner", "varchar(32)"),
|
//COOLDOWN DATA
|
||||||
//GEAR INFO
|
COOLDOWN_DATE("date", "long"),
|
||||||
GEAR_TIER("gear_tier", "text DEFAULT 'BRONZE'"),
|
USES("uses", "integer"),
|
||||||
GEAR_LEVEL("level", "integer DEFAULT 1"),
|
|
||||||
GEAR_XP("xp", "integer DEFAULT 0"),
|
|
||||||
GEAR_CATALYST("catalyst", "text DEFAULT NULL"),
|
|
||||||
GEAR_TRACKER("trackers", "text DEFAULT NULL"), //Trackers stored in json
|
|
||||||
//BASIC GEAR INFO
|
|
||||||
IDENTIFIER("identifier", "varchar(32)"),
|
|
||||||
BASE_TIER("base_tier", "text DEFAULT 'BRONZE'"),
|
|
||||||
BASE_ELEMENT("base_element", "text DEFAULT 'WATER'"),
|
|
||||||
BASE_TYPE("base_type", "text DEFAULT 'SWORD'"),
|
|
||||||
//MISC
|
|
||||||
DATE_ACQUIRED("date_acquired", "text DEFAULT 'N/A'"),
|
|
||||||
FAVORITE("favorite", "boolean DEFAULT false"),
|
|
||||||
;
|
;
|
||||||
|
|
||||||
public String name;
|
public String name;
|
||||||
@ -51,175 +33,52 @@ public class DatabaseCooldowns extends SQLite {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeGear(GearData gear) {
|
public boolean removePlayer(UUID uuid) {
|
||||||
String sql = "DELETE FROM " + table + " WHERE "
|
String sql = "DELETE FROM " + table + " WHERE "
|
||||||
+ COLUMNS.INDEX.name + " = ?";
|
+ COLUMNS.UUID.name + " = ?";
|
||||||
List<Object> params = new ArrayList<>() {{
|
List<Object> params = new ArrayList<>() {{
|
||||||
add(gear.getDatabase_id());
|
add(uuid.toString());
|
||||||
}};
|
}};
|
||||||
return sqlUpdate(sql, params);
|
return sqlUpdate(sql, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeGear(List<GearData> gear) {
|
public List<Object> getCooldown(UUID uuid) {
|
||||||
String sql = "DELETE FROM " + table + " WHERE "
|
|
||||||
+ COLUMNS.INDEX.name + " IN (" + makePlaceholders(gear.size()) + ")";
|
|
||||||
List<Object> params = new ArrayList<>();
|
|
||||||
for (GearData gearData : gear)
|
|
||||||
params.add(gearData.getDatabase_id());
|
|
||||||
return sqlUpdate(sql, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String makePlaceholders(int len) {
|
|
||||||
StringBuilder sb = new StringBuilder(len * 2 - 1);
|
|
||||||
sb.append("?");
|
|
||||||
for (int i = 1; i < len; i++)
|
|
||||||
sb.append(",?");
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<GearData> getGear(Player p) {
|
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
List<GearData> gearList = new ArrayList<>();
|
|
||||||
conn = getSQLConnection();
|
conn = getSQLConnection();
|
||||||
ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE " + COLUMNS.UUID.name + " = ?");
|
ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE " + COLUMNS.UUID.name + " = ?");
|
||||||
ps.setString(1, p.getUniqueId().toString());
|
ps.setString(1, uuid.toString());
|
||||||
|
|
||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
//Load all of players gear
|
if (rs.next()) {
|
||||||
while (rs.next()) {
|
List<Object> data = new ArrayList<>();
|
||||||
GearBaseInfo baseInfo = new GearBaseInfo(
|
data.add(rs.getLong(COLUMNS.COOLDOWN_DATE.name));
|
||||||
rs.getString(COLUMNS.IDENTIFIER.name),
|
data.add(rs.getInt(COLUMNS.USES.name));
|
||||||
ELEMENT_TYPE.valueOf(rs.getString( COLUMNS.BASE_ELEMENT.name)),
|
return data;
|
||||||
GEAR_TIER.valueOf(rs.getString( COLUMNS.BASE_TIER.name)),
|
|
||||||
GEAR_TYPE.valueOf(rs.getString( COLUMNS.BASE_TYPE.name))
|
|
||||||
);
|
|
||||||
GearData data = new GearData(
|
|
||||||
baseInfo,
|
|
||||||
rs.getInt( COLUMNS.INDEX.name),
|
|
||||||
rs.getString( COLUMNS.DATE_ACQUIRED.name),
|
|
||||||
GEAR_TIER.valueOf(rs.getString( COLUMNS.GEAR_TIER.name)),
|
|
||||||
rs.getInt( COLUMNS.GEAR_LEVEL.name),
|
|
||||||
rs.getInt( COLUMNS.GEAR_XP.name),
|
|
||||||
HelperJsonConverter.getCatalystFromJson(rs.getString(COLUMNS.GEAR_CATALYST.name)),
|
|
||||||
HelperJsonConverter.getTrackersFromJson(rs.getString(COLUMNS.GEAR_TRACKER.name))
|
|
||||||
);
|
|
||||||
data.setFavorite(rs.getBoolean(COLUMNS.FAVORITE.name));
|
|
||||||
if (data.getGear().getIdentifier() != null)
|
|
||||||
gearList.add(data);
|
|
||||||
}
|
}
|
||||||
return gearList;
|
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
AmethystGear.getInstance().getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
|
BetterRTP.getInstance().getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
close(ps, rs, conn);
|
close(ps, rs, conn);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fixGear(Player player) {
|
//Set a player Cooldown
|
||||||
//This is here incase in the future someone smart breaks my database and I gotta fix it in code...
|
public void setCooldown(UUID uuid, Long time, int uses) {
|
||||||
}
|
String pre = "INSERT OR REPLACE INTO ";
|
||||||
|
|
||||||
//Create gear
|
|
||||||
public GearData addNewGear(Player p, GearBaseInfo _gear) {
|
|
||||||
String date = HelperDate.getDate(HelperDate.getDate());
|
|
||||||
GearData gearData = new GearData(_gear, date);
|
|
||||||
//Default Catalyst
|
|
||||||
gearData.setCatalysts(List.of(new Catalyst(1, _gear.getElement())));
|
|
||||||
|
|
||||||
String pre = "INSERT INTO ";
|
|
||||||
String sql = pre + table + " ("
|
String sql = pre + table + " ("
|
||||||
+ COLUMNS.UUID.name + ", "
|
+ COLUMNS.UUID.name + ", "
|
||||||
//GEAR INFO
|
+ COLUMNS.COOLDOWN_DATE.name + ", "
|
||||||
+ COLUMNS.GEAR_TIER.name + ", "
|
+ COLUMNS.USES.name + " "
|
||||||
+ COLUMNS.GEAR_LEVEL.name + ", "
|
+ ") VALUES(?, ?, ?)";
|
||||||
+ COLUMNS.GEAR_XP.name + ", "
|
|
||||||
+ COLUMNS.GEAR_CATALYST.name + ", "
|
|
||||||
+ COLUMNS.GEAR_TRACKER.name + ", "
|
|
||||||
//BASE GEAR INFO
|
|
||||||
+ COLUMNS.IDENTIFIER.name + ", "
|
|
||||||
+ COLUMNS.BASE_ELEMENT.name + ", "
|
|
||||||
+ COLUMNS.BASE_TYPE.name + ", "
|
|
||||||
+ COLUMNS.BASE_TIER.name + ", "
|
|
||||||
//MISC
|
|
||||||
+ COLUMNS.DATE_ACQUIRED.name + ", "
|
|
||||||
+ COLUMNS.FAVORITE.name + " "
|
|
||||||
+ ") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
|
||||||
List<Object> params = new ArrayList<>() {{
|
List<Object> params = new ArrayList<>() {{
|
||||||
add(p.getUniqueId().toString());
|
add(uuid.toString());
|
||||||
//GEAR INFO
|
add(time);
|
||||||
add(gearData.getTier().name());
|
add(uses);
|
||||||
add(gearData.getLevel());
|
|
||||||
add(gearData.getXp());
|
|
||||||
add(HelperJsonConverter.getJsonFromCatalysts(gearData.getCatalysts()));
|
|
||||||
add(HelperJsonConverter.getJsonFromTrackers(gearData.getTrackers()));
|
|
||||||
//BASE GEAR INFO
|
|
||||||
add(gearData.getGear().getIdentifier());
|
|
||||||
add(gearData.getGear().getElement().name());
|
|
||||||
add(gearData.getGear().getType().name());
|
|
||||||
add(gearData.getGear().getTier().name());
|
|
||||||
//MISC
|
|
||||||
add(date);
|
|
||||||
add(gearData.isFavorite());
|
|
||||||
}};
|
}};
|
||||||
gearData.setDatabase_id(sqlGetIndex(sql, params));
|
sqlUpdate(sql, params);
|
||||||
|
|
||||||
return gearData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean updateGear(GearData gear) {
|
|
||||||
String sql = "UPDATE " + table + " SET "
|
|
||||||
+ COLUMNS.GEAR_TIER.name + " = ?, "
|
|
||||||
+ COLUMNS.GEAR_LEVEL.name + " = ?, "
|
|
||||||
+ COLUMNS.GEAR_XP.name + " = ?, "
|
|
||||||
+ COLUMNS.GEAR_CATALYST.name + " = ?, "
|
|
||||||
+ COLUMNS.GEAR_TRACKER.name + " = ?, "
|
|
||||||
+ COLUMNS.FAVORITE.name + " = ? "
|
|
||||||
+ "WHERE "
|
|
||||||
+ COLUMNS.INDEX.name + " = ?";
|
|
||||||
List<Object> params = new ArrayList<>() {{
|
|
||||||
add(gear.getTier().name());
|
|
||||||
add(gear.getLevel());
|
|
||||||
add(gear.getXp());
|
|
||||||
add(HelperJsonConverter.getJsonFromCatalysts(gear.getCatalysts()));
|
|
||||||
add(HelperJsonConverter.getJsonFromTrackers(gear.getTrackers()));
|
|
||||||
add(gear.isFavorite());
|
|
||||||
//Database Index
|
|
||||||
add(gear.getDatabase_id());
|
|
||||||
}};
|
|
||||||
gear.setUpdated(false); //Gear has been uploaded, no need to update if nothing new has changed
|
|
||||||
return sqlUpdate(sql, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int sqlGetIndex(String statement, List<Object> params) {
|
|
||||||
Connection conn = null;
|
|
||||||
PreparedStatement ps = null;
|
|
||||||
int index = -1;
|
|
||||||
try {
|
|
||||||
conn = getSQLConnection();
|
|
||||||
ps = conn.prepareStatement(statement, Statement.RETURN_GENERATED_KEYS);
|
|
||||||
if (params != null) {
|
|
||||||
Iterator<Object> it = params.iterator();
|
|
||||||
int paramIndex = 1;
|
|
||||||
while (it.hasNext()) {
|
|
||||||
ps.setObject(paramIndex, it.next());
|
|
||||||
paramIndex++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ps.executeUpdate();
|
|
||||||
ResultSet rs = ps.getGeneratedKeys();
|
|
||||||
if (rs.next()) {
|
|
||||||
//HelperItemGeneral.applyData(HelperData.getData(gear.item), GENERAL_DATA_INT.DATABASE_INDEX, rs.getInt(1));
|
|
||||||
index = rs.getInt(1);
|
|
||||||
}
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
AmethystGear.getInstance().getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
|
|
||||||
} finally {
|
|
||||||
close(ps, null, conn);
|
|
||||||
}
|
|
||||||
return index;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user