Skip to content

Commit

Permalink
Added /itemshop reload command
Browse files Browse the repository at this point in the history
  • Loading branch information
QuickGlare committed Apr 28, 2020
1 parent 67e71e8 commit dae5a71
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 14 deletions.
5 changes: 2 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.alerium</groupId>
<artifactId>ItemShops</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.1-SNAPSHOT</version>

<build>
<plugins>
Expand Down Expand Up @@ -61,8 +61,7 @@
<version>1.12.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>



<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/io/alerium/itemshops/ItemShopsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
)));
}

Expand Down
25 changes: 25 additions & 0 deletions src/main/java/io/alerium/itemshops/commands/ReloadCommand.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
19 changes: 14 additions & 5 deletions src/main/java/io/alerium/itemshops/shops/ShopManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ShopGUI> 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();
}

/**
Expand All @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ public class Command implements CommandExecutor {

private final ItemShopsPlugin plugin = ItemShopsPlugin.getInstance();

private final Message helpMessage;
private final List<SubCommand> 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;
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ commands:
- '&a/itemshop open <name>'
- '&a/itemshop give <player> <amount>'
- '&a/itemshop giveall <amount>'
- '&a/itemshop reload'
open:
shopNotFound: '&cThe shop you''re trying to open doesn''t exist.'
give:
Expand All @@ -19,4 +20,5 @@ commands:
done: '&aYou gave %coins to %player'
giveall:
usage: '&cUsage: /itemshop giveall <amount>'
done: '&aYou gave %coins to %players players'
done: '&aYou gave %coins to %players players'
reload: '&aPlugin reloaded'
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down

0 comments on commit dae5a71

Please sign in to comment.