use of de.Keyle.MyPet.api.skill.skilltree.SkillTree 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.skilltree.SkillTree in project MyPet by xXKeyleXx.
the class CommandChooseSkilltree method onCommand.
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("You can't use this command from server console!");
return true;
}
Player player = (Player) sender;
if (WorldGroup.getGroupByWorld(player.getWorld()).isDisabled()) {
player.sendMessage(Translation.getString("Message.No.AllowedHere", player));
return true;
}
if (MyPetApi.getMyPetManager().hasActiveMyPet(player)) {
final MyPet myPet = MyPetApi.getMyPetManager().getMyPet(player);
final MyPetPlayer myPetOwner = myPet.getOwner();
if (Configuration.Skilltree.AUTOMATIC_SKILLTREE_ASSIGNMENT && !myPet.getOwner().isMyPetAdmin()) {
myPet.autoAssignSkilltree();
sender.sendMessage(Translation.getString("Message.Command.ChooseSkilltree.AutomaticSkilltreeAssignment", myPet.getOwner()));
} else {
if (args.length >= 1) {
if (Configuration.Skilltree.AUTOMATIC_SKILLTREE_ASSIGNMENT && !myPet.getOwner().isMyPetAdmin()) {
myPet.autoAssignSkilltree();
sender.sendMessage(Translation.getString("Message.Command.ChooseSkilltree.AutomaticSkilltreeAssignment", myPet.getOwner()));
} else if (myPet.getSkilltree() != null && Configuration.Skilltree.CHOOSE_SKILLTREE_ONLY_ONCE && !myPet.getOwner().isMyPetAdmin()) {
sender.sendMessage(Util.formatText(Translation.getString("Message.Command.ChooseSkilltree.OnlyOnce", myPet.getOwner()), myPet.getPetName()));
} else {
String skilltreeName = "";
for (String arg : args) {
skilltreeName += arg + " ";
}
skilltreeName = skilltreeName.substring(0, skilltreeName.length() - 1);
if (MyPetApi.getSkilltreeManager().hasSkilltree(skilltreeName)) {
Skilltree skilltree = MyPetApi.getSkilltreeManager().getSkilltree(skilltreeName);
if (skilltree.getMobTypes().contains(myPet.getPetType()) && skilltree.checkRequirements(myPet)) {
int requiredLevel = skilltree.getRequiredLevel();
if (requiredLevel > 1 && myPet.getExperience().getLevel() < requiredLevel) {
myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Skilltree.RequiresLevel.Message", player), myPet.getPetName(), requiredLevel));
} else if (myPet.setSkilltree(skilltree, MyPetSelectSkilltreeEvent.Source.PlayerCommand)) {
sender.sendMessage(Util.formatText(Translation.getString("Message.Skilltree.SwitchedTo", player), Colorizer.setColors(skilltree.getDisplayName())));
if (!myPet.getOwner().isMyPetAdmin() || Configuration.Skilltree.SWITCH_FEE_ADMIN) {
double switchPenalty = Configuration.Skilltree.SWITCH_FEE_FIXED;
switchPenalty += myPet.getExperience().getExp() * Configuration.Skilltree.SWITCH_FEE_PERCENT / 100.;
if (requiredLevel > 1) {
double minExp = myPet.getExperience().getExpByLevel(requiredLevel);
switchPenalty = myPet.getExp() - switchPenalty < minExp ? myPet.getExp() - minExp : switchPenalty;
}
if (Configuration.LevelSystem.Experience.ALLOW_LEVEL_DOWNGRADE) {
myPet.getExperience().removeExp(switchPenalty);
} else {
myPet.getExperience().removeCurrentExp(switchPenalty);
}
}
} else {
sender.sendMessage(Translation.getString("Message.Skilltree.NotSwitched", player));
}
} else {
sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Skilltree.CantFindSkilltree", player), skilltreeName));
}
} else {
sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Skilltree.CantFindSkilltree", player), skilltreeName));
}
}
} else {
List<Skilltree> availableSkilltrees = new ArrayList<>();
for (Skilltree skilltree : MyPetApi.getSkilltreeManager().getOrderedSkilltrees()) {
if (skilltree.getMobTypes().contains(myPet.getPetType()) && skilltree.checkRequirements(myPet)) {
availableSkilltrees.add(skilltree);
}
}
if (availableSkilltrees.size() == 0) {
sender.sendMessage(Util.formatText(Translation.getString("Message.Command.ChooseSkilltree.NoneAvailable", player), myPet.getPetName()));
return true;
}
final Map<Integer, Skilltree> skilltreeSlotMap = new HashMap<>();
IconMenu menu = new IconMenu(Util.cutString(Util.formatText(Translation.getString("Message.Skilltree.Available", myPetOwner), myPet.getPetName()), 32), event -> {
if (myPet != myPetOwner.getMyPet()) {
event.setWillClose(true);
event.setWillDestroy(true);
return;
}
if (myPet.getSkilltree() != null && Configuration.Skilltree.CHOOSE_SKILLTREE_ONLY_ONCE && !myPet.getOwner().isMyPetAdmin()) {
sender.sendMessage(Util.formatText(Translation.getString("Message.Command.ChooseSkilltree.OnlyOnce", myPet.getOwner()), myPet.getPetName()));
} else if (skilltreeSlotMap.containsKey(event.getPosition())) {
Skilltree selecedSkilltree = skilltreeSlotMap.get(event.getPosition());
if (selecedSkilltree != null) {
int requiredLevel = selecedSkilltree.getRequiredLevel();
if (requiredLevel > 1 && myPet.getExperience().getLevel() < requiredLevel) {
myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Skilltree.RequiresLevel.Message", myPetOwner), myPet.getPetName(), requiredLevel));
} else if (myPet.setSkilltree(selecedSkilltree, MyPetSelectSkilltreeEvent.Source.PlayerCommand)) {
myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Skilltree.SwitchedTo", myPetOwner), Colorizer.setColors(selecedSkilltree.getDisplayName())));
if (!myPet.getOwner().isMyPetAdmin() || Configuration.Skilltree.SWITCH_FEE_ADMIN) {
double switchPenalty = Configuration.Skilltree.SWITCH_FEE_FIXED;
switchPenalty += myPet.getExperience().getExp() * Configuration.Skilltree.SWITCH_FEE_PERCENT / 100.;
if (requiredLevel > 1) {
double minExp = myPet.getExperience().getExpByLevel(requiredLevel);
switchPenalty = myPet.getExp() - switchPenalty < minExp ? myPet.getExp() - minExp : switchPenalty;
}
if (Configuration.LevelSystem.Experience.ALLOW_LEVEL_DOWNGRADE) {
myPet.getExperience().removeExp(switchPenalty);
} else {
myPet.getExperience().removeCurrentExp(switchPenalty);
}
}
} else {
myPet.getOwner().sendMessage(Translation.getString("Message.Skilltree.NotSwitched", myPetOwner));
}
}
}
event.setWillClose(true);
event.setWillDestroy(true);
}, MyPetApi.getPlugin());
ItemDatabase itemDatabase = MyPetApi.getServiceManager().getService(ItemDatabase.class).get();
for (int i = 0; i < availableSkilltrees.size(); i++) {
Skilltree addedSkilltree = availableSkilltrees.get(i);
SkilltreeIcon icon = addedSkilltree.getIcon();
MaterialHolder material = itemDatabase.getByID(icon.getMaterial());
if (material == null) {
material = itemDatabase.getByID("oak_sapling");
}
IconMenuItem option = new IconMenuItem().setMaterial(material.getMaterial()).setGlowing(icon.isGlowing()).setTitle(ChatColor.RESET + "❱❱❱ " + ChatColor.DARK_GREEN + Colorizer.setColors(addedSkilltree.getDisplayName()) + ChatColor.RESET + " ❰❰❰");
if (material.isLegacy()) {
option.setData(material.getLegacyId().getData());
}
boolean selectable = false;
int requiredLevel = addedSkilltree.getRequiredLevel();
if (requiredLevel > 1) {
selectable = myPet.getExperience().getLevel() >= addedSkilltree.getRequiredLevel();
}
List<String> description = new ArrayList<>();
if (requiredLevel > 1) {
String reqLevelMessage = ChatColor.RESET + "▶▶▶ ";
if (selectable) {
reqLevelMessage += ChatColor.GREEN;
} else {
reqLevelMessage += ChatColor.DARK_RED;
}
reqLevelMessage += Util.formatText(Translation.getString("Message.Skilltree.RequiresLevel.Item", myPetOwner), requiredLevel) + ChatColor.RESET + " ◀◀◀";
description.add(reqLevelMessage);
}
for (String line : addedSkilltree.getDescription()) {
description.add(ChatColor.RESET + Colorizer.setColors(line));
}
option.addLore(description);
menu.setOption(i, option);
skilltreeSlotMap.put(i, addedSkilltree);
}
menu.open(player);
}
}
} else {
sender.sendMessage(Translation.getString("Message.No.HasPet", player));
}
return true;
}
use of de.Keyle.MyPet.api.skill.skilltree.SkillTree in project MyPet by xXKeyleXx.
the class ShopMyPet method load.
public void load(ConfigurationSection config) {
if (config == null) {
return;
}
price = config.getDouble("Price", 0);
position = config.getInt("Position", -1);
petType = MyPetType.byName(config.getString("PetType", "Pig"));
exp = config.getDouble("EXP");
petName = config.getString("Name", null);
Skilltree skilltree = MyPetApi.getSkilltreeManager().getSkilltree(config.getString("Skilltree", null));
if (skilltree != null && skilltree.getMobTypes().contains(petType)) {
this.skilltree = skilltree;
}
for (String line : config.getStringList("Description")) {
icon.addLoreLine(ChatColor.RESET + Colorizer.setColors(line));
}
List<String> options = config.getStringList("Options");
if (options != null && options.size() > 0) {
TagCompound compound = new TagCompound();
String[] optionsArray = options.toArray(new String[0]);
CommandOptionCreate.createInfo(petType, optionsArray, compound);
this.NBTextendetInfo = compound;
}
}
use of de.Keyle.MyPet.api.skill.skilltree.SkillTree 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.SkillTree in project MyPet by xXKeyleXx.
the class MySqlRepository method getAllMyPets.
@Override
public List<StoredMyPet> getAllMyPets() {
try (Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * FROM pets;")) {
List<MyPetPlayer> playerList = getAllMyPetPlayers();
Map<UUID, MyPetPlayer> owners = new HashMap<>();
for (MyPetPlayer player : playerList) {
owners.put(player.getInternalUUID(), player);
}
List<StoredMyPet> pets = new ArrayList<>();
while (resultSet.next()) {
if (!owners.containsKey(UUID.fromString(resultSet.getString("owner_uuid")))) {
continue;
}
MyPetPlayer owner = owners.get(UUID.fromString(resultSet.getString("owner_uuid")));
InactiveMyPet pet = new InactiveMyPet(owner);
pet.setUUID(UUID.fromString(resultSet.getString("uuid")));
pet.setWorldGroup(resultSet.getString("world_group"));
pet.setExp(resultSet.getDouble("exp"));
pet.setHealth(resultSet.getDouble("health"));
pet.setRespawnTime(resultSet.getInt("respawn_time"));
pet.setPetName(resultSet.getString("name"));
pet.setPetType(MyPetType.valueOf(resultSet.getString("type")));
pet.setLastUsed(resultSet.getLong("last_used"));
pet.setSaturation(resultSet.getInt("hunger"));
pet.wantsToRespawn = resultSet.getBoolean("wants_to_spawn");
String skillTreeName = resultSet.getString("skilltree");
if (skillTreeName != null) {
Skilltree skilltree = MyPetApi.getSkilltreeManager().getSkilltree(skillTreeName);
if (skilltree != null) {
pet.setSkilltree(skilltree);
}
}
pet.setSkills(TagStream.readTag(resultSet.getBlob("skills").getBinaryStream(), true));
pet.setInfo(TagStream.readTag(resultSet.getBlob("info").getBinaryStream(), true));
pets.add(pet);
}
return pets;
} catch (SQLException | IOException e) {
e.printStackTrace();
}
return new ArrayList<>();
}
Aggregations