mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-11-26 04:25:30 +01:00
Started help menu, not sure exactly what it looks like yet
This commit is contained in:
parent
fe7d7cf8f0
commit
c45197c803
@ -19,4 +19,9 @@ logger.pluginenable=Advanced portals have been successfully enabled!
|
||||
logger.plugindisable=Advanced portals are being disabled!
|
||||
logger.plugincrafterror=This version of craftbukkit is not yet supported or something went wrong, please post this message with the version number and the above stacktrace in an issue on GitHub v:%1$s
|
||||
|
||||
command.noargs=%1$s Sorry but you need to specify a sub command, please use \u00Ae/%2$s help \u00Acif you would like a list of possible sub commands.
|
||||
command.noargs=Sorry but you need to specify a sub command, please use \u00Ae/%1$s help \u00Acif you would like a list of possible sub commands.
|
||||
|
||||
command.help.header=\u00Ae--------- \u00Aa%1$s Help - Page %2$s of %3$s\u00Ae ---------------
|
||||
command.help.invalidnum=Sorry but \u00Ae%1$s\u00Ac is not a valid page number.
|
||||
|
||||
command.subcommand.nopermission=Sorry but you don't have permission for that, please use \u00Ae/%1$s help \u00Acif you would like a list of possible sub commands.
|
||||
|
@ -18,6 +18,8 @@ public interface SubCommand {
|
||||
*/
|
||||
boolean onCommand(CommandSenderContainer sender, String[] args);
|
||||
|
||||
boolean hasPermission(CommandSenderContainer sender);
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
|
@ -12,6 +12,8 @@ public class CommandWithSubCommands implements CommandTemplate {
|
||||
|
||||
private final SubCommandRegistry subCommandRegistry;
|
||||
|
||||
private final int subCommandsPerPage = 5;
|
||||
|
||||
public CommandWithSubCommands() {
|
||||
this.subCommandRegistry = new SubCommandRegistry();
|
||||
}
|
||||
@ -37,31 +39,74 @@ public class CommandWithSubCommands implements CommandTemplate {
|
||||
public void onCommand(CommandSenderContainer sender, String commandExecuted, String[] args) {
|
||||
if(args.length > 0) {
|
||||
if(args[0].equalsIgnoreCase("help")) {
|
||||
// TODO start making a help menu
|
||||
int helpPage = 1;
|
||||
String[] subCommands = this.subCommandRegistry.getSubCommands().toArray(new String[0]);
|
||||
int pages = (int) Math.ceil(subCommands.length / (float) this.subCommandsPerPage);
|
||||
if(args.length > 1) {
|
||||
try {
|
||||
helpPage = Integer.parseInt(args[1]);
|
||||
if(helpPage < 0) {
|
||||
helpPage = 1;
|
||||
}
|
||||
else if(helpPage > pages) {
|
||||
helpPage = pages;
|
||||
}
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
sender.sendMessage(Lang.translateInsertVariablesColor("command.help.invalidnum", args[1]));
|
||||
return;
|
||||
}
|
||||
}
|
||||
sender.sendMessage(Lang.translateInsertVariablesColor("command.help.header", commandExecuted, helpPage, pages));
|
||||
int subCommandOffset = (helpPage - 1) * this.subCommandsPerPage;
|
||||
int displayEnd = subCommandOffset + this.subCommandsPerPage;
|
||||
if(displayEnd > subCommands.length) {
|
||||
displayEnd = subCommands.length;
|
||||
}
|
||||
for(; subCommandOffset < displayEnd; subCommandOffset++) {
|
||||
sender.sendMessage("\u00A76/" + commandExecuted + " " + subCommands[subCommandOffset]
|
||||
+ "\u00A7a - " + this.getSubCommand(subCommands[subCommandOffset]).getBasicHelpText());
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(String subCommand : this.subCommandRegistry.getSubCommands()) {
|
||||
if(subCommand.equalsIgnoreCase(args[0])) {
|
||||
this.getSubCommand(subCommand).onCommand(sender, args);
|
||||
for(String subCommandName : this.subCommandRegistry.getSubCommands()) {
|
||||
if(subCommandName.equalsIgnoreCase(args[0])) {
|
||||
SubCommand subCommand = this.getSubCommand(subCommandName);
|
||||
if(subCommand.hasPermission(sender)) {
|
||||
subCommand.onCommand(sender, args);
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateInsertVariablesColor("command.subcommand.nopermission",
|
||||
commandExecuted));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(Lang.translateInsertVariablesColor(Lang.translate("command.noargs"), Lang.translate("messageprefix.negative"), commandExecuted));
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateInsertVariablesColor("command.noargs", commandExecuted));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
|
||||
if(args.length > 0) {
|
||||
for (String subCommand : this.subCommandRegistry.getSubCommands()) {
|
||||
if (subCommand.equalsIgnoreCase(args[0])) {
|
||||
return this.getSubCommand(subCommand).onTabComplete(sender, args);
|
||||
for (String subCommandName : this.subCommandRegistry.getSubCommands()) {
|
||||
if (subCommandName.equalsIgnoreCase(args[0])) {
|
||||
SubCommand subCommand = this.getSubCommand(subCommandName);
|
||||
if(subCommand.hasPermission(sender)) {
|
||||
this.getSubCommand(subCommandName).onTabComplete(sender, args);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return this.subCommandRegistry.getSubCommands();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -39,18 +39,18 @@ public class Lang {
|
||||
}
|
||||
}
|
||||
|
||||
public static String translateInsertVariables(String s, String... args) {
|
||||
public static String translateInsertVariables(String s, Object... args) {
|
||||
String translation = instance.translate(s);
|
||||
for (int i = 1; i <= args.length; i++) {
|
||||
translation = translation.replaceAll("%" + i + "$s", args[i]);
|
||||
translation = translation.replaceAll("%" + i + "$s", args[i].toString());
|
||||
}
|
||||
return translation;
|
||||
}
|
||||
|
||||
public static String translateInsertVariablesColor(String s, String... args) {
|
||||
public static String translateInsertVariablesColor(String s, Object... args) {
|
||||
String translation = instance.translateColor(s);
|
||||
for (int i = 1; i <= args.length; i++) {
|
||||
translation = translation.replaceAll("%" + i + "$s", args[i]);
|
||||
translation = translation.replaceAll("%" + i + "$s", args[i].toString());
|
||||
}
|
||||
return translation;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user