use of de.Keyle.MyPet.api.skill.SkillInstance in project MyPet by xXKeyleXx.
the class MyPet method save.
@Override
public TagCompound save() {
TagCompound petNBT = new TagCompound();
petNBT.getCompoundData().put("UUID", new TagString(getUUID().toString()));
petNBT.getCompoundData().put("Type", new TagString(this.getPetType().name()));
petNBT.getCompoundData().put("Health", new TagDouble(this.health));
petNBT.getCompoundData().put("Respawntime", new TagInt(this.respawnTime));
petNBT.getCompoundData().put("Hunger", new TagDouble(this.saturation));
petNBT.getCompoundData().put("Name", new TagString(this.petName));
petNBT.getCompoundData().put("WorldGroup", new TagString(this.worldGroup));
petNBT.getCompoundData().put("Exp", new TagDouble(this.getExp()));
petNBT.getCompoundData().put("LastUsed", new TagLong(this.lastUsed));
petNBT.getCompoundData().put("Info", writeExtendedInfo());
petNBT.getCompoundData().put("Internal-Owner-UUID", new TagString(this.petOwner.getInternalUUID().toString()));
petNBT.getCompoundData().put("Wants-To-Respawn", new TagByte(wantsToRespawn));
if (this.skillTree != null) {
petNBT.getCompoundData().put("Skilltree", new TagString(skillTree.getName()));
}
TagCompound skillsNBT = new TagCompound();
Collection<SkillInstance> skillList = this.getSkills().getSkills();
if (skillList.size() > 0) {
for (SkillInstance skill : skillList) {
if (skill instanceof NBTStorage) {
NBTStorage storageSkill = (NBTStorage) skill;
TagCompound s = storageSkill.save();
if (s != null) {
skillsNBT.getCompoundData().put(skill.getName(), s);
}
}
}
}
petNBT.getCompoundData().put("Skills", skillsNBT);
return petNBT;
}
use of de.Keyle.MyPet.api.skill.SkillInstance in project MyPet by xXKeyleXx.
the class MyPet method schedule.
public void schedule() {
if (status != PetState.Despawned && getOwner().isOnline()) {
for (SkillInstance skill : skills.getSkills()) {
if (skill instanceof Scheduler) {
((Scheduler) skill).schedule();
}
}
if (status == PetState.Dead) {
respawnTime--;
if (respawnTime <= 0) {
respawnPet();
} else if (MyPetApi.getPluginHookManager().isHookActive(VaultHook.class) && getOwner().hasAutoRespawnEnabled() && respawnTime >= getOwner().getAutoRespawnMin() && Permissions.has(getOwner().getPlayer(), "MyPet.user.respawn")) {
double cost = respawnTime * Configuration.Respawn.COSTS_FACTOR + Configuration.Respawn.COSTS_FIXED;
VaultHook vaultHook = MyPetApi.getPluginHookManager().getHook(VaultHook.class);
if (vaultHook.canPay(getOwner().getPlayer(), cost)) {
vaultHook.pay(getOwner().getPlayer(), cost);
getOwner().sendMessage(Util.formatText(Translation.getString("Message.Command.Respawn.Paid", petOwner.getLanguage()), petName, cost + " " + vaultHook.currencyNameSingular()));
respawnTime = 1;
}
}
}
if (status == PetState.Here) {
if (Configuration.HungerSystem.USE_HUNGER_SYSTEM) {
if (saturation > 1 && --hungerTime <= 0) {
saturation--;
hungerTime = Configuration.HungerSystem.HUNGER_SYSTEM_TIME;
if (saturation == 66) {
getOwner().sendMessage(Util.formatText(Translation.getString("Message.Hunger.Rumbling", getOwner()), getPetName()));
} else if (saturation == 33) {
getOwner().sendMessage(Util.formatText(Translation.getString("Message.Hunger.Hungry", getOwner()), getPetName()));
} else if (saturation == 1) {
getOwner().sendMessage(Util.formatText(Translation.getString("Message.Hunger.Starving", getOwner()), getPetName()));
}
}
if (saturation == 1 && getHealth() >= 2) {
getEntity().get().damage(1.);
}
}
}
}
}
use of de.Keyle.MyPet.api.skill.SkillInstance in project MyPet by xXKeyleXx.
the class CommandSkill method onCommand.
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
Player petOwner = (Player) sender;
if (args.length > 0 && Permissions.has(petOwner, "MyPet.admin", false)) {
petOwner = Bukkit.getServer().getPlayer(args[0]);
if (petOwner == null || !petOwner.isOnline()) {
sender.sendMessage(Translation.getString("Message.No.PlayerOnline", petOwner));
return true;
} else if (!MyPetApi.getMyPetManager().hasActiveMyPet(petOwner)) {
sender.sendMessage(Util.formatText(Translation.getString("Message.No.UserHavePet", petOwner), petOwner.getName()));
return true;
}
}
if (MyPetApi.getMyPetManager().hasActiveMyPet(petOwner)) {
MyPet myPet = MyPetApi.getMyPetManager().getMyPet(petOwner);
myPet.autoAssignSkilltree();
sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Skills.Show", petOwner), myPet.getPetName(), (myPet.getSkilltree() == null ? "-" : myPet.getSkilltree().getDisplayName())));
for (SkillInstance skill : myPet.getSkills().getSkills()) {
if (skill.isActive()) {
sender.sendMessage(" " + ChatColor.GREEN + skill.getName(MyPetApi.getPlatformHelper().getPlayerLanguage(petOwner)) + ChatColor.RESET + " " + skill.getFormattedValue());
}
}
return true;
} else {
sender.sendMessage(Translation.getString("Message.No.HasPet", petOwner));
}
return true;
}
sender.sendMessage("You can't use this command from server console!");
return true;
}
use of de.Keyle.MyPet.api.skill.SkillInstance in project MyPet by xXKeyleXx.
the class CommandOptionReloadSkilltrees method onCommandOption.
@Override
public boolean onCommandOption(CommandSender sender, String[] args) {
SkillTreeMobType.clearMobTypes();
String[] petTypes = new String[MyPetType.values().length + 1];
petTypes[0] = "default";
for (int i = 1; i <= MyPetType.values().length; i++) {
petTypes[i] = MyPetType.values()[i - 1].name();
}
for (MyPet myPet : MyPetApi.getMyPetManager().getAllActiveMyPets()) {
myPet.getSkills().reset();
}
SkillTreeMobType.clearMobTypes();
SkillTreeLoaderNBT.getSkilltreeLoader().loadSkillTrees(MyPetApi.getPlugin().getDataFolder().getPath() + File.separator + "skilltrees", petTypes);
Set<String> skilltreeNames = new LinkedHashSet<>();
for (MyPetType mobType : MyPetType.values()) {
SkillTreeMobType skillTreeMobType = SkillTreeMobType.byPetType(mobType);
SkillTreeLoader.addDefault(skillTreeMobType);
SkillTreeLoader.manageInheritance(skillTreeMobType);
skilltreeNames.addAll(skillTreeMobType.getSkillTreeNames());
}
// register skilltree permissions
for (String skilltreeName : skilltreeNames) {
try {
Bukkit.getPluginManager().addPermission(new Permission("MyPet.custom.skilltree." + skilltreeName));
} catch (Exception ignored) {
}
}
for (MyPet myPet : MyPetApi.getMyPetManager().getAllActiveMyPets()) {
myPet.getSkills().reset();
SkillTree skillTree = myPet.getSkilltree();
if (skillTree != null) {
String skilltreeName = skillTree.getName();
if (SkillTreeMobType.hasMobType(myPet.getPetType())) {
SkillTreeMobType mobType = SkillTreeMobType.byPetType(myPet.getPetType());
if (mobType.hasSkillTree(skilltreeName)) {
skillTree = mobType.getSkillTree(skilltreeName);
} else {
skillTree = null;
}
} else {
skillTree = null;
}
}
myPet.setSkilltree(skillTree);
if (skillTree != null) {
sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Skills.Show", myPet.getOwner()), myPet.getPetName(), (myPet.getSkilltree() == null ? "-" : myPet.getSkilltree().getDisplayName())));
for (SkillInstance skill : myPet.getSkills().getSkills()) {
if (skill.isActive()) {
myPet.getOwner().sendMessage(" " + ChatColor.GREEN + skill.getName(myPet.getOwner().getLanguage()) + ChatColor.RESET + " " + skill.getFormattedValue());
}
}
}
}
sender.sendMessage("[" + ChatColor.AQUA + "MyPet" + ChatColor.RESET + "] skilltrees loaded!");
return true;
}
use of de.Keyle.MyPet.api.skill.SkillInstance in project MyPet by xXKeyleXx.
the class InactiveMyPet method setSkills.
public void setSkills(Collection<SkillInstance> skills) {
if (NBTSkills == null) {
NBTSkills = new TagCompound();
}
for (SkillInstance skill : skills) {
if (skill instanceof NBTStorage) {
NBTStorage storageSkill = (NBTStorage) skill;
TagCompound s = storageSkill.save();
if (s != null) {
this.NBTSkills.getCompoundData().put(skill.getName(), s);
}
}
}
}
Aggregations