Search in sources :

Example 96 with CraftWorld

use of org.bukkit.craftbukkit.v1_8_R1.CraftWorld in project Denizen-For-Bukkit by DenizenScript.

the class PlayerHelperImpl method sendEntitySpawn.

@Override
public FakeEntity sendEntitySpawn(List<PlayerTag> players, DenizenEntityType entityType, LocationTag location, ArrayList<Mechanism> mechanisms, int customId, UUID customUUID, boolean autoTrack) {
    CraftWorld world = ((CraftWorld) location.getWorld());
    net.minecraft.world.entity.Entity nmsEntity;
    if (entityType.isCustom()) {
        if (entityType.customEntityType == CustomEntityType.ITEM_PROJECTILE) {
            org.bukkit.inventory.ItemStack itemStack = new ItemStack(Material.STONE);
            for (Mechanism mechanism : mechanisms) {
                if (mechanism.matches("item") && mechanism.requireObject(ItemTag.class)) {
                    itemStack = mechanism.valueAsType(ItemTag.class).getItemStack();
                }
            }
            nmsEntity = new EntityItemProjectileImpl(world.getHandle(), location, CraftItemStack.asNMSCopy(itemStack));
        } else if (entityType.customEntityType == CustomEntityType.FAKE_PLAYER) {
            String name = null;
            String skin = null;
            for (Mechanism mechanism : new ArrayList<>(mechanisms)) {
                if (mechanism.matches("name")) {
                    name = mechanism.getValue().asString();
                    mechanisms.remove(mechanism);
                } else if (mechanism.matches("skin")) {
                    skin = mechanism.getValue().asString();
                    mechanisms.remove(mechanism);
                }
                if (name != null && skin != null) {
                    break;
                }
            }
            nmsEntity = ((CraftFakePlayerImpl) CustomEntityHelperImpl.spawnFakePlayer(location, name, skin, false)).getHandle();
        } else {
            throw new IllegalArgumentException("entityType");
        }
    } else {
        nmsEntity = world.createEntity(location, entityType.getBukkitEntityType().getEntityClass());
    }
    if (customUUID != null) {
        nmsEntity.setId(customId);
        nmsEntity.setUUID(customUUID);
    }
    EntityTag entity = new EntityTag(nmsEntity.getBukkitEntity());
    entity.isFake = true;
    entity.isFakeValid = true;
    for (Mechanism mechanism : mechanisms) {
        entity.safeAdjustDuplicate(mechanism);
    }
    nmsEntity.unsetRemoved();
    FakeEntity fake = new FakeEntity(players, location, entity.getBukkitEntity().getEntityId());
    fake.entity = new EntityTag(entity.getBukkitEntity());
    fake.entity.isFake = true;
    fake.entity.isFakeValid = true;
    List<TrackerData> trackers = new ArrayList<>();
    fake.triggerSpawnPacket = (player) -> {
        ServerPlayer nmsPlayer = ((CraftPlayer) player.getPlayerEntity()).getHandle();
        ServerGamePacketListenerImpl conn = nmsPlayer.connection;
        final ServerEntity tracker = new ServerEntity(world.getHandle(), nmsEntity, 1, true, conn::send, Collections.singleton(nmsPlayer.connection));
        tracker.addPairing(nmsPlayer);
        final TrackerData data = new TrackerData();
        data.player = player;
        data.tracker = tracker;
        trackers.add(data);
        if (autoTrack) {
            new BukkitRunnable() {

                boolean wasOnline = true;

                @Override
                public void run() {
                    if (!fake.entity.isFakeValid) {
                        cancel();
                        return;
                    }
                    if (player.isOnline()) {
                        if (!wasOnline) {
                            tracker.addPairing(((CraftPlayer) player.getPlayerEntity()).getHandle());
                            wasOnline = true;
                        }
                        tracker.sendChanges();
                    } else if (wasOnline) {
                        wasOnline = false;
                    }
                }
            }.runTaskTimer(Denizen.getInstance(), 1, 1);
        }
    };
    for (PlayerTag player : players) {
        fake.triggerSpawnPacket.accept(player);
    }
    fake.triggerUpdatePacket = () -> {
        for (TrackerData tracker : trackers) {
            if (tracker.player.isOnline()) {
                tracker.tracker.sendChanges();
            }
        }
    };
    fake.triggerDestroyPacket = () -> {
        for (TrackerData tracker : trackers) {
            if (tracker.player.isOnline()) {
                tracker.tracker.removePairing(((CraftPlayer) tracker.player.getPlayerEntity()).getHandle());
            }
        }
        trackers.clear();
    };
    return fake;
}
Also used : FakeEntity(com.denizenscript.denizen.utilities.entity.FakeEntity) EntityItemProjectileImpl(com.denizenscript.denizen.nms.v1_18.impl.entities.EntityItemProjectileImpl) CraftFakePlayerImpl(com.denizenscript.denizen.nms.v1_18.impl.entities.CraftFakePlayerImpl) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) Mechanism(com.denizenscript.denizencore.objects.Mechanism) ServerEntity(net.minecraft.server.level.ServerEntity) EntityTag(com.denizenscript.denizen.objects.EntityTag) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld) ServerGamePacketListenerImpl(net.minecraft.server.network.ServerGamePacketListenerImpl) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) ItemStack(org.bukkit.inventory.ItemStack) ServerPlayer(net.minecraft.server.level.ServerPlayer) CraftItemStack(org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) ItemTag(com.denizenscript.denizen.objects.ItemTag)

