diff --git a/src/main/java/os/arcadiadevs/playerservers/hubcore/PsHubCore.java b/src/main/java/os/arcadiadevs/playerservers/hubcore/PsHubCore.java index bd1b79f..0bb5ed4 100644 --- a/src/main/java/os/arcadiadevs/playerservers/hubcore/PsHubCore.java +++ b/src/main/java/os/arcadiadevs/playerservers/hubcore/PsHubCore.java @@ -24,6 +24,8 @@ import os.arcadiadevs.playerservers.hubcore.models.Allocation; import os.arcadiadevs.playerservers.hubcore.models.Node; import os.arcadiadevs.playerservers.hubcore.models.Server; import os.arcadiadevs.playerservers.hubcore.placeholders.PlayerCount; +import os.arcadiadevs.playerservers.hubcore.statics.Permissions; +import os.arcadiadevs.playerservers.hubcore.utils.ChatUtil; /** * Main class of the plugin. @@ -102,6 +104,17 @@ public class PsHubCore extends JavaPlugin { Bukkit.getPluginManager().registerEvents(new HubEvents(getConfig()), this); Objects.requireNonNull(getCommand("servers")).setExecutor(new CommandManager()); + Objects.requireNonNull(getCommand("playermenu")).setExecutor(new CommandManager()); + + Objects.requireNonNull(getCommand("pshubreload")).setExecutor((sender, command, label, args) -> { + if (sender.hasPermission(Permissions.RELOAD)) { + reloadConfig(); + ChatUtil.sendMessage(sender, "&9PSHubCore> &aConfig reloaded."); + } else { + ChatUtil.sendMessage(sender, "&9PSHubCore> &cYou don't have permission to do that."); + } + return true; + }); // Initialize SpiGUI spiGui = new SpiGUI(this); diff --git a/src/main/java/os/arcadiadevs/playerservers/hubcore/commands/CommandManager.java b/src/main/java/os/arcadiadevs/playerservers/hubcore/commands/CommandManager.java index 4afdffc..85f806a 100644 --- a/src/main/java/os/arcadiadevs/playerservers/hubcore/commands/CommandManager.java +++ b/src/main/java/os/arcadiadevs/playerservers/hubcore/commands/CommandManager.java @@ -5,7 +5,9 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import os.arcadiadevs.playerservers.hubcore.PsHubCore; +import os.arcadiadevs.playerservers.hubcore.guis.PlayerMenuGui; import os.arcadiadevs.playerservers.hubcore.guis.SelectorGui; +import os.arcadiadevs.playerservers.hubcore.statics.Permissions; import os.arcadiadevs.playerservers.hubcore.utils.ChatUtil; /** @@ -13,28 +15,58 @@ import os.arcadiadevs.playerservers.hubcore.utils.ChatUtil; * * @author ArcadiaDevs */ +@SuppressWarnings("NullableProblems") public class CommandManager implements CommandExecutor { @Override public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { + if (!(commandSender instanceof Player player)) { ChatUtil.sendMessage(commandSender, "&9Error> &cYou must be a player to execute this command."); return true; } - if (!PsHubCore.getInstance().getConfig().getBoolean("gui.selector.enabled")) { - ChatUtil.sendMessage(player, "&9PlayerServers> &7Oops, this feature is disabled."); + final var enableGuiPermissions = PsHubCore.getInstance().getConfig().getBoolean("gui.enable-permissions"); + final var commandName = command.getName(); + + if (!enableGuiPermissions) { + if (isPlayerMenu(commandName)) { + PlayerMenuGui.openGui(player); + return true; + } + if (isSelector(commandName)) { + SelectorGui.openGui(player); + return true; + } + } + + if (isPlayerMenu(commandName) && player.hasPermission(Permissions.PLAYER_MENU) ) { + PlayerMenuGui.openGui(player); return true; } - if (command.getName().equalsIgnoreCase("servers") - || command.getName().equalsIgnoreCase("menu") - || command.getName().equalsIgnoreCase("opengui")) { + if (isSelector(commandName) && player.hasPermission(Permissions.SERVER_SELECTOR)) { SelectorGui.openGui(player); + return true; } + ChatUtil.sendMessage(player, PsHubCore.getInstance().getConfig().getString("messages.no-permission")); + return true; } + + private boolean isSelector(String commandName) { + return commandName.equalsIgnoreCase("servers") + || commandName.equalsIgnoreCase("menu") + || commandName.equalsIgnoreCase("opengui"); + } + + private boolean isPlayerMenu(String commandName) { + return commandName.equalsIgnoreCase("playermenu") + || commandName.equalsIgnoreCase("pmenu") + || commandName.equalsIgnoreCase("playergui") + || commandName.equalsIgnoreCase("pgui"); + } } diff --git a/src/main/java/os/arcadiadevs/playerservers/hubcore/events/ClickEvent.java b/src/main/java/os/arcadiadevs/playerservers/hubcore/events/ClickEvent.java index 697e141..bf9c231 100644 --- a/src/main/java/os/arcadiadevs/playerservers/hubcore/events/ClickEvent.java +++ b/src/main/java/os/arcadiadevs/playerservers/hubcore/events/ClickEvent.java @@ -11,6 +11,7 @@ import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerInteractEvent; import os.arcadiadevs.playerservers.hubcore.PsHubCore; import os.arcadiadevs.playerservers.hubcore.guis.SelectorGui; +import os.arcadiadevs.playerservers.hubcore.statics.Permissions; import os.arcadiadevs.playerservers.hubcore.utils.ChatUtil; import os.arcadiadevs.playerservers.hubcore.guis.PlayerMenuGui; @@ -35,6 +36,7 @@ public class ClickEvent implements Listener { @EventHandler public void onClick(PlayerInteractEvent event) { final var player = event.getPlayer(); + final boolean enableGuiPermissions = PsHubCore.getInstance().getConfig().getBoolean("gui.enable-permissions"); if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) { @@ -44,7 +46,7 @@ public class ClickEvent implements Listener { if (instance.getConfig().getBoolean("gui.selector.item.enabled") && player.getInventory().getHeldItemSlot() == PsHubCore.getInstance().getConfig().getInt("gui.selector.item.location")) { - if (!player.hasPermission("hubcore.selector")) { + if (!player.hasPermission(Permissions.SERVER_SELECTOR) && enableGuiPermissions) { ChatUtil.sendMessage(player, instance.getConfig().getString("messages.no-permission")); return; } @@ -55,7 +57,7 @@ public class ClickEvent implements Listener { if (instance.getConfig().getBoolean("gui.player-menu.item.enabled") && player.getInventory().getHeldItemSlot() == PsHubCore.getInstance().getConfig().getInt("gui.player-menu.item.location")) { - if (!player.hasPermission("hubcore.player-menu")) { + if (!player.hasPermission(Permissions.PLAYER_MENU) && enableGuiPermissions) { ChatUtil.sendMessage(player, instance.getConfig().getString("messages.no-permission")); return; } diff --git a/src/main/java/os/arcadiadevs/playerservers/hubcore/statics/Permissions.java b/src/main/java/os/arcadiadevs/playerservers/hubcore/statics/Permissions.java new file mode 100644 index 0000000..fcfa109 --- /dev/null +++ b/src/main/java/os/arcadiadevs/playerservers/hubcore/statics/Permissions.java @@ -0,0 +1,8 @@ +package os.arcadiadevs.playerservers.hubcore.statics; + +public class Permissions { + + public static String SERVER_SELECTOR = "playerservers.hubcore.selector"; + public static String PLAYER_MENU = "playerservers.hubcore.player-menu"; + public static String RELOAD = "playerservers.hubcore.reload"; +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 17cc732..02f5ced 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -25,6 +25,8 @@ messages: no-permission: "&9Error> &7Oops, it seems like you don't have permission to do that." gui: + enable-permissions: false + selector: enabled: true diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 9809e04..846f1c4 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -6,9 +6,19 @@ author: OpenSource softdepend: [PlaceholderAPI] commands: + pshubreload: + usage: /pshubreload + description: Reloads the plugin servers: usage: /servers description: Opens up server selector GUI aliases: - menu - - opengui \ No newline at end of file + - opengui + playermenu: + usage: /playermenu + description: Opens up player menu GUI + aliases: + - pmenu + - playergui + - pgui \ No newline at end of file