mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-02 05:21:47 +01:00
Add /npc bossbar --track and fix equipment caching logic
This commit is contained in:
parent
48798ff9b3
commit
3685d33980
@ -165,16 +165,17 @@ public class NPCCommands {
|
||||
Messaging.sendTr(sender, trait.toggle() ? Messages.AGE_LOCKED : Messages.AGE_UNLOCKED);
|
||||
}
|
||||
if (args.argsLength() <= 1) {
|
||||
if (!toggleLock)
|
||||
if (!toggleLock) {
|
||||
trait.describe(sender);
|
||||
}
|
||||
return;
|
||||
}
|
||||
int age = 0;
|
||||
try {
|
||||
age = args.getInteger(1);
|
||||
if (age > 0) {
|
||||
if (age > 0)
|
||||
throw new CommandException(Messages.INVALID_AGE);
|
||||
}
|
||||
|
||||
Messaging.sendTr(sender, Messages.AGE_SET_NORMAL, npc.getName(), age);
|
||||
} catch (NumberFormatException ex) {
|
||||
if (args.getString(1).equalsIgnoreCase("baby")) {
|
||||
@ -535,12 +536,14 @@ public class NPCCommands {
|
||||
Messaging.sendErrorTr(sender, Messages.NPC_NAME_TOO_LONG, nameLength);
|
||||
name = name.substring(0, nameLength);
|
||||
}
|
||||
|
||||
if (name.length() == 0)
|
||||
throw new CommandException();
|
||||
|
||||
if (!sender.hasPermission("citizens.npc.create.*") && !sender.hasPermission("citizens.npc.createall")
|
||||
&& !sender.hasPermission("citizens.npc.create." + type.name().toLowerCase().replace("_", "")))
|
||||
throw new NoPermissionsException();
|
||||
|
||||
NPCRegistry registry = CitizensAPI.getNPCRegistry();
|
||||
if (args.hasValueFlag("registry")) {
|
||||
registry = CitizensAPI.getNamedNPCRegistry(args.getFlag("registry"));
|
||||
@ -554,14 +557,14 @@ public class NPCCommands {
|
||||
}
|
||||
|
||||
npc = registry.createNPC(type, name);
|
||||
String msg = "You created [[" + npc.getName() + "]] (ID [[" + npc.getId() + "]])";
|
||||
String msg = "Created [[" + npc.getName() + "]] (ID [[" + npc.getId() + "]])";
|
||||
|
||||
int age = 0;
|
||||
if (args.hasFlag('b')) {
|
||||
if (!Ageable.class.isAssignableFrom(type.getEntityClass()))
|
||||
if (!Ageable.class.isAssignableFrom(type.getEntityClass())) {
|
||||
Messaging.sendErrorTr(sender, Messages.MOBTYPE_CANNOT_BE_AGED,
|
||||
type.name().toLowerCase().replace("_", "-"));
|
||||
else {
|
||||
} else {
|
||||
age = -24000;
|
||||
msg += " as a baby";
|
||||
}
|
||||
|
@ -197,9 +197,11 @@ public class HologramTrait extends Trait {
|
||||
onDespawn();
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentLoc == null) {
|
||||
currentLoc = npc.getStoredLocation();
|
||||
}
|
||||
|
||||
boolean nameplateVisible = Boolean
|
||||
.parseBoolean(npc.data().<Object> get(NPC.Metadata.NAMEPLATE_VISIBLE, true).toString());
|
||||
if (npc.requiresNameHologram()) {
|
||||
@ -210,6 +212,7 @@ public class HologramTrait extends Trait {
|
||||
nameNPC = createHologram(npc.getFullName(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
boolean update = currentLoc.getWorld() != npc.getStoredLocation().getWorld()
|
||||
|| currentLoc.distance(npc.getStoredLocation()) >= 0.001 || lastNameplateVisible != nameplateVisible
|
||||
|| Math.abs(lastEntityHeight - getEntityHeight()) >= 0.05;
|
||||
@ -219,28 +222,34 @@ public class HologramTrait extends Trait {
|
||||
currentLoc = npc.getStoredLocation();
|
||||
lastEntityHeight = getEntityHeight();
|
||||
}
|
||||
|
||||
if (nameNPC != null && nameNPC.isSpawned()) {
|
||||
if (update) {
|
||||
nameNPC.teleport(currentLoc.clone().add(0, getEntityHeight(), 0), TeleportCause.PLUGIN);
|
||||
}
|
||||
nameNPC.setName(npc.getFullName());
|
||||
}
|
||||
|
||||
for (int i = 0; i < lineHolograms.size(); i++) {
|
||||
NPC hologramNPC = lineHolograms.get(i);
|
||||
if (!hologramNPC.isSpawned())
|
||||
continue;
|
||||
|
||||
if (update) {
|
||||
hologramNPC.teleport(currentLoc.clone().add(0, getEntityHeight() + getHeight(i), 0),
|
||||
TeleportCause.PLUGIN);
|
||||
}
|
||||
|
||||
if (i >= lines.size()) {
|
||||
Messaging.severe("More hologram NPCs than lines for ID", npc.getId(), "lines", lines);
|
||||
break;
|
||||
}
|
||||
|
||||
String text = lines.get(i);
|
||||
if (ITEM_MATCHER.matcher(text).matches()) {
|
||||
text = null;
|
||||
}
|
||||
|
||||
if (text != null && !ChatColor.stripColor(Colorizer.parseColors(text)).isEmpty()) {
|
||||
hologramNPC.setName(Placeholders.replace(text, null, npc));
|
||||
hologramNPC.data().set(NPC.Metadata.NAMEPLATE_VISIBLE, true);
|
||||
@ -280,6 +289,7 @@ public class HologramTrait extends Trait {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
onDespawn();
|
||||
onSpawn();
|
||||
}
|
||||
|
@ -4,12 +4,14 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.boss.BarFlag;
|
||||
import org.bukkit.boss.BarStyle;
|
||||
import org.bukkit.boss.BossBar;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
@ -18,6 +20,7 @@ import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.persistence.Persist;
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
import net.citizensnpcs.api.trait.TraitName;
|
||||
import net.citizensnpcs.api.util.Placeholders;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
|
||||
@TraitName("bossbar")
|
||||
@ -31,6 +34,8 @@ public class BossBarTrait extends Trait {
|
||||
private BarStyle style = BarStyle.SOLID;
|
||||
@Persist("title")
|
||||
private String title = "";
|
||||
@Persist("track")
|
||||
private String track;
|
||||
@Persist("visible")
|
||||
private boolean visible = true;
|
||||
|
||||
@ -64,6 +69,10 @@ public class BossBarTrait extends Trait {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getTrackingVariable() {
|
||||
return track;
|
||||
}
|
||||
|
||||
private boolean isBoss(Entity entity) {
|
||||
boolean isBoss = entity.getType() == EntityType.ENDER_DRAGON || entity.getType() == EntityType.WITHER
|
||||
|| entity.getType() == EntityType.GUARDIAN;
|
||||
@ -94,6 +103,29 @@ public class BossBarTrait extends Trait {
|
||||
if (bar == null) {
|
||||
return;
|
||||
}
|
||||
if (track != null && !track.isEmpty() && npc.getEntity() instanceof LivingEntity) {
|
||||
LivingEntity entity = (LivingEntity) npc.getEntity();
|
||||
if (track.equalsIgnoreCase("health")) {
|
||||
double maxHealth = entity.getMaxHealth();
|
||||
if (SUPPORT_ATTRIBUTES) {
|
||||
try {
|
||||
maxHealth = entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
|
||||
} catch (Throwable t) {
|
||||
SUPPORT_ATTRIBUTES = false;
|
||||
}
|
||||
}
|
||||
bar.setProgress(entity.getHealth() / maxHealth);
|
||||
} else {
|
||||
String replaced = Placeholders.replace(track,
|
||||
npc.getEntity() instanceof Player ? (Player) npc.getEntity() : null);
|
||||
if (!track.equals(replaced)) {
|
||||
try {
|
||||
bar.setProgress(Double.parseDouble(replaced));
|
||||
} catch (NumberFormatException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
bar.setStyle(style);
|
||||
bar.setVisible(visible);
|
||||
if (color != null) {
|
||||
@ -139,7 +171,13 @@ public class BossBarTrait extends Trait {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public void setTrackVariable(String variable) {
|
||||
this.track = variable;
|
||||
}
|
||||
|
||||
public void setVisible(boolean visible) {
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
private static boolean SUPPORT_ATTRIBUTES = true;
|
||||
}
|
||||
|
@ -410,7 +410,10 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
|
||||
private void updatePackets(boolean navigating) {
|
||||
updateCounter++;
|
||||
if (updateCounter++ <= npc.data().<Integer> get(NPC.Metadata.PACKET_UPDATE_DELAY,
|
||||
Setting.PACKET_UPDATE_DELAY.asInt()))
|
||||
return;
|
||||
updateCounter = 0;
|
||||
boolean itemChanged = false;
|
||||
for (EnumItemSlot slot : EnumItemSlot.values()) {
|
||||
ItemStack equipment = getEquipment(slot);
|
||||
@ -421,10 +424,8 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
equipmentCache.put(slot, equipment);
|
||||
}
|
||||
if (updateCounter++ <= npc.data().<Integer> get(NPC.Metadata.PACKET_UPDATE_DELAY,
|
||||
Setting.PACKET_UPDATE_DELAY.asInt()) && !itemChanged)
|
||||
if (!itemChanged)
|
||||
return;
|
||||
updateCounter = 0;
|
||||
Location current = getBukkitEntity().getLocation(packetLocationCache);
|
||||
Packet<?>[] packets = new Packet[EnumItemSlot.values().length];
|
||||
int i = 0;
|
||||
|
@ -30,7 +30,7 @@ import net.citizensnpcs.util.Util;
|
||||
public class Commands {
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "bossbar --style [style] --color [color] --title [title] --visible [visible] --flags [flags]",
|
||||
usage = "bossbar --style [style] --color [color] --title [title] --visible [visible] --flags [flags] --track [health | placeholder]",
|
||||
desc = "Edit bossbar properties",
|
||||
modifiers = { "bossbar" },
|
||||
min = 1,
|
||||
@ -50,6 +50,9 @@ public class Commands {
|
||||
trait.setColor(color);
|
||||
}
|
||||
}
|
||||
if (args.hasValueFlag("track")) {
|
||||
trait.setTrackVariable(args.getFlag("track"));
|
||||
}
|
||||
if (args.hasValueFlag("title")) {
|
||||
trait.setTitle(Colorizer.parseColors(args.getFlag("title")));
|
||||
}
|
||||
|
@ -416,7 +416,10 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
|
||||
private void updatePackets(boolean navigating) {
|
||||
updateCounter++;
|
||||
if (updateCounter++ <= npc.data().<Integer> get(NPC.Metadata.PACKET_UPDATE_DELAY,
|
||||
Setting.PACKET_UPDATE_DELAY.asInt()))
|
||||
return;
|
||||
updateCounter = 0;
|
||||
boolean itemChanged = false;
|
||||
for (EnumItemSlot slot : EnumItemSlot.values()) {
|
||||
ItemStack equipment = getEquipment(slot);
|
||||
@ -427,11 +430,9 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
equipmentCache.put(slot, equipment);
|
||||
}
|
||||
if (updateCounter++ <= npc.data().<Integer> get(NPC.Metadata.PACKET_UPDATE_DELAY,
|
||||
Setting.PACKET_UPDATE_DELAY.asInt()) && !itemChanged)
|
||||
if (!itemChanged)
|
||||
return;
|
||||
|
||||
updateCounter = 0;
|
||||
Location current = getBukkitEntity().getLocation(packetLocationCache);
|
||||
Packet<?>[] packets = new Packet[EnumItemSlot.values().length];
|
||||
int i = 0;
|
||||
|
@ -33,7 +33,7 @@ import net.citizensnpcs.util.Util;
|
||||
public class Commands {
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "bossbar --style [style] --color [color] --title [title] --visible [visible] --flags [flags]",
|
||||
usage = "bossbar --style [style] --color [color] --title [title] --visible [visible] --flags [flags] --track [health | placeholder]",
|
||||
desc = "Edit bossbar properties",
|
||||
modifiers = { "bossbar" },
|
||||
min = 1,
|
||||
@ -53,6 +53,9 @@ public class Commands {
|
||||
trait.setColor(color);
|
||||
}
|
||||
}
|
||||
if (args.hasValueFlag("track")) {
|
||||
trait.setTrackVariable(args.getFlag("track"));
|
||||
}
|
||||
if (args.hasValueFlag("title")) {
|
||||
trait.setTitle(Colorizer.parseColors(args.getFlag("title")));
|
||||
}
|
||||
|
@ -442,7 +442,10 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
|
||||
private void updatePackets(boolean navigating) {
|
||||
updateCounter++;
|
||||
if (updateCounter++ <= npc.data().<Integer> get(NPC.Metadata.PACKET_UPDATE_DELAY,
|
||||
Setting.PACKET_UPDATE_DELAY.asInt()))
|
||||
return;
|
||||
updateCounter = 0;
|
||||
boolean itemChanged = false;
|
||||
for (EnumItemSlot slot : EnumItemSlot.values()) {
|
||||
ItemStack equipment = getEquipment(slot);
|
||||
@ -453,11 +456,9 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
equipmentCache.put(slot, equipment);
|
||||
}
|
||||
if (updateCounter++ <= npc.data().<Integer> get(NPC.Metadata.PACKET_UPDATE_DELAY,
|
||||
Setting.PACKET_UPDATE_DELAY.asInt()) && !itemChanged)
|
||||
if (!itemChanged)
|
||||
return;
|
||||
|
||||
updateCounter = 0;
|
||||
Location current = getBukkitEntity().getLocation(packetLocationCache);
|
||||
Packet<?>[] packets = new Packet[EnumItemSlot.values().length];
|
||||
int i = 0;
|
||||
|
@ -35,7 +35,7 @@ import net.citizensnpcs.util.Util;
|
||||
public class Commands {
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "bossbar --style [style] --color [color] --title [title] --visible [visible] --flags [flags]",
|
||||
usage = "bossbar --style [style] --color [color] --title [title] --visible [visible] --flags [flags] --track [health | placeholder]",
|
||||
desc = "Edit bossbar properties",
|
||||
modifiers = { "bossbar" },
|
||||
min = 1,
|
||||
@ -55,6 +55,9 @@ public class Commands {
|
||||
trait.setColor(color);
|
||||
}
|
||||
}
|
||||
if (args.hasValueFlag("track")) {
|
||||
trait.setTrackVariable(args.getFlag("track"));
|
||||
}
|
||||
if (args.hasValueFlag("title")) {
|
||||
trait.setTitle(Colorizer.parseColors(args.getFlag("title")));
|
||||
}
|
||||
|
@ -434,7 +434,10 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
|
||||
private void updatePackets(boolean navigating) {
|
||||
updateCounter++;
|
||||
if (updateCounter++ <= npc.data().<Integer> get(NPC.Metadata.PACKET_UPDATE_DELAY,
|
||||
Setting.PACKET_UPDATE_DELAY.asInt()))
|
||||
return;
|
||||
updateCounter = 0;
|
||||
boolean itemChanged = false;
|
||||
for (EnumItemSlot slot : EnumItemSlot.values()) {
|
||||
ItemStack equipment = getEquipment(slot);
|
||||
@ -445,11 +448,9 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
equipmentCache.put(slot, equipment);
|
||||
}
|
||||
if (updateCounter++ <= npc.data().<Integer> get(NPC.Metadata.PACKET_UPDATE_DELAY,
|
||||
Setting.PACKET_UPDATE_DELAY.asInt()) && !itemChanged)
|
||||
if (!itemChanged)
|
||||
return;
|
||||
|
||||
updateCounter = 0;
|
||||
Location current = getBukkitEntity().getLocation(packetLocationCache);
|
||||
Packet<?>[] packets = new Packet[EnumItemSlot.values().length];
|
||||
int i = 0;
|
||||
|
@ -39,7 +39,7 @@ import net.citizensnpcs.util.Util;
|
||||
public class Commands {
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "bossbar --style [style] --color [color] --title [title] --visible [visible] --flags [flags]",
|
||||
usage = "bossbar --style [style] --color [color] --title [title] --visible [visible] --flags [flags] --track [health | placeholder]",
|
||||
desc = "Edit bossbar properties",
|
||||
modifiers = { "bossbar" },
|
||||
min = 1,
|
||||
@ -59,6 +59,9 @@ public class Commands {
|
||||
trait.setColor(color);
|
||||
}
|
||||
}
|
||||
if (args.hasValueFlag("track")) {
|
||||
trait.setTrackVariable(args.getFlag("track"));
|
||||
}
|
||||
if (args.hasValueFlag("title")) {
|
||||
trait.setTitle(Colorizer.parseColors(args.getFlag("title")));
|
||||
}
|
||||
|
@ -438,7 +438,10 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
|
||||
private void updatePackets(boolean navigating) {
|
||||
updateCounter++;
|
||||
if (updateCounter++ <= npc.data().<Integer> get(NPC.Metadata.PACKET_UPDATE_DELAY,
|
||||
Setting.PACKET_UPDATE_DELAY.asInt()))
|
||||
return;
|
||||
updateCounter = 0;
|
||||
boolean itemChanged = false;
|
||||
for (EnumItemSlot slot : EnumItemSlot.values()) {
|
||||
ItemStack equipment = getEquipment(slot);
|
||||
@ -449,11 +452,9 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
equipmentCache.put(slot, equipment);
|
||||
}
|
||||
if (updateCounter++ <= npc.data().<Integer> get(NPC.Metadata.PACKET_UPDATE_DELAY,
|
||||
Setting.PACKET_UPDATE_DELAY.asInt()) && !itemChanged)
|
||||
if (!itemChanged)
|
||||
return;
|
||||
|
||||
updateCounter = 0;
|
||||
Location current = getBukkitEntity().getLocation(packetLocationCache);
|
||||
Packet<?>[] packets = new Packet[EnumItemSlot.values().length];
|
||||
int i = 0;
|
||||
|
@ -52,7 +52,7 @@ import net.citizensnpcs.util.Util;
|
||||
public class Commands {
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "bossbar --style [style] --color [color] --title [title] --visible [visible] --flags [flags]",
|
||||
usage = "bossbar --style [style] --color [color] --title [title] --visible [visible] --flags [flags] --track [health | placeholder]",
|
||||
desc = "Edit bossbar properties",
|
||||
modifiers = { "bossbar" },
|
||||
min = 1,
|
||||
@ -72,6 +72,9 @@ public class Commands {
|
||||
trait.setColor(color);
|
||||
}
|
||||
}
|
||||
if (args.hasValueFlag("track")) {
|
||||
trait.setTrackVariable(args.getFlag("track"));
|
||||
}
|
||||
if (args.hasValueFlag("title")) {
|
||||
trait.setTitle(Colorizer.parseColors(args.getFlag("title")));
|
||||
}
|
||||
|
@ -449,7 +449,10 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
|
||||
private void updatePackets(boolean navigating) {
|
||||
updateCounter++;
|
||||
if (updateCounter++ <= npc.data().<Integer> get(NPC.Metadata.PACKET_UPDATE_DELAY,
|
||||
Setting.PACKET_UPDATE_DELAY.asInt()))
|
||||
return;
|
||||
updateCounter = 0;
|
||||
boolean itemChanged = false;
|
||||
for (EnumItemSlot slot : EnumItemSlot.values()) {
|
||||
ItemStack equipment = getEquipment(slot);
|
||||
@ -460,10 +463,8 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
equipmentCache.put(slot, equipment);
|
||||
}
|
||||
if (updateCounter++ <= npc.data().<Integer> get(NPC.Metadata.PACKET_UPDATE_DELAY,
|
||||
Setting.PACKET_UPDATE_DELAY.asInt()) && !itemChanged)
|
||||
if (!itemChanged)
|
||||
return;
|
||||
updateCounter = 0;
|
||||
Location current = getBukkitEntity().getLocation(packetLocationCache);
|
||||
Packet<?>[] packets = new Packet[EnumItemSlot.values().length];
|
||||
int i = 0;
|
||||
|
@ -91,7 +91,7 @@ public class Commands {
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "bossbar --style [style] --color [color] --title [title] --visible [visible] --flags [flags]",
|
||||
usage = "bossbar --style [style] --color [color] --title [title] --visible [visible] --flags [flags] --track [health | placeholder]",
|
||||
desc = "Edit bossbar properties",
|
||||
modifiers = { "bossbar" },
|
||||
min = 1,
|
||||
@ -111,6 +111,9 @@ public class Commands {
|
||||
trait.setColor(color);
|
||||
}
|
||||
}
|
||||
if (args.hasValueFlag("track")) {
|
||||
trait.setTrackVariable(args.getFlag("track"));
|
||||
}
|
||||
if (args.hasValueFlag("title")) {
|
||||
trait.setTitle(Colorizer.parseColors(args.getFlag("title")));
|
||||
}
|
||||
|
@ -479,7 +479,10 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
|
||||
private void updatePackets(boolean navigating) {
|
||||
updateCounter++;
|
||||
if (updateCounter++ <= npc.data().<Integer> get(NPC.Metadata.PACKET_UPDATE_DELAY,
|
||||
Setting.PACKET_UPDATE_DELAY.asInt()))
|
||||
return;
|
||||
updateCounter = 0;
|
||||
boolean itemChanged = false;
|
||||
for (EnumItemSlot slot : EnumItemSlot.values()) {
|
||||
ItemStack equipment = getEquipment(slot);
|
||||
@ -490,11 +493,9 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
equipmentCache.put(slot, equipment);
|
||||
}
|
||||
if (updateCounter++ <= npc.data().<Integer> get(NPC.Metadata.PACKET_UPDATE_DELAY,
|
||||
Setting.PACKET_UPDATE_DELAY.asInt()) && !itemChanged)
|
||||
if (!itemChanged)
|
||||
return;
|
||||
|
||||
updateCounter = 0;
|
||||
Location current = getBukkitEntity().getLocation(packetLocationCache);
|
||||
Packet<?>[] packets = new Packet[1];
|
||||
List<Pair<EnumItemSlot, ItemStack>> vals = Lists.newArrayList();
|
||||
|
@ -91,7 +91,7 @@ public class Commands {
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "bossbar --style [style] --color [color] --title [title] --visible [visible] --flags [flags]",
|
||||
usage = "bossbar --style [style] --color [color] --title [title] --visible [visible] --flags [flags] --track [health | placeholder]",
|
||||
desc = "Edit bossbar properties",
|
||||
modifiers = { "bossbar" },
|
||||
min = 1,
|
||||
@ -111,6 +111,9 @@ public class Commands {
|
||||
trait.setColor(color);
|
||||
}
|
||||
}
|
||||
if (args.hasValueFlag("track")) {
|
||||
trait.setTrackVariable(args.getFlag("track"));
|
||||
}
|
||||
if (args.hasValueFlag("title")) {
|
||||
trait.setTitle(Colorizer.parseColors(args.getFlag("title")));
|
||||
}
|
||||
|
@ -489,7 +489,10 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
|
||||
private void updatePackets(boolean navigating) {
|
||||
updateCounter++;
|
||||
if (updateCounter++ <= npc.data().<Integer> get(NPC.Metadata.PACKET_UPDATE_DELAY,
|
||||
Setting.PACKET_UPDATE_DELAY.asInt()))
|
||||
return;
|
||||
updateCounter = 0;
|
||||
boolean itemChanged = false;
|
||||
for (EquipmentSlot slot : EquipmentSlot.values()) {
|
||||
ItemStack equipment = getItemBySlot(slot);
|
||||
@ -500,11 +503,9 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
equipmentCache.put(slot, equipment);
|
||||
}
|
||||
if (updateCounter++ <= npc.data().<Integer> get(NPC.Metadata.PACKET_UPDATE_DELAY,
|
||||
Setting.PACKET_UPDATE_DELAY.asInt()) && !itemChanged)
|
||||
if (!itemChanged)
|
||||
return;
|
||||
|
||||
updateCounter = 0;
|
||||
Location current = getBukkitEntity().getLocation(packetLocationCache);
|
||||
List<Pair<EquipmentSlot, ItemStack>> vals = Lists.newArrayList();
|
||||
for (EquipmentSlot slot : EquipmentSlot.values()) {
|
||||
|
@ -127,7 +127,7 @@ public class Commands {
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "bossbar --style [style] --color [color] --title [title] --visible [visible] --flags [flags]",
|
||||
usage = "bossbar --style [style] --color [color] --title [title] --visible [visible] --flags [flags] --track [health | placeholder]",
|
||||
desc = "Edit bossbar properties",
|
||||
modifiers = { "bossbar" },
|
||||
min = 1,
|
||||
@ -147,6 +147,9 @@ public class Commands {
|
||||
trait.setColor(color);
|
||||
}
|
||||
}
|
||||
if (args.hasValueFlag("track")) {
|
||||
trait.setTrackVariable(args.getFlag("track"));
|
||||
}
|
||||
if (args.hasValueFlag("title")) {
|
||||
trait.setTitle(Colorizer.parseColors(args.getFlag("title")));
|
||||
}
|
||||
|
@ -488,22 +488,23 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
|
||||
private void updatePackets(boolean navigating) {
|
||||
updateCounter++;
|
||||
if (updateCounter++ <= npc.data().<Integer> get(NPC.Metadata.PACKET_UPDATE_DELAY,
|
||||
Setting.PACKET_UPDATE_DELAY.asInt()))
|
||||
return;
|
||||
updateCounter = 0;
|
||||
boolean itemChanged = false;
|
||||
for (EquipmentSlot slot : EquipmentSlot.values()) {
|
||||
ItemStack equipment = getItemBySlot(slot);
|
||||
ItemStack cache = equipmentCache.get(slot);
|
||||
if (!(cache == null && equipment == null)
|
||||
&& (cache == null ^ equipment == null || !ItemStack.isSame(cache, equipment))) {
|
||||
System.out.println("item changed " + cache + " " + equipment);
|
||||
itemChanged = true;
|
||||
}
|
||||
equipmentCache.put(slot, equipment);
|
||||
}
|
||||
if (updateCounter++ <= npc.data().<Integer> get(NPC.Metadata.PACKET_UPDATE_DELAY,
|
||||
Setting.PACKET_UPDATE_DELAY.asInt()) && !itemChanged)
|
||||
if (!itemChanged)
|
||||
return;
|
||||
|
||||
updateCounter = 0;
|
||||
Location current = getBukkitEntity().getLocation(packetLocationCache);
|
||||
List<Pair<EquipmentSlot, ItemStack>> vals = Lists.newArrayList();
|
||||
for (EquipmentSlot slot : EquipmentSlot.values()) {
|
||||
|
@ -127,7 +127,7 @@ public class Commands {
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "bossbar --style [style] --color [color] --title [title] --visible [visible] --flags [flags]",
|
||||
usage = "bossbar --style [style] --color [color] --title [title] --visible [visible] --flags [flags] --track [health | placeholder]",
|
||||
desc = "Edit bossbar properties",
|
||||
modifiers = { "bossbar" },
|
||||
min = 1,
|
||||
@ -147,6 +147,9 @@ public class Commands {
|
||||
trait.setColor(color);
|
||||
}
|
||||
}
|
||||
if (args.hasValueFlag("track")) {
|
||||
trait.setTrackVariable(args.getFlag("track"));
|
||||
}
|
||||
if (args.hasValueFlag("title")) {
|
||||
trait.setTitle(Colorizer.parseColors(args.getFlag("title")));
|
||||
}
|
||||
|
@ -399,7 +399,10 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
|
||||
private void updatePackets(boolean navigating) {
|
||||
updateCounter++;
|
||||
if (updateCounter++ <= npc.data().<Integer> get(NPC.Metadata.PACKET_UPDATE_DELAY,
|
||||
Setting.PACKET_UPDATE_DELAY.asInt()))
|
||||
return;
|
||||
updateCounter = 0;
|
||||
boolean itemChanged = false;
|
||||
for (int slot = 0; slot < this.inventory.armor.length; slot++) {
|
||||
ItemStack equipment = getEquipment(slot);
|
||||
@ -410,10 +413,8 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
equipmentCache.put(slot, equipment);
|
||||
}
|
||||
if (updateCounter++ <= npc.data().<Integer> get(NPC.Metadata.PACKET_UPDATE_DELAY,
|
||||
Setting.PACKET_UPDATE_DELAY.asInt()) && !itemChanged)
|
||||
if (!itemChanged)
|
||||
return;
|
||||
updateCounter = 0;
|
||||
Location current = getBukkitEntity().getLocation(packetLocationCache);
|
||||
Packet<?>[] packets = new Packet[this.inventory.armor.length];
|
||||
for (int i = 0; i < this.inventory.armor.length; i++) {
|
||||
|
Loading…
Reference in New Issue
Block a user