Search in sources :

Example 71 with Behavior

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

Example 72 with Behavior

use of de.Keyle.MyPet.api.skill.skills.Behavior in project MyPet by xXKeyleXx.

the class EntityMyEnderman method doMyPetTick.

protected void doMyPetTick() {
    super.doMyPetTick();
    BehaviorImpl skill = getMyPet().getSkills().get(BehaviorImpl.class);
    Behavior.BehaviorMode behavior = skill.getBehavior();
    if (behavior == Behavior.BehaviorMode.Aggressive) {
        if (!getMyPet().isScreaming()) {
            getMyPet().setScreaming(true);
        }
    } else {
        if (getMyPet().isScreaming()) {
            getMyPet().setScreaming(false);
        }
    }
}
Also used : BehaviorImpl(de.Keyle.MyPet.skill.skills.BehaviorImpl) Behavior(de.Keyle.MyPet.api.skill.skills.Behavior)

Example 73 with Behavior

use of de.Keyle.MyPet.api.skill.skills.Behavior in project MyPet by xXKeyleXx.

the class MyPetEntityListener method onMyPet.

@EventHandler(priority = EventPriority.MONITOR)
public void onMyPet(final EntityDeathEvent event) {
    // noinspection ConstantConditions
    if (event.getEntity() == null) {
        // catch invalid events (i.e. EnchantmentAPI)
        return;
    }
    LivingEntity deadEntity = event.getEntity();
    if (WorldGroup.getGroupByWorld(deadEntity.getWorld()).isDisabled()) {
        return;
    }
    if (deadEntity instanceof MyPetBukkitEntity) {
        MyPet myPet = ((MyPetBukkitEntity) deadEntity).getMyPet();
        // check health for death events where the pet isn't really dead (/killall)
        if (myPet == null || myPet.getHealth() > 0) {
            return;
        }
        final MyPetPlayer owner = myPet.getOwner();
        if (MyPetApi.getMyPetInfo().getReleaseOnDeath(myPet.getPetType()) && !owner.isMyPetAdmin()) {
            MyPetRemoveEvent removeEvent = new MyPetRemoveEvent(myPet, MyPetRemoveEvent.Source.Death);
            Bukkit.getServer().getPluginManager().callEvent(removeEvent);
            if (myPet.getSkills().isActive(Backpack.class)) {
                CustomInventory inv = myPet.getSkills().get(Backpack.class).getInventory();
                inv.dropContentAt(myPet.getLocation().get());
            }
            if (myPet instanceof MyPetEquipment) {
                ((MyPetEquipment) myPet).dropEquipment();
            }
            myPet.removePet();
            owner.setMyPetForWorldGroup(WorldGroup.getGroupByWorld(owner.getPlayer().getWorld().getName()), null);
            myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Command.Release.Dead", owner), myPet.getPetName()));
            MyPetApi.getMyPetManager().deactivateMyPet(owner, false);
            MyPetApi.getRepository().removeMyPet(myPet.getUUID(), null);
            return;
        }
        myPet.setRespawnTime((Configuration.Respawn.TIME_FIXED + MyPetApi.getMyPetInfo().getCustomRespawnTimeFixed(myPet.getPetType())) + (myPet.getExperience().getLevel() * (Configuration.Respawn.TIME_FACTOR + MyPetApi.getMyPetInfo().getCustomRespawnTimeFactor(myPet.getPetType()))));
        myPet.setStatus(PetState.Dead);
        if (deadEntity.getLastDamageCause() instanceof EntityDamageByEntityEvent) {
            EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) deadEntity.getLastDamageCause();
            if (e.getDamager() instanceof Player) {
                myPet.setRespawnTime((Configuration.Respawn.TIME_PLAYER_FIXED + MyPetApi.getMyPetInfo().getCustomRespawnTimeFixed(myPet.getPetType())) + (myPet.getExperience().getLevel() * (Configuration.Respawn.TIME_PLAYER_FACTOR + MyPetApi.getMyPetInfo().getCustomRespawnTimeFactor(myPet.getPetType()))));
            } else if (e.getDamager() instanceof MyPetBukkitEntity) {
                MyPet killerMyPet = ((MyPetBukkitEntity) e.getDamager()).getMyPet();
                if (myPet.getSkills().isActive(Behavior.class) && killerMyPet.getSkills().isActive(Behavior.class)) {
                    Behavior killerBehaviorSkill = killerMyPet.getSkills().get(Behavior.class);
                    Behavior deadBehaviorSkill = myPet.getSkills().get(Behavior.class);
                    if (deadBehaviorSkill.getBehavior() == BehaviorMode.Duel && killerBehaviorSkill.getBehavior() == BehaviorMode.Duel) {
                        MyPetMinecraftEntity myPetEntity = ((MyPetBukkitEntity) deadEntity).getHandle();
                        if (e.getDamager().equals(myPetEntity.getMyPetTarget())) {
                            myPet.setRespawnTime(10);
                            killerMyPet.setHealth(Double.MAX_VALUE);
                        }
                    }
                }
            }
        }
        event.setDroppedExp(0);
        event.getDrops().clear();
        if (Configuration.LevelSystem.Experience.LOSS_FIXED > 0 || Configuration.LevelSystem.Experience.LOSS_PERCENT > 0) {
            double lostExpirience = Configuration.LevelSystem.Experience.LOSS_FIXED;
            lostExpirience += myPet.getExperience().getRequiredExp() * Configuration.LevelSystem.Experience.LOSS_PERCENT / 100;
            if (lostExpirience > myPet.getExp()) {
                lostExpirience = myPet.getExp();
            }
            if (myPet.getSkilltree() != null) {
                int requiredLevel = myPet.getSkilltree().getRequiredLevel();
                if (requiredLevel > 1) {
                    double minExp = myPet.getExperience().getExpByLevel(requiredLevel);
                    lostExpirience = myPet.getExp() - lostExpirience < minExp ? myPet.getExp() - minExp : lostExpirience;
                }
            }
            if (Configuration.LevelSystem.Experience.ALLOW_LEVEL_DOWNGRADE) {
                lostExpirience = myPet.getExperience().removeExp(lostExpirience);
            } else {
                lostExpirience = myPet.getExperience().removeCurrentExp(lostExpirience);
            }
            if (Configuration.LevelSystem.Experience.DROP_LOST_EXP && lostExpirience < 0) {
                event.setDroppedExp((int) (Math.abs(lostExpirience)));
            }
        }
        if (myPet.getSkills().isActive(Backpack.class)) {
            BackpackImpl inventorySkill = myPet.getSkills().get(BackpackImpl.class);
            inventorySkill.closeInventory();
            if (inventorySkill.getDropOnDeath().getValue() && !owner.isMyPetAdmin()) {
                inventorySkill.getInventory().dropContentAt(myPet.getLocation().get());
            }
        }
        sendDeathMessage(event);
        myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Spawn.Respawn.In", owner.getPlayer()), myPet.getPetName(), myPet.getRespawnTime()));
        if (MyPetApi.getHookHelper().isEconomyEnabled() && owner.hasAutoRespawnEnabled() && myPet.getRespawnTime() >= owner.getAutoRespawnMin() && Permissions.has(owner.getPlayer(), "MyPet.command.respawn")) {
            double costs = myPet.getRespawnTime() * Configuration.Respawn.COSTS_FACTOR + Configuration.Respawn.COSTS_FIXED;
            if (MyPetApi.getHookHelper().getEconomy().canPay(owner, costs)) {
                MyPetApi.getHookHelper().getEconomy().pay(owner, costs);
                myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Command.Respawn.Paid", owner.getPlayer()), myPet.getPetName(), costs + " " + MyPetApi.getHookHelper().getEconomy().currencyNameSingular()));
                myPet.setRespawnTime(1);
            } else {
                myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Command.Respawn.NoMoney", owner.getPlayer()), myPet.getPetName(), costs + " " + MyPetApi.getHookHelper().getEconomy().currencyNameSingular()));
            }
        }
    }
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) BackpackImpl(de.Keyle.MyPet.skill.skills.BackpackImpl) Backpack(de.Keyle.MyPet.api.skill.skills.Backpack) MyPetRemoveEvent(de.Keyle.MyPet.api.event.MyPetRemoveEvent) Behavior(de.Keyle.MyPet.api.skill.skills.Behavior) CustomInventory(de.Keyle.MyPet.api.util.inventory.CustomInventory) EventHandler(org.bukkit.event.EventHandler)

