Search in sources :

Example 1 with SkinnableEntity

use of net.citizensnpcs.npc.skin.SkinnableEntity in project Citizens2 by CitizensDev.

the class NMSImpl method sendTabListRemove.

@Override
public void sendTabListRemove(Player recipient, Collection<? extends SkinnableEntity> skinnableNPCs) {
    Preconditions.checkNotNull(recipient);
    Preconditions.checkNotNull(skinnableNPCs);
    EntityPlayer[] entities = new EntityPlayer[skinnableNPCs.size()];
    int i = 0;
    for (SkinnableEntity skinnable : skinnableNPCs) {
        entities[i] = (EntityPlayer) skinnable;
        i++;
    }
    NMSImpl.sendPacket(recipient, new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, entities));
}
Also used : SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) EntityPlayer(net.minecraft.server.v1_10_R1.EntityPlayer) PacketPlayOutPlayerInfo(net.minecraft.server.v1_10_R1.PacketPlayOutPlayerInfo) PathPoint(net.minecraft.server.v1_10_R1.PathPoint)

Example 2 with SkinnableEntity

use of net.citizensnpcs.npc.skin.SkinnableEntity in project Citizens2 by CitizensDev.

the class NMSImpl method sendTabListRemove.

@Override
public void sendTabListRemove(Player recipient, Collection<? extends SkinnableEntity> skinnableNPCs) {
    Preconditions.checkNotNull(recipient);
    Preconditions.checkNotNull(skinnableNPCs);
    EntityPlayer[] entities = new EntityPlayer[skinnableNPCs.size()];
    int i = 0;
    for (SkinnableEntity skinnable : skinnableNPCs) {
        entities[i] = (EntityPlayer) skinnable;
        i++;
    }
    NMSImpl.sendPacket(recipient, new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, entities));
}
Also used : SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) EntityPlayer(net.minecraft.server.v1_8_R3.EntityPlayer) PacketPlayOutPlayerInfo(net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo) PathPoint(net.minecraft.server.v1_8_R3.PathPoint)

Example 3 with SkinnableEntity

use of net.citizensnpcs.npc.skin.SkinnableEntity in project Citizens2 by CitizensDev.

the class PlayerlistTrackerEntry method updatePlayer.

@Override
public void updatePlayer(final EntityPlayer entityplayer) {
    // prevent updates to NPC "viewers"
    if (entityplayer instanceof EntityHumanNPC)
        return;
    Entity tracker = getTracker(this);
    if (entityplayer != tracker && c(entityplayer)) {
        if (!this.trackedPlayers.contains(entityplayer) && ((entityplayer.u().getPlayerChunkMap().a(entityplayer, tracker.ae, tracker.ag)) || (tracker.attachedToPlayer))) {
            if ((tracker instanceof SkinnableEntity)) {
                SkinnableEntity skinnable = (SkinnableEntity) tracker;
                Player player = skinnable.getBukkitEntity();
                if (!entityplayer.getBukkitEntity().canSee(player))
                    return;
                skinnable.getSkinTracker().updateViewer(entityplayer.getBukkitEntity());
            }
        }
    }
    super.updatePlayer(entityplayer);
}
Also used : SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) Entity(net.minecraft.server.v1_8_R3.Entity) Player(org.bukkit.entity.Player) EntityPlayer(net.minecraft.server.v1_8_R3.EntityPlayer) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) EntityHumanNPC(net.citizensnpcs.nms.v1_8_R3.entity.EntityHumanNPC)

Example 4 with SkinnableEntity

use of net.citizensnpcs.npc.skin.SkinnableEntity in project Citizens2 by CitizensDev.

the class CitizensNPC method spawn.

