Update CheckCommand

This commit is contained in:
2026-05-22 16:01:01 +02:00
parent 28ce288815
commit 256bcfb1bf
4 changed files with 91 additions and 6 deletions
@@ -146,7 +146,7 @@ public final class GameModeConfig<M, W> {
public final List<String> CheckQuestions;
/**
* The allowed checkers to check this schematic type denoted by a list of SteamWar ids.
* The allowed checkers to check this schematic type denoted by a list of SteamwarUser ids.
* The people need the {@link UserPerm#CHECK} to be able to check though.
*
* @implSpec {@code []} by default -> denoting every person with {@link UserPerm#CHECK} can check it
@@ -20,6 +20,7 @@
package de.steamwar.command;
import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.command.SimpleCommand.Invocation;
import de.steamwar.messages.Chatter;
import de.steamwar.messages.Message;
import de.steamwar.sql.UserPerm;
@@ -91,11 +92,15 @@ public class SWCommand extends AbstractSWCommand<Chatter> {
@Override
public boolean hasPermission(Invocation invocation) {
return permission == null || Chatter.of(invocation.source()).user().perms().contains(permission);
return SWCommand.this.hasPermission(invocation);
}
};
}
protected boolean hasPermission(Invocation invocation) {
return permission == null || Chatter.of(invocation.source()).user().perms().contains(permission);
}
@Override
public void unregister() {
if (command == null) return;
@@ -19,6 +19,7 @@
package de.steamwar.velocitycore.commands;
import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ServerConnection;
import de.steamwar.command.SWCommand;
@@ -70,9 +71,38 @@ public class CheckCommand extends SWCommand {
}
public CheckCommand() {
super("check", UserPerm.CHECK);
super("check");
VelocityCore.schedule(() -> sendReminder(Chatter.serverteam())).repeat(10, TimeUnit.MINUTES).schedule();
VelocityCore.schedule(() -> sendReminder(Chatter.allStream())).repeat(10, TimeUnit.MINUTES).schedule();
}
@Override
protected boolean hasPermission(SimpleCommand.Invocation invocation) {
return mayCheck(Chatter.of(invocation.source()).user());
}
private boolean mayCheck(SteamwarUser 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());
}
private boolean hasThingsToCheck(SteamwarUser user) {
return getSchemsToCheck().stream().anyMatch(schematicNode -> mayCheck(user, schematicNode));
}
private boolean mayCheck(SteamwarUser user, SchematicNode schematic) {
GameModeConfig<String, String> gameModeConfig = ArenaMode.getBySchemType(schematic.getSchemtype());
if (gameModeConfig == null) gameModeConfig = GameModeConfig.getDefaults();
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) {
@@ -142,8 +172,7 @@ public class CheckCommand extends SWCommand {
}
int playerTeam = sender.user().hasPerm(UserPerm.MODERATION) ? 0 : sender.user().getTeam();
// Ignore 795 SteamWar Team
if (playerTeam != 0 && playerTeam != 795 && SteamwarUser.byId(schem.getOwner()).getTeam() == playerTeam) {
if (playerTeam != 0 && SteamwarUser.byId(schem.getOwner()).getTeam() == playerTeam) {
sender.system("CHECK_SCHEMATIC_OWN_TEAM");
return;
}
@@ -0,0 +1,51 @@
/*
* 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;
}
}