Search in sources :

Example 1 with EntityEffect

use of org.bukkit.EntityEffect in project Glowstone by GlowstoneMC.

the class GlowEntity method playEffect.

@Override
public void playEffect(EntityEffect type) {
    if (type.getApplicable().isInstance(this)) {
        EntityStatusMessage message = new EntityStatusMessage(entityId, type);
        world.getRawPlayers().stream().filter(player -> player.canSeeEntity(this)).forEach(player -> player.getSession().send(message));
    }
}
Also used : Plugin(org.bukkit.plugin.Plugin) EntityEffect(org.bukkit.EntityEffect) EntityUnleashEvent(org.bukkit.event.entity.EntityUnleashEvent) StatusFlags(net.glowstone.entity.meta.MetadataIndex.StatusFlags) UuidUtils(net.glowstone.util.UuidUtils) Projectile(org.bukkit.entity.Projectile) BlockFace(org.bukkit.block.BlockFace) Player(org.bukkit.entity.Player) EntityMountEvent(org.spigotmc.event.entity.EntityMountEvent) EntityPortalExitEvent(org.bukkit.event.entity.EntityPortalExitEvent) Block(org.bukkit.block.Block) Location(org.bukkit.Location) EntityRotationMessage(net.glowstone.net.message.play.entity.EntityRotationMessage) EntityStatusMessage(net.glowstone.net.message.play.entity.EntityStatusMessage) World(org.bukkit.World) InteractEntityMessage(net.glowstone.net.message.play.player.InteractEntityMessage) Chunk(org.bukkit.Chunk) BoundingBox(net.glowstone.entity.physics.BoundingBox) GlowWorld(net.glowstone.GlowWorld) GlowItemFrame(net.glowstone.entity.objects.GlowItemFrame) Material(org.bukkit.Material) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Position(net.glowstone.util.Position) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) PersistentDataContainer(org.bukkit.persistence.PersistentDataContainer) PistonMoveReaction(org.bukkit.block.PistonMoveReaction) EntityMetadataMessage(net.glowstone.net.message.play.entity.EntityMetadataMessage) Entity(org.bukkit.entity.Entity) CreatureSpawnEvent(org.bukkit.event.entity.CreatureSpawnEvent) GlowChunk(net.glowstone.chunk.GlowChunk) Set(java.util.Set) UUID(java.util.UUID) EntityType(org.bukkit.entity.EntityType) LivingEntity(org.bukkit.entity.LivingEntity) ItemStack(org.bukkit.inventory.ItemStack) EntityTeleportMessage(net.glowstone.net.message.play.entity.EntityTeleportMessage) Objects(java.util.Objects) EntityBoundingBox(net.glowstone.entity.physics.EntityBoundingBox) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) MetadataIndex(net.glowstone.entity.meta.MetadataIndex) MetadataValue(org.bukkit.metadata.MetadataValue) Entry(net.glowstone.entity.meta.MetadataMap.Entry) VehicleExitEvent(org.bukkit.event.vehicle.VehicleExitEvent) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) PlayerInitialSpawnEvent(com.destroystokyo.paper.event.player.PlayerInitialSpawnEvent) Setter(lombok.Setter) SetPassengerMessage(net.glowstone.net.message.play.entity.SetPassengerMessage) VehicleEnterEvent(org.bukkit.event.vehicle.VehicleEnterEvent) Getter(lombok.Getter) MetadataMap(net.glowstone.entity.meta.MetadataMap) Message(com.flowpowered.network.Message) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ArrayList(java.util.ArrayList) EntityDismountEvent(org.spigotmc.event.entity.EntityDismountEvent) Lists(com.google.common.collect.Lists) Environment(org.bukkit.World.Environment) PermissionAttachment(org.bukkit.permissions.PermissionAttachment) ImmutableList(com.google.common.collect.ImmutableList) GlowLeashHitch(net.glowstone.entity.objects.GlowLeashHitch) Component(net.kyori.adventure.text.Component) Vehicle(org.bukkit.entity.Vehicle) GlowSession(net.glowstone.net.GlowSession) GlowServer(net.glowstone.GlowServer) LinkedList(java.util.LinkedList) TextMessage(net.glowstone.util.TextMessage) RelativeEntityPositionMessage(net.glowstone.net.message.play.entity.RelativeEntityPositionMessage) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) MetadataStore(org.bukkit.metadata.MetadataStore) PlayerSpawnLocationEvent(org.spigotmc.event.player.PlayerSpawnLocationEvent) GlowPainting(net.glowstone.entity.objects.GlowPainting) EntityPortalEvent(org.bukkit.event.entity.EntityPortalEvent) TeleportCause(org.bukkit.event.player.PlayerTeleportEvent.TeleportCause) UnleashReason(org.bukkit.event.entity.EntityUnleashEvent.UnleashReason) EventFactory(net.glowstone.EventFactory) EntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) PermissionAttachmentInfo(org.bukkit.permissions.PermissionAttachmentInfo) EntityVelocityMessage(net.glowstone.net.message.play.entity.EntityVelocityMessage) Permission(org.bukkit.permissions.Permission) Vector(org.bukkit.util.Vector) AttachEntityMessage(net.glowstone.net.message.play.entity.AttachEntityMessage) Pose(org.bukkit.entity.Pose) Preconditions(com.google.common.base.Preconditions) RelativeEntityPositionRotationMessage(net.glowstone.net.message.play.entity.RelativeEntityPositionRotationMessage) EntityPortalEnterEvent(org.bukkit.event.entity.EntityPortalEnterEvent) MetadataStoreBase(org.bukkit.metadata.MetadataStoreBase) Collections(java.util.Collections) ProjectileHitEvent(org.bukkit.event.entity.ProjectileHitEvent) EntityStatusMessage(net.glowstone.net.message.play.entity.EntityStatusMessage)

