Search in sources :

Example 41 with CraftWorld

use of org.bukkit.craftbukkit.v1_17_R1.CraftWorld in project MyPet by xXKeyleXx.

the class PlatformHelper method strikeLightning.

@Override
public void strikeLightning(Location loc, float distance) {
    ServerLevel world = ((CraftWorld) loc.getWorld()).getHandle();
    LightningBolt lightning = new LightningBolt(EntityType.LIGHTNING_BOLT, world);
    lightning.setVisualOnly(true);
    lightning.moveTo(loc.getX(), loc.getY(), loc.getZ(), 0.0F, 0.0F);
    /*world.getCraftServer()
                .getServer()
                .getPlayerList()
                .broadcast(null, loc.getX(), loc.getY(), loc.getZ(), distance, world.dimension(),
                        new ClientboundAddEntityPacket(lightning));
        world.getCraftServer()
                .getServer()
                .getPlayerList()
                .broadcast(null, loc.getX(), loc.getY(), loc.getZ(), distance, world.dimension(),
                        new ClientboundSoundPacket(SoundEvents.LIGHTNING_BOLT_THUNDER, SoundSource.WEATHER, loc.getX(), loc.getY(), loc.getZ(), distance, 1F));
        */
    // Thank you wrong mappings for this workaround
    DedicatedServer server = world.getCraftServer().getServer();
    Method getPlayerListReflect = ReflectionUtil.getMethod(DedicatedServer.class, "getPlayerList");
    try {
        DedicatedPlayerList playerList = (DedicatedPlayerList) getPlayerListReflect.invoke(server, null);
        playerList.broadcast(null, loc.getX(), loc.getY(), loc.getZ(), distance, world.dimension(), new ClientboundAddEntityPacket(lightning));
        playerList.broadcast(null, loc.getX(), loc.getY(), loc.getZ(), distance, world.dimension(), new ClientboundSoundPacket(SoundEvents.LIGHTNING_BOLT_THUNDER, SoundSource.WEATHER, loc.getX(), loc.getY(), loc.getZ(), distance, 1F));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) LightningBolt(net.minecraft.world.entity.LightningBolt) ClientboundAddEntityPacket(net.minecraft.network.protocol.game.ClientboundAddEntityPacket) DedicatedPlayerList(net.minecraft.server.dedicated.DedicatedPlayerList) DedicatedServer(net.minecraft.server.dedicated.DedicatedServer) Method(java.lang.reflect.Method) ClientboundSoundPacket(net.minecraft.network.protocol.game.ClientboundSoundPacket) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld) InvocationTargetException(java.lang.reflect.InvocationTargetException) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException)

Example 42 with CraftWorld

use of org.bukkit.craftbukkit.v1_17_R1.CraftWorld in project MyPet by xXKeyleXx.

the class EntityRegistry method createMinecraftEntity.

@Override
public MyPetMinecraftEntity createMinecraftEntity(MyPet pet, org.bukkit.World bukkitWorld) {
    EntityMyPet petEntity = null;
    Class<? extends MyPetMinecraftEntity> entityClass = entityClasses.get(pet.getPetType());
    Level world = ((CraftWorld) bukkitWorld).getHandle();
    try {
        Constructor<?> ctor = entityClass.getConstructor(Level.class, MyPet.class);
        Object obj = ctor.newInstance(world, pet);
        if (obj instanceof EntityMyPet) {
            petEntity = (EntityMyPet) obj;
        }
    } catch (Exception e) {
        MyPetApi.getLogger().info(ChatColor.RED + Util.getClassName(entityClass) + "(" + pet.getPetType() + ") is no valid MyPet(Entity)!");
        e.printStackTrace();
    }
    return petEntity;
}
Also used : Level(net.minecraft.world.level.Level) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld)

Example 43 with CraftWorld

use of org.bukkit.craftbukkit.v1_17_R1.CraftWorld in project MyPet by xXKeyleXx.

the class EntityRegistry method createMinecraftEntity.

