Search in sources :

Example 11 with Entity

use of net.minecraft.server.v1_14_R1.Entity in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelperImpl method setSpeed.

@Override
public void setSpeed(Entity entity, double speed) {
    net.minecraft.world.entity.Entity nmsEntityEntity = ((CraftEntity) entity).getHandle();
    if (!(nmsEntityEntity instanceof Mob)) {
        return;
    }
    Mob nmsEntity = (Mob) nmsEntityEntity;
    nmsEntity.getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(speed);
}
Also used : Mob(net.minecraft.world.entity.Mob) org.bukkit.craftbukkit.v1_17_R1.entity(org.bukkit.craftbukkit.v1_17_R1.entity) org.bukkit.entity(org.bukkit.entity) net.minecraft.world.entity(net.minecraft.world.entity)

Example 12 with Entity

use of net.minecraft.server.v1_14_R1.Entity in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelperImpl method sendHidePacket.

/*
        Hide Entity
     */
@Override
public void sendHidePacket(Player pl, Entity entity) {
    if (entity instanceof Player) {
        pl.hidePlayer(Denizen.getInstance(), (Player) entity);
        return;
    }
    CraftPlayer craftPlayer = (CraftPlayer) pl;
    ServerPlayer entityPlayer = craftPlayer.getHandle();
    if (entityPlayer.connection != null && !craftPlayer.equals(entity)) {
        ChunkMap tracker = ((ServerLevel) craftPlayer.getHandle().level).getChunkProvider().chunkMap;
        net.minecraft.world.entity.Entity other = ((CraftEntity) entity).getHandle();
        ChunkMap.TrackedEntity entry = tracker.G.get(other.getId());
        if (entry != null) {
            entry.removePlayer(entityPlayer);
        }
        if (Denizen.supportsPaper) {
            // Workaround for Paper issue
            entityPlayer.connection.send(new ClientboundRemoveEntitiesPacket(other.getId()));
        }
    }
}
Also used : ServerPlayer(net.minecraft.server.level.ServerPlayer) ChunkMap(net.minecraft.server.level.ChunkMap) ClientboundRemoveEntitiesPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket) ServerPlayer(net.minecraft.server.level.ServerPlayer) org.bukkit.craftbukkit.v1_17_R1.entity(org.bukkit.craftbukkit.v1_17_R1.entity) org.bukkit.entity(org.bukkit.entity) net.minecraft.world.entity(net.minecraft.world.entity)

Example 13 with Entity

use of net.minecraft.server.v1_14_R1.Entity in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelperImpl method follow.

@Override
public void follow(final Entity target, final Entity follower, final double speed, final double lead, final double maxRange, final boolean allowWander, final boolean teleport) {
    if (target == null || follower == null) {
        return;
    }
    final net.minecraft.world.entity.Entity nmsEntityFollower = ((CraftEntity) follower).getHandle();
    if (!(nmsEntityFollower instanceof Mob)) {
        return;
    }
    final Mob nmsFollower = (Mob) nmsEntityFollower;
    final PathNavigation followerNavigation = nmsFollower.getNavigation();
    UUID uuid = follower.getUniqueId();
    if (followTasks.containsKey(uuid)) {
        followTasks.get(uuid).cancel();
    }
    final int locationNearInt = (int) Math.floor(lead);
    final boolean hasMax = maxRange > lead;
    followTasks.put(follower.getUniqueId(), new BukkitRunnable() {

        private boolean inRadius = false;

        public void run() {
            if (!target.isValid() || !follower.isValid()) {
                this.cancel();
            }
            followerNavigation.setSpeedModifier(2D);
            Location targetLocation = target.getLocation();
            Path path;
            if (hasMax && !Utilities.checkLocation(targetLocation, follower.getLocation(), maxRange) && !target.isDead() && target.isOnGround()) {
                if (!inRadius) {
                    if (teleport) {
                        follower.teleport(Utilities.getWalkableLocationNear(targetLocation, locationNearInt));
                    } else {
                        cancel();
                    }
                } else {
                    inRadius = false;
                    path = followerNavigation.createPath(targetLocation.getX(), targetLocation.getY(), targetLocation.getZ(), 0);
                    if (path != null) {
                        followerNavigation.moveTo(path, 1D);
                        followerNavigation.setSpeedModifier(2D);
                    }
                }
            } else if (!inRadius && !Utilities.checkLocation(targetLocation, follower.getLocation(), lead)) {
                path = followerNavigation.createPath(targetLocation.getX(), targetLocation.getY(), targetLocation.getZ(), 0);
                if (path != null) {
                    followerNavigation.moveTo(path, 1D);
                    followerNavigation.setSpeedModifier(2D);
                }
            } else {
                inRadius = true;
            }
            if (inRadius && !allowWander) {
                followerNavigation.stop();
            }
            nmsFollower.getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(speed);
        }
    }.runTaskTimer(NMSHandler.getJavaPlugin(), 0, 10));
}
Also used : Path(net.minecraft.world.level.pathfinder.Path) Mob(net.minecraft.world.entity.Mob) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) PathNavigation(net.minecraft.world.entity.ai.navigation.PathNavigation) org.bukkit.craftbukkit.v1_17_R1.entity(org.bukkit.craftbukkit.v1_17_R1.entity) org.bukkit.entity(org.bukkit.entity) net.minecraft.world.entity(net.minecraft.world.entity) ResourceLocation(net.minecraft.resources.ResourceLocation) Location(org.bukkit.Location)

