diff --git a/src/main/java/com/songoda/skyblock/command/commands/admin/UpgradeCommand.java b/src/main/java/com/songoda/skyblock/command/commands/admin/UpgradeCommand.java index d920abd5..72b657f0 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/admin/UpgradeCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/admin/UpgradeCommand.java @@ -25,7 +25,7 @@ public class UpgradeCommand extends SubCommand { Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml")); FileConfiguration configLoad = config.getFileConfiguration(); - + if (skyblock.getUpgradeManager() == null) { messageManager.sendMessage(player, configLoad.getString("Command.Island.Admin.Upgrade.Disabled.Message")); soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F); diff --git a/src/main/java/com/songoda/skyblock/config/FileManager.java b/src/main/java/com/songoda/skyblock/config/FileManager.java index 5729aac4..0ddf9abe 100644 --- a/src/main/java/com/songoda/skyblock/config/FileManager.java +++ b/src/main/java/com/songoda/skyblock/config/FileManager.java @@ -5,15 +5,16 @@ import com.songoda.skyblock.SkyBlock; import com.songoda.skyblock.island.IslandWorld; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import java.io.*; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Map.Entry; import java.util.logging.Level; public class FileManager { @@ -31,13 +32,18 @@ public class FileManager { if (!skyblock.getDataFolder().exists()) { skyblock.getDataFolder().mkdir(); } + + File structureDirectory = new File(skyblock.getDataFolder().toString() + "/structures"); - if (!new File(skyblock.getDataFolder().toString() + "/structures").exists()) { - new File(skyblock.getDataFolder().toString() + "/structures").mkdir(); + if (!structureDirectory.exists()) { + structureDirectory.mkdir(); } + + // Will remain null unless WorldEdit is present. + File schematicsDirectory = null; - if (Bukkit.getPluginManager().isPluginEnabled("WorldEdit") && !new File(skyblock.getDataFolder().toString() + "/schematics").exists()) { - new File(skyblock.getDataFolder().toString() + "/schematics").mkdir(); + if (Bukkit.getPluginManager().isPluginEnabled("WorldEdit") && !(schematicsDirectory = new File(skyblock.getDataFolder().toString() + "/schematics")).exists()) { + schematicsDirectory.mkdir(); } Map configFiles = new LinkedHashMap<>(); @@ -53,19 +59,40 @@ public class FileManager { configFiles.put("structures.yml", new File(skyblock.getDataFolder(), "structures.yml")); configFiles.put("structures/default.structure", new File(skyblock.getDataFolder().toString() + "/structures", "default.structure")); + + File oldStructureFile = new File(skyblock.getDataFolder().toString() + "/structures", "default.structure"); + oldStructureFile.delete(); - for (String configFileList : configFiles.keySet()) { - File configFile = configFiles.get(configFileList); + for (Entry configEntry : configFiles.entrySet()) { + + String fileName = configEntry.getKey(); + File configFile = configEntry.getValue(); + + if (fileName.equals("structures/default.structure")) { + configFile.delete(); + try { + configFile.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + try (InputStream is = skyblock.getResource(fileName); + OutputStream os = new FileOutputStream(configFile)) { + ByteStreams.copy(is, os); + } catch (IOException e) { + e.printStackTrace(); + } + continue; + } if (configFile.exists()) { - if (configFileList.equals("config.yml") || configFileList.equals("language.yml") - || configFileList.equals("settings.yml")) { + if (fileName.equals("config.yml") || fileName.equals("language.yml") + || fileName.equals("settings.yml")) { FileChecker fileChecker; - if (configFileList.equals("config.yml")) { - fileChecker = new FileChecker(skyblock, this, configFileList, true); + if (fileName.equals("config.yml")) { + fileChecker = new FileChecker(skyblock, this, fileName, true); } else { - fileChecker = new FileChecker(skyblock, this, configFileList, false); + fileChecker = new FileChecker(skyblock, this, fileName, false); } fileChecker.loadSections(); @@ -75,13 +102,13 @@ public class FileManager { } else { try { configFile.createNewFile(); - try (InputStream is = skyblock.getResource(configFileList); + try (InputStream is = skyblock.getResource(fileName); OutputStream os = new FileOutputStream(configFile)) { ByteStreams.copy(is, os); } - if (configFileList.equals("worlds.yml")) { - File mainConfigFile = new File(skyblock.getDataFolder(), "config.yml"); + if (fileName.equals("worlds.yml")) { + File mainConfigFile = configFiles.get("config.yml"); if (isFileExist(mainConfigFile)) { Config config = new Config(this, configFile); @@ -116,54 +143,46 @@ public class FileManager { } public void setLocation(Config config, String path, Location location, boolean direction) { - File configFile = config.getFile(); - FileConfiguration configLoad = config.getFileConfiguration(); - configLoad.set(path + ".world", location.getWorld().getName()); - configLoad.set(path + ".x", Double.valueOf(location.getX())); - configLoad.set(path + ".y", Double.valueOf(location.getY())); - configLoad.set(path + ".z", Double.valueOf(location.getZ())); + final ConfigurationSection section = config.getFileConfiguration().createSection(path); + + section.set("world", location.getWorld().getName()); + section.set("x", Double.valueOf(location.getX())); + section.set("y", Double.valueOf(location.getY())); + section.set("z", Double.valueOf(location.getZ())); if (direction) { - configLoad.set(path + ".yaw", Float.valueOf(location.getYaw())); - configLoad.set(path + ".pitch", Float.valueOf(location.getPitch())); + section.set("yaw", Float.valueOf(location.getYaw())); + section.set("pitch", Float.valueOf(location.getPitch())); } try { - configLoad.save(configFile); + config.getFileConfiguration().save(config.getFile()); } catch (IOException ex) { ex.printStackTrace(); } } public Location getLocation(Config config, String path, boolean direction) { - Location location = null; - FileConfiguration configLoad = config.getFileConfiguration(); + ConfigurationSection section = config.getFileConfiguration().getConfigurationSection(path); - if (configLoad.contains(path)) { - String world = configLoad.getString(path + ".world"); + if (section == null) return null; - double x = configLoad.getDouble(path + ".x"); - double y = configLoad.getDouble(path + ".y"); - double z = configLoad.getDouble(path + ".z"); - double yaw = 0.0D; - double pitch = 0.0D; + String world = section.getString("world"); + double x = section.getDouble("x"); + double y = section.getDouble("y"); + double z = section.getDouble("z"); - if (configLoad.contains(path + ".yaw")) { - yaw = configLoad.getDouble(path + ".yaw"); - pitch = configLoad.getDouble(path + ".pitch"); - } + double yaw = 0.0D; + double pitch = 0.0D; - location = new org.bukkit.Location(Bukkit.getWorld(world), x, y, z); - - if (direction) { - location.setYaw((float) yaw); - location.setPitch((float) pitch); - } + if (direction) { + yaw = section.getDouble("yaw"); + pitch = section.getDouble("pitch"); } - return location; + return new org.bukkit.Location(Bukkit.getWorld(world), x, y, z, (short) yaw, (short) pitch); } public boolean isFileExist(File configPath) { @@ -181,9 +200,10 @@ public class FileManager { } public Config getConfig(File configPath) { - if (loadedConfigs.containsKey(configPath.getPath())) { - return loadedConfigs.get(configPath.getPath()); - } + + Config cached = loadedConfigs.get(configPath.getPath()); + + if (cached != null) return cached; Config config = new Config(this, configPath); loadedConfigs.put(configPath.getPath(), config); diff --git a/src/main/java/com/songoda/skyblock/island/IslandManager.java b/src/main/java/com/songoda/skyblock/island/IslandManager.java index 36d6c187..89765bc8 100644 --- a/src/main/java/com/songoda/skyblock/island/IslandManager.java +++ b/src/main/java/com/songoda/skyblock/island/IslandManager.java @@ -1276,7 +1276,7 @@ public class IslandManager { FileConfiguration configLoad = config.getFileConfiguration(); boolean coopPlayers = island.getSetting(IslandRole.Operator, "CoopPlayers").getStatus(); - + for (Player all : Bukkit.getOnlinePlayers()) { if (uuid != null && all.getUniqueId().equals(uuid)) { continue; @@ -1367,9 +1367,7 @@ public class IslandManager { public List getCoopIslands(Player player) { List islands = new ArrayList<>(); - for (UUID islandList : getIslands().keySet()) { - Island island = getIslands().get(islandList); - + for (Island island : getIslands().values()) { if (island.getCoopPlayers().containsKey(player.getUniqueId())) { islands.add(island); } @@ -1379,9 +1377,7 @@ public class IslandManager { } public Island getIslandAtLocation(org.bukkit.Location location) { - for (UUID islandList : getIslands().keySet()) { - Island island = getIslands().get(islandList); - + for (Island island : getIslands().values()) { if (isLocationAtIsland(island, location)) { return island; } diff --git a/src/main/java/com/songoda/skyblock/listeners/Block.java b/src/main/java/com/songoda/skyblock/listeners/Block.java index 9919e0ed..0b19c20f 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Block.java +++ b/src/main/java/com/songoda/skyblock/listeners/Block.java @@ -99,7 +99,7 @@ public class Block implements Listener { int droppedAmount = 0; if (event.getPlayer().isSneaking()) { - Location dropLoc = event.getBlock().getLocation().clone().add(0.5, 0.5, 0.5); + Location dropLoc = event.getBlock().getLocation().add(0.5, 0.5, 0.5); int count = stackable.getSize(); droppedAmount = count; while (count > 64) { @@ -110,7 +110,7 @@ public class Block implements Listener { block.setType(Material.AIR); stackable.setSize(0); } else { - block.getWorld().dropItemNaturally(block.getLocation().clone().add(.5, 1, .5), new ItemStack(material, 1, data)); + block.getWorld().dropItemNaturally(block.getLocation().add(.5, 1, .5), new ItemStack(material, 1, data)); stackable.takeOne(); droppedAmount = 1; } diff --git a/src/main/java/com/songoda/skyblock/listeners/Grow.java b/src/main/java/com/songoda/skyblock/listeners/Grow.java index c531e39f..22bbc4c9 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Grow.java +++ b/src/main/java/com/songoda/skyblock/listeners/Grow.java @@ -2,6 +2,7 @@ package com.songoda.skyblock.listeners; import java.io.File; import java.lang.reflect.InvocationTargetException; +import java.util.Iterator; import java.util.List; import org.bukkit.Material; @@ -46,19 +47,20 @@ public class Grow implements Listener { IslandManager islandManager = skyblock.getIslandManager(); Island origin = islandManager.getIslandAtLocation(event.getLocation()); - for (BlockState state : event.getBlocks()) { + for (Iterator it = event.getBlocks().iterator(); it.hasNext();) { + BlockState state = it.next(); Island growingTo = islandManager.getIslandAtLocation(state.getLocation()); // This block is ok to continue as it's not related to Skyblock islands. if (origin == null && growingTo == null) continue; // A block from the structure is outside/inside that it's not suppose to. if (origin == null || growingTo == null) { - event.getBlocks().remove(state); + it.remove(); continue; } // The structure is growing from one island to another. if (!origin.getIslandUUID().equals(growingTo.getIslandUUID())) { - event.getBlocks().remove(state); + it.remove(); continue; } } diff --git a/src/main/java/com/songoda/skyblock/menus/Coop.java b/src/main/java/com/songoda/skyblock/menus/Coop.java index 1f0cf999..60da1401 100644 --- a/src/main/java/com/songoda/skyblock/menus/Coop.java +++ b/src/main/java/com/songoda/skyblock/menus/Coop.java @@ -162,7 +162,13 @@ public class Coop { if ((island.hasRole(IslandRole.Operator, player.getUniqueId()) && island.getSetting(IslandRole.Operator, "CoopPlayers").getStatus()) || island.hasRole(IslandRole.Owner, player.getUniqueId())) { + String playerName = ChatColor.stripColor(is.getItemMeta().getDisplayName()); + + int space = playerName.indexOf(" "); + + if(space != -1) playerName = playerName.substring(0, space); + Bukkit.getServer().dispatchCommand(player, "island coop " + playerName); Bukkit.getServer().getScheduler().runTaskLater(skyblock, @@ -184,10 +190,7 @@ public class Coop { Island island = islandManager.getIsland(player); Map coopPlayers = island.getCoopPlayers(); - for (UUID uuid : coopPlayers.keySet()) - if (!Bukkit.getOfflinePlayer(uuid).hasPlayedBefore()) - coopPlayers.remove(uuid); - + int playerMenuPage = playerData.getPage(), nextEndIndex = coopPlayers.size() - playerMenuPage * 36; nInv.addItem(nInv.createItem(Materials.OAK_FENCE_GATE.parseItem(), diff --git a/src/main/java/com/songoda/skyblock/menus/Upgrade.java b/src/main/java/com/songoda/skyblock/menus/Upgrade.java index a12c01f9..8fda10de 100644 --- a/src/main/java/com/songoda/skyblock/menus/Upgrade.java +++ b/src/main/java/com/songoda/skyblock/menus/Upgrade.java @@ -379,6 +379,7 @@ public class Upgrade { economyManager.withdraw(player, upgrade.getCost()); island.setSize(upgrade.getValue()); + islandManager.updateBorder(island); Bukkit.getServer().getPluginManager().callEvent(new IslandUpgradeEvent( island.getAPIWrapper(), player, APIUtil.fromImplementation( diff --git a/src/main/java/com/songoda/skyblock/utils/structure/StructureUtil.java b/src/main/java/com/songoda/skyblock/utils/structure/StructureUtil.java index d1daaf8a..eac82b58 100644 --- a/src/main/java/com/songoda/skyblock/utils/structure/StructureUtil.java +++ b/src/main/java/com/songoda/skyblock/utils/structure/StructureUtil.java @@ -1,6 +1,8 @@ package com.songoda.skyblock.utils.structure; +import com.google.common.io.Files; import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; import com.google.gson.reflect.TypeToken; import com.songoda.skyblock.SkyBlock; import com.songoda.skyblock.config.FileManager; @@ -32,203 +34,221 @@ import java.util.ArrayList; import java.util.Base64; import java.util.LinkedHashMap; import java.util.List; +import java.util.logging.Level; public final class StructureUtil { - public static void saveStructure(File configFile, org.bukkit.Location originLocation, - org.bukkit.Location[] positions) throws Exception { - if (!configFile.exists()) { - configFile.createNewFile(); - } + public static void saveStructure(File configFile, org.bukkit.Location originLocation, + org.bukkit.Location[] positions) throws Exception { + if (!configFile.exists()) { + configFile.createNewFile(); + } - LinkedHashMap blocks = SelectionLocation.getBlocks(originLocation, positions[0], positions[1]); - LinkedHashMap entities = SelectionLocation.getEntities(originLocation, positions[0], - positions[1]); + LinkedHashMap blocks = SelectionLocation.getBlocks(originLocation, positions[0], positions[1]); + LinkedHashMap entities = SelectionLocation.getEntities(originLocation, positions[0], + positions[1]); - List blockData = new ArrayList<>(); - List entityData = new ArrayList<>(); + List blockData = new ArrayList<>(); + List entityData = new ArrayList<>(); - String originBlockLocation = ""; + String originBlockLocation = ""; - for (Block blockList : blocks.keySet()) { - Location location = blocks.get(blockList); + for (Block blockList : blocks.keySet()) { + Location location = blocks.get(blockList); - if (location.isOriginLocation()) { - originBlockLocation = location.getX() + ":" + location.getY() + ":" + location.getZ() + ":" - + positions[0].getWorld().getName(); + if (location.isOriginLocation()) { + originBlockLocation = location.getX() + ":" + location.getY() + ":" + location.getZ() + ":" + + positions[0].getWorld().getName(); - if (blockList.getType() == Material.AIR) { - blockData.add(BlockUtil.convertBlockToBlockData(blockList, location.getX(), location.getY(), - location.getZ())); - } - } + if (blockList.getType() == Material.AIR) { + blockData.add(BlockUtil.convertBlockToBlockData(blockList, location.getX(), location.getY(), + location.getZ())); + } + } - if (blockList.getType() == Material.AIR) { - continue; - } + if (blockList.getType() == Material.AIR) { + continue; + } - blockData.add( - BlockUtil.convertBlockToBlockData(blockList, location.getX(), location.getY(), location.getZ())); - } + blockData.add( + BlockUtil.convertBlockToBlockData(blockList, location.getX(), location.getY(), location.getZ())); + } - for (Entity entityList : entities.keySet()) { - if (entityList.getType() == EntityType.PLAYER) { - continue; - } + for (Entity entityList : entities.keySet()) { + if (entityList.getType() == EntityType.PLAYER) { + continue; + } - Location location = entities.get(entityList); - entityData.add(EntityUtil.convertEntityToEntityData(entityList, location.getX(), location.getY(), - location.getZ())); - } + Location location = entities.get(entityList); + entityData.add(EntityUtil.convertEntityToEntityData(entityList, location.getX(), location.getY(), + location.getZ())); + } - if (!originBlockLocation.isEmpty()) { - originBlockLocation = originBlockLocation + ":" + originLocation.getYaw() + ":" + originLocation.getPitch(); - } + if (!originBlockLocation.isEmpty()) { + originBlockLocation = originBlockLocation + ":" + originLocation.getYaw() + ":" + originLocation.getPitch(); + } - String JSONString = new Gson().toJson(new Storage(new Gson().toJson(blockData), new Gson().toJson(entityData), - originBlockLocation, System.currentTimeMillis(), NMSUtil.getVersionNumber()), Storage.class); + String JSONString = new Gson().toJson(new Storage(new Gson().toJson(blockData), new Gson().toJson(entityData), + originBlockLocation, System.currentTimeMillis(), NMSUtil.getVersionNumber()), Storage.class); - FileOutputStream fileOutputStream = new FileOutputStream(configFile, false); - fileOutputStream.write(Base64.getEncoder().encode(JSONString.getBytes(StandardCharsets.UTF_8))); - fileOutputStream.flush(); - fileOutputStream.close(); - } + FileOutputStream fileOutputStream = new FileOutputStream(configFile, false); + fileOutputStream.write(Base64.getEncoder().encode(JSONString.getBytes(StandardCharsets.UTF_8))); + fileOutputStream.flush(); + fileOutputStream.close(); + } - public static Structure loadStructure(File configFile) throws IOException { - if (!configFile.exists()) - return null; + private static String getBase64String(File file) { + if (!file.exists()) return null; - byte[] content = new byte[(int) configFile.length()]; + String firstLine = null; - FileInputStream fileInputStream = new FileInputStream(configFile); - fileInputStream.read(content); - fileInputStream.close(); + try { + firstLine = Files.asCharSource(file, StandardCharsets.UTF_8).readFirstLine(); + } catch (IOException e) { + e.printStackTrace(); + } - String json; - try { - json = Compression.decompress(content); - } catch (Exception e) { - Bukkit.getConsoleSender().sendMessage("Could not load structure '" + configFile.getName() + "' Try using the '/is admin structure tool' command to make a new schematic of it."); - File defaultStructure = new File(SkyBlock.getInstance().getDataFolder() + "/" + "structures", "default.structure"); - content = new byte[(int) defaultStructure.length()]; - fileInputStream = new FileInputStream(defaultStructure); - fileInputStream.read(content); - fileInputStream.close(); - json = Compression.decompress(content); - } + return firstLine; + } - Storage storage = new Gson().fromJson(json, Storage.class); - return new Structure(storage, configFile.getName()); - } + public static Structure loadStructure(File configFile) throws IOException { + String base64 = getBase64String(configFile); - @SuppressWarnings("unchecked") - public static Float[] pasteStructure(Structure structure, org.bukkit.Location location, BlockDegreesType type) { - Storage storage = structure.getStructureStorage(); + if (base64 == null) { + base64 = getBase64String( + new File(SkyBlock.getInstance().getDataFolder() + "/" + "structures", "default.structure")); + SkyBlock.getInstance().getLogger().log(Level.SEVERE, + "Unable to load structure '" + configFile.getAbsolutePath() + "' using default instead."); + } - String[] originLocationPositions = null; + if (base64 == null) { + throw new IllegalArgumentException("Couldn't load the default structure file."); + } - if (!storage.getOriginLocation().isEmpty()) { - originLocationPositions = storage.getOriginLocation().split(":"); - } + Storage storage; - float yaw = 0.0F, pitch = 0.0F; + try { + storage = new Gson().fromJson( + new String(Base64.getDecoder().decode(base64.getBytes(StandardCharsets.UTF_8))), Storage.class); + } catch (JsonSyntaxException e) { + e.printStackTrace(); + return null; + } - if (originLocationPositions.length == 6) { - yaw = Float.valueOf(originLocationPositions[4]); - pitch = Float.valueOf(originLocationPositions[5]); - } + return new Structure(storage, configFile.getName()); + } - List blockData = new Gson().fromJson(storage.getBlocks(), - new TypeToken>() { - }.getType()); + @SuppressWarnings("unchecked") + public static Float[] pasteStructure(Structure structure, org.bukkit.Location location, BlockDegreesType type) { + Storage storage = structure.getStructureStorage(); - for (BlockData blockDataList : blockData) { - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SkyBlock.getInstance(), () -> { - try { - org.bukkit.Location blockRotationLocation = LocationUtil - .rotateLocation(new org.bukkit.Location(location.getWorld(), blockDataList.getX(), - blockDataList.getY(), blockDataList.getZ()), type); - org.bukkit.Location blockLocation = new org.bukkit.Location(location.getWorld(), - location.getX() - Math.abs(Integer.valueOf(storage.getOriginLocation().split(":")[0])), - location.getY() - Integer.valueOf(storage.getOriginLocation().split(":")[1]), - location.getZ() + Math.abs(Integer.valueOf(storage.getOriginLocation().split(":")[2]))); - blockLocation.add(blockRotationLocation); - BlockUtil.convertBlockDataToBlock(blockLocation.getBlock(), blockDataList); - } catch (Exception e) { - SkyBlock.getInstance().getLogger().warning("Unable to convert BlockData to Block for type {" + blockDataList.getMaterial() + - ":" + blockDataList.getData() + "} in structure {" + structure.getStructureFile() + "}"); - } - }); - } + String[] originLocationPositions = null; - Bukkit.getScheduler().scheduleSyncDelayedTask(SkyBlock.getInstance(), () -> { - for (EntityData entityDataList : (List) new Gson().fromJson(storage.getEntities(), - new TypeToken>() { - }.getType())) { - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SkyBlock.getInstance(), () -> { - try { - org.bukkit.Location blockRotationLocation = LocationUtil - .rotateLocation(new org.bukkit.Location(location.getWorld(), entityDataList.getX(), - entityDataList.getY(), entityDataList.getZ()), type); - org.bukkit.Location blockLocation = new org.bukkit.Location(location.getWorld(), - location.getX() - Math.abs(Integer.valueOf(storage.getOriginLocation().split(":")[0])), - location.getY() - Integer.valueOf(storage.getOriginLocation().split(":")[1]), - location.getZ() + Math.abs(Integer.valueOf(storage.getOriginLocation().split(":")[2]))); - blockLocation.add(blockRotationLocation); - EntityUtil.convertEntityDataToEntity(entityDataList, blockLocation, type); - } catch (Exception e) { - SkyBlock.getInstance().getLogger().warning("Unable to convert EntityData to Entity for type {" + entityDataList.getEntityType() + - "} in structure {" + structure.getStructureFile() + "}"); - } - }); - } - }, 60L); + if (!storage.getOriginLocation().isEmpty()) { + originLocationPositions = storage.getOriginLocation().split(":"); + } - return new Float[]{yaw, pitch}; - } + float yaw = 0.0F, pitch = 0.0F; - public static ItemStack getTool() throws Exception { - SkyBlock skyblock = SkyBlock.getInstance(); + if (originLocationPositions.length == 6) { + yaw = Float.valueOf(originLocationPositions[4]); + pitch = Float.valueOf(originLocationPositions[5]); + } - FileManager fileManager = skyblock.getFileManager(); + List blockData = new Gson().fromJson(storage.getBlocks(), new TypeToken>() { + }.getType()); - FileManager.Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml")); - FileConfiguration configLoad = config.getFileConfiguration(); + for (BlockData blockDataList : blockData) { + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SkyBlock.getInstance(), () -> { + try { + org.bukkit.Location blockRotationLocation = LocationUtil + .rotateLocation(new org.bukkit.Location(location.getWorld(), blockDataList.getX(), + blockDataList.getY(), blockDataList.getZ()), type); + org.bukkit.Location blockLocation = new org.bukkit.Location(location.getWorld(), + location.getX() - Math.abs(Integer.valueOf(storage.getOriginLocation().split(":")[0])), + location.getY() - Integer.valueOf(storage.getOriginLocation().split(":")[1]), + location.getZ() + Math.abs(Integer.valueOf(storage.getOriginLocation().split(":")[2]))); + blockLocation.add(blockRotationLocation); + BlockUtil.convertBlockDataToBlock(blockLocation.getBlock(), blockDataList); + } catch (Exception e) { + SkyBlock.getInstance().getLogger() + .warning("Unable to convert BlockData to Block for type {" + blockDataList.getMaterial() + + ":" + blockDataList.getData() + "} in structure {" + structure.getStructureFile() + + "}"); + } + }); + } - ItemStack is = new ItemStack( - Material.valueOf(fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")) - .getFileConfiguration().getString("Island.Admin.Structure.Selector"))); - ItemMeta im = is.getItemMeta(); - im.setDisplayName(ChatColor.translateAlternateColorCodes('&', - configLoad.getString("Island.Structure.Tool.Item.Displayname"))); + Bukkit.getScheduler().scheduleSyncDelayedTask(SkyBlock.getInstance(), () -> { + for (EntityData entityDataList : (List) new Gson().fromJson(storage.getEntities(), + new TypeToken>() { + }.getType())) { + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SkyBlock.getInstance(), () -> { + try { + org.bukkit.Location blockRotationLocation = LocationUtil + .rotateLocation(new org.bukkit.Location(location.getWorld(), entityDataList.getX(), + entityDataList.getY(), entityDataList.getZ()), type); + org.bukkit.Location blockLocation = new org.bukkit.Location(location.getWorld(), + location.getX() - Math.abs(Integer.valueOf(storage.getOriginLocation().split(":")[0])), + location.getY() - Integer.valueOf(storage.getOriginLocation().split(":")[1]), + location.getZ() + Math.abs(Integer.valueOf(storage.getOriginLocation().split(":")[2]))); + blockLocation.add(blockRotationLocation); + EntityUtil.convertEntityDataToEntity(entityDataList, blockLocation, type); + } catch (Exception e) { + SkyBlock.getInstance().getLogger() + .warning("Unable to convert EntityData to Entity for type {" + + entityDataList.getEntityType() + "} in structure {" + + structure.getStructureFile() + "}"); + } + }); + } + }, 60L); - List itemLore = new ArrayList<>(); + return new Float[] { yaw, pitch }; + } - for (String itemLoreList : configLoad.getStringList("Island.Structure.Tool.Item.Lore")) { - itemLore.add(ChatColor.translateAlternateColorCodes('&', itemLoreList)); - } + public static ItemStack getTool() throws Exception { + SkyBlock skyblock = SkyBlock.getInstance(); - im.setLore(itemLore); - is.setItemMeta(im); + FileManager fileManager = skyblock.getFileManager(); - return is; - } + FileManager.Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml")); + FileConfiguration configLoad = config.getFileConfiguration(); - public static org.bukkit.Location[] getFixedLocations(org.bukkit.Location location1, - org.bukkit.Location location2) { - org.bukkit.Location location1Fixed = location1.clone(); - org.bukkit.Location location2Fixed = location2.clone(); + ItemStack is = new ItemStack( + Material.valueOf(fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")) + .getFileConfiguration().getString("Island.Admin.Structure.Selector"))); + ItemMeta im = is.getItemMeta(); + im.setDisplayName(ChatColor.translateAlternateColorCodes('&', + configLoad.getString("Island.Structure.Tool.Item.Displayname"))); - if (location1.getX() > location2.getX()) { - location1Fixed.setX(location2.getX()); - location2Fixed.setX(location1.getX()); - } + List itemLore = new ArrayList<>(); - if (location1.getZ() < location2.getZ()) { - location1Fixed.setZ(location2.getZ()); - location2Fixed.setZ(location1.getZ()); - } + for (String itemLoreList : configLoad.getStringList("Island.Structure.Tool.Item.Lore")) { + itemLore.add(ChatColor.translateAlternateColorCodes('&', itemLoreList)); + } - return new org.bukkit.Location[]{location1Fixed, location2Fixed}; - } + im.setLore(itemLore); + is.setItemMeta(im); + + return is; + } + + public static org.bukkit.Location[] getFixedLocations(org.bukkit.Location location1, + org.bukkit.Location location2) { + org.bukkit.Location location1Fixed = location1.clone(); + org.bukkit.Location location2Fixed = location2.clone(); + + if (location1.getX() > location2.getX()) { + location1Fixed.setX(location2.getX()); + location2Fixed.setX(location1.getX()); + } + + if (location1.getZ() < location2.getZ()) { + location1Fixed.setZ(location2.getZ()); + location2Fixed.setZ(location1.getZ()); + } + + return new org.bukkit.Location[] { location1Fixed, location2Fixed }; + } } diff --git a/src/main/resources/structures/default.structure b/src/main/resources/structures/default.structure index fc2652e3..c4836d54 100644 Binary files a/src/main/resources/structures/default.structure and b/src/main/resources/structures/default.structure differ