Add InUse
Dieser Commit ist enthalten in:
Ursprung
63d59121b3
Commit
e88f183e72
@ -37,6 +37,7 @@ public class PersonalKit {
|
||||
private final String gamemode;
|
||||
private String inventory;
|
||||
private String armor;
|
||||
private boolean inUse;
|
||||
|
||||
private PersonalKit(ResultSet rs) throws SQLException {
|
||||
kitID = rs.getInt("KitID");
|
||||
@ -45,6 +46,7 @@ public class PersonalKit {
|
||||
inventory = rs.getString("Inventory");
|
||||
armor = rs.getString("Armor");
|
||||
name = rs.getString("Name");
|
||||
inUse = rs.getBoolean("InUse");
|
||||
}
|
||||
|
||||
public static List<PersonalKit> get(int userID, String gamemode){
|
||||
@ -81,6 +83,23 @@ public class PersonalKit {
|
||||
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(){
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(new StringReader(inventory));
|
||||
return Objects.requireNonNull(config.getList("Inventory")).toArray(new ItemStack[0]);
|
||||
@ -103,6 +122,15 @@ public class PersonalKit {
|
||||
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) {
|
||||
this.name = name;
|
||||
SQL.update("UPDATE PersonalKit SET Name = ? WHERE KitID = ?", this.name, kitID);
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren