Search in sources :

Example 41 with Entity

use of net.minecraft.server.v1_11_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 42 with Entity

use of net.minecraft.server.v1_11_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 43 with Entity

use of net.minecraft.server.v1_11_R1.Entity in project beam by apache.

the class EntityToRowRowToEntityTest method testRowToEntityConverterWithoutKey.

@Test
public void testRowToEntityConverterWithoutKey() {
    Schema schemaWithoutKey = Schema.builder().addFields(SCHEMA.getFields().stream().filter(f -> !f.getName().equals("__key__")).collect(Collectors.toList())).build();
    Row rowWithoutKey = Row.withSchema(schemaWithoutKey).addValues(schemaWithoutKey.getFieldNames().stream().map(ROW::getValue).collect(Collectors.toList())).build();
    PCollection<Entity> result = pipeline.apply(Create.of(rowWithoutKey)).setRowSchema(schemaWithoutKey).apply(RowToEntity.createTest(UUID_VALUE, "__key__", KIND));
    PAssert.that(result).containsInAnyOrder(ENTITY);
    pipeline.run().waitUntilFinish();
}
Also used : Arrays(java.util.Arrays) RunWith(org.junit.runner.RunWith) DatastoreHelper.makeValue(com.google.datastore.v1.client.DatastoreHelper.makeValue) INT64(org.apache.beam.sdk.schemas.Schema.FieldType.INT64) DOUBLE(org.apache.beam.sdk.schemas.Schema.FieldType.DOUBLE) Key(com.google.datastore.v1.Key) Create(org.apache.beam.sdk.transforms.Create) DatastoreHelper.makeKey(com.google.datastore.v1.client.DatastoreHelper.makeKey) TestPipeline(org.apache.beam.sdk.testing.TestPipeline) Value(com.google.datastore.v1.Value) Row(org.apache.beam.sdk.values.Row) FieldType.array(org.apache.beam.sdk.schemas.Schema.FieldType.array) DateTimeFormat(org.joda.time.format.DateTimeFormat) PAssert(org.apache.beam.sdk.testing.PAssert) DateTime(org.joda.time.DateTime) FieldType(org.apache.beam.sdk.schemas.Schema.FieldType) Test(org.junit.Test) BYTES(org.apache.beam.sdk.schemas.Schema.FieldType.BYTES) UUID(java.util.UUID) JUnit4(org.junit.runners.JUnit4) DATETIME(org.apache.beam.sdk.schemas.Schema.FieldType.DATETIME) PCollection(org.apache.beam.sdk.values.PCollection) Collectors(java.util.stream.Collectors) Schema(org.apache.beam.sdk.schemas.Schema) StandardCharsets(java.nio.charset.StandardCharsets) Entity(com.google.datastore.v1.Entity) ByteString(com.google.protobuf.ByteString) BOOLEAN(org.apache.beam.sdk.schemas.Schema.FieldType.BOOLEAN) Rule(org.junit.Rule) STRING(org.apache.beam.sdk.schemas.Schema.FieldType.STRING) Collections(java.util.Collections) Entity(com.google.datastore.v1.Entity) Schema(org.apache.beam.sdk.schemas.Schema) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Example 44 with Entity

use of net.minecraft.server.v1_11_R1.Entity in project beam by apache.

the class EntityToRowRowToEntityTest method testEntityToRowConverterWithoutKey.