Example 14 with Entity

use of net.minecraft.server.v1_14_R1.Entity in project java-docs-samples by GoogleCloudPlatform.

the class Detect method analyzeLabels.

/**
 * Performs label analysis on the video at the provided Cloud Storage path.
 *
 * @param gcsUri the path to the video file to analyze.
 */
public static void analyzeLabels(String gcsUri) throws Exception {
    // Instantiate a com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient
    try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) {
        // Provide path to file hosted on GCS as "gs://bucket-name/..."
        AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder().setInputUri(gcsUri).addFeatures(Feature.LABEL_DETECTION).build();
        // Create an operation that will contain the response when the operation completes.
        OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> response = client.annotateVideoAsync(request);
        System.out.println("Waiting for operation to complete...");
        for (VideoAnnotationResults results : response.get().getAnnotationResultsList()) {
            // process video / segment level label annotations
            System.out.println("Locations: ");
            for (LabelAnnotation labelAnnotation : results.getSegmentLabelAnnotationsList()) {
                System.out.println("Video label: " + labelAnnotation.getEntity().getDescription());
                // categories
                for (Entity categoryEntity : labelAnnotation.getCategoryEntitiesList()) {
                    System.out.println("Video label category: " + categoryEntity.getDescription());
                }
                // segments
                for (LabelSegment segment : labelAnnotation.getSegmentsList()) {
                    double startTime = segment.getSegment().getStartTimeOffset().getSeconds() + segment.getSegment().getStartTimeOffset().getNanos() / 1e9;
                    double endTime = segment.getSegment().getEndTimeOffset().getSeconds() + segment.getSegment().getEndTimeOffset().getNanos() / 1e9;
                    System.out.printf("Segment location: %.3f:%.3f\n", startTime, endTime);
                    System.out.println("Confidence: " + segment.getConfidence());
                }
            }
            // process shot label annotations
            for (LabelAnnotation labelAnnotation : results.getShotLabelAnnotationsList()) {
                System.out.println("Shot label: " + labelAnnotation.getEntity().getDescription());
                // categories
                for (Entity categoryEntity : labelAnnotation.getCategoryEntitiesList()) {
                    System.out.println("Shot label category: " + categoryEntity.getDescription());
                }
                // segments
                for (LabelSegment segment : labelAnnotation.getSegmentsList()) {
                    double startTime = segment.getSegment().getStartTimeOffset().getSeconds() + segment.getSegment().getStartTimeOffset().getNanos() / 1e9;
                    double endTime = segment.getSegment().getEndTimeOffset().getSeconds() + segment.getSegment().getEndTimeOffset().getNanos() / 1e9;
                    System.out.printf("Segment location: %.3f:%.3f\n", startTime, endTime);
                    System.out.println("Confidence: " + segment.getConfidence());
                }
            }
            // process frame label annotations
            for (LabelAnnotation labelAnnotation : results.getFrameLabelAnnotationsList()) {
                System.out.println("Frame label: " + labelAnnotation.getEntity().getDescription());
                // categories
                for (Entity categoryEntity : labelAnnotation.getCategoryEntitiesList()) {
                    System.out.println("Frame label category: " + categoryEntity.getDescription());
                }
                // segments
                for (LabelSegment segment : labelAnnotation.getSegmentsList()) {
                    double startTime = segment.getSegment().getStartTimeOffset().getSeconds() + segment.getSegment().getStartTimeOffset().getNanos() / 1e9;
                    double endTime = segment.getSegment().getEndTimeOffset().getSeconds() + segment.getSegment().getEndTimeOffset().getNanos() / 1e9;
                    System.out.printf("Segment location: %.3f:%.2f\n", startTime, endTime);
                    System.out.println("Confidence: " + segment.getConfidence());
                }
            }
        }
    }
