Search in sources :

Example 6 with Skill

use of de.Keyle.MyPet.api.skill.skilltree.Skill in project MyPet by xXKeyleXx.

the class LevelListener method on.

@EventHandler
public void on(MyPetLevelUpEvent event) {
    MyPet myPet = event.getPet();
    int lvl = event.getLevel();
    int fromLvl = event.fromLevel();
    if (!event.isQuiet()) {
        int maxlevel = myPet.getSkilltree() != null ? myPet.getSkilltree().getMaxLevel() : 0;
        if (maxlevel != 0 && lvl >= maxlevel) {
            myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.LevelSystem.ReachedMaxLevel", event.getOwner()), myPet.getPetName(), maxlevel));
        } else {
            myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.LevelSystem.LevelUp", event.getOwner()), myPet.getPetName(), event.getLevel()));
        }
    }
    Skilltree skilltree = myPet.getSkilltree();
    if (skilltree != null) {
        for (int i = fromLvl + 1; i <= lvl; i++) {
            if (!event.isQuiet()) {
                List<String> notifications = skilltree.getNotifications(i);
                for (String notification : notifications) {
                    notification = notification.replace("{{owner}}", myPet.getOwner().getName()).replace("{{level}}", "" + lvl).replace("{{pet}}", myPet.getPetName());
                    notification = Colorizer.setColors(notification);
                    String[] lines = notification.split("(<br>|\\\\n|\n|<br\\s?/>)");
                    for (String line : lines) {
                        myPet.getOwner().sendMessage(line);
                    }
                }
            }
            Set<Skill> affectedSkills = new HashSet<>();
            List<Upgrade> upgrades = skilltree.getUpgrades(i);
            for (Upgrade upgrade : upgrades) {
                SkillName sn = Util.getClassAnnotation(upgrade.getClass(), SkillName.class);
                if (sn != null) {
                    Skill skill = myPet.getSkills().get(sn.value());
                    if (skill != null) {
                        upgrade.apply(skill);
                        affectedSkills.add(skill);
                    }
                }
            }
            if (!event.isQuiet()) {
                for (Skill skill : affectedSkills) {
                    String[] messages = skill.getUpgradeMessage();
                    if (messages != null && messages.length > 0) {
                        for (String message : messages) {
                            myPet.getOwner().sendMessage("  " + message);
                        }
                    }
                }
            }
        }
    }
    if (myPet.getStatus() == MyPet.PetState.Here) {
        myPet.getEntity().ifPresent(entity -> {
            entity.getHandle().updateNameTag();
            if (!event.isQuiet()) {
                myPet.setHealth(myPet.getMaxHealth());
                myPet.setSaturation(100);
                new SpiralAnimation(1, entity.getEyeHeight() + 0.5, new EntityLocationHolder(entity)) {

                    @Override
                    protected void playParticleEffect(Location location) {
                        MyPetApi.getPlatformHelper().playParticleEffect(location, ParticleCompat.CRIT_MAGIC.get(), 0, 0, 0, 0, 1, 32);
                    }
                }.loop(2);
                entity.getWorld().playSound(entity.getLocation(), Sound.valueOf(SoundCompat.LEVEL_UP.get()), 1F, 0.7F);
            }
        });
    }
}
Also used : Skilltree(de.Keyle.MyPet.api.skill.skilltree.Skilltree) SkillName(de.Keyle.MyPet.api.skill.SkillName) MyPet(de.Keyle.MyPet.api.entity.MyPet) Upgrade(de.Keyle.MyPet.api.skill.Upgrade) Skill(de.Keyle.MyPet.api.skill.skilltree.Skill) SpiralAnimation(de.Keyle.MyPet.api.util.animation.particle.SpiralAnimation) EntityLocationHolder(de.Keyle.MyPet.api.util.location.EntityLocationHolder) HashSet(java.util.HashSet) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 7 with Skill

use of de.Keyle.MyPet.api.skill.skilltree.Skill in project MyPet by xXKeyleXx.