@Override
public boolean spawn(Location at) {
    Preconditions.checkNotNull(at, "location cannot be null");
    if (isSpawned()) {
        Messaging.debug("Tried to spawn", getId(), "while already spawned.");
        return false;
    }
    data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
    at = at.clone();
    getTrait(CurrentLocation.class).setLocation(at);
    entityController.spawn(at, this);
    getEntity().setMetadata(NPC_METADATA_MARKER, new FixedMetadataValue(CitizensAPI.getPlugin(), true));
    boolean couldSpawn = !Util.isLoaded(at) ? false : NMS.addEntityToWorld(getEntity(), SpawnReason.CUSTOM);
    // 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();
        }
    }
    getEntity().teleport(at);
    if (!couldSpawn) {
        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;
    }
    NMS.setHeadYaw(getEntity(), at.getYaw());
    // Set the spawned state
    getTrait(CurrentLocation.class).setLocation(at);
    getTrait(Spawned.class).setSpawned(true);
    NPCSpawnEvent spawnEvent = new NPCSpawnEvent(this, at);
    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());
        }
    }
    return true;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) NPCNeedsRespawnEvent(net.citizensnpcs.NPCNeedsRespawnEvent) Spawned(net.citizensnpcs.api.trait.trait.Spawned) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) NPCSpawnEvent(net.citizensnpcs.api.event.NPCSpawnEvent) Trait(net.citizensnpcs.api.trait.Trait) CurrentLocation(net.citizensnpcs.trait.CurrentLocation)

Example 5 with SkinnableEntity

use of net.citizensnpcs.npc.skin.SkinnableEntity in project Citizens2 by CitizensDev.

the class PlayerlistTrackerEntry method updatePlayer.

@Override
public void updatePlayer(final EntityPlayer entityplayer) {
    // prevent updates to NPC "viewers"
    if (entityplayer instanceof EntityHumanNPC)
        return;
    Entity tracker = getTracker(this);
    if (entityplayer != tracker && c(entityplayer)) {
        if (!this.trackedPlayers.contains(entityplayer) && ((entityplayer.x().getPlayerChunkMap().a(entityplayer, tracker.ac, tracker.ae)) || (tracker.attachedToPlayer))) {
            if ((tracker instanceof SkinnableEntity)) {
                SkinnableEntity skinnable = (SkinnableEntity) tracker;
                Player player = skinnable.getBukkitEntity();
                if (!entityplayer.getBukkitEntity().canSee(player))
                    return;
                skinnable.getSkinTracker().updateViewer(entityplayer.getBukkitEntity());
            }
        }
    }
    super.updatePlayer(entityplayer);
}
Also used : SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) Entity(net.minecraft.server.v1_10_R1.Entity) EntityPlayer(net.minecraft.server.v1_10_R1.EntityPlayer) Player(org.bukkit.entity.Player) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) EntityHumanNPC(net.citizensnpcs.nms.v1_10_R1.entity.EntityHumanNPC)

Aggregations

SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)15 Player (org.bukkit.entity.Player)9 EntityPlayer (net.minecraft.server.v1_10_R1.EntityPlayer)2 EntityPlayer (net.minecraft.server.v1_11_R1.EntityPlayer)2 EntityPlayer (net.minecraft.server.v1_12_R1.EntityPlayer)2 EntityPlayer (net.minecraft.server.v1_8_R3.EntityPlayer)2 NPCNeedsRespawnEvent (net.citizensnpcs.NPCNeedsRespawnEvent)1 Command (net.citizensnpcs.api.command.Command)1 Requirements (net.citizensnpcs.api.command.Requirements)1 CommandException (net.citizensnpcs.api.command.exception.CommandException)1 ServerCommandException (net.citizensnpcs.api.command.exception.ServerCommandException)1 NPCSpawnEvent (net.citizensnpcs.api.event.NPCSpawnEvent)1 Trait (net.citizensnpcs.api.trait.Trait)1 Spawned (net.citizensnpcs.api.trait.trait.Spawned)1 EntityHumanNPC (net.citizensnpcs.nms.v1_10_R1.entity.EntityHumanNPC)1 EntityHumanNPC (net.citizensnpcs.nms.v1_11_R1.entity.EntityHumanNPC)1 EntityHumanNPC (net.citizensnpcs.nms.v1_12_R1.entity.EntityHumanNPC)1 EntityHumanNPC (net.citizensnpcs.nms.v1_8_R3.entity.EntityHumanNPC)1 CurrentLocation (net.citizensnpcs.trait.CurrentLocation)1 Entity (net.minecraft.server.v1_10_R1.Entity)1