From 362eb8b6bbd2db10bec0a77bde42bb771bf45f6c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 3 Mar 2023 20:37:37 +0100 Subject: [PATCH 01/23] Add feature disable --- src/de/steamwar/linkage/LinkageProcessor.java | 52 +++++++++++++++++-- src/de/steamwar/linkage/Linked.java | 1 + 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/de/steamwar/linkage/LinkageProcessor.java b/src/de/steamwar/linkage/LinkageProcessor.java index 488f9bf..29382a5 100644 --- a/src/de/steamwar/linkage/LinkageProcessor.java +++ b/src/de/steamwar/linkage/LinkageProcessor.java @@ -36,6 +36,7 @@ import javax.lang.model.element.VariableElement; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeMirror; import javax.tools.Diagnostic; +import javax.tools.StandardLocation; import java.io.*; import java.lang.annotation.Annotation; import java.nio.file.Files; @@ -56,6 +57,8 @@ public class LinkageProcessor extends AbstractProcessor { private String name; private String className; + private Set disabledFeatures = new HashSet<>(); + private Messager messager; private boolean processed = false; @@ -75,6 +78,7 @@ public class LinkageProcessor extends AbstractProcessor { className = "LinkageUtils"; mainClass(); + disabledFeatures(); } @SneakyThrows @@ -102,6 +106,18 @@ public class LinkageProcessor extends AbstractProcessor { } } + @SneakyThrows + private void disabledFeatures() { + File file = new File(System.getProperty("user.dir"), "disabled-features.txt"); + if (!file.exists()) return; + @Cleanup BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file))); + reader.lines() + .map(String::trim) + .filter(line -> !line.isEmpty()) + .filter(line -> !line.startsWith("#")) + .forEach(disabledFeatures::add); + } + @SneakyThrows @Override public boolean process(Set annotations, RoundEnvironment roundEnv) { @@ -111,9 +127,27 @@ public class LinkageProcessor extends AbstractProcessor { Writer writer = processingEnv.getFiler().createSourceFile("de.steamwar." + name + ".linkage.LinkageUtils").openWriter(); BuildPlan buildPlan = new BuildPlan("de.steamwar." + name + ".linkage", className); + Set disabledElements = new HashSet<>(); + Set elements = roundEnv.getElementsAnnotatedWith(Linked.class).stream() .filter(element -> element.getKind() == ElementKind.CLASS) .map(TypeElement.class::cast) + .peek(element -> { + String featureName = element.getAnnotation(Linked.class).feature(); + if (featureName.isEmpty()) { + String tempName = element.getQualifiedName().toString(); + if (tempName.contains(".features.")) { + tempName = tempName.substring(tempName.indexOf(".features.") + 10); + featureName = tempName.substring(0, tempName.indexOf('.')); + } else { + tempName = tempName.substring(0, tempName.lastIndexOf('.')); + featureName = tempName.substring(tempName.lastIndexOf('.') + 1); + } + } + if (disabledFeatures.contains(featureName) || disabledFeatures.contains("*")) { + disabledElements.add(element); + } + }) .peek(typeElement -> System.out.println("Found element: " + typeElement.getQualifiedName().toString())) .collect(Collectors.toSet()); @@ -147,8 +181,14 @@ public class LinkageProcessor extends AbstractProcessor { messager.printMessage(Diagnostic.Kind.ERROR, "Field " + variableElement.getSimpleName() + " must be non final", variableElement); continue; } - neededFields.put(typeElement.getQualifiedName().toString(), typeElement); TypeElement fieldType = (TypeElement) ((DeclaredType) variableElement.asType()).asElement(); + if (disabledElements.contains(fieldType)) { + continue; + } + if (disabledElements.contains(typeElement)) { + continue; + } + neededFields.put(typeElement.getQualifiedName().toString(), typeElement); neededFields.put(fieldType.getQualifiedName().toString(), fieldType); fieldInjections.add(() -> { @@ -159,6 +199,7 @@ public class LinkageProcessor extends AbstractProcessor { } } neededFields.forEach((s, typeElement) -> { + if (disabledElements.contains(typeElement)) return; buildPlan.addImport(typeElement.getQualifiedName().toString()); String t = typeElement.getSimpleName().toString(); t = t.substring(0, 1).toLowerCase() + t.substring(1); @@ -188,8 +229,13 @@ public class LinkageProcessor extends AbstractProcessor { return methodBuilder; }); - if (!entry.getKey().isEmpty()) method.addLine("if (" + String.join(" && ", entry.getKey()) + ") {"); + boolean generated = false; for (Map.Entry> toGenerate : group.getValue().entrySet()) { + if (disabledElements.contains(toGenerate.getKey())) continue; + if (!generated && !entry.getKey().isEmpty()) { + method.addLine("if (" + String.join(" && ", entry.getKey()) + ") {"); + generated = true; + } TypeElement typeElement = toGenerate.getKey(); String instance = getElement(typeElement, neededFields); if (toGenerate.getValue().size() > 1 && instance.startsWith("new ")) { @@ -202,7 +248,7 @@ public class LinkageProcessor extends AbstractProcessor { linkageType.generateCode(buildPlan, method, finalInstance, typeElement); }); } - if (!entry.getKey().isEmpty()) method.addLine("}"); + if (generated && !entry.getKey().isEmpty()) method.addLine("}"); } } diff --git a/src/de/steamwar/linkage/Linked.java b/src/de/steamwar/linkage/Linked.java index f3836e0..dbaf0eb 100644 --- a/src/de/steamwar/linkage/Linked.java +++ b/src/de/steamwar/linkage/Linked.java @@ -24,4 +24,5 @@ import java.lang.annotation.*; @Retention(RetentionPolicy.SOURCE) @Target({ElementType.TYPE}) public @interface Linked { + String feature() default ""; } From e4c2b05e4f7fc4dc89a3bd57eabad5c2faebbab4 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 7 Apr 2023 22:28:44 +0200 Subject: [PATCH 02/23] Add RequestSchematicSearchPacket --- .../packets/client/ImALobbyPacket.java | 1 - .../client/RequestSchematicSearchPacket.java | 39 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/de/steamwar/network/packets/client/RequestSchematicSearchPacket.java diff --git a/src/de/steamwar/network/packets/client/ImALobbyPacket.java b/src/de/steamwar/network/packets/client/ImALobbyPacket.java index d8e1ba4..dcd07dd 100644 --- a/src/de/steamwar/network/packets/client/ImALobbyPacket.java +++ b/src/de/steamwar/network/packets/client/ImALobbyPacket.java @@ -21,7 +21,6 @@ package de.steamwar.network.packets.client; import de.steamwar.network.packets.NetworkPacket; import lombok.EqualsAndHashCode; -import lombok.Getter; @EqualsAndHashCode(callSuper = true) public class ImALobbyPacket extends NetworkPacket { diff --git a/src/de/steamwar/network/packets/client/RequestSchematicSearchPacket.java b/src/de/steamwar/network/packets/client/RequestSchematicSearchPacket.java new file mode 100644 index 0000000..ea8420c --- /dev/null +++ b/src/de/steamwar/network/packets/client/RequestSchematicSearchPacket.java @@ -0,0 +1,39 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.network.packets.client; + +import de.steamwar.network.packets.NetworkPacket; +import lombok.*; + +@Builder +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +@Getter +public class RequestSchematicSearchPacket extends NetworkPacket { + private static final long serialVersionUID = -6525229932332581648L; + + private int playerId; + private int schematicId; + private boolean ignoreBlockData; + private boolean ignoreAir; + private boolean airAsAny; + +} From 4a6465953f1ba7ad3fbf4b0df73196d2ef2a0428 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 1 May 2023 11:19:00 +0200 Subject: [PATCH 03/23] Hotfix Season.getSeasonStart --- src/de/steamwar/sql/Season.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/sql/Season.java b/src/de/steamwar/sql/Season.java index 8768ad8..0044c25 100644 --- a/src/de/steamwar/sql/Season.java +++ b/src/de/steamwar/sql/Season.java @@ -32,7 +32,14 @@ public class Season { public static String getSeasonStart() { Calendar calendar = Calendar.getInstance(); - return calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) / 4 * 3 + 1) + "-1"; + int month = calendar.get(Calendar.MONTH); + if (month <= 4) { + return calendar.get(Calendar.YEAR) + "-1-1"; + } else if (month <= 8) { + return calendar.get(Calendar.YEAR) + "-5-1"; + } else { + return calendar.get(Calendar.YEAR) + "-9-1"; + } } public static String convertSeasonToString(int season){ From 5aca43b35e9b9fca5252ee107e3e0d08c3c9d7fa Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 1 May 2023 11:33:09 +0200 Subject: [PATCH 04/23] Hotfix Season.getSeasonStart --- src/de/steamwar/sql/Season.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/sql/Season.java b/src/de/steamwar/sql/Season.java index 0044c25..a713fe2 100644 --- a/src/de/steamwar/sql/Season.java +++ b/src/de/steamwar/sql/Season.java @@ -33,9 +33,9 @@ public class Season { public static String getSeasonStart() { Calendar calendar = Calendar.getInstance(); int month = calendar.get(Calendar.MONTH); - if (month <= 4) { + if (month <= 3) { return calendar.get(Calendar.YEAR) + "-1-1"; - } else if (month <= 8) { + } else if (month <= 7) { return calendar.get(Calendar.YEAR) + "-5-1"; } else { return calendar.get(Calendar.YEAR) + "-9-1"; From 59e397b826336dddf36727306aab4f6f96eaa5a4 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 3 May 2023 17:47:10 +0200 Subject: [PATCH 05/23] Better error handling --- src/de/steamwar/sql/internal/SqlTypeMapper.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/sql/internal/SqlTypeMapper.java b/src/de/steamwar/sql/internal/SqlTypeMapper.java index 34c6173..53a2cc2 100644 --- a/src/de/steamwar/sql/internal/SqlTypeMapper.java +++ b/src/de/steamwar/sql/internal/SqlTypeMapper.java @@ -32,7 +32,12 @@ public final class SqlTypeMapper { private static final Map, SqlTypeMapper> mappers = new IdentityHashMap<>(); public static SqlTypeMapper getMapper(Class clazz) { - return (SqlTypeMapper) mappers.get(clazz); + SqlTypeMapper result = (SqlTypeMapper) mappers.get(clazz); + + if(result == null) + throw new SecurityException("Unregistered mapper requested: " + clazz.getName()); + + return result; } public static > void ordinalEnumMapper(Class type) { From 229f74991e1643d4016b1e39f7e7fca1420df3c8 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 3 May 2023 17:50:27 +0200 Subject: [PATCH 06/23] Fix loading order --- src/de/steamwar/sql/Event.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/de/steamwar/sql/Event.java b/src/de/steamwar/sql/Event.java index 7985232..a853e13 100644 --- a/src/de/steamwar/sql/Event.java +++ b/src/de/steamwar/sql/Event.java @@ -32,6 +32,10 @@ import java.util.List; @AllArgsConstructor public class Event { + static { + SchematicType.Normal.name(); // Ensure SchematicType is loaded. + } + private static final Table table = new Table<>(Event.class); private static final SelectStatement byCurrent = new SelectStatement<>(table, "SELECT * FROM Event WHERE Start < now() AND End > now()"); From 97c38b64b3012daebcbd470ca08adf8a68f85e80 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 3 May 2023 17:52:21 +0200 Subject: [PATCH 07/23] Fix loading order --- src/de/steamwar/sql/SchematicNode.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/de/steamwar/sql/SchematicNode.java b/src/de/steamwar/sql/SchematicNode.java index 7bedbdc..6002739 100644 --- a/src/de/steamwar/sql/SchematicNode.java +++ b/src/de/steamwar/sql/SchematicNode.java @@ -20,9 +20,7 @@ package de.steamwar.sql; import de.steamwar.sql.internal.*; -import lombok.AccessLevel; import lombok.Getter; -import lombok.Setter; import java.sql.Timestamp; import java.time.Instant; @@ -32,6 +30,7 @@ import java.util.function.Predicate; public class SchematicNode { static { + SchematicType.Normal.name(); // Ensure SchematicType is loaded. new SqlTypeMapper<>(SchematicNode.class, null, (rs, identifier) -> { throw new SecurityException("SchematicNode cannot be used as type (recursive select)"); }, (st, index, value) -> st.setInt(index, value.nodeId)); } From a26e69e6f2a43d9890bce0a7f2549eb7ef6ab34e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 8 May 2023 16:31:11 +0200 Subject: [PATCH 08/23] Fix SchemDownload --- src/de/steamwar/sql/NodeDownload.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/sql/NodeDownload.java b/src/de/steamwar/sql/NodeDownload.java index 585b3db..666cf68 100644 --- a/src/de/steamwar/sql/NodeDownload.java +++ b/src/de/steamwar/sql/NodeDownload.java @@ -26,7 +26,7 @@ import lombok.AllArgsConstructor; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.security.Timestamp; +import java.sql.Timestamp; import java.time.Instant; @AllArgsConstructor From 0b274f288ff1218cb3eb5bded4064b3003b0344e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 10 May 2023 17:06:28 +0200 Subject: [PATCH 09/23] Add duration field to FightEndsPacket --- src/de/steamwar/network/packets/common/FightEndsPacket.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/de/steamwar/network/packets/common/FightEndsPacket.java b/src/de/steamwar/network/packets/common/FightEndsPacket.java index a970d7b..c1d86bb 100644 --- a/src/de/steamwar/network/packets/common/FightEndsPacket.java +++ b/src/de/steamwar/network/packets/common/FightEndsPacket.java @@ -38,4 +38,5 @@ public class FightEndsPacket extends NetworkPacket { private List bluePlayers; private List redPlayers; private String gameMode; + private int duration; } From 727a27a9fb855dfe022084ed3070b8cfc7f58cc1 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 11 May 2023 16:05:21 +0200 Subject: [PATCH 10/23] Update UserElo for new ranked system --- src/de/steamwar/sql/UserElo.java | 134 +++++++++++++++++-------------- 1 file changed, 72 insertions(+), 62 deletions(-) diff --git a/src/de/steamwar/sql/UserElo.java b/src/de/steamwar/sql/UserElo.java index 5de692c..c13c603 100644 --- a/src/de/steamwar/sql/UserElo.java +++ b/src/de/steamwar/sql/UserElo.java @@ -33,22 +33,18 @@ import java.util.concurrent.ConcurrentHashMap; @AllArgsConstructor public class UserElo { - private static final int ELO_DEFAULT = 1000; private static final Map>> gameModeUserEloCache = new ConcurrentHashMap<>(); - private static final Map maxEloCache = new ConcurrentHashMap<>(); private static final Map emblemCache = new ConcurrentHashMap<>(); public static void clear() { gameModeUserEloCache.clear(); - maxEloCache.clear(); emblemCache.clear(); } private static final Table table = new Table<>(UserElo.class); private static final SelectStatement getElo = table.select(Table.PRIMARY); private static final Statement setElo = table.insertAll(); - private static final Statement maxElo = new Statement("SELECT MAX(Elo) AS MaxElo FROM UserElo WHERE Season = ? AND GameMode = ?"); private static final Statement place = new Statement("SELECT COUNT(*) AS Place FROM UserElo WHERE GameMode = ? AND Elo > ? AND Season = ?"); private static final Statement fightsOfSeason = new Statement("SELECT COUNT(*) AS Fights FROM FightPlayer INNER JOIN Fight F on FightPlayer.FightID = F.FightID WHERE UserID = ? AND GameMode = ? AND UNIX_TIMESTAMP(StartTime) + Duration >= UNIX_TIMESTAMP(?)"); @@ -63,7 +59,7 @@ public class UserElo { private final int elo; public static int getEloOrDefault(int userID, String gameMode) { - return getElo(userID, gameMode).orElse(ELO_DEFAULT); + return getElo(userID, gameMode).orElse(0); } public static Optional getElo(int userID, String gameMode) { @@ -78,21 +74,13 @@ public class UserElo { }, userID, gameMode, Season.getSeasonStart()); } - private static int getMaxElo(String gameMode) { - return maxEloCache.computeIfAbsent(gameMode, gm -> maxElo.select(rs -> { - if (rs.next()) - return rs.getInt("MaxElo"); - return 0; - }, Season.getSeason(), gameMode)); - } - public static void setElo(int userId, String gameMode, int elo) { emblemCache.remove(userId); - Optional oldElo = Optional.ofNullable(gameModeUserEloCache.computeIfAbsent(gameMode, gm -> new HashMap<>()).put(userId, Optional.of(elo))).orElse(Optional.empty()); - int maxElo = getMaxElo(gameMode); - if (elo > maxElo || (oldElo.isPresent() && oldElo.get() == maxElo)) { - maxEloCache.remove(gameMode); + int oldPlacement = getPlacement(getElo(userId, gameMode).orElse(0), gameMode); + int newPlacement = getPlacement(elo, gameMode); + + if (oldPlacement <= 3 || newPlacement <= 3) { emblemCache.clear(); } @@ -109,70 +97,92 @@ public class UserElo { public static String getEmblem(SteamwarUser user, List rankedModes) { return emblemCache.computeIfAbsent(user.getId(), userId -> { - switch( - rankedModes.stream().filter( - mode -> UserElo.getFightsOfSeason(user.getId(), mode) >= 10 - ).map( - mode -> getProgression(user.getId(), mode) - ).max(Integer::compareTo).orElse(0) - ) { - case 0: - return ""; - case 1: - return "§7✧ "; - case 2: - return "§f✦ "; - case 3: - return "§e✶ "; - case 4: - return "§a✷ "; - case 5: - return "§b✸ "; - case 6: - return "§c✹ "; - case 7: - return "§5❂ "; - default: - throw new SecurityException("Progression out of range"); + int emblemProgression = -1; + for (String mode : rankedModes) { + if (UserElo.getFightsOfSeason(userId, mode) == 0) continue; + int progression = getProgression(userId, mode); + if (progression > emblemProgression) { + emblemProgression = progression; + } } + return toEmblem(emblemProgression); }); } public static String getEmblemProgression(String gameMode, int userId) { switch (getProgression(userId, gameMode)) { + case -1: + return "§f/ §6∨ ∧ §7∨ ∧ §e∨ ∧ §5❂ III II I"; case 0: - return "§8✧ ✦ ✶ ✷ ✸ ✹ ❂"; + return "§8/ §6∨ §8∧ ∨ ∧ ∨ ∧ ❂ III II I"; case 1: - return "§7✧ §8✦ ✶ ✷ ✸ ✹ ❂"; + return "§8/ ∨ §6∧ §8∨ ∧ ∨ ∧ ❂ III II I"; case 2: - return "§8✧ §f✦ §8✶ ✷ ✸ ✹ ❂"; + return "§8/ ∨ ∧ §7∨ §8∧ ∨ ∧ ❂ III II I"; case 3: - return "§8✧ ✦ §e✶ §8✷ ✸ ✹ ❂"; + return "§8/ ∨ ∧ ∨ §7∧ §8∨ ∧ ❂ III II I"; case 4: - return "§8✧ ✦ ✶ §a✷ §8✸ ✹ ❂"; + return "§8/ ∨ ∧ ∨ ∧ §e∨ §8∧ ❂ III II I"; case 5: - return "§8✧ ✦ ✶ ✷ §b✸ §8✹ ❂"; + return "§8/ ∨ ∧ ∨ ∧ ∨ §e∧ §8❂ III II I"; case 6: - return "§8✧ ✦ ✶ ✷ ✸ §c✹ §8❂"; + return "§8/ ∨ ∧ ∨ ∧ ∨ ∧ §5❂ §8III II I"; case 7: - return "§8✧ ✦ ✶ ✷ ✸ ✹ §5❂"; + return "§8/ ∨ ∧ ∨ ∧ ∨ ∧ ❂ §5III §8II I"; + case 8: + return "§8/ ∨ ∧ ∨ ∧ ∨ ∧ ❂ III §5II §8I"; + case 9: + return "§8/ ∨ ∧ ∨ ∧ ∨ ∧ ❂ III II §5I"; default: throw new SecurityException("Progression is not in range"); } } - private static int getProgression(int userId, String gameMode) { - int elo = getElo(userId, gameMode).orElse(0); - if(elo == 0) - return 0; - int maxElo = getMaxElo(gameMode); + public static int getProgression(int userId, String gameMode) { + int elo = getElo(userId, gameMode).orElse(-1); + if (elo < 0) return -1; - if (elo > maxElo * 0.99) return 7; - if (elo > maxElo * 0.97) return 6; - if (elo > maxElo * 0.94) return 5; - if (elo > maxElo * 0.88) return 4; - if (elo > maxElo * 0.76) return 3; - if (elo > maxElo * 0.51) return 2; - return 1; + if (elo <= 100) return 0; + if (elo <= 200) return 1; + if (elo <= 400) return 2; + if (elo <= 600) return 3; + if (elo <= 900) return 4; + if (elo <= 1200) return 5; + + int placement = getPlacement(elo, gameMode); + if (placement == 1) return 9; + if (placement == 2) return 8; + if (placement == 3) return 7; + + return 6; + } + + public static String toEmblem(int progression) { + switch(progression) { + case -1: + return ""; + case 0: + return "§6∨ "; + case 1: + return "§6∧ "; + case 2: + return "§7∨ "; + case 3: + return "§7∧ "; + case 4: + return "§e∨ "; + case 5: + return "§e∧ "; + case 6: + return "§5❂ "; + case 7: + return "§5III "; + case 8: + return "§5II "; + case 9: + return "§5I "; + default: + throw new SecurityException("Progression out of range"); + } } } From a8270a386cf2a6bf44bd27a5802d85c0cbcba331 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 12 May 2023 17:25:06 +0200 Subject: [PATCH 11/23] Add UserElo.ELO_DEFAULT --- src/de/steamwar/sql/UserElo.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/sql/UserElo.java b/src/de/steamwar/sql/UserElo.java index c13c603..30f2158 100644 --- a/src/de/steamwar/sql/UserElo.java +++ b/src/de/steamwar/sql/UserElo.java @@ -34,6 +34,8 @@ import java.util.concurrent.ConcurrentHashMap; @AllArgsConstructor public class UserElo { + private static final int ELO_DEFAULT = 0; + private static final Map>> gameModeUserEloCache = new ConcurrentHashMap<>(); private static final Map emblemCache = new ConcurrentHashMap<>(); @@ -59,7 +61,7 @@ public class UserElo { private final int elo; public static int getEloOrDefault(int userID, String gameMode) { - return getElo(userID, gameMode).orElse(0); + return getElo(userID, gameMode).orElse(ELO_DEFAULT); } public static Optional getElo(int userID, String gameMode) { From 92f32e410b566a77fed123e1faa42eddcdbd0e0d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 12 May 2023 23:36:20 +0200 Subject: [PATCH 12/23] Update some more stuff --- src/de/steamwar/sql/UserElo.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/sql/UserElo.java b/src/de/steamwar/sql/UserElo.java index 30f2158..2413232 100644 --- a/src/de/steamwar/sql/UserElo.java +++ b/src/de/steamwar/sql/UserElo.java @@ -83,6 +83,7 @@ public class UserElo { int newPlacement = getPlacement(elo, gameMode); if (oldPlacement <= 3 || newPlacement <= 3) { + gameModeUserEloCache.getOrDefault(gameMode, new HashMap<>()).remove(userId); emblemCache.clear(); } @@ -114,7 +115,7 @@ public class UserElo { public static String getEmblemProgression(String gameMode, int userId) { switch (getProgression(userId, gameMode)) { case -1: - return "§f/ §6∨ ∧ §7∨ ∧ §e∨ ∧ §5❂ III II I"; + return "§f/ §8∨ ∧ ∨ ∧ ∨ ∧ ❂ III II I"; case 0: return "§8/ §6∨ §8∧ ∨ ∧ ∨ ∧ ❂ III II I"; case 1: From 5ca6d9f4a46ea440b0ca9fe6083c9e6c593206d1 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 12 May 2023 23:40:05 +0200 Subject: [PATCH 13/23] Update to use Collections.emptyMap() --- src/de/steamwar/sql/UserElo.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/de/steamwar/sql/UserElo.java b/src/de/steamwar/sql/UserElo.java index 2413232..3c3467c 100644 --- a/src/de/steamwar/sql/UserElo.java +++ b/src/de/steamwar/sql/UserElo.java @@ -25,10 +25,7 @@ import de.steamwar.sql.internal.Statement; import de.steamwar.sql.internal.Table; import lombok.AllArgsConstructor; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; @AllArgsConstructor @@ -83,7 +80,7 @@ public class UserElo { int newPlacement = getPlacement(elo, gameMode); if (oldPlacement <= 3 || newPlacement <= 3) { - gameModeUserEloCache.getOrDefault(gameMode, new HashMap<>()).remove(userId); + gameModeUserEloCache.getOrDefault(gameMode, Collections.emptyMap()).remove(userId); emblemCache.clear(); } From a2bb52ab263d518dd6d103ee41ba06bf3bce7f45 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 13 May 2023 16:00:54 +0200 Subject: [PATCH 14/23] Fix another thing --- src/de/steamwar/sql/UserElo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/sql/UserElo.java b/src/de/steamwar/sql/UserElo.java index 3c3467c..235fc30 100644 --- a/src/de/steamwar/sql/UserElo.java +++ b/src/de/steamwar/sql/UserElo.java @@ -79,8 +79,8 @@ public class UserElo { int oldPlacement = getPlacement(getElo(userId, gameMode).orElse(0), gameMode); int newPlacement = getPlacement(elo, gameMode); + gameModeUserEloCache.getOrDefault(gameMode, Collections.emptyMap()).remove(userId); if (oldPlacement <= 3 || newPlacement <= 3) { - gameModeUserEloCache.getOrDefault(gameMode, Collections.emptyMap()).remove(userId); emblemCache.clear(); } From b4ce9493d13a171eebdbe1c8dae95275e099f2fa Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 18 May 2023 08:43:33 +0200 Subject: [PATCH 15/23] Add Script SQL-Type --- src/de/steamwar/sql/Script.java | 90 +++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/de/steamwar/sql/Script.java diff --git a/src/de/steamwar/sql/Script.java b/src/de/steamwar/sql/Script.java new file mode 100644 index 0000000..c66fb80 --- /dev/null +++ b/src/de/steamwar/sql/Script.java @@ -0,0 +1,90 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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 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; + +@AllArgsConstructor +@Getter +public class Script { + + private static final Table