Skip to content

Commit

Permalink
Version 2.0.3
Browse files Browse the repository at this point in the history
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.*
  • Loading branch information
Andre601 committed Sep 17, 2018
1 parent 5f3e194 commit 9d910ed
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 64 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -6,7 +6,7 @@

<groupId>com.andre601</groupId>
<artifactId>HelpGUI</artifactId>
<version>2.0.1-BETA</version>
<version>2.0.3</version>
<build>
<plugins>
<plugin>
Expand Down
47 changes: 24 additions & 23 deletions src/main/java/com/andre601/helpgui/HelpGUI.java
Expand Up @@ -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(){
Expand All @@ -59,52 +60,52 @@ 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){
return System.currentTimeMillis() - 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(){
Expand Down
27 changes: 22 additions & 5 deletions src/main/java/com/andre601/helpgui/commands/CmdHelpGUI.java
Expand Up @@ -7,27 +7,44 @@
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")
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();
}
}
@@ -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;
Expand Down Expand Up @@ -37,7 +38,10 @@ public ScrollerInventory(ArrayList<ItemStack> 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{
Expand Down
38 changes: 20 additions & 18 deletions src/main/java/com/andre601/helpgui/util/config/ConfigPaths.java
Expand Up @@ -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";


}
10 changes: 2 additions & 8 deletions 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<String> getStringList(String path){
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/com/andre601/helpgui/util/logging/LogUtil.java
Expand Up @@ -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));
}

}
14 changes: 12 additions & 2 deletions src/main/resources/config.yml
Expand Up @@ -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
Expand Down Expand Up @@ -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!'
11 changes: 10 additions & 1 deletion 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
Expand All @@ -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
Expand All @@ -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

0 comments on commit 9d910ed

Please sign in to comment.