use of de.Keyle.MyPet.api.util.animation.particle.SpiralAnimation in project MyPet by xXKeyleXx.
the class LevelUpListener method on.
@EventHandler
public void on(MyPetLevelUpEvent event) {
MyPet myPet = event.getPet();
int lvl = event.getLevel();
int lastLvl = event.getLastLevel();
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().getLanguage()), myPet.getPetName(), maxlevel));
} else {
myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.LevelSystem.LevelUp", event.getOwner().getLanguage()), myPet.getPetName(), event.getLevel()));
}
}
SkillTree skillTree = myPet.getSkilltree();
if (skillTree != null) {
if (skillTree.getLastLevelWithSkills() < lvl) {
lvl = skillTree.getLastLevelWithSkills();
}
for (int i = lastLvl + 1; i <= lvl; i++) {
if (skillTree.hasLevel(i)) {
SkillTreeLevel level = skillTree.getLevel(i);
if (!event.isQuiet()) {
if (level.hasLevelupMessage()) {
myPet.getOwner().sendMessage(Colorizer.setColors(level.getLevelupMessage()));
}
}
List<SkillInfo> skillList = level.getSkills();
for (SkillInfo skill : skillList) {
myPet.getSkills().getSkill(skill.getName()).upgrade(skill, event.isQuiet());
}
}
}
}
if (myPet.getStatus() == MyPet.PetState.Here) {
MyPetBukkitEntity entity = myPet.getEntity().get();
entity.getHandle().updateNameTag();
if (!event.isQuiet()) {
myPet.setHealth(myPet.getMaxHealth());
myPet.setSaturation(100);
final boolean version17 = MyPetApi.getCompatUtil().compareWithMinecraftVersion("1.8") < 0;
new SpiralAnimation(1, entity.getEyeHeight() + 0.5, new EntityLocationHolder(entity)) {
@Override
protected void playParticleEffect(Location location) {
if (version17) {
MyPetApi.getPlatformHelper().playParticleEffect(location, "magicCrit", 0, 0, 0, 0, 1, 32);
} else {
MyPetApi.getPlatformHelper().playParticleEffect(location, "CRIT_MAGIC", 0, 0, 0, 0, 1, 32);
}
// MyPetApi.getPlatformHelper().playParticleEffect(location, "flame", 0, 0, 0, 0, 1, 32);
}
}.loop(2);
if (MyPetApi.getCompatUtil().compareWithMinecraftVersion("1.9") >= 0) {
entity.getWorld().playSound(entity.getLocation(), "entity.player.levelup", 1F, 0.7F);
} else {
entity.getWorld().playSound(entity.getLocation(), Sound.valueOf("LEVEL_UP"), 1F, 0.7F);
}
}
}
}
use of de.Keyle.MyPet.api.util.animation.particle.SpiralAnimation 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);
}
});
}
}
Aggregations