Skip to content

Commit

Permalink
Improve the error checking mechanism for the ChestShopSign metadata…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
Feli499 committed Jan 6, 2024
1 parent 93cfe7d commit 2d073f7
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java
Expand Up @@ -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) {
Expand Down

0 comments on commit 2d073f7

Please sign in to comment.