@Override
public MyPetMinecraftEntity createMinecraftEntity(MyPet pet, org.bukkit.World bukkitWorld) {
    EntityMyPet petEntity = null;
    Class<? extends MyPetMinecraftEntity> entityClass = entityClasses.get(pet.getPetType());
    Level world = ((CraftWorld) bukkitWorld).getHandle();
    try {
        Constructor<?> ctor = entityClass.getConstructor(Level.class, MyPet.class);
        Object obj = ctor.newInstance(world, pet);
        if (obj instanceof EntityMyPet) {
            petEntity = (EntityMyPet) obj;
        }
    } catch (Exception e) {
        MyPetApi.getLogger().info(ChatColor.RED + Util.getClassName(entityClass) + "(" + pet.getPetType() + ") is no valid MyPet(Entity)!");
        e.printStackTrace();
    }
    return petEntity;
}
Also used : Level(net.minecraft.world.level.Level) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld)

Example 44 with CraftWorld

use of org.bukkit.craftbukkit.v1_17_R1.CraftWorld in project Citizens2 by CitizensDev.

the class FallingBlockController method createEntity.

@Override
protected Entity createEntity(Location at, NPC npc) {
    WorldServer ws = ((CraftWorld) at.getWorld()).getHandle();
    Block id = Blocks.STONE;
    int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
    if (npc.data().has("falling-block-id") || npc.data().has(NPC.ITEM_ID_METADATA)) {
        id = CraftMagicNumbers.getBlock(Material.getMaterial(npc.data().<String>get(NPC.ITEM_ID_METADATA, npc.data().<String>get("falling-block-id"))));
    }
    final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(), id.fromLegacyData(data));
    return handle.getBukkitEntity();
}
Also used : EntityFallingBlock(net.minecraft.server.v1_10_R1.EntityFallingBlock) Block(net.minecraft.server.v1_10_R1.Block) FallingBlock(org.bukkit.entity.FallingBlock) WorldServer(net.minecraft.server.v1_10_R1.WorldServer) CraftWorld(org.bukkit.craftbukkit.v1_10_R1.CraftWorld)

Example 45 with CraftWorld

use of org.bukkit.craftbukkit.v1_17_R1.CraftWorld in project Citizens2 by CitizensDev.

the class ItemController method createEntity.

@Override
protected Entity createEntity(Location at, NPC npc) {
    WorldServer ws = ((CraftWorld) at.getWorld()).getHandle();
    Material id = Material.STONE;
    int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
    if (npc.data().has(NPC.ITEM_ID_METADATA)) {
        id = Material.getMaterial(npc.data().<String>get(NPC.ITEM_ID_METADATA));
    }
    final EntityItemNPC handle = new EntityItemNPC(ws, npc, at.getX(), at.getY(), at.getZ(), CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(id, 1, (short) data)));
    return handle.getBukkitEntity();
}
Also used : WorldServer(net.minecraft.server.v1_10_R1.WorldServer) Material(org.bukkit.Material) CraftItemStack(org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack) ItemStack(net.minecraft.server.v1_10_R1.ItemStack) CraftWorld(org.bukkit.craftbukkit.v1_10_R1.CraftWorld)

Aggregations

ServerLevel (net.minecraft.server.level.ServerLevel)63 Location (org.bukkit.Location)56 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)42 ItemStack (org.bukkit.inventory.ItemStack)42 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)40 BlockPos (net.minecraft.core.BlockPos)36 Zombie (org.bukkit.entity.Zombie)32 LivingEntity (org.bukkit.entity.LivingEntity)29 CraftWorld (org.bukkit.craftbukkit.v1_11_R1.CraftWorld)28 CraftWorld (org.bukkit.craftbukkit.v1_8_R3.CraftWorld)28 ItemEntity (net.minecraft.world.entity.item.ItemEntity)27 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)26 HangingEntity (net.minecraft.world.entity.decoration.HangingEntity)25 FallingBlockEntity (net.minecraft.world.entity.item.FallingBlockEntity)25 FireworkRocketEntity (net.minecraft.world.entity.projectile.FireworkRocketEntity)25 SignBlockEntity (net.minecraft.world.level.block.entity.SignBlockEntity)25 Entity (org.bukkit.entity.Entity)25 HumanEntity (org.bukkit.entity.HumanEntity)25 CraftWorld (org.bukkit.craftbukkit.v1_12_R1.CraftWorld)23 CraftWorld (org.bukkit.craftbukkit.v1_9_R1.CraftWorld)17