From 615b7b54d6ea5440d6ad5b443d05b909d7c61972 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 3 Jul 2022 12:18:57 +0200 Subject: [PATCH 1/2] Add SchematicNode.getElo --- .../src/de/steamwar/sql/Provider.java | 1 + .../src/de/steamwar/sql/SQLProvider.java | 11 ++++ .../src/de/steamwar/sql/SchematicNode.java | 8 +++ .../src/de/steamwar/sql/Season.java | 54 +++++++++++++++++++ .../de/steamwar/sql/StandaloneProvider.java | 5 ++ 5 files changed, 79 insertions(+) create mode 100644 SpigotCore_Main/src/de/steamwar/sql/Season.java diff --git a/SpigotCore_Main/src/de/steamwar/sql/Provider.java b/SpigotCore_Main/src/de/steamwar/sql/Provider.java index 686c491..b511a03 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/Provider.java +++ b/SpigotCore_Main/src/de/steamwar/sql/Provider.java @@ -103,4 +103,5 @@ public interface Provider { void deleteSchematicNode(SchematicNode node); InputStream getSchematicData(SchematicNode node) throws IOException; void saveSchematicNode(SchematicNode node, InputStream blob, boolean newFormat); + int getSchematicElo(SchematicNode node, int season); } diff --git a/SpigotCore_Main/src/de/steamwar/sql/SQLProvider.java b/SpigotCore_Main/src/de/steamwar/sql/SQLProvider.java index b1dfe51..ce1da9a 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SQLProvider.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SQLProvider.java @@ -413,6 +413,7 @@ public class SQLProvider implements Provider { private static final Statement updateDatabase = new Statement("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?"); private static final Statement selSchemData = new Statement("SELECT NodeData FROM SchematicNode WHERE NodeId = ?"); private static final Statement deleteNode = new Statement("DELETE FROM SchematicNode WHERE NodeId = ?"); + private static final Statement schemElo = new Statement("SELECT Elo FROM SchemElo WHERE SchemId = ? AND Season = ?"); private static final Statement.ResultSetUser> toSchematicList = rs -> { List nodes = new ArrayList<>(); @@ -627,4 +628,14 @@ public class SQLProvider implements Provider { public void saveSchematicNode(SchematicNode node, InputStream blob, boolean newFormat) { updateDatabase.update(blob, newFormat, node.getId()); } + + @Override + public int getSchematicElo(SchematicNode node, int season) { + return schemElo.select(rs -> { + if(rs.next()) { + return rs.getInt("Elo"); + } + return 0; + }, node.getId(), season); + } } diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java index a18f87a..eea35b4 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java @@ -521,4 +521,12 @@ public class SchematicNode { this.allowReplay = allowReplay; updateDB(); } + + public int getElo(int season) { + if (isDir) { + return 0; + } else { + return Provider.impl.getSchematicElo(this, season); + } + } } diff --git a/SpigotCore_Main/src/de/steamwar/sql/Season.java b/SpigotCore_Main/src/de/steamwar/sql/Season.java new file mode 100644 index 0000000..8768ad8 --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/sql/Season.java @@ -0,0 +1,54 @@ +/* + * 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.sql; + +import java.util.Calendar; + +public class Season { + private Season() {} + + public static int getSeason() { + Calendar calendar = Calendar.getInstance(); + int yearIndex = calendar.get(Calendar.MONTH) / 4; + return (calendar.get(Calendar.YEAR) * 3 + yearIndex); + } + + public static String getSeasonStart() { + Calendar calendar = Calendar.getInstance(); + return calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) / 4 * 3 + 1) + "-1"; + } + + public static String convertSeasonToString(int season){ + if (season == -1) return ""; + int yearSeason = season % 3; + int year = (season - yearSeason) / 3; + return String.format("%d-%d", year, yearSeason); + } + + public static int convertSeasonToNumber(String season){ + if (season.isEmpty()) return -1; + String[] split = season.split("-"); + try { + return Integer.parseInt(split[0]) * 3 + Integer.parseInt(split[1]); + } catch (NumberFormatException e) { + return -1; + } + } +} diff --git a/SpigotCore_Main/src/de/steamwar/sql/StandaloneProvider.java b/SpigotCore_Main/src/de/steamwar/sql/StandaloneProvider.java index b5924e8..0a9b3f7 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/StandaloneProvider.java +++ b/SpigotCore_Main/src/de/steamwar/sql/StandaloneProvider.java @@ -406,4 +406,9 @@ public class StandaloneProvider implements Provider { throw new SecurityException(e); } } + + @Override + public int getSchematicElo(SchematicNode node, int season) { + return 0; + } } From d17bcaf0bc1557abd4da5e29fcfd46b0f77f7016 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 3 Jul 2022 12:21:14 +0200 Subject: [PATCH 2/2] Update SchematicNode.getElo --- SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java index eea35b4..cadf8fd 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java @@ -523,10 +523,6 @@ public class SchematicNode { } public int getElo(int season) { - if (isDir) { - return 0; - } else { - return Provider.impl.getSchematicElo(this, season); - } + return Provider.impl.getSchematicElo(this, season); } }