Search in sources :

Example 1 with StorageChest

use of com.bgsoftware.wildchests.api.objects.chests.StorageChest in project WildChests by BG-Software-LLC.

the class DataHandler method loadResultSet.

private void loadResultSet(ResultSet resultSet, String tableName, List<Chest> updateContentsChests) throws SQLException {
    while (resultSet.next()) {
        UUID placer = UUID.fromString(resultSet.getString("placer"));
        String stringLocation = resultSet.getString("location");
        String errorMessage = null;
        try {
            if (Bukkit.getWorld(stringLocation.split(", ")[0]) == null) {
                errorMessage = "Null world.";
            } else {
                Location location = LocationUtils.fromString(stringLocation);
                ChestData chestData = plugin.getChestsManager().getChestData(resultSet.getString("chest_data"));
                WChest chest = plugin.getChestsManager().loadChest(placer, location, chestData);
                if (chest instanceof StorageChest) {
                    String item = resultSet.getString("item");
                    String amount = resultSet.getString("amount");
                    String maxAmount = resultSet.getString("max_amount");
                    ((WStorageChest) chest).loadFromData(item, amount, maxAmount);
                } else {
                    String serialized = resultSet.getString("inventories");
                    if (chest instanceof LinkedChest) {
                        String linkedChest = resultSet.getString("linked_chest");
                        ((WLinkedChest) chest).loadFromData(serialized, linkedChest);
                    } else {
                        ((WRegularChest) chest).loadFromData(serialized);
                    }
                    if (serialized.toCharArray()[0] != '*')
                        updateContentsChests.add(chest);
                }
            }
        } catch (Exception ex) {
            errorMessage = ex.getMessage();
        }
        if (errorMessage != null) {
            WildChestsPlugin.log("Couldn't load the location " + stringLocation);
            WildChestsPlugin.log(errorMessage);
            if (errorMessage.contains("Null") && plugin.getSettings().invalidWorldDelete) {
                SQLHelper.executeUpdate("DELETE FROM " + tableName + " WHERE location = '" + stringLocation + "';");
                WildChestsPlugin.log("Deleted spawner (" + stringLocation + ") from database.");
            }
        }
    }
}
Also used : ChestData(com.bgsoftware.wildchests.api.objects.data.ChestData) WLinkedChest(com.bgsoftware.wildchests.objects.chests.WLinkedChest) UUID(java.util.UUID) WChest(com.bgsoftware.wildchests.objects.chests.WChest) LinkedChest(com.bgsoftware.wildchests.api.objects.chests.LinkedChest) WLinkedChest(com.bgsoftware.wildchests.objects.chests.WLinkedChest) WRegularChest(com.bgsoftware.wildchests.objects.chests.WRegularChest) WStorageChest(com.bgsoftware.wildchests.objects.chests.WStorageChest) SQLException(java.sql.SQLException) IOException(java.io.IOException) Location(org.bukkit.Location) StorageChest(com.bgsoftware.wildchests.api.objects.chests.StorageChest) WStorageChest(com.bgsoftware.wildchests.objects.chests.WStorageChest)

Aggregations

LinkedChest (com.bgsoftware.wildchests.api.objects.chests.LinkedChest)1 StorageChest (com.bgsoftware.wildchests.api.objects.chests.StorageChest)1 ChestData (com.bgsoftware.wildchests.api.objects.data.ChestData)1 WChest (com.bgsoftware.wildchests.objects.chests.WChest)1 WLinkedChest (com.bgsoftware.wildchests.objects.chests.WLinkedChest)1 WRegularChest (com.bgsoftware.wildchests.objects.chests.WRegularChest)1 WStorageChest (com.bgsoftware.wildchests.objects.chests.WStorageChest)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 UUID (java.util.UUID)1 Location (org.bukkit.Location)1