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
@@ -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);
}
}
}