mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-27 09:42:37 +01:00
Add /npc useitem
This commit is contained in:
parent
88ab30840b
commit
a29fb3059a
@ -2506,6 +2506,27 @@ public class NPCCommands {
|
||||
Messaging.sendTr(sender, Messages.ENTITY_TYPE_SET, npc.getName(), args.getString(1));
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "useitem (-o(ffhand))",
|
||||
desc = "Sets an NPC to be using their held items",
|
||||
modifiers = { "useitem" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
flags = "o",
|
||||
permission = "citizens.npc.useitem")
|
||||
public void useitem(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
boolean offhand = args.hasFlag('o');
|
||||
if (offhand) {
|
||||
npc.data().set(NPC.Metadata.USING_OFFHAND_ITEM, !npc.data().get(NPC.Metadata.USING_OFFHAND_ITEM, false));
|
||||
Messaging.sendTr(sender, Messages.TOGGLED_USING_OFFHAND_ITEM,
|
||||
npc.data().get(NPC.Metadata.USING_OFFHAND_ITEM));
|
||||
} else {
|
||||
npc.data().set(NPC.Metadata.USING_HELD_ITEM, !npc.data().get(NPC.Metadata.USING_HELD_ITEM, false));
|
||||
Messaging.sendTr(sender, Messages.TOGGLED_USING_HELD_ITEM, npc.data().get(NPC.Metadata.USING_HELD_ITEM));
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "vulnerable (-t)",
|
||||
|
@ -49,6 +49,7 @@ import net.citizensnpcs.trait.SneakTrait;
|
||||
import net.citizensnpcs.util.ChunkCoord;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.PlayerAnimation;
|
||||
import net.citizensnpcs.util.PlayerUpdateTask;
|
||||
import net.citizensnpcs.util.Util;
|
||||
|
||||
@ -374,8 +375,8 @@ public class CitizensNPC extends AbstractNPC {
|
||||
}
|
||||
|
||||
boolean isLiving = getEntity() instanceof LivingEntity;
|
||||
if (updateCounter++ > data().<Integer> get(NPC.Metadata.PACKET_UPDATE_DELAY,
|
||||
Setting.PACKET_UPDATE_DELAY.asInt())) {
|
||||
int packetUpdateDelay = data().get(NPC.Metadata.PACKET_UPDATE_DELAY, Setting.PACKET_UPDATE_DELAY.asInt());
|
||||
if (updateCounter++ > packetUpdateDelay) {
|
||||
if (Setting.KEEP_CHUNKS_LOADED.asBoolean()) {
|
||||
ChunkCoord currentCoord = new ChunkCoord(getStoredLocation());
|
||||
if (!currentCoord.equals(cachedCoord)) {
|
||||
@ -396,6 +397,9 @@ public class CitizensNPC extends AbstractNPC {
|
||||
if (isLiving) {
|
||||
NMS.setKnockbackResistance((LivingEntity) getEntity(), isProtected() ? 1D : 0D);
|
||||
}
|
||||
if (isLiving && getEntity() instanceof Player) {
|
||||
updateUsingItemState((Player) getEntity());
|
||||
}
|
||||
|
||||
if (SUPPORT_SILENT && data().has(NPC.SILENT_METADATA)) {
|
||||
try {
|
||||
@ -458,6 +462,29 @@ public class CitizensNPC extends AbstractNPC {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateUsingItemState(Player player) {
|
||||
boolean useItem = data().get(NPC.Metadata.USING_HELD_ITEM, false),
|
||||
offhand = data().get(NPC.Metadata.USING_OFFHAND_ITEM, false);
|
||||
int lastState = data().get("using-item-state", 0);
|
||||
if (useItem) {
|
||||
if (lastState != 1 || updateCounter == 0) {
|
||||
NMS.playAnimation(PlayerAnimation.START_USE_MAINHAND_ITEM, player, 64);
|
||||
lastState = 1;
|
||||
}
|
||||
} else if (offhand) {
|
||||
if (lastState != 2 || updateCounter == 0) {
|
||||
NMS.playAnimation(PlayerAnimation.START_USE_OFFHAND_ITEM, player, 64);
|
||||
lastState = 2;
|
||||
}
|
||||
} else {
|
||||
if (lastState != 0) {
|
||||
NMS.playAnimation(PlayerAnimation.STOP_USE_ITEM, player, 64);
|
||||
lastState = 0;
|
||||
}
|
||||
}
|
||||
data().set("using-item-state", lastState);
|
||||
}
|
||||
|
||||
private static final Location CACHE_LOCATION = new Location(null, 0, 0, 0);
|
||||
private static final SetMultimap<ChunkCoord, NPC> CHUNK_LOADERS = HashMultimap.create();
|
||||
private static final String NPC_METADATA_MARKER = "NPC";
|
||||
|
@ -369,6 +369,8 @@ public class Messages {
|
||||
public static final String TEXT_EDITOR_SPEECH_BUBBLES_SET = "citizens.editors.text.speech-bubbles-set";
|
||||
public static final String TEXT_EDITOR_START_PROMPT = "citizens.editors.text.start-prompt";
|
||||
public static final String TO_ENTITY_NOT_FOUND = "citizens.commands.npc.tpto.to-not-found";
|
||||
public static final String TOGGLED_USING_HELD_ITEM = "citizens.commands.npc.useitem.held-item-toggled";
|
||||
public static final String TOGGLED_USING_OFFHAND_ITEM = "citizens.commands.npc.useitem.offhand-item-toggled";
|
||||
public static final String TPTO_SUCCESS = "citizens.commands.npc.tpto.success";
|
||||
public static final String TRAIT_LOAD_FAILED = "citizens.notifications.trait-load-failed";
|
||||
public static final String TRAIT_NOT_CONFIGURABLE = "citizens.commands.traitc.not-configurable";
|
||||
|
@ -245,6 +245,8 @@ citizens.commands.npc.tphere.missing-cursor-block=Please look at a block to tele
|
||||
citizens.commands.npc.tphere.teleported=[[{0}]] was teleported to {1}.
|
||||
citizens.commands.npc.type.set=[[{0}]]''s type set to [[{1}]].
|
||||
citizens.commands.npc.type.invalid=[[{0}]] is not a valid type.
|
||||
citizens.commands.npc.useitem.held-item-toggled=Using held item set to [[{0}]].
|
||||
citizens.commands.npc.useitem.offhand-item-toggled=Using offhand item set to [[{0}]].
|
||||
citizens.commands.npc.vulnerable.set=[[{0}]] is now vulnerable.
|
||||
citizens.commands.npc.vulnerable.stopped=[[{0}]] is no longer vulnerable.
|
||||
citizens.commands.npc.wolf.unknown-collar-color=[[{0}]] is not an RGB-formatted collar color or the name of a DyeColor.
|
||||
|
Loading…
Reference in New Issue
Block a user