use of de.Keyle.MyPet.entity.InactiveMyPet in project MyPet by xXKeyleXx.
the class MyPetManager method getInactiveMyPetFromMyPet.
// Inactive -----------------------------------------------------------------
public StoredMyPet getInactiveMyPetFromMyPet(StoredMyPet myPet) {
InactiveMyPet inactiveMyPet = new InactiveMyPet(myPet.getOwner());
inactiveMyPet.setUUID(myPet.getUUID());
inactiveMyPet.setPetName(myPet.getPetName());
inactiveMyPet.setWorldGroup(myPet.getWorldGroup());
inactiveMyPet.setExp(myPet.getExp());
inactiveMyPet.setHealth(myPet.getHealth());
inactiveMyPet.setSaturation(myPet.getSaturation());
inactiveMyPet.setRespawnTime(myPet.getRespawnTime());
inactiveMyPet.setSkills(myPet.getSkillInfo());
inactiveMyPet.setInfo(myPet.getInfo());
inactiveMyPet.setPetType(myPet.getPetType());
inactiveMyPet.setSkilltree(myPet.getSkilltree());
inactiveMyPet.setLastUsed(myPet.getLastUsed());
inactiveMyPet.wantsToRespawn = myPet.wantsToRespawn();
return inactiveMyPet;
}
use of de.Keyle.MyPet.entity.InactiveMyPet 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.entity.InactiveMyPet in project MyPet by xXKeyleXx.
the class NbtRepository method getMyPets.
@Override
public void getMyPets(final MyPetPlayer owner, final RepositoryCallback<List<StoredMyPet>> callback) {
if (callback != null) {
List<StoredMyPet> petList = new ArrayList<>();
for (UUID petUUID : petPlayerMultiMap.get(owner.getInternalUUID())) {
if (petTags.containsKey(petUUID)) {
InactiveMyPet myPet = new InactiveMyPet(owner);
myPet.load(petTags.get(petUUID));
List<RepositoryMyPetConverterService> converters = MyPetApi.getServiceManager().getServices(RepositoryMyPetConverterService.class);
for (RepositoryMyPetConverterService converter : converters) {
converter.convert(myPet);
}
petList.add(myPet);
}
}
callback.run(petList);
}
}
use of de.Keyle.MyPet.entity.InactiveMyPet in project MyPet by xXKeyleXx.
the class NbtRepository method getMyPet.
@Override
public void getMyPet(final UUID uuid, final RepositoryCallback<StoredMyPet> callback) {
if (callback != null) {
if (petTags.containsKey(uuid)) {
TagCompound petTag = petTags.get(uuid);
UUID ownerUUID;
if (petTag.containsKeyAs("Internal-Owner-UUID", TagString.class)) {
ownerUUID = UUID.fromString(petTag.getAs("Internal-Owner-UUID", TagString.class).getStringData());
} else {
return;
}
if (!playerTags.containsKey(ownerUUID)) {
return;
}
MyPetPlayer owner = MyPetApi.getPlayerManager().getMyPetPlayer(ownerUUID);
if (owner != null) {
InactiveMyPet myPet = new InactiveMyPet(owner);
myPet.load(petTag);
List<RepositoryMyPetConverterService> converters = MyPetApi.getServiceManager().getServices(RepositoryMyPetConverterService.class);
for (RepositoryMyPetConverterService converter : converters) {
converter.convert(myPet);
}
callback.run(myPet);
}
}
}
}
use of de.Keyle.MyPet.entity.InactiveMyPet 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