Add investigation state handling for CheckedSchematic

This commit is contained in:
2025-05-31 22:44:40 +02:00
parent c30f24ab8f
commit 9ba8a83a3b
6 changed files with 61 additions and 15 deletions
@@ -28,13 +28,16 @@ import lombok.Getter;
import java.sql.Timestamp;
import java.util.List;
import java.util.Optional;
@AllArgsConstructor
public class CheckedSchematic {
public static final String INVESTIGATION_PENDING_KEY = "$invest:";
private static final Table<CheckedSchematic> table = new Table<>(CheckedSchematic.class);
private static final SelectStatement<CheckedSchematic> statusOfNode = new SelectStatement<>(table, "SELECT * FROM CheckedSchematic WHERE NodeId = ? AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC");
private static final SelectStatement<CheckedSchematic> nodeHistory = new SelectStatement<>(table, "SELECT * FROM CheckedSchematic WHERE NodeId = ? AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC");
private static final SelectStatement<CheckedSchematic> statusOfNode = new SelectStatement<>(table, "SELECT * FROM CheckedSchematic WHERE NodeId = ? AND DeclineReason != 'Prüfvorgang abgebrochen' AND DeclineReason NOT LIKE '" + INVESTIGATION_PENDING_KEY + "%' ORDER BY EndTime DESC");
private static final SelectStatement<CheckedSchematic> lastCheck = new SelectStatement<>(table, "SELECT * FROM CheckedSchematic WHERE NodeId = ? AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC LIMIT 1");
private static final Statement insert = table.insertAll();
public static void create(int nodeId, String name, int owner, int validator, Timestamp startTime, Timestamp endTime, String reason){
@@ -45,12 +48,16 @@ public class CheckedSchematic {
create(node.getId(), node.getName(), node.getOwner(), validator, startTime, endTime, reason);
}
public static void createInvestigationPending(SchematicNode node, Timestamp startTime, Timestamp endTime, int validator, String reason){
create(node, validator, startTime, endTime, INVESTIGATION_PENDING_KEY + reason);
}
public static List<CheckedSchematic> getLastDeclinedOfNode(int node){
return statusOfNode.listSelect(node);
}
public static List<CheckedSchematic> previousChecks(SchematicNode node) {
return nodeHistory.listSelect(node.getId());
public static Optional<CheckedSchematic> getLastCheck(int node){
return Optional.ofNullable(lastCheck.select(node));
}
@Field(nullable = true)
@@ -83,4 +90,20 @@ public class CheckedSchematic {
public int getSchemOwner() {
return nodeOwner;
}
public boolean isInvestigationPending() {
return declineReason.startsWith(INVESTIGATION_PENDING_KEY);
}
public String getInvestigationPendingReason() {
return declineReason.substring(INVESTIGATION_PENDING_KEY.length());
}
public Optional<CheckedSchematic> castToUserSafe() {
if (isInvestigationPending()) {
return Optional.empty();
} else {
return Optional.of(this);
}
}
}
@@ -107,7 +107,7 @@ public class GUI {
if(node.getOwner() == user.getId()){
if(!node.isDir() && node.getSchemtype().writeable()){
CheckedSchematic.getLastDeclinedOfNode(node.getId()).stream().findFirst().ifPresent(checkedSchematic ->
CheckedSchematic.getLastCheck(node.getId()).flatMap(CheckedSchematic::castToUserSafe).ifPresent(checkedSchematic ->
inv.setItem(1, SWItem.getDye(10), (byte) 10, SchematicSystem.MESSAGE.parse("GUI_INFO_STATUS", player, node.getSchemtype().name()), Collections.singletonList(SchematicSystem.MESSAGE.parse("GUI_INFO_STATUS_LORE", player, checkedSchematic.getDeclineReason().replaceAll("&", "§"))), false, click -> {}));
}
Material mat = SWItem.getMaterial(node.getItem());
@@ -246,7 +246,7 @@ public class SchematicCommandUtils {
}
SchematicSystem.MESSAGE.sendPrefixless("UTIL_INFO_FORMAT", player, node.getFileEnding());
CheckedSchematic.getLastDeclinedOfNode(node.getId()).stream().findFirst().ifPresent(checkedSchematic -> SchematicSystem.MESSAGE.sendPrefixless("UTIL_INFO_STATUS", player, checkedSchematic.getEndTime(), checkedSchematic.getDeclineReason()));
CheckedSchematic.getLastCheck(node.getId()).flatMap(CheckedSchematic::castToUserSafe).ifPresent(checkedSchematic -> SchematicSystem.MESSAGE.sendPrefixless("UTIL_INFO_STATUS", player, checkedSchematic.getEndTime(), checkedSchematic.getDeclineReason()));
} else {
SchematicSystem.MESSAGE.sendPrefixless("UTIL_INFO_TYPE", player, SchematicSystem.MESSAGE.parse("UTIL_INFO_TYPE_DIR", player));
}
@@ -319,6 +319,7 @@ CHECK_LIST_CHECKING_HOVER=§eTo the reviewer
CHECK_SCHEMATIC_ALREADY_CHECKING=§cYou are already reviewing a schematic!
CHECK_SCHEMATIC_OWN=§cYou cannot review your own schematics.
CHECK_SCHEMATIC_OWN_TEAM=§cYou cannot review your team schematics.
CHECK_SCHEMATIC_INVESTIGATION_PENDING=§cThis schematic is currently under investigation
CHECK_SCHEMATIC_PREVIOUS=§7{0} from {1}§8: §e{2}
CHECK_INVALID_RANK=§cUnknown schematic rank.
CHECK_ABORT=§aThe test operation was canceled!
@@ -301,6 +301,7 @@ CHECK_LIST_CHECKING_HOVER=§eZum Prüfer
CHECK_SCHEMATIC_ALREADY_CHECKING=§cDu prüfst schon eine Schematic!
CHECK_SCHEMATIC_OWN=§cDu kannst nicht deine eigenen Schematics prüfen.
CHECK_SCHEMATIC_OWN_TEAM=§cDu kannst nicht Schematics deines Teams prüfen.
CHECK_SCHEMATIC_INVESTIGATION_PENDING=§cDiese Schematic wird grade untersucht!
CHECK_SCHEMATIC_PREVIOUS=§7{0} von {1}§8: §e{2}
CHECK_INVALID_RANK=§cUnbekannter Schematicrang.
CHECK_ABORT=§aDer Prüfvorgang wurde abgebrochen!
@@ -98,11 +98,12 @@ public class CheckCommand extends SWCommand {
for (SchematicNode schematic : schematicList) {
CheckSession current = currentSchems.get(schematic.getId());
if (current == null) {
Optional<CheckedSchematic> lastCheck = CheckedSchematic.getLastCheck(schematic.getId());
sender.prefixless("CHECK_LIST_TO_CHECK",
new Message("CHECK_LIST_TO_CHECK_HOVER"),
ClickEvent.runCommand("/check schematic " + schematic.getId()),
lastCheck.map(CheckedSchematic::isInvestigationPending).orElse(false) ? new Message("PLAIN_STRING", lastCheck.map(CheckedSchematic::getInvestigationPendingReason).orElseThrow()) : new Message("CHECK_LIST_TO_CHECK_HOVER"),
!lastCheck.map(CheckedSchematic::isInvestigationPending).orElse(false) || sender.user().hasPerm(UserPerm.MODERATION) ? ClickEvent.runCommand("/check schematic " + schematic.getId()) : ClickEvent.suggestCommand(""),
getWaitTime(schematic),
schematic.getSchemtype().getKuerzel(), SteamwarUser.get(schematic.getOwner()).getUserName(), schematic.getName());
schematic.getSchemtype().getKuerzel(), SteamwarUser.get(schematic.getOwner()).getUserName(), (lastCheck.map(CheckedSchematic::isInvestigationPending).orElse(false) ? "§c" : "") + schematic.getName());
} else {
sender.prefixless("CHECK_LIST_CHECKING",
new Message("CHECK_LIST_CHECKING_HOVER"),
@@ -128,6 +129,10 @@ public class CheckCommand extends SWCommand {
sender.system("CHECK_SCHEMATIC_OWN");
return;
}
Optional<CheckedSchematic> lastCheck = CheckedSchematic.getLastCheck(schem.getId());
if(!lastCheck.map(CheckedSchematic::isInvestigationPending).orElse(false) || sender.user().hasPerm(UserPerm.MODERATION)) {
sender.system("CHECK_SCHEMATIC_INVESTIGATION_PENDING");
}
int playerTeam = sender.user().hasPerm(UserPerm.MODERATION) ? 0 : sender.user().getTeam();
if (playerTeam != 0 && SteamwarUser.get(schem.getOwner()).getTeam() == playerTeam) {
@@ -172,6 +177,14 @@ public class CheckCommand extends SWCommand {
currentCheckers.get(sender.getPlayer().getUniqueId()).decline(String.join(" ", message));
}
@Register(value = "block")
public void block(PlayerChatter sender, String... message) {
if(notChecking(sender.getPlayer()))
return;
currentCheckers.get(sender.getPlayer().getUniqueId()).block(String.join(" ", message));
}
public static List<SchematicNode> getSchemsToCheck(){
List<SchematicNode> schematicList = new ArrayList<>();
@@ -212,7 +225,7 @@ public class CheckCommand extends SWCommand {
currentCheckers.put(checker.user().getUUID(), this);
currentSchems.put(schematic.getId(), this);
for(CheckedSchematic previous : CheckedSchematic.previousChecks(schematic))
for(CheckedSchematic previous : CheckedSchematic.getLastDeclinedOfNode(schematic.getId()))
checker.prefixless("CHECK_SCHEMATIC_PREVIOUS", previous.getEndTime(), SteamwarUser.get(previous.getValidator()).getUserName(), previous.getDeclineReason());
next();
}).start();
@@ -237,7 +250,7 @@ public class CheckCommand extends SWCommand {
}
private void accept(){
if(concludeCheckSession("freigegeben", fightTypes.get(schematic.getSchemtype()))) {
if(concludeCheckSession("freigegeben", fightTypes.get(schematic.getSchemtype()), false)) {
Chatter owner = Chatter.of(SteamwarUser.get(schematic.getOwner()).getUUID());
owner.withPlayerOrOffline(
player -> owner.system("CHECK_ACCEPTED", schematic.getSchemtype().name(), schematic.getName()),
@@ -248,7 +261,7 @@ public class CheckCommand extends SWCommand {
}
private void decline(String reason){
if(concludeCheckSession(reason, SchematicType.Normal)) {
if(concludeCheckSession(reason, SchematicType.Normal, false)) {
Chatter owner = Chatter.of(SteamwarUser.get(schematic.getOwner()).getUUID());
owner.withPlayerOrOffline(
player -> owner.system("CHECK_DECLINED", schematic.getSchemtype().name(), schematic.getName(), reason),
@@ -264,14 +277,18 @@ public class CheckCommand extends SWCommand {
}
private void abort(){
concludeCheckSession("Prüfvorgang abgebrochen", null);
concludeCheckSession("Prüfvorgang abgebrochen", null, false);
}
private boolean concludeCheckSession(String reason, SchematicType type) {
private boolean concludeCheckSession(String reason, SchematicType type, boolean investigation) {
boolean exists = SchematicNode.getSchematicNode(schematic.getId()) != null;
if(exists) {
CheckedSchematic.create(schematic, checker.user().getId(), startTime, Timestamp.from(Instant.now()), reason);
if (investigation) {
CheckedSchematic.createInvestigationPending(schematic, startTime, Timestamp.from(Instant.now()), checker.user().getId(), reason);
} else {
CheckedSchematic.create(schematic, checker.user().getId(), startTime, Timestamp.from(Instant.now()), reason);
}
if(type != null)
schematic.setSchemtype(type);
}
@@ -289,5 +306,9 @@ public class CheckCommand extends SWCommand {
currentCheckers.remove(checker.user().getUUID());
currentSchems.remove(schematic.getId());
}
public void block(String reason) {
concludeCheckSession(reason, null, true);
}
}
}