SteamWar/SpigotCore
Archiviert
13
0
Dieser Commit ist enthalten in:
Chaoscaot 2021-01-09 12:13:03 +01:00
Ursprung 63d59121b3
Commit e88f183e72

Datei anzeigen

@ -37,6 +37,7 @@ public class PersonalKit {
private final String gamemode; private final String gamemode;
private String inventory; private String inventory;
private String armor; private String armor;
private boolean inUse;
private PersonalKit(ResultSet rs) throws SQLException { private PersonalKit(ResultSet rs) throws SQLException {
kitID = rs.getInt("KitID"); kitID = rs.getInt("KitID");
@ -45,6 +46,7 @@ public class PersonalKit {
inventory = rs.getString("Inventory"); inventory = rs.getString("Inventory");
armor = rs.getString("Armor"); armor = rs.getString("Armor");
name = rs.getString("Name"); name = rs.getString("Name");
inUse = rs.getBoolean("InUse");
} }
public static List<PersonalKit> get(int userID, String gamemode){ public static List<PersonalKit> get(int userID, String gamemode){
@ -81,6 +83,23 @@ public class PersonalKit {
userID, gamemode, name, inventoryConfig.saveToString(), armorConfig.saveToString()); userID, gamemode, name, inventoryConfig.saveToString(), armorConfig.saveToString());
} }
public static PersonalKit getKitInUse(int userID, String gamemode) {
ResultSet rs = SQL.select("SELECT * FROM PersonalKit WHERE UserID = ? AND GameMode = ? AND InUse = ?", userID, gamemode, true);
try {
List<PersonalKit> list = new ArrayList<>();
while (rs.next())
list.add(new PersonalKit(rs));
if(list.size() > 1) {
list.forEach(kit -> {
if(list.indexOf(kit) >= 1) kit.setInUse(false);
});
}
return list.get(0);
} catch (SQLException e) {
throw new SecurityException("Failed loading personal kit", e);
}
}
public ItemStack[] getInventory(){ public ItemStack[] getInventory(){
YamlConfiguration config = YamlConfiguration.loadConfiguration(new StringReader(inventory)); YamlConfiguration config = YamlConfiguration.loadConfiguration(new StringReader(inventory));
return Objects.requireNonNull(config.getList("Inventory")).toArray(new ItemStack[0]); return Objects.requireNonNull(config.getList("Inventory")).toArray(new ItemStack[0]);
@ -103,6 +122,15 @@ public class PersonalKit {
return gamemode; return gamemode;
} }
public boolean isInUse() {
return inUse;
}
public void setInUse(boolean inUse) {
this.inUse = inUse;
SQL.update("UPDATE PersonalKit SET InUse = ? WHERE KitID = ?", this.inUse, kitID);
}
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
SQL.update("UPDATE PersonalKit SET Name = ? WHERE KitID = ?", this.name, kitID); SQL.update("UPDATE PersonalKit SET Name = ? WHERE KitID = ?", this.name, kitID);