This commit is contained in:
theone1000 2019-10-13 19:10:58 -06:00
parent 05059829d1
commit 46308e328f
9 changed files with 263 additions and 221 deletions

View File

@ -25,7 +25,7 @@ public class UpgradeCommand extends SubCommand {
Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml")); Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"));
FileConfiguration configLoad = config.getFileConfiguration(); FileConfiguration configLoad = config.getFileConfiguration();
if (skyblock.getUpgradeManager() == null) { if (skyblock.getUpgradeManager() == null) {
messageManager.sendMessage(player, configLoad.getString("Command.Island.Admin.Upgrade.Disabled.Message")); messageManager.sendMessage(player, configLoad.getString("Command.Island.Admin.Upgrade.Disabled.Message"));
soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F); soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F);

View File

@ -5,15 +5,16 @@ import com.songoda.skyblock.SkyBlock;
import com.songoda.skyblock.island.IslandWorld; import com.songoda.skyblock.island.IslandWorld;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import java.io.*; import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Level; import java.util.logging.Level;
public class FileManager { public class FileManager {
@ -31,13 +32,18 @@ public class FileManager {
if (!skyblock.getDataFolder().exists()) { if (!skyblock.getDataFolder().exists()) {
skyblock.getDataFolder().mkdir(); skyblock.getDataFolder().mkdir();
} }
File structureDirectory = new File(skyblock.getDataFolder().toString() + "/structures");
if (!new File(skyblock.getDataFolder().toString() + "/structures").exists()) { if (!structureDirectory.exists()) {
new File(skyblock.getDataFolder().toString() + "/structures").mkdir(); structureDirectory.mkdir();
} }
// Will remain null unless WorldEdit is present.
File schematicsDirectory = null;
if (Bukkit.getPluginManager().isPluginEnabled("WorldEdit") && !new File(skyblock.getDataFolder().toString() + "/schematics").exists()) { if (Bukkit.getPluginManager().isPluginEnabled("WorldEdit") && !(schematicsDirectory = new File(skyblock.getDataFolder().toString() + "/schematics")).exists()) {
new File(skyblock.getDataFolder().toString() + "/schematics").mkdir(); schematicsDirectory.mkdir();
} }
Map<String, File> configFiles = new LinkedHashMap<>(); Map<String, File> configFiles = new LinkedHashMap<>();
@ -53,19 +59,40 @@ public class FileManager {
configFiles.put("structures.yml", new File(skyblock.getDataFolder(), "structures.yml")); configFiles.put("structures.yml", new File(skyblock.getDataFolder(), "structures.yml"));
configFiles.put("structures/default.structure", configFiles.put("structures/default.structure",
new File(skyblock.getDataFolder().toString() + "/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()) { for (Entry<String, File> configEntry : configFiles.entrySet()) {
File configFile = configFiles.get(configFileList);
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 (configFile.exists()) {
if (configFileList.equals("config.yml") || configFileList.equals("language.yml") if (fileName.equals("config.yml") || fileName.equals("language.yml")
|| configFileList.equals("settings.yml")) { || fileName.equals("settings.yml")) {
FileChecker fileChecker; FileChecker fileChecker;
if (configFileList.equals("config.yml")) { if (fileName.equals("config.yml")) {
fileChecker = new FileChecker(skyblock, this, configFileList, true); fileChecker = new FileChecker(skyblock, this, fileName, true);
} else { } else {
fileChecker = new FileChecker(skyblock, this, configFileList, false); fileChecker = new FileChecker(skyblock, this, fileName, false);
} }
fileChecker.loadSections(); fileChecker.loadSections();
@ -75,13 +102,13 @@ public class FileManager {
} else { } else {
try { try {
configFile.createNewFile(); configFile.createNewFile();
try (InputStream is = skyblock.getResource(configFileList); try (InputStream is = skyblock.getResource(fileName);
OutputStream os = new FileOutputStream(configFile)) { OutputStream os = new FileOutputStream(configFile)) {
ByteStreams.copy(is, os); ByteStreams.copy(is, os);
} }
if (configFileList.equals("worlds.yml")) { if (fileName.equals("worlds.yml")) {
File mainConfigFile = new File(skyblock.getDataFolder(), "config.yml"); File mainConfigFile = configFiles.get("config.yml");
if (isFileExist(mainConfigFile)) { if (isFileExist(mainConfigFile)) {
Config config = new Config(this, configFile); Config config = new Config(this, configFile);
@ -116,54 +143,46 @@ public class FileManager {
} }
public void setLocation(Config config, String path, Location location, boolean direction) { 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()); final ConfigurationSection section = config.getFileConfiguration().createSection(path);
configLoad.set(path + ".x", Double.valueOf(location.getX()));
configLoad.set(path + ".y", Double.valueOf(location.getY())); section.set("world", location.getWorld().getName());
configLoad.set(path + ".z", Double.valueOf(location.getZ())); section.set("x", Double.valueOf(location.getX()));
section.set("y", Double.valueOf(location.getY()));
section.set("z", Double.valueOf(location.getZ()));
if (direction) { if (direction) {
configLoad.set(path + ".yaw", Float.valueOf(location.getYaw())); section.set("yaw", Float.valueOf(location.getYaw()));
configLoad.set(path + ".pitch", Float.valueOf(location.getPitch())); section.set("pitch", Float.valueOf(location.getPitch()));
} }
try { try {
configLoad.save(configFile); config.getFileConfiguration().save(config.getFile());
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
public Location getLocation(Config config, String path, boolean direction) { 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)) { if (section == null) return null;
String world = configLoad.getString(path + ".world");
double x = configLoad.getDouble(path + ".x"); String world = section.getString("world");
double y = configLoad.getDouble(path + ".y"); double x = section.getDouble("x");
double z = configLoad.getDouble(path + ".z"); double y = section.getDouble("y");
double yaw = 0.0D; double z = section.getDouble("z");
double pitch = 0.0D;
if (configLoad.contains(path + ".yaw")) { double yaw = 0.0D;
yaw = configLoad.getDouble(path + ".yaw"); double pitch = 0.0D;
pitch = configLoad.getDouble(path + ".pitch");
}
location = new org.bukkit.Location(Bukkit.getWorld(world), x, y, z); if (direction) {
yaw = section.getDouble("yaw");
if (direction) { pitch = section.getDouble("pitch");
location.setYaw((float) yaw);
location.setPitch((float) pitch);
}
} }
return location; return new org.bukkit.Location(Bukkit.getWorld(world), x, y, z, (short) yaw, (short) pitch);
} }
public boolean isFileExist(File configPath) { public boolean isFileExist(File configPath) {
@ -181,9 +200,10 @@ public class FileManager {
} }
public Config getConfig(File configPath) { 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); Config config = new Config(this, configPath);
loadedConfigs.put(configPath.getPath(), config); loadedConfigs.put(configPath.getPath(), config);

View File

@ -1276,7 +1276,7 @@ public class IslandManager {
FileConfiguration configLoad = config.getFileConfiguration(); FileConfiguration configLoad = config.getFileConfiguration();
boolean coopPlayers = island.getSetting(IslandRole.Operator, "CoopPlayers").getStatus(); boolean coopPlayers = island.getSetting(IslandRole.Operator, "CoopPlayers").getStatus();
for (Player all : Bukkit.getOnlinePlayers()) { for (Player all : Bukkit.getOnlinePlayers()) {
if (uuid != null && all.getUniqueId().equals(uuid)) { if (uuid != null && all.getUniqueId().equals(uuid)) {
continue; continue;
@ -1367,9 +1367,7 @@ public class IslandManager {
public List<Island> getCoopIslands(Player player) { public List<Island> getCoopIslands(Player player) {
List<Island> islands = new ArrayList<>(); List<Island> islands = new ArrayList<>();
for (UUID islandList : getIslands().keySet()) { for (Island island : getIslands().values()) {
Island island = getIslands().get(islandList);
if (island.getCoopPlayers().containsKey(player.getUniqueId())) { if (island.getCoopPlayers().containsKey(player.getUniqueId())) {
islands.add(island); islands.add(island);
} }
@ -1379,9 +1377,7 @@ public class IslandManager {
} }
public Island getIslandAtLocation(org.bukkit.Location location) { public Island getIslandAtLocation(org.bukkit.Location location) {
for (UUID islandList : getIslands().keySet()) { for (Island island : getIslands().values()) {
Island island = getIslands().get(islandList);
if (isLocationAtIsland(island, location)) { if (isLocationAtIsland(island, location)) {
return island; return island;
} }

View File

@ -99,7 +99,7 @@ public class Block implements Listener {
int droppedAmount = 0; int droppedAmount = 0;
if (event.getPlayer().isSneaking()) { 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(); int count = stackable.getSize();
droppedAmount = count; droppedAmount = count;
while (count > 64) { while (count > 64) {
@ -110,7 +110,7 @@ public class Block implements Listener {
block.setType(Material.AIR); block.setType(Material.AIR);
stackable.setSize(0); stackable.setSize(0);
} else { } 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(); stackable.takeOne();
droppedAmount = 1; droppedAmount = 1;
} }

View File

@ -2,6 +2,7 @@ package com.songoda.skyblock.listeners;
import java.io.File; import java.io.File;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.Iterator;
import java.util.List; import java.util.List;
import org.bukkit.Material; import org.bukkit.Material;
@ -46,19 +47,20 @@ public class Grow implements Listener {
IslandManager islandManager = skyblock.getIslandManager(); IslandManager islandManager = skyblock.getIslandManager();
Island origin = islandManager.getIslandAtLocation(event.getLocation()); Island origin = islandManager.getIslandAtLocation(event.getLocation());
for (BlockState state : event.getBlocks()) { for (Iterator<BlockState> it = event.getBlocks().iterator(); it.hasNext();) {
BlockState state = it.next();
Island growingTo = islandManager.getIslandAtLocation(state.getLocation()); Island growingTo = islandManager.getIslandAtLocation(state.getLocation());
// This block is ok to continue as it's not related to Skyblock islands. // This block is ok to continue as it's not related to Skyblock islands.
if (origin == null && growingTo == null) if (origin == null && growingTo == null)
continue; continue;
// A block from the structure is outside/inside that it's not suppose to. // A block from the structure is outside/inside that it's not suppose to.
if (origin == null || growingTo == null) { if (origin == null || growingTo == null) {
event.getBlocks().remove(state); it.remove();
continue; continue;
} }
// The structure is growing from one island to another. // The structure is growing from one island to another.
if (!origin.getIslandUUID().equals(growingTo.getIslandUUID())) { if (!origin.getIslandUUID().equals(growingTo.getIslandUUID())) {
event.getBlocks().remove(state); it.remove();
continue; continue;
} }
} }

View File

@ -162,7 +162,13 @@ public class Coop {
if ((island.hasRole(IslandRole.Operator, player.getUniqueId()) if ((island.hasRole(IslandRole.Operator, player.getUniqueId())
&& island.getSetting(IslandRole.Operator, "CoopPlayers").getStatus()) && island.getSetting(IslandRole.Operator, "CoopPlayers").getStatus())
|| island.hasRole(IslandRole.Owner, player.getUniqueId())) { || island.hasRole(IslandRole.Owner, player.getUniqueId())) {
String playerName = ChatColor.stripColor(is.getItemMeta().getDisplayName()); 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().dispatchCommand(player, "island coop " + playerName);
Bukkit.getServer().getScheduler().runTaskLater(skyblock, Bukkit.getServer().getScheduler().runTaskLater(skyblock,
@ -184,10 +190,7 @@ public class Coop {
Island island = islandManager.getIsland(player); Island island = islandManager.getIsland(player);
Map<UUID, IslandCoop> coopPlayers = island.getCoopPlayers(); Map<UUID, IslandCoop> 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; int playerMenuPage = playerData.getPage(), nextEndIndex = coopPlayers.size() - playerMenuPage * 36;
nInv.addItem(nInv.createItem(Materials.OAK_FENCE_GATE.parseItem(), nInv.addItem(nInv.createItem(Materials.OAK_FENCE_GATE.parseItem(),

View File

@ -379,6 +379,7 @@ public class Upgrade {
economyManager.withdraw(player, upgrade.getCost()); economyManager.withdraw(player, upgrade.getCost());
island.setSize(upgrade.getValue()); island.setSize(upgrade.getValue());
islandManager.updateBorder(island);
Bukkit.getServer().getPluginManager().callEvent(new IslandUpgradeEvent( Bukkit.getServer().getPluginManager().callEvent(new IslandUpgradeEvent(
island.getAPIWrapper(), player, APIUtil.fromImplementation( island.getAPIWrapper(), player, APIUtil.fromImplementation(

View File

@ -1,6 +1,8 @@
package com.songoda.skyblock.utils.structure; package com.songoda.skyblock.utils.structure;
import com.google.common.io.Files;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.songoda.skyblock.SkyBlock; import com.songoda.skyblock.SkyBlock;
import com.songoda.skyblock.config.FileManager; import com.songoda.skyblock.config.FileManager;
@ -32,203 +34,221 @@ import java.util.ArrayList;
import java.util.Base64; import java.util.Base64;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.logging.Level;
public final class StructureUtil { public final class StructureUtil {
public static void saveStructure(File configFile, org.bukkit.Location originLocation, public static void saveStructure(File configFile, org.bukkit.Location originLocation,
org.bukkit.Location[] positions) throws Exception { org.bukkit.Location[] positions) throws Exception {
if (!configFile.exists()) { if (!configFile.exists()) {
configFile.createNewFile(); configFile.createNewFile();
} }
LinkedHashMap<Block, Location> blocks = SelectionLocation.getBlocks(originLocation, positions[0], positions[1]); LinkedHashMap<Block, Location> blocks = SelectionLocation.getBlocks(originLocation, positions[0], positions[1]);
LinkedHashMap<Entity, Location> entities = SelectionLocation.getEntities(originLocation, positions[0], LinkedHashMap<Entity, Location> entities = SelectionLocation.getEntities(originLocation, positions[0],
positions[1]); positions[1]);
List<BlockData> blockData = new ArrayList<>(); List<BlockData> blockData = new ArrayList<>();
List<EntityData> entityData = new ArrayList<>(); List<EntityData> entityData = new ArrayList<>();
String originBlockLocation = ""; String originBlockLocation = "";
for (Block blockList : blocks.keySet()) { for (Block blockList : blocks.keySet()) {
Location location = blocks.get(blockList); Location location = blocks.get(blockList);
if (location.isOriginLocation()) { if (location.isOriginLocation()) {
originBlockLocation = location.getX() + ":" + location.getY() + ":" + location.getZ() + ":" originBlockLocation = location.getX() + ":" + location.getY() + ":" + location.getZ() + ":"
+ positions[0].getWorld().getName(); + positions[0].getWorld().getName();
if (blockList.getType() == Material.AIR) { if (blockList.getType() == Material.AIR) {
blockData.add(BlockUtil.convertBlockToBlockData(blockList, location.getX(), location.getY(), blockData.add(BlockUtil.convertBlockToBlockData(blockList, location.getX(), location.getY(),
location.getZ())); location.getZ()));
} }
} }
if (blockList.getType() == Material.AIR) { if (blockList.getType() == Material.AIR) {
continue; continue;
} }
blockData.add( blockData.add(
BlockUtil.convertBlockToBlockData(blockList, location.getX(), location.getY(), location.getZ())); BlockUtil.convertBlockToBlockData(blockList, location.getX(), location.getY(), location.getZ()));
} }
for (Entity entityList : entities.keySet()) { for (Entity entityList : entities.keySet()) {
if (entityList.getType() == EntityType.PLAYER) { if (entityList.getType() == EntityType.PLAYER) {
continue; continue;
} }
Location location = entities.get(entityList); Location location = entities.get(entityList);
entityData.add(EntityUtil.convertEntityToEntityData(entityList, location.getX(), location.getY(), entityData.add(EntityUtil.convertEntityToEntityData(entityList, location.getX(), location.getY(),
location.getZ())); location.getZ()));
} }
if (!originBlockLocation.isEmpty()) { if (!originBlockLocation.isEmpty()) {
originBlockLocation = originBlockLocation + ":" + originLocation.getYaw() + ":" + originLocation.getPitch(); originBlockLocation = originBlockLocation + ":" + originLocation.getYaw() + ":" + originLocation.getPitch();
} }
String JSONString = new Gson().toJson(new Storage(new Gson().toJson(blockData), new Gson().toJson(entityData), String JSONString = new Gson().toJson(new Storage(new Gson().toJson(blockData), new Gson().toJson(entityData),
originBlockLocation, System.currentTimeMillis(), NMSUtil.getVersionNumber()), Storage.class); originBlockLocation, System.currentTimeMillis(), NMSUtil.getVersionNumber()), Storage.class);
FileOutputStream fileOutputStream = new FileOutputStream(configFile, false); FileOutputStream fileOutputStream = new FileOutputStream(configFile, false);
fileOutputStream.write(Base64.getEncoder().encode(JSONString.getBytes(StandardCharsets.UTF_8))); fileOutputStream.write(Base64.getEncoder().encode(JSONString.getBytes(StandardCharsets.UTF_8)));
fileOutputStream.flush(); fileOutputStream.flush();
fileOutputStream.close(); fileOutputStream.close();
} }
public static Structure loadStructure(File configFile) throws IOException { private static String getBase64String(File file) {
if (!configFile.exists()) if (!file.exists()) return null;
return null;
byte[] content = new byte[(int) configFile.length()]; String firstLine = null;
FileInputStream fileInputStream = new FileInputStream(configFile); try {
fileInputStream.read(content); firstLine = Files.asCharSource(file, StandardCharsets.UTF_8).readFirstLine();
fileInputStream.close(); } catch (IOException e) {
e.printStackTrace();
}
String json; return firstLine;
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);
}
Storage storage = new Gson().fromJson(json, Storage.class); public static Structure loadStructure(File configFile) throws IOException {
return new Structure(storage, configFile.getName()); String base64 = getBase64String(configFile);
}
@SuppressWarnings("unchecked") if (base64 == null) {
public static Float[] pasteStructure(Structure structure, org.bukkit.Location location, BlockDegreesType type) { base64 = getBase64String(
Storage storage = structure.getStructureStorage(); 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()) { Storage storage;
originLocationPositions = storage.getOriginLocation().split(":");
}
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) { return new Structure(storage, configFile.getName());
yaw = Float.valueOf(originLocationPositions[4]); }
pitch = Float.valueOf(originLocationPositions[5]);
}
List<BlockData> blockData = new Gson().fromJson(storage.getBlocks(), @SuppressWarnings("unchecked")
new TypeToken<List<BlockData>>() { public static Float[] pasteStructure(Structure structure, org.bukkit.Location location, BlockDegreesType type) {
}.getType()); Storage storage = structure.getStructureStorage();
for (BlockData blockDataList : blockData) { String[] originLocationPositions = null;
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() + "}");
}
});
}
Bukkit.getScheduler().scheduleSyncDelayedTask(SkyBlock.getInstance(), () -> { if (!storage.getOriginLocation().isEmpty()) {
for (EntityData entityDataList : (List<EntityData>) new Gson().fromJson(storage.getEntities(), originLocationPositions = storage.getOriginLocation().split(":");
new TypeToken<List<EntityData>>() { }
}.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);
return new Float[]{yaw, pitch}; float yaw = 0.0F, pitch = 0.0F;
}
public static ItemStack getTool() throws Exception { if (originLocationPositions.length == 6) {
SkyBlock skyblock = SkyBlock.getInstance(); yaw = Float.valueOf(originLocationPositions[4]);
pitch = Float.valueOf(originLocationPositions[5]);
}
FileManager fileManager = skyblock.getFileManager(); List<BlockData> blockData = new Gson().fromJson(storage.getBlocks(), new TypeToken<List<BlockData>>() {
}.getType());
FileManager.Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml")); for (BlockData blockDataList : blockData) {
FileConfiguration configLoad = config.getFileConfiguration(); 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( Bukkit.getScheduler().scheduleSyncDelayedTask(SkyBlock.getInstance(), () -> {
Material.valueOf(fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")) for (EntityData entityDataList : (List<EntityData>) new Gson().fromJson(storage.getEntities(),
.getFileConfiguration().getString("Island.Admin.Structure.Selector"))); new TypeToken<List<EntityData>>() {
ItemMeta im = is.getItemMeta(); }.getType())) {
im.setDisplayName(ChatColor.translateAlternateColorCodes('&', Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SkyBlock.getInstance(), () -> {
configLoad.getString("Island.Structure.Tool.Item.Displayname"))); 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<String> itemLore = new ArrayList<>(); return new Float[] { yaw, pitch };
}
for (String itemLoreList : configLoad.getStringList("Island.Structure.Tool.Item.Lore")) { public static ItemStack getTool() throws Exception {
itemLore.add(ChatColor.translateAlternateColorCodes('&', itemLoreList)); SkyBlock skyblock = SkyBlock.getInstance();
}
im.setLore(itemLore); FileManager fileManager = skyblock.getFileManager();
is.setItemMeta(im);
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, ItemStack is = new ItemStack(
org.bukkit.Location location2) { Material.valueOf(fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml"))
org.bukkit.Location location1Fixed = location1.clone(); .getFileConfiguration().getString("Island.Admin.Structure.Selector")));
org.bukkit.Location location2Fixed = location2.clone(); ItemMeta im = is.getItemMeta();
im.setDisplayName(ChatColor.translateAlternateColorCodes('&',
configLoad.getString("Island.Structure.Tool.Item.Displayname")));
if (location1.getX() > location2.getX()) { List<String> itemLore = new ArrayList<>();
location1Fixed.setX(location2.getX());
location2Fixed.setX(location1.getX());
}
if (location1.getZ() < location2.getZ()) { for (String itemLoreList : configLoad.getStringList("Island.Structure.Tool.Item.Lore")) {
location1Fixed.setZ(location2.getZ()); itemLore.add(ChatColor.translateAlternateColorCodes('&', itemLoreList));
location2Fixed.setZ(location1.getZ()); }
}
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 };
}
} }