From 871e45ffbbf422f475e3b237079158ff70d16efc Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 4 Feb 2023 12:55:08 +0100 Subject: [PATCH] WIP CommonDB Signed-off-by: Lixfel --- CommonCore | 2 +- src/de/steamwar/bungeecore/ArenaMode.java | 2 +- .../bungeecore/bot/events/EventManager.java | 2 +- .../bungeecore/commands/BauCommand.java | 3 +- .../bungeecore/commands/CheckCommand.java | 13 +- .../bungeecore/commands/EventCommand.java | 6 +- .../bungeecore/commands/JoinmeCommand.java | 2 +- .../bungeecore/commands/ReplayCommand.java | 2 +- .../bungeecore/commands/TpCommand.java | 2 +- .../bungeecore/listeners/CheckListener.java | 2 +- .../network/handlers/FightEndsHandler.java | 1 + .../network/handlers/PrepareSchemHandler.java | 2 +- .../bungeecore/sql/BauweltMember.java | 118 ------------ src/de/steamwar/bungeecore/sql/Fight.java | 5 +- .../bungeecore/sql/SchematicNode.java | 1 + .../bungeecore/sql/SchematicType.java | 177 ------------------ src/de/steamwar/sql/SQLWrapperImpl.java | 22 ++- 17 files changed, 47 insertions(+), 315 deletions(-) delete mode 100644 src/de/steamwar/bungeecore/sql/BauweltMember.java delete mode 100644 src/de/steamwar/bungeecore/sql/SchematicType.java diff --git a/CommonCore b/CommonCore index fca45b0..d439ecb 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit fca45b084e22653391b526d57396ec386fa7444f +Subproject commit d439ecb8d01d576310766e497c970bce7eb1db2f diff --git a/src/de/steamwar/bungeecore/ArenaMode.java b/src/de/steamwar/bungeecore/ArenaMode.java index abb6b77..d33aeeb 100644 --- a/src/de/steamwar/bungeecore/ArenaMode.java +++ b/src/de/steamwar/bungeecore/ArenaMode.java @@ -19,7 +19,7 @@ package de.steamwar.bungeecore; -import de.steamwar.bungeecore.sql.SchematicType; +import de.steamwar.sql.SchematicType; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.config.Configuration; import net.md_5.bungee.config.ConfigurationProvider; diff --git a/src/de/steamwar/bungeecore/bot/events/EventManager.java b/src/de/steamwar/bungeecore/bot/events/EventManager.java index cd57767..1cd09d3 100644 --- a/src/de/steamwar/bungeecore/bot/events/EventManager.java +++ b/src/de/steamwar/bungeecore/bot/events/EventManager.java @@ -22,7 +22,7 @@ package de.steamwar.bungeecore.bot.events; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; import de.steamwar.bungeecore.sql.EventFight; -import de.steamwar.bungeecore.sql.Team; +import de.steamwar.sql.Team; import de.steamwar.sql.TeamTeilnahme; import de.steamwar.sql.Event; import lombok.experimental.UtilityClass; diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index 9740cc7..b73855f 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -32,6 +32,7 @@ import de.steamwar.command.TypeValidator; import de.steamwar.messages.ChatSender; import de.steamwar.network.packets.server.BaumemberUpdatePacket; import de.steamwar.bungeecore.util.BauLockState; +import de.steamwar.sql.BauweltMember; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; @@ -122,7 +123,7 @@ public class BauCommand extends SWCommand { @Register(value = "addmember", description = "BAU_ADDMEMBER_USAGE") public void addmember(ProxiedPlayer p, @Validator("addMemberTarget") SteamwarUser target) { - new BauweltMember(p.getUniqueId(), target.getUuid(), false, false); + BauweltMember.addMember(p.getUniqueId(), target.getUuid()); Message.send("BAU_ADDMEMBER_ADDED", p); ProxiedPlayer z = ProxyServer.getInstance().getPlayer(target.getUuid()); diff --git a/src/de/steamwar/bungeecore/commands/CheckCommand.java b/src/de/steamwar/bungeecore/commands/CheckCommand.java index 02fc7a8..e231f75 100644 --- a/src/de/steamwar/bungeecore/commands/CheckCommand.java +++ b/src/de/steamwar/bungeecore/commands/CheckCommand.java @@ -24,11 +24,10 @@ import de.steamwar.bungeecore.bot.util.DiscordSchemAlert; import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.bungeecore.sql.CheckedSchematic; import de.steamwar.bungeecore.sql.SchematicNode; -import de.steamwar.bungeecore.sql.SchematicType; +import de.steamwar.sql.SchematicType; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.command.SWCommand; import net.md_5.bungee.api.ChatColor; -import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.TextComponent; @@ -37,12 +36,12 @@ import net.md_5.bungee.config.Configuration; import java.sql.Timestamp; import java.time.Instant; -import java.time.format.DateTimeFormatter; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.logging.Level; public class CheckCommand extends SWCommand { + private static final Map fightTypes = new HashMap<>(); private static Map> checkQuestions = new HashMap<>(); private static Map> ranks = new HashMap<>(); @@ -55,6 +54,10 @@ public class CheckCommand extends SWCommand { ranks.put(checkType, config.getStringList("Ranks")); } + public static void addFightType(SchematicType checkType, SchematicType fightType) { + fightTypes.put(checkType, fightType); + } + public static boolean isChecking(ProxiedPlayer player){ return currentCheckers.containsKey(player.getUniqueId()); } @@ -215,7 +218,7 @@ public class CheckCommand extends SWCommand { this.checkList = checkQuestions.get(schematic.getSchemtype()).listIterator(); ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { - ArenaMode mode = ArenaMode.getBySchemType(schematic.getSchemtype().fightType()); + ArenaMode mode = ArenaMode.getBySchemType(fightTypes.get(schematic.getSchemtype())); if(new ServerStarter().test(mode, mode.getRandomMap(), checker).check(schematic.getId()).start() == null) { remove(); return; @@ -273,7 +276,7 @@ public class CheckCommand extends SWCommand { schematic.setRank(rank); } - schematic.setType(schematic.getSchemtype().fightType().toDB()); + schematic.setType(fightTypes.get(schematic.getSchemtype()).toDB()); CheckedSchematic.create(schematic, SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "freigegeben"); SteamwarUser user = SteamwarUser.get(schematic.getOwner()); ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid()); diff --git a/src/de/steamwar/bungeecore/commands/EventCommand.java b/src/de/steamwar/bungeecore/commands/EventCommand.java index e106d59..082b9b7 100644 --- a/src/de/steamwar/bungeecore/commands/EventCommand.java +++ b/src/de/steamwar/bungeecore/commands/EventCommand.java @@ -21,8 +21,8 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.sql.EventFight; -import de.steamwar.bungeecore.sql.SchematicType; -import de.steamwar.bungeecore.sql.Team; +import de.steamwar.sql.SchematicType; +import de.steamwar.sql.Team; import de.steamwar.sql.TeamTeilnahme; import de.steamwar.sql.Event; import net.md_5.bungee.api.CommandSender; @@ -88,7 +88,7 @@ public class EventCommand extends BasicCommand { String schemType = e.getSchemType(); if (schemType != null) { SchematicType schematicType = SchematicType.fromDB(schemType); - if (schematicType != null && schematicType.deadline() != null && now.isBefore(schematicType.deadline().toInstant())) { + if (schematicType != null && schematicType.getDeadline() != null && now.isBefore(schematicType.getDeadline().toInstant())) { Message.send("EVENT_COMING_SCHEM_DEADLINE", player, e.getDeadline()); } } diff --git a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java index e897ba0..5c9d589 100644 --- a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java +++ b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java @@ -20,7 +20,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; -import de.steamwar.bungeecore.sql.BauweltMember; +import de.steamwar.sql.BauweltMember; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; diff --git a/src/de/steamwar/bungeecore/commands/ReplayCommand.java b/src/de/steamwar/bungeecore/commands/ReplayCommand.java index ff012b9..86aca8f 100644 --- a/src/de/steamwar/bungeecore/commands/ReplayCommand.java +++ b/src/de/steamwar/bungeecore/commands/ReplayCommand.java @@ -25,7 +25,7 @@ import de.steamwar.bungeecore.inventory.SWListInv; import de.steamwar.bungeecore.inventory.SWStreamInv; import de.steamwar.bungeecore.sql.Fight; import de.steamwar.bungeecore.sql.Punishment; -import de.steamwar.bungeecore.sql.SchematicType; +import de.steamwar.sql.SchematicType; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.command.SWCommand; import de.steamwar.messages.ChatSender; diff --git a/src/de/steamwar/bungeecore/commands/TpCommand.java b/src/de/steamwar/bungeecore/commands/TpCommand.java index 7025b10..9b48eaa 100644 --- a/src/de/steamwar/bungeecore/commands/TpCommand.java +++ b/src/de/steamwar/bungeecore/commands/TpCommand.java @@ -20,7 +20,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; -import de.steamwar.bungeecore.sql.BauweltMember; +import de.steamwar.sql.BauweltMember; import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.Team; diff --git a/src/de/steamwar/bungeecore/listeners/CheckListener.java b/src/de/steamwar/bungeecore/listeners/CheckListener.java index 1370a0d..0f236d6 100644 --- a/src/de/steamwar/bungeecore/listeners/CheckListener.java +++ b/src/de/steamwar/bungeecore/listeners/CheckListener.java @@ -22,7 +22,7 @@ package de.steamwar.bungeecore.listeners; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.commands.CheckCommand; import de.steamwar.bungeecore.sql.SchematicNode; -import de.steamwar.bungeecore.sql.SchematicType; +import de.steamwar.sql.SchematicType; import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.PlayerDisconnectEvent; diff --git a/src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java index b6a3f6b..d6dc4a0 100644 --- a/src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java @@ -23,6 +23,7 @@ import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.sql.*; import de.steamwar.network.packets.PacketHandler; import de.steamwar.network.packets.common.FightEndsPacket; +import de.steamwar.sql.SchematicType; import lombok.RequiredArgsConstructor; import java.util.*; diff --git a/src/de/steamwar/bungeecore/network/handlers/PrepareSchemHandler.java b/src/de/steamwar/bungeecore/network/handlers/PrepareSchemHandler.java index c59c8df..2f25c44 100644 --- a/src/de/steamwar/bungeecore/network/handlers/PrepareSchemHandler.java +++ b/src/de/steamwar/bungeecore/network/handlers/PrepareSchemHandler.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.network.handlers; import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.ServerStarter; -import de.steamwar.bungeecore.sql.SchematicType; +import de.steamwar.sql.SchematicType; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.network.packets.PacketHandler; import de.steamwar.network.packets.client.PrepareSchemPacket; diff --git a/src/de/steamwar/bungeecore/sql/BauweltMember.java b/src/de/steamwar/bungeecore/sql/BauweltMember.java deleted file mode 100644 index 66222bf..0000000 --- a/src/de/steamwar/bungeecore/sql/BauweltMember.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.sql; - -import de.steamwar.sql.internal.Statement; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -public class BauweltMember{ - - private static final Statement delete = new Statement("DELETE FROM BauweltMember WHERE BauweltID = ? AND MemberID = ?"); - private static final Statement update = new Statement("INSERT INTO BauweltMember (BauweltID, MemberID, WorldEdit, World) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE WorldEdit = VALUES(WorldEdit), World = VALUES(World)"); - private static final Statement getMember = new Statement("SELECT * FROM BauweltMember WHERE BauweltID = ? AND MemberID = ?"); - private static final Statement getMembers = new Statement("SELECT * FROM BauweltMember WHERE BauweltID = ?"); - - private final int bauweltID; - private final int memberID; - private boolean worldEdit; - private boolean world; - - - private BauweltMember(int ownerID, int memberID, boolean worldEdit, boolean world, boolean updateDB){ - bauweltID = ownerID; - this.memberID = memberID; - this.worldEdit = worldEdit; - this.world = world; - if(updateDB) - updateDB(); - } - - public BauweltMember(int ownerID, int memberID, boolean worldEdit, boolean world){ - this(ownerID, memberID, worldEdit, world, true); - } - - public BauweltMember(UUID ownerID, UUID memberID, boolean worldEdit, boolean world){ - this(SteamwarUser.get(ownerID).getId(), SteamwarUser.get(memberID).getId(), worldEdit, world); - } - - public void remove(){ - delete.update(bauweltID, memberID); - } - - private void updateDB(){ - update.update(bauweltID, memberID, worldEdit, world); - } - - public static BauweltMember getBauMember(UUID ownerID, UUID memberID){ - return getBauMember(SteamwarUser.get(ownerID).getId(), SteamwarUser.get(memberID).getId()); - } - - public static BauweltMember getBauMember(int ownerID, int memberID){ - return getMember.select(rs -> { - if(!rs.next()) - return null; - - return new BauweltMember(ownerID, memberID, rs.getBoolean("WorldEdit"), rs.getBoolean("World"), false); - }, ownerID, memberID); - } - - public static List getMembers(UUID bauweltID){ - return getMembers(SteamwarUser.get(bauweltID).getId()); - } - - public static List getMembers(int bauweltID){ - return getMembers.select(rs -> { - List members = new ArrayList<>(); - while(rs.next()){ - members.add(new BauweltMember(bauweltID, rs.getInt("MemberID"), rs.getBoolean("WorldEdit"), rs.getBoolean("World"), false)); - } - return members; - }, bauweltID); - } - - public int getBauweltID() { - return bauweltID; - } - - public int getMemberID() { - return memberID; - } - - public boolean isWorldEdit() { - return worldEdit; - } - - public void setWorldEdit(boolean worldEdit) { - this.worldEdit = worldEdit; - updateDB(); - } - - public boolean isWorld() { - return world; - } - - public void setWorld(boolean world) { - this.world = world; - updateDB(); - } -} diff --git a/src/de/steamwar/bungeecore/sql/Fight.java b/src/de/steamwar/bungeecore/sql/Fight.java index 463dee7..7de3de0 100644 --- a/src/de/steamwar/bungeecore/sql/Fight.java +++ b/src/de/steamwar/bungeecore/sql/Fight.java @@ -20,6 +20,7 @@ package de.steamwar.bungeecore.sql; import de.steamwar.sql.FightPlayer; +import de.steamwar.sql.SchematicType; import de.steamwar.sql.internal.Statement; import de.steamwar.bungeecore.ArenaMode; @@ -91,8 +92,8 @@ public class Fight { return fights; } - public de.steamwar.bungeecore.sql.SchematicType getSchemType() { - return de.steamwar.bungeecore.sql.SchematicType.fromDB(gameMode); + public SchematicType getSchemType() { + return SchematicType.fromDB(gameMode); } public ArenaMode getGameMode() { diff --git a/src/de/steamwar/bungeecore/sql/SchematicNode.java b/src/de/steamwar/bungeecore/sql/SchematicNode.java index 66a9183..9c91c02 100644 --- a/src/de/steamwar/bungeecore/sql/SchematicNode.java +++ b/src/de/steamwar/bungeecore/sql/SchematicNode.java @@ -20,6 +20,7 @@ package de.steamwar.bungeecore.sql; +import de.steamwar.sql.SchematicType; import de.steamwar.sql.internal.Statement; import java.io.InputStream; diff --git a/src/de/steamwar/bungeecore/sql/SchematicType.java b/src/de/steamwar/bungeecore/sql/SchematicType.java deleted file mode 100644 index 9592070..0000000 --- a/src/de/steamwar/bungeecore/sql/SchematicType.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.sql; - -import de.steamwar.bungeecore.commands.CheckCommand; -import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.config.Configuration; -import net.md_5.bungee.config.ConfigurationProvider; -import net.md_5.bungee.config.YamlConfiguration; - -import java.io.File; -import java.io.IOException; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.*; - -public class SchematicType { - public static final SchematicType Normal = new SchematicType("Normal", "", null, Type.NORMAL, null, null); //Has to stay publicly availible - - private static final Map fromDB; - private static final Map fightType; - private static final List types; - - static { - File folder = new File(ProxyServer.getInstance().getPluginsFolder(), "FightSystem"); - - List tmpTypes = new LinkedList<>(); - Map tmpFromDB = new HashMap<>(); - Map tmpFightType = new HashMap<>(); - - tmpTypes.add(Normal); - tmpFromDB.put(Normal.name().toLowerCase(), Normal); - - if(folder.exists()) { - for(File configFile : folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))) { - Configuration config; - try { - config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile); - } catch (IOException e) { - throw new SecurityException("Could not load SchematicTypes", e); - } - - if(!config.contains("Schematic")) - continue; - - String type = config.getString("Schematic.Type"); - assert type != null; - String shortcut = config.getString("Schematic.Shortcut"); - if(tmpFromDB.containsKey(type.toLowerCase())) - continue; - - String material = config.getString("Schematic.Material"); - - SchematicType checktype = null; - if(!config.getStringList("CheckQuestions").isEmpty()) { - checktype = new SchematicType("C" + type, "C" + shortcut, material, Type.CHECK_TYPE, null, null); - tmpTypes.add(checktype); - tmpFromDB.put(checktype.toDB(), checktype); - CheckCommand.setCheckQuestions(checktype, config); - } - - Date deadline; - String deadlineString = config.getString("deadline", null); - if (deadlineString != null) { - try { - SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm"); - deadline = dateFormat.parse(deadlineString); - } catch (ParseException e) { - throw new SecurityException(e.getMessage(), e); - } - } else { - deadline = null; - } - - SchematicType current = new SchematicType(type, shortcut, material, config.getKeys().contains("Server") ? Type.FIGHT_TYPE : Type.NORMAL, checktype, deadline); - if(checktype != null) - tmpFightType.put(checktype, current); - tmpFromDB.put(type.toLowerCase(), current); - } - } - - fromDB = Collections.unmodifiableMap(tmpFromDB); - fightType = Collections.unmodifiableMap(tmpFightType); - types = Collections.unmodifiableList(tmpTypes); - } - - private final String name; - private final String kuerzel; - private final String material; - private final Type type; - private final SchematicType checkType; - private final Date deadline; - - private SchematicType(String name, String kuerzel, String material, Type type, SchematicType checkType, Date deadline){ - this.name = name; - this.kuerzel = kuerzel; - this.material = material != null && !"".equals(material) ? material : "STONE_BUTTON"; - this.type = type; - this.checkType = checkType; - this.deadline = deadline; - } - - public boolean isAssignable(){ - return type == Type.NORMAL || (type == Type.FIGHT_TYPE && checkType != null); - } - - public SchematicType checkType(){ - return checkType; - } - - public SchematicType fightType(){ - return fightType.get(this); - } - - public boolean check(){ - return type == Type.CHECK_TYPE; - } - - public boolean fight(){ - return type == Type.FIGHT_TYPE; - } - - public boolean writeable(){ - return type == Type.NORMAL; - } - - public String name(){ - return name; - } - - public String getMaterial() { - return material; - } - - public String getKuerzel() { - return kuerzel; - } - - public String toDB(){ - return name.toLowerCase(); - } - - public Date deadline() { - return deadline; - } - - public static SchematicType fromDB(String input){ - return fromDB.getOrDefault(input.toLowerCase(), null); - } - - public static List values(){ - return types; - } - - enum Type{ - NORMAL, - CHECK_TYPE, - FIGHT_TYPE - } -} diff --git a/src/de/steamwar/sql/SQLWrapperImpl.java b/src/de/steamwar/sql/SQLWrapperImpl.java index f564ff2..176dfd4 100644 --- a/src/de/steamwar/sql/SQLWrapperImpl.java +++ b/src/de/steamwar/sql/SQLWrapperImpl.java @@ -20,6 +20,7 @@ package de.steamwar.sql; import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.commands.CheckCommand; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -29,12 +30,28 @@ import net.md_5.bungee.config.YamlConfiguration; import java.io.File; import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.Arrays; +import java.util.Date; import java.util.List; import java.util.Map; import java.util.stream.Collectors; public class SQLWrapperImpl implements SQLWrapper { + + private static final SimpleDateFormat deadlineFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm"); + private static Date parseDeadline(String deadline) { + if(deadline == null) + return null; + + try { + return deadlineFormat.parse(deadline); + } catch (ParseException e) { + throw new SecurityException(e.getMessage(), e); + } + } + @Override public void loadSchemTypes(List tmpTypes, Map tmpFromDB) { File folder = new File(BungeeCore.get().getDataFolder().getParentFile(), "FightSystem"); @@ -63,11 +80,14 @@ public class SQLWrapperImpl implements SQLWrapper { checktype = new SchematicType("C" + type, "C" + shortcut, SchematicType.Type.CHECK_TYPE, null, material); tmpTypes.add(checktype); tmpFromDB.put(checktype.toDB(), checktype); + CheckCommand.setCheckQuestions(checktype, config); } - SchematicType current = new SchematicType(type, shortcut, !config.contains("Server") ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material); + SchematicType current = new SchematicType(type, shortcut, !config.contains("Server") ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material, parseDeadline(config.getString("deadline", null))); tmpTypes.add(current); tmpFromDB.put(type.toLowerCase(), current); + if(checktype != null) + CheckCommand.addFightType(checktype, current); } } }