From c9a82832c04b7ed70349658eea8ee7b0b25c5943 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 1 Nov 2021 12:34:21 +0100 Subject: [PATCH] Remove deprecated APIs --- .../de/steamwar/core/VersionedCallable.java | 51 ------------------- .../de/steamwar/core/VersionedRunnable.java | 45 ---------------- .../src/de/steamwar/sql/BauweltMember.java | 44 ++-------------- .../src/de/steamwar/sql/CheckedSchematic.java | 28 +--------- .../src/de/steamwar/sql/Fight.java | 22 -------- .../src/de/steamwar/sql/PersonalKit.java | 12 ----- 6 files changed, 7 insertions(+), 195 deletions(-) delete mode 100644 SpigotCore_Main/src/de/steamwar/core/VersionedCallable.java delete mode 100644 SpigotCore_Main/src/de/steamwar/core/VersionedRunnable.java diff --git a/SpigotCore_Main/src/de/steamwar/core/VersionedCallable.java b/SpigotCore_Main/src/de/steamwar/core/VersionedCallable.java deleted file mode 100644 index 0da1b6f..0000000 --- a/SpigotCore_Main/src/de/steamwar/core/VersionedCallable.java +++ /dev/null @@ -1,51 +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.core; - -import java.util.concurrent.Callable; - -public class VersionedCallable { - - private Callable callable; - private int minVersion; - - public VersionedCallable(Callable callable, int minVersion) { - this.callable = callable; - this.minVersion = minVersion; - } - - @Deprecated - public static T call(VersionedCallable... versionedCallables) { - for (int i = versionedCallables.length - 1; i >= 0; i--) { - VersionedCallable versionedCallable = versionedCallables[i]; - if (Core.getVersion() >= versionedCallable.minVersion) { - try { - return versionedCallable.callable.call(); - } catch (Exception e) { - throw new RuntimeException("Could not run version dependent code", e); - } - } - } - throw new SecurityException(); - } - -} diff --git a/SpigotCore_Main/src/de/steamwar/core/VersionedRunnable.java b/SpigotCore_Main/src/de/steamwar/core/VersionedRunnable.java deleted file mode 100644 index 604169a..0000000 --- a/SpigotCore_Main/src/de/steamwar/core/VersionedRunnable.java +++ /dev/null @@ -1,45 +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.core; - -public class VersionedRunnable { - - private Runnable runnable; - private int minVersion; - - public VersionedRunnable(Runnable runnable, int minVersion) { - this.runnable = runnable; - this.minVersion = minVersion; - } - - @Deprecated - public static void call(VersionedRunnable... versionedRunnables) { - for (int i = versionedRunnables.length - 1; i >= 0; i--) { - VersionedRunnable versionedRunnable = versionedRunnables[i]; - if (Core.getVersion() >= versionedRunnable.minVersion) { - versionedRunnable.runnable.run(); - return; - } - } - } - -} diff --git a/SpigotCore_Main/src/de/steamwar/sql/BauweltMember.java b/SpigotCore_Main/src/de/steamwar/sql/BauweltMember.java index 273f1ce..31a7ed0 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/BauweltMember.java +++ b/SpigotCore_Main/src/de/steamwar/sql/BauweltMember.java @@ -30,8 +30,8 @@ public class BauweltMember{ private final int bauweltID; private final int memberID; - private boolean worldEdit; - private boolean world; + private final boolean worldEdit; + private final boolean world; private static final List members = new ArrayList<>(); @@ -39,36 +39,14 @@ public class BauweltMember{ members.clear(); } - private BauweltMember(int ownerID, int memberID, boolean worldEdit, boolean world, boolean updateDB){ + private BauweltMember(int ownerID, int memberID, boolean worldEdit, boolean world) { bauweltID = ownerID; this.memberID = memberID; this.worldEdit = worldEdit; this.world = world; - if(updateDB) - updateDB(); members.add(this); } - 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, true); - } - - @Deprecated - public void remove(){ - SQL.update("DELETE FROM BauweltMember WHERE BauweltID = ? AND MemberID = ?", bauweltID, memberID); - members.remove(this); - } - - @Deprecated - private void updateDB(){ - SQL.update("INSERT INTO BauweltMember (BauweltID, MemberID, WorldEdit, World) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE WorldEdit = VALUES(WorldEdit), World = VALUES(World)", - bauweltID, memberID, worldEdit, world); - } - public static BauweltMember getBauMember(UUID ownerID, UUID memberID){ return getBauMember(SteamwarUser.get(ownerID).getId(), SteamwarUser.get(memberID).getId()); } @@ -80,7 +58,7 @@ public class BauweltMember{ return getMember.select(rs -> { if(!rs.next()) return null; - return new BauweltMember(ownerID, memberID, rs.getBoolean("WorldEdit"), rs.getBoolean("World"), false); + return new BauweltMember(ownerID, memberID, rs.getBoolean("WorldEdit"), rs.getBoolean("World")); }, ownerID, memberID); } @@ -92,7 +70,7 @@ public class BauweltMember{ 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)); + members.add(new BauweltMember(bauweltID, rs.getInt("MemberID"), rs.getBoolean("WorldEdit"), rs.getBoolean("World"))); return members; }, bauweltID); } @@ -109,19 +87,7 @@ public class BauweltMember{ return worldEdit; } - @Deprecated - public void setWorldEdit(boolean worldEdit) { - this.worldEdit = worldEdit; - updateDB(); - } - public boolean isWorld() { return world; } - - @Deprecated - public void setWorld(boolean world) { - this.world = world; - updateDB(); - } } diff --git a/SpigotCore_Main/src/de/steamwar/sql/CheckedSchematic.java b/SpigotCore_Main/src/de/steamwar/sql/CheckedSchematic.java index db8df93..e3f31cc 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/CheckedSchematic.java +++ b/SpigotCore_Main/src/de/steamwar/sql/CheckedSchematic.java @@ -36,32 +36,13 @@ public class CheckedSchematic { private final Timestamp endTime; private final String declineReason; - private CheckedSchematic(String schemName, int schemOwner, int validator, Timestamp startTime, Timestamp endTime, String declineReason, boolean insertDB){ + private CheckedSchematic(String schemName, int schemOwner, int validator, Timestamp startTime, Timestamp endTime, String declineReason){ this.schemName = schemName; this.schemOwner = schemOwner; this.validator = validator; this.startTime = startTime; this.endTime = endTime; this.declineReason = declineReason; - if(insertDB) - insertDB(); - } - - @Deprecated - public CheckedSchematic(String schemName, int schemOwner, int validator, Timestamp startTime, Timestamp endTime, String declineReason){ - this(schemName, schemOwner, validator, startTime, endTime, declineReason, true); - } - - @Deprecated - public CheckedSchematic(String schemName, UUID schemOwner, UUID validator, Timestamp startTime, Timestamp endTime, String declineReason){ - this(schemName, SteamwarUser.get(schemOwner).getId(), SteamwarUser.get(validator).getId(), startTime, endTime, declineReason, true); - } - - @Deprecated - private void insertDB(){ - SQL.update("INSERT INTO CheckedSchematic" + - " (SchemName, SchemOwner, Validator, StartTime, EndTime, DeclineReason) VALUES (?, ?, ?, ?, ?, ?)", - schemName, schemOwner, validator, startTime, endTime, declineReason); } public static List getLastDeclined(UUID schemOwner){ @@ -72,16 +53,11 @@ public class CheckedSchematic { return checkHistory.select(rs -> { List history = new ArrayList<>(); while(rs.next()) - history.add(new CheckedSchematic(rs.getString("SchemName"), schemOwner, rs.getInt("Validator"), rs.getTimestamp("StartTime"), rs.getTimestamp("EndTime"), rs.getString("DeclineReason"), false)); + history.add(new CheckedSchematic(rs.getString("SchemName"), schemOwner, rs.getInt("Validator"), rs.getTimestamp("StartTime"), rs.getTimestamp("EndTime"), rs.getString("DeclineReason"))); return history; }, schemOwner); } - @Deprecated - public void remove() { - SQL.update("DELETE FROM CheckedSchematic WHERE SchemOwner = ? AND SchemName = ?", schemOwner, schemName); - } - public String getSchemName() { return schemName; } diff --git a/SpigotCore_Main/src/de/steamwar/sql/Fight.java b/SpigotCore_Main/src/de/steamwar/sql/Fight.java index aa3b54b..584d17e 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/Fight.java +++ b/SpigotCore_Main/src/de/steamwar/sql/Fight.java @@ -20,8 +20,6 @@ package de.steamwar.sql; import java.io.InputStream; -import java.sql.Blob; -import java.sql.SQLException; import java.sql.Timestamp; import java.util.function.Consumer; @@ -45,15 +43,6 @@ public class Fight { }); } - @Deprecated - public static InputStream getReplay(int fightID) { - return getReplay.select(rs -> { - rs.next(); - Blob replay = rs.getBlob("Replay"); - return replay.getBinaryStream(); - }, fightID); - } - public static void getReplay(int fightID, Consumer reader) { getReplay.select(rs -> { rs.next(); @@ -62,17 +51,6 @@ public class Fight { }, fightID); } - @Deprecated - public static void setReplay(int fightID, byte[] data) { - Blob blob = SQL.blob(); - try { - blob.setBytes(1, data); - } catch (SQLException e) { - throw new SecurityException(e); - } - setReplay.update(blob, fightID); - } - public static void setReplay(int fightID, InputStream data) { setReplay.update(data, fightID); } diff --git a/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java b/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java index f66d07b..b4f0f41 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java +++ b/SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java @@ -90,18 +90,6 @@ public class PersonalKit { }, userID, gamemode); } - @Deprecated - public static boolean nameInUse(int userID, String gamemode, String name) { - ResultSet set = SQL.select("SELECT COUNT(*) AS Count FROM PersonalKit WHERE UserID = ? AND GameMode = ? AND Name = ?", userID, gamemode, name); - try { - if(!set.next()) - return true; - return set.getInt("Count") > 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]);