Search in sources :

Example 46 with EntityPlayer

use of net.minecraft.server.v1_16_R1.EntityPlayer in project MyPet by xXKeyleXx.

the class ControlTarget method shouldStart.

@Override
public boolean shouldStart() {
    if (controlPathfinderGoal == null) {
        if (petEntity.getPathfinder().hasGoal("Control")) {
            controlPathfinderGoal = (Control) petEntity.getPathfinder().getGoal("Control");
        }
    }
    if (controlPathfinderGoal == null) {
        return false;
    }
    if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
        return false;
    }
    if (controlPathfinderGoal.moveTo != null && petEntity.canMove()) {
        Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
        if (behaviorSkill.isActive()) {
            if (behaviorSkill.getBehavior() == BehaviorMode.Friendly) {
                return false;
            }
        }
        for (EntityLiving entityLiving : this.petEntity.world.a(EntityLiving.class, this.petEntity.getBoundingBox().grow((double) this.range, 4.0D, (double) this.range))) {
            if (entityLiving != petEntity && !(entityLiving instanceof EntityArmorStand)) {
                if (entityLiving instanceof EntityPlayer) {
                    Player targetPlayer = (Player) entityLiving.getBukkitEntity();
                    if (myPet.getOwner().equals(targetPlayer)) {
                        continue;
                    } else if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetPlayer, true)) {
                        continue;
                    }
                } else if (entityLiving instanceof EntityTameableAnimal) {
                    EntityTameableAnimal tameable = (EntityTameableAnimal) entityLiving;
                    if (tameable.isTamed() && tameable.getOwner() != null) {
                        Player tameableOwner = (Player) tameable.getOwner().getBukkitEntity();
                        if (myPet.getOwner().equals(tameableOwner)) {
                            continue;
                        } else if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), tameableOwner, true)) {
                            continue;
                        }
                    }
                } else if (entityLiving instanceof EntityMyPet) {
                    MyPet targetMyPet = ((EntityMyPet) entityLiving).getMyPet();
                    if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetMyPet.getOwner().getPlayer(), true)) {
                        continue;
                    }
                }
                if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), entityLiving.getBukkitEntity())) {
                    continue;
                }
                if (behaviorSkill != null) {
                    if (behaviorSkill.getBehavior() == BehaviorMode.Raid) {
                        if (entityLiving instanceof EntityTameableAnimal) {
                            continue;
                        } else if (entityLiving instanceof EntityMyPet) {
                            continue;
                        } else if (entityLiving instanceof EntityPlayer) {
                            continue;
                        }
                    }
                }
                controlPathfinderGoal.stopControl();
                this.target = entityLiving;
                return true;
            }
        }
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) EntityPlayer(net.minecraft.server.v1_9_R2.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer) EntityMyPet(de.Keyle.MyPet.compat.v1_9_R2.entity.EntityMyPet) EntityLiving(net.minecraft.server.v1_9_R2.EntityLiving) MyPet(de.Keyle.MyPet.api.entity.MyPet) EntityMyPet(de.Keyle.MyPet.compat.v1_9_R2.entity.EntityMyPet) EntityPlayer(net.minecraft.server.v1_9_R2.EntityPlayer) EntityTameableAnimal(net.minecraft.server.v1_9_R2.EntityTameableAnimal) EntityArmorStand(net.minecraft.server.v1_9_R2.EntityArmorStand) Behavior(de.Keyle.MyPet.api.skill.skills.Behavior)

Example 47 with EntityPlayer

use of net.minecraft.server.v1_16_R1.EntityPlayer 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) Configuration(de.Keyle.MyPet.api.Configuration) net.minecraft.server.v1_16_R1(net.minecraft.server.v1_16_R1) 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) ENTITY_LIVING_broadcastItemBreak(de.Keyle.MyPet.compat.v1_16_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak) Player(org.bukkit.entity.Player) EntityMyPet(de.Keyle.MyPet.compat.v1_16_R1.entity.EntityMyPet) CraftItemStack(org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack) InvocationTargetException(java.lang.reflect.InvocationTargetException) Player(org.bukkit.entity.Player) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 48 with EntityPlayer

