mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-22 18:45:29 +01:00
npc hologram margintop/marginbottom
command (#3027)
* Add `npc hologram margin` command * Revert `mb` and `mt` declaration change. * Change `margin` to `margintop` and `marginbottom` Also fix mistake in usage syntax.
This commit is contained in:
parent
3571c05d9d
commit
da2ab6324a
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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}
|
||||
*/
|
||||
|
@ -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";
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user