Implement CheckCommand for Checkers not having Check perm

This commit is contained in:
2026-06-17 10:47:23 +02:00
parent 256bcfb1bf
commit 73d4ed26c8
4 changed files with 46 additions and 92 deletions
@@ -151,7 +151,7 @@ public final class GameModeConfig<M, W> {
* *
* @implSpec {@code []} by default -> denoting every person with {@link UserPerm#CHECK} can check it * @implSpec {@code []} by default -> denoting every person with {@link UserPerm#CHECK} can check it
*/ */
public final List<Integer> Checkers; public final Set<Integer> Checkers;
/** /**
* Bundle for countdowns during the fight * Bundle for countdowns during the fight
@@ -246,7 +246,7 @@ public final class GameModeConfig<M, W> {
} }
CheckQuestions = loader.getStringList("CheckQuestions"); CheckQuestions = loader.getStringList("CheckQuestions");
Checkers = loader.getIntList("Checkers"); Checkers = loader.getIntSet("Checkers");
Times = new TimesConfig(loader.with("Times")); Times = new TimesConfig(loader.with("Times"));
// Arena would be here to be in config order but needs Schematic.Size and EnterStages loaded afterwards // Arena would be here to be in config order but needs Schematic.Size and EnterStages loaded afterwards
Schematic = new SchematicConfig<>(loader.with("Schematic")); Schematic = new SchematicConfig<>(loader.with("Schematic"));
@@ -139,6 +139,12 @@ final class YMLWrapper<M, W> {
return get(path, o -> (List<Integer>) o); return get(path, o -> (List<Integer>) o);
} }
public Set<Integer> getIntSet(String path) {
List<Integer> list = get(path, o -> (List<Integer>) o);
if (list.isEmpty()) return Collections.emptySet();
return Collections.unmodifiableSet(new HashSet<>(list));
}
public List<SchematicType> getSchematicTypeList(String path) { public List<SchematicType> getSchematicTypeList(String path) {
List<String> list = getStringList(path); List<String> list = getStringList(path);
if (list.isEmpty()) { if (list.isEmpty()) {
@@ -72,80 +72,79 @@ public class CheckCommand extends SWCommand {
public CheckCommand() { public CheckCommand() {
super("check"); super("check");
VelocityCore.schedule(() -> Chatter.allStream().forEach(CheckCommand::sendReminder)).repeat(10, TimeUnit.MINUTES).schedule();
VelocityCore.schedule(() -> sendReminder(Chatter.allStream())).repeat(10, TimeUnit.MINUTES).schedule();
} }
@Override @Override
protected boolean hasPermission(SimpleCommand.Invocation invocation) { protected boolean hasPermission(SimpleCommand.Invocation invocation) {
return mayCheck(Chatter.of(invocation.source()).user()); SteamwarUser user = Chatter.of(invocation.source()).user();
}
private boolean mayCheck(SteamwarUser user) {
if (user.perms().contains(UserPerm.CHECK)) return true; if (user.perms().contains(UserPerm.CHECK)) return true;
return GameModeConfig.getAll() return GameModeConfig.getAll()
.stream() .stream()
.filter(GameModeConfig::isActive) .filter(GameModeConfig::isActive)
.flatMap(gameMode -> gameMode.Checkers.stream()) .anyMatch(gameMode -> gameMode.Checkers.contains(user.getId()));
.anyMatch(integer -> integer == user.getId());
} }
private boolean hasThingsToCheck(SteamwarUser user) { private static Map<SchematicNode, SteamwarUser> getSchematics(SteamwarUser user) {
return getSchemsToCheck().stream().anyMatch(schematicNode -> mayCheck(user, schematicNode)); Map<SchematicNode, SteamwarUser> 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<String, String> gameModeConfig = ArenaMode.getBySchemType(schematic.getSchemtype()); GameModeConfig<String, String> gameModeConfig = ArenaMode.getBySchemType(schematic.getSchemtype());
if (gameModeConfig == null) gameModeConfig = GameModeConfig.getDefaults(); if (gameModeConfig == null) gameModeConfig = GameModeConfig.getDefaults();
if (user.hasPerm(UserPerm.ADMINISTRATION)) return true;
if (gameModeConfig.Checkers.isEmpty() && user.hasPerm(UserPerm.CHECK)) return true; if (gameModeConfig.Checkers.isEmpty() && user.hasPerm(UserPerm.CHECK)) return true;
return gameModeConfig.Checkers.contains(user.getId()); return gameModeConfig.Checkers.contains(user.getId());
} }
private boolean needsCheck(SchematicNode schematicNode) {
return currentSchems.containsKey(schematicNode.getId());
}
public static void sendReminder(Chatter chatter) { public static void sendReminder(Chatter chatter) {
List<SchematicNode> schematics = getSchemsToCheck(); Map<SchematicNode, SteamwarUser> schematics = getSchematics(chatter.user());
if (schematics.size() == currentCheckers.size()) return; 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") @Register(value = "list", description = "CHECK_HELP_LIST")
public void list(Chatter sender) { public void list(Chatter sender) {
List<SchematicNode> schematicList = getSchemsToCheck(); Map<SchematicNode, SteamwarUser> schematics = getSchematics(sender.user());
sender.system("CHECK_LIST_HEADER", schematicList.size()); sender.system("CHECK_LIST_HEADER", schematics.size());
for (SchematicNode schematic : schematicList) { for (Map.Entry<SchematicNode, SteamwarUser> entry : schematics.entrySet()) {
GameModeConfig<String, String> gameModeConfig = ArenaMode.getBySchemType(schematic.getSchemtype()); ClickEvent clickEvent;
if (gameModeConfig == null) gameModeConfig = GameModeConfig.getDefaults(); Message hoverMessage;
CheckSession current = currentSchems.get(schematic.getId()); if (entry.getValue() == null) {
ClickEvent clickEvent = null; clickEvent = ClickEvent.runCommand("/check schematic " + entry.getKey().getId());
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"); hoverMessage = new Message("CHECK_LIST_TO_CHECK_HOVER");
} else { } else {
clickEvent = ClickEvent.runCommand("/join " + current.checker.user().getUserName()); clickEvent = ClickEvent.runCommand("/join " + entry.getValue().getUserName());
hoverMessage = new Message("CHECK_LIST_CHECKING_HOVER"); hoverMessage = new Message("CHECK_LIST_CHECKING_HOVER");
} }
}
if (current == null) { if (entry.getValue() == null) {
sender.prefixless("CHECK_LIST_TO_CHECK", sender.prefixless("CHECK_LIST_TO_CHECK",
hoverMessage, hoverMessage,
clickEvent, clickEvent,
getWaitTime(schematic), getWaitTime(entry.getKey()),
schematic.getSchemtype().getKuerzel(), SteamwarUser.byId(schematic.getOwner()).getUserName(), schematic.getName()); entry.getKey().getSchemtype().getKuerzel(), SteamwarUser.byId(entry.getKey().getOwner()).getUserName(), entry.getKey().getName());
} else { } else {
sender.prefixless("CHECK_LIST_CHECKING", sender.prefixless("CHECK_LIST_CHECKING",
hoverMessage, hoverMessage,
clickEvent, clickEvent,
getWaitTime(schematic), getWaitTime(entry.getKey()),
schematic.getSchemtype().getKuerzel(), SteamwarUser.byId(schematic.getOwner()).getUserName(), schematic.getName(), current.checker.user().getUserName()); entry.getKey().getSchemtype().getKuerzel(), SteamwarUser.byId(entry.getKey().getOwner()).getUserName(), entry.getKey().getName(), entry.getValue().getUserName());
} }
} }
} }
@@ -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 <https://www.gnu.org/licenses/>.
*/
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<SchematicNode> getSchemsToCheck() {
List<SchematicNode> schematicList = new ArrayList<>();
for (SchematicType type : SchematicType.values()) {
if (type.check()) {
schematicList.addAll(SchematicNode.getAllSchematicsOfType(type));
}
}
return schematicList;
}
}