use of net.minecraft.server.v1_16_R1.EntityPlayer in project MyPet by xXKeyleXx.

the class MeleeAttack method shouldStart.

@Override
public boolean shouldStart() {
    if (myPet.getDamage() <= 0) {
        return false;
    }
    if (!this.petEntity.hasTarget()) {
        return false;
    }
    EntityLiving targetEntity = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle();
    if (targetEntity instanceof EntityArmorStand) {
        return false;
    }
    if (petEntity.getMyPet().getRangedDamage() > 0 && this.petEntity.f(targetEntity.locX, targetEntity.getBoundingBox().b, targetEntity.locZ) >= 20) {
        return false;
    }
    Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
    if (behaviorSkill != null && behaviorSkill.isActive()) {
        if (behaviorSkill.getBehavior() == Behavior.BehaviorMode.Friendly) {
            return false;
        }
        if (behaviorSkill.getBehavior() == Behavior.BehaviorMode.Raid) {
            if (targetEntity instanceof EntityTameableAnimal && ((EntityTameableAnimal) targetEntity).isTamed()) {
                return false;
            }
            if (targetEntity instanceof EntityMyPet) {
                return false;
            }
            if (targetEntity instanceof EntityPlayer) {
                return false;
            }
        }
    }
    this.targetEntity = targetEntity;
    return true;
}
Also used : EntityMyPet(de.Keyle.MyPet.compat.v1_8_R3.entity.EntityMyPet) EntityLiving(net.minecraft.server.v1_8_R3.EntityLiving) EntityTameableAnimal(net.minecraft.server.v1_8_R3.EntityTameableAnimal) EntityPlayer(net.minecraft.server.v1_8_R3.EntityPlayer) CraftLivingEntity(org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity) EntityArmorStand(net.minecraft.server.v1_8_R3.EntityArmorStand) Behavior(de.Keyle.MyPet.api.skill.skills.Behavior)

Example 49 with EntityPlayer

use of net.minecraft.server.v1_16_R1.EntityPlayer in project Denizen-For-Bukkit by DenizenScript.

the class ProfileEditor_v1_8_R3 method updatePlayer.

@Override
protected void updatePlayer(Player player, final boolean isSkinChanging) {
    final EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    final UUID uuid = player.getUniqueId();
    PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(entityPlayer.getId());
    for (Player p : Bukkit.getServer().getOnlinePlayers()) {
        if (!p.getUniqueId().equals(uuid)) {
            PacketHelper_v1_8_R3.sendPacket(p, destroyPacket);
        }
    }
    new BukkitRunnable() {

        @Override
        public void run() {
            PacketPlayOutPlayerInfo playerInfo = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, entityPlayer);
            PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(entityPlayer);
            for (Player player : Bukkit.getServer().getOnlinePlayers()) {
                PacketHelper_v1_8_R3.sendPacket(player, playerInfo);
                if (!player.getUniqueId().equals(uuid)) {
                    PacketHelper_v1_8_R3.sendPacket(player, spawnPacket);
                } else {
                    if (isSkinChanging) {
                        boolean isFlying = player.isFlying();
                        PacketHelper_v1_8_R3.sendPacket(player, new PacketPlayOutRespawn(player.getWorld().getEnvironment().getId(), entityPlayer.getWorld().getDifficulty(), entityPlayer.getWorld().worldData.getType(), entityPlayer.playerInteractManager.getGameMode()));
                        player.teleport(player.getLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
                        player.setFlying(isFlying);
                    }
                    player.updateInventory();
                }
            }
        }
    }.runTaskLater(NMSHandler.getJavaPlugin(), 5);
}
Also used : Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer) EntityPlayer(net.minecraft.server.v1_8_R3.EntityPlayer) PacketPlayOutNamedEntitySpawn(net.minecraft.server.v1_8_R3.PacketPlayOutNamedEntitySpawn) PacketPlayOutEntityDestroy(net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy) EntityPlayer(net.minecraft.server.v1_8_R3.EntityPlayer) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) CraftPlayer(org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer) PacketPlayOutPlayerInfo(net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo) PacketPlayOutRespawn(net.minecraft.server.v1_8_R3.PacketPlayOutRespawn) UUID(java.util.UUID)

