From 034015ee4d444c84002a4732a6d23a8ec29d78f3 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 16 Jun 2018 19:06:08 -0700 Subject: [PATCH] Switched back to using hard-coded islands while debugging. Removed unused imports. --- .../island/builders/IslandBuilder.java | 451 +++++++++++++--- .../island/builders/IslandBuilderNew.java | 196 +++++++ .../island/builders/IslandBuilderOld.java | 487 ------------------ .../bskyblock/managers/IslandsManager.java | 3 +- .../bskyblock/managers/LocalesManager.java | 8 +- .../bskyblock/managers/island/NewIsland.java | 2 +- .../bskyblock/panels/LanguagePanel.java | 2 - .../bskyblock/panels/SettingsPanel.java | 2 +- 8 files changed, 578 insertions(+), 573 deletions(-) create mode 100644 src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilderNew.java delete mode 100644 src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilderOld.java diff --git a/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilder.java b/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilder.java index 2140cf21b..548d727e1 100644 --- a/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilder.java +++ b/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilder.java @@ -1,33 +1,31 @@ package us.tastybento.bskyblock.island.builders; -import java.io.File; -import java.io.IOException; -import java.util.EnumMap; import java.util.List; -import java.util.Map; import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.TreeType; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; import org.bukkit.block.Sign; -import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.material.Chest; -import us.tastybento.bskyblock.BSkyBlock; +import us.tastybento.bskyblock.Constants; +import us.tastybento.bskyblock.Constants.GameType; import us.tastybento.bskyblock.api.localization.TextVariables; import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.database.objects.Island; /** - * Generates islands + * Fired when a team event happens. * * @author tastybento * @since 1.0 @@ -46,64 +44,12 @@ public class IslandBuilder { private List chestItems; private UUID playerUUID; private String playerName; - private BSkyBlock plugin; - private Map islandSchems = new EnumMap<>(IslandType.class); //TODO support companions? - public IslandBuilder(BSkyBlock plugin, Island island) { - this.plugin = plugin; + public IslandBuilder(Island island) { this.island = island; world = island.getWorld(); - loadIslands(); - } - - private void loadIslands() { - File schems = new File(plugin.getDataFolder(), "schems"); - if (!schems.exists()) { - if (!schems.mkdirs()) { - plugin.logError("Could not make schems folder!"); - } else { - copySchems(schems); - } - } - - try { - Clipboard cb = new Clipboard(plugin); - cb.load("island"); - islandSchems.put(IslandType.ISLAND, cb); - } catch (IOException | InvalidConfigurationException e) { - plugin.logError("Could not load default island"); - } - if (plugin.getSettings().isNetherGenerate() && plugin.getSettings().isNetherIslands()) { - try { - Clipboard cbn = new Clipboard(plugin); - cbn.load("nether-island"); - islandSchems.put(IslandType.NETHER, cbn); - } catch (IOException | InvalidConfigurationException e) { - plugin.logError("Could not load default nether island"); - } - } - if (plugin.getSettings().isEndGenerate() && plugin.getSettings().isEndIslands()) { - try { - Clipboard cbe = new Clipboard(plugin); - cbe.load("end-island"); - islandSchems.put(IslandType.END, cbe); - } catch (IOException | InvalidConfigurationException e) { - plugin.logError("Could not load default end island"); - } - } - plugin.log("Loaded " + islandSchems.size() + " islands"); - } - - /** - * Copies schems from the jar file - * @param schems2 - */ - private void copySchems(File schems2) { - plugin.saveResource("schems/island.schem", false); - plugin.saveResource("schems/nether-island.schem", false); - plugin.saveResource("schems/end-island.schem", false); } /** @@ -132,32 +78,377 @@ public class IslandBuilder { } public void build() { - plugin.log("Pasting island to " + type); - Location loc = island.getCenter(); // Switch on island type switch (type) { - case NETHER: - world = Bukkit.getWorld(island.getWorld().getName() + "_nether"); - if (world == null) { - return; - } - loc = island.getCenter().toVector().toLocation(world); - break; - case END: - world = Bukkit.getWorld(island.getWorld().getName() + "_the_end"); - if (world == null) { - return; - } - loc = island.getCenter().toVector().toLocation(world); - break; - default: - break; + case ISLAND: + world = island.getWorld(); + if (Constants.GAMETYPE == GameType.ACIDISLAND) { + generateAcidIslandBlocks(); + } else { + generateIslandBlocks(); + } + break; + case NETHER: + world = Bukkit.getWorld(island.getWorld().getName() + "_nether"); + if (world == null) { + return; + } + generateNetherBlocks(); + break; + case END: + world = Bukkit.getWorld(island.getWorld().getName() + "_the_end"); + if (world == null) { + return; + } + generateEndBlocks(); + break; } - plugin.log("Pasting island to " + loc); - islandSchems.get(type).paste(loc); // Do other stuff } + /** + * Creates the AcidIsland default island block by block + */ + private void generateAcidIslandBlocks() { + // AcidIsland + // Build island layer by layer + // Start from the base + // half sandstone; half sand + int x = island.getCenter().getBlockX(); + int z = island.getCenter().getBlockZ(); + int islandHeight = island.getCenter().getBlockY(); + + int y = 0; + for (int x_space = x - 4; x_space <= x + 4; x_space++) { + for (int z_space = z - 4; z_space <= z + 4; z_space++) { + Block b = world.getBlockAt(x_space, y, z_space); + b.setType(Material.BEDROCK); + } + } + for (y = 1; y < islandHeight + 5; y++) { + for (int x_space = x - 4; x_space <= x + 4; x_space++) { + for (int z_space = z - 4; z_space <= z + 4; z_space++) { + Block b = world.getBlockAt(x_space, y, z_space); + if (y < (islandHeight / 2)) { + b.setType(Material.SANDSTONE); + } else { + b.setType(Material.SAND); + } + } + } + } + // Then cut off the corners to make it round-ish + for (y = 0; y < islandHeight + 5; y++) { + for (int x_space = x - 4; x_space <= x + 4; x_space += 8) { + for (int z_space = z - 4; z_space <= z + 4; z_space += 8) { + Block b = world.getBlockAt(x_space, y, z_space); + b.setType(Material.STATIONARY_WATER); + } + } + } + // Add some grass + for (y = islandHeight + 4; y < islandHeight + 5; y++) { + for (int x_space = x - 2; x_space <= x + 2; x_space++) { + for (int z_space = z - 2; z_space <= z + 2; z_space++) { + Block blockToChange = world.getBlockAt(x_space, y, z_space); + blockToChange.setType(Material.GRASS); + } + } + } + // Place bedrock - MUST be there (ensures island are not + // overwritten + Block b = world.getBlockAt(x, islandHeight, z); + b.setType(Material.BEDROCK); + // Then add some more dirt in the classic shape + y = islandHeight + 3; + for (int x_space = x - 2; x_space <= x + 2; x_space++) { + for (int z_space = z - 2; z_space <= z + 2; z_space++) { + b = world.getBlockAt(x_space, y, z_space); + b.setType(Material.DIRT); + } + } + b = world.getBlockAt(x - 3, y, z); + b.setType(Material.DIRT); + b = world.getBlockAt(x + 3, y, z); + b.setType(Material.DIRT); + b = world.getBlockAt(x, y, z - 3); + b.setType(Material.DIRT); + b = world.getBlockAt(x, y, z + 3); + b.setType(Material.DIRT); + y = islandHeight + 2; + for (int x_space = x - 1; x_space <= x + 1; x_space++) { + for (int z_space = z - 1; z_space <= z + 1; z_space++) { + b = world.getBlockAt(x_space, y, z_space); + b.setType(Material.DIRT); + } + } + b = world.getBlockAt(x - 2, y, z); + b.setType(Material.DIRT); + b = world.getBlockAt(x + 2, y, z); + b.setType(Material.DIRT); + b = world.getBlockAt(x, y, z - 2); + b.setType(Material.DIRT); + b = world.getBlockAt(x, y, z + 2); + b.setType(Material.DIRT); + y = islandHeight + 1; + b = world.getBlockAt(x - 1, y, z); + b.setType(Material.DIRT); + b = world.getBlockAt(x + 1, y, z); + b.setType(Material.DIRT); + b = world.getBlockAt(x, y, z - 1); + b.setType(Material.DIRT); + b = world.getBlockAt(x, y, z + 1); + b.setType(Material.DIRT); + + // Add island items + y = islandHeight; + // Add tree (natural) + Location treeLoc = new Location(world, x, y + 5D, z); + world.generateTree(treeLoc, TreeType.ACACIA); + + // Place a helpful sign in front of player + placeSign(x, islandHeight + 5, z + 3); + // Place the chest - no need to use the safe spawn function + // because we + // know what this island looks like + placeChest(x, islandHeight + 5, z + 1); + } + + private void generateIslandBlocks() { + // Skyblock + // Build island layer by layer + // Start from the base + // half sandstone; half sand + int x = island.getCenter().getBlockX(); + int z = island.getCenter().getBlockZ(); + int islandHeight = island.getCenter().getBlockY(); + + World world = island.getCenter().getWorld(); + int y; + // Add some grass + for (y = islandHeight + 4; y < islandHeight + 5; y++) { + for (int x_space = x - 3; x_space <= x + 3; x_space++) { + for (int z_space = z - 3; z_space <= z + 3; z_space++) { + world.getBlockAt(x_space, y, z_space).setType(Material.GRASS); + } + } + } + + // Then cut off the corners to make it round-ish + for (int x_space = x - 3; x_space <= x + 3; x_space += 6) { + for (int z_space = z - 3; z_space <= z + 3; z_space += 6) { + world.getBlockAt(x_space, y-1, z_space).setType(Material.AIR); + } + } + // Place bedrock - MUST be there (ensures island are not + // overwritten + Block b = world.getBlockAt(x, islandHeight, z); + b.setType(Material.BEDROCK); + // Then add some more dirt in the classic shape + y = islandHeight + 3; + for (int x_space = x - 2; x_space <= x + 2; x_space++) { + for (int z_space = z - 2; z_space <= z + 2; z_space++) { + b = world.getBlockAt(x_space, y, z_space); + b.setType(Material.DIRT); + } + } + b = world.getBlockAt(x - 3, y, z); + b.setType(Material.DIRT); + b = world.getBlockAt(x + 3, y, z); + b.setType(Material.DIRT); + b = world.getBlockAt(x, y, z - 3); + b.setType(Material.DIRT); + b = world.getBlockAt(x, y, z + 3); + b.setType(Material.DIRT); + y = islandHeight + 2; + for (int x_space = x - 1; x_space <= x + 1; x_space++) { + for (int z_space = z - 1; z_space <= z + 1; z_space++) { + b = world.getBlockAt(x_space, y, z_space); + b.setType(Material.DIRT); + } + } + b = world.getBlockAt(x - 2, y, z); + b.setType(Material.DIRT); + b = world.getBlockAt(x + 2, y, z); + b.setType(Material.DIRT); + b = world.getBlockAt(x, y, z - 2); + b.setType(Material.DIRT); + b = world.getBlockAt(x, y, z + 2); + b.setType(Material.DIRT); + y = islandHeight + 1; + b = world.getBlockAt(x - 1, y, z); + b.setType(Material.DIRT); + b = world.getBlockAt(x + 1, y, z); + b.setType(Material.DIRT); + b = world.getBlockAt(x, y, z - 1); + b.setType(Material.DIRT); + b = world.getBlockAt(x, y, z + 1); + b.setType(Material.DIRT); + + // Add island items + y = islandHeight; + // Add tree (natural) + Location treeLoc = new Location(world, x, y + 5D, z); + world.generateTree(treeLoc, TreeType.TREE); + + // Place a helpful sign in front of player + placeSign(x, islandHeight + 5, z + 3); + // Place the chest - no need to use the safe spawn function + // because we + // know what this island looks like + placeChest(x, islandHeight + 5, z + 1); + } + + private void generateNetherBlocks() { + // Nether block + int x = island.getCenter().getBlockX(); + int z = island.getCenter().getBlockZ(); + int islandHeight = island.getCenter().getBlockY(); + + int y; + for (y = islandHeight + 4; y < islandHeight + 5; y++) { + for (int x_space = x - 3; x_space <= x + 3; x_space++) { + for (int z_space = z - 3; z_space <= z + 3; z_space++) { + world.getBlockAt(x_space, y, z_space).setType(Material.NETHER_BRICK); + } + } + } + // Then cut off the corners to make it round-ish + for (int x_space = x - 3; x_space <= x + 3; x_space += 6) { + for (int z_space = z - 3; z_space <= z + 3; z_space += 6) { + world.getBlockAt(x_space, y-1, z_space).setType(Material.AIR); + } + } + // Place bedrock - MUST be there (ensures island are not + // overwritten + Block b = world.getBlockAt(x, islandHeight, z); + b.setType(Material.BEDROCK); + // Then add some more dirt in the classic shape + y = islandHeight + 3; + for (int x_space = x - 2; x_space <= x + 2; x_space++) { + for (int z_space = z - 2; z_space <= z + 2; z_space++) { + b = world.getBlockAt(x_space, y, z_space); + b.setType(Material.NETHERRACK); + } + } + b = world.getBlockAt(x - 3, y, z); + b.setType(Material.SOUL_SAND); + b = world.getBlockAt(x + 3, y, z); + b.setType(Material.SOUL_SAND); + b = world.getBlockAt(x, y, z - 3); + b.setType(Material.SOUL_SAND); + b = world.getBlockAt(x, y, z + 3); + b.setType(Material.SOUL_SAND); + y = islandHeight + 2; + for (int x_space = x - 1; x_space <= x + 1; x_space++) { + for (int z_space = z - 1; z_space <= z + 1; z_space++) { + b = world.getBlockAt(x_space, y, z_space); + b.setType(Material.GRAVEL); + } + } + b = world.getBlockAt(x - 2, y, z); + b.setType(Material.QUARTZ_ORE); + b = world.getBlockAt(x + 2, y, z); + b.setType(Material.QUARTZ_ORE); + b = world.getBlockAt(x, y, z - 2); + b.setType(Material.QUARTZ_ORE); + b = world.getBlockAt(x, y, z + 2); + b.setType(Material.QUARTZ_ORE); + y = islandHeight + 1; + b = world.getBlockAt(x - 1, y, z); + b.setType(Material.MAGMA); + b = world.getBlockAt(x + 1, y, z); + b.setType(Material.MAGMA); + b = world.getBlockAt(x, y, z - 1); + b.setType(Material.MAGMA); + b = world.getBlockAt(x, y, z + 1); + b.setType(Material.MAGMA); + + // Place a helpful sign in front of player + placeSign(x, islandHeight + 5, z + 3); + // Place the chest - no need to use the safe spawn function + // because we know what this island looks like + placeChest(x, islandHeight + 5, z + 1); + } + + private void generateEndBlocks() { + // Nether block + int x = island.getCenter().getBlockX(); + int z = island.getCenter().getBlockZ(); + int islandHeight = island.getCenter().getBlockY(); + + int y; + // Add some grass + for (y = islandHeight + 4; y < islandHeight + 5; y++) { + for (int x_space = x - 3; x_space <= x + 3; x_space++) { + for (int z_space = z - 3; z_space <= z + 3; z_space++) { + world.getBlockAt(x_space, y, z_space).setType(Material.END_BRICKS); + } + } + } + // Then cut off the corners to make it round-ish + for (int x_space = x - 3; x_space <= x + 3; x_space += 6) { + for (int z_space = z - 3; z_space <= z + 3; z_space += 6) { + world.getBlockAt(x_space, y-1, z_space).setType(Material.AIR); + } + } + // Place bedrock - MUST be there (ensures island are not + // overwritten + Block b = world.getBlockAt(x, islandHeight, z); + b.setType(Material.BEDROCK); + // Then add some more dirt in the classic shape + y = islandHeight + 3; + for (int x_space = x - 2; x_space <= x + 2; x_space++) { + for (int z_space = z - 2; z_space <= z + 2; z_space++) { + b = world.getBlockAt(x_space, y, z_space); + b.setType(Material.ENDER_STONE); + } + } + b = world.getBlockAt(x - 3, y, z); + b.setType(Material.OBSIDIAN); + b = world.getBlockAt(x + 3, y, z); + b.setType(Material.OBSIDIAN); + b = world.getBlockAt(x, y, z - 3); + b.setType(Material.OBSIDIAN); + b = world.getBlockAt(x, y, z + 3); + b.setType(Material.OBSIDIAN); + y = islandHeight + 2; + for (int x_space = x - 1; x_space <= x + 1; x_space++) { + for (int z_space = z - 1; z_space <= z + 1; z_space++) { + b = world.getBlockAt(x_space, y, z_space); + b.setType(Material.ENDER_STONE); + } + } + b = world.getBlockAt(x - 2, y, z); + b.setType(Material.ENDER_STONE); + b = world.getBlockAt(x + 2, y, z); + b.setType(Material.ENDER_STONE); + b = world.getBlockAt(x, y, z - 2); + b.setType(Material.ENDER_STONE); + b = world.getBlockAt(x, y, z + 2); + b.setType(Material.ENDER_STONE); + y = islandHeight + 1; + b = world.getBlockAt(x - 1, y, z); + b.setType(Material.ENDER_STONE); + b = world.getBlockAt(x + 1, y, z); + b.setType(Material.ENDER_STONE); + b = world.getBlockAt(x, y, z - 1); + b.setType(Material.ENDER_STONE); + b = world.getBlockAt(x, y, z + 1); + b.setType(Material.ENDER_STONE); + + // Add island items + y = islandHeight; + // Spawn an ender crystal + world.spawnEntity(new Location(world, x, y + 5D, z), EntityType.ENDER_CRYSTAL); + + // Place a helpful sign in front of player + placeSign(x, islandHeight + 5, z + 3); + // Place the chest - no need to use the safe spawn function + // because we know what this island looks like + placeChest(x, islandHeight + 5, z + 1); + } + private void placeSign(int x, int y, int z) { Block blockToChange = world.getBlockAt(x, y, z); blockToChange.setType(Material.SIGN_POST); diff --git a/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilderNew.java b/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilderNew.java new file mode 100644 index 000000000..7254d4d6d --- /dev/null +++ b/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilderNew.java @@ -0,0 +1,196 @@ +package us.tastybento.bskyblock.island.builders; + +import java.io.File; +import java.io.IOException; +import java.util.EnumMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.BlockState; +import org.bukkit.block.Sign; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; +import org.bukkit.material.Chest; + +import us.tastybento.bskyblock.BSkyBlock; +import us.tastybento.bskyblock.api.localization.TextVariables; +import us.tastybento.bskyblock.api.user.User; +import us.tastybento.bskyblock.database.objects.Island; + +/** + * Generates islands + * + * @author tastybento + * @since 1.0 + */ +public class IslandBuilderNew { + + public enum IslandType { + ISLAND, + NETHER, + END + } + + private Island island; + private World world; + private IslandType type = IslandType.ISLAND; + private List chestItems; + private UUID playerUUID; + private String playerName; + private BSkyBlock plugin; + private Map islandSchems = new EnumMap<>(IslandType.class); + + //TODO support companions? + + public IslandBuilderNew(BSkyBlock plugin, Island island) { + this.plugin = plugin; + this.island = island; + world = island.getWorld(); + loadIslands(); + } + + private void loadIslands() { + File schems = new File(plugin.getDataFolder(), "schems"); + if (!schems.exists()) { + if (!schems.mkdirs()) { + plugin.logError("Could not make schems folder!"); + } else { + copySchems(schems); + } + } + + try { + Clipboard cb = new Clipboard(plugin); + cb.load("island"); + islandSchems.put(IslandType.ISLAND, cb); + } catch (IOException | InvalidConfigurationException e) { + plugin.logError("Could not load default island"); + } + if (plugin.getSettings().isNetherGenerate() && plugin.getSettings().isNetherIslands()) { + try { + Clipboard cbn = new Clipboard(plugin); + cbn.load("nether-island"); + islandSchems.put(IslandType.NETHER, cbn); + } catch (IOException | InvalidConfigurationException e) { + plugin.logError("Could not load default nether island"); + } + } + if (plugin.getSettings().isEndGenerate() && plugin.getSettings().isEndIslands()) { + try { + Clipboard cbe = new Clipboard(plugin); + cbe.load("end-island"); + islandSchems.put(IslandType.END, cbe); + } catch (IOException | InvalidConfigurationException e) { + plugin.logError("Could not load default end island"); + } + } + plugin.log("Loaded " + islandSchems.size() + " islands"); + } + + /** + * Copies schems from the jar file + * @param schems2 + */ + private void copySchems(File schems2) { + plugin.saveResource("schems/island.schem", false); + plugin.saveResource("schems/nether-island.schem", false); + plugin.saveResource("schems/end-island.schem", false); + } + + /** + * @param type the type to set + */ + public IslandBuilderNew setType(IslandType type) { + this.type = type; + return this; + } + + /** + * @param player - the player the player to set + */ + public IslandBuilderNew setPlayer(Player player) { + playerUUID = player.getUniqueId(); + playerName = player.getName(); + return this; + } + + /** + * @param list the default chestItems to set + */ + public IslandBuilderNew setChestItems(List list) { + chestItems = list; + return this; + } + + public void build() { + plugin.log("Pasting island to " + type); + Location loc = island.getCenter(); + // Switch on island type + switch (type) { + case NETHER: + world = Bukkit.getWorld(island.getWorld().getName() + "_nether"); + if (world == null) { + return; + } + loc = island.getCenter().toVector().toLocation(world); + break; + case END: + world = Bukkit.getWorld(island.getWorld().getName() + "_the_end"); + if (world == null) { + return; + } + loc = island.getCenter().toVector().toLocation(world); + break; + default: + break; + } + plugin.log("Pasting island to " + loc); + islandSchems.get(type).paste(loc); + // Do other stuff + } + + private void placeSign(int x, int y, int z) { + Block blockToChange = world.getBlockAt(x, y, z); + blockToChange.setType(Material.SIGN_POST); + if (playerUUID != null) { + Sign sign = (Sign) blockToChange.getState(); + User user = User.getInstance(playerUUID); + + // Sets the lines of the sign + sign.setLine(0, user.getTranslation("new-island.sign.line0", TextVariables.NAME, playerName)); + sign.setLine(1, user.getTranslation("new-island.sign.line1", TextVariables.NAME, playerName)); + sign.setLine(2, user.getTranslation("new-island.sign.line2", TextVariables.NAME, playerName)); + sign.setLine(3, user.getTranslation("new-island.sign.line3", TextVariables.NAME, playerName)); + + ((org.bukkit.material.Sign) sign.getData()).setFacingDirection(BlockFace.NORTH); + sign.update(); + } + } + + private void placeChest(int x, int y, int z) { + // Fill the chest and orient it correctly + Block blockToChange = world.getBlockAt(x, y, z); + blockToChange.setType(Material.CHEST); + BlockState state = blockToChange.getState(); + Chest chest = new Chest(BlockFace.SOUTH); + state.setData(chest); + state.update(); + if (!chestItems.isEmpty()) { + InventoryHolder chestBlock = (InventoryHolder) state; + for (ItemStack item: chestItems) { + chestBlock.getInventory().addItem(item); + } + } + } +} + + diff --git a/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilderOld.java b/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilderOld.java deleted file mode 100644 index f6addc05b..000000000 --- a/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilderOld.java +++ /dev/null @@ -1,487 +0,0 @@ -package us.tastybento.bskyblock.island.builders; - -import java.util.List; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.TreeType; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.BlockState; -import org.bukkit.block.Sign; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.ItemStack; -import org.bukkit.material.Chest; - -import us.tastybento.bskyblock.Constants; -import us.tastybento.bskyblock.Constants.GameType; -import us.tastybento.bskyblock.api.localization.TextVariables; -import us.tastybento.bskyblock.api.user.User; -import us.tastybento.bskyblock.database.objects.Island; - -/** - * Fired when a team event happens. - * - * @author tastybento - * @since 1.0 - */ -public class IslandBuilderOld { - - public enum IslandType { - ISLAND, - NETHER, - END - } - - private Island island; - private World world; - private IslandType type = IslandType.ISLAND; - private List chestItems; - private UUID playerUUID; - private String playerName; - - //TODO support companions? - - public IslandBuilderOld(Island island) { - this.island = island; - world = island.getWorld(); - } - - /** - * @param type the type to set - */ - public IslandBuilderOld setType(IslandType type) { - this.type = type; - return this; - } - - /** - * @param player - the player the player to set - */ - public IslandBuilderOld setPlayer(Player player) { - playerUUID = player.getUniqueId(); - playerName = player.getName(); - return this; - } - - /** - * @param list the default chestItems to set - */ - public IslandBuilderOld setChestItems(List list) { - chestItems = list; - return this; - } - - public void build() { - // Switch on island type - switch (type) { - case ISLAND: - world = island.getWorld(); - if (Constants.GAMETYPE == GameType.ACIDISLAND) { - generateAcidIslandBlocks(); - } else { - generateIslandBlocks(); - } - break; - case NETHER: - world = Bukkit.getWorld(island.getWorld().getName() + "_nether"); - if (world == null) { - return; - } - generateNetherBlocks(); - break; - case END: - world = Bukkit.getWorld(island.getWorld().getName() + "_the_end"); - if (world == null) { - return; - } - generateEndBlocks(); - break; - } - // Do other stuff - } - - /** - * Creates the AcidIsland default island block by block - */ - private void generateAcidIslandBlocks() { - // AcidIsland - // Build island layer by layer - // Start from the base - // half sandstone; half sand - int x = island.getCenter().getBlockX(); - int z = island.getCenter().getBlockZ(); - int islandHeight = island.getCenter().getBlockY(); - - int y = 0; - for (int x_space = x - 4; x_space <= x + 4; x_space++) { - for (int z_space = z - 4; z_space <= z + 4; z_space++) { - Block b = world.getBlockAt(x_space, y, z_space); - b.setType(Material.BEDROCK); - } - } - for (y = 1; y < islandHeight + 5; y++) { - for (int x_space = x - 4; x_space <= x + 4; x_space++) { - for (int z_space = z - 4; z_space <= z + 4; z_space++) { - Block b = world.getBlockAt(x_space, y, z_space); - if (y < (islandHeight / 2)) { - b.setType(Material.SANDSTONE); - } else { - b.setType(Material.SAND); - } - } - } - } - // Then cut off the corners to make it round-ish - for (y = 0; y < islandHeight + 5; y++) { - for (int x_space = x - 4; x_space <= x + 4; x_space += 8) { - for (int z_space = z - 4; z_space <= z + 4; z_space += 8) { - Block b = world.getBlockAt(x_space, y, z_space); - b.setType(Material.STATIONARY_WATER); - } - } - } - // Add some grass - for (y = islandHeight + 4; y < islandHeight + 5; y++) { - for (int x_space = x - 2; x_space <= x + 2; x_space++) { - for (int z_space = z - 2; z_space <= z + 2; z_space++) { - Block blockToChange = world.getBlockAt(x_space, y, z_space); - blockToChange.setType(Material.GRASS); - } - } - } - // Place bedrock - MUST be there (ensures island are not - // overwritten - Block b = world.getBlockAt(x, islandHeight, z); - b.setType(Material.BEDROCK); - // Then add some more dirt in the classic shape - y = islandHeight + 3; - for (int x_space = x - 2; x_space <= x + 2; x_space++) { - for (int z_space = z - 2; z_space <= z + 2; z_space++) { - b = world.getBlockAt(x_space, y, z_space); - b.setType(Material.DIRT); - } - } - b = world.getBlockAt(x - 3, y, z); - b.setType(Material.DIRT); - b = world.getBlockAt(x + 3, y, z); - b.setType(Material.DIRT); - b = world.getBlockAt(x, y, z - 3); - b.setType(Material.DIRT); - b = world.getBlockAt(x, y, z + 3); - b.setType(Material.DIRT); - y = islandHeight + 2; - for (int x_space = x - 1; x_space <= x + 1; x_space++) { - for (int z_space = z - 1; z_space <= z + 1; z_space++) { - b = world.getBlockAt(x_space, y, z_space); - b.setType(Material.DIRT); - } - } - b = world.getBlockAt(x - 2, y, z); - b.setType(Material.DIRT); - b = world.getBlockAt(x + 2, y, z); - b.setType(Material.DIRT); - b = world.getBlockAt(x, y, z - 2); - b.setType(Material.DIRT); - b = world.getBlockAt(x, y, z + 2); - b.setType(Material.DIRT); - y = islandHeight + 1; - b = world.getBlockAt(x - 1, y, z); - b.setType(Material.DIRT); - b = world.getBlockAt(x + 1, y, z); - b.setType(Material.DIRT); - b = world.getBlockAt(x, y, z - 1); - b.setType(Material.DIRT); - b = world.getBlockAt(x, y, z + 1); - b.setType(Material.DIRT); - - // Add island items - y = islandHeight; - // Add tree (natural) - Location treeLoc = new Location(world, x, y + 5D, z); - world.generateTree(treeLoc, TreeType.ACACIA); - - // Place a helpful sign in front of player - placeSign(x, islandHeight + 5, z + 3); - // Place the chest - no need to use the safe spawn function - // because we - // know what this island looks like - placeChest(x, islandHeight + 5, z + 1); - } - - private void generateIslandBlocks() { - // Skyblock - // Build island layer by layer - // Start from the base - // half sandstone; half sand - int x = island.getCenter().getBlockX(); - int z = island.getCenter().getBlockZ(); - int islandHeight = island.getCenter().getBlockY(); - - World world = island.getCenter().getWorld(); - int y; - // Add some grass - for (y = islandHeight + 4; y < islandHeight + 5; y++) { - for (int x_space = x - 3; x_space <= x + 3; x_space++) { - for (int z_space = z - 3; z_space <= z + 3; z_space++) { - world.getBlockAt(x_space, y, z_space).setType(Material.GRASS); - } - } - } - - // Then cut off the corners to make it round-ish - for (int x_space = x - 3; x_space <= x + 3; x_space += 6) { - for (int z_space = z - 3; z_space <= z + 3; z_space += 6) { - world.getBlockAt(x_space, y-1, z_space).setType(Material.AIR); - } - } - // Place bedrock - MUST be there (ensures island are not - // overwritten - Block b = world.getBlockAt(x, islandHeight, z); - b.setType(Material.BEDROCK); - // Then add some more dirt in the classic shape - y = islandHeight + 3; - for (int x_space = x - 2; x_space <= x + 2; x_space++) { - for (int z_space = z - 2; z_space <= z + 2; z_space++) { - b = world.getBlockAt(x_space, y, z_space); - b.setType(Material.DIRT); - } - } - b = world.getBlockAt(x - 3, y, z); - b.setType(Material.DIRT); - b = world.getBlockAt(x + 3, y, z); - b.setType(Material.DIRT); - b = world.getBlockAt(x, y, z - 3); - b.setType(Material.DIRT); - b = world.getBlockAt(x, y, z + 3); - b.setType(Material.DIRT); - y = islandHeight + 2; - for (int x_space = x - 1; x_space <= x + 1; x_space++) { - for (int z_space = z - 1; z_space <= z + 1; z_space++) { - b = world.getBlockAt(x_space, y, z_space); - b.setType(Material.DIRT); - } - } - b = world.getBlockAt(x - 2, y, z); - b.setType(Material.DIRT); - b = world.getBlockAt(x + 2, y, z); - b.setType(Material.DIRT); - b = world.getBlockAt(x, y, z - 2); - b.setType(Material.DIRT); - b = world.getBlockAt(x, y, z + 2); - b.setType(Material.DIRT); - y = islandHeight + 1; - b = world.getBlockAt(x - 1, y, z); - b.setType(Material.DIRT); - b = world.getBlockAt(x + 1, y, z); - b.setType(Material.DIRT); - b = world.getBlockAt(x, y, z - 1); - b.setType(Material.DIRT); - b = world.getBlockAt(x, y, z + 1); - b.setType(Material.DIRT); - - // Add island items - y = islandHeight; - // Add tree (natural) - Location treeLoc = new Location(world, x, y + 5D, z); - world.generateTree(treeLoc, TreeType.TREE); - - // Place a helpful sign in front of player - placeSign(x, islandHeight + 5, z + 3); - // Place the chest - no need to use the safe spawn function - // because we - // know what this island looks like - placeChest(x, islandHeight + 5, z + 1); - } - - private void generateNetherBlocks() { - // Nether block - int x = island.getCenter().getBlockX(); - int z = island.getCenter().getBlockZ(); - int islandHeight = island.getCenter().getBlockY(); - - int y; - for (y = islandHeight + 4; y < islandHeight + 5; y++) { - for (int x_space = x - 3; x_space <= x + 3; x_space++) { - for (int z_space = z - 3; z_space <= z + 3; z_space++) { - world.getBlockAt(x_space, y, z_space).setType(Material.NETHER_BRICK); - } - } - } - // Then cut off the corners to make it round-ish - for (int x_space = x - 3; x_space <= x + 3; x_space += 6) { - for (int z_space = z - 3; z_space <= z + 3; z_space += 6) { - world.getBlockAt(x_space, y-1, z_space).setType(Material.AIR); - } - } - // Place bedrock - MUST be there (ensures island are not - // overwritten - Block b = world.getBlockAt(x, islandHeight, z); - b.setType(Material.BEDROCK); - // Then add some more dirt in the classic shape - y = islandHeight + 3; - for (int x_space = x - 2; x_space <= x + 2; x_space++) { - for (int z_space = z - 2; z_space <= z + 2; z_space++) { - b = world.getBlockAt(x_space, y, z_space); - b.setType(Material.NETHERRACK); - } - } - b = world.getBlockAt(x - 3, y, z); - b.setType(Material.SOUL_SAND); - b = world.getBlockAt(x + 3, y, z); - b.setType(Material.SOUL_SAND); - b = world.getBlockAt(x, y, z - 3); - b.setType(Material.SOUL_SAND); - b = world.getBlockAt(x, y, z + 3); - b.setType(Material.SOUL_SAND); - y = islandHeight + 2; - for (int x_space = x - 1; x_space <= x + 1; x_space++) { - for (int z_space = z - 1; z_space <= z + 1; z_space++) { - b = world.getBlockAt(x_space, y, z_space); - b.setType(Material.GRAVEL); - } - } - b = world.getBlockAt(x - 2, y, z); - b.setType(Material.QUARTZ_ORE); - b = world.getBlockAt(x + 2, y, z); - b.setType(Material.QUARTZ_ORE); - b = world.getBlockAt(x, y, z - 2); - b.setType(Material.QUARTZ_ORE); - b = world.getBlockAt(x, y, z + 2); - b.setType(Material.QUARTZ_ORE); - y = islandHeight + 1; - b = world.getBlockAt(x - 1, y, z); - b.setType(Material.MAGMA); - b = world.getBlockAt(x + 1, y, z); - b.setType(Material.MAGMA); - b = world.getBlockAt(x, y, z - 1); - b.setType(Material.MAGMA); - b = world.getBlockAt(x, y, z + 1); - b.setType(Material.MAGMA); - - // Place a helpful sign in front of player - placeSign(x, islandHeight + 5, z + 3); - // Place the chest - no need to use the safe spawn function - // because we know what this island looks like - placeChest(x, islandHeight + 5, z + 1); - } - - private void generateEndBlocks() { - // Nether block - int x = island.getCenter().getBlockX(); - int z = island.getCenter().getBlockZ(); - int islandHeight = island.getCenter().getBlockY(); - - int y; - // Add some grass - for (y = islandHeight + 4; y < islandHeight + 5; y++) { - for (int x_space = x - 3; x_space <= x + 3; x_space++) { - for (int z_space = z - 3; z_space <= z + 3; z_space++) { - world.getBlockAt(x_space, y, z_space).setType(Material.END_BRICKS); - } - } - } - // Then cut off the corners to make it round-ish - for (int x_space = x - 3; x_space <= x + 3; x_space += 6) { - for (int z_space = z - 3; z_space <= z + 3; z_space += 6) { - world.getBlockAt(x_space, y-1, z_space).setType(Material.AIR); - } - } - // Place bedrock - MUST be there (ensures island are not - // overwritten - Block b = world.getBlockAt(x, islandHeight, z); - b.setType(Material.BEDROCK); - // Then add some more dirt in the classic shape - y = islandHeight + 3; - for (int x_space = x - 2; x_space <= x + 2; x_space++) { - for (int z_space = z - 2; z_space <= z + 2; z_space++) { - b = world.getBlockAt(x_space, y, z_space); - b.setType(Material.ENDER_STONE); - } - } - b = world.getBlockAt(x - 3, y, z); - b.setType(Material.OBSIDIAN); - b = world.getBlockAt(x + 3, y, z); - b.setType(Material.OBSIDIAN); - b = world.getBlockAt(x, y, z - 3); - b.setType(Material.OBSIDIAN); - b = world.getBlockAt(x, y, z + 3); - b.setType(Material.OBSIDIAN); - y = islandHeight + 2; - for (int x_space = x - 1; x_space <= x + 1; x_space++) { - for (int z_space = z - 1; z_space <= z + 1; z_space++) { - b = world.getBlockAt(x_space, y, z_space); - b.setType(Material.ENDER_STONE); - } - } - b = world.getBlockAt(x - 2, y, z); - b.setType(Material.ENDER_STONE); - b = world.getBlockAt(x + 2, y, z); - b.setType(Material.ENDER_STONE); - b = world.getBlockAt(x, y, z - 2); - b.setType(Material.ENDER_STONE); - b = world.getBlockAt(x, y, z + 2); - b.setType(Material.ENDER_STONE); - y = islandHeight + 1; - b = world.getBlockAt(x - 1, y, z); - b.setType(Material.ENDER_STONE); - b = world.getBlockAt(x + 1, y, z); - b.setType(Material.ENDER_STONE); - b = world.getBlockAt(x, y, z - 1); - b.setType(Material.ENDER_STONE); - b = world.getBlockAt(x, y, z + 1); - b.setType(Material.ENDER_STONE); - - // Add island items - y = islandHeight; - // Spawn an ender crystal - world.spawnEntity(new Location(world, x, y + 5D, z), EntityType.ENDER_CRYSTAL); - - // Place a helpful sign in front of player - placeSign(x, islandHeight + 5, z + 3); - // Place the chest - no need to use the safe spawn function - // because we know what this island looks like - placeChest(x, islandHeight + 5, z + 1); - } - - private void placeSign(int x, int y, int z) { - Block blockToChange = world.getBlockAt(x, y, z); - blockToChange.setType(Material.SIGN_POST); - if (playerUUID != null) { - Sign sign = (Sign) blockToChange.getState(); - User user = User.getInstance(playerUUID); - - // Sets the lines of the sign - sign.setLine(0, user.getTranslation("new-island.sign.line0", TextVariables.NAME, playerName)); - sign.setLine(1, user.getTranslation("new-island.sign.line1", TextVariables.NAME, playerName)); - sign.setLine(2, user.getTranslation("new-island.sign.line2", TextVariables.NAME, playerName)); - sign.setLine(3, user.getTranslation("new-island.sign.line3", TextVariables.NAME, playerName)); - - ((org.bukkit.material.Sign) sign.getData()).setFacingDirection(BlockFace.NORTH); - sign.update(); - } - } - - private void placeChest(int x, int y, int z) { - // Fill the chest and orient it correctly - Block blockToChange = world.getBlockAt(x, y, z); - blockToChange.setType(Material.CHEST); - BlockState state = blockToChange.getState(); - Chest chest = new Chest(BlockFace.SOUTH); - state.setData(chest); - state.update(); - if (!chestItems.isEmpty()) { - InventoryHolder chestBlock = (InventoryHolder) state; - for (ItemStack item: chestItems) { - chestBlock.getInventory().addItem(item); - } - } - } -} - - diff --git a/src/main/java/us/tastybento/bskyblock/managers/IslandsManager.java b/src/main/java/us/tastybento/bskyblock/managers/IslandsManager.java index 3de615d3b..09552ec99 100644 --- a/src/main/java/us/tastybento/bskyblock/managers/IslandsManager.java +++ b/src/main/java/us/tastybento/bskyblock/managers/IslandsManager.java @@ -703,7 +703,8 @@ public class IslandsManager { try { handler.saveObject(island); } catch (Exception e) { - plugin.logError("Could not save island to datavase when running async! " + e.getMessage()); + plugin.logError("Could not save island to database when running async! " + e.getMessage()); + e.printStackTrace(); } } }; diff --git a/src/main/java/us/tastybento/bskyblock/managers/LocalesManager.java b/src/main/java/us/tastybento/bskyblock/managers/LocalesManager.java index 23b49faf5..b15f754b9 100644 --- a/src/main/java/us/tastybento/bskyblock/managers/LocalesManager.java +++ b/src/main/java/us/tastybento/bskyblock/managers/LocalesManager.java @@ -4,7 +4,13 @@ import java.io.File; import java.io.FilenameFilter; import java.io.IOException; import java.io.InputStream; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Objects; import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.api.localization.BSBLocale; diff --git a/src/main/java/us/tastybento/bskyblock/managers/island/NewIsland.java b/src/main/java/us/tastybento/bskyblock/managers/island/NewIsland.java index 875210319..dee27ec63 100644 --- a/src/main/java/us/tastybento/bskyblock/managers/island/NewIsland.java +++ b/src/main/java/us/tastybento/bskyblock/managers/island/NewIsland.java @@ -120,7 +120,7 @@ public class NewIsland { .build(); if (!event.isCancelled()) { // Create island - IslandBuilder ib = new IslandBuilder(plugin, island) + IslandBuilder ib = new IslandBuilder(island) .setPlayer(user.getPlayer()) .setChestItems(plugin.getSettings().getChestItems()) .setType(IslandType.ISLAND); diff --git a/src/main/java/us/tastybento/bskyblock/panels/LanguagePanel.java b/src/main/java/us/tastybento/bskyblock/panels/LanguagePanel.java index 1bab87395..1cc2a9c0e 100644 --- a/src/main/java/us/tastybento/bskyblock/panels/LanguagePanel.java +++ b/src/main/java/us/tastybento/bskyblock/panels/LanguagePanel.java @@ -1,8 +1,6 @@ package us.tastybento.bskyblock.panels; import java.util.Locale; -import java.util.Set; -import java.util.SortedSet; import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.api.panels.builders.PanelBuilder; diff --git a/src/main/java/us/tastybento/bskyblock/panels/SettingsPanel.java b/src/main/java/us/tastybento/bskyblock/panels/SettingsPanel.java index 7255ce0ac..4e26c31f4 100644 --- a/src/main/java/us/tastybento/bskyblock/panels/SettingsPanel.java +++ b/src/main/java/us/tastybento/bskyblock/panels/SettingsPanel.java @@ -2,7 +2,7 @@ package us.tastybento.bskyblock.panels; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; -import org.bukkit.material.MaterialData; + import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.api.flags.Flag; import us.tastybento.bskyblock.api.panels.PanelItem;