From 2d073f79ddf2c688515f6ec9626bf294f09f7783 Mon Sep 17 00:00:00 2001 From: Maik E Date: Sun, 7 Jan 2024 00:31:16 +0100 Subject: [PATCH] Improve the error checking mechanism for the `ChestShopSign` metadata handling by introducing a validation layer. This layer will delay the metadata saving task, allowing the system to verify its correctness before execution, hence improving data integrity. The async task is scheduled with a one tick delay to ensure a smoother operation even under potential exceptions. --- .../ChestShop/Signs/ChestShopSign.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java b/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java index f3236ef9f..599161ac8 100644 --- a/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java +++ b/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java @@ -171,18 +171,20 @@ public static ChestShopMetaData getChestShopMetaData(Sign sign) { public static void saveChestShopMetaData(Sign sign, ChestShopMetaData chestShopMetaData) { - try { + Bukkit.getScheduler().scheduleSyncDelayedTask(ChestShop.getPlugin(), () -> { + try { - YamlConfiguration yamlConfiguration = new YamlConfiguration(); - yamlConfiguration.set("metadata", chestShopMetaData); + YamlConfiguration yamlConfiguration = new YamlConfiguration(); + yamlConfiguration.set("metadata", chestShopMetaData); - String string = yamlConfiguration.saveToString(); - sign.getPersistentDataContainer().set(METADATA_NAMESPACED_KEY, PersistentDataType.STRING, string); - sign.update(); + String string = yamlConfiguration.saveToString(); + sign.getPersistentDataContainer().set(METADATA_NAMESPACED_KEY, PersistentDataType.STRING, string); + sign.update(); - } catch (Exception e) { - Bukkit.getLogger().log(Level.WARNING, "Exception saving Chestshop Metadata (" + sign.getX() + " " + sign.getY() + " " + sign.getZ() + ").", e); - } + } catch (Exception e) { + Bukkit.getLogger().log(Level.WARNING, "Exception saving Chestshop Metadata (" + sign.getX() + " " + sign.getY() + " " + sign.getZ() + ").", e); + } + }, 1L); } public static boolean isValidPreparedSign(String[] lines) {