Search in sources :

Example 1 with WChest

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();
        }
    });
}
Also used : Material(org.bukkit.Material) WChest(com.bgsoftware.wildchests.objects.chests.WChest) Location(org.bukkit.Location)

Example 2 with WChest

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();
}
Also used : ChestData(com.bgsoftware.wildchests.api.objects.data.ChestData) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) UUID(java.util.UUID) WChest(com.bgsoftware.wildchests.objects.chests.WChest) File(java.io.File) SQLException(java.sql.SQLException) IOException(java.io.IOException) Location(org.bukkit.Location)

Example 3 with WChest

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.");
            }
        }
    }
}
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)

Example 4 with WChest

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);
    }
}
Also used : TileEntity(net.minecraft.server.v1_16_R3.TileEntity) BlockPosition(net.minecraft.server.v1_16_R3.BlockPosition) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) World(net.minecraft.server.v1_16_R3.World) WChest(com.bgsoftware.wildchests.objects.chests.WChest) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) Location(org.bukkit.Location)

Example 5 with WChest

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);
}
Also used : TileEntity(net.minecraft.server.v1_8_R3.TileEntity) BlockPosition(net.minecraft.server.v1_8_R3.BlockPosition) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld) World(net.minecraft.server.v1_8_R3.World) WChest(com.bgsoftware.wildchests.objects.chests.WChest) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld) Location(org.bukkit.Location)

Aggregations

WChest (com.bgsoftware.wildchests.objects.chests.WChest)10 Location (org.bukkit.Location)8 LinkedChest (com.bgsoftware.wildchests.api.objects.chests.LinkedChest)3 StorageChest (com.bgsoftware.wildchests.api.objects.chests.StorageChest)3 ChestData (com.bgsoftware.wildchests.api.objects.data.ChestData)3 WLinkedChest (com.bgsoftware.wildchests.objects.chests.WLinkedChest)3 WRegularChest (com.bgsoftware.wildchests.objects.chests.WRegularChest)3 WStorageChest (com.bgsoftware.wildchests.objects.chests.WStorageChest)3 UUID (java.util.UUID)3 Chest (com.bgsoftware.wildchests.api.objects.chests.Chest)2 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 Chunk (org.bukkit.Chunk)2 Material (org.bukkit.Material)2 WildChestsPlugin (com.bgsoftware.wildchests.WildChestsPlugin)1 ChestsManager (com.bgsoftware.wildchests.api.handlers.ChestsManager)1 RegularChest (com.bgsoftware.wildchests.api.objects.chests.RegularChest)1 WChestData (com.bgsoftware.wildchests.objects.data.WChestData)1 ChunkPosition (com.bgsoftware.wildchests.utils.ChunkPosition)1