Example 97 with CraftWorld

use of org.bukkit.craftbukkit.v1_8_R1.CraftWorld in project Denizen-For-Bukkit by DenizenScript.

the class WorldHelperImpl method setStatic.

@Override
public void setStatic(World world, boolean isStatic) {
    ServerLevel worldServer = ((CraftWorld) world).getHandle();
    ReflectionHelper.setFieldValue(net.minecraft.world.level.Level.class, ReflectionMappingsInfo.Level_isClientSide, worldServer, isStatic);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld)

Example 98 with CraftWorld

use of org.bukkit.craftbukkit.v1_8_R1.CraftWorld in project Denizen-For-Bukkit by DenizenScript.

the class ChunkHelperImpl method changeChunkServerThread.

@Override
public void changeChunkServerThread(World world) {
    if (DenizenCoreImplementation.tagThread == null) {
        return;
    }
    if (resetServerThread != null) {
        return;
    }
    ServerLevel nmsWorld = ((CraftWorld) world).getHandle();
    ServerChunkCache provider = nmsWorld.getChunkSource();
    try {
        resetServerThread = (Thread) chunkProviderServerThreadField.get(provider);
        chunkProviderServerThreadFieldSetter.invoke(provider, Thread.currentThread());
        worldThreadFieldSetter.invoke(nmsWorld, Thread.currentThread());
    } catch (Throwable ex) {
        Debug.echoError(ex);
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ServerChunkCache(net.minecraft.server.level.ServerChunkCache) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld)

Example 99 with CraftWorld

use of org.bukkit.craftbukkit.v1_8_R1.CraftWorld in project Denizen-For-Bukkit by DenizenScript.

the class ChunkHelperImpl method restoreServerThread.

@Override
public void restoreServerThread(World world) {
    if (DenizenCoreImplementation.tagThread == null) {
        return;
    }
    if (resetServerThread == null) {
        return;
    }
    ServerLevel nmsWorld = ((CraftWorld) world).getHandle();
    ServerChunkCache provider = nmsWorld.getChunkSource();
    try {
        chunkProviderServerThreadFieldSetter.invoke(provider, resetServerThread);
        worldThreadFieldSetter.invoke(nmsWorld, resetServerThread);
        resetServerThread = null;
    } catch (Throwable ex) {
        Debug.echoError(ex);
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ServerChunkCache(net.minecraft.server.level.ServerChunkCache) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld)

Example 100 with CraftWorld

use of org.bukkit.craftbukkit.v1_8_R1.CraftWorld in project Denizen-For-Bukkit by DenizenScript.

the class CustomEntityHelper_v1_8_R3 method spawnItemProjectile.

@Override
public ItemProjectile spawnItemProjectile(Location location, ItemStack itemStack) {
    CraftWorld world = (CraftWorld) location.getWorld();
    EntityItemProjectile_v1_8_R3 entity = new EntityItemProjectile_v1_8_R3(world, location, itemStack);
    return entity.getBukkitEntity();
}
Also used : EntityItemProjectile_v1_8_R3(net.aufdemrand.denizen.nms.impl.entities.EntityItemProjectile_v1_8_R3) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld)

Aggregations

Location (org.bukkit.Location)55 Zombie (org.bukkit.entity.Zombie)32 CraftWorld (org.bukkit.craftbukkit.v1_11_R1.CraftWorld)28 CraftWorld (org.bukkit.craftbukkit.v1_8_R3.CraftWorld)28 ItemStack (org.bukkit.inventory.ItemStack)27 CraftWorld (org.bukkit.craftbukkit.v1_12_R1.CraftWorld)23 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)19 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)17 CraftWorld (org.bukkit.craftbukkit.v1_9_R1.CraftWorld)17 ServerLevel (net.minecraft.server.level.ServerLevel)16 CraftWorld (org.bukkit.craftbukkit.v1_10_R1.CraftWorld)16 GameProfile (com.mojang.authlib.GameProfile)11 UUID (java.util.UUID)11 Scoreboard (org.bukkit.scoreboard.Scoreboard)11 Team (org.bukkit.scoreboard.Team)11 CraftWorld (org.bukkit.craftbukkit.v1_9_R2.CraftWorld)8 BabyZombie (pl.plajer.villagedefense3.creatures.v1_9_R1.BabyZombie)8 FastZombie (pl.plajer.villagedefense3.creatures.v1_9_R1.FastZombie)8 HardZombie (pl.plajer.villagedefense3.creatures.v1_9_R1.HardZombie)8 TankerZombie (pl.plajer.villagedefense3.creatures.v1_9_R1.TankerZombie)8