Search in sources :

Example 51 with CraftWorld

use of org.bukkit.craftbukkit.v1_16_R2.CraftWorld in project RayTraceAntiXray by stonar96.

the class WorldListener method onWorldInit.

@SuppressWarnings("deprecation")
@EventHandler
public void onWorldInit(WorldInitEvent event) {
    if (plugin.isEnabled(event.getWorld())) {
        List<String> toTrace = plugin.getConfig().getList("world-settings." + event.getWorld().getName() + ".anti-xray.ray-trace-blocks", plugin.getConfig().getList("world-settings.default.anti-xray.ray-trace-blocks")).stream().filter(o -> o != null).map(String::valueOf).collect(Collectors.toList());
        try {
            Field chunkPacketBlockController = Level.class.getDeclaredField("chunkPacketBlockController");
            chunkPacketBlockController.setAccessible(true);
            Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
            theUnsafe.setAccessible(true);
            Unsafe unsafe = (Unsafe) theUnsafe.get(null);
            unsafe.putObject(((CraftWorld) event.getWorld()).getHandle(), unsafe.objectFieldOffset(chunkPacketBlockController), new ChunkPacketBlockControllerAntiXray(plugin, plugin.getConfig().getInt("world-settings." + event.getWorld().getName() + ".anti-xray.max-ray-trace-block-count-per-chunk", plugin.getConfig().getInt("world-settings.default.anti-xray.max-ray-trace-block-count-per-chunk")), toTrace.isEmpty() ? null : toTrace, ((CraftWorld) event.getWorld()).getHandle(), MinecraftServer.getServer().executor));
        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
Also used : Field(java.lang.reflect.Field) Unsafe(sun.misc.Unsafe) ChunkPacketBlockControllerAntiXray(com.vanillage.raytraceantixray.antixray.ChunkPacketBlockControllerAntiXray) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld) EventHandler(org.bukkit.event.EventHandler)

Example 52 with CraftWorld

use of org.bukkit.craftbukkit.v1_16_R2.CraftWorld in project RayTraceAntiXray by stonar96.

the class UpdateBukkitRunnable method run.

@Override
public void run() {
    for (Entry<UUID, PlayerData> entry : plugin.getPlayerData().entrySet()) {
        PlayerData playerData = entry.getValue();
        Level level = ((CraftWorld) playerData.getLocations().get(0).getWorld()).getHandle();
        ChunkPacketBlockController chunkPacketBlockController = level.chunkPacketBlockController;
        if (chunkPacketBlockController instanceof ChunkPacketBlockControllerAntiXray) {
            Queue<BlockPos> result = playerData.getResult();
            for (BlockPos block = result.poll(); block != null; block = result.poll()) {
                ((ChunkPacketBlockControllerAntiXray) chunkPacketBlockController).updateBlock(level, block);
            }
        }
    }
}
Also used : ChunkPacketBlockController(com.destroystokyo.paper.antixray.ChunkPacketBlockController) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) UUID(java.util.UUID) ChunkPacketBlockControllerAntiXray(com.vanillage.raytraceantixray.antixray.ChunkPacketBlockControllerAntiXray) PlayerData(com.vanillage.raytraceantixray.data.PlayerData) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld)

Example 53 with CraftWorld

use of org.bukkit.craftbukkit.v1_16_R2.CraftWorld in project Mohist by MohistMC.

the class CraftChest method getInventory.

@Override
public Inventory getInventory() {
    CraftInventory inventory = (CraftInventory) this.getBlockInventory();
    if (!isPlaced() || isWorldGeneration()) {
        return inventory;
    }
    // The logic here is basically identical to the logic in ChestBlock.interact
    CraftWorld world = (CraftWorld) this.getWorld();
    ChestBlock blockChest = (ChestBlock) (this.getType() == Material.CHEST ? Blocks.CHEST : Blocks.TRAPPED_CHEST);
    MenuProvider nms = blockChest.getMenuProvider(data, world.getHandle(), this.getPosition(), true);
    if (nms instanceof ChestBlock.DoubleInventory) {
        inventory = new CraftInventoryDoubleChest((ChestBlock.DoubleInventory) nms);
    }
    return inventory;
}
Also used : CraftInventory(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventory) ChestBlock(net.minecraft.world.level.block.ChestBlock) CraftInventoryDoubleChest(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryDoubleChest) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld) MenuProvider(net.minecraft.world.MenuProvider)

