forked from SteamWar/SteamWar
Remove outdated SQL-related Java classes (GDPRQuery, Field, SelectStatement, SqlTypeMapper, Statement) and update references across modules.
Signed-off-by: Chaoscaot <max@maxsp.de>
This commit is contained in:
@@ -19,119 +19,79 @@
|
||||
|
||||
package de.steamwar.sql;
|
||||
|
||||
import de.steamwar.sql.internal.Field;
|
||||
import de.steamwar.sql.internal.SelectStatement;
|
||||
import de.steamwar.sql.internal.Statement;
|
||||
import de.steamwar.sql.internal.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class PersonalKit {
|
||||
|
||||
private static final Table<PersonalKit> table = new Table<>(PersonalKit.class);
|
||||
private static final SelectStatement<PersonalKit> getKits = table.selectFields("UserID", "GameMode");
|
||||
private static final SelectStatement<PersonalKit> getKit = table.select(Table.PRIMARY);
|
||||
private static final SelectStatement<PersonalKit> getKitInUse = table.selectFields("UserID", "GameMode", "InUse");
|
||||
private static final Statement update = table.insertAll();
|
||||
private static final Statement delete = table.delete(Table.PRIMARY);
|
||||
|
||||
@Getter
|
||||
@Field(keys = {Table.PRIMARY})
|
||||
private final int userID;
|
||||
@Getter
|
||||
@Field(keys = {Table.PRIMARY})
|
||||
private final String gamemode;
|
||||
@Getter
|
||||
@Field(keys = {Table.PRIMARY})
|
||||
private final String name;
|
||||
@Field
|
||||
private String inventory;
|
||||
@Field
|
||||
private String armor;
|
||||
@Getter
|
||||
@Field(def = "1")
|
||||
private boolean inUse;
|
||||
private final InternalKit kit;
|
||||
|
||||
public String getRawInventory() {
|
||||
return inventory;
|
||||
return kit.getRawInventory();
|
||||
}
|
||||
|
||||
public String getRawArmor() {
|
||||
return armor;
|
||||
return kit.getRawArmor();
|
||||
}
|
||||
|
||||
public ItemStack[] getInventory(){
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(new StringReader(inventory));
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(new StringReader(getRawInventory()));
|
||||
return Objects.requireNonNull(config.getList("Inventory")).toArray(new ItemStack[0]);
|
||||
}
|
||||
|
||||
public ItemStack[] getArmor(){
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(new StringReader(armor));
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(new StringReader(getRawArmor()));
|
||||
return Objects.requireNonNull(config.getList("Armor")).toArray(new ItemStack[0]);
|
||||
}
|
||||
|
||||
public void setInUse() {
|
||||
PersonalKit kit = getKitInUse(userID, gamemode);
|
||||
if(kit != null)
|
||||
kit.setUse(false);
|
||||
setUse(true);
|
||||
}
|
||||
|
||||
private void setUse(boolean inUse) {
|
||||
this.inUse = inUse;
|
||||
update();
|
||||
kit.setDefault();
|
||||
}
|
||||
|
||||
public void setInventory(ItemStack[] inventory) {
|
||||
this.inventory = saveInvConfig("Inventory", inventory);
|
||||
update();
|
||||
kit.setInventory(saveInvConfig("Inventory", inventory));
|
||||
}
|
||||
|
||||
public void setArmor(ItemStack[] armor) {
|
||||
this.armor = saveInvConfig("Armor", armor);
|
||||
update();
|
||||
kit.setArmor(saveInvConfig("Armor", armor));
|
||||
}
|
||||
|
||||
public void setContainer(ItemStack[] inventory, ItemStack[] armor) {
|
||||
this.armor = saveInvConfig("Armor", armor);
|
||||
this.inventory = saveInvConfig("Inventory", inventory);
|
||||
update();
|
||||
setInventory(inventory);
|
||||
setArmor(armor);
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
delete.update(userID, gamemode, name);
|
||||
}
|
||||
|
||||
private void update() {
|
||||
update.update(userID, gamemode, name, inventory, armor, inUse);
|
||||
kit.delete();
|
||||
}
|
||||
|
||||
public static List<PersonalKit> get(int userID, String gamemode){
|
||||
return getKits.listSelect(userID, gamemode);
|
||||
return InternalKit.get(userID, gamemode).stream().map(PersonalKit::new).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static PersonalKit get(int userID, String gamemode, String name) {
|
||||
return getKit.select(userID, gamemode, name);
|
||||
InternalKit kit = InternalKit.get(userID, gamemode, name);
|
||||
if(kit == null)
|
||||
return null;
|
||||
return new PersonalKit(kit);
|
||||
}
|
||||
|
||||
public static PersonalKit create(int userID, String gamemode, String name, ItemStack[] inventory, ItemStack[] armor){
|
||||
if(armor == null) {
|
||||
armor = new ItemStack[]{null, null, null, null};
|
||||
}
|
||||
PersonalKit kit = new PersonalKit(userID, gamemode, name, saveInvConfig("Inventory", inventory), saveInvConfig("Armor", armor), true);
|
||||
kit.update();
|
||||
return kit;
|
||||
InternalKit kit = InternalKit.create(userID, gamemode, name, saveInvConfig("Inventory", inventory), saveInvConfig("Armor", armor));
|
||||
return new PersonalKit(kit);
|
||||
}
|
||||
|
||||
public static PersonalKit getKitInUse(int userID, String gamemode) {
|
||||
return getKitInUse.select(userID, gamemode, true);
|
||||
InternalKit kit = InternalKit.getKitInUse(userID, gamemode);
|
||||
if(kit == null)
|
||||
return null;
|
||||
return new PersonalKit(kit);
|
||||
}
|
||||
|
||||
private static String saveInvConfig(String name, ItemStack[] inv) {
|
||||
|
||||
@@ -20,19 +20,12 @@
|
||||
package de.steamwar.sql;
|
||||
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.core.WorldEditWrapper;
|
||||
import de.steamwar.sql.internal.SqlTypeMapper;
|
||||
import de.steamwar.sql.internal.Statement;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PipedInputStream;
|
||||
import java.sql.Blob;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class SchematicData {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user