Example 2 with EntityEffect

use of org.bukkit.EntityEffect in project Denizen-For-Bukkit by DenizenScript.

the class AnimateCommand method execute.

@Override
public void execute(final ScriptEntry scriptEntry) {
    List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
    List<PlayerTag> forPlayers = (List<PlayerTag>) scriptEntry.getObject("for");
    PlayerAnimation animation = scriptEntry.hasObject("animation") ? (PlayerAnimation) scriptEntry.getObject("animation") : null;
    EntityEffect effect = scriptEntry.hasObject("effect") ? (EntityEffect) scriptEntry.getObject("effect") : null;
    String nmsAnimation = scriptEntry.hasObject("nms_animation") ? (String) scriptEntry.getObject("nms_animation") : null;
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), (animation != null ? db("animation", animation.name()) : effect != null ? db("effect", effect.name()) : db("animation", nmsAnimation)), db("entities", entities), db("for", forPlayers));
    }
    for (EntityTag entity : entities) {
        if (entity.isSpawned()) {
            try {
                if (animation != null && entity.getBukkitEntity() instanceof Player) {
                    Player player = (Player) entity.getBukkitEntity();
                    animation.play(player);
                } else if (effect != null) {
                    if (forPlayers != null) {
                        for (PlayerTag player : forPlayers) {
                            NMSHandler.getPacketHelper().sendEntityEffect(player.getPlayerEntity(), entity.getBukkitEntity(), effect.getData());
                        }
                    } else {
                        entity.getBukkitEntity().playEffect(effect);
                    }
                } else if (nmsAnimation != null) {
                    EntityAnimation entityAnimation = NMSHandler.getAnimationHelper().getEntityAnimation(nmsAnimation);
                    entityAnimation.play(entity.getBukkitEntity());
                } else {
                    Debug.echoError("No way to play the given animation on entity '" + entity + "'");
                }
            } catch (Exception e) {
                Debug.echoError(scriptEntry, "Error playing that animation!");
                Debug.echoError(e);
            }
        }
    }
}
Also used : EntityEffect(org.bukkit.EntityEffect) EntityAnimation(com.denizenscript.denizen.nms.interfaces.EntityAnimation) Player(org.bukkit.entity.Player) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) PlayerAnimation(net.citizensnpcs.util.PlayerAnimation) EntityTag(com.denizenscript.denizen.objects.EntityTag) List(java.util.List) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 3 with EntityEffect

use of org.bukkit.EntityEffect in project Denizen-For-Bukkit by DenizenScript.

