mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-26 12:15:15 +01:00
Fix #336 Create task to generate a commands page
- Fix logic for optional tags - Fix file output format - Add generated file to repository
This commit is contained in:
parent
37918e845c
commit
e5e7e04c2b
@ -12,12 +12,15 @@ import utils.TagReplacer;
|
|||||||
import utils.ToolTask;
|
import utils.ToolTask;
|
||||||
import utils.ToolsConstants;
|
import utils.ToolsConstants;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class CommandPageCreater implements ToolTask {
|
public class CommandPageCreater implements ToolTask {
|
||||||
|
|
||||||
|
private static final String OUTPUT_FILE = ToolsConstants.DOCS_FOLDER + "commands.md";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTaskName() {
|
public String getTaskName() {
|
||||||
return "createCommandPage";
|
return "createCommandPage";
|
||||||
@ -30,20 +33,33 @@ public class CommandPageCreater implements ToolTask {
|
|||||||
+ "commands/command_entry.tpl.md");
|
+ "commands/command_entry.tpl.md");
|
||||||
|
|
||||||
StringBuilder commandsResult = new StringBuilder();
|
StringBuilder commandsResult = new StringBuilder();
|
||||||
for (CommandDescription command : baseCommands) {
|
addCommandsInfo(commandsResult, baseCommands, template, true);
|
||||||
|
|
||||||
|
FileUtils.generateFileFromTemplate(
|
||||||
|
ToolsConstants.TOOLS_SOURCE_ROOT + "commands/commands.tpl.md",
|
||||||
|
OUTPUT_FILE,
|
||||||
|
ANewMap.with("commands", commandsResult.toString()).build());
|
||||||
|
System.out.println("Wrote to '" + OUTPUT_FILE + "' with " + baseCommands.size() + " base commands.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addCommandsInfo(StringBuilder sb, Collection<CommandDescription> commands,
|
||||||
|
final String template, boolean addNewLine) {
|
||||||
|
for (CommandDescription command : commands) {
|
||||||
Map<String, String> tags = ANewMap
|
Map<String, String> tags = ANewMap
|
||||||
.with("command", CommandUtils.constructCommandPath(command))
|
.with("command", CommandUtils.constructCommandPath(command))
|
||||||
.and("description", command.getDetailedDescription())
|
.and("description", command.getDetailedDescription())
|
||||||
.and("arguments", formatArguments(command.getArguments()))
|
.and("arguments", formatArguments(command.getArguments()))
|
||||||
.and("permissions", formatPermissions(command.getCommandPermissions()))
|
.and("permissions", formatPermissions(command.getCommandPermissions()))
|
||||||
.build();
|
.build();
|
||||||
commandsResult.append(TagReplacer.applyReplacements(template, tags));
|
sb.append(TagReplacer.applyReplacements(template, tags));
|
||||||
}
|
|
||||||
|
|
||||||
FileUtils.generateFileFromTemplate(
|
if (!command.getChildren().isEmpty()) {
|
||||||
ToolsConstants.TOOLS_SOURCE_ROOT + "commands/commands.tpl.md",
|
addCommandsInfo(sb, command.getChildren(), template, false);
|
||||||
ToolsConstants.DOCS_FOLDER + "commands.md",
|
}
|
||||||
ANewMap.with("commands", commandsResult.toString()).build());
|
if (addNewLine) {
|
||||||
|
sb.append("\n\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String formatPermissions(CommandPermissions permissions) {
|
private static String formatPermissions(CommandPermissions permissions) {
|
||||||
@ -54,16 +70,16 @@ public class CommandPageCreater implements ToolTask {
|
|||||||
for (PermissionNode node : permissions.getPermissionNodes()) {
|
for (PermissionNode node : permissions.getPermissionNodes()) {
|
||||||
result += node.getNode() + " ";
|
result += node.getNode() + " ";
|
||||||
}
|
}
|
||||||
return result;
|
return result.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String formatArguments(Iterable<CommandArgumentDescription> arguments) {
|
private static String formatArguments(Iterable<CommandArgumentDescription> arguments) {
|
||||||
StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
for (CommandArgumentDescription argument : arguments) {
|
for (CommandArgumentDescription argument : arguments) {
|
||||||
String argumentName = argument.isOptional()
|
String argumentName = argument.isOptional()
|
||||||
? "[" + argument.getDescription() + "]"
|
? "[" + argument.getName() + "]"
|
||||||
: "<" + argument.getDescription() + ">";
|
: "<" + argument.getName() + ">";
|
||||||
result.append(argumentName).append(" ");
|
result.append(" ").append(argumentName);
|
||||||
}
|
}
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
{command}: {description} _{arguments}_
|
- **{command}**{arguments}: {description}[permissions]
|
||||||
[permissions]Permission: {permissions}[/permissions]
|
<br />Requires `{permissions}`[/permissions]
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
## AuthMe commands
|
<!-- {gen_warning} -->
|
||||||
You can use the following commands to use the functions of AuthMe:
|
<!-- File auto-generated on {gen_date}. See commands/commands.tpl.md -->
|
||||||
|
|
||||||
|
## AuthMe Commands
|
||||||
|
You can use the following commands to use the features of AuthMe. Mandatory arguments are marked with `< >`
|
||||||
|
brackets; optional arguments are enclosed in square brackets (`[ ]`).
|
||||||
|
|
||||||
{commands}
|
{commands}
|
||||||
|
91
src/tools/docs/commands.md
Normal file
91
src/tools/docs/commands.md
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
<!-- AUTO-GENERATED FILE! Do not edit this directly -->
|
||||||
|
<!-- File auto-generated on Sat Dec 26 13:56:13 CET 2015. See commands/commands.tpl.md -->
|
||||||
|
|
||||||
|
## AuthMe Commands
|
||||||
|
You can use the following commands to use the features of AuthMe. Mandatory arguments are marked with `< >`
|
||||||
|
brackets; optional arguments are enclosed in square brackets (`[ ]`).
|
||||||
|
|
||||||
|
- **/authme**: The main AuthMeReloaded command. The root for all admin commands.
|
||||||
|
- **/authme help** [query]: View detailed help pages about AuthMeReloaded commands.
|
||||||
|
- **/authme register** <player> <password>: Register the specified player with the specified password.
|
||||||
|
<br />Requires `authme.admin.register`
|
||||||
|
- **/authme unregister** <player>: Unregister the specified player.
|
||||||
|
<br />Requires `authme.admin.unregister`
|
||||||
|
- **/authme forcelogin** [player]: Enforce the specified player to login.
|
||||||
|
<br />Requires `authme.player.canbeforced`
|
||||||
|
- **/authme password** <player> <pwd>: Change the password of a player.
|
||||||
|
<br />Requires `authme.admin.changepassword`
|
||||||
|
- **/authme lastlogin** [player]: View the date of the specified players last login.
|
||||||
|
<br />Requires `authme.admin.lastlogin`
|
||||||
|
- **/authme accounts** [player]: Display all accounts of a player by his player name or IP.
|
||||||
|
<br />Requires `authme.admin.accounts`
|
||||||
|
- **/authme getemail** [player]: Display the email address of the specified player if set.
|
||||||
|
<br />Requires `authme.admin.getemail`
|
||||||
|
- **/authme chgemail** <player> <email>: Change the email address of the specified player.
|
||||||
|
<br />Requires `authme.admin.changemail`
|
||||||
|
- **/authme getip** <player>: Get the IP address of the specified online player.
|
||||||
|
<br />Requires `authme.admin.getip`
|
||||||
|
- **/authme spawn** <player>: Teleport to the spawn.
|
||||||
|
<br />Requires `authme.admin.spawn`
|
||||||
|
- **/authme setspawn**: Change the player's spawn to your current position.
|
||||||
|
<br />Requires `authme.admin.setspawn`
|
||||||
|
- **/authme firstspawn**: Teleport to the first spawn.
|
||||||
|
<br />Requires `authme.admin.firstspawn`
|
||||||
|
- **/authme setfirstspawn**: Change the first player's spawn to your current position.
|
||||||
|
<br />Requires `authme.admin.setfirstspawn`
|
||||||
|
- **/authme purge** <days>: Purge old AuthMeReloaded data longer than the specified amount of days ago.
|
||||||
|
<br />Requires `authme.admin.purge`
|
||||||
|
- **/authme resetpos** <player>: Purge the last know position of the specified player.
|
||||||
|
<br />Requires `authme.admin.purgelastpos`
|
||||||
|
- **/authme purgebannedplayers**: Purge all AuthMeReloaded data for banned players.
|
||||||
|
<br />Requires `authme.admin.purgebannedplayers`
|
||||||
|
- **/authme switchantibot** [mode]: Switch or toggle the AntiBot mode to the specified state.
|
||||||
|
<br />Requires `authme.admin.switchantibot`
|
||||||
|
- **/authme reload**: Reload the AuthMeReloaded plugin.
|
||||||
|
<br />Requires `authme.admin.reload`
|
||||||
|
- **/authme version**: Show detailed information about the installed AuthMeReloaded version, the developers, contributors, and license.
|
||||||
|
|
||||||
|
|
||||||
|
- **/login** <password>: Command to log in using AuthMeReloaded.
|
||||||
|
<br />Requires `authme.player.login`
|
||||||
|
- **/login help** [query]: View detailed help pages about AuthMeReloaded login commands.
|
||||||
|
|
||||||
|
|
||||||
|
- **/logout**: Command to logout using AuthMeReloaded.
|
||||||
|
<br />Requires `authme.player.logout`
|
||||||
|
- **/logout help** [query]: View detailed help pages about AuthMeReloaded logout commands.
|
||||||
|
|
||||||
|
|
||||||
|
- **/register** <password> [verifyPassword]: Command to register using AuthMeReloaded.
|
||||||
|
<br />Requires `authme.player.register`
|
||||||
|
- **/register help** [query]: View detailed help pages about AuthMeReloaded register commands.
|
||||||
|
|
||||||
|
|
||||||
|
- **/unreg** <password>: Command to unregister using AuthMeReloaded.
|
||||||
|
<br />Requires `authme.player.unregister`
|
||||||
|
- **/unreg help** [query]: View detailed help pages about AuthMeReloaded unregister commands.
|
||||||
|
|
||||||
|
|
||||||
|
- **/changepassword** <oldPassword> <newPassword>: Command to change your password using AuthMeReloaded.
|
||||||
|
<br />Requires `authme.player.changepassword`
|
||||||
|
- **/changepassword help** [query]: View detailed help pages about AuthMeReloaded changepassword commands.
|
||||||
|
|
||||||
|
|
||||||
|
- **/email**: The AuthMeReloaded Email command base.
|
||||||
|
- **/email help** [query]: View detailed help pages about AuthMeReloaded email commands.
|
||||||
|
- **/email add** <email> <verifyEmail>: Add a new email address to your account.
|
||||||
|
<br />Requires `authme.player.email.add`
|
||||||
|
- **/email change** <oldEmail> <newEmail>: Change an email address of your account.
|
||||||
|
<br />Requires `authme.player.email.change`
|
||||||
|
- **/email recover** <email>: Recover your account using an Email address by sending a mail containing a new password.
|
||||||
|
<br />Requires `authme.player.email.recover`
|
||||||
|
|
||||||
|
|
||||||
|
- **/captcha** <captcha>: Captcha command for AuthMeReloaded.
|
||||||
|
<br />Requires `authme.player.captcha`
|
||||||
|
- **/captcha help** [query]: View detailed help pages about AuthMeReloaded captcha commands.
|
||||||
|
|
||||||
|
|
||||||
|
- **/converter** <job>: Converter command for AuthMeReloaded.
|
||||||
|
<br />Requires `authme.admin.converter`
|
||||||
|
- **/converter help** [query]: View detailed help pages about AuthMeReloaded converter commands.
|
@ -4,6 +4,8 @@ import fr.xephi.authme.util.StringUtils;
|
|||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class responsible for replacing template tags to actual content.
|
* Class responsible for replacing template tags to actual content.
|
||||||
@ -15,6 +17,9 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class TagReplacer {
|
public class TagReplacer {
|
||||||
|
|
||||||
|
private TagReplacer() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace a template with default tags and custom ones supplied by a map.
|
* Replace a template with default tags and custom ones supplied by a map.
|
||||||
*
|
*
|
||||||
@ -29,11 +34,9 @@ public class TagReplacer {
|
|||||||
final String name = tagRule.getKey();
|
final String name = tagRule.getKey();
|
||||||
final String value = tagRule.getValue();
|
final String value = tagRule.getValue();
|
||||||
|
|
||||||
String replacement = StringUtils.isEmpty(value) ? "" : "\\1";
|
result = replaceOptionalTag(result, name, value)
|
||||||
result = result.replaceAll("\\[" + name + "\\](.*?)\\[/" + name + "\\]", replacement);
|
.replace("{" + name + "}", value);
|
||||||
result = result.replace("{" + tagRule.getKey() + "}", tagRule.getValue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return applyReplacements(result);
|
return applyReplacements(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,5 +52,21 @@ public class TagReplacer {
|
|||||||
.replace("{gen_warning}", "AUTO-GENERATED FILE! Do not edit this directly");
|
.replace("{gen_warning}", "AUTO-GENERATED FILE! Do not edit this directly");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String replaceOptionalTag(String text, String tagName, String tagValue) {
|
||||||
|
Pattern regex = Pattern.compile("\\[" + tagName + "\\](.*?)\\[/" + tagName + "\\]", Pattern.DOTALL);
|
||||||
|
Matcher matcher = regex.matcher(text);
|
||||||
|
|
||||||
|
if (!matcher.find()) {
|
||||||
|
// Couldn't find results, so just return text as it is
|
||||||
|
return text;
|
||||||
|
} else if (StringUtils.isEmpty(tagValue)) {
|
||||||
|
// Tag is empty, replace [tagName]some_text[/tagName] to nothing
|
||||||
|
return matcher.replaceAll("");
|
||||||
|
} else {
|
||||||
|
// Tag is not empty, so replace [tagName]some_text[/tagName] to some_text
|
||||||
|
return matcher.replaceAll(matcher.group(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user