use of de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType in project MyPet by xXKeyleXx.
the class SqLiteRepository method getAllMyPets.
@Override
public List<StoredMyPet> getAllMyPets() {
try {
List<MyPetPlayer> playerList = getAllMyPetPlayers();
Map<UUID, MyPetPlayer> owners = new HashMap<>();
for (MyPetPlayer player : playerList) {
owners.put(player.getInternalUUID(), player);
}
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * FROM pets;");
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.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.setHungerValue(resultSet.getInt("hunger"));
pet.setWorldGroup(resultSet.getString("world_group"));
pet.wantsToRespawn = resultSet.getBoolean("wants_to_spawn");
String skillTreeName = resultSet.getString("skilltree");
if (skillTreeName != null) {
if (SkillTreeMobType.byPetType(pet.getPetType()) != null) {
SkillTreeMobType mobType = SkillTreeMobType.byPetType(pet.getPetType());
if (mobType.hasSkillTree(skillTreeName)) {
pet.setSkilltree(mobType.getSkillTree(skillTreeName));
}
}
}
pet.setSkills(TagStream.readTag(resultSet.getBytes("skills"), true));
pet.setInfo(TagStream.readTag(resultSet.getBytes("info"), true));
pets.add(pet);
}
return pets;
} catch (SQLException | IOException e) {
e.printStackTrace();
}
return new ArrayList<>();
}
use of de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType in project MyPet by xXKeyleXx.
the class SkillTreeLoaderNBT method saveSkillTree.
protected boolean saveSkillTree(ConfigurationNBT nbtConfiguration, String petTypeName) {
boolean saveMobType = false;
SkillTreeMobType mobType;
if (petTypeName.equalsIgnoreCase("default")) {
mobType = SkillTreeMobType.DEFAULT;
} else if (SkillTreeMobType.hasMobType(MyPetType.byName(petTypeName, false))) {
mobType = SkillTreeMobType.getMobTypeByName(petTypeName);
} else {
return false;
}
if (mobType.getSkillTreeNames().size() != 0) {
mobType.cleanupPlaces();
List<TagCompound> skilltreeList = new ArrayList<>();
for (SkillTree skillTree : mobType.getSkillTrees()) {
TagCompound skilltreeCompound = new TagCompound();
skilltreeCompound.getCompoundData().put("Name", new TagString(skillTree.getName()));
skilltreeCompound.getCompoundData().put("Place", new TagInt(mobType.getSkillTreePlace(skillTree)));
if (skillTree.hasInheritance()) {
skilltreeCompound.getCompoundData().put("Inherits", new TagString(skillTree.getInheritance()));
}
if (skillTree.hasCustomPermissions()) {
skilltreeCompound.getCompoundData().put("Permission", new TagString(skillTree.getPermission()));
}
if (skillTree.hasDisplayName()) {
skilltreeCompound.getCompoundData().put("Display", new TagString(skillTree.getDisplayName()));
}
if (skillTree.getMaxLevel() > 0) {
skilltreeCompound.getCompoundData().put("MaxLevel", new TagInt(skillTree.getMaxLevel()));
}
if (skillTree.getRequiredLevel() > 1) {
skilltreeCompound.getCompoundData().put("RequiredLevel", new TagInt(skillTree.getRequiredLevel()));
}
if (skillTree.getDescription().size() > 0) {
List<TagString> descriptionTagList = new ArrayList<>();
for (String line : skillTree.getDescription()) {
descriptionTagList.add(new TagString(line));
}
skilltreeCompound.getCompoundData().put("Description", new TagList(descriptionTagList));
}
skilltreeCompound.getCompoundData().put("IconItem", skillTree.getIconItem());
List<TagCompound> levelList = new ArrayList<>();
for (SkillTreeLevel level : skillTree.getLevelList()) {
TagCompound levelCompound = new TagCompound();
levelCompound.getCompoundData().put("Level", new TagInt(level.getLevel()));
if (level.hasLevelupMessage()) {
levelCompound.getCompoundData().put("Message", new TagString(level.getLevelupMessage()));
}
List<TagCompound> skillList = new ArrayList<>();
for (SkillInfo skill : skillTree.getLevel(level.getLevel()).getSkills()) {
if (!skill.isAddedByInheritance()) {
TagCompound skillCompound = new TagCompound();
skillCompound.getCompoundData().put("Name", new TagString(skill.getName()));
skillCompound.getCompoundData().put("Properties", skill.getProperties());
skillList.add(skillCompound);
}
}
levelCompound.getCompoundData().put("Skills", new TagList(skillList));
levelList.add(levelCompound);
}
skilltreeCompound.getCompoundData().put("Level", new TagList(levelList));
skilltreeList.add(skilltreeCompound);
}
nbtConfiguration.getNBTCompound().getCompoundData().put("Skilltrees", new TagList(skilltreeList));
if (mobType.getSkillTreeNames().size() > 0) {
nbtConfiguration.save();
saveMobType = true;
}
}
return saveMobType;
}
use of de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType in project MyPet by xXKeyleXx.
the class SqLiteRepository method resultSetToMyPet.
// Pets ------------------------------------------------------------------------------------------------------------
private List<StoredMyPet> resultSetToMyPet(MyPetPlayer owner, ResultSet resultSet, boolean next) {
List<StoredMyPet> pets = new ArrayList<>();
try {
while (!next || resultSet.next()) {
next = true;
InactiveMyPet pet = new InactiveMyPet(owner);
pet.setUUID(UUID.fromString(resultSet.getString("uuid")));
pet.setExp(resultSet.getDouble("exp"));
pet.setHealth(resultSet.getDouble("health"));
pet.setRespawnTime(resultSet.getInt("respawn_time"));
pet.setPetName(new String(resultSet.getBytes("name"), StandardCharsets.UTF_8));
pet.setPetType(MyPetType.valueOf(resultSet.getString("type")));
pet.setLastUsed(resultSet.getLong("last_used"));
pet.setHungerValue(resultSet.getDouble("hunger"));
pet.setWorldGroup(resultSet.getString("world_group"));
pet.wantsToRespawn = resultSet.getBoolean("wants_to_spawn");
String skillTreeName = resultSet.getString("skilltree");
if (skillTreeName != null) {
if (SkillTreeMobType.byPetType(pet.getPetType()) != null) {
SkillTreeMobType mobType = SkillTreeMobType.byPetType(pet.getPetType());
if (mobType.hasSkillTree(skillTreeName)) {
pet.setSkilltree(mobType.getSkillTree(skillTreeName));
}
}
}
pet.setSkills(TagStream.readTag(resultSet.getBytes("skills"), true));
pet.setInfo(TagStream.readTag(resultSet.getBytes("info"), true));
Optional<RepositoryMyPetConverterService> converter = MyPetApi.getServiceManager().getService(RepositoryMyPetConverterService.class);
if (converter.isPresent()) {
converter.get().convert(pet);
}
pets.add(pet);
}
} catch (SQLException | IOException e) {
e.printStackTrace();
}
return pets;
}
use of de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType in project MyPet by xXKeyleXx.
the class SkillTreeLoaderNBT method loadSkillTrees.
public void loadSkillTrees(String configPath, List<String> mobtypes) {
ConfigurationNBT skilltreeConfig;
File skillFile;
for (String mobType : mobtypes) {
skillFile = new File(configPath + File.separator + mobType.toLowerCase() + ".st");
SkillTreeMobType skillTreeMobType;
if (mobType.equalsIgnoreCase("default")) {
skillTreeMobType = SkillTreeMobType.DEFAULT;
} else {
skillTreeMobType = SkillTreeMobType.getMobTypeByName(mobType);
}
if (!skillFile.exists()) {
continue;
}
skilltreeConfig = new ConfigurationNBT(skillFile);
if (skilltreeConfig.load()) {
try {
loadSkillTree(skilltreeConfig, skillTreeMobType);
} catch (Exception e) {
MyPetApi.getLogger().warning("Error while loading skilltrees from: " + mobType.toLowerCase() + ".st");
e.printStackTrace();
}
}
skillTreeMobType.cleanupPlaces();
}
}
use of de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType in project MyPet by xXKeyleXx.
the class CommandChooseSkilltree method onCommand.
public boolean onCommand(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 (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().getLanguage()));
} 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().getLanguage()), myPet.getPetName()));
} else if (SkillTreeMobType.hasMobType(myPet.getPetType())) {
SkillTreeMobType skillTreeMobType = SkillTreeMobType.byPetType(myPet.getPetType());
if (args.length >= 1) {
String skilltreeName = "";
for (String arg : args) {
skilltreeName += arg + " ";
}
skilltreeName = skilltreeName.substring(0, skilltreeName.length() - 1);
if (skillTreeMobType.hasSkillTree(skilltreeName)) {
SkillTree skillTree = skillTreeMobType.getSkillTree(skilltreeName);
if (Permissions.hasLegacy(player, "MyPet.skilltree.", skillTree.getPermission())) {
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)) {
sender.sendMessage(Util.formatText(Translation.getString("Message.Skilltree.SwitchedTo", player), skillTree.getName()));
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;
}
myPet.getExperience().removeExp(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 : skillTreeMobType.getSkillTrees()) {
if (Permissions.hasLegacy(player, "MyPet.skilltree.", skillTree.getPermission())) {
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), new IconMenu.OptionClickEventHandler() {
@Override
public void onOptionClick(IconMenu.OptionClickEvent event) {
if (myPet != myPetOwner.getMyPet()) {
event.setWillClose(true);
event.setWillDestroy(true);
return;
}
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)) {
myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Skilltree.SwitchedTo", myPetOwner), selecedSkilltree.getName()));
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;
}
myPet.getExperience().removeExp(switchPenalty);
}
} else {
myPet.getOwner().sendMessage(Translation.getString("Message.Skilltree.NotSwitched", myPetOwner));
}
}
}
event.setWillClose(true);
event.setWillDestroy(true);
}
}, MyPetApi.getPlugin());
for (int i = 0; i < availableSkilltrees.size(); i++) {
SkillTree addedSkilltree = availableSkilltrees.get(i);
TagCompound tag = addedSkilltree.getIconItem();
IconMenuItem option = IconMenuItem.fromTagCompund(tag);
option.setTitle(ChatColor.RESET + "❱❱❱ " + ChatColor.DARK_GREEN + Colorizer.setColors(addedSkilltree.getDisplayName()) + ChatColor.RESET + " ❰❰❰");
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(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;
}
Aggregations