use of de.Keyle.MyPet.api.player.MyPetPlayer in project MyPet by xXKeyleXx.
the class NbtRepository method getMyPetPlayer.
@Override
public void getMyPetPlayer(final Player player, final RepositoryCallback<MyPetPlayer> callback) {
if (callback != null) {
for (TagCompound playerTag : playerTags.values()) {
if (playerTag.containsKeyAs("UUID", TagCompound.class)) {
TagCompound uuidTag = playerTag.getAs("UUID", TagCompound.class);
if (uuidTag.getCompoundData().containsKey("Mojang-UUID")) {
if (UUID.fromString(uuidTag.getAs("Mojang-UUID", TagString.class).getStringData()).equals(player.getUniqueId())) {
MyPetPlayer myPetPlayer = createMyPetPlayer(playerTag);
callback.run(myPetPlayer);
return;
}
}
if (uuidTag.getCompoundData().containsKey("Name")) {
if (uuidTag.getAs("Name", TagString.class).getStringData().equals(player.getName())) {
MyPetPlayer myPetPlayer = createMyPetPlayer(playerTag);
callback.run(myPetPlayer);
return;
}
}
if (playerTag.getCompoundData().containsKey("Name")) {
if (playerTag.getAs("Name", TagString.class).getStringData().equals(player.getName())) {
MyPetPlayer myPetPlayer = createMyPetPlayer(playerTag);
callback.run(myPetPlayer);
return;
}
}
}
}
}
}
use of de.Keyle.MyPet.api.player.MyPetPlayer 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);
Optional<RepositoryMyPetConverterService> converter = MyPetApi.getServiceManager().getService(RepositoryMyPetConverterService.class);
if (converter.isPresent()) {
converter.get().convert(myPet);
}
callback.run(myPet);
}
}
}
}
use of de.Keyle.MyPet.api.player.MyPetPlayer in project MyPet by xXKeyleXx.
the class SqLiteRepository method getAllMyPetPlayers.
@Override
public List<MyPetPlayer> getAllMyPetPlayers() {
try {
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * FROM players;");
List<MyPetPlayer> players = new ArrayList<>();
MyPetPlayer player;
while (true) {
player = resultSetToMyPetPlayer(resultSet);
if (player == null) {
break;
}
players.add(player);
}
return players;
} catch (SQLException e) {
e.printStackTrace();
}
return new ArrayList<>();
}
use of de.Keyle.MyPet.api.player.MyPetPlayer 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.player.MyPetPlayer in project MyPet by xXKeyleXx.
the class MinigamesHook method onSpectateMinigame.
@EventHandler
public void onSpectateMinigame(SpectateMinigameEvent event) {
if (MyPetApi.getPlayerManager().isMyPetPlayer(event.getPlayer())) {
MyPetPlayer player = MyPetApi.getPlayerManager().getMyPetPlayer(event.getPlayer());
if (player.hasMyPet() && player.getMyPet().getStatus() == MyPet.PetState.Here) {
player.getMyPet().removePet();
player.getPlayer().sendMessage(Translation.getString("Message.No.AllowedHere", player.getPlayer()));
}
}
}
Aggregations