use of de.Keyle.MyPet.api.skill.skilltree.Skilltree in project MyPet by xXKeyleXx.
the class SkillTreeLoader method manageInheritance.
public static void manageInheritance(SkillTreeMobType skillTreeMobType) {
Map<SkillTree, SkillTree> skillTreeClones = new HashMap<>();
for (SkillTree skillTree : skillTreeMobType.getSkillTrees()) {
skillTreeClones.put(skillTree, skillTree.clone());
}
for (SkillTree skillTree : skillTreeMobType.getSkillTrees()) {
alreadyLoadedInheritance.clear();
if (skillTree.hasInheritance()) {
alreadyLoadedInheritance.add(skillTree);
manageInheritance(skillTreeMobType, skillTree, skillTree, skillTreeClones, 0);
}
}
}
use of de.Keyle.MyPet.api.skill.skilltree.Skilltree 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.Skilltree in project MyPet by xXKeyleXx.
the class CommandOptionSkilltree method onTabComplete.
@Override
public List<String> onTabComplete(CommandSender commandSender, String[] strings) {
if (strings.length == 2) {
return null;
}
if (strings.length == 3) {
Player player = Bukkit.getServer().getPlayer(strings[1]);
if (player == null || !player.isOnline()) {
return Collections.emptyList();
}
if (MyPetApi.getMyPetManager().hasActiveMyPet(player)) {
MyPet myPet = MyPetApi.getMyPetManager().getMyPet(player);
List<String> skilltreeList = new ArrayList<>();
for (Skilltree skilltree : MyPetApi.getSkilltreeManager().getSkilltrees()) {
if (skilltree.getMobTypes().contains(myPet.getPetType())) {
skilltreeList.add(skilltree.getName());
}
}
return filterTabCompletionResults(skilltreeList, strings[2]);
}
}
return Collections.emptyList();
}
use of de.Keyle.MyPet.api.skill.skilltree.Skilltree in project MyPet by xXKeyleXx.
the class CommandChooseSkilltree method onTabComplete.
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String s, String[] strings) {
if (sender instanceof Player) {
Player player = (Player) sender;
if (Permissions.has(player, "MyPet.admin", false)) {
if (MyPetApi.getMyPetManager().hasActiveMyPet(player)) {
MyPet myPet = MyPetApi.getMyPetManager().getMyPet(player);
List<String> skilltreeList = new ArrayList<>();
for (Skilltree skilltree : MyPetApi.getSkilltreeManager().getOrderedSkilltrees()) {
if (skilltree.getMobTypes().contains(myPet.getPetType()) && skilltree.checkRequirements(myPet)) {
skilltreeList.add(skilltree.getName());
}
}
return filterTabCompletionResults(skilltreeList, strings[0]);
}
}
}
return Collections.emptyList();
}
use of de.Keyle.MyPet.api.skill.skilltree.Skilltree in project MyPet by xXKeyleXx.
the class MySqlRepository method resultSetToMyPet.
// Pets ------------------------------------------------------------------------------------------------------------
private List<StoredMyPet> resultSetToMyPet(MyPetPlayer owner, ResultSet resultSet) {
List<StoredMyPet> pets = new ArrayList<>();
try {
while (resultSet.next()) {
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(Util.toString(resultSet.getBinaryStream("name"), StandardCharsets.UTF_8));
pet.setPetType(MyPetType.valueOf(resultSet.getString("type")));
pet.setLastUsed(resultSet.getLong("last_used"));
pet.setSaturation(resultSet.getDouble("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);
}
}
try {
pet.setSkills(TagStream.readTag(resultSet.getBlob("skills").getBinaryStream(), true));
} catch (ZipException exception) {
MyPetApi.getMyPetLogger().warning("Pet skills of player \"" + pet.getOwner().getName() + "\" (" + pet.getPetName() + ") could not be loaded!");
}
try {
pet.setInfo(TagStream.readTag(resultSet.getBlob("info").getBinaryStream(), true));
} catch (ZipException exception) {
MyPetApi.getMyPetLogger().warning("Pet info of player \"" + pet.getOwner().getName() + "\" (" + pet.getPetName() + ") could not be loaded!");
}
List<RepositoryMyPetConverterService> converters = MyPetApi.getServiceManager().getServices(RepositoryMyPetConverterService.class);
for (RepositoryMyPetConverterService converter : converters) {
converter.convert(pet);
}
pets.add(pet);
}
} catch (SQLException | IOException e) {
e.printStackTrace();
}
return pets;
}
Aggregations