use of com.bgsoftware.wildchests.objects.chests.WLinkedChest 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.");
}
}
}
}
use of com.bgsoftware.wildchests.objects.chests.WLinkedChest in project WildChests by BG-Software-LLC.
the class ChestsHandler method loadChest.
public WChest loadChest(UUID placer, Location location, ChestData chestData) {
WChest chest;
switch(chestData.getChestType()) {
case CHEST:
chest = new WRegularChest(placer, location, chestData);
break;
case LINKED_CHEST:
chest = new WLinkedChest(placer, location, chestData);
break;
case STORAGE_UNIT:
chest = new WStorageChest(placer, location, chestData);
break;
default:
throw new IllegalArgumentException("Invalid chest at " + location);
}
chests.put(location, chest);
chestsByChunks.computeIfAbsent(ChunkPosition.of(location), s -> Sets.newConcurrentHashSet()).add(chest);
return chest;
}
Aggregations