From 70cabfaa81ea2e2a0ebc9e899a74b628e5d12198 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 14 Mar 2019 16:27:22 +0100 Subject: [PATCH] Reload msg, old perm check, Player cmd fix --- .../java/buttondevteam/core/ThorpeCommand.java | 5 ++++- .../lib/architecture/ButtonPlugin.java | 16 +++++++++++----- .../java/buttondevteam/lib/chat/Command2.java | 6 +++--- .../java/buttondevteam/lib/chat/Command2MC.java | 4 +++- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/ButtonCore/src/main/java/buttondevteam/core/ThorpeCommand.java b/ButtonCore/src/main/java/buttondevteam/core/ThorpeCommand.java index 5fb924f..91f2d5c 100644 --- a/ButtonCore/src/main/java/buttondevteam/core/ThorpeCommand.java +++ b/ButtonCore/src/main/java/buttondevteam/core/ThorpeCommand.java @@ -9,6 +9,9 @@ import org.bukkit.command.CommandSender; public class ThorpeCommand extends ICommand2MC { @Command2.Subcommand //TODO: Main permissions (groups) like 'mod' public void reload(CommandSender sender) { - MainPlugin.Instance.reloadConfig(); + if (MainPlugin.Instance.tryReloadConfig()) + sender.sendMessage("§bConfig reloaded."); + else + sender.sendMessage("§cFailed to reload config. Check console."); } } diff --git a/ButtonCore/src/main/java/buttondevteam/lib/architecture/ButtonPlugin.java b/ButtonCore/src/main/java/buttondevteam/lib/architecture/ButtonPlugin.java index e06ab95..25df8af 100644 --- a/ButtonCore/src/main/java/buttondevteam/lib/architecture/ButtonPlugin.java +++ b/ButtonCore/src/main/java/buttondevteam/lib/architecture/ButtonPlugin.java @@ -71,17 +71,23 @@ public abstract class ButtonPlugin extends JavaPlugin { @Override public void reloadConfig() { - justReload(); - loadConfig(); - componentStack.forEach(c -> Component.updateConfig(this, c)); + tryReloadConfig(); } - public void justReload() { + public boolean tryReloadConfig() { + if (!justReload()) return false; + loadConfig(); + componentStack.forEach(c -> Component.updateConfig(this, c)); + return true; + } + + public boolean justReload() { if (loaded && ConfigData.saveNow(getConfig())) { getLogger().warning("Saved pending configuration changes to the file, didn't reload (try again)."); - return; + return false; } super.reloadConfig(); loaded = true; //Needed because for the first time it uses reloadConfig() to load it + return true; } } diff --git a/ButtonCore/src/main/java/buttondevteam/lib/chat/Command2.java b/ButtonCore/src/main/java/buttondevteam/lib/chat/Command2.java index 8327314..03e5dd4 100644 --- a/ButtonCore/src/main/java/buttondevteam/lib/chat/Command2.java +++ b/ButtonCore/src/main/java/buttondevteam/lib/chat/Command2.java @@ -5,7 +5,6 @@ import buttondevteam.lib.player.ChromaGamerBase; import lombok.RequiredArgsConstructor; import lombok.experimental.var; import lombok.val; -import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.YamlConfiguration; import java.io.InputStreamReader; @@ -105,7 +104,8 @@ public abstract class Command2 final ChromaGamerBase cg; if (sendertype.isAssignableFrom(sender.getClass())) params.add(sender); //The command either expects a CommandSender or it is a Player, or some other expected type - else if (CommandSender.class.isAssignableFrom(sendertype) && sender instanceof Command2MCSender) + else if (sender instanceof Command2MCSender + && sendertype.isAssignableFrom(((Command2MCSender) sender).getSender().getClass())) params.add(((Command2MCSender) sender).getSender()); else if (ChromaGamerBase.class.isAssignableFrom(sendertype) && sender instanceof Command2MCSender @@ -238,4 +238,4 @@ public abstract class Command2 public String[] getCommandsText() { return commandHelp.toArray(new String[0]); } -} //TODO: Test support of Player instead of CommandSender +} diff --git a/ButtonCore/src/main/java/buttondevteam/lib/chat/Command2MC.java b/ButtonCore/src/main/java/buttondevteam/lib/chat/Command2MC.java index 4a26622..b7a736c 100644 --- a/ButtonCore/src/main/java/buttondevteam/lib/chat/Command2MC.java +++ b/ButtonCore/src/main/java/buttondevteam/lib/chat/Command2MC.java @@ -12,7 +12,9 @@ public class Command2MC extends Command2 { @Override public boolean hasPermission(Command2MCSender sender, ICommand2MC command) { - return MainPlugin.permission.has(sender.getSender(), "thorpe.command." + command.getCommandPath().replace(' ', '.')); + return command.getClass().getAnnotation(CommandClass.class).modOnly() + ? MainPlugin.permission.has(sender.getSender(), "tbmc.admin") //TODO: Change when groups are implemented + : MainPlugin.permission.has(sender.getSender(), "thorpe.command." + command.getCommandPath().replace(' ', '.')); } /**