mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-20 23:21:32 +01:00
Add specific help for some commands, default locale is empty to focus on system locale
This commit is contained in:
parent
d8acbb47ae
commit
a01d871ae3
@ -104,6 +104,10 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
|
||||
((CraftServer) Bukkit.getServer()).enablePlugins(PluginLoadOrder.POSTWORLD);
|
||||
}
|
||||
|
||||
public CommandInfo getCommandInfo(String rootCommand, String modifier) {
|
||||
return commands.getCommand(rootCommand, modifier);
|
||||
}
|
||||
|
||||
public Iterable<CommandInfo> getCommands(String base) {
|
||||
return commands.getCommands(base);
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public class Settings {
|
||||
}
|
||||
},
|
||||
HIGHLIGHT_COLOUR("general.color-scheme.message-highlight", "<e>"),
|
||||
LOCALE("general.translation.locale", "en"),
|
||||
LOCALE("general.translation.locale", ""),
|
||||
MAX_NPC_LIMIT_CHECKS("npc.limits.max-permission-checks", 100),
|
||||
MAX_SPEED("npc.limits.max-speed", 100),
|
||||
MESSAGE_COLOUR("general.color-scheme.message", "<a>"),
|
||||
|
@ -35,6 +35,7 @@ import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
public class CommandManager {
|
||||
@ -155,8 +156,8 @@ public class CommandManager {
|
||||
|
||||
EntityType type = npc.getTrait(MobType.class).getType();
|
||||
if (!types.contains(type)) {
|
||||
throw new RequirementMissingException(Messaging.tr(Messages.COMMAND_REQUIREMENTS_INVALID_MOB_TYPE,
|
||||
type.getName()));
|
||||
throw new RequirementMissingException(Messaging.tr(
|
||||
Messages.COMMAND_REQUIREMENTS_INVALID_MOB_TYPE, type.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -187,6 +188,19 @@ public class CommandManager {
|
||||
return cmds.toArray(new String[cmds.size()]);
|
||||
}
|
||||
|
||||
public CommandInfo getCommand(String rootCommand, String modifier) {
|
||||
String joined = Joiner.on(' ').join(rootCommand, modifier);
|
||||
for (Entry<String, Method> entry : commands.entrySet()) {
|
||||
if (!entry.getKey().equalsIgnoreCase(joined))
|
||||
continue;
|
||||
Command commandAnnotation = entry.getValue().getAnnotation(Command.class);
|
||||
if (commandAnnotation == null)
|
||||
continue;
|
||||
return new CommandInfo(commandAnnotation, requirements.get(entry.getValue()));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<CommandInfo> getCommands(String command) {
|
||||
List<CommandInfo> cmds = new ArrayList<CommandInfo>();
|
||||
for (Entry<String, Method> entry : commands.entrySet()) {
|
||||
|
@ -28,7 +28,7 @@ public class AdminCommands {
|
||||
" "
|
||||
+ StringHelper.wrapHeader("<e>Citizens v" + plugin.getDescription().getVersion()));
|
||||
Messaging.send(player, " <7>-- <c>Written by fullwall and aPunch");
|
||||
Messaging.send(player, " <7>-- <c>Source: http://github.com/CitizensDev");
|
||||
Messaging.send(player, " <7>-- <c>Source Code: http://github.com/CitizensDev");
|
||||
Messaging.send(player, " <7>-- <c>Website: " + plugin.getDescription().getWebsite());
|
||||
}
|
||||
|
||||
@ -55,6 +55,7 @@ public class AdminCommands {
|
||||
aliases = { "citizens" },
|
||||
usage = "save (-a)",
|
||||
desc = "Save NPCs",
|
||||
help = Messages.COMMAND_SAVE_HELP,
|
||||
modifiers = { "save" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
|
@ -16,6 +16,7 @@ import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.Paginator;
|
||||
import net.citizensnpcs.util.StringHelper;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
@ -57,9 +58,7 @@ public class HelpCommands {
|
||||
|| (!sender.hasPermission("citizens.admin") && !sender.hasPermission("citizens."
|
||||
+ command.permission())))
|
||||
continue;
|
||||
lines.add("<7>/<c>" + command.aliases()[0]
|
||||
+ (command.usage().isEmpty() ? "" : " " + command.usage()) + " <7>- <e>"
|
||||
+ Messaging.tryTranslate(command.desc()));
|
||||
lines.add(format(command));
|
||||
if (command.modifiers().length > 1)
|
||||
processed.add(info);
|
||||
}
|
||||
@ -113,9 +112,16 @@ public class HelpCommands {
|
||||
throw new CommandException(Messages.COMMAND_PAGE_MISSING, page);
|
||||
}
|
||||
|
||||
private void sendSpecificHelp(CommandSender sender, String string, String string2) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
private void sendSpecificHelp(CommandSender sender, String rootCommand, String modifier)
|
||||
throws CommandException {
|
||||
CommandInfo info = plugin.getCommandInfo(rootCommand, modifier);
|
||||
if (info == null)
|
||||
throw new CommandException(Messages.COMMAND_MISSING, rootCommand + " " + modifier);
|
||||
Messaging.send(sender, format(info.getCommandAnnotation()));
|
||||
String help = Messaging.tryTranslate(info.getCommandAnnotation().help());
|
||||
if (help.isEmpty())
|
||||
return;
|
||||
Messaging.send(sender, ChatColor.AQUA + help);
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -155,4 +161,11 @@ public class HelpCommands {
|
||||
}
|
||||
sendHelp(sender, "waypoints", page);
|
||||
}
|
||||
|
||||
private static final String COMMAND_FORMAT = "<7>/<c>%s%s <7>- <e>%s";
|
||||
|
||||
private static final String format(Command command) {
|
||||
return String.format(COMMAND_FORMAT, command.aliases()[0], (command.usage().isEmpty() ? "" : " "
|
||||
+ command.usage()), Messaging.tryTranslate(command.desc()));
|
||||
}
|
||||
}
|
@ -68,6 +68,7 @@ public class NPCCommands {
|
||||
aliases = { "npc" },
|
||||
usage = "age [age] (-l)",
|
||||
desc = "Set the age of a NPC",
|
||||
help = Messages.COMMAND_AGE_HELP,
|
||||
flags = "l",
|
||||
modifiers = { "age" },
|
||||
min = 1,
|
||||
@ -111,6 +112,7 @@ public class NPCCommands {
|
||||
aliases = { "npc" },
|
||||
usage = "behaviour [scripts] (-r)",
|
||||
desc = "Sets the behaviour of a NPC",
|
||||
help = Messages.BEHAVIOUR_HELP,
|
||||
modifiers = { "behaviour", "ai" },
|
||||
flags = "r",
|
||||
min = 2,
|
||||
|
@ -10,6 +10,7 @@ public class Messages {
|
||||
public static final String ALREADY_IN_EDITOR = "citizens.editors.already-in-editor";
|
||||
public static final String ALREADY_OWNER = "citizens.commands.npc.owner.already-owner";
|
||||
public static final String AVAILABLE_WAYPOINT_PROVIDERS = "citizens.waypoints.available-providers-header";
|
||||
public static final String BEHAVIOUR_HELP = "citizens.commands.npc.behaviour.help";
|
||||
public static final String BEHAVIOURS_ADDED = "citizens.commands.npc.behaviour.added";
|
||||
public static final String BEHAVIOURS_REMOVED = "citizens.commands.npc.behaviour.removed";
|
||||
public static final String CITIZENS_DISABLED = "citizens.notifications.disabled";
|
||||
@ -21,10 +22,12 @@ public class Messages {
|
||||
public static final String CITIZENS_RELOADING = "citizens.notifications.reloading";
|
||||
public static final String CITIZENS_SAVED = "citizens.notifications.saved";
|
||||
public static final String CITIZENS_SAVING = "citizens.notifications.saving";
|
||||
public static final String COMMAND_AGE_HELP = "citizens.commands.npc.age.help";
|
||||
public static final String COMMAND_HELP_HEADER = "citizens.commands.help.header";
|
||||
public static final String COMMAND_ID_NOT_FOUND = "citizens.commands.id-not-found";
|
||||
public static final String COMMAND_INVALID_MOBTYPE = "citizens.commands.invalid-mobtype";
|
||||
public static final String COMMAND_INVALID_NUMBER = "citizens.commands.invalid-number";
|
||||
public static final String COMMAND_MISSING = "citizens.commands.help.command-missing";
|
||||
public static final String COMMAND_MISSING_TRAIT = "citizens.commands.requirements.missing-required-trait";
|
||||
public static final String COMMAND_MUST_BE_INGAME = "citizens.commands.requirements.must-be-ingame";
|
||||
public static final String COMMAND_MUST_BE_OWNER = "citizens.commands.requirements.must-be-owner";
|
||||
@ -32,6 +35,7 @@ public class Messages {
|
||||
public static final String COMMAND_PAGE_MISSING = "citizens.commands.page-missing";
|
||||
public static final String COMMAND_REPORT_ERROR = "citizens.commands.console-error";
|
||||
public static final String COMMAND_REQUIREMENTS_INVALID_MOB_TYPE = "citizens.commands.requirements.disallowed-mobtype";
|
||||
public static final String COMMAND_SAVE_HELP = "citizens.commands.citizens.save.help";
|
||||
public static final String CONTROLLABLE_REMOVED = "citizens.commands.npc.controllable.removed";
|
||||
public static final String CONTROLLABLE_SET = "citizens.commands.npc.controllable.set";
|
||||
public static final String CURRENT_WAYPOINT_PROVIDER = "citizens.waypoints.current-provider";
|
||||
|
@ -98,6 +98,8 @@ public class Messaging {
|
||||
}
|
||||
|
||||
public static String tryTranslate(Object possible) {
|
||||
if (possible == null)
|
||||
return "";
|
||||
String message = possible.toString();
|
||||
int count = 0;
|
||||
for (int i = 0; i < message.length(); i++) {
|
||||
|
@ -1,12 +1,16 @@
|
||||
citizens.changed-implementation=Citizens implementation changed, disabling plugin.
|
||||
citizens.commands.citizens.save.help=Use the -a flag to save async (off the main server thread).
|
||||
citizens.commands.console-error=Please report this error: [See console]
|
||||
citizens.commands.help.header=Help
|
||||
citizens.commands.npc.behaviour.help=The scripts argument is a comma-separated list of file names. Scripts will be loaded automatically and run every tick. Use the [[-r]] flag to remove behaviours.
|
||||
citizens.commands.npc.age.help=Can only be used on entities that can become babies. Use the [[-l]] flag to lock age over time (note: relogs may be required to see this).
|
||||
citizens.commands.id-not-found=Couldn't find any NPC with ID {0}.
|
||||
citizens.commands.invalid-mobtype={0} is not a valid mobtype.
|
||||
citizens.commands.invalid-number=That is not a valid number.
|
||||
citizens.commands.npc.age.cannot-be-aged=The mob type '{0}' cannot be aged.
|
||||
citizens.commands.npc.age.invalid-age=Invalid age. Valid ages are adult, baby, number between -24000 and 0
|
||||
citizens.commands.npc.age.locked=Age locked.
|
||||
citizens.commands.help.command-missing=Command /{0} not found.
|
||||
citizens.commands.npc.age.set-adult=[[{0}]] is now an adult.
|
||||
citizens.commands.npc.age.set-baby=[[{0}]] is now a baby.
|
||||
citizens.commands.npc.age.set-normal=[[{0}]] is now age [[{1}]].
|
||||
|
Loading…
Reference in New Issue
Block a user