use of de.Keyle.MyPet.api.player.MyPetPlayer in project MyPet by xXKeyleXx.
the class NbtRepository method getAllMyPets.
// Pets ------------------------------------------------------------------------------------------------------------
@Override
public List<StoredMyPet> getAllMyPets() {
List<MyPetPlayer> playerList = getAllMyPetPlayers();
Map<UUID, MyPetPlayer> owners = new HashMap<>();
for (MyPetPlayer player : playerList) {
owners.put(player.getInternalUUID(), player);
}
List<StoredMyPet> pets = new ArrayList<>();
for (UUID petUUID : petTags.keySet()) {
TagCompound petTag = petTags.get(petUUID);
if (petTag.containsKeyAs("Internal-Owner-UUID", TagString.class)) {
UUID ownerUUID = UUID.fromString(petTag.getAs("Internal-Owner-UUID", TagString.class).getStringData());
if (owners.containsKey(ownerUUID)) {
InactiveMyPet myPet = new InactiveMyPet(owners.get(ownerUUID));
myPet.load(petTag);
pets.add(myPet);
}
}
}
return pets;
}
use of de.Keyle.MyPet.api.player.MyPetPlayer in project MyPet by xXKeyleXx.
the class SqLiteRepository method addMyPetPlayers.
@SuppressWarnings("unchecked")
public boolean addMyPetPlayers(List<MyPetPlayer> players) {
try {
PreparedStatement statement = connection.prepareStatement("INSERT INTO players (" + "internal_uuid, " + "mojang_uuid, " + "name, " + "auto_respawn, " + "auto_respawn_min, " + "capture_mode, " + "health_bar, " + "pet_idle_volume, " + "extended_info, " + "multi_world) " + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
int i = 0;
HashSet<String> playerNames = new HashSet<>();
for (MyPetPlayer player : players) {
String playerName = player.getName();
if (playerNames.contains(playerName)) {
MyPetApi.getLogger().info("Found duplicate Player: " + player.toString());
continue;
}
playerNames.add(playerName);
statement.setString(1, player.getInternalUUID().toString());
statement.setString(2, player.getMojangUUID() != null ? player.getMojangUUID().toString() : null);
statement.setString(3, playerName);
statement.setBoolean(4, player.hasAutoRespawnEnabled());
statement.setInt(5, player.getAutoRespawnMin());
statement.setBoolean(6, false);
statement.setBoolean(7, player.isHealthBarActive());
statement.setFloat(8, player.getPetLivingSoundVolume());
statement.setBytes(9, TagStream.writeTag(player.getExtendedInfo(), true));
JSONObject multiWorldObject = new JSONObject();
for (String worldGroupName : player.getMyPetsForWorldGroups().keySet()) {
multiWorldObject.put(worldGroupName, player.getMyPetsForWorldGroups().get(worldGroupName).toString());
}
statement.setString(10, multiWorldObject.toJSONString());
statement.addBatch();
if (++i % 500 == 0 && i != players.size()) {
statement.executeBatch();
}
}
statement.executeBatch();
return true;
} catch (SQLException | IOException e) {
e.printStackTrace();
}
return false;
}
use of de.Keyle.MyPet.api.player.MyPetPlayer in project MyPet by xXKeyleXx.
the class SqLiteRepository method savePlayers.
@SuppressWarnings("unchecked")
private void savePlayers() {
for (MyPetPlayer player : MyPetApi.getPlayerManager().getMyPetPlayers()) {
try {
PreparedStatement statement = connection.prepareStatement("UPDATE players SET " + "mojang_uuid=?, " + "name=?, " + "auto_respawn=?, " + "auto_respawn_min=?, " + "capture_mode=?, " + "health_bar=?, " + "pet_idle_volume=?, " + "extended_info=?, " + "multi_world=? " + "WHERE internal_uuid=?;");
statement.setString(1, player.getMojangUUID() != null ? player.getMojangUUID().toString() : null);
statement.setString(2, player.getName());
statement.setBoolean(3, player.hasAutoRespawnEnabled());
statement.setInt(4, player.getAutoRespawnMin());
statement.setBoolean(5, false);
statement.setBoolean(6, player.isHealthBarActive());
statement.setFloat(7, player.getPetLivingSoundVolume());
statement.setBytes(8, TagStream.writeTag(player.getExtendedInfo(), true));
JSONObject multiWorldObject = new JSONObject();
for (String worldGroupName : player.getMyPetsForWorldGroups().keySet()) {
multiWorldObject.put(worldGroupName, player.getMyPetsForWorldGroups().get(worldGroupName).toString());
}
statement.setString(9, multiWorldObject.toJSONString());
statement.setString(10, player.getInternalUUID().toString());
int result = statement.executeUpdate();
// MyPetLogger.write("UPDATE player: " + result);
} catch (SQLException | IOException e) {
e.printStackTrace();
}
}
}
use of de.Keyle.MyPet.api.player.MyPetPlayer in project MyPet by xXKeyleXx.
the class BattleArenaHook method onJoinBattleArena.
@EventHandler
public void onJoinBattleArena(ArenaPlayerEnterEvent event) {
if (MyPetApi.getPlayerManager().isMyPetPlayer(event.getPlayer().getName())) {
MyPetPlayer player = MyPetApi.getPlayerManager().getMyPetPlayer(event.getPlayer().getPlayer());
if (player.hasMyPet() && player.getMyPet().getStatus() == MyPet.PetState.Here) {
player.getMyPet().removePet();
player.getPlayer().sendMessage(Translation.getString("Message.No.AllowedHere", player.getPlayer()));
}
}
}
use of de.Keyle.MyPet.api.player.MyPetPlayer in project MyPet by xXKeyleXx.
the class MinigamesHook method onJoinMinigame.
@EventHandler
public void onJoinMinigame(JoinMinigameEvent 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