the class AnimateCommand method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
    // Get objects
    List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
    PlayerAnimation animation = scriptEntry.hasObject("animation") ? (PlayerAnimation) scriptEntry.getObject("animation") : null;
    EntityEffect effect = scriptEntry.hasObject("effect") ? (EntityEffect) scriptEntry.getObject("effect") : null;
    String nmsAnimation = scriptEntry.hasObject("nms_animation") ? (String) scriptEntry.getObject("nms_animation") : null;
    // Report to dB
    dB.report(scriptEntry, getName(), (animation != null ? aH.debugObj("animation", animation.name()) : effect != null ? aH.debugObj("effect", effect.name()) : aH.debugObj("animation", nmsAnimation)) + aH.debugObj("entities", entities.toString()));
    // Go through all the entities and animate them
    for (dEntity entity : entities) {
        if (entity.isSpawned()) {
            try {
                if (animation != null && entity.getBukkitEntity() instanceof Player) {
                    Player player = (Player) entity.getBukkitEntity();
                    animation.play(player);
                } else if (effect != null) {
                    entity.getBukkitEntity().playEffect(effect);
                } else {
                    EntityAnimation entityAnimation = NMSHandler.getInstance().getAnimationHelper().getEntityAnimation(nmsAnimation);
                    entityAnimation.play(entity.getBukkitEntity());
                }
            } catch (Exception e) {
                dB.echoError(scriptEntry.getResidingQueue(), "Error playing that animation!");
            }
        // We tried!
        }
    }
}
Also used : EntityEffect(org.bukkit.EntityEffect) EntityAnimation(net.aufdemrand.denizen.nms.interfaces.EntityAnimation) Player(org.bukkit.entity.Player) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) PlayerAnimation(net.citizensnpcs.util.PlayerAnimation) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException) CommandExecutionException(net.aufdemrand.denizencore.exceptions.CommandExecutionException)

Example 4 with EntityEffect

use of org.bukkit.EntityEffect in project Glowstone by GlowstoneMC.

the class GlowEntity method playEffectKnownAndSelf.