Example 50 with EntityPlayer

use of net.minecraft.server.v1_16_R1.EntityPlayer in project Denizen-For-Bukkit by DenizenScript.

the class ProfileEditor_v1_10_R1 method updatePlayer.

@Override
protected void updatePlayer(Player player, final boolean isSkinChanging) {
    final EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    final UUID uuid = player.getUniqueId();
    PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(entityPlayer.getId());
    for (Player p : Bukkit.getServer().getOnlinePlayers()) {
        if (!p.getUniqueId().equals(uuid)) {
            PacketHelper_v1_10_R1.sendPacket(p, destroyPacket);
        }
    }
    new BukkitRunnable() {

        @Override
        public void run() {
            PacketPlayOutPlayerInfo playerInfo = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, entityPlayer);
            PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(entityPlayer);
            for (Player player : Bukkit.getServer().getOnlinePlayers()) {
                PacketHelper_v1_10_R1.sendPacket(player, playerInfo);
                if (!player.getUniqueId().equals(uuid)) {
                    PacketHelper_v1_10_R1.sendPacket(player, spawnPacket);
                } else {
                    if (isSkinChanging) {
                        boolean isFlying = player.isFlying();
                        PacketHelper_v1_10_R1.sendPacket(player, new PacketPlayOutRespawn(player.getWorld().getEnvironment().getId(), entityPlayer.getWorld().getDifficulty(), entityPlayer.getWorld().worldData.getType(), entityPlayer.playerInteractManager.getGameMode()));
                        player.teleport(player.getLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
                        player.setFlying(isFlying);
                    }
                    player.updateInventory();
                }
            }
        }
    }.runTaskLater(NMSHandler.getJavaPlugin(), 5);
}
Also used : EntityPlayer(net.minecraft.server.v1_10_R1.EntityPlayer) Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer) PacketPlayOutNamedEntitySpawn(net.minecraft.server.v1_10_R1.PacketPlayOutNamedEntitySpawn) PacketPlayOutEntityDestroy(net.minecraft.server.v1_10_R1.PacketPlayOutEntityDestroy) EntityPlayer(net.minecraft.server.v1_10_R1.EntityPlayer) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) CraftPlayer(org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer) PacketPlayOutPlayerInfo(net.minecraft.server.v1_10_R1.PacketPlayOutPlayerInfo) PacketPlayOutRespawn(net.minecraft.server.v1_10_R1.PacketPlayOutRespawn) UUID(java.util.UUID)

Aggregations

Player (org.bukkit.entity.Player)26 MyPet (de.Keyle.MyPet.api.entity.MyPet)17 EntityPlayer (net.minecraft.server.v1_8_R3.EntityPlayer)16 EntityPlayer (net.minecraft.server.v1_12_R1.EntityPlayer)13 EntityPlayer (net.minecraft.server.v1_10_R1.EntityPlayer)12 EntityPlayer (net.minecraft.server.v1_11_R1.EntityPlayer)12 Behavior (de.Keyle.MyPet.api.skill.skills.Behavior)11 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)10 CraftPlayer (org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer)9 NPC (net.citizensnpcs.api.npc.NPC)8 NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)8 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)8 Behavior (de.Keyle.MyPet.skill.skills.Behavior)6 EntityPlayer (net.minecraft.server.v1_9_R2.EntityPlayer)6 CraftPlayer (org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer)6 CraftPlayer (org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer)6 CraftPlayer (org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer)6 CraftPlayer (org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer)5 UUID (java.util.UUID)4 PacketPlayOutPlayerInfo (net.minecraft.server.v1_10_R1.PacketPlayOutPlayerInfo)4