Example 54 with CraftWorld

use of org.bukkit.craftbukkit.v1_16_R2.CraftWorld in project Mohist by MohistMC.

the class CraftDropper method drop.

@Override
public void drop() {
    ensureNoWorldGeneration();
    Block block = getBlock();
    if (block.getType() == Material.DROPPER) {
        CraftWorld world = (CraftWorld) this.getWorld();
        DropperBlock drop = (DropperBlock) Blocks.DROPPER;
        drop.dispenseFrom(world.getHandle(), this.getPosition());
    }
}
Also used : DropperBlock(net.minecraft.world.level.block.DropperBlock) Block(org.bukkit.block.Block) DropperBlock(net.minecraft.world.level.block.DropperBlock) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld)

Example 55 with CraftWorld

use of org.bukkit.craftbukkit.v1_16_R2.CraftWorld in project Mohist by MohistMC.

the class CraftLivingEntity method launchProjectile.

@Override
@SuppressWarnings("unchecked")
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
    Preconditions.checkState(!getHandle().generation, "Cannot launch projectile during world generation");
    net.minecraft.world.level.Level world = ((CraftWorld) getWorld()).getHandle();
    net.minecraft.world.entity.Entity launch = null;
    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.world.entity.projectile.Snowball(world, getHandle());
        // ItemSnowball
        ((net.minecraft.world.entity.projectile.ThrowableProjectile) launch).shootFromRotation(getHandle(), getHandle().getXRot(), getHandle().getYRot(), 0.0F, 1.5F, 1.0F);
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.world.entity.projectile.ThrownEgg(world, getHandle());
        // ItemEgg
        ((net.minecraft.world.entity.projectile.ThrowableProjectile) launch).shootFromRotation(getHandle(), getHandle().getXRot(), getHandle().getYRot(), 0.0F, 1.5F, 1.0F);
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.world.entity.projectile.ThrownEnderpearl(world, getHandle());
        // ItemEnderPearl
        ((net.minecraft.world.entity.projectile.ThrowableProjectile) launch).shootFromRotation(getHandle(), getHandle().getXRot(), getHandle().getYRot(), 0.0F, 1.5F, 1.0F);
    } else if (AbstractArrow.class.isAssignableFrom(projectile)) {
        if (TippedArrow.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.world.entity.projectile.Arrow(world, getHandle());
            ((net.minecraft.world.entity.projectile.Arrow) launch).setPotionType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));
        } else if (SpectralArrow.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.world.entity.projectile.SpectralArrow(world, getHandle());
        } else if (Trident.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.world.entity.projectile.ThrownTrident(world, getHandle(), new net.minecraft.world.item.ItemStack(net.minecraft.world.item.Items.TRIDENT));
        } else {
            launch = new net.minecraft.world.entity.projectile.Arrow(world, getHandle());
        }
        // ItemBow
        ((net.minecraft.world.entity.projectile.AbstractArrow) launch).shootFromRotation(getHandle(), getHandle().getXRot(), getHandle().getYRot(), 0.0F, 3.0F, 1.0F);
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        if (LingeringPotion.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.world.entity.projectile.ThrownPotion(world, getHandle());
            ((net.minecraft.world.entity.projectile.ThrownPotion) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
        } else {
            launch = new net.minecraft.world.entity.projectile.ThrownPotion(world, getHandle());
            ((net.minecraft.world.entity.projectile.ThrownPotion) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.SPLASH_POTION, 1)));
        }
        // ItemSplashPotion
        ((net.minecraft.world.entity.projectile.ThrowableProjectile) launch).shootFromRotation(getHandle(), getHandle().getXRot(), getHandle().getYRot(), -20.0F, 0.5F, 1.0F);
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.world.entity.projectile.ThrownExperienceBottle(world, getHandle());
        // ItemExpBottle
        ((net.minecraft.world.entity.projectile.ThrowableProjectile) launch).shootFromRotation(getHandle(), getHandle().getXRot(), getHandle().getYRot(), -20.0F, 0.7F, 1.0F);
    } else if (FishHook.class.isAssignableFrom(projectile) && getHandle() instanceof net.minecraft.world.entity.player.Player) {
        launch = new net.minecraft.world.entity.projectile.FishingHook((net.minecraft.world.entity.player.Player) getHandle(), world, 0, 0);
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection().multiply(10);
        if (SmallFireball.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.world.entity.projectile.SmallFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.world.entity.projectile.WitherSkull(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (DragonFireball.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.world.entity.projectile.DragonFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else {
            launch = new net.minecraft.world.entity.projectile.LargeFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ(), 1);
        }
        ((AbstractHurtingProjectile) launch).projectileSource = this;
        launch.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    } else if (LlamaSpit.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection();
        launch = net.minecraft.world.entity.EntityType.LLAMA_SPIT.create(world);
        ((net.minecraft.world.entity.projectile.LlamaSpit) launch).setOwner(getHandle());
        // net.minecraft.world.entity.animal.horse.Llama
        ((net.minecraft.world.entity.projectile.LlamaSpit) launch).shoot(direction.getX(), direction.getY(), direction.getZ(), 1.5F, 10.0F);
        launch.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    } else if (ShulkerBullet.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        launch = new net.minecraft.world.entity.projectile.ShulkerBullet(world, getHandle(), null, null);
        launch.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    } else if (Firework.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        launch = new FireworkRocketEntity(world, net.minecraft.world.item.ItemStack.EMPTY, getHandle());
        launch.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    }
    Validate.notNull(launch, "Projectile not supported");
    if (velocity != null) {
        ((T) launch.getBukkitEntity()).setVelocity(velocity);
    }
    world.addFreshEntity(launch);
    return (T) launch.getBukkitEntity();
}
Also used : FireworkRocketEntity(net.minecraft.world.entity.projectile.FireworkRocketEntity) ShulkerBullet(org.bukkit.entity.ShulkerBullet) PotionData(org.bukkit.potion.PotionData) DragonFireball(org.bukkit.entity.DragonFireball) Fireball(org.bukkit.entity.Fireball) SmallFireball(org.bukkit.entity.SmallFireball) TippedArrow(org.bukkit.entity.TippedArrow) DragonFireball(org.bukkit.entity.DragonFireball) AbstractHurtingProjectile(net.minecraft.world.entity.projectile.AbstractHurtingProjectile) Trident(org.bukkit.entity.Trident) ThrownPotion(org.bukkit.entity.ThrownPotion) SmallFireball(org.bukkit.entity.SmallFireball) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld) Vector(org.bukkit.util.Vector) SpectralArrow(org.bukkit.entity.SpectralArrow) AbstractArrow(org.bukkit.entity.AbstractArrow) TippedArrow(org.bukkit.entity.TippedArrow) FishHook(org.bukkit.entity.FishHook) Player(org.bukkit.entity.Player) Egg(org.bukkit.entity.Egg) LlamaSpit(org.bukkit.entity.LlamaSpit) ThrownExpBottle(org.bukkit.entity.ThrownExpBottle) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack) AbstractArrow(org.bukkit.entity.AbstractArrow) Location(org.bukkit.Location)

Aggregations

ServerLevel (net.minecraft.server.level.ServerLevel)147 Location (org.bukkit.Location)131 CraftWorld (org.bukkit.craftbukkit.v1_18_R2.CraftWorld)111 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)103 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)95 BlockPos (net.minecraft.core.BlockPos)83 CraftWorld (org.bukkit.craftbukkit.v1_12_R1.CraftWorld)74 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)66 ItemStack (org.bukkit.inventory.ItemStack)61 Block (org.bukkit.block.Block)57 LivingEntity (org.bukkit.entity.LivingEntity)54 CraftWorld (org.bukkit.craftbukkit.v1_8_R3.CraftWorld)53 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)47 ArrayList (java.util.ArrayList)43 World (org.bukkit.World)41 CraftWorld (org.bukkit.craftbukkit.v1_11_R1.CraftWorld)39 Entity (org.bukkit.entity.Entity)39 Level (net.minecraft.world.level.Level)38 List (java.util.List)34 GameProfile (com.mojang.authlib.GameProfile)32