Search in sources :

Example 76 with CraftWorld

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

the class PacketHelperImpl method showBlockAction.

@Override
public void showBlockAction(Player player, Location location, int action, int state) {
    BlockPosition position = new BlockPosition(location.getX(), location.getY(), location.getZ());
    Block block = ((CraftWorld) location.getWorld()).getHandle().getType(position).getBlock();
    sendPacket(player, new PacketPlayOutBlockAction(position, block, action, state));
}
Also used : FakeBlock(com.denizenscript.denizen.utilities.blocks.FakeBlock) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld)

Example 77 with CraftWorld

use of org.bukkit.craftbukkit.v1_16_R3.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.server.v1_16_R3.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.e(customId);
        nmsEntity.a_(customUUID);
    }
    EntityTag entity = new EntityTag(nmsEntity.getBukkitEntity());
    for (Mechanism mechanism : mechanisms) {
        entity.safeAdjustDuplicate(mechanism);
    }
    nmsEntity.dead = false;
    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) -> {
        EntityPlayer nmsPlayer = ((CraftPlayer) player.getPlayerEntity()).getHandle();
        PlayerConnection conn = nmsPlayer.playerConnection;
        final EntityTrackerEntry tracker = new EntityTrackerEntry(world.getHandle(), nmsEntity, 1, true, conn::sendPacket, Collections.singleton(nmsPlayer));
        tracker.b(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.b(((CraftPlayer) player.getPlayerEntity()).getHandle());
                            wasOnline = true;
                        }
                        tracker.a();
                    } 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.a();
            }
        }
    };
    fake.triggerDestroyPacket = () -> {
        for (TrackerData tracker : trackers) {
            if (tracker.player.isOnline()) {
                tracker.tracker.a(((CraftPlayer) tracker.player.getPlayerEntity()).getHandle());
            }
        }
        trackers.clear();
    };
    return fake;
}
Also used : FakeEntity(com.denizenscript.denizen.utilities.entity.FakeEntity) EntityItemProjectileImpl(com.denizenscript.denizen.nms.v1_16.impl.entities.EntityItemProjectileImpl) CraftFakePlayerImpl(com.denizenscript.denizen.nms.v1_16.impl.entities.CraftFakePlayerImpl) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) Mechanism(com.denizenscript.denizencore.objects.Mechanism) EntityTag(com.denizenscript.denizen.objects.EntityTag) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) ItemStack(org.bukkit.inventory.ItemStack) net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) ItemTag(com.denizenscript.denizen.objects.ItemTag)

Example 78 with CraftWorld

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

the class BlockHelperImpl method doRandomTick.

@Override
public void doRandomTick(Location location) {
    BlockPosition pos = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
    Chunk nmsChunk = ((CraftChunk) location.getChunk()).getHandle();
    IBlockData nmsBlock = nmsChunk.getType(pos);
    WorldServer nmsWorld = ((CraftWorld) location.getWorld()).getHandle();
    if (nmsBlock.isTicking()) {
        nmsBlock.b(nmsWorld, pos, nmsWorld.random);
    }
    Fluid fluid = nmsBlock.getFluid();
    if (fluid.f()) {
        fluid.b(nmsWorld, pos, nmsWorld.random);
    }
}
Also used : CraftChunk(org.bukkit.craftbukkit.v1_16_R3.CraftChunk) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) CraftChunk(org.bukkit.craftbukkit.v1_16_R3.CraftChunk)

Example 79 with CraftWorld

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

the class CustomEntityHelperImpl method spawnItemProjectile.

@Override
public ItemProjectile spawnItemProjectile(Location location, ItemStack itemStack) {
    CraftWorld world = (CraftWorld) location.getWorld();
    EntityItemProjectileImpl entity = new EntityItemProjectileImpl(world.getHandle(), location, CraftItemStack.asNMSCopy(itemStack));
    world.getHandle().addEntity(entity);
    return entity.getBukkitEntity();
}
Also used : EntityItemProjectileImpl(com.denizenscript.denizen.nms.v1_16.impl.entities.EntityItemProjectileImpl) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld)

Example 80 with CraftWorld

use of org.bukkit.craftbukkit.v1_16_R3.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.getChunkProvider();
    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_17_R1.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)22 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)20 ServerLevel (net.minecraft.server.level.ServerLevel)18 CraftWorld (org.bukkit.craftbukkit.v1_9_R1.CraftWorld)17 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