use of com.bgsoftware.wildchests.objects.chests.WChest in project WildChests by BG-Software-LLC.
the class ChunksListener method handleChunkLoad.
public static void handleChunkLoad(WildChestsPlugin plugin, Chunk chunk) {
plugin.getChestsManager().getChests(chunk).forEach(chest -> {
Location location = chest.getLocation();
Material blockType = location.getBlock().getType();
if (blockType != Material.CHEST) {
WildChestsPlugin.log("Loading chunk " + chunk.getX() + ", " + chunk.getX() + " but found a chest not " + "associated with a chest block but " + blockType + " at " + location.getWorld().getName() + ", " + location.getBlockX() + ", " + location.getBlockY() + ", " + location.getBlockZ());
chest.remove();
} else {
((WChest) chest).onChunkLoad();
}
});
}
use of com.bgsoftware.wildchests.objects.chests.WChest in project WildChests by BG-Software-LLC.
the class DataHandler method loadOldDatabase.
private void loadOldDatabase() {
File dataFolder = new File(plugin.getDataFolder(), "data");
if (!dataFolder.exists())
return;
YamlConfiguration cfg;
for (File chestFile : dataFolder.listFiles()) {
try {
cfg = YamlConfiguration.loadConfiguration(chestFile);
UUID placer = UUID.fromString(cfg.getString("placer"));
Location location = LocationUtils.fromString(chestFile.getName().replace(".yml", ""));
ChestData chestData = plugin.getChestsManager().getChestData(cfg.getString("data"));
WChest chest = (WChest) plugin.getChestsManager().addChest(placer, location, chestData);
chest.loadFromFile(cfg);
chestFile.delete();
} catch (Exception ex) {
WildChestsPlugin.log("Looks like the file " + chestFile.getName() + " is corrupted. Creating a backup file...");
File backupFile = new File(plugin.getDataFolder(), "data-backup/" + chestFile.getName());
copyFiles(chestFile, backupFile);
ex.printStackTrace();
}
}
if (dataFolder.listFiles().length == 0)
dataFolder.delete();
}
use of com.bgsoftware.wildchests.objects.chests.WChest 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.WChest in project WildChests by BG-Software-LLC.
the class NMSInventory_v1_16_R3 method updateTileEntity.
@Override
public void updateTileEntity(Chest chest) {
Location loc = chest.getLocation();
World world = ((CraftWorld) loc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
TileEntity tileEntity = world.getTileEntity(blockPosition);
TileEntityWildChest tileEntityWildChest;
if (tileEntity instanceof TileEntityWildChest) {
tileEntityWildChest = (TileEntityWildChest) tileEntity;
((WChest) chest).setTileEntityContainer(tileEntityWildChest);
} else {
tileEntityWildChest = new TileEntityWildChest(chest, world, blockPosition);
world.removeTileEntity(blockPosition);
world.setTileEntity(blockPosition, tileEntityWildChest);
}
}
use of com.bgsoftware.wildchests.objects.chests.WChest in project WildChests by BG-Software-LLC.
the class NMSInventory_v1_8_R3 method updateTileEntity.
@Override
public void updateTileEntity(Chest chest) {
Location loc = chest.getLocation();
World world = ((CraftWorld) loc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
TileEntity tileEntity = world.getTileEntity(blockPosition);
TileEntityWildChest tileEntityWildChest;
if (tileEntity instanceof TileEntityWildChest) {
tileEntityWildChest = (TileEntityWildChest) tileEntity;
((WChest) chest).setTileEntityContainer(tileEntityWildChest);
} else {
tileEntityWildChest = new TileEntityWildChest(chest, world, blockPosition);
}
world.setTileEntity(blockPosition, tileEntityWildChest);
}
Aggregations