Search in sources :

Example 26 with MyPetPlayer

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;
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) InactiveMyPet(de.Keyle.MyPet.entity.InactiveMyPet) TagCompound(de.keyle.knbt.TagCompound) StoredMyPet(de.Keyle.MyPet.api.entity.StoredMyPet)

Example 27 with MyPetPlayer

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;
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) JSONObject(org.json.simple.JSONObject) IOException(java.io.IOException)

Example 28 with MyPetPlayer

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();
        }
    }
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) JSONObject(org.json.simple.JSONObject) IOException(java.io.IOException)

Example 29 with MyPetPlayer

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()));
        }
    }
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 30 with MyPetPlayer

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()));
        }
    }
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) EventHandler(org.bukkit.event.EventHandler)

Aggregations

MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)46 EventHandler (org.bukkit.event.EventHandler)19 MyPet (de.Keyle.MyPet.api.entity.MyPet)17 Player (org.bukkit.entity.Player)16 StoredMyPet (de.Keyle.MyPet.api.entity.StoredMyPet)14 InactiveMyPet (de.Keyle.MyPet.entity.InactiveMyPet)8 WorldGroup (de.Keyle.MyPet.api.WorldGroup)7 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)6 TagCompound (de.keyle.knbt.TagCompound)5 List (java.util.List)5 UUID (java.util.UUID)4 Optional (com.google.common.base.Optional)3 RepositoryCallback (de.Keyle.MyPet.api.repository.RepositoryCallback)3 SkillTreeMobType (de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType)3 SqLiteRepository (de.Keyle.MyPet.repository.types.SqLiteRepository)3 MyPetPlayerImpl (de.Keyle.MyPet.util.player.MyPetPlayerImpl)3 FancyMessage (de.keyle.fanciful.FancyMessage)3 IOException (java.io.IOException)3 MyPetSaveEvent (de.Keyle.MyPet.api.event.MyPetSaveEvent)2 ConfigItem (de.Keyle.MyPet.api.util.ConfigItem)2