diff --git a/src/main/java/com/Acrobot/ChestShop/Commands/Version.java b/src/main/java/com/Acrobot/ChestShop/Commands/Version.java index 7f500d1..6c6de52 100644 --- a/src/main/java/com/Acrobot/ChestShop/Commands/Version.java +++ b/src/main/java/com/Acrobot/ChestShop/Commands/Version.java @@ -1,6 +1,7 @@ package com.Acrobot.ChestShop.Commands; import com.Acrobot.ChestShop.ChestShop; +import com.Acrobot.ChestShop.Events.ChestShopReloadEvent; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -12,7 +13,7 @@ import org.bukkit.command.CommandSender; public class Version implements CommandExecutor { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (args.length > 0 && args[0].equals("reload")) { - ChestShop.getPlugin().loadConfig(); + ChestShop.callEvent(new ChestShopReloadEvent(sender)); sender.sendMessage(ChatColor.DARK_GREEN + "The config was reloaded."); return true; diff --git a/src/main/java/com/Acrobot/ChestShop/Events/ChestShopReloadEvent.java b/src/main/java/com/Acrobot/ChestShop/Events/ChestShopReloadEvent.java new file mode 100644 index 0000000..248c923 --- /dev/null +++ b/src/main/java/com/Acrobot/ChestShop/Events/ChestShopReloadEvent.java @@ -0,0 +1,35 @@ +package com.Acrobot.ChestShop.Events; + +import org.bukkit.command.CommandSender; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +/** + * Represents a plugin reload call + * + * @author Acrobot + */ +public class ChestShopReloadEvent extends Event { + private static final HandlerList handlers = new HandlerList(); + + private CommandSender sender; + + public ChestShopReloadEvent(CommandSender sender) { + this.sender = sender; + } + + /** + * @return CommandSender who initiated the call + */ + public CommandSender getSender() { + return sender; + } + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/DiscountModule.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/DiscountModule.java index 89f8f65..2b1cbd9 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/DiscountModule.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/DiscountModule.java @@ -2,7 +2,7 @@ package com.Acrobot.ChestShop.Listeners.Modules; import com.Acrobot.Breeze.Utils.PriceUtil; import com.Acrobot.ChestShop.ChestShop; -import com.Acrobot.ChestShop.Containers.AdminInventory; +import com.Acrobot.ChestShop.Events.ChestShopReloadEvent; import com.Acrobot.ChestShop.Events.PreTransactionEvent; import com.Acrobot.ChestShop.Permission; import com.Acrobot.ChestShop.UUIDs.NameManager; @@ -28,6 +28,10 @@ public class DiscountModule implements Listener { private Set groupList = new HashSet(); public DiscountModule() { + load(); + } + + private void load() { config = YamlConfiguration.loadConfiguration(ChestShop.loadFile("discounts.yml")); config.options().header("This file is for discount management. You are able to do that:\n" + @@ -45,6 +49,11 @@ public class DiscountModule implements Listener { groupList = config.getKeys(false); } + @EventHandler + public void onReload(ChestShopReloadEvent event) { + load(); + } + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onPreTransaction(PreTransactionEvent event) { if (event.getTransactionType() != BUY || !NameManager.isAdminShop(event.getOwnerAccount().getUuid())) { diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/PriceRestrictionModule.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/PriceRestrictionModule.java index 9de7a89..790d165 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/PriceRestrictionModule.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/PriceRestrictionModule.java @@ -2,6 +2,7 @@ package com.Acrobot.ChestShop.Listeners.Modules; import com.Acrobot.Breeze.Utils.PriceUtil; import com.Acrobot.ChestShop.ChestShop; +import com.Acrobot.ChestShop.Events.ChestShopReloadEvent; import com.Acrobot.ChestShop.Events.ItemParseEvent; import com.Acrobot.ChestShop.Events.PreShopCreationEvent; import org.bukkit.Bukkit; @@ -34,6 +35,10 @@ public class PriceRestrictionModule implements Listener { private static final double INVALID_PATH = Double.MIN_VALUE; public PriceRestrictionModule() { + load(); + } + + private void load() { File file = new File(ChestShop.getFolder(), "priceLimits.yml"); configuration = YamlConfiguration.loadConfiguration(file); @@ -92,6 +97,11 @@ public class PriceRestrictionModule implements Listener { } } + @EventHandler + public void onReload(ChestShopReloadEvent event) { + load(); + } + @EventHandler public void onPreShopCreation(PreShopCreationEvent event) { ItemParseEvent parseEvent = new ItemParseEvent(event.getSignLine(ITEM_LINE)); diff --git a/src/main/java/com/Acrobot/ChestShop/Plugins/ChestShop.java b/src/main/java/com/Acrobot/ChestShop/Plugins/ChestShop.java index f84f383..75fa233 100644 --- a/src/main/java/com/Acrobot/ChestShop/Plugins/ChestShop.java +++ b/src/main/java/com/Acrobot/ChestShop/Plugins/ChestShop.java @@ -1,9 +1,9 @@ package com.Acrobot.ChestShop.Plugins; +import com.Acrobot.ChestShop.Events.ChestShopReloadEvent; import com.Acrobot.ChestShop.Events.Protection.ProtectionCheckEvent; import com.Acrobot.ChestShop.Permission; import com.Acrobot.ChestShop.Signs.ChestShopSign; -import com.Acrobot.ChestShop.UUIDs.NameManager; import com.Acrobot.ChestShop.Utils.uBlock; import org.bukkit.block.Block; import org.bukkit.block.Sign; @@ -18,6 +18,12 @@ import static com.Acrobot.Breeze.Utils.BlockUtil.isSign; * @author Acrobot */ public class ChestShop implements Listener { + + @EventHandler + public static void onReload(ChestShopReloadEvent event) { + com.Acrobot.ChestShop.ChestShop.getPlugin().loadConfig(); + } + @EventHandler public static void onProtectionCheck(ProtectionCheckEvent event) { if (event.getResult() == Event.Result.DENY || event.isBuiltInProtectionIgnored()) {