From 917d674f21cbe0927bce3202bfe04fb31e215b87 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 30 May 2022 11:56:19 +0200 Subject: [PATCH] =?UTF-8?q?Add=20deadline=20to=20autopr=C3=BCfer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../schematicsystem/CheckSchemType.java | 26 +++++++++++++++++++ .../commands/SchematicCommandUtils.java | 8 +++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemType.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemType.java index 9af5cee..257c466 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemType.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemType.java @@ -30,6 +30,10 @@ import org.bukkit.configuration.file.YamlConfiguration; import java.io.File; import java.io.IOException; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.Instant; import java.util.*; import java.util.logging.Level; @@ -45,6 +49,8 @@ public class CheckSchemType { private final Map, Integer> limits; private final int maxBlocks; + private final Date deadline; + private CheckSchemType(ConfigurationSection section) { String name = section.getString("Schematic.Type"); width = section.getInt("Schematic.Size.x"); @@ -65,6 +71,18 @@ public class CheckSchemType { } } + String deadlineString = section.getString("deadline", null); + if (deadlineString != null) { + try { + SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm"); + deadline = dateFormat.parse(deadlineString); + } catch (ParseException e) { + throw new SecurityException(e.getMessage(), e); + } + } else { + deadline = null; + } + types.put(SchematicType.fromDB(name.toLowerCase()), this); types.put(SchematicType.fromDB("c" + name.toLowerCase()), this); } @@ -126,6 +144,14 @@ public class CheckSchemType { return new HashMap<>(limits); } + public boolean isAfterDeadline() { + return deadline != null && deadline.before(Date.from(Instant.now())); + } + + public String getDeadline() { + return DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.GERMAN).format(deadline); + } + public static final ICheckSchemType impl = VersionDependent.getVersionImpl(SchematicSystem.getInstance()); diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java index ea92be3..b5fc0e9 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java @@ -392,7 +392,13 @@ public class SchematicCommandUtils { return; } - AutoCheckResult result = CheckSchemType.get(type).autoCheck(node); + CheckSchemType checkSchemType = CheckSchemType.get(type); + if (checkSchemType.isAfterDeadline()) { + player.sendMessage("§cVon diesem Typen können keine Schematics mehr eingesendet werden. Einsendeschluss war: " + checkSchemType.getDeadline()); + return; + } + + AutoCheckResult result = checkSchemType.autoCheck(node); Collection errors = result.errors(); for (String warning : result.warnings()) { player.sendMessage(" §e" + warning);