mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-27 19:47:51 +01:00
Add /template list
This commit is contained in:
parent
db7d6035f4
commit
317444c588
@ -86,4 +86,19 @@ public class TemplateCommands {
|
||||
TemplateBuilder.create(name).from(npc).override(args.hasFlag('o')).buildAndSave();
|
||||
Messaging.sendTr(sender, Messages.TEMPLATE_CREATED);
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "template", "tpl" },
|
||||
usage = "list",
|
||||
desc = "Lists available templates",
|
||||
modifiers = { "list" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "citizens.templates.list")
|
||||
public void list(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
Messaging.sendTr(sender, Messages.TEMPLATE_LIST_HEADER);
|
||||
for (Template template : Template.allTemplates()) {
|
||||
Messaging.send(sender, "[[-]] " + template.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ import net.citizensnpcs.api.util.MemoryDataKey;
|
||||
import net.citizensnpcs.api.util.YamlStorage;
|
||||
import net.citizensnpcs.api.util.YamlStorage.YamlKey;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
@ -54,7 +56,6 @@ public class Template {
|
||||
|
||||
private static class Node {
|
||||
String headKey;
|
||||
|
||||
Map<String, Object> map;
|
||||
|
||||
private Node(String headKey, Map<String, Object> map) {
|
||||
@ -102,7 +103,14 @@ public class Template {
|
||||
}
|
||||
}
|
||||
|
||||
private static YamlStorage templates = new YamlStorage(new File(CitizensAPI.getDataFolder(), "templates.yml"));
|
||||
public static Iterable<Template> allTemplates() {
|
||||
return Iterables.transform(templates.getKey("").getSubKeys(), new Function<DataKey, Template>() {
|
||||
@Override
|
||||
public Template apply(DataKey arg0) {
|
||||
return Template.byName(arg0.name());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Template byName(String name) {
|
||||
if (!templates.getKey("").keyExists(name))
|
||||
@ -113,6 +121,8 @@ public class Template {
|
||||
return new Template(name, replacements, override);
|
||||
}
|
||||
|
||||
private static YamlStorage templates = new YamlStorage(new File(CitizensAPI.getDataFolder(), "templates.yml"));
|
||||
|
||||
static {
|
||||
templates.load();
|
||||
}
|
||||
|
@ -201,6 +201,7 @@ public class Messages {
|
||||
public static final String TEMPLATE_APPLIED = "citizens.commands.template.applied";
|
||||
public static final String TEMPLATE_CONFLICT = "citizens.commands.template.conflict";
|
||||
public static final String TEMPLATE_CREATED = "citizens.commands.template.created";
|
||||
public static final String TEMPLATE_LIST_HEADER = "citizens.commands.template.list.header";
|
||||
public static final String TEMPLATE_MISSING = "citizens.commands.template.missing";
|
||||
public static final String TEXT_EDITOR_ADD_PROMPT = "citizens.editors.text.add-prompt";
|
||||
public static final String TEXT_EDITOR_ADDED_ENTRY = "citizens.editors.text.added-entry";
|
||||
|
@ -140,6 +140,7 @@ citizens.commands.template.applied=Template applied to [[{0}]] NPCs.
|
||||
citizens.commands.template.conflict=A template by that name already exists.
|
||||
citizens.commands.template.created=Template created.
|
||||
citizens.commands.template.missing=Template not found.
|
||||
citizens.commands.template.list.header=]]Available templates[[:]]
|
||||
citizens.commands.trait.added=Added {0} successfully.
|
||||
citizens.commands.trait.failed-to-add=<7>Couldn''t add {0}.
|
||||
citizens.commands.trait.failed-to-change=<7>Couldn''t change {0}.
|
||||
|
Loading…
Reference in New Issue
Block a user