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
@@ -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<SchematicNode, SteamwarUser> getSchematics(SteamwarUser user) {
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());
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<SchematicNode> schematics = getSchemsToCheck();
if (schematics.size() == currentCheckers.size()) return;
Map<SchematicNode, SteamwarUser> 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<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) {
GameModeConfig<String, String> 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<SchematicNode, SteamwarUser> 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());
}
}
}
@@ -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;
}
}