Search in sources :

Example 16 with WorldServer

use of net.minecraft.server.v1_16_R3.WorldServer in project MyPet by xXKeyleXx.

the class EntityMyEnderDragon method onLivingUpdate.

@Override
public void onLivingUpdate() {
    super.onLivingUpdate();
    if (Configuration.MyPet.EnderDragon.CAN_GLIDE) {
        if (!this.onGround && this.getMot().y < 0.0D) {
            this.setMot(getMot().d(1, 0.6D, 1));
        }
    }
    if (!registered && this.valid) {
        if (this.getWorld() instanceof WorldServer) {
            WorldServer world = (WorldServer) this.getWorld();
            Arrays.stream(this.children).forEach(entityMyPetPart -> world.entitiesById.put(entityMyPetPart.getId(), entityMyPetPart));
        }
        this.registered = true;
    }
}
Also used : WorldServer(net.minecraft.server.v1_16_R1.WorldServer)

Example 17 with WorldServer

use of net.minecraft.server.v1_16_R3.WorldServer in project MyPet by xXKeyleXx.

the class EntityMyPig method handlePlayerInteraction.

@Override
public EnumInteractionResult handlePlayerInteraction(final EntityHuman entityhuman, EnumHand enumhand, final ItemStack itemStack) {
    if (enumhand == EnumHand.OFF_HAND) {
        if (itemStack != null) {
            if (itemStack.getItem() == Items.LEAD) {
                ((WorldServer) this.world).getChunkProvider().broadcastIncludingSelf(this, new PacketPlayOutAttachEntity(this, null));
                entityhuman.a(EnumHand.OFF_HAND, ItemStack.b);
                new BukkitRunnable() {

                    @Override
                    public void run() {
                        if (entityhuman instanceof EntityPlayer) {
                            entityhuman.a(EnumHand.OFF_HAND, itemStack);
                            Player p = (Player) entityhuman.getBukkitEntity();
                            if (!p.isOnline()) {
                                p.saveData();
                            }
                        }
                    }
                }.runTaskLater(MyPetApi.getPlugin(), 5);
            }
        }
        return EnumInteractionResult.CONSUME;
    }
    if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) {
        return EnumInteractionResult.CONSUME;
    }
    if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) {
        if (itemStack.getItem() == Items.SADDLE && !getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking()) {
            getMyPet().setSaddle(CraftItemStack.asBukkitCopy(itemStack));
            if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
                itemStack.subtract(1);
                if (itemStack.getCount() <= 0) {
                    entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.b);
                }
            }
            return EnumInteractionResult.CONSUME;
        } else if (itemStack.getItem() == Items.SHEARS && getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking()) {
            EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + 1, this.locZ(), CraftItemStack.asNMSCopy(getMyPet().getSaddle()));
            entityitem.pickupDelay = 10;
            entityitem.setMot(entityitem.getMot().add(0, this.random.nextFloat() * 0.05F, 0));
            this.world.addEntity(entityitem);
            makeSound("entity.sheep.shear", 1.0F, 1.0F);
            getMyPet().setSaddle(null);
            if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
                try {
                    itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand));
                } catch (Error e) {
                    // TODO REMOVE
                    itemStack.damage(1, entityhuman, (entityhuman1) -> {
                        try {
                            ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand);
                        } catch (IllegalAccessException | InvocationTargetException ex) {
                            ex.printStackTrace();
                        }
                    });
                }
            }
            return EnumInteractionResult.CONSUME;
        } else if (Configuration.MyPet.Pig.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) {
            if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
                itemStack.subtract(1);
                if (itemStack.getCount() <= 0) {
                    entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.b);
                }
            }
            getMyPet().setBaby(false);
            return EnumInteractionResult.CONSUME;
        }
    }
    return EnumInteractionResult.PASS;
}
Also used : MyPet(de.Keyle.MyPet.api.entity.MyPet) ENTITY_LIVING_broadcastItemBreak(de.Keyle.MyPet.compat.v1_16_R3.CompatManager.ENTITY_LIVING_broadcastItemBreak) Configuration(de.Keyle.MyPet.api.Configuration) EntitySize(de.Keyle.MyPet.api.entity.EntitySize) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) MyPetApi(de.Keyle.MyPet.MyPetApi) MyPig(de.Keyle.MyPet.api.entity.types.MyPig) Player(org.bukkit.entity.Player) net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3) EntityMyPet(de.Keyle.MyPet.compat.v1_16_R3.entity.EntityMyPet) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) InvocationTargetException(java.lang.reflect.InvocationTargetException) Player(org.bukkit.entity.Player) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 18 with WorldServer

