use of de.Keyle.MyPet.api.skill.skilltree.Skilltree 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.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.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.Skilltree in project MyPet by xXKeyleXx.
the class LevelListener method on.
@EventHandler
public void on(MyPetLevelEvent event) {
if (event instanceof MyPetLevelUpEvent || event instanceof MyPetLevelDownEvent) {
return;
}
MyPet myPet = event.getPet();
int lvl = event.getLevel();
myPet.getSkills().all().forEach(Skill::reset);
Skilltree skilltree = myPet.getSkilltree();
if (skilltree != null) {
for (int i = 1; i <= lvl; i++) {
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);
}
}
}
}
}
}
use of de.Keyle.MyPet.api.skill.skilltree.Skilltree in project MyPet by xXKeyleXx.
the class LevelListener method on.
@EventHandler
public void on(MyPetLevelDownEvent event) {
MyPet myPet = event.getPet();
int lvl = event.getLevel();
int fromLvl = event.fromLevel();
if (!event.isQuiet()) {
myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.LevelSystem.LevelDown", event.getOwner()), myPet.getPetName(), event.getLevel()));
}
Skilltree skilltree = myPet.getSkilltree();
if (skilltree != null) {
for (int i = fromLvl; i > lvl; i--) {
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.invert(skill);
}
}
}
}
}
if (myPet.getStatus() == MyPet.PetState.Here) {
myPet.getEntity().ifPresent(entity -> {
entity.getHandle().updateNameTag();
if (!event.isQuiet()) {
myPet.setHealth(myPet.getMaxHealth());
myPet.setSaturation(100);
new FixedCircleAnimation(1, entity.getEyeHeight() + 0.5, 10, new EntityLocationHolder(entity)) {
@Override
protected void playParticleEffect(Location location) {
MyPetApi.getPlatformHelper().playParticleEffect(location, ParticleCompat.BLOCK_CRACK.get(), 0, 0, 0, 0, 1, 32, ParticleCompat.REDSTONE_BLOCK_DATA);
}
}.once();
entity.getWorld().playSound(entity.getLocation(), Sound.valueOf(SoundCompat.LEVEL_DOWN.get()), 1F, 0.7F);
}
});
}
}
use of de.Keyle.MyPet.api.skill.skilltree.Skilltree in project MyPet by xXKeyleXx.
the class MongoDbRepository method documentToMyPet.
// Pets ------------------------------------------------------------------------------------------------------------
private StoredMyPet documentToMyPet(MyPetPlayer owner, Document document) {
try {
InactiveMyPet pet = new InactiveMyPet(owner);
pet.setUUID(UUID.fromString(document.getString("uuid")));
pet.setWorldGroup(document.getString("world_group"));
pet.setExp(document.getDouble("exp"));
pet.setHealth(document.getDouble("health"));
pet.setRespawnTime(document.getInteger("respawn_time"));
pet.setPetName(document.getString("name"));
pet.setPetType(MyPetType.valueOf(document.getString("type")));
pet.setLastUsed(document.getLong("last_used"));
pet.setSaturation(((Number) document.get("hunger")).doubleValue());
pet.wantsToRespawn = document.getBoolean("wants_to_spawn");
String skillTreeName = document.getString("skilltree");
if (skillTreeName != null) {
Skilltree skilltree = MyPetApi.getSkilltreeManager().getSkilltree(skillTreeName);
if (skilltree != null) {
pet.setSkilltree(skilltree);
}
}
try {
pet.setSkills(TagStream.readTag(((Binary) document.get("skills")).getData(), 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(((Binary) document.get("info")).getData(), 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);
}
return pet;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
use of de.Keyle.MyPet.api.skill.skilltree.Skilltree in project MyPet by xXKeyleXx.
the class SkillTreeLoaderNBT method loadSkillTree.
protected void loadSkillTree(ConfigurationNBT nbtConfiguration, SkillTreeMobType skillTreeMobType) {
TagList skilltreeList = nbtConfiguration.getNBTCompound().getAs("Skilltrees", TagList.class);
for (int i_skilltree = 0; i_skilltree < skilltreeList.size(); i_skilltree++) {
TagCompound skilltreeCompound = skilltreeList.getTagAs(i_skilltree, TagCompound.class);
SkillTree skillTree = new SkillTree(skilltreeCompound.getAs("Name", TagString.class).getStringData());
int place = skilltreeCompound.getAs("Place", TagInt.class).getIntData();
if (skilltreeCompound.getCompoundData().containsKey("Inherits")) {
skillTree.setInheritance(skilltreeCompound.getAs("Inherits", TagString.class).getStringData());
}
if (skilltreeCompound.getCompoundData().containsKey("Permission")) {
skillTree.setPermission(skilltreeCompound.getAs("Permission", TagString.class).getStringData());
}
if (skilltreeCompound.getCompoundData().containsKey("Display")) {
skillTree.setDisplayName(skilltreeCompound.getAs("Display", TagString.class).getStringData());
}
if (skilltreeCompound.getCompoundData().containsKey("MaxLevel")) {
skillTree.setMaxLevel(skilltreeCompound.getAs("MaxLevel", TagInt.class).getIntData());
}
if (skilltreeCompound.getCompoundData().containsKey("RequiredLevel")) {
skillTree.setRequiredLevel(skilltreeCompound.getAs("RequiredLevel", TagInt.class).getIntData());
}
if (skilltreeCompound.getCompoundData().containsKey("IconItem")) {
skillTree.setIconItem(skilltreeCompound.getAs("IconItem", TagCompound.class));
}
if (skilltreeCompound.getCompoundData().containsKey("Description")) {
TagList descriptionTagList = skilltreeCompound.getAs("Description", TagList.class);
for (int i = 0; i < descriptionTagList.size(); i++) {
skillTree.addDescriptionLine(descriptionTagList.getTagAs(i, TagString.class).getStringData());
}
}
if (skilltreeCompound.getCompoundData().containsKey("Level")) {
TagList levelList = skilltreeCompound.getAs("Level", TagList.class);
for (int i_level = 0; i_level < levelList.size(); i_level++) {
TagCompound levelCompound = levelList.getTag(i_level);
int thisLevel;
if (levelCompound.containsKeyAs("Level", TagInt.class)) {
thisLevel = levelCompound.getAs("Level", TagInt.class).getIntData();
} else {
thisLevel = levelCompound.getAs("Level", TagShort.class).getShortData();
}
SkillTreeLevel newLevel = skillTree.addLevel(thisLevel);
if (levelCompound.getCompoundData().containsKey("Message")) {
String message = levelCompound.getAs("Message", TagString.class).getStringData();
newLevel.setLevelupMessage(message);
}
TagList skillList = levelCompound.get("Skills");
for (int i_skill = 0; i_skill < skillList.size(); i_skill++) {
TagCompound skillCompound = skillList.getTag(i_skill);
String skillName = skillCompound.getAs("Name", TagString.class).getStringData();
if (SkillsInfo.getSkillInfoClass(skillName) != null) {
TagCompound skillPropertyCompound = skillCompound.get("Properties");
SkillInfo skill = SkillsInfo.getNewSkillInfoInstance(skillName);
if (skill != null) {
skill.setProperties(skillPropertyCompound);
skill.setDefaultProperties();
skillTree.addSkillToLevel(thisLevel, skill);
}
}
}
}
}
skillTreeMobType.addSkillTree(skillTree, place);
}
}
Aggregations