2017-12-30 08:36:36 +01:00
|
|
|
package net.citizensnpcs.npc;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.EntityType;
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
|
|
|
import org.bukkit.entity.Player;
|
2018-08-08 10:08:38 +02:00
|
|
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
2020-03-27 18:14:11 +01:00
|
|
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
2017-12-30 08:36:36 +01:00
|
|
|
import org.bukkit.metadata.FixedMetadataValue;
|
|
|
|
import org.bukkit.scoreboard.Team;
|
|
|
|
|
|
|
|
import com.google.common.base.Preconditions;
|
|
|
|
import com.google.common.base.Throwables;
|
2019-05-29 10:45:18 +02:00
|
|
|
import com.google.common.collect.HashMultimap;
|
|
|
|
import com.google.common.collect.SetMultimap;
|
2017-12-30 08:36:36 +01:00
|
|
|
|
|
|
|
import net.citizensnpcs.NPCNeedsRespawnEvent;
|
|
|
|
import net.citizensnpcs.Settings.Setting;
|
|
|
|
import net.citizensnpcs.api.CitizensAPI;
|
|
|
|
import net.citizensnpcs.api.ai.Navigator;
|
|
|
|
import net.citizensnpcs.api.event.DespawnReason;
|
|
|
|
import net.citizensnpcs.api.event.NPCDespawnEvent;
|
|
|
|
import net.citizensnpcs.api.event.NPCSpawnEvent;
|
2018-08-08 10:08:38 +02:00
|
|
|
import net.citizensnpcs.api.event.SpawnReason;
|
2017-12-30 08:36:36 +01:00
|
|
|
import net.citizensnpcs.api.npc.AbstractNPC;
|
|
|
|
import net.citizensnpcs.api.npc.BlockBreaker;
|
|
|
|
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
|
|
|
|
import net.citizensnpcs.api.npc.NPC;
|
|
|
|
import net.citizensnpcs.api.npc.NPCRegistry;
|
|
|
|
import net.citizensnpcs.api.trait.Trait;
|
|
|
|
import net.citizensnpcs.api.trait.trait.MobType;
|
|
|
|
import net.citizensnpcs.api.trait.trait.Spawned;
|
|
|
|
import net.citizensnpcs.api.util.DataKey;
|
|
|
|
import net.citizensnpcs.api.util.Messaging;
|
|
|
|
import net.citizensnpcs.npc.ai.CitizensNavigator;
|
|
|
|
import net.citizensnpcs.npc.skin.SkinnableEntity;
|
|
|
|
import net.citizensnpcs.trait.CurrentLocation;
|
2020-03-02 07:51:54 +01:00
|
|
|
import net.citizensnpcs.trait.Gravity;
|
2019-07-12 09:39:38 +02:00
|
|
|
import net.citizensnpcs.trait.ScoreboardTrait;
|
2019-05-29 10:45:18 +02:00
|
|
|
import net.citizensnpcs.util.ChunkCoord;
|
2017-12-30 08:36:36 +01:00
|
|
|
import net.citizensnpcs.util.Messages;
|
|
|
|
import net.citizensnpcs.util.NMS;
|
2020-04-29 14:56:39 +02:00
|
|
|
import net.citizensnpcs.util.PlayerUpdateTask;
|
2017-12-30 08:36:36 +01:00
|
|
|
import net.citizensnpcs.util.Util;
|
|
|
|
|
|
|
|
public class CitizensNPC extends AbstractNPC {
|
2019-05-29 10:45:18 +02:00
|
|
|
private ChunkCoord cachedCoord;
|
2017-12-30 08:36:36 +01:00
|
|
|
private EntityController entityController;
|
|
|
|
private final CitizensNavigator navigator = new CitizensNavigator(this);
|
|
|
|
private int updateCounter = 0;
|
|
|
|
|
|
|
|
public CitizensNPC(UUID uuid, int id, String name, EntityController entityController, NPCRegistry registry) {
|
|
|
|
super(uuid, id, name, registry);
|
|
|
|
Preconditions.checkNotNull(entityController);
|
|
|
|
this.entityController = entityController;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean despawn(DespawnReason reason) {
|
|
|
|
if (!isSpawned() && reason != DespawnReason.DEATH) {
|
|
|
|
Messaging.debug("Tried to despawn", getId(), "while already despawned.");
|
|
|
|
if (reason == DespawnReason.REMOVAL) {
|
|
|
|
Bukkit.getPluginManager().callEvent(new NPCDespawnEvent(this, reason));
|
|
|
|
}
|
|
|
|
if (reason == DespawnReason.RELOAD) {
|
|
|
|
unloadEvents();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
NPCDespawnEvent event = new NPCDespawnEvent(this, reason);
|
|
|
|
if (reason == DespawnReason.CHUNK_UNLOAD) {
|
|
|
|
event.setCancelled(Setting.KEEP_CHUNKS_LOADED.asBoolean());
|
|
|
|
}
|
|
|
|
Bukkit.getPluginManager().callEvent(event);
|
2018-02-13 10:18:15 +01:00
|
|
|
if (event.isCancelled() && reason != DespawnReason.DEATH) {
|
2019-05-29 10:45:18 +02:00
|
|
|
Messaging.debug("Couldn't despawn", getId(), "due to despawn event cancellation. Will load chunk.",
|
2017-12-30 08:36:36 +01:00
|
|
|
getEntity().isValid());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
boolean keepSelected = getTrait(Spawned.class).shouldSpawn();
|
|
|
|
if (!keepSelected) {
|
|
|
|
data().remove("selectors");
|
|
|
|
}
|
2020-04-29 14:56:39 +02:00
|
|
|
if (getEntity() instanceof Player) {
|
|
|
|
PlayerUpdateTask.deregisterPlayer(getEntity());
|
|
|
|
}
|
2017-12-30 08:36:36 +01:00
|
|
|
navigator.onDespawn();
|
|
|
|
if (reason == DespawnReason.RELOAD) {
|
|
|
|
unloadEvents();
|
|
|
|
}
|
|
|
|
for (Trait trait : new ArrayList<Trait>(traits.values())) {
|
|
|
|
trait.onDespawn();
|
|
|
|
}
|
2019-10-03 15:33:06 +02:00
|
|
|
Messaging.debug("Despawned", getId(), "DespawnReason." + reason);
|
2018-02-13 10:18:15 +01:00
|
|
|
if (reason == DespawnReason.DEATH) {
|
|
|
|
entityController.setEntity(null);
|
|
|
|
} else {
|
|
|
|
entityController.remove();
|
|
|
|
}
|
2017-12-30 08:36:36 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-29 10:45:18 +02:00
|
|
|
@Override
|
|
|
|
public void destroy() {
|
|
|
|
super.destroy();
|
|
|
|
resetCachedCoord();
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
@Override
|
|
|
|
public void faceLocation(Location location) {
|
|
|
|
if (!isSpawned())
|
|
|
|
return;
|
|
|
|
Util.faceLocation(getEntity(), location);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BlockBreaker getBlockBreaker(Block targetBlock, BlockBreakerConfiguration config) {
|
|
|
|
return NMS.getBlockBreaker(getEntity(), targetBlock, config);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Entity getEntity() {
|
|
|
|
return entityController == null ? null : entityController.getBukkitEntity();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Navigator getNavigator() {
|
|
|
|
return navigator;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Location getStoredLocation() {
|
2020-03-27 18:14:11 +01:00
|
|
|
return isSpawned() ? getEntity().getLocation(CACHE_LOCATION) : getTrait(CurrentLocation.class).getLocation();
|
2017-12-30 08:36:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isFlyable() {
|
|
|
|
updateFlyableState();
|
|
|
|
return super.isFlyable();
|
|
|
|
}
|
|
|
|
|
2019-10-03 07:14:20 +02:00
|
|
|
@Override
|
|
|
|
public boolean isSpawned() {
|
|
|
|
return getEntity() != null && NMS.isValid(getEntity());
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
@Override
|
|
|
|
public void load(final DataKey root) {
|
|
|
|
super.load(root);
|
|
|
|
// Spawn the NPC
|
|
|
|
CurrentLocation spawnLocation = getTrait(CurrentLocation.class);
|
|
|
|
if (getTrait(Spawned.class).shouldSpawn() && spawnLocation.getLocation() != null) {
|
2020-04-30 17:11:45 +02:00
|
|
|
if (spawnLocation.getLocation() != null) {
|
|
|
|
spawn(spawnLocation.getLocation(), SpawnReason.RESPAWN);
|
|
|
|
} else {
|
|
|
|
Messaging.debug("Tried to spawn", getId(), "on load but world was null");
|
|
|
|
}
|
2017-12-30 08:36:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
navigator.load(root.getRelative("navigator"));
|
|
|
|
}
|
|
|
|
|
2019-05-29 10:45:18 +02:00
|
|
|
private void resetCachedCoord() {
|
2020-05-01 11:49:03 +02:00
|
|
|
if (cachedCoord == null)
|
|
|
|
return;
|
|
|
|
CHUNK_LOADERS.remove(NPC_METADATA_MARKER, CHUNK_LOADERS);
|
|
|
|
CHUNK_LOADERS.remove(cachedCoord, this);
|
|
|
|
if (CHUNK_LOADERS.get(cachedCoord).size() == 0) {
|
|
|
|
cachedCoord.setForceLoaded(false);
|
2019-05-29 10:45:18 +02:00
|
|
|
}
|
2020-05-01 11:49:03 +02:00
|
|
|
cachedCoord = null;
|
2019-05-29 10:45:18 +02:00
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
@Override
|
|
|
|
public void save(DataKey root) {
|
|
|
|
super.save(root);
|
|
|
|
if (!data().get(NPC.SHOULD_SAVE_METADATA, true))
|
|
|
|
return;
|
|
|
|
navigator.save(root.getRelative("navigator"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setBukkitEntityType(EntityType type) {
|
|
|
|
EntityController controller = EntityControllers.createForType(type);
|
|
|
|
if (controller == null)
|
|
|
|
throw new IllegalArgumentException("Unsupported entity type " + type);
|
|
|
|
setEntityController(controller);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setEntityController(EntityController newController) {
|
|
|
|
Preconditions.checkNotNull(newController);
|
|
|
|
boolean wasSpawned = isSpawned();
|
|
|
|
Location prev = null;
|
|
|
|
if (wasSpawned) {
|
2020-03-27 18:14:11 +01:00
|
|
|
prev = getEntity().getLocation(CACHE_LOCATION);
|
2017-12-30 08:36:36 +01:00
|
|
|
despawn(DespawnReason.PENDING_RESPAWN);
|
|
|
|
}
|
|
|
|
entityController = newController;
|
|
|
|
if (wasSpawned) {
|
2018-08-08 10:08:38 +02:00
|
|
|
spawn(prev, SpawnReason.RESPAWN);
|
2017-12-30 08:36:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setFlyable(boolean flyable) {
|
|
|
|
super.setFlyable(flyable);
|
|
|
|
updateFlyableState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean spawn(Location at) {
|
2018-08-08 10:08:38 +02:00
|
|
|
return spawn(at, SpawnReason.PLUGIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean spawn(Location at, SpawnReason reason) {
|
2017-12-30 08:36:36 +01:00
|
|
|
Preconditions.checkNotNull(at, "location cannot be null");
|
2018-08-08 10:08:38 +02:00
|
|
|
Preconditions.checkNotNull(reason, "reason cannot be null");
|
2017-12-30 08:36:36 +01:00
|
|
|
if (isSpawned()) {
|
|
|
|
Messaging.debug("Tried to spawn", getId(), "while already spawned.");
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-24 13:52:35 +02:00
|
|
|
if (at.getWorld() == null) {
|
|
|
|
Messaging.debug("Tried to spawn", getId(), "but the world was null.");
|
|
|
|
return false;
|
|
|
|
}
|
2017-12-30 08:36:36 +01:00
|
|
|
data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
|
|
|
at = at.clone();
|
2019-05-29 10:45:18 +02:00
|
|
|
|
2020-03-27 18:20:20 +01:00
|
|
|
if (reason == SpawnReason.CHUNK_LOAD || reason == SpawnReason.COMMAND) {
|
2019-06-12 15:06:06 +02:00
|
|
|
at.getChunk().load();
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
getTrait(CurrentLocation.class).setLocation(at);
|
|
|
|
entityController.spawn(at, this);
|
|
|
|
|
|
|
|
getEntity().setMetadata(NPC_METADATA_MARKER, new FixedMetadataValue(CitizensAPI.getPlugin(), true));
|
|
|
|
|
2018-08-08 10:08:38 +02:00
|
|
|
boolean couldSpawn = !Util.isLoaded(at) ? false
|
|
|
|
: NMS.addEntityToWorld(getEntity(), CreatureSpawnEvent.SpawnReason.CUSTOM);
|
2017-12-30 08:36:36 +01:00
|
|
|
|
|
|
|
// send skin packets, if applicable, before other NMS packets are sent
|
|
|
|
if (couldSpawn) {
|
|
|
|
SkinnableEntity skinnable = getEntity() instanceof SkinnableEntity ? ((SkinnableEntity) getEntity()) : null;
|
|
|
|
if (skinnable != null) {
|
|
|
|
skinnable.getSkinTracker().onSpawnNPC();
|
|
|
|
}
|
2020-05-04 10:21:34 +02:00
|
|
|
} else {
|
2017-12-30 08:36:36 +01:00
|
|
|
Messaging.debug("Retrying spawn of", getId(), "later due to chunk being unloaded.",
|
|
|
|
Util.isLoaded(at) ? "Util.isLoaded true" : "Util.isLoaded false");
|
|
|
|
// we need to wait for a chunk load before trying to spawn
|
|
|
|
entityController.remove();
|
|
|
|
Bukkit.getPluginManager().callEvent(new NPCNeedsRespawnEvent(this, at));
|
|
|
|
return false;
|
|
|
|
}
|
2018-11-30 15:34:47 +01:00
|
|
|
getEntity().teleport(at);
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
NMS.setHeadYaw(getEntity(), at.getYaw());
|
2020-04-30 13:11:56 +02:00
|
|
|
NMS.setBodyYaw(getEntity(), at.getYaw());
|
2017-12-30 08:36:36 +01:00
|
|
|
|
|
|
|
// Set the spawned state
|
|
|
|
getTrait(CurrentLocation.class).setLocation(at);
|
|
|
|
getTrait(Spawned.class).setSpawned(true);
|
|
|
|
|
2018-08-08 10:08:38 +02:00
|
|
|
NPCSpawnEvent spawnEvent = new NPCSpawnEvent(this, at, reason);
|
2017-12-30 08:36:36 +01:00
|
|
|
Bukkit.getPluginManager().callEvent(spawnEvent);
|
|
|
|
|
|
|
|
if (spawnEvent.isCancelled()) {
|
|
|
|
entityController.remove();
|
|
|
|
Messaging.debug("Couldn't spawn", getId(), "due to event cancellation.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
navigator.onSpawn();
|
|
|
|
|
|
|
|
// Modify NPC using traits after the entity has been created
|
|
|
|
Collection<Trait> onSpawn = traits.values();
|
|
|
|
|
|
|
|
// work around traits modifying the map during this iteration.
|
|
|
|
for (Trait trait : onSpawn.toArray(new Trait[onSpawn.size()])) {
|
|
|
|
try {
|
|
|
|
trait.onSpawn();
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
Messaging.severeTr(Messages.TRAIT_ONSPAWN_FAILED, trait.getName(), getId());
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getEntity() instanceof LivingEntity) {
|
|
|
|
LivingEntity entity = (LivingEntity) getEntity();
|
|
|
|
entity.setRemoveWhenFarAway(false);
|
|
|
|
|
|
|
|
if (NMS.getStepHeight(entity) < 1) {
|
|
|
|
NMS.setStepHeight(entity, 1);
|
|
|
|
}
|
|
|
|
if (getEntity() instanceof Player) {
|
|
|
|
NMS.replaceTrackerEntry((Player) getEntity());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-29 14:56:39 +02:00
|
|
|
if (getEntity() instanceof Player) {
|
|
|
|
PlayerUpdateTask.registerPlayer(getEntity());
|
|
|
|
}
|
|
|
|
|
2020-03-02 07:51:54 +01:00
|
|
|
updateFlyableState();
|
|
|
|
|
2020-05-04 10:21:34 +02:00
|
|
|
Messaging.debug("Spawned", getId(), "SpawnReason." + reason);
|
2017-12-30 08:36:36 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-03-27 18:14:11 +01:00
|
|
|
@Override
|
|
|
|
public void teleport(Location location, TeleportCause reason) {
|
|
|
|
super.teleport(location, reason);
|
2020-05-12 16:33:54 +02:00
|
|
|
if (isSpawned() && getEntity().getLocation(CACHE_LOCATION).distanceSquared(location) < 1) {
|
|
|
|
NMS.setHeadYaw(getEntity(), location.getYaw());
|
|
|
|
}
|
2020-03-27 18:14:11 +01:00
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
@Override
|
|
|
|
public void update() {
|
|
|
|
try {
|
|
|
|
super.update();
|
2019-05-07 14:02:14 +02:00
|
|
|
if (!isSpawned()) {
|
2019-05-29 10:45:18 +02:00
|
|
|
resetCachedCoord();
|
2017-12-30 08:36:36 +01:00
|
|
|
return;
|
2019-05-07 14:02:14 +02:00
|
|
|
}
|
2017-12-30 08:36:36 +01:00
|
|
|
if (data().get(NPC.SWIMMING_METADATA, true)) {
|
|
|
|
NMS.trySwim(getEntity());
|
|
|
|
}
|
|
|
|
navigator.run();
|
2019-03-07 17:12:29 +01:00
|
|
|
if (SUPPORT_GLOWING) {
|
|
|
|
try {
|
|
|
|
getEntity().setGlowing(data().get(NPC.GLOWING_METADATA, false));
|
|
|
|
} catch (NoSuchMethodError e) {
|
|
|
|
SUPPORT_GLOWING = false;
|
|
|
|
}
|
2018-04-07 10:02:35 +02:00
|
|
|
}
|
2019-04-26 12:20:34 +02:00
|
|
|
|
2020-05-01 11:49:03 +02:00
|
|
|
boolean isLiving = getEntity() instanceof LivingEntity;
|
|
|
|
if (updateCounter++ > Setting.PACKET_UPDATE_DELAY.asInt()) {
|
2019-05-29 10:45:18 +02:00
|
|
|
if (Setting.KEEP_CHUNKS_LOADED.asBoolean()) {
|
|
|
|
ChunkCoord currentCoord = new ChunkCoord(getStoredLocation());
|
|
|
|
if (!currentCoord.equals(cachedCoord)) {
|
|
|
|
resetCachedCoord();
|
|
|
|
currentCoord.setForceLoaded(true);
|
|
|
|
CHUNK_LOADERS.put(currentCoord, this);
|
|
|
|
cachedCoord = currentCoord;
|
|
|
|
}
|
|
|
|
}
|
2020-05-01 11:49:03 +02:00
|
|
|
if (isLiving) {
|
|
|
|
updateCustomName();
|
|
|
|
}
|
2017-12-30 08:36:36 +01:00
|
|
|
updateCounter = 0;
|
|
|
|
}
|
|
|
|
|
2020-05-01 11:49:03 +02:00
|
|
|
if (isLiving) {
|
2017-12-30 08:36:36 +01:00
|
|
|
String nameplateVisible = data().<Object> get(NPC.NAMEPLATE_VISIBLE_METADATA, true).toString();
|
2020-03-01 08:29:47 +01:00
|
|
|
((LivingEntity) getEntity()).setCustomNameVisible(Boolean.parseBoolean(nameplateVisible));
|
|
|
|
|
2020-05-01 11:49:03 +02:00
|
|
|
NMS.setKnockbackResistance((LivingEntity) getEntity(),
|
|
|
|
data().get(NPC.DEFAULT_PROTECTED_METADATA, true) ? 1D : 0D);
|
2017-12-30 08:36:36 +01:00
|
|
|
}
|
|
|
|
|
2019-03-07 17:12:29 +01:00
|
|
|
if (SUPPORT_SILENT && data().has(NPC.SILENT_METADATA)) {
|
2018-04-07 10:02:35 +02:00
|
|
|
try {
|
|
|
|
getEntity().setSilent(Boolean.parseBoolean(data().get(NPC.SILENT_METADATA).toString()));
|
|
|
|
} catch (NoSuchMethodError e) {
|
2019-03-07 17:12:29 +01:00
|
|
|
SUPPORT_SILENT = false;
|
2018-04-07 10:02:35 +02:00
|
|
|
}
|
2017-12-30 08:36:36 +01:00
|
|
|
}
|
|
|
|
} catch (Exception ex) {
|
|
|
|
Throwable error = Throwables.getRootCause(ex);
|
|
|
|
Messaging.logTr(Messages.EXCEPTION_UPDATING_NPC, getId(), error.getMessage());
|
|
|
|
error.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-26 12:20:34 +02:00
|
|
|
private void updateCustomName() {
|
|
|
|
boolean nameVisibility = false;
|
|
|
|
|
|
|
|
if (!getEntity().isCustomNameVisible()
|
|
|
|
&& !data().<Object> get(NPC.NAMEPLATE_VISIBLE_METADATA, true).toString().equals("hover")) {
|
|
|
|
getEntity().setCustomName("");
|
|
|
|
} else {
|
|
|
|
nameVisibility = true;
|
|
|
|
getEntity().setCustomName(getFullName());
|
|
|
|
}
|
|
|
|
|
|
|
|
String teamName = data().get(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, "");
|
|
|
|
Team team = null;
|
|
|
|
if (!(getEntity() instanceof Player) || teamName.length() == 0
|
2020-05-01 11:49:25 +02:00
|
|
|
|| (team = Util.getDummyScoreboard().getTeam(teamName)) == null)
|
2019-04-26 12:20:34 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
|
|
|
|
team.unregister();
|
|
|
|
data().remove(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-12 09:39:38 +02:00
|
|
|
getTrait(ScoreboardTrait.class).apply(team, nameVisibility);
|
2019-04-26 12:20:34 +02:00
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
private void updateFlyableState() {
|
|
|
|
EntityType type = isSpawned() ? getEntity().getType() : getTrait(MobType.class).getType();
|
|
|
|
if (type == null)
|
|
|
|
return;
|
2020-03-21 08:19:46 +01:00
|
|
|
if (!Util.isAlwaysFlyable(type))
|
|
|
|
return;
|
|
|
|
if (!data().has(NPC.FLYABLE_METADATA)) {
|
|
|
|
data().setPersistent(NPC.FLYABLE_METADATA, true);
|
|
|
|
}
|
|
|
|
if (!hasTrait(Gravity.class)) {
|
|
|
|
getTrait(Gravity.class).setEnabled(true);
|
2017-12-30 08:36:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-27 18:51:53 +01:00
|
|
|
private static final Location CACHE_LOCATION = new Location(null, 0, 0, 0);
|
2019-05-29 10:45:18 +02:00
|
|
|
private static final SetMultimap<ChunkCoord, NPC> CHUNK_LOADERS = HashMultimap.create();
|
2017-12-30 08:36:36 +01:00
|
|
|
private static final String NPC_METADATA_MARKER = "NPC";
|
2019-03-07 17:12:29 +01:00
|
|
|
private static boolean SUPPORT_GLOWING = true;
|
2019-04-26 12:20:34 +02:00
|
|
|
private static boolean SUPPORT_SILENT = true;
|
2017-12-30 08:36:36 +01:00
|
|
|
}
|