From 0bfadad222ab9ebb356cd9e7e135121dc38e1d79 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Wed, 1 Mar 2023 10:02:27 -0600 Subject: [PATCH] Reload IA on change option (Legacy IA hook option) --- .../com/hibiscusmc/hmccosmetics/config/Settings.java | 11 +++++++++++ .../hmccosmetics/hooks/items/HookItemAdder.java | 5 ++--- common/src/main/resources/config.yml | 5 +++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Settings.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Settings.java index fb31b4a0..6251e593 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Settings.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Settings.java @@ -32,6 +32,9 @@ public class Settings { private static final String UNAPPLY_DEATH_PATH = "unapply-on-death"; private static final String FORCE_PERMISSION_JOIN_PATH = "force-permission-join"; private static final String EMOTE_DISTANCE_PATH = "emote-distance"; + private static final String HOOK_SETTING_PATH = "hook-settings"; + private static final String HOOK_ITEMADDER_PATH = "itemsadder"; + private static final String HOOK_RELOAD_CHANGE_PATH = "reload-on-change"; private static String defaultMenu; private static String dyeMenuName; @@ -46,6 +49,7 @@ public class Settings { private static boolean debugMode; private static boolean unapplyOnDeath; private static boolean forcePermissionJoin; + private static boolean itemsAdderChangeReload; private static int lookDownPitch; private static int viewDistance; private static int tickPeriod; @@ -91,6 +95,10 @@ public class Settings { dyeMenuName = dyeMenuSettings.node(DYE_MENU_NAME).getString("Dye Menu"); dyeMenuInputSlot = dyeMenuSettings.node(DYE_MENU_INPUT_SLOT).getInt(19); dyeMenuOutputSlot = dyeMenuSettings.node(DYE_MENU_OUTPUT_SLOT).getInt(25); + + ConfigurationNode hookSettings = source.node(HOOK_SETTING_PATH); + ConfigurationNode itemsAdderSettings = hookSettings.node(HOOK_ITEMADDER_PATH); + itemsAdderChangeReload = itemsAdderSettings.node(HOOK_RELOAD_CHANGE_PATH).getBoolean(false); } private static Vector loadVector(final ConfigurationNode config) { @@ -190,6 +198,9 @@ public class Settings { public static boolean isDebugEnabled() { return debugMode; } + public static boolean getItemsAdderReloadChange() { + return itemsAdderChangeReload; + } public static int getTickPeriod() { return tickPeriod; diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/items/HookItemAdder.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/items/HookItemAdder.java index bf37f3d8..441d9c2d 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/items/HookItemAdder.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/items/HookItemAdder.java @@ -1,6 +1,7 @@ package com.hibiscusmc.hmccosmetics.hooks.items; import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin; +import com.hibiscusmc.hmccosmetics.config.Settings; import com.hibiscusmc.hmccosmetics.hooks.Hook; import dev.lone.itemsadder.api.CustomStack; import dev.lone.itemsadder.api.Events.ItemsAdderLoadDataEvent; @@ -11,8 +12,6 @@ import org.bukkit.inventory.ItemStack; public class HookItemAdder extends Hook implements Listener { - // I hate IA, this overcomplicate stuff is so unneeded if it just did its stuff when its needed. - private boolean enabled = false; public HookItemAdder() { @@ -33,7 +32,7 @@ public class HookItemAdder extends Hook implements Listener { @EventHandler public void onItemAdderDataLoad(ItemsAdderLoadDataEvent event) { - if (enabled) return; // Only run on the first event fired; ignore all rest + if (enabled && !Settings.getItemsAdderReloadChange()) return; // Defaultly it will only run once at startup. If hook setting is enable this.enabled = true; HMCCosmeticsPlugin.setup(); } diff --git a/common/src/main/resources/config.yml b/common/src/main/resources/config.yml index 54129905..d79a9ab1 100644 --- a/common/src/main/resources/config.yml +++ b/common/src/main/resources/config.yml @@ -40,6 +40,11 @@ dye-menu: title: "ยงf๎€๎€‚" input-slot: 19 output-slot: 25 +hook-settings: + itemsadder: + # This causes the plugin to reload itself after any ItemsAdder change. This keeps the plugin fully up to date with IA, but + # could cause console spam as HMCCosmetics has to reload itself as well. + reload-on-change: false wardrobe: # spawn static wardrobe if in this radius of wardrobe-location static-radius: 10