New command system improvements, broadcast toggles, config fixes #62
4 changed files with 21 additions and 10 deletions
|
@ -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.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<TC extends ICommand2, TP extends Command2Sender>
|
|||
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<TC extends ICommand2, TP extends Command2Sender>
|
|||
public String[] getCommandsText() {
|
||||
return commandHelp.toArray(new String[0]);
|
||||
}
|
||||
} //TODO: Test support of Player instead of CommandSender
|
||||
}
|
||||
|
|
|
@ -12,7 +12,9 @@ public class Command2MC extends Command2<ICommand2MC, Command2MCSender> {
|
|||
|
||||
@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(' ', '.'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue