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);
}
});
}
}
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;
}
}
}
}
}
}
}
}
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);
}
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;
}
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;
}
Aggregations