use of net.minecraft.server.v1_16_R3.WorldServer in project Citizens2 by CitizensDev.

the class NMSImpl method updateNavigationWorld.

@Override
public void updateNavigationWorld(org.bukkit.entity.Entity entity, World world) {
    if (NAVIGATION_WORLD_FIELD == null)
        return;
    Entity en = NMSImpl.getHandle(entity);
    if (en == null || !(en instanceof EntityInsentient))
        return;
    EntityInsentient handle = (EntityInsentient) en;
    WorldServer worldHandle = ((CraftWorld) world).getHandle();
    try {
        NAVIGATION_WORLD_FIELD.set(handle.getNavigation(), worldHandle);
    } catch (Exception e) {
        Messaging.logTr(Messages.ERROR_UPDATING_NAVIGATION_WORLD, e.getMessage());
    }
}
Also used : PathEntity(net.minecraft.server.v1_10_R1.PathEntity) LivingEntity(org.bukkit.entity.LivingEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) CraftEntity(org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity) Entity(net.minecraft.server.v1_10_R1.Entity) EntityInsentient(net.minecraft.server.v1_10_R1.EntityInsentient) WorldServer(net.minecraft.server.v1_10_R1.WorldServer) CraftWorld(org.bukkit.craftbukkit.v1_10_R1.CraftWorld) ReportedException(net.minecraft.server.v1_10_R1.ReportedException) CommandException(net.citizensnpcs.api.command.exception.CommandException)

Example 19 with WorldServer

use of net.minecraft.server.v1_16_R3.WorldServer 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_11_R1.EntityFallingBlock) CraftFallingBlock(org.bukkit.craftbukkit.v1_11_R1.entity.CraftFallingBlock) FallingBlock(org.bukkit.entity.FallingBlock) Block(net.minecraft.server.v1_11_R1.Block) WorldServer(net.minecraft.server.v1_11_R1.WorldServer) CraftWorld(org.bukkit.craftbukkit.v1_11_R1.CraftWorld)

Example 20 with WorldServer

use of net.minecraft.server.v1_16_R3.WorldServer 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_11_R1.WorldServer) Material(org.bukkit.Material) CraftItemStack(org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack) ItemStack(net.minecraft.server.v1_11_R1.ItemStack) CraftWorld(org.bukkit.craftbukkit.v1_11_R1.CraftWorld)

Aggregations

GameProfile (com.mojang.authlib.GameProfile)9 UUID (java.util.UUID)9 Scoreboard (org.bukkit.scoreboard.Scoreboard)9 Team (org.bukkit.scoreboard.Team)9 WorldServer (net.minecraft.server.v1_11_R1.WorldServer)8 WorldServer (net.minecraft.server.v1_8_R3.WorldServer)8 WorldServer (net.minecraft.server.v1_10_R1.WorldServer)7 WorldServer (net.minecraft.server.v1_12_R1.WorldServer)7 CraftWorld (org.bukkit.craftbukkit.v1_11_R1.CraftWorld)7 CraftWorld (org.bukkit.craftbukkit.v1_8_R3.CraftWorld)7 CraftWorld (org.bukkit.craftbukkit.v1_10_R1.CraftWorld)6 CraftWorld (org.bukkit.craftbukkit.v1_12_R1.CraftWorld)6 Property (com.mojang.authlib.properties.Property)5 BigInteger (java.math.BigInteger)5 MessageDigest (java.security.MessageDigest)5 EnumSet (java.util.EnumSet)4 Set (java.util.Set)4 PlayerProfile (net.aufdemrand.denizen.nms.util.PlayerProfile)4 CommandException (net.citizensnpcs.api.command.exception.CommandException)4 Skin (net.citizensnpcs.npc.skin.Skin)4