diff --git a/pom.xml b/pom.xml index 199a8a9..38fd7bf 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.alerium ItemShops - 1.0-SNAPSHOT + 1.1-SNAPSHOT @@ -61,8 +61,7 @@ 1.12.2-R0.1-SNAPSHOT provided - - + me.clip placeholderapi diff --git a/src/main/java/io/alerium/itemshops/ItemShopsPlugin.java b/src/main/java/io/alerium/itemshops/ItemShopsPlugin.java index 40bef50..b5b866f 100644 --- a/src/main/java/io/alerium/itemshops/ItemShopsPlugin.java +++ b/src/main/java/io/alerium/itemshops/ItemShopsPlugin.java @@ -5,6 +5,7 @@ import io.alerium.itemshops.commands.GiveAllCommand; import io.alerium.itemshops.commands.GiveCommand; import io.alerium.itemshops.commands.OpenCommand; +import io.alerium.itemshops.commands.ReloadCommand; import io.alerium.itemshops.integrations.PlaceholderAPI; import io.alerium.itemshops.shops.ShopManager; import io.alerium.itemshops.utils.commands.Command; @@ -67,10 +68,11 @@ private void registerInstances() { } private void registerCommands() { - getCommand("itemshop").setExecutor(new Command(messages.getMessage("commands.help").format(), Arrays.asList( + getCommand("itemshop").setExecutor(new Command(Arrays.asList( new GiveAllCommand(), new GiveCommand(), - new OpenCommand() + new OpenCommand(), + new ReloadCommand() ))); } diff --git a/src/main/java/io/alerium/itemshops/commands/ReloadCommand.java b/src/main/java/io/alerium/itemshops/commands/ReloadCommand.java new file mode 100644 index 0000000..8b82e77 --- /dev/null +++ b/src/main/java/io/alerium/itemshops/commands/ReloadCommand.java @@ -0,0 +1,25 @@ +package io.alerium.itemshops.commands; + +import io.alerium.itemshops.ItemShopsPlugin; +import io.alerium.itemshops.utils.commands.SubCommand; +import org.bukkit.command.CommandSender; + +public class ReloadCommand extends SubCommand { + + private final ItemShopsPlugin plugin = ItemShopsPlugin.getInstance(); + + public ReloadCommand() { + super("reload", "itemshops.reload", false); + } + + @Override + public void execute(CommandSender sender, String[] args) { + plugin.getConfiguration().reload(); + plugin.getMessages().reload(); + + plugin.getShopManager().reload(); + plugin.getCoinsManager().enable(); + + plugin.getMessages().getMessage("commands.reload").format().send(sender); + } +} diff --git a/src/main/java/io/alerium/itemshops/shops/ShopManager.java b/src/main/java/io/alerium/itemshops/shops/ShopManager.java index ce23849..dcb79f9 100644 --- a/src/main/java/io/alerium/itemshops/shops/ShopManager.java +++ b/src/main/java/io/alerium/itemshops/shops/ShopManager.java @@ -19,21 +19,18 @@ public class ShopManager { private final ItemShopsPlugin plugin = ItemShopsPlugin.getInstance(); + private final File folder = new File(plugin.getDataFolder(), "shops"); private final List shops = new ArrayList<>(); @Getter private GUIInfo mainGui; public void enable() { - File folder = new File(plugin.getDataFolder(), "shops"); if (!folder.exists()) { folder.mkdir(); plugin.saveResource("shops/armor.yml", false); } - for (File file : folder.listFiles()) - loadShop(file.getName().replaceAll("\\.yml", "")); - - loadMainGui(); + reload(); } /** @@ -50,6 +47,18 @@ public ShopGUI getShopGui(String name) { return null; } + /** + * This method reloads all the shops from the config files + */ + public void reload() { + shops.clear(); + + for (File file : folder.listFiles()) + loadShop(file.getName().replaceAll("\\.yml", "")); + + loadMainGui(); + } + /** * This method loads the main GUI */ diff --git a/src/main/java/io/alerium/itemshops/utils/commands/Command.java b/src/main/java/io/alerium/itemshops/utils/commands/Command.java index 55af367..c5145f2 100644 --- a/src/main/java/io/alerium/itemshops/utils/commands/Command.java +++ b/src/main/java/io/alerium/itemshops/utils/commands/Command.java @@ -15,13 +15,12 @@ public class Command implements CommandExecutor { private final ItemShopsPlugin plugin = ItemShopsPlugin.getInstance(); - private final Message helpMessage; private final List commands; @Override public boolean onCommand(CommandSender sender, org.bukkit.command.Command command, String label, String[] args) { if (args.length == 0) { - helpMessage.send(sender); + plugin.getMessages().getMessage("commands.help").format().send(sender); return true; } diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 3dc872e..792ab8c 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -11,6 +11,7 @@ commands: - '&a/itemshop open ' - '&a/itemshop give ' - '&a/itemshop giveall ' + - '&a/itemshop reload' open: shopNotFound: '&cThe shop you''re trying to open doesn''t exist.' give: @@ -19,4 +20,5 @@ commands: done: '&aYou gave %coins to %player' giveall: usage: '&cUsage: /itemshop giveall ' - done: '&aYou gave %coins to %players players' \ No newline at end of file + done: '&aYou gave %coins to %players players' + reload: '&aPlugin reloaded' \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 59536fc..4302632 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: ItemShops author: xQuickGlare -version: 1.0 +version: 1.1 main: io.alerium.itemshops.ItemShopsPlugin api-version: 1.15 softdepend: [PlaceholderAPI]