From 9d910ed29920f10830829d995a20011588321f8a Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Mon, 17 Sep 2018 15:37:32 +0200 Subject: [PATCH] Version 2.0.3 Config.yml: + ShowBanner + NoPermission-message + ReloadNotifyPlayer CmdHelpGUI.java: + permission-check to HelpGUI.java for both subcommands. + Players with helpgui.notify get the ReloadNotifyPlayer message ScrollerInventory.java ~ Comment updated HelpGUI.java: + Check for config-option ShowBanner plugin.yml: + permission helpgui.admin + permission helpgui.notify ~ Moved child-perms from helpgui.* to helpgui.admin ~ Made helpgui.admin a child-perm of helpgui.* --- pom.xml | 2 +- .../java/com/andre601/helpgui/HelpGUI.java | 47 ++++++++++--------- .../andre601/helpgui/commands/CmdHelpGUI.java | 27 +++++++++-- .../helpgui/manager/ScrollerInventory.java | 6 ++- .../helpgui/util/config/ConfigPaths.java | 38 ++++++++------- .../helpgui/util/config/ConfigUtil.java | 10 +--- .../helpgui/util/logging/LogUtil.java | 6 +-- src/main/resources/config.yml | 14 +++++- src/main/resources/plugin.yml | 11 ++++- 9 files changed, 97 insertions(+), 64 deletions(-) diff --git a/pom.xml b/pom.xml index 0b3d410..7f8d918 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.andre601 HelpGUI - 2.0.1-BETA + 2.0.3 diff --git a/src/main/java/com/andre601/helpgui/HelpGUI.java b/src/main/java/com/andre601/helpgui/HelpGUI.java index 2c5b622..ece6232 100644 --- a/src/main/java/com/andre601/helpgui/HelpGUI.java +++ b/src/main/java/com/andre601/helpgui/HelpGUI.java @@ -26,26 +26,27 @@ public void onEnable(){ long startTime = System.currentTimeMillis(); instance = this; + ConfigUtil.setupFile(); - sendBanner(); + if(ConfigUtil.config().getBoolean(ConfigPaths.SHOW_BANNER)) + sendBanner(); - ConfigUtil.setupFile(); loadCommands(); - LogUtil.INFO("&7Register events..."); + LogUtil.LOG("&7Register events..."); Bukkit.getPluginManager().registerEvents(new EventManager(), this); - LogUtil.INFO("&7Events successfully registered!"); + LogUtil.LOG("&7Events successfully registered!"); - LogUtil.INFO("&7Checking for Vault..."); + LogUtil.LOG("&7Checking for Vault..."); checkVaultStatus(); - LogUtil.INFO("&7Plugin enabled in " + getTime(startTime) + "ms!"); + LogUtil.LOG("&7Plugin enabled in " + getTime(startTime) + "ms!"); } public void onDisable(){ // Unregister all the commands unloadCommands(); - LogUtil.INFO("&7HelpGUI disabled! Good bye."); + LogUtil.LOG("&7HelpGUI disabled! Good bye."); } public static HelpGUI getInstance(){ @@ -59,37 +60,37 @@ public static boolean getVaultStatus(){ public void checkVaultStatus(){ if(VaultIntegrationManager.setupPermission()){ vaultEnabled = true; - LogUtil.INFO(config().getString(ConfigPaths.MSG_VAULT_FOUND)); + LogUtil.LOG(config().getString(ConfigPaths.MSG_VAULT_FOUND)); }else{ vaultEnabled = false; - LogUtil.WARN(config().getString(ConfigPaths.MSG_VAULT_NOT_FOUND)); + LogUtil.LOG(config().getString(ConfigPaths.MSG_VAULT_NOT_FOUND)); } } private void loadCommands(){ manager = new BukkitCommandManager(this); - LogUtil.INFO("&7Register Command Contexts..."); + LogUtil.LOG("&7Register Command Contexts..."); manager.getCommandContexts().registerOptionalContext(PlayerUtil.class, c -> { PlayerUtil playerUtil = new PlayerUtil(getInstance()); playerUtil.search(c.getPlayer(), c.getFirstArg() != null ? c.popFirstArg() : null); return playerUtil; }); - LogUtil.INFO("&7Command Contexts successfully loaded!"); + LogUtil.LOG("&7Command Contexts successfully loaded!"); manager.enableUnstableAPI("help"); - LogUtil.INFO("&7Registering commands..."); + LogUtil.LOG("&7Registering commands..."); manager.registerCommand(new CmdHelp()); manager.registerCommand(new CmdHelpGUI()); - LogUtil.INFO("&7Commands successfully loaded!"); + LogUtil.LOG("&7Commands successfully loaded!"); } private void unloadCommands(){ // The manager is already registered, so we don't have to worry... - LogUtil.INFO("&7Unload Commands..."); + LogUtil.LOG("&7Unload Commands..."); manager.unregisterCommands(); - LogUtil.INFO("&7Commands unloaded."); + LogUtil.LOG("&7Commands unloaded."); } private long getTime(long startTime){ @@ -97,14 +98,14 @@ private long getTime(long startTime){ } private void sendBanner(){ - LogUtil.INFO(""); - LogUtil.INFO("&a _ _ &2 ____"); - LogUtil.INFO("&a| | | | &2 / ___)"); - LogUtil.INFO("&a| |_| | &2| / _"); - LogUtil.INFO("&a|_____| &2|_| (_|"); - LogUtil.INFO("&a _ _ &2 _____"); - LogUtil.INFO("&a|_| |_| &2 \\___/"); - LogUtil.INFO(""); + LogUtil.LOG(""); + LogUtil.LOG("&a _ _ &2 ____"); + LogUtil.LOG("&a| | | | &2 / ___)"); + LogUtil.LOG("&a| |_| | &2| / _"); + LogUtil.LOG("&a|_____| &2|_| (_|"); + LogUtil.LOG("&a _ _ &2 _____"); + LogUtil.LOG("&a|_| |_| &2 \\___/"); + LogUtil.LOG(""); } public String prefix(){ diff --git a/src/main/java/com/andre601/helpgui/commands/CmdHelpGUI.java b/src/main/java/com/andre601/helpgui/commands/CmdHelpGUI.java index b8f6008..5fd0ad4 100644 --- a/src/main/java/com/andre601/helpgui/commands/CmdHelpGUI.java +++ b/src/main/java/com/andre601/helpgui/commands/CmdHelpGUI.java @@ -7,6 +7,7 @@ import com.andre601.helpgui.util.config.ConfigPaths; import com.andre601.helpgui.util.config.ConfigUtil; import com.andre601.helpgui.util.logging.LogUtil; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; @CommandAlias("helpgui|hgui") @@ -14,20 +15,36 @@ public class CmdHelpGUI extends BaseCommand { @Subcommand("reload") @Description("Reloads the config.yml") - @CommandPermission("helpgui.reload") public void reloadConfig(Player player){ - LogUtil.INFO("&7Reloading config.yml..."); + if(!player.hasPermission("helpgui.reload")){ + player.sendMessage(ConfigUtil.color(ConfigPaths.ERR_NO_PERMISSION)); + return; + } + + LogUtil.LOG("&7Reloading config.yml..."); player.sendMessage(HelpGUI.getInstance().prefix() + ConfigUtil.color(ConfigPaths.MSG_CONFIG_ATTEMPREL)); HelpGUI.getInstance().reloadConfig(); - LogUtil.INFO("&7Reload complete!"); + LogUtil.LOG("&7Reload complete!"); player.sendMessage(HelpGUI.getInstance().prefix() + ConfigUtil.color(ConfigPaths.MSG_CONFIG_RELOADED)); + + for(Player p : Bukkit.getOnlinePlayers()){ + if(p.hasPermission("helpgui.notify")) + if(p != player) + p.sendMessage(HelpGUI.getInstance().prefix() + + ConfigUtil.color(ConfigPaths.MSG_CONFIG_REL_NOTIFY_PLAYER) + .replace("%player%", player.getName()) + ); + } } @Default @HelpCommand - @CommandPermission("helpgui.help") @Description("Shows this help page.") - public void onHelp(CommandHelp help){ + public void onHelp(Player player, CommandHelp help){ + if(!player.hasPermission("helpgui.help")){ + player.sendMessage(HelpGUI.getInstance().prefix() + ConfigUtil.color(ConfigPaths.ERR_NO_PERMISSION)); + return; + } help.showHelp(); } } diff --git a/src/main/java/com/andre601/helpgui/manager/ScrollerInventory.java b/src/main/java/com/andre601/helpgui/manager/ScrollerInventory.java index fedb171..286f6ca 100644 --- a/src/main/java/com/andre601/helpgui/manager/ScrollerInventory.java +++ b/src/main/java/com/andre601/helpgui/manager/ScrollerInventory.java @@ -1,5 +1,6 @@ package com.andre601.helpgui.manager; +import com.andre601.helpgui.HelpGUI; import com.andre601.helpgui.util.config.ConfigPaths; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -37,7 +38,10 @@ public ScrollerInventory(ArrayList items, String name, Player p){ if(page.firstEmpty() == 53){ page.addItem(items.get(i)); pages.add(page); - // Check for if the item is NOT the last one in the itemlist. + /* + * Had to add this weird "fix" because the plugin created a blank GUI, if the last item fills the last + * slot of the other inv... + */ if(i < (items.size() - 1)) page = getBlankPage(name); }else{ diff --git a/src/main/java/com/andre601/helpgui/util/config/ConfigPaths.java b/src/main/java/com/andre601/helpgui/util/config/ConfigPaths.java index 30b01fc..8ad3d59 100644 --- a/src/main/java/com/andre601/helpgui/util/config/ConfigPaths.java +++ b/src/main/java/com/andre601/helpgui/util/config/ConfigPaths.java @@ -2,30 +2,32 @@ public final class ConfigPaths { + public static String SHOW_BANNER = "Main.ShowBanner"; public static String DP_MODE = "Main.DisabledPlayers.Mode"; public static String DISABLED_PLAYERS = "Main.DisabledPlayers.Players"; public static String DW_MODE = "Main.DisabledWorlds.Mode"; public static String DISABLED_WORLDS = "Main.DisabledWorlds.Worlds"; - public static String MSG_INV_TITLE = "Messages.HelpInv.Title"; - public static String MSG_INV_INFO = "Messages.HelpInv.Info"; - public static String MSG_INV_INFO_DESC = "Messages.HelpInv.InfoDesc"; - public static String MSG_NEXT_PAGE = "Messages.HelpInv.NextPage"; - public static String MSG_PREV_PAGE = "Messages.HelpInv.PrevPage"; - public static String MSG_VAULT_FOUND = "Messages.Startup.VaultFound"; - public static String MSG_VAULT_NOT_FOUND = "Messages.Startup.VaultNotFound"; - public static String MSG_NO_PLAYER = "Messages.Console.NoPlayer"; - public static String MSG_HELP_SEND = "Messages.HelpRequest.Sender"; - public static String MSG_HELP_RECEIVED = "Messages.HelpRequest.Recipient"; - public static String MSG_CONFIG_ATTEMPREL = "Messages.Config.AttemptReload"; - public static String MSG_CONFIG_RELOADED = "Messages.Config.Reloaded"; - public static String ERR_CMD_DISABLED = "Messages.Errors.CommandDisabled"; - public static String ERR_NOT_ONLINE = "Messages.Errors.NotOnline"; - public static String ERR_DISABLED_WORLD = "Messages.Errors.DisabledWorld"; - public static String ERR_NO_PLAYERS_FOUND = "Messages.Errors.NoPlayersFound"; - public static String ERR_NO_GROUP = "Messages.Errors.NoGroup"; - public static String ERR_VAULT_NOT_ENABLED = "Messages.Errors.VaultNotEnabled"; + public static String MSG_INV_TITLE = "Messages.HelpInv.Title"; + public static String MSG_INV_INFO = "Messages.HelpInv.Info"; + public static String MSG_INV_INFO_DESC = "Messages.HelpInv.InfoDesc"; + public static String MSG_NEXT_PAGE = "Messages.HelpInv.NextPage"; + public static String MSG_PREV_PAGE = "Messages.HelpInv.PrevPage"; + public static String MSG_VAULT_FOUND = "Messages.Startup.VaultFound"; + public static String MSG_VAULT_NOT_FOUND = "Messages.Startup.VaultNotFound"; + public static String MSG_HELP_SEND = "Messages.HelpRequest.Sender"; + public static String MSG_HELP_RECEIVED = "Messages.HelpRequest.Recipient"; + public static String MSG_CONFIG_ATTEMPREL = "Messages.Config.AttemptReload"; + public static String MSG_CONFIG_RELOADED = "Messages.Config.Reloaded"; + public static String MSG_CONFIG_REL_NOTIFY_PLAYER = "Messages.Config.ReloadNotifyPlayer"; + public static String ERR_CMD_DISABLED = "Messages.Errors.CommandDisabled"; + public static String ERR_NOT_ONLINE = "Messages.Errors.NotOnline"; + public static String ERR_DISABLED_WORLD = "Messages.Errors.DisabledWorld"; + public static String ERR_NO_PLAYERS_FOUND = "Messages.Errors.NoPlayersFound"; + public static String ERR_NO_GROUP = "Messages.Errors.NoGroup"; + public static String ERR_VAULT_NOT_ENABLED = "Messages.Errors.VaultNotEnabled"; + public static String ERR_NO_PERMISSION = "Messages.Errors.NoPermission"; } diff --git a/src/main/java/com/andre601/helpgui/util/config/ConfigUtil.java b/src/main/java/com/andre601/helpgui/util/config/ConfigUtil.java index 793477f..9e13aff 100644 --- a/src/main/java/com/andre601/helpgui/util/config/ConfigUtil.java +++ b/src/main/java/com/andre601/helpgui/util/config/ConfigUtil.java @@ -1,25 +1,19 @@ package com.andre601.helpgui.util.config; import com.andre601.helpgui.HelpGUI; -import com.andre601.helpgui.util.config.ConfigPaths; import com.andre601.helpgui.util.logging.LogUtil; -import com.google.common.io.ByteStreams; import org.bukkit.ChatColor; import org.bukkit.configuration.file.FileConfiguration; -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class ConfigUtil { public static void setupFile(){ - LogUtil.INFO("&7Loading config.yml..."); + LogUtil.LOG("&7Loading config.yml..."); HelpGUI.getInstance().saveDefaultConfig(); - LogUtil.INFO("&7Config successfully loaded!"); + LogUtil.LOG("&7Config successfully loaded!"); } public static List getStringList(String path){ diff --git a/src/main/java/com/andre601/helpgui/util/logging/LogUtil.java b/src/main/java/com/andre601/helpgui/util/logging/LogUtil.java index 19688bd..e8f2193 100644 --- a/src/main/java/com/andre601/helpgui/util/logging/LogUtil.java +++ b/src/main/java/com/andre601/helpgui/util/logging/LogUtil.java @@ -7,12 +7,8 @@ public final class LogUtil { public static String prefix = "&f[&aHelp&2GUI&f] "; - public static void INFO(String info){ + public static void LOG(String info){ HelpGUI.getInstance().getServer().getConsoleSender().sendMessage(ConfigUtil.transformCol(prefix + info)); } - public static void WARN(String warn){ - HelpGUI.getInstance().getServer().getConsoleSender().sendMessage(ConfigUtil.transformCol(prefix + warn)); - } - } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 9cac9ab..003a07a 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -17,6 +17,10 @@ # https://github.com/Andre601/HelpGUI/wiki # Main: + # + # Should the banner be visible on startup? + # + ShowBanner: true DisabledPlayers: # # Choose which player heads are shown in the GUI @@ -103,12 +107,18 @@ Messages: DisabledWorld: '&cYou cannot use HelpGUI in this world.' NoPlayersFound: '&cNo players found. :,(' VaultNotEnabled: '&cVault is not enabled/installed!' + NoPermission: '&cYou do not have permission for that!' Config: # # Messages for reloading the config. # - # AttemptReload: Message on start of reload. - # Reloaded: When the plugin successfully reloaded the config. + # AttemptReload: Message on start of reload. + # Reloaded: When the plugin successfully reloaded the config. + # ReloadNotifyPlayer: Players with helpgui.notify receive this message. + # + # Placeholder: + # %player% -> Name of the player, that reloaded the plugin. # AttemptReload: '&7Reloading config.yml...' Reloaded: '&aconfig.yml successfully reloaded!' + ReloadNotifyPlayer: '&b%player% &7reloaded the config!' diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index fb00b29..caad81e 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: HelpGUI -version: 2.0.1-BETA +version: 2.0.3 author: Andre_601 main: com.andre601.helpgui.HelpGUI @@ -19,12 +19,18 @@ commands: permissions: helpgui.*: + description: permission for all HelpGUI-commands + default: op + children: + helpgui.admin: true + helpgui.admin: description: permission for all HelpGUI-commands default: op children: helpgui.help: true helpgui.reload: true helpgui.staff: true + helpgui.notify: true helpgui.disablehelp: description: Disables /help for a user/group default: false @@ -36,4 +42,7 @@ permissions: default: op helpgui.staff: description: Permission for the Staff-Mode option + default: op + helpgui.notify: + description: Notifies players about config-reloads default: op \ No newline at end of file