Add very basic /npc hologram command

This commit is contained in:
fullwall 2020-06-30 18:17:14 +08:00
parent 05cc8de3c7
commit 381f303023
5 changed files with 97 additions and 0 deletions

View File

@ -92,6 +92,7 @@ import net.citizensnpcs.trait.EndermanTrait;
import net.citizensnpcs.trait.FollowTrait; import net.citizensnpcs.trait.FollowTrait;
import net.citizensnpcs.trait.GameModeTrait; import net.citizensnpcs.trait.GameModeTrait;
import net.citizensnpcs.trait.Gravity; import net.citizensnpcs.trait.Gravity;
import net.citizensnpcs.trait.HologramTrait;
import net.citizensnpcs.trait.HorseModifiers; import net.citizensnpcs.trait.HorseModifiers;
import net.citizensnpcs.trait.LookClose; import net.citizensnpcs.trait.LookClose;
import net.citizensnpcs.trait.MountTrait; import net.citizensnpcs.trait.MountTrait;
@ -701,6 +702,25 @@ public class NPCCommands {
Messaging.sendTr(sender, key, npc.getName()); Messaging.sendTr(sender, key, npc.getName());
} }
@Command(
aliases = { "npc" },
usage = "hologram [text]",
desc = "Controls NPC hologram",
modifiers = { "hologram" },
min = 1,
max = -1,
permission = "citizens.npc.hologram")
public void hologram(CommandContext args, CommandSender sender, NPC npc) {
HologramTrait trait = npc.getTrait(HologramTrait.class);
if (args.argsLength() == 1) {
trait.setText(null);
Messaging.sendTr(sender, Messages.HOLOGRAM_TEXT_REMOVED);
} else {
trait.setText(args.getJoinedStrings(1));
Messaging.sendTr(sender, Messages.HOLOGRAM_TEXT_SET);
}
}
@Command( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "horse|llama|donkey|mule (--color color) (--type type) (--style style) (-cb)", usage = "horse|llama|donkey|mule (--color color) (--type type) (--style style) (-cb)",

View File

@ -31,6 +31,7 @@ import net.citizensnpcs.trait.EndermanTrait;
import net.citizensnpcs.trait.FollowTrait; import net.citizensnpcs.trait.FollowTrait;
import net.citizensnpcs.trait.GameModeTrait; import net.citizensnpcs.trait.GameModeTrait;
import net.citizensnpcs.trait.Gravity; import net.citizensnpcs.trait.Gravity;
import net.citizensnpcs.trait.HologramTrait;
import net.citizensnpcs.trait.HorseModifiers; import net.citizensnpcs.trait.HorseModifiers;
import net.citizensnpcs.trait.LookClose; import net.citizensnpcs.trait.LookClose;
import net.citizensnpcs.trait.MountTrait; import net.citizensnpcs.trait.MountTrait;
@ -69,6 +70,7 @@ public class CitizensTraitFactory implements TraitFactory {
registerTrait(TraitInfo.create(GameModeTrait.class)); registerTrait(TraitInfo.create(GameModeTrait.class));
registerTrait(TraitInfo.create(Gravity.class)); registerTrait(TraitInfo.create(Gravity.class));
registerTrait(TraitInfo.create(HorseModifiers.class)); registerTrait(TraitInfo.create(HorseModifiers.class));
registerTrait(TraitInfo.create(HologramTrait.class));
registerTrait(TraitInfo.create(Inventory.class)); registerTrait(TraitInfo.create(Inventory.class));
registerTrait(TraitInfo.create(LookClose.class)); registerTrait(TraitInfo.create(LookClose.class));
registerTrait(TraitInfo.create(OcelotModifiers.class)); registerTrait(TraitInfo.create(OcelotModifiers.class));

View File

@ -0,0 +1,71 @@
package net.citizensnpcs.trait;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.MemoryNPCDataStore;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.NPCRegistry;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;
import net.citizensnpcs.api.util.Placeholders;
/**
* Persists a hologram attached to the NPC.
*/
@TraitName("hologramtrait")
public class HologramTrait extends Trait {
private final NPCRegistry registry = CitizensAPI
.createAnonymousNPCRegistry(new MemoryNPCDataStore());
private NPC hologramNPC;
@Persist
private String text;
public HologramTrait() {
super("hologramtrait");
}
@Override
public void onDespawn() {
if (hologramNPC != null) {
hologramNPC.destroy();
}
}
@Override
public void onSpawn() {
hologramNPC = registry.createNPC(EntityType.ARMOR_STAND, "");
ArmorStandTrait trait = hologramNPC.getTrait(ArmorStandTrait.class);
trait.setVisible(false);
trait.setSmall(true);
hologramNPC.spawn(npc.getStoredLocation());
hologramNPC.getEntity().setInvulnerable(true);
hologramNPC.getEntity().setGravity(false);
}
@Override
public void run() {
if (!npc.isSpawned())
return;
ArmorStand hologram = (ArmorStand) hologramNPC.getEntity();
if (hologram == null)
return;
if (hologram.getVehicle() == null || hologram.getVehicle() != npc.getEntity()) {
if (hologram.getVehicle() != npc.getEntity()) {
hologram.leaveVehicle();
}
npc.getEntity().addPassenger(hologram);
}
if (text != null && !text.isEmpty()) {
hologramNPC.setName(Placeholders.replace(text, null, npc));
} else {
}
}
public void setText(String text) {
this.text = text;
}
}

View File

@ -134,6 +134,8 @@ public class Messages {
public static final String GUIDED_WAYPOINT_EDITOR_ALREADY_TAKEN = "citizens.editors.waypoints.guided.already-taken"; public static final String GUIDED_WAYPOINT_EDITOR_ALREADY_TAKEN = "citizens.editors.waypoints.guided.already-taken";
public static final String GUIDED_WAYPOINT_EDITOR_BEGIN = "citizens.editors.waypoints.guided.begin"; public static final String GUIDED_WAYPOINT_EDITOR_BEGIN = "citizens.editors.waypoints.guided.begin";
public static final String GUIDED_WAYPOINT_EDITOR_END = "citizens.editors.waypoints.guided.end"; public static final String GUIDED_WAYPOINT_EDITOR_END = "citizens.editors.waypoints.guided.end";
public static final String HOLOGRAM_TEXT_REMOVED = "citizens.commands.npc.hologram.text-removed";
public static final String HOLOGRAM_TEXT_SET = "citizens.commands.npc.hologram.text-set";
public static final String HORSE_CHEST_SET = "citizens.commands.npc.horse.chest-set"; public static final String HORSE_CHEST_SET = "citizens.commands.npc.horse.chest-set";
public static final String HORSE_CHEST_UNSET = "citizens.commands.npc.horse.chest-unset"; public static final String HORSE_CHEST_UNSET = "citizens.commands.npc.horse.chest-unset";
public static final String HORSE_COLOR_SET = "citizens.commands.npc.horse.color-set"; public static final String HORSE_COLOR_SET = "citizens.commands.npc.horse.color-set";

View File

@ -87,6 +87,8 @@ citizens.commands.npc.glowing.unset=[[{0}]] is no longer glowing.
citizens.commands.npc.glowing.color-set=[[{0}]]''s glowing color set to {1}]]. citizens.commands.npc.glowing.color-set=[[{0}]]''s glowing color set to {1}]].
citizens.commands.npc.guardian.elder-unset=[[{0}]] is no longer an elder guardian. citizens.commands.npc.guardian.elder-unset=[[{0}]] is no longer an elder guardian.
citizens.commands.npc.guardian.elder-set=[[{0}]] is now an elder guardian. citizens.commands.npc.guardian.elder-set=[[{0}]] is now an elder guardian.
citizens.commands.npc.hologram.text-set=Set hologram text to [[{0}]].
citizens.commands.npc.hologram.text-removed=Removed hologram text.
citizens.commands.npc.horse.chest-set=The horse is now carrying a chest. citizens.commands.npc.horse.chest-set=The horse is now carrying a chest.
citizens.commands.npc.horse.chest-unset=The horse is no longer carrying a chest. citizens.commands.npc.horse.chest-unset=The horse is no longer carrying a chest.
citizens.commands.npc.horse.color-set=The horse''s color was set to [[{0}]]. citizens.commands.npc.horse.color-set=The horse''s color was set to [[{0}]].