use of de.Keyle.MyPet.util.player.MyPetPlayerImpl in project MyPet by xXKeyleXx.
the class MongoDbRepository method documentToPlayer.
// Players ---------------------------------------------------------------------------------------------------------
private MyPetPlayer documentToPlayer(Document document) {
try {
MyPetPlayerImpl petPlayer;
UUID internalUUID = UUID.fromString(document.getString("internal_uuid"));
String playerName = document.getString("name");
// raw "get" fixes wrong data type
UUID mojangUUID = document.get("mojang_uuid") != null ? UUID.fromString("" + document.get("mojang_uuid")) : null;
if (mojangUUID != null) {
petPlayer = new MyPetPlayerImpl(internalUUID, mojangUUID);
petPlayer.setLastKnownName(playerName);
} else if (playerName != null) {
petPlayer = new MyPetPlayerImpl(internalUUID, playerName);
} else {
MyPetApi.getLogger().warning("Player with no UUID or name found!");
return null;
}
try {
petPlayer.setExtendedInfo(TagStream.readTag(((Binary) document.get("extended_info")).getData(), true));
} catch (ZipException exception) {
MyPetApi.getMyPetLogger().warning("Extended info of player \"" + playerName + "\" (" + mojangUUID + ") could not be loaded!");
}
Document jsonObject = (Document) document.get("multi_world");
for (Object o : jsonObject.keySet()) {
String petUUID = jsonObject.get(o.toString()).toString();
petPlayer.setMyPetForWorldGroup(o.toString(), UUID.fromString(petUUID));
}
if (document.containsKey("settings")) {
document = (Document) document.get("settings");
}
petPlayer.setAutoRespawnEnabled(document.getBoolean("auto_respawn"));
petPlayer.setAutoRespawnMin(document.getInteger("auto_respawn_min"));
petPlayer.setCaptureHelperActive(document.getBoolean("capture_mode"));
petPlayer.setHealthBarActive(document.getBoolean("health_bar"));
petPlayer.setPetLivingSoundVolume(document.getDouble("pet_idle_volume").floatValue());
return petPlayer;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
use of de.Keyle.MyPet.util.player.MyPetPlayerImpl in project MyPet by xXKeyleXx.
the class MySqlRepository method resultSetToMyPetPlayer.
// Players ---------------------------------------------------------------------------------------------------------
private MyPetPlayer resultSetToMyPetPlayer(ResultSet resultSet) {
try {
if (resultSet.next()) {
MyPetPlayerImpl petPlayer;
UUID internalUUID = UUID.fromString(resultSet.getString("internal_uuid"));
String playerName = resultSet.getString("name");
UUID mojangUUID = resultSet.getString("mojang_uuid") != null ? UUID.fromString(resultSet.getString("mojang_uuid")) : null;
if (mojangUUID != null) {
petPlayer = new MyPetPlayerImpl(internalUUID, mojangUUID);
petPlayer.setLastKnownName(playerName);
} else if (playerName != null) {
petPlayer = new MyPetPlayerImpl(internalUUID, playerName);
} else {
MyPetApi.getLogger().warning("Player with no UUID or name found!");
return null;
}
petPlayer.setAutoRespawnEnabled(resultSet.getBoolean("auto_respawn"));
petPlayer.setAutoRespawnMin(resultSet.getInt("auto_respawn_min"));
petPlayer.setCaptureHelperActive(resultSet.getBoolean("capture_mode"));
petPlayer.setHealthBarActive(resultSet.getBoolean("health_bar"));
petPlayer.setPetLivingSoundVolume(resultSet.getFloat("pet_idle_volume"));
try {
petPlayer.setExtendedInfo(TagStream.readTag(resultSet.getBlob("extended_info").getBinaryStream(), true));
} catch (ZipException exception) {
MyPetApi.getMyPetLogger().warning("Extended info of player \"" + playerName + "\" (" + mojangUUID + ") could not be loaded!");
}
ResultSetMetaData metaData = resultSet.getMetaData();
int column = resultSet.findColumn("multi_world");
switch(metaData.getColumnTypeName(column)) {
case "BLOB":
try {
TagCompound worldGroups = TagStream.readTag(resultSet.getBlob(column).getBinaryStream(), true);
for (String worldGroupName : worldGroups.getCompoundData().keySet()) {
String petUUID = worldGroups.getAs(worldGroupName, TagString.class).getStringData();
petPlayer.setMyPetForWorldGroup(worldGroupName, UUID.fromString(petUUID));
}
} catch (ZipException exception) {
MyPetApi.getMyPetLogger().warning("Multiworld info of player \"" + playerName + "\" (" + mojangUUID + ") could not be loaded!");
}
break;
case "VARCHAR":
try {
JsonObject jsonObject = gson.fromJson(resultSet.getString(column), JsonObject.class);
for (String uuid : jsonObject.keySet()) {
String petUUID = jsonObject.get(uuid).getAsString();
petPlayer.setMyPetForWorldGroup(uuid, UUID.fromString(petUUID));
}
} catch (JsonParseException e) {
e.printStackTrace();
}
}
return petPlayer;
}
} catch (SQLException | IOException e) {
e.printStackTrace();
}
return null;
}
Aggregations