mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-29 19:41:50 +01:00
Add /template delete and fix templates
This commit is contained in:
parent
317444c588
commit
1a8a9d1d6e
@ -87,6 +87,22 @@ public class TemplateCommands {
|
||||
Messaging.sendTr(sender, Messages.TEMPLATE_CREATED);
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "template", "tpl" },
|
||||
usage = "delete [template name]",
|
||||
desc = "Deletes a template",
|
||||
modifiers = { "delete" },
|
||||
min = 2,
|
||||
max = 2,
|
||||
permission = "citizens.templates.delete")
|
||||
public void delete(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
String name = args.getString(1);
|
||||
if (Template.byName(name) == null)
|
||||
throw new CommandException(Messages.TEMPLATE_MISSING);
|
||||
Template.byName(name).delete();
|
||||
Messaging.sendTr(sender, Messages.TEMPLATE_DELETED, name);
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "template", "tpl" },
|
||||
usage = "list",
|
||||
|
@ -31,23 +31,29 @@ public class Template {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void apply(NPC npc) {
|
||||
MemoryDataKey memoryKey = new MemoryDataKey();
|
||||
((CitizensNPC) npc).save(memoryKey);
|
||||
npc.save(memoryKey);
|
||||
List<Node> queue = Lists.newArrayList(new Node("", replacements));
|
||||
for (int i = 0; i < queue.size(); i++) {
|
||||
Node node = queue.get(i);
|
||||
for (Entry<String, Object> entry : node.map.entrySet()) {
|
||||
String fullKey = node.headKey + '.' + entry.getKey();
|
||||
String fullKey = node.headKey.isEmpty() ? entry.getKey() : node.headKey + '.' + entry.getKey();
|
||||
if (entry.getValue() instanceof Map<?, ?>) {
|
||||
queue.add(new Node(fullKey, (Map<String, Object>) entry.getValue()));
|
||||
continue;
|
||||
}
|
||||
boolean overwrite = memoryKey.keyExists(fullKey) | override;
|
||||
if (!overwrite)
|
||||
if (!overwrite || fullKey.equals("uuid"))
|
||||
continue;
|
||||
memoryKey.setRaw(fullKey, entry.getValue());
|
||||
}
|
||||
}
|
||||
((CitizensNPC) npc).load(memoryKey);
|
||||
npc.load(memoryKey);
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
templates.load();
|
||||
templates.getKey("").removeKey(name);
|
||||
templates.save();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@ -82,7 +88,7 @@ public class Template {
|
||||
replacements.clear();
|
||||
MemoryDataKey key = new MemoryDataKey();
|
||||
((CitizensNPC) npc).save(key);
|
||||
replacements.putAll(key.getRawTree());
|
||||
replacements.putAll(key.getValuesDeep());
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -92,6 +98,7 @@ public class Template {
|
||||
}
|
||||
|
||||
public void save() {
|
||||
templates.load();
|
||||
DataKey root = templates.getKey(name);
|
||||
root.setBoolean("override", override);
|
||||
root.setRaw("replacements", replacements);
|
||||
@ -104,6 +111,7 @@ public class Template {
|
||||
}
|
||||
|
||||
public static Iterable<Template> allTemplates() {
|
||||
templates.load();
|
||||
return Iterables.transform(templates.getKey("").getSubKeys(), new Function<DataKey, Template>() {
|
||||
@Override
|
||||
public Template apply(DataKey arg0) {
|
||||
@ -113,6 +121,7 @@ public class Template {
|
||||
}
|
||||
|
||||
public static Template byName(String name) {
|
||||
templates.load();
|
||||
if (!templates.getKey("").keyExists(name))
|
||||
return null;
|
||||
YamlKey key = templates.getKey(name);
|
||||
|
@ -26,9 +26,11 @@ public class HumanController extends AbstractEntityController {
|
||||
@Override
|
||||
protected Entity createEntity(final Location at, final NPC npc) {
|
||||
WorldServer ws = ((CraftWorld) at.getWorld()).getHandle();
|
||||
String parseColors = Colorizer.parseColors(npc.getFullName());
|
||||
if (parseColors.length() > 16)
|
||||
parseColors = parseColors.substring(0, 16);
|
||||
final EntityHumanNPC handle = new EntityHumanNPC(ws.getServer().getServer(), ws, new GameProfile(UUID
|
||||
.randomUUID().toString(), Colorizer.parseColors(npc.getFullName()).substring(0, 16)),
|
||||
new PlayerInteractManager(ws), npc);
|
||||
.randomUUID().toString(), parseColors), new PlayerInteractManager(ws), npc);
|
||||
handle.setPositionRotation(at.getX(), at.getY(), at.getZ(), at.getYaw(), at.getPitch());
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
|
@ -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_DELETED = "citizens.commands.template.delete.deleted";
|
||||
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";
|
||||
|
@ -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.delete.deleted=Deleted template [[{0}]].
|
||||
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}.
|
||||
|
Loading…
Reference in New Issue
Block a user