From e10eb194b23b13b03c5a3eff8feb43af8bc2f52c Mon Sep 17 00:00:00 2001 From: Tastybento Date: Sat, 9 Dec 2017 10:43:35 -0800 Subject: [PATCH] Removed deprecated methods. --- .../island/builders/IslandBuilder.java | 494 ++++++++++++++++++ .../bskyblock/util/SafeSpotTeleport.java | 11 +- 2 files changed, 496 insertions(+), 9 deletions(-) create mode 100644 src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilder.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 new file mode 100644 index 000000000..7bfc9d854 --- /dev/null +++ b/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilder.java @@ -0,0 +1,494 @@ +package us.tastybento.bskyblock.island.builders; + +import java.util.UUID; + +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.Chest; +import org.bukkit.block.Sign; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.material.DirectionalContainer; + +import us.tastybento.bskyblock.BSkyBlock; +import us.tastybento.bskyblock.config.Settings; +import us.tastybento.bskyblock.config.Settings.GameType; +import us.tastybento.bskyblock.database.objects.Island; +import us.tastybento.bskyblock.generators.IslandWorld; + +/** + * Fired when a team event happens. + * + * @author tastybento + * @since 1.0 + */ +public class IslandBuilder { + + public enum IslandType { + ISLAND, + NETHER, + END + }; + + private Island island; + private World world; + private IslandType type = IslandType.ISLAND; + //private List companionNames = new ArrayList<>(); + private ItemStack[] defaultChestItems; + //private List companions = new ArrayList<>(); + private UUID playerUUID; + private String playerName; + + public IslandBuilder(Island island) { + super(); + this.island = island; + this.world = island.getWorld(); + } + + + /** + * @param type the type to set + */ + public IslandBuilder setType(IslandType type) { + this.type = type; + switch(type) { + case END: + this.world = IslandWorld.getEndWorld(); + break; + case ISLAND: + this.world = IslandWorld.getIslandWorld(); + break; + case NETHER: + this.world = IslandWorld.getNetherWorld(); + break; + default: + this.world = island.getWorld(); + break; + + } + return this; + } + + + /** + * @param player the player to set + */ + public IslandBuilder setPlayer(Player player) { + this.playerUUID = player.getUniqueId(); + this.playerName = player.getName(); + return this; + } + + + /** + * @param defaultChestItems the defaultChestItems to set + */ + public IslandBuilder setDefaultChestItems(ItemStack[] defaultChestItems) { + this.defaultChestItems = defaultChestItems; + return this; + } + + + public void build() { + // Switch on island type + if (type == IslandType.ISLAND) { + if (Settings.GAMETYPE == GameType.ACIDISLAND) { + generateAcidIslandBlocks(); + } else { + generateIslandBlocks(); + } + } else if (type == IslandType.NETHER){ + generateNetherBlocks(); + } else if (type == IslandType.END){ + generateEndBlocks(); + } + // 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(); + + World world = island.getCenter().getWorld(); + 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++) { + final 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++) { + final 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) { + final 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++) { + final 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) + final Location treeLoc = new Location(world, x, y + 5D, z); + world.generateTree(treeLoc, TreeType.ACACIA); + // Place the cow + //final Location location = new Location(world, x, (islandHeight + 5), z - 2); + + // 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 = 0; + // 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++) { + final 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) + final Location treeLoc = new Location(world, x, y + 5D, z); + world.generateTree(treeLoc, TreeType.TREE); + // Place the cow + //final Location location = new Location(world, x, (islandHeight + 5), z - 2); + + // 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(); + + World world = island.getCenter().getWorld(); + int y = 0; + // 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++) { + final Block blockToChange = world.getBlockAt(x_space, y, z_space); + blockToChange.setType(Material.NETHER_BRICK); + } + } + } + // 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); + + // Add island items + y = islandHeight; + // Add tree (natural) + final Location treeLoc = new Location(world, x, y + 5D, z); + world.generateTree(treeLoc, TreeType.TREE); + // Place the cow + //final Location location = new Location(world, x, (islandHeight + 5), z - 2); + + // 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(); + + World world = island.getCenter().getWorld(); + int y = 0; + // 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++) { + final Block blockToChange = world.getBlockAt(x_space, y, z_space); + blockToChange.setType(Material.END_BRICKS); + } + } + } + // 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; + // Add tree (natural) + final Location treeLoc = new Location(world, x, y + 5D, z); + world.spawnEntity(treeLoc, EntityType.ENDER_CRYSTAL); + //world.generateTree(treeLoc, TreeType.TREE); + // Place the cow + //final Location location = new Location(world, x, (islandHeight + 5), z - 2); + + // 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 (this.playerUUID != null) { + Sign sign = (Sign) blockToChange.getState(); + for (int i=0; i<4; i++) { + sign.setLine(i, BSkyBlock.getPlugin().getLocale(playerUUID).get("signLine" + i).replace("[player]", playerName)); + } + ((org.bukkit.material.Sign) sign.getData()).setFacingDirection(BlockFace.NORTH); + sign.update(); + } + } + + private void placeChest(int x, int y, int z) { + Block blockToChange = world.getBlockAt(x, y, z); + blockToChange.setType(Material.CHEST); + // Only set if the config has items in it + if (defaultChestItems.length > 0) { + final Chest chest = (Chest) blockToChange.getState(); + final Inventory inventory = chest.getInventory(); + inventory.clear(); + inventory.setContents(defaultChestItems); + chest.update(); + } + // Fill the chest and orient it correctly (1.8 faces it north! + DirectionalContainer dc = (DirectionalContainer) blockToChange.getState().getData(); + dc.setFacingDirection(BlockFace.SOUTH); + //blockToChange.setData(dc.getData(), true); + } +} + + diff --git a/src/main/java/us/tastybento/bskyblock/util/SafeSpotTeleport.java b/src/main/java/us/tastybento/bskyblock/util/SafeSpotTeleport.java index 554d46b12..25d30b407 100644 --- a/src/main/java/us/tastybento/bskyblock/util/SafeSpotTeleport.java +++ b/src/main/java/us/tastybento/bskyblock/util/SafeSpotTeleport.java @@ -100,7 +100,6 @@ public class SafeSpotTeleport { //plugin.getLogger().info("DEBUG:world height = " + worldHeight); plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { - @SuppressWarnings("deprecation") @Override public void run() { // Find a safe spot, defined as a solid block, with 2 air spaces above it @@ -111,12 +110,6 @@ public class SafeSpotTeleport { ChunkSnapshot safeChunk = null; ChunkSnapshot portalChunk = null; boolean safeSpotFound = false; - /* - try { - nms = checkVersion(); - } catch (Exception e) { - e.printStackTrace(); - }*/ Vector safeSpotInChunk = null; Vector portalPart = null; double distance = 0D; @@ -128,7 +121,7 @@ public class SafeSpotTeleport { for (y = Math.min(chunk.getHighestBlockYAt(x, z), worldHeight); y >= 0; y--) { //System.out.println("Trying " + (16 * chunk.getX() + x) + " " + y + " " + (16 * chunk.getZ() + z)); // Check for portal - only if this is not a safe home search - if (!setHome && chunk.getBlockTypeId(x, y, z) == Material.PORTAL.getId()) { + if (!setHome && chunk.getBlockType(x, y, z).equals(Material.PORTAL)) { if (portalPart == null || (distance > islandLoc.toVector().distanceSquared(new Vector(x,y,z)))) { // First one found or a closer one, save the chunk the position and the distance portalChunk = chunk; @@ -163,7 +156,7 @@ public class SafeSpotTeleport { x = portalPart.getBlockX(); y = portalPart.getBlockY(); z = portalPart.getBlockZ(); - while (portalChunk.getBlockTypeId(x,y,z) == Material.PORTAL.getId()) { + while (portalChunk.getBlockType(x,y,z).equals(Material.PORTAL)) { y--; } //System.out.print("DEBUG: Portal teleport loc = " + (16 * portalChunk.getX() + x) + "," + (y) + "," + (16 * portalChunk.getZ() + z));