the class MyPetEntityListener method onMyPetDamageMonitor.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMyPetDamageMonitor(final EntityDamageByEntityEvent event) {
    if (event.getEntity() == null) {
        // catch invalid events (i.e. EnchantmentAPI)
        return;
    }
    Entity target = event.getEntity();
    if (WorldGroup.getGroupByWorld(target.getWorld()).isDisabled()) {
        return;
    }
    if (target instanceof LivingEntity) {
        Entity source = event.getDamager();
        if (Configuration.LevelSystem.Experience.DAMAGE_WEIGHTED_EXPERIENCE_DISTRIBUTION && !(target instanceof Player) && !(target instanceof MyPetBukkitEntity)) {
            LivingEntity livingSource = null;
            if (source instanceof Projectile) {
                Projectile projectile = (Projectile) source;
                if (projectile.getShooter() instanceof LivingEntity) {
                    livingSource = (LivingEntity) projectile.getShooter();
                }
            } else if (source instanceof LivingEntity) {
                livingSource = (LivingEntity) source;
            }
            if (livingSource != null) {
                MyPetExperience.addDamageToEntity(livingSource, (LivingEntity) target, event.getDamage());
            }
        }
        if (source instanceof Projectile) {
            ProjectileSource projectileSource = ((Projectile) source).getShooter();
            if (projectileSource instanceof Entity) {
                source = (Entity) projectileSource;
            }
        }
        if (source instanceof MyPetBukkitEntity) {
            MyPet myPet = ((MyPetBukkitEntity) source).getMyPet();
            if (myPet.getStatus() != PetState.Here) {
                return;
            }
            // fix influence of other plugins for this event and throw damage event
            MyPetDamageEvent petDamageEvent = new MyPetDamageEvent(myPet, target, event.getOriginalDamage(EntityDamageEvent.DamageModifier.BASE));
            Bukkit.getPluginManager().callEvent(petDamageEvent);
            if (petDamageEvent.isCancelled()) {
                event.setCancelled(true);
                return;
            } else {
                event.setDamage(petDamageEvent.getDamage());
            }
            if (!isSkillActive) {
                for (Skill skill : myPet.getSkills().all()) {
                    if (skill instanceof OnHitSkill) {
                        OnHitSkill onHitSkill = (OnHitSkill) skill;
                        if (onHitSkill.trigger()) {
                            MyPetOnHitSkillEvent skillEvent = new MyPetOnHitSkillEvent(myPet, onHitSkill, (LivingEntity) target);
                            Bukkit.getPluginManager().callEvent(skillEvent);
                            if (!skillEvent.isCancelled()) {
                                isSkillActive = true;
                                onHitSkill.apply((LivingEntity) target);
                                isSkillActive = false;
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) OnDamageByEntitySkill(de.Keyle.MyPet.api.skill.OnDamageByEntitySkill) Skill(de.Keyle.MyPet.api.skill.skilltree.Skill) OnHitSkill(de.Keyle.MyPet.api.skill.OnHitSkill) MyPetOnHitSkillEvent(de.Keyle.MyPet.api.event.MyPetOnHitSkillEvent) MyPetDamageEvent(de.Keyle.MyPet.api.event.MyPetDamageEvent) OnHitSkill(de.Keyle.MyPet.api.skill.OnHitSkill) ProjectileSource(org.bukkit.projectiles.ProjectileSource) EntityMyPetProjectile(de.Keyle.MyPet.api.entity.skill.ranged.EntityMyPetProjectile) CraftMyPetProjectile(de.Keyle.MyPet.api.entity.skill.ranged.CraftMyPetProjectile) EventHandler(org.bukkit.event.EventHandler)

Example 8 with Skill

use of de.Keyle.MyPet.api.skill.skilltree.Skill in project MyPet by xXKeyleXx.

the class MyPetManager method activateMyPet.

// All ----------------------------------------------------------------------
public Optional<MyPet> activateMyPet(StoredMyPet storedMyPet) {
    if (storedMyPet == null) {
        return Optional.empty();
    }
    if (!storedMyPet.getOwner().isOnline()) {
        return Optional.empty();
    }
    if (storedMyPet.getOwner().hasMyPet()) {
        if (!deactivateMyPet(storedMyPet.getOwner(), true)) {
            return Optional.empty();
        }
    }
    Event event = new MyPetLoadEvent(storedMyPet);
    Bukkit.getServer().getPluginManager().callEvent(event);
    MyPet myPet = MyPetClass.getByMyPetType(storedMyPet.getPetType()).getNewMyPetInstance(storedMyPet.getOwner());
    myPet.setUUID(storedMyPet.getUUID());
    myPet.setPetName(storedMyPet.getPetName());
    myPet.setRespawnTime(storedMyPet.getRespawnTime());
    myPet.setWorldGroup(storedMyPet.getWorldGroup());
    myPet.setInfo(storedMyPet.getInfo());
    myPet.setLastUsed(storedMyPet.getLastUsed());
    myPet.setWantsToRespawn(storedMyPet.wantsToRespawn());
    myPet.getExperience().setExp(storedMyPet.getExp());
    myPet.setSkilltree(storedMyPet.getSkilltree());
    Collection<Skill> skills = myPet.getSkills().all();
    if (skills.size() > 0) {
        for (Skill skill : skills) {
            if (skill instanceof NBTStorage) {
                NBTStorage storageSkill = (NBTStorage) skill;
                if (storedMyPet.getSkillInfo().getCompoundData().containsKey(skill.getName())) {
                    storageSkill.load(storedMyPet.getSkillInfo().getAs(skill.getName(), TagCompound.class));
                }
            }
        }
    }
    myPet.setHealth(storedMyPet.getHealth());
    myPet.setSaturation(storedMyPet.getSaturation());
    mActivePetsPlayer.put(myPet, myPet.getOwner());
    event = new MyPetActivatedEvent(myPet);
    Bukkit.getServer().getPluginManager().callEvent(event);
    return Optional.of(myPet);
}
Also used : MyPetLoadEvent(de.Keyle.MyPet.api.event.MyPetLoadEvent) Skill(de.Keyle.MyPet.api.skill.skilltree.Skill) MyPet(de.Keyle.MyPet.api.entity.MyPet) InactiveMyPet(de.Keyle.MyPet.entity.InactiveMyPet) StoredMyPet(de.Keyle.MyPet.api.entity.StoredMyPet) MyPetActivatedEvent(de.Keyle.MyPet.api.event.MyPetActivatedEvent) Event(org.bukkit.event.Event) MyPetLoadEvent(de.Keyle.MyPet.api.event.MyPetLoadEvent) NBTStorage(de.Keyle.MyPet.api.util.NBTStorage) MyPetActivatedEvent(de.Keyle.MyPet.api.event.MyPetActivatedEvent) TagCompound(de.keyle.knbt.TagCompound)

Example 9 with Skill

use of de.Keyle.MyPet.api.skill.skilltree.Skill in project MyPet by xXKeyleXx.

the class CommandSkill method onCommand.

public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    Player petOwner;
    if (args.length == 0 && sender instanceof Player) {
        petOwner = (Player) sender;
    } else if (args.length > 0 && (!(sender instanceof Player) || Permissions.has((Player) sender, "MyPet.admin"))) {
        petOwner = Bukkit.getServer().getPlayer(args[0]);
        if (petOwner == null || !petOwner.isOnline()) {
            sender.sendMessage(Translation.getString("Message.No.PlayerOnline", sender));
            return true;
        } else if (!MyPetApi.getMyPetManager().hasActiveMyPet(petOwner)) {
            sender.sendMessage(Util.formatText(Translation.getString("Message.No.UserHavePet", sender), petOwner.getName()));
            return true;
        }
    } else {
        if (sender instanceof Player) {
            sender.sendMessage(Translation.getString("Message.No.AllowedHere", sender));
        } else {
            sender.sendMessage("You can't use this command from server console!");
        }
        return true;
    }
    if (WorldGroup.getGroupByWorld(petOwner.getWorld()).isDisabled()) {
        sender.sendMessage(Translation.getString("Message.No.AllowedHere", sender));
    }
    if (MyPetApi.getMyPetManager().hasActiveMyPet(petOwner)) {
        MyPet myPet = MyPetApi.getMyPetManager().getMyPet(petOwner);
        myPet.autoAssignSkilltree();
        sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Skills.Show", sender), myPet.getPetName(), myPet.getSkilltree() == null ? "-" : Colorizer.setColors(myPet.getSkilltree().getDisplayName())));
        for (Skill skill : myPet.getSkills().all()) {
            if (skill.isActive()) {
                sender.sendMessage("  " + ChatColor.GREEN + skill.getName(MyPetApi.getPlatformHelper().getCommandSenderLanguage(sender)) + ChatColor.RESET + " " + skill.toPrettyString(MyPetApi.getPlatformHelper().getCommandSenderLanguage(sender)));
            }
        }
        return true;
    } else {
        sender.sendMessage(Translation.getString("Message.No.HasPet", sender));
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) Skill(de.Keyle.MyPet.api.skill.skilltree.Skill) MyPet(de.Keyle.MyPet.api.entity.MyPet)

Example 10 with Skill

use of de.Keyle.MyPet.api.skill.skilltree.Skill in project MyPet by xXKeyleXx.

the class MyPet method getSkillInfo.

public TagCompound getSkillInfo() {
    TagCompound skillsNBT = new TagCompound();
    Collection<Skill> skillList = this.getSkills().all();
    if (skillList.size() > 0) {
        for (Skill skill : skillList) {
            if (skill instanceof NBTStorage) {
                NBTStorage storageSkill = (NBTStorage) skill;
                TagCompound s = storageSkill.save();
                if (s != null) {
                    skillsNBT.getCompoundData().put(skill.getName(), s);
                }
            }
        }
    }
    return skillsNBT;
}
Also used : Skill(de.Keyle.MyPet.api.skill.skilltree.Skill) NBTStorage(de.Keyle.MyPet.api.util.NBTStorage)

Aggregations

Skill (de.Keyle.MyPet.api.skill.skilltree.Skill)11 MyPet (de.Keyle.MyPet.api.entity.MyPet)5 EventHandler (org.bukkit.event.EventHandler)5 NBTStorage (de.Keyle.MyPet.api.util.NBTStorage)4 SkillName (de.Keyle.MyPet.api.skill.SkillName)3 Upgrade (de.Keyle.MyPet.api.skill.Upgrade)3 Skilltree (de.Keyle.MyPet.api.skill.skilltree.Skilltree)3 CraftMyPetProjectile (de.Keyle.MyPet.api.entity.skill.ranged.CraftMyPetProjectile)2 EntityMyPetProjectile (de.Keyle.MyPet.api.entity.skill.ranged.EntityMyPetProjectile)2 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)2 OnDamageByEntitySkill (de.Keyle.MyPet.api.skill.OnDamageByEntitySkill)2 OnHitSkill (de.Keyle.MyPet.api.skill.OnHitSkill)2 EntityLocationHolder (de.Keyle.MyPet.api.util.location.EntityLocationHolder)2 Location (org.bukkit.Location)2 StoredMyPet (de.Keyle.MyPet.api.entity.StoredMyPet)1 MyPetActivatedEvent (de.Keyle.MyPet.api.event.MyPetActivatedEvent)1 MyPetDamageEvent (de.Keyle.MyPet.api.event.MyPetDamageEvent)1 MyPetLevelDownEvent (de.Keyle.MyPet.api.event.MyPetLevelDownEvent)1 MyPetLevelUpEvent (de.Keyle.MyPet.api.event.MyPetLevelUpEvent)1 MyPetLoadEvent (de.Keyle.MyPet.api.event.MyPetLoadEvent)1