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();
}
}
}
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);
}
}
}
}
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;
}
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());
}
}
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();
}
Aggregations