diff --git a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java index 29a1aecdd..f17f6f5f4 100644 --- a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -1081,14 +1081,14 @@ public class NPCCommands { @Command( aliases = { "npc" }, - usage = "hologram add [text] | set [line #] [text] | remove [line #] | clear | lineheight [height] | direction [up|down]", + usage = "hologram add [text] | set [line #] [text] | remove [line #] | clear | lineheight [height] | direction [up|down] | margintop [line #] [margin] | marginbottom [line #] [margin]", desc = "Controls NPC hologram text", modifiers = { "hologram" }, min = 1, max = -1, permission = "citizens.npc.hologram") public void hologram(CommandContext args, CommandSender sender, NPC npc, - @Arg(value = 1, completions = { "add", "set", "remove", "clear", "lineheight", "direction" }) String action) + @Arg(value = 1, completions = { "add", "set", "remove", "clear", "lineheight", "direction", "margintop", "marginbottom" }) String action) throws CommandException { HologramTrait trait = npc.getOrAddTrait(HologramTrait.class); if (args.argsLength() == 1) { @@ -1148,6 +1148,32 @@ public class NPCCommands { : HologramDirection.TOP_DOWN; trait.setDirection(direction); Messaging.sendTr(sender, Messages.HOLOGRAM_DIRECTION_SET, Util.prettyEnum(direction)); + } else if (action.equalsIgnoreCase("margintop")) { + if (args.argsLength() == 2) { + throw new CommandException(Messages.HOLOGRAM_INVALID_LINE); + } + int idx = Math.max(0, args.getInteger(2)); + if (idx >= trait.getLines().size()) { + throw new CommandException(Messages.HOLOGRAM_INVALID_LINE); + } + if (args.argsLength() == 3) { + throw new CommandException(Messages.HOLOGRAM_MARGIN_MISSING); + } + trait.setMargin(idx, "top", args.getDouble(3)); + Messaging.sendTr(sender, Messages.HOLOGRAM_MARGIN_SET, idx, "top", args.getDouble(3)); + } else if (action.equalsIgnoreCase("marginbottom")) { + if (args.argsLength() == 2) { + throw new CommandException(Messages.HOLOGRAM_INVALID_LINE); + } + int idx = Math.max(0, args.getInteger(2)); + if (idx >= trait.getLines().size()) { + throw new CommandException(Messages.HOLOGRAM_INVALID_LINE); + } + if (args.argsLength() == 3) { + throw new CommandException(Messages.HOLOGRAM_MARGIN_MISSING); + } + trait.setMargin(idx, "bottom", args.getDouble(3)); + Messaging.sendTr(sender, Messages.HOLOGRAM_MARGIN_SET, idx, "bottom", args.getDouble(3)); } } diff --git a/main/src/main/java/net/citizensnpcs/trait/HologramTrait.java b/main/src/main/java/net/citizensnpcs/trait/HologramTrait.java index eea97c430..073955bf7 100644 --- a/main/src/main/java/net/citizensnpcs/trait/HologramTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/HologramTrait.java @@ -202,7 +202,10 @@ public class HologramTrait extends Trait { public void load(DataKey root) { clear(); for (DataKey key : root.getRelative("lines").getIntegerSubKeys()) { - lines.add(new HologramLine(key.getString(""), true)); + HologramLine line = new HologramLine(key.keyExists("text") ? key.getString("text") : key.getString(""), true); + line.mt = key.keyExists("margin.top") ? key.getDouble("margin.top") : 0.0; + line.mb = key.keyExists("margin.bottom") ? key.getDouble("margin.bottom") : 0.0; + lines.add(line); } } @@ -353,7 +356,9 @@ public class HologramTrait extends Trait { for (HologramLine line : lines) { if (!line.persist) continue; - root.setString("lines." + i, line.text); + root.setString("lines." + i + ".text", line.text); + root.setDouble("lines." + i + ".margin.top", line.mt); + root.setDouble("lines." + i + ".margin.bottom", line.mb); i++; } } @@ -402,6 +407,26 @@ public class HologramTrait extends Trait { reloadLineHolograms(); } + /** + * Sets the margin of a line at a specific index + * + * @param idx + * The index + * @param type + * The margin type, top or bottom + * @param margin + * The margin + */ + public void setMargin(int idx, String type, double margin) { + if (type.equalsIgnoreCase("top")) { + lines.get(idx).mt = margin; + } + else if (type.equalsIgnoreCase("bottom")) { + lines.get(idx).mb = margin; + } + reloadLineHolograms(); + } + /** * Implementation-specific method: {@see NPC.Metadata#HOLOGRAM_LINE_SUPPLIER} */ diff --git a/main/src/main/java/net/citizensnpcs/util/Messages.java b/main/src/main/java/net/citizensnpcs/util/Messages.java index 0eba25a26..019c0be64 100644 --- a/main/src/main/java/net/citizensnpcs/util/Messages.java +++ b/main/src/main/java/net/citizensnpcs/util/Messages.java @@ -158,6 +158,8 @@ public class Messages { public static final String HOLOGRAM_LINE_SET = "citizens.commands.npc.hologram.text-set"; public static final String HOLOGRAM_TEXT_MISSING = "citizens.commands.npc.hologram.text-missing"; public static final String HOLOGRAM_TEXT_REMOVED = "citizens.commands.npc.hologram.text-removed"; + public static final String HOLOGRAM_MARGIN_MISSING = "citizens.commands.npc.hologram.margin-missing"; + public static final String HOLOGRAM_MARGIN_SET = "citizens.commands.npc.hologram.margin-set"; public static final String HOME_TRAIT_DELAY_SET = "citizens.commands.npc.home.delay-set"; public static final String HOME_TRAIT_DISTANCE_SET = "citizens.commands.npc.home.distance-set"; public static final String HOME_TRAIT_LOCATION_SET = "citizens.commands.npc.home.home-set"; diff --git a/main/src/main/resources/messages_en.properties b/main/src/main/resources/messages_en.properties index cae586d5e..e54cfe889 100644 --- a/main/src/main/resources/messages_en.properties +++ b/main/src/main/resources/messages_en.properties @@ -126,6 +126,8 @@ citizens.commands.npc.hologram.line-removed=Removed line [[{0}]]. citizens.commands.npc.hologram.direction-set=Direction set to [[{0}]]. citizens.commands.npc.hologram.line-add=Added a new hologram line: [[{0}]]. citizens.commands.npc.hologram.cleared=Hologram lines cleared. +citizens.commands.npc.hologram.margin-missing=Missing margin to set. +citizens.commands.npc.hologram.margin-set=Set hologram line [[{0}]] margin [[{1}]] to [[{2}]]. citizens.commands.npc.home.home-set=Home set to [[{0}]]. citizens.commands.npc.home.distance-set=Distance before returning home set to [[{0}]] blocks. citizens.commands.npc.home.teleport-set=[[{0}]] will now teleport home.