Example 74 with Behavior

use of de.Keyle.MyPet.api.skill.skills.Behavior in project MyPet by xXKeyleXx.

the class RangedAttack method shouldStart.

@Override
public boolean shouldStart() {
    if (myPet.getRangedDamage() <= 0) {
        return false;
    }
    if (!entityMyPet.canMove()) {
        return false;
    }
    if (!entityMyPet.hasTarget()) {
        return false;
    }
    LivingEntity target = ((CraftLivingEntity) this.entityMyPet.getMyPetTarget()).getHandle();
    if (target instanceof ArmorStand) {
        return false;
    }
    double meleeDamage = myPet.getDamage();
    if (meleeDamage > 0 && this.entityMyPet.distanceToSqr(target.getX(), target.getBoundingBox().minY, target.getZ()) < 4) {
        Ranged rangedSkill = myPet.getSkills().get(Ranged.class);
        if (meleeDamage > rangedSkill.getDamage().getValue().doubleValue()) {
            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 (target instanceof TamableAnimal && ((TamableAnimal) target).isTame()) {
                return false;
            }
            if (target instanceof EntityMyPet) {
                return false;
            }
            if (target instanceof ServerPlayer) {
                return false;
            }
        }
    }
    this.target = target;
    return true;
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity) Ranged(de.Keyle.MyPet.api.skill.skills.Ranged) EntityMyPet(de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet) ArmorStand(net.minecraft.world.entity.decoration.ArmorStand) TamableAnimal(net.minecraft.world.entity.TamableAnimal) ServerPlayer(net.minecraft.server.level.ServerPlayer) CraftLivingEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity) Behavior(de.Keyle.MyPet.api.skill.skills.Behavior)

