Search in sources :

Example 56 with EntityPlayer

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

the class OwnerHurtByTarget method shouldStart.

@Override
public boolean shouldStart() {
    if (!petEntity.canMove()) {
        return false;
    }
    if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
        return false;
    }
    this.lastDamager = owner.getLastDamager();
    if (this.lastDamager == null || !lastDamager.isAlive()) {
        return false;
    }
    if (lastDamager instanceof EntityArmorStand) {
        return false;
    }
    if (lastDamager == petEntity) {
        return false;
    }
    if (lastDamager instanceof EntityPlayer) {
        if (owner == lastDamager) {
            return false;
        }
        Player targetPlayer = (Player) lastDamager.getBukkitEntity();
        if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetPlayer, true)) {
            return false;
        }
    } else if (lastDamager instanceof EntityMyPet) {
        MyPet targetMyPet = ((EntityMyPet) lastDamager).getMyPet();
        if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetMyPet.getOwner().getPlayer(), true)) {
            return false;
        }
    } else if (lastDamager instanceof EntityTameableAnimal) {
        EntityTameableAnimal tameable = (EntityTameableAnimal) lastDamager;
        if (tameable.isTamed() && tameable.getOwner() != null) {
            Player tameableOwner = (Player) tameable.getOwner().getBukkitEntity();
            if (myPet.getOwner().equals(tameableOwner)) {
                return false;
            }
        }
    }
    if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), lastDamager.getBukkitEntity())) {
        return false;
    }
    Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
    if (behaviorSkill != null && behaviorSkill.isActive()) {
        if (behaviorSkill.getBehavior() == BehaviorMode.Friendly) {
            return false;
        }
        if (behaviorSkill.getBehavior() == BehaviorMode.Raid) {
            if (lastDamager instanceof EntityTameableAnimal && ((EntityTameableAnimal) lastDamager).isTamed()) {
                return false;
            }
            if (lastDamager instanceof EntityMyPet) {
                return false;
            }
            if (lastDamager instanceof EntityPlayer) {
                return false;
            }
        }
    }
    return true;
}
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) 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 57 with EntityPlayer

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

the class OwnerHurtByTarget method shouldStart.

@Override
public boolean shouldStart() {
    if (!petEntity.canMove()) {
        return false;
    }
    if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
        return false;
    }
    this.lastDamager = owner.getLastDamager();
    if (this.lastDamager == null || !lastDamager.isAlive()) {
        return false;
    }
    if (lastDamager instanceof EntityArmorStand) {
        return false;
    }
    if (lastDamager == petEntity) {
        return false;
    }
    if (lastDamager instanceof EntityPlayer) {
        if (owner == lastDamager) {
            return false;
        }
        Player targetPlayer = (Player) lastDamager.getBukkitEntity();
        if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetPlayer, true)) {
            return false;
        }
    } else if (lastDamager instanceof EntityMyPet) {
        MyPet targetMyPet = ((EntityMyPet) lastDamager).getMyPet();
        if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetMyPet.getOwner().getPlayer(), true)) {
            return false;
        }
    } else if (lastDamager instanceof EntityTameableAnimal) {
        EntityTameableAnimal tameable = (EntityTameableAnimal) lastDamager;
        if (tameable.isTamed() && tameable.getOwner() != null) {
            Player tameableOwner = (Player) tameable.getOwner().getBukkitEntity();
            if (myPet.getOwner().equals(tameableOwner)) {
                return false;
            }
        }
    }
    if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), lastDamager.getBukkitEntity())) {
        return false;
    }
    Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
    if (behaviorSkill != null && behaviorSkill.isActive()) {
        if (behaviorSkill.getBehavior() == BehaviorMode.Friendly) {
            return false;
        }
        if (behaviorSkill.getBehavior() == BehaviorMode.Raid) {
            if (lastDamager instanceof EntityTameableAnimal && ((EntityTameableAnimal) lastDamager).isTamed()) {
                return false;
            }
            if (lastDamager instanceof EntityMyPet) {
                return false;
            }
            if (lastDamager instanceof EntityPlayer) {
                return false;
            }
        }
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) EntityPlayer(net.minecraft.server.v1_16_R1.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer) EntityMyPet(de.Keyle.MyPet.compat.v1_16_R1.entity.EntityMyPet) MyPet(de.Keyle.MyPet.api.entity.MyPet) EntityMyPet(de.Keyle.MyPet.compat.v1_16_R1.entity.EntityMyPet) EntityPlayer(net.minecraft.server.v1_16_R1.EntityPlayer) EntityTameableAnimal(net.minecraft.server.v1_16_R1.EntityTameableAnimal) EntityArmorStand(net.minecraft.server.v1_16_R1.EntityArmorStand) Behavior(de.Keyle.MyPet.api.skill.skills.Behavior)

