mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-17 04:41:31 +01:00
Update held item status every tick
This commit is contained in:
parent
b12ae2ee66
commit
6fd6d12092
@ -824,15 +824,15 @@ public class NPCCommands {
|
||||
if (args.hasValueFlag("color")) {
|
||||
ChatColor chatColor = Util.matchEnum(ChatColor.values(), args.getFlag("color"));
|
||||
npc.getOrAddTrait(ScoreboardTrait.class).setColor(chatColor);
|
||||
if (!npc.data().has(NPC.GLOWING_METADATA)) {
|
||||
npc.data().setPersistent(NPC.GLOWING_METADATA, true);
|
||||
if (!npc.data().has(NPC.Metadata.GLOWING)) {
|
||||
npc.data().setPersistent(NPC.Metadata.GLOWING, true);
|
||||
}
|
||||
Messaging.sendTr(sender, Messages.GLOWING_COLOR_SET, npc.getName(),
|
||||
chatColor == null ? ChatColor.WHITE + "white" : chatColor + Util.prettyEnum(chatColor));
|
||||
return;
|
||||
}
|
||||
npc.data().setPersistent(NPC.GLOWING_METADATA, !npc.data().get(NPC.GLOWING_METADATA, false));
|
||||
boolean glowing = npc.data().get(NPC.GLOWING_METADATA);
|
||||
npc.data().setPersistent(NPC.Metadata.GLOWING, !npc.data().get(NPC.Metadata.GLOWING, false));
|
||||
boolean glowing = npc.data().get(NPC.Metadata.GLOWING);
|
||||
Messaging.sendTr(sender, glowing ? Messages.GLOWING_SET : Messages.GLOWING_UNSET, npc.getName());
|
||||
}
|
||||
|
||||
@ -2553,11 +2553,12 @@ public class NPCCommands {
|
||||
npc.data().setPersistent(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));
|
||||
Boolean.toString(npc.data().get(NPC.Metadata.USING_OFFHAND_ITEM)));
|
||||
} else {
|
||||
npc.data().setPersistent(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));
|
||||
Messaging.sendTr(sender, Messages.TOGGLED_USING_HELD_ITEM,
|
||||
Boolean.toString(npc.data().get(NPC.Metadata.USING_HELD_ITEM)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -364,14 +364,13 @@ public class CitizensNPC extends AbstractNPC {
|
||||
return;
|
||||
}
|
||||
if (navigator.isNavigating()) {
|
||||
if (!data().has(NPC.Metadata.SWIMMING) || data().<Boolean> get(NPC.Metadata.SWIMMING)) {
|
||||
if (data().get(NPC.Metadata.SWIMMING, true)) {
|
||||
Location currentDest = navigator.getPathStrategy().getCurrentDestination();
|
||||
if (currentDest == null || currentDest.getY() > getStoredLocation().getY()) {
|
||||
NMS.trySwim(getEntity(), SwimmingExaminer.isWaterMob(getEntity()) ? 0.02F : 0.04F);
|
||||
}
|
||||
}
|
||||
} else if (data().has(NPC.Metadata.SWIMMING) ? data().<Boolean> get(NPC.Metadata.SWIMMING)
|
||||
: !SwimmingExaminer.isWaterMob(getEntity())) {
|
||||
} else if (data().<Boolean> get(NPC.Metadata.SWIMMING, !SwimmingExaminer.isWaterMob(getEntity()))) {
|
||||
NMS.trySwim(getEntity());
|
||||
}
|
||||
navigator.run();
|
||||
@ -473,24 +472,15 @@ 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;
|
||||
}
|
||||
NMS.playAnimation(PlayerAnimation.STOP_USE_ITEM, player, 64);
|
||||
NMS.playAnimation(PlayerAnimation.START_USE_MAINHAND_ITEM, player, 64);
|
||||
} else if (offhand) {
|
||||
if (lastState != 2 || updateCounter == 0) {
|
||||
NMS.playAnimation(PlayerAnimation.START_USE_OFFHAND_ITEM, player, 64);
|
||||
lastState = 2;
|
||||
}
|
||||
NMS.playAnimation(PlayerAnimation.STOP_USE_ITEM, player, 64);
|
||||
NMS.playAnimation(PlayerAnimation.START_USE_OFFHAND_ITEM, player, 64);
|
||||
} else {
|
||||
if (lastState != 0) {
|
||||
NMS.playAnimation(PlayerAnimation.STOP_USE_ITEM, player, 64);
|
||||
lastState = 0;
|
||||
}
|
||||
NMS.playAnimation(PlayerAnimation.STOP_USE_ITEM, player, 64);
|
||||
}
|
||||
data().set("using-item-state", lastState);
|
||||
}
|
||||
|
||||
private static final Location CACHE_LOCATION = new Location(null, 0, 0, 0);
|
||||
|
@ -34,12 +34,11 @@ public class ScoreboardTrait extends Trait {
|
||||
}
|
||||
|
||||
public void apply(Team team, boolean nameVisibility) {
|
||||
boolean changed = false;
|
||||
Set<String> newTags = new HashSet<String>(tags);
|
||||
if (SUPPORT_TAGS) {
|
||||
try {
|
||||
if (!npc.getEntity().getScoreboardTags().equals(tags)) {
|
||||
changed = true;
|
||||
justSpawned = true;
|
||||
for (Iterator<String> iterator = npc.getEntity().getScoreboardTags().iterator(); iterator
|
||||
.hasNext();) {
|
||||
String oldTag = iterator.next();
|
||||
@ -60,7 +59,7 @@ public class ScoreboardTrait extends Trait {
|
||||
try {
|
||||
OptionStatus visibility = nameVisibility ? OptionStatus.ALWAYS : OptionStatus.NEVER;
|
||||
if (visibility != team.getOption(Option.NAME_TAG_VISIBILITY)) {
|
||||
changed = true;
|
||||
justSpawned = true;
|
||||
}
|
||||
team.setOption(Option.NAME_TAG_VISIBILITY, visibility);
|
||||
} catch (NoSuchMethodError e) {
|
||||
@ -99,7 +98,7 @@ public class ScoreboardTrait extends Trait {
|
||||
|| (previousGlowingColor != null && color != previousGlowingColor)) {
|
||||
team.setColor(color);
|
||||
previousGlowingColor = color;
|
||||
changed = true;
|
||||
justSpawned = true;
|
||||
}
|
||||
} catch (NoSuchMethodError err) {
|
||||
SUPPORT_GLOWING_COLOR = false;
|
||||
@ -110,11 +109,11 @@ public class ScoreboardTrait extends Trait {
|
||||
&& !team.getPrefix().equals(previousGlowingColor.toString()))) {
|
||||
team.setPrefix(color.toString());
|
||||
previousGlowingColor = color;
|
||||
changed = true;
|
||||
justSpawned = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (changed || justSpawned) {
|
||||
if (justSpawned) {
|
||||
Util.sendTeamPacketToOnlinePlayers(team, 2);
|
||||
justSpawned = false;
|
||||
}
|
||||
@ -139,6 +138,7 @@ public class ScoreboardTrait extends Trait {
|
||||
|
||||
public void setColor(ChatColor color) {
|
||||
this.color = color;
|
||||
justSpawned = true;
|
||||
}
|
||||
|
||||
private static boolean SUPPORT_COLLIDABLE_SETOPTION = true;
|
||||
|
Loading…
Reference in New Issue
Block a user