@Test
public void testEntityToRowConverterWithoutKey() {
    Schema schemaWithoutKey = Schema.builder().addFields(SCHEMA.getFields().stream().filter(f -> !f.getName().equals("__key__")).collect(Collectors.toList())).build();
    Row rowWithoutKey = Row.withSchema(schemaWithoutKey).addValues(schemaWithoutKey.getFieldNames().stream().map(ROW::getValue).collect(Collectors.toList())).build();
    PCollection<Row> result = pipeline.apply(Create.of(ENTITY)).apply(EntityToRow.create(schemaWithoutKey, DEFAULT_KEY_FIELD));
    PAssert.that(result).containsInAnyOrder(rowWithoutKey);
    pipeline.run().waitUntilFinish();
}
Also used : Arrays(java.util.Arrays) RunWith(org.junit.runner.RunWith) DatastoreHelper.makeValue(com.google.datastore.v1.client.DatastoreHelper.makeValue) INT64(org.apache.beam.sdk.schemas.Schema.FieldType.INT64) DOUBLE(org.apache.beam.sdk.schemas.Schema.FieldType.DOUBLE) Key(com.google.datastore.v1.Key) Create(org.apache.beam.sdk.transforms.Create) DatastoreHelper.makeKey(com.google.datastore.v1.client.DatastoreHelper.makeKey) TestPipeline(org.apache.beam.sdk.testing.TestPipeline) Value(com.google.datastore.v1.Value) Row(org.apache.beam.sdk.values.Row) FieldType.array(org.apache.beam.sdk.schemas.Schema.FieldType.array) DateTimeFormat(org.joda.time.format.DateTimeFormat) PAssert(org.apache.beam.sdk.testing.PAssert) DateTime(org.joda.time.DateTime) FieldType(org.apache.beam.sdk.schemas.Schema.FieldType) Test(org.junit.Test) BYTES(org.apache.beam.sdk.schemas.Schema.FieldType.BYTES) UUID(java.util.UUID) JUnit4(org.junit.runners.JUnit4) DATETIME(org.apache.beam.sdk.schemas.Schema.FieldType.DATETIME) PCollection(org.apache.beam.sdk.values.PCollection) Collectors(java.util.stream.Collectors) Schema(org.apache.beam.sdk.schemas.Schema) StandardCharsets(java.nio.charset.StandardCharsets) Entity(com.google.datastore.v1.Entity) ByteString(com.google.protobuf.ByteString) BOOLEAN(org.apache.beam.sdk.schemas.Schema.FieldType.BOOLEAN) Rule(org.junit.Rule) STRING(org.apache.beam.sdk.schemas.Schema.FieldType.STRING) Collections(java.util.Collections) Schema(org.apache.beam.sdk.schemas.Schema) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Example 45 with Entity

use of net.minecraft.server.v1_11_R1.Entity in project beam by apache.

the class DatastoreV1Test method testReadFnRetriesErrors.

/**
 * Tests that {@link ReadFn} retries after an error.
 */
@Test
public void testReadFnRetriesErrors() throws Exception {
    // An empty query to read entities.
    Query query = Query.newBuilder().setLimit(Int32Value.newBuilder().setValue(1)).build();
    // Use mockResponseForQuery to generate results.
    when(mockDatastore.runQuery(any(RunQueryRequest.class))).thenThrow(new DatastoreException("RunQuery", Code.DEADLINE_EXCEEDED, "", null)).thenAnswer(invocationOnMock -> {
        Query q = ((RunQueryRequest) invocationOnMock.getArguments()[0]).getQuery();
        return mockResponseForQuery(q);
    });
    ReadFn readFn = new ReadFn(V_1_OPTIONS, mockDatastoreFactory);
    DoFnTester<Query, Entity> doFnTester = DoFnTester.of(readFn);
    doFnTester.setCloningBehavior(CloningBehavior.DO_NOT_CLONE);
    doFnTester.processBundle(query);
    verifyMetricWasSet("BatchDatastoreRead", "ok", NAMESPACE, 1);
    verifyMetricWasSet("BatchDatastoreRead", "unknown", NAMESPACE, 1);
}
Also used : Entity(com.google.datastore.v1.Entity) DeleteEntity(org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteEntity) GqlQuery(com.google.datastore.v1.GqlQuery) Query(com.google.datastore.v1.Query) ReadFn(org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.Read.ReadFn) RunQueryRequest(com.google.datastore.v1.RunQueryRequest) DatastoreException(com.google.datastore.v1.client.DatastoreException) Test(org.junit.Test)

Aggregations

SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)41 LivingEntity (org.bukkit.entity.LivingEntity)41 CraftEntity (org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity)17 net.minecraft.world.entity (net.minecraft.world.entity)16 org.bukkit.entity (org.bukkit.entity)16 Entity (net.minecraft.server.v1_12_R1.Entity)13 Entity (com.google.datastore.v1.Entity)12 Entity (net.minecraft.server.v1_11_R1.Entity)12 Entity (net.minecraft.server.v1_8_R3.Entity)11 PathEntity (net.minecraft.server.v1_11_R1.PathEntity)10 NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)9 PathEntity (net.minecraft.server.v1_8_R3.PathEntity)9 CraftEntity (org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity)9 Entity (net.minecraft.server.v1_10_R1.Entity)8 PathEntity (net.minecraft.server.v1_12_R1.PathEntity)8 Mob (net.minecraft.world.entity.Mob)8 CraftWorld (org.bukkit.craftbukkit.v1_11_R1.CraftWorld)8 CraftEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity)8 Test (org.junit.Test)8 Key (com.google.datastore.v1.Key)7