Example 58 with EntityPlayer

use of net.minecraft.server.v1_16_R3.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_12_R1.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer) EntityMyPet(de.Keyle.MyPet.compat.v1_12_R1.entity.EntityMyPet) EntityLiving(net.minecraft.server.v1_12_R1.EntityLiving) MyPet(de.Keyle.MyPet.api.entity.MyPet) EntityMyPet(de.Keyle.MyPet.compat.v1_12_R1.entity.EntityMyPet) EntityPlayer(net.minecraft.server.v1_12_R1.EntityPlayer) EntityTameableAnimal(net.minecraft.server.v1_12_R1.EntityTameableAnimal) EntityArmorStand(net.minecraft.server.v1_12_R1.EntityArmorStand) Behavior(de.Keyle.MyPet.api.skill.skills.Behavior)

Example 59 with EntityPlayer

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

the class OwnerHurtByTarget method shouldStart.

@Override
public boolean shouldStart() {
    if (!petEntity.canMove()) {
        return false;
    }
    if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
        return false;
    }
    this.lastDamager = owner.getLastDamager();
    if (this.lastDamager == null || !lastDamager.isAlive()) {
        return false;
    }
    if (lastDamager instanceof EntityArmorStand) {
        return false;
    }
    if (lastDamager == petEntity) {
        return false;
    }
    if (lastDamager instanceof EntityPlayer) {
        if (owner == lastDamager) {
            return false;
        }
        Player targetPlayer = (Player) lastDamager.getBukkitEntity();
        if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetPlayer, true)) {
            return false;
        }
    } else if (lastDamager instanceof EntityMyPet) {
        MyPet targetMyPet = ((EntityMyPet) lastDamager).getMyPet();
        if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetMyPet.getOwner().getPlayer(), true)) {
            return false;
        }
    } else if (lastDamager instanceof EntityTameableAnimal) {
        EntityTameableAnimal tameable = (EntityTameableAnimal) lastDamager;
        if (tameable.isTamed() && tameable.getOwner() != null) {
            Player tameableOwner = (Player) tameable.getOwner().getBukkitEntity();
            if (myPet.getOwner().equals(tameableOwner)) {
                return false;
            }
        }
    }
    if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), lastDamager.getBukkitEntity())) {
        return false;
    }
    Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
    if (behaviorSkill != null && behaviorSkill.isActive()) {
        if (behaviorSkill.getBehavior() == BehaviorMode.Friendly) {
            return false;
        }
        if (behaviorSkill.getBehavior() == BehaviorMode.Raid) {
            if (lastDamager instanceof EntityTameableAnimal && ((EntityTameableAnimal) lastDamager).isTamed()) {
                return false;
            }
            if (lastDamager instanceof EntityMyPet) {
                return false;
            }
            if (lastDamager instanceof EntityPlayer) {
                return false;
            }
        }
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) EntityPlayer(net.minecraft.server.v1_12_R1.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer) EntityMyPet(de.Keyle.MyPet.compat.v1_12_R1.entity.EntityMyPet) MyPet(de.Keyle.MyPet.api.entity.MyPet) EntityMyPet(de.Keyle.MyPet.compat.v1_12_R1.entity.EntityMyPet) EntityPlayer(net.minecraft.server.v1_12_R1.EntityPlayer) EntityTameableAnimal(net.minecraft.server.v1_12_R1.EntityTameableAnimal) EntityArmorStand(net.minecraft.server.v1_12_R1.EntityArmorStand) Behavior(de.Keyle.MyPet.api.skill.skills.Behavior)

Example 60 with EntityPlayer

use of net.minecraft.server.v1_16_R3.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) 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)

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)11 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