Example 75 with Behavior

use of de.Keyle.MyPet.api.skill.skills.Behavior 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.getLastHurtByMob();
    if (this.lastDamager == null || !lastDamager.isAlive()) {
        return false;
    }
    if (lastDamager instanceof ArmorStand) {
        return false;
    }
    if (lastDamager == petEntity) {
        return false;
    }
    if (lastDamager instanceof ServerPlayer) {
        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 TamableAnimal) {
        // Method: getOwner -> mojang mapping maps that to fx() even tho it still is getOwner.
        Method getOwnerReflect = ReflectionUtil.getMethod(TamableAnimal.class, "getOwner");
        TamableAnimal tameable = (TamableAnimal) lastDamager;
        try {
            if (tameable.isTame() && getOwnerReflect.invoke(tameable, null) != null) {
                Player tameableOwner = (Player) ((net.minecraft.world.entity.player.Player) getOwnerReflect.invoke(tameable, null)).getBukkitEntity();
                if (myPet.getOwner().equals(tameableOwner)) {
                    return false;
                }
            }
        } catch (IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
        }
    }
    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 TamableAnimal && ((TamableAnimal) lastDamager).isTame()) {
                return false;
            }
            if (lastDamager instanceof EntityMyPet) {
                return false;
            }
            return !(lastDamager instanceof ServerPlayer);
        }
    }
    return true;
}
Also used : CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer) Player(org.bukkit.entity.Player) ServerPlayer(net.minecraft.server.level.ServerPlayer) EntityMyPet(de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet) TamableAnimal(net.minecraft.world.entity.TamableAnimal) MyPet(de.Keyle.MyPet.api.entity.MyPet) EntityMyPet(de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) ArmorStand(net.minecraft.world.entity.decoration.ArmorStand) ServerPlayer(net.minecraft.server.level.ServerPlayer) Behavior(de.Keyle.MyPet.api.skill.skills.Behavior)

Aggregations

Behavior (de.Keyle.MyPet.api.skill.skills.Behavior)81 BehaviorImpl (de.Keyle.MyPet.skill.skills.BehaviorImpl)23 MyPet (de.Keyle.MyPet.api.entity.MyPet)22 Player (org.bukkit.entity.Player)15 Ranged (de.Keyle.MyPet.api.skill.skills.Ranged)13 ServerPlayer (net.minecraft.server.level.ServerPlayer)11 TamableAnimal (net.minecraft.world.entity.TamableAnimal)11 ArmorStand (net.minecraft.world.entity.decoration.ArmorStand)9 EntityMyPet (de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet)7 EntityMyPet (de.Keyle.MyPet.compat.v1_12_R1.entity.EntityMyPet)6 EntityMyPet (de.Keyle.MyPet.compat.v1_18_R1.entity.EntityMyPet)6 EntityMyPet (de.Keyle.MyPet.compat.v1_8_R3.entity.EntityMyPet)6 EntityMyPet (de.Keyle.MyPet.compat.v1_16_R1.entity.EntityMyPet)5 EntityMyPet (de.Keyle.MyPet.compat.v1_16_R3.entity.EntityMyPet)5 EntityMyPet (de.Keyle.MyPet.compat.v1_9_R2.entity.EntityMyPet)5 EntityLiving (net.minecraft.server.v1_8_R3.EntityLiving)5 CraftLivingEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity)5 CraftPlayer (org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer)5 CraftLivingEntity (org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity)5 CraftLivingEntity (org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity)5