// [END detect_labels_gcs]
}
Also used : VideoIntelligenceServiceClient(com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient) AnnotateVideoProgress(com.google.cloud.videointelligence.v1.AnnotateVideoProgress) Entity(com.google.cloud.videointelligence.v1.Entity) LabelSegment(com.google.cloud.videointelligence.v1.LabelSegment) AnnotateVideoRequest(com.google.cloud.videointelligence.v1.AnnotateVideoRequest) VideoAnnotationResults(com.google.cloud.videointelligence.v1.VideoAnnotationResults) LabelAnnotation(com.google.cloud.videointelligence.v1.LabelAnnotation) AnnotateVideoResponse(com.google.cloud.videointelligence.v1.AnnotateVideoResponse)

Example 15 with Entity

use of net.minecraft.server.v1_14_R1.Entity in project java-docs-samples by GoogleCloudPlatform.

the class QuickstartSample method main.

/**
 * Demonstrates using the video intelligence client to detect labels in a video file.
 */
public static void main(String[] args) throws Exception {
    // Instantiate a video intelligence client
    try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) {
        // The Google Cloud Storage path to the video to annotate.
        String gcsUri = "gs://demomaker/cat.mp4";
        // Create an operation that will contain the response when the operation completes.
        AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder().setInputUri(gcsUri).addFeatures(Feature.LABEL_DETECTION).build();
        OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> response = client.annotateVideoAsync(request);
        System.out.println("Waiting for operation to complete...");
        List<VideoAnnotationResults> results = response.get().getAnnotationResultsList();
        if (results.isEmpty()) {
            System.out.println("No labels detected in " + gcsUri);
            return;
        }
        for (VideoAnnotationResults result : results) {
            System.out.println("Labels:");
            // get video segment label annotations
            for (LabelAnnotation annotation : result.getSegmentLabelAnnotationsList()) {
                System.out.println("Video label description : " + annotation.getEntity().getDescription());
                // categories
                for (Entity categoryEntity : annotation.getCategoryEntitiesList()) {
                    System.out.println("Label Category description : " + categoryEntity.getDescription());
                }
                // segments
                for (LabelSegment segment : annotation.getSegmentsList()) {
                    double startTime = segment.getSegment().getStartTimeOffset().getSeconds() + segment.getSegment().getStartTimeOffset().getNanos() / 1e9;
                    double endTime = segment.getSegment().getEndTimeOffset().getSeconds() + segment.getSegment().getEndTimeOffset().getNanos() / 1e9;
                    System.out.printf("Segment location : %.3f:%.3f\n", startTime, endTime);
                    System.out.println("Confidence : " + segment.getConfidence());
                }
            }
        }
    }
}
Also used : VideoIntelligenceServiceClient(com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient) AnnotateVideoProgress(com.google.cloud.videointelligence.v1.AnnotateVideoProgress) Entity(com.google.cloud.videointelligence.v1.Entity) LabelSegment(com.google.cloud.videointelligence.v1.LabelSegment) AnnotateVideoRequest(com.google.cloud.videointelligence.v1.AnnotateVideoRequest) VideoAnnotationResults(com.google.cloud.videointelligence.v1.VideoAnnotationResults) LabelAnnotation(com.google.cloud.videointelligence.v1.LabelAnnotation) AnnotateVideoResponse(com.google.cloud.videointelligence.v1.AnnotateVideoResponse)

Aggregations

LivingEntity (org.bukkit.entity.LivingEntity)95 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)88 net.minecraft.world.entity (net.minecraft.world.entity)32 org.bukkit.entity (org.bukkit.entity)32 Entity (com.google.datastore.v1.Entity)31 Location (org.bukkit.Location)30 ArrayList (java.util.ArrayList)21 Test (org.junit.Test)21 Entity (net.minecraft.server.v1_12_R1.Entity)20 Entity (net.minecraft.server.v1_16_R3.Entity)19 NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)18 Player (org.bukkit.entity.Player)18 Entity (net.minecraft.server.v1_8_R3.Entity)17 Entity (net.minecraft.server.v1_11_R1.Entity)16 Mob (net.minecraft.world.entity.Mob)16 CraftEntity (org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity)16 org.bukkit.craftbukkit.v1_17_R1.entity (org.bukkit.craftbukkit.v1_17_R1.entity)16 PathEntity (net.minecraft.server.v1_16_R3.PathEntity)13 Entity (net.minecraft.server.v1_15_R1.Entity)12 Entity (net.minecraft.server.v1_13_R2.Entity)11