diff --git a/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java b/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java index 51d6bf14..d22d8978 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java +++ b/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java @@ -151,7 +151,7 @@ public final class GameModeConfig { * * @implSpec {@code []} by default -> denoting every person with {@link UserPerm#CHECK} can check it */ - public final List Checkers; + public final Set Checkers; /** * Bundle for countdowns during the fight @@ -246,7 +246,7 @@ public final class GameModeConfig { } CheckQuestions = loader.getStringList("CheckQuestions"); - Checkers = loader.getIntList("Checkers"); + Checkers = loader.getIntSet("Checkers"); Times = new TimesConfig(loader.with("Times")); // Arena would be here to be in config order but needs Schematic.Size and EnterStages loaded afterwards Schematic = new SchematicConfig<>(loader.with("Schematic")); diff --git a/CommonCore/SQL/src/de/steamwar/sql/YMLWrapper.java b/CommonCore/SQL/src/de/steamwar/sql/YMLWrapper.java index 39eff9bb..567524ff 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/YMLWrapper.java +++ b/CommonCore/SQL/src/de/steamwar/sql/YMLWrapper.java @@ -139,6 +139,12 @@ final class YMLWrapper { return get(path, o -> (List) o); } + public Set getIntSet(String path) { + List list = get(path, o -> (List) o); + if (list.isEmpty()) return Collections.emptySet(); + return Collections.unmodifiableSet(new HashSet<>(list)); + } + public List getSchematicTypeList(String path) { List list = getStringList(path); if (list.isEmpty()) { diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java index 1b3aaa43..76be799e 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java @@ -72,80 +72,79 @@ public class CheckCommand extends SWCommand { public CheckCommand() { super("check"); - - VelocityCore.schedule(() -> sendReminder(Chatter.allStream())).repeat(10, TimeUnit.MINUTES).schedule(); + VelocityCore.schedule(() -> Chatter.allStream().forEach(CheckCommand::sendReminder)).repeat(10, TimeUnit.MINUTES).schedule(); } @Override protected boolean hasPermission(SimpleCommand.Invocation invocation) { - return mayCheck(Chatter.of(invocation.source()).user()); - } - - private boolean mayCheck(SteamwarUser user) { + SteamwarUser user = Chatter.of(invocation.source()).user(); if (user.perms().contains(UserPerm.CHECK)) return true; return GameModeConfig.getAll() .stream() .filter(GameModeConfig::isActive) - .flatMap(gameMode -> gameMode.Checkers.stream()) - .anyMatch(integer -> integer == user.getId()); + .anyMatch(gameMode -> gameMode.Checkers.contains(user.getId())); } - private boolean hasThingsToCheck(SteamwarUser user) { - return getSchemsToCheck().stream().anyMatch(schematicNode -> mayCheck(user, schematicNode)); + private static Map getSchematics(SteamwarUser user) { + Map map = new HashMap<>(); + for (SchematicNode schematicNode : getSchemsToCheck()) { + if (!mayCheck(user, schematicNode)) continue; + CheckSession checkSession = currentSchems.get(schematicNode.getId()); + if (checkSession == null) { + map.put(schematicNode, null); + } else { + map.put(schematicNode, checkSession.checker.user()); + } + } + return map; } - private boolean mayCheck(SteamwarUser user, SchematicNode schematic) { + private static boolean mayCheck(SteamwarUser user, SchematicNode schematic) { GameModeConfig gameModeConfig = ArenaMode.getBySchemType(schematic.getSchemtype()); if (gameModeConfig == null) gameModeConfig = GameModeConfig.getDefaults(); + if (user.hasPerm(UserPerm.ADMINISTRATION)) return true; if (gameModeConfig.Checkers.isEmpty() && user.hasPerm(UserPerm.CHECK)) return true; return gameModeConfig.Checkers.contains(user.getId()); } - private boolean needsCheck(SchematicNode schematicNode) { - return currentSchems.containsKey(schematicNode.getId()); - } - public static void sendReminder(Chatter chatter) { - List schematics = getSchemsToCheck(); - if (schematics.size() == currentCheckers.size()) return; + Map schematics = getSchematics(chatter.user()); + if (schematics.isEmpty()) return; + long needsChecking = schematics.entrySet().stream().filter(entry -> entry.getValue() == null).count(); + if (needsChecking == 0) return; - chatter.system("CHECK_REMINDER", new Message("CHECK_REMINDER_HOVER"), ClickEvent.runCommand("/check list"), schematics.size() - currentCheckers.size()); + chatter.system("CHECK_REMINDER", new Message("CHECK_REMINDER_HOVER"), ClickEvent.runCommand("/check list"), needsChecking); } @Register(value = "list", description = "CHECK_HELP_LIST") public void list(Chatter sender) { - List schematicList = getSchemsToCheck(); + Map schematics = getSchematics(sender.user()); - sender.system("CHECK_LIST_HEADER", schematicList.size()); + sender.system("CHECK_LIST_HEADER", schematics.size()); - for (SchematicNode schematic : schematicList) { - GameModeConfig gameModeConfig = ArenaMode.getBySchemType(schematic.getSchemtype()); - if (gameModeConfig == null) gameModeConfig = GameModeConfig.getDefaults(); - CheckSession current = currentSchems.get(schematic.getId()); - ClickEvent clickEvent = null; - Message hoverMessage = null; - if (gameModeConfig.Checkers.isEmpty() || gameModeConfig.Checkers.contains(sender.user().getId())) { - if (current == null) { - clickEvent = ClickEvent.runCommand("/check schematic " + schematic.getId()); - hoverMessage = new Message("CHECK_LIST_TO_CHECK_HOVER"); - } else { - clickEvent = ClickEvent.runCommand("/join " + current.checker.user().getUserName()); - hoverMessage = new Message("CHECK_LIST_CHECKING_HOVER"); - } + for (Map.Entry entry : schematics.entrySet()) { + ClickEvent clickEvent; + Message hoverMessage; + if (entry.getValue() == null) { + clickEvent = ClickEvent.runCommand("/check schematic " + entry.getKey().getId()); + hoverMessage = new Message("CHECK_LIST_TO_CHECK_HOVER"); + } else { + clickEvent = ClickEvent.runCommand("/join " + entry.getValue().getUserName()); + hoverMessage = new Message("CHECK_LIST_CHECKING_HOVER"); } - if (current == null) { + if (entry.getValue() == null) { sender.prefixless("CHECK_LIST_TO_CHECK", hoverMessage, clickEvent, - getWaitTime(schematic), - schematic.getSchemtype().getKuerzel(), SteamwarUser.byId(schematic.getOwner()).getUserName(), schematic.getName()); + getWaitTime(entry.getKey()), + entry.getKey().getSchemtype().getKuerzel(), SteamwarUser.byId(entry.getKey().getOwner()).getUserName(), entry.getKey().getName()); } else { sender.prefixless("CHECK_LIST_CHECKING", hoverMessage, clickEvent, - getWaitTime(schematic), - schematic.getSchemtype().getKuerzel(), SteamwarUser.byId(schematic.getOwner()).getUserName(), schematic.getName(), current.checker.user().getUserName()); + getWaitTime(entry.getKey()), + entry.getKey().getSchemtype().getKuerzel(), SteamwarUser.byId(entry.getKey().getOwner()).getUserName(), entry.getKey().getName(), entry.getValue().getUserName()); } } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand2.java b/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand2.java deleted file mode 100644 index e90043ef..00000000 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand2.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2026 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.velocitycore.commands; - -import com.velocitypowered.api.command.SimpleCommand; -import de.steamwar.command.SWCommand; -import de.steamwar.sql.SchematicNode; -import de.steamwar.sql.SchematicType; - -import java.util.ArrayList; -import java.util.List; - -public class CheckCommand2 extends SWCommand { - - public CheckCommand2() { - super("check"); - } - - @Override - protected boolean hasPermission(SimpleCommand.Invocation invocation) { - return false; // TODO: Implement! - } - - public static List getSchemsToCheck() { - List schematicList = new ArrayList<>(); - - for (SchematicType type : SchematicType.values()) { - if (type.check()) { - schematicList.addAll(SchematicNode.getAllSchematicsOfType(type)); - } - } - return schematicList; - } -}