MultiKits #88
@ -25,11 +25,14 @@ import org.bukkit.inventory.ItemStack;
|
||||
import java.io.StringReader;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class PersonalKit {
|
||||
|
||||
private final int userID;
|
||||
private String name;
|
||||
private final String gamemode;
|
||||
private String inventory;
|
||||
private String armor;
|
||||
@ -39,30 +42,42 @@ public class PersonalKit {
|
||||
gamemode = rs.getString("GameMode");
|
||||
inventory = rs.getString("Inventory");
|
||||
armor = rs.getString("Armor");
|
||||
name = rs.getString("Name");
|
||||
}
|
||||
|
||||
public static PersonalKit get(int userID, String gamemode){
|
||||
public static List<PersonalKit> get(int userID, String gamemode){
|
||||
ResultSet rs = SQL.select("SELECT * FROM PersonalKit WHERE UserID = ? AND GameMode = ?", userID, gamemode);
|
||||
try {
|
||||
List<PersonalKit> list = new ArrayList<>();
|
||||
while (rs.next())
|
||||
list.add(new PersonalKit(rs));
|
||||
return list;
|
||||
} catch (SQLException e) {
|
||||
throw new SecurityException("Failed loading personal kit", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static PersonalKit get(int userID, String gamemode, String name) {
|
||||
ResultSet rs = SQL.select("SELECT * FROM PersonalKit WHERE UserID = ? AND GameMode = ? AND Name = ?", userID, gamemode, name);
|
||||
try {
|
||||
if(!rs.next())
|
||||
return null;
|
||||
|
||||
return new PersonalKit(rs);
|
||||
} catch (SQLException e) {
|
||||
throw new SecurityException("Failed loading personal kit", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static PersonalKit save(int userID, String gamemode, ItemStack[] inventory, ItemStack[] armor){
|
||||
public static PersonalKit create(int userID, String gamemode, String name, ItemStack[] inventory, ItemStack[] armor){
|
||||
YamlConfiguration inventoryConfig = new YamlConfiguration();
|
||||
inventoryConfig.set("Inventory", inventory);
|
||||
|
||||
YamlConfiguration armorConfig = new YamlConfiguration();
|
||||
armorConfig.set("Armor", armor);
|
||||
|
||||
SQL.update("INSERT INTO PersonalKit (UserID, GameMode, Inventory, Armor) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE Inventory = VALUES(Inventory), Armor = VALUES(Armor)",
|
||||
SQL.update("INSERT INTO PersonalKit (UserID, GameMode, Name, Inventory, Armor) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE Inventory = VALUES(Inventory), Armor = VALUES(Armor)",
|
||||
userID, gamemode, inventoryConfig.saveToString(), armorConfig.saveToString());
|
||||
return get(userID, gamemode);
|
||||
return get(userID, gamemode, name);
|
||||
}
|
||||
|
||||
public ItemStack[] getInventory(){
|
||||
@ -74,4 +89,37 @@ public class PersonalKit {
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(new StringReader(armor));
|
||||
return Objects.requireNonNull(config.getList("Armor")).toArray(new ItemStack[0]);
|
||||
}
|
||||
|
||||
public int getUserID() {
|
||||
return userID;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
|
||||
}
|
||||
|
||||
public String getGamemode() {
|
||||
return gamemode;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
SQL.update("UPDATE PersonalKit SET Name = ?", this.name);
|
||||
}
|
||||
|
||||
public void setInventory(ItemStack[] inventory) {
|
||||
YamlConfiguration inventoryConfig = new YamlConfiguration();
|
||||
inventoryConfig.set("Inventory", inventory);
|
||||
|
||||
this.inventory = inventoryConfig.saveToString();
|
||||
SQL.update("UPDATE PersonalKit SET Inventory = ?", this.inventory);
|
||||
}
|
||||
|
||||
public void setArmor(ItemStack[] armor) {
|
||||
YamlConfiguration armorConfig = new YamlConfiguration();
|
||||
armorConfig.set("Armor", armor);
|
||||
|
||||
this.armor = armorConfig.saveToString();
|
||||
SQL.update("UPDATE PersonalKit SET Armor = ?", this.armor);
|
||||
}
|
||||
Lixfel
hat
Wurde bislang nicht benötigt, warum jetzt? Wurde bislang nicht benötigt, warum jetzt?
Chaoscaot
hat
Habe es einfach mal Präventiv reingepackt, weil ich zu diesem Zeitpunkt noch nicht ganz wusste, ob ich es brauchen würde. Kann eigentlich weg. Habe es einfach mal Präventiv reingepackt, weil ich zu diesem Zeitpunkt noch nicht ganz wusste, ob ich es brauchen würde. Kann eigentlich weg.
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Ich weiß jetzt nicht ganz den Sinn dieser "NameInUse" Funktion, um Abzufragen, ob dieser Name derzeit verwendet wird, ist das denkbar ungeeignet.
Sinnvoller wäre denke ich ein getInUse(), um das derzeitige Kit in Benutzung zu bekommen. (Es sei denn, du hast da einen sehr speziellen Anwendungsfall)