public void playEffectKnownAndSelf(EntityEffect type) {
    if (type.getApplicable().isInstance(this)) {
        EntityStatusMessage message = new EntityStatusMessage(entityId, type);
        if (this instanceof GlowPlayer) {
            ((GlowPlayer) this).getSession().send(message);
        }
        world.getRawPlayers().stream().filter(player -> player.canSeeEntity(this)).forEach(player -> player.getSession().send(message));
    }
}
Also used : Plugin(org.bukkit.plugin.Plugin) EntityEffect(org.bukkit.EntityEffect) EntityUnleashEvent(org.bukkit.event.entity.EntityUnleashEvent) StatusFlags(net.glowstone.entity.meta.MetadataIndex.StatusFlags) UuidUtils(net.glowstone.util.UuidUtils) Projectile(org.bukkit.entity.Projectile) BlockFace(org.bukkit.block.BlockFace) Player(org.bukkit.entity.Player) EntityMountEvent(org.spigotmc.event.entity.EntityMountEvent) EntityPortalExitEvent(org.bukkit.event.entity.EntityPortalExitEvent) Block(org.bukkit.block.Block) Location(org.bukkit.Location) EntityRotationMessage(net.glowstone.net.message.play.entity.EntityRotationMessage) EntityStatusMessage(net.glowstone.net.message.play.entity.EntityStatusMessage) World(org.bukkit.World) InteractEntityMessage(net.glowstone.net.message.play.player.InteractEntityMessage) Chunk(org.bukkit.Chunk) BoundingBox(net.glowstone.entity.physics.BoundingBox) GlowWorld(net.glowstone.GlowWorld) GlowItemFrame(net.glowstone.entity.objects.GlowItemFrame) Material(org.bukkit.Material) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Position(net.glowstone.util.Position) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) PersistentDataContainer(org.bukkit.persistence.PersistentDataContainer) PistonMoveReaction(org.bukkit.block.PistonMoveReaction) EntityMetadataMessage(net.glowstone.net.message.play.entity.EntityMetadataMessage) Entity(org.bukkit.entity.Entity) CreatureSpawnEvent(org.bukkit.event.entity.CreatureSpawnEvent) GlowChunk(net.glowstone.chunk.GlowChunk) Set(java.util.Set) UUID(java.util.UUID) EntityType(org.bukkit.entity.EntityType) LivingEntity(org.bukkit.entity.LivingEntity) ItemStack(org.bukkit.inventory.ItemStack) EntityTeleportMessage(net.glowstone.net.message.play.entity.EntityTeleportMessage) Objects(java.util.Objects) EntityBoundingBox(net.glowstone.entity.physics.EntityBoundingBox) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) MetadataIndex(net.glowstone.entity.meta.MetadataIndex) MetadataValue(org.bukkit.metadata.MetadataValue) Entry(net.glowstone.entity.meta.MetadataMap.Entry) VehicleExitEvent(org.bukkit.event.vehicle.VehicleExitEvent) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) PlayerInitialSpawnEvent(com.destroystokyo.paper.event.player.PlayerInitialSpawnEvent) Setter(lombok.Setter) SetPassengerMessage(net.glowstone.net.message.play.entity.SetPassengerMessage) VehicleEnterEvent(org.bukkit.event.vehicle.VehicleEnterEvent) Getter(lombok.Getter) MetadataMap(net.glowstone.entity.meta.MetadataMap) Message(com.flowpowered.network.Message) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ArrayList(java.util.ArrayList) EntityDismountEvent(org.spigotmc.event.entity.EntityDismountEvent) Lists(com.google.common.collect.Lists) Environment(org.bukkit.World.Environment) PermissionAttachment(org.bukkit.permissions.PermissionAttachment) ImmutableList(com.google.common.collect.ImmutableList) GlowLeashHitch(net.glowstone.entity.objects.GlowLeashHitch) Component(net.kyori.adventure.text.Component) Vehicle(org.bukkit.entity.Vehicle) GlowSession(net.glowstone.net.GlowSession) GlowServer(net.glowstone.GlowServer) LinkedList(java.util.LinkedList) TextMessage(net.glowstone.util.TextMessage) RelativeEntityPositionMessage(net.glowstone.net.message.play.entity.RelativeEntityPositionMessage) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) MetadataStore(org.bukkit.metadata.MetadataStore) PlayerSpawnLocationEvent(org.spigotmc.event.player.PlayerSpawnLocationEvent) GlowPainting(net.glowstone.entity.objects.GlowPainting) EntityPortalEvent(org.bukkit.event.entity.EntityPortalEvent) TeleportCause(org.bukkit.event.player.PlayerTeleportEvent.TeleportCause) UnleashReason(org.bukkit.event.entity.EntityUnleashEvent.UnleashReason) EventFactory(net.glowstone.EventFactory) EntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) PermissionAttachmentInfo(org.bukkit.permissions.PermissionAttachmentInfo) EntityVelocityMessage(net.glowstone.net.message.play.entity.EntityVelocityMessage) Permission(org.bukkit.permissions.Permission) Vector(org.bukkit.util.Vector) AttachEntityMessage(net.glowstone.net.message.play.entity.AttachEntityMessage) Pose(org.bukkit.entity.Pose) Preconditions(com.google.common.base.Preconditions) RelativeEntityPositionRotationMessage(net.glowstone.net.message.play.entity.RelativeEntityPositionRotationMessage) EntityPortalEnterEvent(org.bukkit.event.entity.EntityPortalEnterEvent) MetadataStoreBase(org.bukkit.metadata.MetadataStoreBase) Collections(java.util.Collections) ProjectileHitEvent(org.bukkit.event.entity.ProjectileHitEvent) EntityStatusMessage(net.glowstone.net.message.play.entity.EntityStatusMessage)

Aggregations

List (java.util.List)4 EntityEffect (org.bukkit.EntityEffect)4 Player (org.bukkit.entity.Player)4 PlayerInitialSpawnEvent (com.destroystokyo.paper.event.player.PlayerInitialSpawnEvent)2 Message (com.flowpowered.network.Message)2 Preconditions (com.google.common.base.Preconditions)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 ImmutableList (com.google.common.collect.ImmutableList)2 Lists (com.google.common.collect.Lists)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 LinkedList (java.util.LinkedList)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Set (java.util.Set)2 UUID (java.util.UUID)2 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)2 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)2 Getter (lombok.Getter)2 Setter (lombok.Setter)2