forked from SteamWar/SteamWar
PR Stuff
This commit is contained in:
@@ -40,20 +40,8 @@ public class CheckedSchematic {
|
||||
private static final SelectStatement<CheckedSchematic> getUnseen = new SelectStatement<>(table, "SELECT * FROM CheckedSchematic WHERE Seen = 0 AND NodeOwner = ? ORDER BY StartTime DESC");
|
||||
private static final Statement updateSeen = new Statement("UPDATE CheckedSchematic SET Seen = ? WHERE StartTime = ? AND EndTime = ? AND NodeName = ?");
|
||||
|
||||
public static void create(int nodeId, String name, int owner, int validator, Timestamp startTime, Timestamp endTime, String reason, boolean seen, String nodeType) {
|
||||
insert.update(nodeId, owner, name, validator, startTime, endTime, reason, seen, nodeType);
|
||||
}
|
||||
|
||||
public static void create(int nodeId, String name, int owner, int validator, Timestamp startTime, Timestamp endTime, String reason, String nodeType) {
|
||||
create(nodeId, name, owner, validator, startTime, endTime, reason, true, nodeType);
|
||||
}
|
||||
|
||||
public static void create(SchematicNode node, int validator, Timestamp startTime, Timestamp endTime, String reason, boolean seen) {
|
||||
create(node.getId(), node.getName(), node.getOwner(), validator, startTime, endTime, reason, seen, node.getSchemtype().toDB());
|
||||
}
|
||||
|
||||
public static void create(SchematicNode node, int validator, Timestamp startTime, Timestamp endTime, String reason) {
|
||||
create(node.getId(), node.getName(), node.getOwner(), validator, startTime, endTime, reason, true, node.getSchemtype().toDB());
|
||||
insert.update(node.getId(), node.getName(), node.getOwner(), validator, startTime, endTime, reason, seen, node.getSchemtype().toDB());
|
||||
}
|
||||
|
||||
public static List<CheckedSchematic> getLastDeclinedOfNode(int node) {
|
||||
|
||||
@@ -85,14 +85,12 @@ public interface Chatter {
|
||||
else
|
||||
return withPlayer.apply(player);
|
||||
}
|
||||
default boolean withPlayerOrOffline(Consumer<Player> withPlayer, Runnable withOffline) {
|
||||
default void withPlayerOrOffline(Consumer<Player> withPlayer, Runnable withOffline) {
|
||||
Player player = getPlayer();
|
||||
if(player == null) {
|
||||
withOffline.run();
|
||||
return false;
|
||||
} else {
|
||||
withPlayer.accept(player);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
default void withPlayer(Consumer<Player> function) {
|
||||
|
||||
@@ -41,7 +41,7 @@ import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class CheckCommand extends SWCommand {
|
||||
@@ -240,26 +240,26 @@ public class CheckCommand extends SWCommand {
|
||||
private void accept(){
|
||||
concludeCheckSession("freigegeben", fightTypes.get(schematic.getSchemtype()), () -> {
|
||||
Chatter owner = Chatter.of(SteamwarUser.get(schematic.getOwner()).getUUID());
|
||||
boolean isOnline = owner.withPlayerOrOffline(
|
||||
owner.withPlayerOrOffline(
|
||||
player -> owner.system("CHECK_ACCEPTED", schematic.getSchemtype().name(), schematic.getName()),
|
||||
() -> DiscordAlert.send(owner, Color.GREEN, new Message("DC_TITLE_SCHEMINFO"), new Message("DC_SCHEM_ACCEPT", schematic.getName()), true)
|
||||
);
|
||||
notifyTeam(new Message("CHECK_ACCEPTED_TEAM", schematic.getName(), owner.user().getUserName()));
|
||||
|
||||
return isOnline;
|
||||
return owner.getPlayer() != null;
|
||||
});
|
||||
}
|
||||
|
||||
private void decline(String reason){
|
||||
concludeCheckSession(reason, SchematicType.Normal, () -> {
|
||||
Chatter owner = Chatter.of(SteamwarUser.get(schematic.getOwner()).getUUID());
|
||||
boolean isOnline = owner.withPlayerOrOffline(
|
||||
owner.withPlayerOrOffline(
|
||||
player -> owner.system("CHECK_DECLINED", schematic.getSchemtype().name(), schematic.getName(), reason),
|
||||
() -> DiscordAlert.send(owner, Color.RED, new Message("DC_TITLE_SCHEMINFO"), new Message("DC_SCHEM_DECLINE", schematic.getName(), reason), false)
|
||||
);
|
||||
notifyTeam(new Message("CHECK_DECLINED_TEAM", schematic.getName(), owner.user().getUserName(), reason));
|
||||
|
||||
return isOnline;
|
||||
return owner.getPlayer() != null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -272,9 +272,9 @@ public class CheckCommand extends SWCommand {
|
||||
concludeCheckSession("Prüfvorgang abgebrochen", null, () -> true);
|
||||
}
|
||||
|
||||
private void concludeCheckSession(String reason, SchematicType type, Supplier<Boolean> sendMessageIsOnline) {
|
||||
private void concludeCheckSession(String reason, SchematicType type, BooleanSupplier sendMessageIsOnline) {
|
||||
if(SchematicNode.getSchematicNode(schematic.getId()) != null) {
|
||||
CheckedSchematic.create(schematic, checker.user().getId(), startTime, Timestamp.from(Instant.now()), reason, sendMessageIsOnline.get());
|
||||
CheckedSchematic.create(schematic, checker.user().getId(), startTime, Timestamp.from(Instant.now()), reason, sendMessageIsOnline.getAsBoolean());
|
||||
if(type != null)
|
||||
schematic.setSchemtype(type);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user