diff --git a/lib/.gitignore b/lib/.gitignore deleted file mode 100644 index c7183b066..000000000 --- a/lib/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/spigot-1.12.jar diff --git a/lib/library-1.12.jar b/lib/library-1.12.jar deleted file mode 100644 index b5cdce841..000000000 Binary files a/lib/library-1.12.jar and /dev/null differ diff --git a/pom.xml b/pom.xml index e0bd9b63e..4fa09c087 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,6 @@ 1.8 UTF-8 UTF-8 - ${project.basedir}/lib clean package install @@ -81,13 +80,6 @@ VaultAPI LATEST - - spigotmc.org - library-1.12 - system - ${server.jars}/library-1.12.jar - 1.12 - diff --git a/schematics/harder.schematic b/schematics/harder.schematic deleted file mode 100644 index 9e316a72c..000000000 Binary files a/schematics/harder.schematic and /dev/null differ diff --git a/schematics/island.schematic b/schematics/island.schematic deleted file mode 100644 index 8370749d6..000000000 Binary files a/schematics/island.schematic and /dev/null differ diff --git a/schematics/nether.schematic b/schematics/nether.schematic deleted file mode 100644 index ba3b16e86..000000000 Binary files a/schematics/nether.schematic and /dev/null differ diff --git a/src/main/java/us/tastybento/bskyblock/BSkyBlock.java b/src/main/java/us/tastybento/bskyblock/BSkyBlock.java index 5b67a572e..c7e6a5c6c 100755 --- a/src/main/java/us/tastybento/bskyblock/BSkyBlock.java +++ b/src/main/java/us/tastybento/bskyblock/BSkyBlock.java @@ -27,7 +27,6 @@ import us.tastybento.bskyblock.listeners.protection.IslandGuard; import us.tastybento.bskyblock.listeners.protection.IslandGuard1_8; import us.tastybento.bskyblock.listeners.protection.IslandGuard1_9; import us.tastybento.bskyblock.listeners.protection.NetherEvents; -import us.tastybento.bskyblock.schematics.SchematicsMgr; import us.tastybento.bskyblock.util.VaultHelper; /** @@ -44,9 +43,6 @@ public class BSkyBlock extends JavaPlugin { private IslandsManager islandsManager; private OfflineHistoryMessages offlineHistoryMessages; - // Schematics - private SchematicsMgr schematicsManager; - // Metrics private Metrics metrics; @@ -114,7 +110,6 @@ public class BSkyBlock extends JavaPlugin { new ItemStack(Material.COBBLESTONE,5), new ItemStack(Material.SAPLING,2) }; - schematicsManager = new SchematicsMgr(plugin); Settings.defaultLanguage = "en-US"; localeManager = new LocaleManager(plugin); @@ -236,13 +231,6 @@ public class BSkyBlock extends JavaPlugin { return plugin; } - /** - * @return the schematics - */ - public SchematicsMgr getSchematics() { - return schematicsManager; - } - /** * @param sender * @return Locale object for sender diff --git a/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java b/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java index 881afefc0..23b47e444 100755 --- a/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java @@ -30,7 +30,6 @@ import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.database.managers.island.NewIsland; import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.panels.LanguagePanel; -import us.tastybento.bskyblock.schematics.Schematic; import us.tastybento.bskyblock.util.Util; import us.tastybento.bskyblock.util.VaultHelper; @@ -332,11 +331,9 @@ public class IslandCommand extends AbstractCommand { // Create new island and then delete the old one if (DEBUG) plugin.getLogger().info("DEBUG: making new island "); - Schematic schematic = plugin.getSchematics().getSchematic("default"); try { NewIsland.builder() .player(player) - .schematic(schematic) .oldIsland(oldIsland) .build(); } catch (IOException e) { @@ -1527,11 +1524,9 @@ public class IslandCommand extends AbstractCommand { */ protected void createIsland(Player player) { //TODO: Add panels, make a selection. - Schematic schematic = plugin.getSchematics().getSchematic("default"); try { NewIsland.builder() .player(player) - .schematic(schematic) .build(); } catch (IOException e) { plugin.getLogger().severe("Could not create island for player."); diff --git a/src/main/java/us/tastybento/bskyblock/database/managers/island/NewIsland.java b/src/main/java/us/tastybento/bskyblock/database/managers/island/NewIsland.java index fd8ceb8cc..8e2eb5873 100644 --- a/src/main/java/us/tastybento/bskyblock/database/managers/island/NewIsland.java +++ b/src/main/java/us/tastybento/bskyblock/database/managers/island/NewIsland.java @@ -10,8 +10,8 @@ import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.generators.IslandWorld; -import us.tastybento.bskyblock.schematics.Schematic; -import us.tastybento.bskyblock.schematics.Schematic.PasteReason; +import us.tastybento.bskyblock.island.builders.IslandBuilder; +import us.tastybento.bskyblock.island.builders.IslandBuilder.IslandType; /** * Create and paste a new island @@ -22,14 +22,10 @@ public class NewIsland { private static final boolean DEBUG = false; private final BSkyBlock plugin = BSkyBlock.getPlugin(); private Island island; - private final Island oldIsland; - private final Schematic schematic; private final Player player; - private NewIsland(Island oldIsland, Schematic schematic, Player player) { + private NewIsland(Island oldIsland, Player player) { super(); - this.oldIsland = oldIsland; - this.schematic = schematic; this.player = player; newIsland(); if (oldIsland != null) { @@ -60,7 +56,6 @@ public class NewIsland { */ public static class Builder { private Island oldIsland; - private Schematic schematic; private Player player; public Builder oldIsland(Island oldIsland) { @@ -68,10 +63,6 @@ public class NewIsland { return this; } - public Builder schematic(Schematic schematic) { - this.schematic = schematic; - return this; - } public Builder player(Player player) { this.player = player; @@ -79,8 +70,8 @@ public class NewIsland { } public Island build() throws IOException { - if (schematic != null && player != null) { - NewIsland newIsland = new NewIsland(oldIsland,schematic, player); + if (player != null) { + NewIsland newIsland = new NewIsland(oldIsland, player); return newIsland.getIsland(); } throw new IOException("Insufficient parameters. Must have a schematic and a player"); @@ -88,8 +79,7 @@ public class NewIsland { } /** - * Makes an island using schematic. No permission checks are made. They have to be decided - * before this method is called. + * Makes an island. */ public void newIsland() { if (DEBUG) @@ -107,8 +97,7 @@ public class NewIsland { plugin.getLogger().info("DEBUG: found " + next); // Add to the grid - Island myIsland = plugin.getIslands().createIsland(next, playerUUID); - myIsland.setLevelHandicap(schematic.getLevelHandicap()); + island = plugin.getIslands().createIsland(next, playerUUID); // Save the player so that if the server is reset weird things won't happen plugin.getPlayers().save(true); plugin.getIslands().save(true); @@ -118,76 +107,31 @@ public class NewIsland { // Set the biome //BiomesPanel.setIslandBiome(next, schematic.getBiome()); - // Teleport to the new home - if (schematic.isPlayerSpawn()) { - // Set home and teleport - plugin.getPlayers().setHomeLocation(playerUUID, schematic.getPlayerSpawn(next), 1); + // Set home loction + plugin.getPlayers().setHomeLocation(playerUUID, next, 1); + + // Create island + new IslandBuilder(island) + .setPlayer(player) + .setDefaultChestItems(Settings.chestItems) + .setType(IslandType.ISLAND) + .build(); + if (Settings.netherGenerate && Settings.netherIslands && IslandWorld.getNetherWorld() != null) { + new IslandBuilder(island) + .setPlayer(player) + .setDefaultChestItems(Settings.chestItems) + .setType(IslandType.NETHER) + .build(); } - - // Create island based on schematic - if (schematic != null) { - //plugin.getLogger().info("DEBUG: pasting schematic " + schematic.getName() + " " + schematic.getPerm()); - //plugin.getLogger().info("DEBUG: nether world is " + BSkyBlock.getNetherWorld()); - // Paste the starting island. If it is a HELL biome, then we start in the Nether - if (Settings.netherGenerate && schematic.isInNether() && Settings.netherIslands && IslandWorld.getNetherWorld() != null) { - // Nether start - // Paste the overworld if it exists - if (!schematic.getPartnerName().isEmpty()) { - // A partner schematic is available - pastePartner(plugin.getSchematics().getSchematic(schematic.getPartnerName()),next, player); - } - // Switch home location to the Nether - next = next.toVector().toLocation(IslandWorld.getNetherWorld()); - // Set the player's island location to this new spot - //plugin.getPlayers().setIslandLocation(playerUUID, next); - schematic.pasteSchematic(next, player, true, firstTime ? PasteReason.NEW_ISLAND: PasteReason.RESET, oldIsland); - } else { - // Over world start - //plugin.getLogger().info("DEBUG: pasting"); - //long timer = System.nanoTime(); - // Paste the island and teleport the player home - schematic.pasteSchematic(next, player, true, firstTime ? PasteReason.NEW_ISLAND: PasteReason.RESET, oldIsland); - //double diff = (System.nanoTime() - timer)/1000000; - //plugin.getLogger().info("DEBUG: nano time = " + diff + " ms"); - //plugin.getLogger().info("DEBUG: pasted overworld"); - if (Settings.netherGenerate && Settings.netherIslands && IslandWorld.getNetherWorld() != null) { - // Paste the other world schematic - final Location netherLoc = next.toVector().toLocation(IslandWorld.getNetherWorld()); - if (schematic.getPartnerName().isEmpty()) { - // This will paste the over world schematic again - //plugin.getLogger().info("DEBUG: pasting nether"); - pastePartner(schematic, netherLoc, player); - //plugin.getLogger().info("DEBUG: pasted nether"); - } else { - if (plugin.getSchematics().getAll().containsKey(schematic.getPartnerName())) { - //plugin.getLogger().info("DEBUG: pasting partner"); - // A partner schematic is available - pastePartner(plugin.getSchematics().getAll().get(schematic.getPartnerName()),netherLoc, player); - } else { - plugin.getLogger().severe("Partner schematic heading '" + schematic.getPartnerName() + "' does not exist"); - } - } - } - } + if (Settings.endGenerate && Settings.endIslands && IslandWorld.getEndWorld() != null) { + new IslandBuilder(island) + .setPlayer(player) + .setDefaultChestItems(Settings.chestItems) + .setType(IslandType.END) + .build(); } } - /** - * Does a delayed pasting of the partner island - * @param schematic - * @param player - */ - private void pastePartner(final Schematic schematic, final Location loc, final Player player) { - plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() { - - @Override - public void run() { - schematic.pasteSchematic(loc, player, false, PasteReason.PARTNER, null); - - }}, 60L); - - } - /** * Get the location of next free island spot * @param playerUUID 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 7bfc9d854..08d7dc0b3 100644 --- a/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilder.java +++ b/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilder.java @@ -8,13 +8,13 @@ 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.BlockState; import org.bukkit.block.Sign; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; -import org.bukkit.material.DirectionalContainer; +import org.bukkit.material.Chest; import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.config.Settings; @@ -123,18 +123,17 @@ public class IslandBuilder { 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); + 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); + Block b = world.getBlockAt(x_space, y, z_space); if (y < (islandHeight / 2)) { b.setType(Material.SANDSTONE); } else { @@ -147,7 +146,7 @@ public class IslandBuilder { 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); + Block b = world.getBlockAt(x_space, y, z_space); b.setType(Material.STATIONARY_WATER); } } @@ -156,7 +155,7 @@ public class IslandBuilder { 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); + Block blockToChange = world.getBlockAt(x_space, y, z_space); blockToChange.setType(Material.GRASS); } } @@ -209,10 +208,10 @@ public class IslandBuilder { // Add island items y = islandHeight; // Add tree (natural) - final Location treeLoc = new Location(world, x, y + 5D, z); + 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); + //Location location = new Location(world, x, (islandHeight + 5), z - 2); // Place a helpful sign in front of player placeSign(x, islandHeight + 5, z + 3); @@ -235,13 +234,19 @@ public class IslandBuilder { 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); + 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); @@ -290,10 +295,10 @@ public class IslandBuilder { // Add island items y = islandHeight; // Add tree (natural) - final Location treeLoc = new Location(world, x, y + 5D, z); + 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); + //Location location = new Location(world, x, (islandHeight + 5), z - 2); // Place a helpful sign in front of player placeSign(x, islandHeight + 5, z + 3); @@ -309,17 +314,20 @@ public class IslandBuilder { 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); + 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); @@ -368,10 +376,10 @@ public class IslandBuilder { // Add island items y = islandHeight; // Add tree (natural) - final Location treeLoc = new Location(world, x, y + 5D, z); + 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); + //Location location = new Location(world, x, (islandHeight + 5), z - 2); // Place a helpful sign in front of player placeSign(x, islandHeight + 5, z + 3); @@ -387,17 +395,21 @@ public class IslandBuilder { 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); + 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); @@ -446,11 +458,11 @@ public class IslandBuilder { // Add island items y = islandHeight; // Add tree (natural) - final Location treeLoc = new Location(world, x, y + 5D, z); + 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); + //Location location = new Location(world, x, (islandHeight + 5), z - 2); // Place a helpful sign in front of player placeSign(x, islandHeight + 5, z + 3); @@ -474,20 +486,17 @@ public class IslandBuilder { } 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); - // Only set if the config has items in it + BlockState state = blockToChange.getState(); + Chest chest = new Chest(BlockFace.SOUTH); + state.setData(chest); if (defaultChestItems.length > 0) { - final Chest chest = (Chest) blockToChange.getState(); - final Inventory inventory = chest.getInventory(); - inventory.clear(); - inventory.setContents(defaultChestItems); - chest.update(); + InventoryHolder ih = (InventoryHolder) state; + ih.getInventory().setContents(defaultChestItems); } - // 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); + state.update(); } } diff --git a/src/main/java/us/tastybento/bskyblock/listeners/NetherPortals.java b/src/main/java/us/tastybento/bskyblock/listeners/NetherPortals.java index 6c7ee9b4f..85f28e895 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/NetherPortals.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/NetherPortals.java @@ -19,8 +19,8 @@ import us.tastybento.bskyblock.database.managers.island.IslandsManager; import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island.SettingsFlag; import us.tastybento.bskyblock.generators.IslandWorld; -import us.tastybento.bskyblock.schematics.Schematic; -import us.tastybento.bskyblock.schematics.Schematic.PasteReason; +import us.tastybento.bskyblock.island.builders.IslandBuilder; +import us.tastybento.bskyblock.island.builders.IslandBuilder.IslandType; import us.tastybento.bskyblock.util.SafeSpotTeleport; import us.tastybento.bskyblock.util.Util; import us.tastybento.bskyblock.util.VaultHelper; @@ -220,18 +220,12 @@ public class NetherPortals implements Listener { if (plugin.getIslands().bigScan(netherIsland, 20) == null) { if (DEBUG) plugin.getLogger().info("DEBUG: big scan is null"); - plugin.getLogger().warning("Creating nether island for " + event.getPlayer().getName() + " using default nether schematic"); - Schematic nether = plugin.getSchematics().getSchematic("nether"); - if (nether != null) { - if (DEBUG) - plugin.getLogger().info("DEBUG: pasting at " + island.getCenter().toVector()); - nether.pasteSchematic(netherIsland, event.getPlayer(), false, PasteReason.PARTNER, island); - } else { - plugin.getLogger().severe("Cannot teleport player to nether because there is no nether schematic"); - event.setCancelled(true); - Util.sendMessage(event.getPlayer(), plugin.getLocale(event.getPlayer().getUniqueId()).get("warps.error.NotSafe")); - return; - } + plugin.getLogger().warning("Creating nether island for " + event.getPlayer().getName()); + new IslandBuilder(island) + .setPlayer(event.getPlayer()) + .setDefaultChestItems(Settings.chestItems) + .setType(IslandType.NETHER) + .build(); } } if (DEBUG) diff --git a/src/main/java/us/tastybento/bskyblock/schematics/BannerBlock.java b/src/main/java/us/tastybento/bskyblock/schematics/BannerBlock.java deleted file mode 100644 index b8340977f..000000000 --- a/src/main/java/us/tastybento/bskyblock/schematics/BannerBlock.java +++ /dev/null @@ -1,139 +0,0 @@ -package us.tastybento.bskyblock.schematics; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.bukkit.DyeColor; -import org.bukkit.block.Banner; -import org.bukkit.block.Block; -import org.bukkit.block.banner.Pattern; -import org.bukkit.block.banner.PatternType; - -import us.tastybento.org.jnbt.CompoundTag; -import us.tastybento.org.jnbt.IntTag; -import us.tastybento.org.jnbt.ListTag; -import us.tastybento.org.jnbt.StringTag; -import us.tastybento.org.jnbt.Tag; - -/** - * This class describes banners and is used in schematic importing - * - * @author tastybento - * - */ -public class BannerBlock { - private DyeColor bannerBaseColor; - private List bannerPattern; - - private static HashMap patternKey; - // bs, mc, cr, drs, dls, hhb, mr, hh, sc, gru, ss, gra, ts, ms, tt - // bts, tr, tts, sku, cre, tl, vhr, vh, bo, cbo, bri - - // ss, tt - static { - patternKey = new HashMap<>(); - patternKey.put("", PatternType.BASE); - patternKey.put("bo", PatternType.BORDER); - patternKey.put("bri", PatternType.BRICKS); - patternKey.put("mc", PatternType.CIRCLE_MIDDLE); - patternKey.put("cre", PatternType.CREEPER); - patternKey.put("cr", PatternType.CROSS); - patternKey.put("cbo", PatternType.CURLY_BORDER); - patternKey.put("ld", PatternType.DIAGONAL_LEFT); - patternKey.put("lud", PatternType.DIAGONAL_LEFT_MIRROR); - patternKey.put("rd", PatternType.DIAGONAL_RIGHT); - patternKey.put("rud", PatternType.DIAGONAL_RIGHT_MIRROR); - patternKey.put("flo", PatternType.FLOWER); - patternKey.put("gra", PatternType.GRADIENT); - patternKey.put("gru", PatternType.GRADIENT_UP); - patternKey.put("hh", PatternType.HALF_HORIZONTAL); - patternKey.put("hhb", PatternType.HALF_HORIZONTAL_MIRROR); - patternKey.put("vh", PatternType.HALF_VERTICAL); - patternKey.put("vhr", PatternType.HALF_VERTICAL_MIRROR); - patternKey.put("moj", PatternType.MOJANG); - patternKey.put("mr", PatternType.RHOMBUS_MIDDLE); - patternKey.put("sku", PatternType.SKULL); - patternKey.put("bl", PatternType.SQUARE_BOTTOM_LEFT); - patternKey.put("br", PatternType.SQUARE_BOTTOM_RIGHT); - patternKey.put("tl", PatternType.SQUARE_TOP_LEFT); - patternKey.put("tr", PatternType.SQUARE_TOP_RIGHT); - patternKey.put("sc", PatternType.STRAIGHT_CROSS); - patternKey.put("bs", PatternType.STRIPE_BOTTOM); - patternKey.put("ms", PatternType.STRIPE_CENTER); - patternKey.put("dls", PatternType.STRIPE_DOWNLEFT); - patternKey.put("drs", PatternType.STRIPE_DOWNRIGHT); - patternKey.put("ls", PatternType.STRIPE_LEFT); - patternKey.put("ms", PatternType.STRIPE_MIDDLE); - patternKey.put("rs", PatternType.STRIPE_RIGHT); - patternKey.put("ss", PatternType.STRIPE_SMALL); - patternKey.put("ts", PatternType.STRIPE_TOP); - patternKey.put("bt", PatternType.TRIANGLE_BOTTOM); - patternKey.put("tt", PatternType.TRIANGLE_TOP); - patternKey.put("bts", PatternType.TRIANGLES_BOTTOM); - patternKey.put("tts", PatternType.TRIANGLES_TOP); - } - - public boolean set(Block block) { - Banner banner = (Banner) block.getState(); - banner.setBaseColor(bannerBaseColor); - banner.setPatterns(bannerPattern); - banner.update(); - return true; - } - - @SuppressWarnings("deprecation") - public boolean prep(Map tileData) { - // Format for banner is: - // Patterns = List of patterns - // id = String "BannerBlock" - // Base = Int color - // Then the location - // z = Int - // y = Int - // x = Int - try { - // Do the base color - int baseColor = 15 - ((IntTag) tileData.get("Base")).getValue(); - // //ASkyBlock.getPlugin().getLogger().info("Base value = " + - // baseColor); - // baseColor green = 10 - bannerBaseColor = DyeColor.getByDyeData((byte) baseColor); - // Do the patterns (no idea if this will work or not) - bannerPattern = new ArrayList<>(); - ListTag patterns = (ListTag) tileData.get("Patterns"); - if (patterns != null) { - for (Tag pattern : patterns.getValue()) { - // ASkyBlock.getPlugin().getLogger().info("pattern = " + - // pattern); - // Translate pattern to PatternType - if (pattern instanceof CompoundTag) { - CompoundTag patternColor = (CompoundTag) pattern; - // The tag is made up of pattern (String) and color - // (int) - Map patternValue = patternColor.getValue(); - StringTag mark = (StringTag) patternValue.get("Pattern"); - Integer markColor = 15 - ((IntTag) patternValue.get("Color")).getValue(); - // ASkyBlock.getPlugin().getLogger().info("mark = " + - // mark.getValue()); - // ASkyBlock.getPlugin().getLogger().info("color = " + - // markColor); - DyeColor dColor = DyeColor.getByDyeData(markColor.byteValue()); - // ASkyBlock.getPlugin().getLogger().info(" dye color = " - // + dColor.toString()); - if (patternKey.containsKey(mark.getValue())) { - Pattern newPattern = new Pattern(dColor, patternKey.get(mark.getValue())); - bannerPattern.add(newPattern); - } - } - } - } - } catch (Exception e) { - e.printStackTrace(); - } - - return true; - } - -} diff --git a/src/main/java/us/tastybento/bskyblock/schematics/EntityObject.java b/src/main/java/us/tastybento/bskyblock/schematics/EntityObject.java deleted file mode 100644 index e7420c9c5..000000000 --- a/src/main/java/us/tastybento/bskyblock/schematics/EntityObject.java +++ /dev/null @@ -1,347 +0,0 @@ -package us.tastybento.bskyblock.schematics; - -import org.bukkit.entity.EntityType; -import org.bukkit.util.BlockVector; -import org.bukkit.util.Vector; - -public class EntityObject { - private EntityType type; - private BlockVector location; - private byte color; - private float yaw; - private float pitch; - private boolean sheared; - private Vector motion; - private int age; - private int rabbitType; - private int catType; - private boolean sitting; - private int profession; - private boolean carryingChest; - private boolean owned; - private byte collarColor; - // Paintings - private byte facing; - private String motive; - // Item Frames - private float itemDropChance; - private byte itemRotation; - // Coordinates for tiles - private Double tileX = null; - private Double tileY = null; - private Double tileZ = null; - // Items informations - private Byte count = null; - private Short damage = null; - private String id = null; - - /** - * @return the type - */ - public EntityType getType() { - return type; - } - /** - * @param type the type to set - */ - public void setType(EntityType type) { - this.type = type; - } - /** - * @return the location - */ - public BlockVector getLocation() { - return location; - } - /** - * @param location the location to set - */ - public void setLocation(BlockVector location) { - this.location = location; - } - /** - * @return the color - */ - public byte getColor() { - return color; - } - /** - * @param color the color to set - */ - public void setColor(byte color) { - this.color = color; - } - /** - * @return the yaw - */ - public float getYaw() { - return yaw; - } - /** - * @param yaw the yaw to set - */ - public void setYaw(float yaw) { - this.yaw = yaw; - } - - /** - * @return the pitch - */ - public float getPitch() { - return pitch; - } - - /** - * @param pitch - */ - public void setPitch(float pitch) { - this.pitch = pitch; - } - /** - * @return the sheared - */ - public boolean isSheared() { - return sheared; - } - /** - * @param sheared the sheared to set - */ - public void setSheared(boolean sheared) { - this.sheared = sheared; - } - /** - * @return the motion - */ - public Vector getMotion() { - return motion; - } - /** - * @param motion the motion to set - */ - public void setMotion(Vector motion) { - this.motion = motion; - } - /** - * @return the age - */ - public int getAge() { - return age; - } - /** - * @param age the age to set - */ - public void setAge(int age) { - this.age = age; - } - /** - * @return the profession - */ - public int getProfession() { - return profession; - } - /** - * @param profession the profession to set - */ - public void setProfession(int profession) { - this.profession = profession; - } - /** - * @return the rabbitType - */ - public int getRabbitType() { - return rabbitType; - } - /** - * @param rabbitType the rabbitType to set - */ - public void setRabbitType(int rabbitType) { - this.rabbitType = rabbitType; - } - /** - * @return the carryingChest - */ - public boolean isCarryingChest() { - return carryingChest; - } - /** - * @param carryingChest the carryingChest to set - */ - public void setCarryingChest(byte carryingChest) { - if (carryingChest > (byte)0) { - this.carryingChest = true; - } - this.carryingChest = false; - } - /** - * @return the catType - */ - public int getCatType() { - return catType; - } - /** - * @param catType the catType to set - */ - public void setCatType(int catType) { - this.catType = catType; - } - /** - * @return the sitting - */ - public boolean isSitting() { - return sitting; - } - /** - * @param sitting the sitting to set - */ - public void setSitting(byte sitting) { - if (sitting > (byte)0) { - this.sitting = true; - } - this.sitting = false; - } - /** - * @return the owned - */ - public boolean isOwned() { - return owned; - } - /** - * @param owned the owned to set - */ - public void setOwned(boolean owned) { - this.owned = owned; - } - /** - * @return the collarColor - */ - public byte getCollarColor() { - return collarColor; - } - /** - * @param collarColor the collarColor to set - */ - public void setCollarColor(byte collarColor) { - this.collarColor = collarColor; - } - /** - * @return the facing - */ - public byte getFacing() { - return facing; - } - /** - * @param facing the facing to set - */ - public void setFacing(byte facing) { - this.facing = facing; - } - /** - * @return the motive - */ - public String getMotive() { - return motive; - } - /** - * @param motive the motive to set - */ - public void setMotive(String motive) { - this.motive = motive; - } - /** - * @return the itemDropChance - */ - public float getItemDropChance() { - return itemDropChance; - } - /** - * @param itemDropChance the itemDropChance to set - */ - public void setItemDropChance(float itemDropChance) { - this.itemDropChance = itemDropChance; - } - /** - * @return the itemRotation - */ - public byte getItemRotation() { - return itemRotation; - } - /** - * @param itemRotation the itemRotation to set - */ - public void setItemRotation(byte itemRotation) { - this.itemRotation = itemRotation; - } - /** - * @return the tileX - */ - public Double getTileX() { - return tileX; - } - /** - * @param tileX the tileX to set - */ - public void setTileX(Double tileX) { - this.tileX = tileX; - } - /** - * @return the tileX - */ - public Double getTileY() { - return tileY; - } - /** - * @param tileY the tileY to set - */ - public void setTileY(Double tileY) { - this.tileY = tileY; - } - /** - * @return the tileX - */ - public Double getTileZ() { - return tileZ; - } - /** - * @param tileZ the tileZ to set - */ - public void setTileZ(Double tileZ) { - this.tileZ = tileZ; - } - /** - * @return the count - */ - public Byte getCount() { - return count; - } - - /** - * @param count the count to set - */ - public void setCount(Byte count) { - this.count = count; - } - /** - * @return the damage - */ - public Short getDamage() { - return damage; - } - /** - * @param damage the damage to set - */ - public void setDamage(Short damage) { - this.damage = damage; - } - /** - * @return the id - */ - public String getId() { - return id; - } - /** - * @param id the id to set - */ - public void setId(String id) { - this.id = id; - } -} diff --git a/src/main/java/us/tastybento/bskyblock/schematics/IslandBlock.java b/src/main/java/us/tastybento/bskyblock/schematics/IslandBlock.java deleted file mode 100644 index 6b0146390..000000000 --- a/src/main/java/us/tastybento/bskyblock/schematics/IslandBlock.java +++ /dev/null @@ -1,563 +0,0 @@ -package us.tastybento.bskyblock.schematics; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.block.Chest; -import org.bukkit.block.CreatureSpawner; -import org.bukkit.block.DoubleChest; -import org.bukkit.block.Sign; -import org.bukkit.entity.EntityType; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; -import org.json.simple.JSONValue; -import org.json.simple.parser.ContainerFactory; -import org.json.simple.parser.JSONParser; -import org.json.simple.parser.ParseException; - -import us.tastybento.bskyblock.util.nms.NMSAbstraction; -import us.tastybento.org.jnbt.CompoundTag; -import us.tastybento.org.jnbt.ListTag; -import us.tastybento.org.jnbt.StringTag; -import us.tastybento.org.jnbt.Tag; - -public class IslandBlock { - private short typeId; - private byte data; - private int x; - private int y; - private int z; - private List signText; - private BannerBlock banner; - private EntityType spawnerBlockType; - // Chest contents - private HashMap chestContents = new HashMap<>(); - public static final HashMap WEtoM = new HashMap<>(); - public static final HashMap WEtoME = new HashMap<>(); - - static { - // Establish the World Edit to Material look up - // V1.8 items - if (!Bukkit.getServer().getVersion().contains("(MC: 1.7")) { - - WEtoM.put("ARMORSTAND",Material.ARMOR_STAND); - WEtoM.put("ACACIA_DOOR",Material.ACACIA_DOOR_ITEM); - WEtoM.put("BIRCH_DOOR",Material.BIRCH_DOOR_ITEM); - WEtoM.put("BIRCH_STAIRS",Material.BIRCH_WOOD_STAIRS); - WEtoM.put("DARK_OAK_DOOR",Material.DARK_OAK_DOOR_ITEM); - WEtoM.put("JUNGLE_DOOR",Material.JUNGLE_DOOR_ITEM); - WEtoM.put("SLIME",Material.SLIME_BLOCK); - WEtoM.put("SPRUCE_DOOR",Material.SPRUCE_DOOR_ITEM); - } - WEtoM.put("BREWING_STAND",Material.BREWING_STAND_ITEM); - WEtoM.put("CARROT_ON_A_STICK",Material.CARROT_STICK); - WEtoM.put("CARROT",Material.CARROT_ITEM); - WEtoM.put("CAULDRON", Material.CAULDRON_ITEM); - WEtoM.put("CLOCK", Material.WATCH); - WEtoM.put("COBBLESTONE_WALL",Material.COBBLE_WALL); - WEtoM.put("COMMAND_BLOCK",Material.COMMAND); - WEtoM.put("COMMANDBLOCK_MINECART",Material.COMMAND_MINECART); - WEtoM.put("COMPARATOR",Material.REDSTONE_COMPARATOR); - WEtoM.put("COOKED_PORKCHOP", Material.GRILLED_PORK); - WEtoM.put("CLOCK", Material.WATCH); - WEtoM.put("CRAFTING_TABLE", Material.WORKBENCH); - WEtoM.put("DIAMOND_HORSE_ARMOR",Material.DIAMOND_BARDING); - WEtoM.put("DIAMOND_SHOVEL",Material.DIAMOND_SPADE); - WEtoM.put("DYE",Material.INK_SACK); - WEtoM.put("ENCHANTING_TABLE", Material.ENCHANTMENT_TABLE); //1.11 rename - WEtoM.put("END_PORTAL_FRAME",Material.ENDER_PORTAL_FRAME); - WEtoM.put("END_PORTAL", Material.ENDER_PORTAL); // 1.11 rename - WEtoM.put("END_STONE", Material.ENDER_STONE); - WEtoM.put("EXPERIENCE_BOTTLE",Material.EXP_BOTTLE); - WEtoM.put("FILLED_MAP",Material.MAP); - WEtoM.put("FIRE_CHARGE",Material.FIREBALL); - WEtoM.put("FIREWORKS",Material.FIREWORK); - WEtoM.put("FLOWER_POT", Material.FLOWER_POT_ITEM); - WEtoM.put("GLASS_PANE",Material.THIN_GLASS); - WEtoM.put("GOLDEN_CHESTPLATE",Material.GOLD_CHESTPLATE); - WEtoM.put("GOLDEN_HORSE_ARMOR",Material.GOLD_BARDING); - WEtoM.put("GOLDEN_LEGGINGS",Material.GOLD_LEGGINGS); - WEtoM.put("GOLDEN_PICKAXE",Material.GOLD_PICKAXE); - WEtoM.put("GOLDEN_RAIL",Material.POWERED_RAIL); - WEtoM.put("GOLDEN_SHOVEL",Material.GOLD_SPADE); - WEtoM.put("GOLDEN_SWORD", Material.GOLD_SWORD); - WEtoM.put("GOLDEN_HELMET", Material.GOLD_HELMET); - WEtoM.put("GOLDEN_HOE", Material.GOLD_HOE); - WEtoM.put("GOLDEN_AXE", Material.GOLD_AXE); - WEtoM.put("GOLDEN_BOOTS", Material.GOLD_BOOTS); - WEtoM.put("GUNPOWDER", Material.SULPHUR); - WEtoM.put("HARDENED_CLAY",Material.HARD_CLAY); - WEtoM.put("HEAVY_WEIGHTED_PRESSURE_PLATE",Material.GOLD_PLATE); - WEtoM.put("IRON_BARS",Material.IRON_FENCE); - WEtoM.put("IRON_HORSE_ARMOR",Material.IRON_BARDING); - WEtoM.put("IRON_SHOVEL",Material.IRON_SPADE); - WEtoM.put("LEAD",Material.LEASH); - WEtoM.put("LEAVES2",Material.LEAVES_2); - WEtoM.put("LIGHT_WEIGHTED_PRESSURE_PLATE",Material.IRON_PLATE); - WEtoM.put("LOG2",Material.LOG_2); - WEtoM.put("MAP",Material.EMPTY_MAP); - WEtoM.put("MYCELIUM", Material.MYCEL); - WEtoM.put("NETHER_BRICK_FENCE",Material.NETHER_FENCE); - WEtoM.put("NETHER_WART",Material.NETHER_STALK); - WEtoM.put("NETHERBRICK",Material.NETHER_BRICK_ITEM); - WEtoM.put("OAK_STAIRS",Material.WOOD_STAIRS); - WEtoM.put("POTATO", Material.POTATO_ITEM); - WEtoM.put("RAIL",Material.RAILS); - WEtoM.put("RECORD_11",Material.RECORD_11); - WEtoM.put("RECORD_13",Material.GOLD_RECORD); - WEtoM.put("RECORD_BLOCKS",Material.RECORD_3); - WEtoM.put("RECORD_CAT",Material.GREEN_RECORD); - WEtoM.put("RECORD_CHIRP",Material.RECORD_4); - WEtoM.put("RECORD_FAR",Material.RECORD_5); - WEtoM.put("RECORD_MALL",Material.RECORD_6); - WEtoM.put("RECORD_MELLOHI",Material.RECORD_7); - WEtoM.put("RECORD_STAL",Material.RECORD_8); - WEtoM.put("RECORD_STRAD",Material.RECORD_9); - WEtoM.put("RECORD_WAIT",Material.RECORD_12); - WEtoM.put("RECORD_WARD",Material.RECORD_10); - WEtoM.put("RED_FLOWER",Material.RED_ROSE); - WEtoM.put("REEDS",Material.SUGAR_CANE); - WEtoM.put("REPEATER",Material.DIODE); - WEtoM.put("SKULL", Material.SKULL_ITEM); - WEtoM.put("SPAWN_EGG",Material.MONSTER_EGG); - WEtoM.put("STONE_BRICK_STAIRS",Material.BRICK_STAIRS); - WEtoM.put("STONE_BRICK_STAIRS",Material.SMOOTH_STAIRS); - WEtoM.put("STONE_SHOVEL",Material.STONE_SPADE); - WEtoM.put("STONE_SLAB",Material.STEP); - WEtoM.put("STONE_STAIRS",Material.COBBLESTONE_STAIRS); - WEtoM.put("TNT_MINECART",Material.EXPLOSIVE_MINECART); - WEtoM.put("WATERLILY",Material.WATER_LILY); - WEtoM.put("WHEAT_SEEDS", Material.SEEDS); - WEtoM.put("WOODEN_AXE",Material.WOOD_AXE); - WEtoM.put("WOODEN_BUTTON",Material.WOOD_BUTTON); - WEtoM.put("WOODEN_DOOR",Material.WOOD_DOOR); - WEtoM.put("WOODEN_HOE",Material.WOOD_HOE); - WEtoM.put("WOODEN_PICKAXE",Material.WOOD_PICKAXE); - WEtoM.put("WOODEN_PRESSURE_PLATE",Material.WOOD_PLATE); - WEtoM.put("WOODEN_SHOVEL",Material.WOOD_SPADE); - WEtoM.put("WOODEN_SLAB",Material.WOOD_STEP); - WEtoM.put("WOODEN_SWORD",Material.WOOD_SWORD); - WEtoM.put("MUSHROOM_STEW",Material.MUSHROOM_SOUP); - // Entities - WEtoME.put("LAVASLIME", EntityType.MAGMA_CUBE); - WEtoME.put("ENTITYHORSE", EntityType.HORSE); - WEtoME.put("OZELOT", EntityType.OCELOT); - WEtoME.put("MUSHROOMCOW", EntityType.MUSHROOM_COW); - WEtoME.put("MOOSHROOM", EntityType.MUSHROOM_COW); // 1.11 rename - WEtoME.put("PIGZOMBIE", EntityType.PIG_ZOMBIE); - WEtoME.put("ZOMBIE_PIGMAN", EntityType.PIG_ZOMBIE); // 1.11 rename - WEtoME.put("CAVESPIDER", EntityType.CAVE_SPIDER); - WEtoME.put("XPORB", EntityType.EXPERIENCE_ORB); - WEtoME.put("XP_ORB", EntityType.EXPERIENCE_ORB); // 1.11 rename - WEtoME.put("MINECARTRIDEABLE", EntityType.MINECART); - WEtoME.put("MINECARTHOPPER", EntityType.MINECART_HOPPER); - WEtoME.put("HOPPER_MINECART", EntityType.MINECART_HOPPER); - WEtoME.put("MINECARTFURNACE", EntityType.MINECART_FURNACE); - WEtoME.put("FURNACE_MINECART", EntityType.MINECART_FURNACE); - WEtoME.put("MINECARTMOBSPAWNER", EntityType.MINECART_MOB_SPAWNER); - WEtoME.put("SPAWNER_MINECART", EntityType.MINECART_MOB_SPAWNER); // 1.11 rename - WEtoME.put("MINECARTTNT", EntityType.MINECART_TNT); - WEtoME.put("TNT_MINECART", EntityType.MINECART_TNT); // 1.11 - WEtoME.put("LEASH_KNOT",EntityType.LEASH_HITCH); // 1.11 - WEtoME.put("MINECARTCHEST", EntityType.MINECART_CHEST); - WEtoME.put("CHEST_MINECART", EntityType.MINECART_CHEST); //1.11 rename - WEtoME.put("VILLAGERGOLEM", EntityType.IRON_GOLEM); - WEtoME.put("ENDERDRAGON", EntityType.ENDER_DRAGON); - WEtoME.put("PAINTING", EntityType.PAINTING); - WEtoME.put("ITEMFRAME", EntityType.ITEM_FRAME); - if (!Bukkit.getServer().getVersion().contains("(MC: 1.7")) { - WEtoME.put("ENDERCRYSTAL", EntityType.ENDER_CRYSTAL); - WEtoME.put("ARMORSTAND", EntityType.ARMOR_STAND); - } - // 1.10 entities and materials - if (!Bukkit.getServer().getVersion().contains("(MC: 1.7") && !Bukkit.getServer().getVersion().contains("(MC: 1.8") && !Bukkit.getServer().getVersion().contains("(MC: 1.9")) { - WEtoME.put("POLARBEAR", EntityType.POLAR_BEAR); - WEtoM.put("ENDER_CRYSTAL", Material.END_CRYSTAL); // 1.11 - } - } - - /** - * @param x - * @param y - * @param z - */ - public IslandBlock(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - signText = null; - banner = null; - spawnerBlockType = null; - chestContents = new HashMap<>(); - } - /** - * @return the type - */ - public int getTypeId() { - return typeId; - } - /** - * @param type the type to set - */ - public void setTypeId(short type) { - this.typeId = type; - } - /** - * @return the data - */ - public int getData() { - return data; - } - /** - * @param data the data to set - */ - public void setData(byte data) { - this.data = data; - } - - /** - * @return the signText - */ - public List getSignText() { - return signText; - } - /** - * @param signText the signText to set - */ - public void setSignText(List signText) { - this.signText = signText; - } - - /** - * @param s - * @param b - */ - public void setBlock(int s, byte b) { - this.typeId = (short)s; - this.data = b; - } - - /** - * Sets this block up with all the banner data required - * @param map - */ - public void setBanner(Map map) { - banner = new BannerBlock(); - banner.prep(map); - } - - /** - * Sets the spawner type if this block is a spawner - * @param tileData - */ - public void setSpawnerType(Map tileData) { - //Bukkit.getLogger().info("DEBUG: " + tileData.toString()); - String creatureType = ""; - if (tileData.containsKey("EntityId")) { - creatureType = ((StringTag) tileData.get("EntityId")).getValue().toUpperCase(); - } else if (tileData.containsKey("SpawnData")) { - // 1.9 format - Map spawnData = ((CompoundTag) tileData.get("SpawnData")).getValue(); - //Bukkit.getLogger().info("DEBUG: " + spawnData.toString()); - if (spawnData.containsKey("id")) { - creatureType = ((StringTag) spawnData.get("id")).getValue().toUpperCase(); - } - } - //Bukkit.getLogger().info("DEBUG: creature type = " + creatureType); - // The mob type might be prefixed with "Minecraft:" - if (creatureType.startsWith("MINECRAFT:")) { - creatureType = creatureType.substring(10); - } - if (WEtoME.containsKey(creatureType)) { - spawnerBlockType = WEtoME.get(creatureType); - } else { - try { - spawnerBlockType = EntityType.valueOf(creatureType); - } catch (Exception e) { - Bukkit.getLogger().warning("Spawner setting of " + creatureType + " is unknown for this server. Skipping."); - } - } - //Bukkit.getLogger().info("DEBUG: spawnerblock type = " + spawnerBlockType); - } - - /** - * Sets this block's sign data - * @param tileData - */ - public void setSign(Map tileData) { - signText = new ArrayList<>(); - List text = new ArrayList<>(); - for (int i = 1; i < 5; i++) { - String line = ((StringTag) tileData.get("Text" + String.valueOf(i))).getValue(); - // This value can actually be a string that says null sometimes. - if (line.equalsIgnoreCase("null")) { - line = ""; - } - //System.out.println("DEBUG: line " + i + " = '"+ line + "' of length " + line.length()); - text.add(line); - } - - JSONParser parser = new JSONParser(); - ContainerFactory containerFactory = new ContainerFactory(){ - public List creatArrayContainer() { - return new LinkedList(); - } - - public Map createObjectContainer() { - return new LinkedHashMap(); - } - - }; - // This just removes all the JSON formatting and provides the raw text - for (int line = 0; line < 4; line++) { - String lineText = ""; - if (!text.get(line).equals("\"\"") && !text.get(line).isEmpty()) { - //String lineText = text.get(line).replace("{\"extra\":[\"", "").replace("\"],\"text\":\"\"}", ""); - //Bukkit.getLogger().info("DEBUG: sign text = '" + text.get(line) + "'"); - if (text.get(line).startsWith("{")) { - // JSON string - try { - - Map json = (Map)parser.parse(text.get(line), containerFactory); - List list = (List) json.get("extra"); - //System.out.println("DEBUG1:" + JSONValue.toJSONString(list)); - if (list != null) { - Iterator iter = list.iterator(); - while(iter.hasNext()){ - Object next = iter.next(); - String format = JSONValue.toJSONString(next); - //System.out.println("DEBUG2:" + format); - // This doesn't see right, but appears to be the easiest way to identify this string as JSON... - if (format.startsWith("{")) { - // JSON string - Map jsonFormat = (Map)parser.parse(format, containerFactory); - Iterator formatIter = jsonFormat.entrySet().iterator(); - while (formatIter.hasNext()) { - Map.Entry entry = (Map.Entry)formatIter.next(); - //System.out.println("DEBUG3:" + entry.getKey() + "=>" + entry.getValue()); - String key = entry.getKey().toString(); - String value = entry.getValue().toString(); - if (key.equalsIgnoreCase("color")) { - try { - lineText += ChatColor.valueOf(value.toUpperCase()); - } catch (Exception noColor) { - Bukkit.getLogger().warning("Unknown color " + value +" in sign when pasting schematic, skipping..."); - } - } else if (key.equalsIgnoreCase("text")) { - lineText += value; - } else { - // Formatting - usually the value is always true, but check just in case - if (key.equalsIgnoreCase("obfuscated") && value.equalsIgnoreCase("true")) { - lineText += ChatColor.MAGIC; - } else if (key.equalsIgnoreCase("underlined") && value.equalsIgnoreCase("true")) { - lineText += ChatColor.UNDERLINE; - } else { - // The rest of the formats - try { - lineText += ChatColor.valueOf(key.toUpperCase()); - } catch (Exception noFormat) { - // Ignore - //System.out.println("DEBUG3:" + key + "=>" + value); - Bukkit.getLogger().warning("Unknown format " + value +" in sign when pasting schematic, skipping..."); - } - } - } - } - } else { - // This is unformatted text. It is included in "". A reset is required to clear - // any previous formatting - if (format.length()>1) { - lineText += ChatColor.RESET + format.substring(format.indexOf('"')+1,format.lastIndexOf('"')); - } - } - } - } else { - // No extra tag - json = (Map)parser.parse(text.get(line), containerFactory); - String value = (String) json.get("text"); - //System.out.println("DEBUG text only?:" + value); - lineText += value; - } - } catch (ParseException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } else { - // This is unformatted text (not JSON). It is included in "". - if (text.get(line).length() > 1) { - try { - lineText = text.get(line).substring(text.get(line).indexOf('"')+1,text.get(line).lastIndexOf('"')); - } catch (Exception e) { - //There may not be those "'s, so just use the raw line - lineText = text.get(line); - } - } else { - // just in case it isn't - show the raw line - lineText = text.get(line); - } - } - //Bukkit.getLogger().info("Line " + line + " is " + lineText); - } - signText.add(lineText); - } - } - - public void setBook(Map tileData) { - //Bukkit.getLogger().info("DEBUG: Book data "); - Bukkit.getLogger().info(tileData.toString()); - } - - @SuppressWarnings("deprecation") - public void setChest(NMSAbstraction nms, Map tileData) { - try { - ListTag chestItems = (ListTag) tileData.get("Items"); - if (chestItems != null) { - //int number = 0; - for (Tag item : chestItems.getValue()) { - // Format for chest items is: - // id = short value of item id - // Damage = short value of item damage - // Count = the number of items - // Slot = the slot in the chest - // inventory - - if (item instanceof CompoundTag) { - try { - // Id is a number - short itemType = (Short) ((CompoundTag) item).getValue().get("id").getValue(); - short itemDamage = (Short) ((CompoundTag) item).getValue().get("Damage").getValue(); - byte itemAmount = (Byte) ((CompoundTag) item).getValue().get("Count").getValue(); - byte itemSlot = (Byte) ((CompoundTag) item).getValue().get("Slot").getValue(); - ItemStack chestItem = new ItemStack(itemType, itemAmount, itemDamage); - chestContents.put(itemSlot, chestItem); - } catch (ClassCastException ex) { - // Id is a material - String itemType = (String) ((CompoundTag) item).getValue().get("id").getValue(); - try { - // Get the material - if (itemType.startsWith("minecraft:")) { - String material = itemType.substring(10).toUpperCase(); - // Special case for non-standard material names - Material itemMaterial; - - //Bukkit.getLogger().info("DEBUG: " + material); - - if (WEtoM.containsKey(material)) { - //Bukkit.getLogger().info("DEBUG: Found in hashmap"); - itemMaterial = WEtoM.get(material); - } else { - //Bukkit.getLogger().info("DEBUG: Not in hashmap"); - itemMaterial = Material.valueOf(material); - } - short itemDamage = (Short) ((CompoundTag) item).getValue().get("Damage").getValue(); - byte itemAmount = (Byte) ((CompoundTag) item).getValue().get("Count").getValue(); - byte itemSlot = (Byte) ((CompoundTag) item).getValue().get("Slot").getValue(); - ItemStack chestItem = new ItemStack(itemMaterial, itemAmount, itemDamage); - if (itemMaterial.equals(Material.WRITTEN_BOOK)) { - chestItem = nms.setBook(item); - } - // Check for potions - if (itemMaterial.toString().contains("POTION")) { - chestItem = nms.setPotion(itemMaterial, item, chestItem); - } - chestContents.put(itemSlot, chestItem); - } - } catch (Exception exx) { - // Bukkit.getLogger().info(item.toString()); - // Bukkit.getLogger().info(((CompoundTag)item).getValue().get("id").getName()); - Bukkit.getLogger().severe( - "Could not parse item [" + itemType.substring(10).toUpperCase() + "] in schematic - skipping!"); - // Bukkit.getLogger().severe(item.toString()); - exx.printStackTrace(); - } - - } - - // Bukkit.getLogger().info("Set chest inventory slot " - // + itemSlot + " to " + - // chestItem.toString()); - } - } - //Bukkit.getLogger().info("Added " + number + " items to chest"); - } - } catch (Exception e) { - Bukkit.getLogger().severe("Could not parse schematic file item, skipping!"); - // e.printStackTrace(); - } - } - - - /** - * Paste this block at blockLoc - * @param nms - * @param blockLoc - */ - //@SuppressWarnings("deprecation") - @SuppressWarnings("deprecation") - public void paste(NMSAbstraction nms, Location blockLoc, boolean usePhysics, Biome biome) { - // Only paste air if it is below the sea level and in the overworld - Block block = new Location(blockLoc.getWorld(), x, y, z).add(blockLoc).getBlock(); - block.setBiome(biome); - block.getChunk().load(); - nms.setBlockSuperFast(block, typeId, data, usePhysics); - if (signText != null) { - if (block.getTypeId() != typeId) { - block.setTypeId(typeId); - } - // Sign - Sign sign = (Sign) block.getState(); - int index = 0; - for (String line : signText) { - sign.setLine(index++, line); - } - sign.update(); - } else if (banner != null) { - banner.set(block); - } else if (spawnerBlockType != null) { - if (block.getTypeId() != typeId) { - block.setTypeId(typeId); - } - CreatureSpawner cs = (CreatureSpawner)block.getState(); - cs.setSpawnedType(spawnerBlockType); - } else if (!chestContents.isEmpty()) { - if (block.getTypeId() != typeId) { - block.setTypeId(typeId); - } - // Check if this is a double chest - Chest chestBlock = (Chest) block.getState(); - InventoryHolder iH = chestBlock.getInventory().getHolder(); - if (iH instanceof DoubleChest) { - //Bukkit.getLogger().info("DEBUG: double chest"); - DoubleChest doubleChest = (DoubleChest) iH; - for (ItemStack chestItem: chestContents.values()) { - doubleChest.getInventory().addItem(chestItem); - } - } else { - // Single chest - for (Entry en : chestContents.entrySet()) { - chestBlock.getInventory().setItem(en.getKey(), en.getValue()); - } - } - } - } - - /** - * @return Vector for where this block is in the schematic - */ - public Vector getVector() { - return new Vector(x,y,z); - } -} diff --git a/src/main/java/us/tastybento/bskyblock/schematics/Schematic.java b/src/main/java/us/tastybento/bskyblock/schematics/Schematic.java deleted file mode 100644 index 8893b1857..000000000 --- a/src/main/java/us/tastybento/bskyblock/schematics/Schematic.java +++ /dev/null @@ -1,1753 +0,0 @@ -package us.tastybento.bskyblock.schematics; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.Set; - -import org.bukkit.Art; -import org.bukkit.Bukkit; -import org.bukkit.DyeColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Rotation; -import org.bukkit.TreeType; -import org.bukkit.World; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.BlockState; -import org.bukkit.block.Chest; -import org.bukkit.block.DoubleChest; -import org.bukkit.block.Sign; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Horse; -import org.bukkit.entity.ItemFrame; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Ocelot; -import org.bukkit.entity.Painting; -import org.bukkit.entity.Player; -import org.bukkit.entity.Rabbit; -import org.bukkit.entity.Sheep; -import org.bukkit.entity.Villager; -import org.bukkit.entity.Villager.Profession; -import org.bukkit.entity.Wolf; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.material.DirectionalContainer; -import org.bukkit.util.BlockVector; -import org.bukkit.util.Vector; - -import net.milkbowl.vault.economy.EconomyResponse; -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.util.DeleteIslandChunks; -import us.tastybento.bskyblock.util.Util; -import us.tastybento.bskyblock.util.VaultHelper; -import us.tastybento.bskyblock.util.nms.NMSAbstraction; -import us.tastybento.org.jnbt.ByteArrayTag; -import us.tastybento.org.jnbt.ByteTag; -import us.tastybento.org.jnbt.CompoundTag; -import us.tastybento.org.jnbt.FloatTag; -import us.tastybento.org.jnbt.IntTag; -import us.tastybento.org.jnbt.ListTag; -import us.tastybento.org.jnbt.NBTInputStream; -import us.tastybento.org.jnbt.ShortTag; -import us.tastybento.org.jnbt.StringTag; -import us.tastybento.org.jnbt.Tag; - -public class Schematic { - private BSkyBlock plugin; - //private short[] blocks; - //private byte[] data; - private short width; - private short length; - private short height; - private Map> tileEntitiesMap = new HashMap>(); - //private HashMap entitiesMap = new HashMap(); - private List entitiesList = new ArrayList(); - private File file; - private String heading; - private String name; - private String perm; - private String description; - private int rating; - private boolean useDefaultChest; - private Material icon; - private Biome biome; - private boolean usePhysics; - private boolean pasteEntities; - private boolean visible; - private int order; - // These hashmaps enable translation between WorldEdit strings and Bukkit names - //private HashMap WEtoME = new HashMap(); - private List islandCompanion; - private List companionNames; - private ItemStack[] defaultChestItems; - // Name of a schematic this one is paired with - private String partnerName = ""; - // Key blocks - private Vector bedrock; - private Vector chest; - private Vector welcomeSign; - private Vector topGrass; - private Vector playerSpawn; - //private Material playerSpawnBlock; - private NMSAbstraction nms; - private Set attachable = new HashSet(); - private Map paintingList = new HashMap(); - private Map facingList = new HashMap(); - private Map rotationList = new HashMap(); - private List islandBlocks; - //private boolean pasteAir; - private int durability; - private int levelHandicap; - private double cost; - // The reason why this schematic is being pasted - public enum PasteReason { - /** - * This is a new island - */ - NEW_ISLAND, - /** - * This is a partner island - */ - PARTNER, - /** - * This is a reset - */ - RESET - }; - - public Schematic(BSkyBlock plugin) { - this.plugin = plugin; - // Initialize - name = ""; - heading = ""; - description = "Default Island"; - perm = ""; - icon = Material.MAP; - rating = 50; - useDefaultChest = true; - biome = Settings.defaultBiome; - usePhysics = Settings.usePhysics; - file = null; - islandCompanion = new ArrayList(); - islandCompanion.add(Settings.companionType); - companionNames = Settings.companionNames; - defaultChestItems = Settings.chestItems; - visible = true; - order = 0; - bedrock = null; - chest = null; - welcomeSign = null; - topGrass = null; - playerSpawn = null; - //playerSpawnBlock = null; - partnerName = ""; - } - - @SuppressWarnings("deprecation") - public Schematic(BSkyBlock plugin, File file) throws IOException { - this.plugin = plugin; - // Initialize - short[] blocks; - byte[] data; - name = file.getName(); - heading = ""; - description = ""; - perm = ""; - icon = Material.MAP; - rating = 50; - useDefaultChest = true; - biome = Settings.defaultBiome; - usePhysics = Settings.usePhysics; - islandCompanion = new ArrayList(); - islandCompanion.add(Settings.companionType); - companionNames = Settings.companionNames; - defaultChestItems = Settings.chestItems; - pasteEntities = false; - visible = true; - order = 0; - bedrock = null; - chest = null; - welcomeSign = null; - topGrass = null; - playerSpawn = null; - //playerSpawnBlock = null; - partnerName = ""; - - attachable.add(Material.STONE_BUTTON.getId()); - attachable.add(Material.WOOD_BUTTON.getId()); - attachable.add(Material.COCOA.getId()); - attachable.add(Material.LADDER.getId()); - attachable.add(Material.LEVER.getId()); - attachable.add(Material.PISTON_EXTENSION.getId()); - attachable.add(Material.REDSTONE_TORCH_OFF.getId()); - attachable.add(Material.REDSTONE_TORCH_ON.getId()); - attachable.add(Material.WALL_SIGN.getId()); - attachable.add(Material.TORCH.getId()); - attachable.add(Material.TRAP_DOOR.getId()); - attachable.add(Material.TRIPWIRE_HOOK.getId()); - attachable.add(Material.VINE.getId()); - attachable.add(Material.WOODEN_DOOR.getId()); - attachable.add(Material.IRON_DOOR.getId()); - attachable.add(Material.RED_MUSHROOM.getId()); - attachable.add(Material.BROWN_MUSHROOM.getId()); - attachable.add(Material.PORTAL.getId()); - - // Painting list, useful to check if painting exsits or nor - paintingList.put("Kebab", Art.KEBAB); - paintingList.put("Aztec", Art.AZTEC); - paintingList.put("Alban", Art.ALBAN); - paintingList.put("Aztec2", Art.AZTEC2); - paintingList.put("Bomb", Art.BOMB); - paintingList.put("Plant", Art.PLANT); - paintingList.put("Wasteland", Art.WASTELAND); - paintingList.put("Wanderer", Art.WANDERER); - paintingList.put("Graham", Art.GRAHAM); - paintingList.put("Pool", Art.POOL); - paintingList.put("Courbet", Art.COURBET); - paintingList.put("Sunset", Art.SUNSET); - paintingList.put("Sea", Art.SEA); - paintingList.put("Creebet", Art.CREEBET); - paintingList.put("Match", Art.MATCH); - paintingList.put("Bust", Art.BUST); - paintingList.put("Stage", Art.STAGE); - paintingList.put("Void", Art.VOID); - paintingList.put("SkullAndRoses", Art.SKULL_AND_ROSES); - paintingList.put("Wither", Art.WITHER); - paintingList.put("Fighters", Art.FIGHTERS); - paintingList.put("Skeleton", Art.SKELETON); - paintingList.put("DonkeyKong", Art.DONKEYKONG); - paintingList.put("Pointer", Art.POINTER); - paintingList.put("Pigscene", Art.PIGSCENE); - paintingList.put("BurningSkull", Art.BURNINGSKULL); - - facingList.put((byte) 0, BlockFace.SOUTH); - facingList.put((byte) 1, BlockFace.WEST); - facingList.put((byte) 2, BlockFace.NORTH); - facingList.put((byte) 3, BlockFace.EAST); - - rotationList.put((byte) 0, Rotation.NONE); - rotationList.put((byte) 2, Rotation.CLOCKWISE); - rotationList.put((byte) 4, Rotation.FLIPPED); - rotationList.put((byte) 6, Rotation.COUNTER_CLOCKWISE); - - if (!Bukkit.getServer().getVersion().contains("(MC: 1.7")) { - rotationList.put((byte) 1, Rotation.CLOCKWISE_45); - rotationList.put((byte) 3, Rotation.CLOCKWISE_135); - rotationList.put((byte) 5, Rotation.FLIPPED_45); - rotationList.put((byte) 7, Rotation.COUNTER_CLOCKWISE_45); - } - - try { - nms = Util.getNMSHandler(); - } catch (Exception e) { - e.printStackTrace(); - } - // Establish the World Edit to Material look up - // V1.8 items - if (!Bukkit.getServer().getVersion().contains("(MC: 1.7")) { - attachable.add(Material.IRON_TRAPDOOR.getId()); - attachable.add(Material.WALL_BANNER.getId()); - attachable.add(Material.ACACIA_DOOR.getId()); - attachable.add(Material.BIRCH_DOOR.getId()); - attachable.add(Material.SPRUCE_DOOR.getId()); - attachable.add(Material.DARK_OAK_DOOR.getId()); - attachable.add(Material.JUNGLE_DOOR.getId()); - } - - // Entities - /* - WEtoME.put("LAVASLIME", EntityType.MAGMA_CUBE); - WEtoME.put("ENTITYHORSE", EntityType.HORSE); - WEtoME.put("OZELOT", EntityType.OCELOT); - WEtoME.put("MUSHROOMCOW", EntityType.MUSHROOM_COW); - WEtoME.put("PIGZOMBIE", EntityType.PIG_ZOMBIE); - */ - this.file = file; - // Try to load the file - try { - FileInputStream stream = new FileInputStream(file); - // InputStream is = new DataInputStream(new - // GZIPInputStream(stream)); - NBTInputStream nbtStream = new NBTInputStream(stream); - - CompoundTag schematicTag = (CompoundTag) nbtStream.readTag(); - nbtStream.close(); - stream.close(); - if (!schematicTag.getName().equals("Schematic")) { - throw new IllegalArgumentException("Tag \"Schematic\" does not exist or is not first"); - } - - Map schematic = schematicTag.getValue(); - - Vector origin = null; - try { - int originX = getChildTag(schematic, "WEOriginX", IntTag.class).getValue(); - int originY = getChildTag(schematic, "WEOriginY", IntTag.class).getValue(); - int originZ = getChildTag(schematic, "WEOriginZ", IntTag.class).getValue(); - Vector min = new Vector(originX, originY, originZ); - - //int offsetX = getChildTag(schematic, "WEOffsetX", IntTag.class).getValue(); - //int offsetY = getChildTag(schematic, "WEOffsetY", IntTag.class).getValue(); - //int offsetZ = getChildTag(schematic, "WEOffsetZ", IntTag.class).getValue(); - //Vector offset = new Vector(offsetX, offsetY, offsetZ); - - //origin = min.subtract(offset); - origin = min.clone(); - } catch (Exception ignored) {} - //Bukkit.getLogger().info("Origin = " + origin); - - - if (!schematic.containsKey("Blocks")) { - throw new IllegalArgumentException("Schematic file is missing a \"Blocks\" tag"); - } - - width = getChildTag(schematic, "Width", ShortTag.class).getValue(); - length = getChildTag(schematic, "Length", ShortTag.class).getValue(); - height = getChildTag(schematic, "Height", ShortTag.class).getValue(); - - String materials = getChildTag(schematic, "Materials", StringTag.class).getValue(); - if (!materials.equals("Alpha")) { - throw new IllegalArgumentException("Schematic file is not an Alpha schematic"); - } - - byte[] blockId = getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue(); - data = getChildTag(schematic, "Data", ByteArrayTag.class).getValue(); - byte[] addId = new byte[0]; - blocks = new short[blockId.length]; // Have to later combine IDs - // We support 4096 block IDs using the same method as vanilla - // Minecraft, where - // the highest 4 bits are stored in a separate byte array. - if (schematic.containsKey("AddBlocks")) { - addId = getChildTag(schematic, "AddBlocks", ByteArrayTag.class).getValue(); - } - - // Combine the AddBlocks data with the first 8-bit block ID - for (int index = 0; index < blockId.length; index++) { - if ((index >> 1) >= addId.length) { // No corresponding - // AddBlocks index - blocks[index] = (short) (blockId[index] & 0xFF); - } else { - if ((index & 1) == 0) { - blocks[index] = (short) (((addId[index >> 1] & 0x0F) << 8) + (blockId[index] & 0xFF)); - } else { - blocks[index] = (short) (((addId[index >> 1] & 0xF0) << 4) + (blockId[index] & 0xFF)); - } - } - } - // Entities - List entities = getChildTag(schematic, "Entities", ListTag.class).getValue(); - for (Tag tag : entities) { - if (!(tag instanceof CompoundTag)) - continue; - - CompoundTag t = (CompoundTag) tag; - //Bukkit.getLogger().info("**************************************"); - EntityObject ent = new EntityObject(); - for (Map.Entry entry : t.getValue().entrySet()) { - //Bukkit.getLogger().info("DEBUG " + entry.getKey() + ">>>>" + entry.getValue()); - //Bukkit.getLogger().info("++++++++++++++++++++++++++++++++++++++++++++++++++"); - if (entry.getKey().equals("id")) { - String id = ((StringTag)entry.getValue()).getValue().toUpperCase(); - //Bukkit.getLogger().info("DEBUG: ID is '" + id + "'"); - // The mob type might be prefixed with "Minecraft:" - if (id.startsWith("MINECRAFT:")) { - id = id.substring(10); - } - if (IslandBlock.WEtoME.containsKey(id)) { - //Bukkit.getLogger().info("DEBUG: id found"); - ent.setType(IslandBlock.WEtoME.get(id)); - } else if (!id.equalsIgnoreCase("ITEM")){ - for (EntityType type : EntityType.values()) { - if (type.toString().equals(id)) { - ent.setType(type); - break; - } - } - } - } - - if (entry.getKey().equals("Pos")) { - //Bukkit.getLogger().info("DEBUG Pos fond"); - if (entry.getValue() instanceof ListTag) { - //Bukkit.getLogger().info("DEBUG coord found"); - List pos = new ArrayList(); - pos = ((ListTag) entry.getValue()).getValue(); - //Bukkit.getLogger().info("DEBUG pos: " + pos); - double x = (double)pos.get(0).getValue() - origin.getX(); - double y = (double)pos.get(1).getValue() - origin.getY(); - double z = (double)pos.get(2).getValue() - origin.getZ(); - ent.setLocation(new BlockVector(x,y,z)); - } - } else if (entry.getKey().equals("Motion")) { - //Bukkit.getLogger().info("DEBUG Pos fond"); - if (entry.getValue() instanceof ListTag) { - //Bukkit.getLogger().info("DEBUG coord found"); - List pos = new ArrayList(); - pos = ((ListTag) entry.getValue()).getValue(); - //Bukkit.getLogger().info("DEBUG pos: " + pos); - ent.setMotion(new Vector((double)pos.get(0).getValue(), (double)pos.get(1).getValue() - ,(double)pos.get(2).getValue())); - } - } else if (entry.getKey().equals("Rotation")) { - //Bukkit.getLogger().info("DEBUG Pos fond"); - if (entry.getValue() instanceof ListTag) { - //Bukkit.getLogger().info("DEBUG coord found"); - List pos = new ArrayList(); - pos = ((ListTag) entry.getValue()).getValue(); - //Bukkit.getLogger().info("DEBUG pos: " + pos); - ent.setYaw((float)pos.get(0).getValue()); - ent.setPitch((float)pos.get(1).getValue()); - } - } else if (entry.getKey().equals("Color")) { - if (entry.getValue() instanceof ByteTag) { - ent.setColor(((ByteTag) entry.getValue()).getValue()); - } - } else if (entry.getKey().equals("Sheared")) { - if (entry.getValue() instanceof ByteTag) { - if (((ByteTag) entry.getValue()).getValue() != (byte)0) { - ent.setSheared(true); - } else { - ent.setSheared(false); - } - } - } else if (entry.getKey().equals("RabbitType")) { - if (entry.getValue() instanceof IntTag) { - ent.setRabbitType(((IntTag)entry.getValue()).getValue()); - } - } else if (entry.getKey().equals("Profession")) { - if (entry.getValue() instanceof IntTag) { - ent.setProfession(((IntTag)entry.getValue()).getValue()); - } - } else if (entry.getKey().equals("CarryingChest")) { - if (entry.getValue() instanceof ByteTag) { - ent.setCarryingChest(((ByteTag) entry.getValue()).getValue()); - } - } else if (entry.getKey().equals("OwnerUUID")) { - ent.setOwned(true); - } else if (entry.getKey().equals("CollarColor")) { - if (entry.getValue() instanceof ByteTag) { - ent.setCollarColor(((ByteTag) entry.getValue()).getValue()); - } - } else if (entry.getKey().equals("Facing")) { - if (entry.getValue() instanceof ByteTag) { - ent.setFacing(((ByteTag) entry.getValue()).getValue()); - } - } else if (entry.getKey().equals("Motive")) { - if (entry.getValue() instanceof StringTag) { - ent.setMotive(((StringTag) entry.getValue()).getValue()); - } - } else if (entry.getKey().equals("ItemDropChance")) { - if (entry.getValue() instanceof FloatTag) { - ent.setItemDropChance(((FloatTag) entry.getValue()).getValue()); - } - } else if (entry.getKey().equals("ItemRotation")) { - if (entry.getValue() instanceof ByteTag){ - ent.setItemRotation(((ByteTag) entry.getValue()).getValue()); - } - } else if (entry.getKey().equals("Item")) { - if (entry.getValue() instanceof CompoundTag) { - CompoundTag itemTag = (CompoundTag) entry.getValue(); - for (Map.Entry itemEntry : itemTag.getValue().entrySet()) { - if (itemEntry.getKey().equals("Count")){ - if (itemEntry.getValue() instanceof ByteTag){ - ent.setCount(((ByteTag) itemEntry.getValue()).getValue()); - } - } else if (itemEntry.getKey().equals("Damage")){ - if (itemEntry.getValue() instanceof ShortTag){ - ent.setDamage(((ShortTag) itemEntry.getValue()).getValue()); - } - } else if (itemEntry.getKey().equals("id")){ - if (itemEntry.getValue() instanceof StringTag){ - ent.setId(((StringTag) itemEntry.getValue()).getValue()); - } - } - } - } - } else if (entry.getKey().equals("TileX")){ - if (entry.getValue() instanceof IntTag){ - ent.setTileX((double)((IntTag)entry.getValue()).getValue() - origin.getX()); - } - } else if (entry.getKey().equals("TileY")){ - if (entry.getValue() instanceof IntTag){ - ent.setTileY((double)((IntTag)entry.getValue()).getValue() - origin.getY()); - } - } else if (entry.getKey().equals("TileZ")){ - if (entry.getValue() instanceof IntTag){ - ent.setTileZ((double)((IntTag)entry.getValue()).getValue() - origin.getZ()); - } - } - } - - if (ent.getType() != null) { - //Bukkit.getLogger().info("DEBUG: adding " + ent.getType().toString() + " at " + ent.getLocation().toString()); - //entitiesMap.put(new BlockVector(x,y,z), mobType); - entitiesList.add(ent); - } - } - //Bukkit.getLogger().info("DEBUG: size of entities = " + entities.size()); - // Tile entities - List tileEntities = getChildTag(schematic, "TileEntities", ListTag.class).getValue(); - // Map> tileEntitiesMap = new - // HashMap>(); - - for (Tag tag : tileEntities) { - if (!(tag instanceof CompoundTag)) - continue; - CompoundTag t = (CompoundTag) tag; - - int x = 0; - int y = 0; - int z = 0; - - Map values = new HashMap(); - - for (Map.Entry entry : t.getValue().entrySet()) { - if (entry.getKey().equals("x")) { - if (entry.getValue() instanceof IntTag) { - x = ((IntTag) entry.getValue()).getValue(); - } - } else if (entry.getKey().equals("y")) { - if (entry.getValue() instanceof IntTag) { - y = ((IntTag) entry.getValue()).getValue(); - } - } else if (entry.getKey().equals("z")) { - if (entry.getValue() instanceof IntTag) { - z = ((IntTag) entry.getValue()).getValue(); - } - } - - values.put(entry.getKey(), entry.getValue()); - } - - BlockVector vec = new BlockVector(x, y, z); - tileEntitiesMap.put(vec, values); - } - } catch (IOException e) { - Bukkit.getLogger().severe("Could not load island schematic! Error in file."); - e.printStackTrace(); - throw new IOException(); - } - - // Check for key blocks - // Find top most bedrock - this is the key stone - // Find top most chest - // Find top most grass - List grassBlocks = new ArrayList(); - for (int x = 0; x < width; ++x) { - for (int y = 0; y < height; ++y) { - for (int z = 0; z < length; ++z) { - int index = y * width * length + z * width + x; - // Bukkit.getLogger().info("DEBUG " + index + - // " changing to ID:"+blocks[index] + " data = " + - // blockData[index]); - if (blocks[index] == 7) { - // Last bedrock - if (bedrock == null || bedrock.getY() < y) { - bedrock = new Vector(x, y, z); - //Bukkit.getLogger().info("DEBUG higher bedrock found:" + bedrock.toString()); - } - } else if (blocks[index] == 54) { - // Last chest - if (chest == null || chest.getY() < y) { - chest = new Vector(x, y, z); - // Bukkit.getLogger().info("Island loc:" + - // loc.toString()); - // Bukkit.getLogger().info("Chest relative location is " - // + chest.toString()); - } - } else if (blocks[index] == 63) { - // Sign - if (welcomeSign == null || welcomeSign.getY() < y) { - welcomeSign = new Vector(x, y, z); - // Bukkit.getLogger().info("DEBUG higher sign found:" - // + welcomeSign.toString()); - } - } else if (blocks[index] == 2) { - // Grass - grassBlocks.add(new Vector(x,y,z)); - } - } - } - } - if (bedrock == null) { - Bukkit.getLogger().severe("Schematic must have at least one bedrock in it!"); - throw new IOException(); - } - // Find other key blocks - if (!grassBlocks.isEmpty()) { - // Sort by height - List sorted = new ArrayList(); - for (Vector v : grassBlocks) { - //if (GridManager.isSafeLocation(v.toLocation(world))) { - // Add to sorted list - boolean inserted = false; - for (int i = 0; i < sorted.size(); i++) { - if (v.getBlockY() > sorted.get(i).getBlockY()) { - sorted.add(i, v); - inserted = true; - break; - } - } - if (!inserted) { - // just add to the end of the list - sorted.add(v); - } - } - topGrass = sorted.get(0); - } else { - topGrass = null; - } - - // Preload the blocks - prePasteSchematic(blocks, data); - } - - /** - * @return the biome - */ - public Biome getBiome() { - return biome; - } - - /** - * @return the description - */ - public String getDescription() { - return description; - } - - /** - * @return the file - */ - public File getFile() { - return file; - } - - /** - * @return the heading - */ - public String getHeading() { - return heading; - } - - /** - * @return the height - */ - public short getHeight() { - return height; - } - - /** - * @return the icon - */ - public Material getIcon() { - return icon; - } - - /** - * @return the durability of the icon - */ - public int getDurability() { - return durability; - } - - /** - * @return the length - */ - public short getLength() { - return length; - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @return the perm - */ - public String getPerm() { - return perm; - } - - /** - * @return the rating - */ - public int getRating() { - return rating; - } - - /** - * @return the tileEntitiesMap - */ - public Map> getTileEntitiesMap() { - return tileEntitiesMap; - } - - /** - * @return the width - */ - public short getWidth() { - return width; - } - - /** - * @return the useDefaultChest - */ - public boolean isUseDefaultChest() { - return useDefaultChest; - } - - /** - * @return the usePhysics - */ - public boolean isUsePhysics() { - return usePhysics; - } - - /* - * This function pastes using World Edit - problem is that because it reads a file, it's slow. - @SuppressWarnings("deprecation") - */ - /* - * - public void pasteSchematic(final Location loc, final Player player, boolean teleport) { - plugin.getLogger().info("WE Pasting"); - com.sk89q.worldedit.Vector WEorigin = new com.sk89q.worldedit.Vector(loc.getBlockX(),loc.getBlockY(),loc.getBlockZ()); - EditSession es = new EditSession(new BukkitWorld(loc.getWorld()), 999999999); - try { - CuboidClipboard cc = CuboidClipboard.loadSchematic(file); - cc.paste(es, WEorigin, false); - cc.pasteEntities(WEorigin); - } catch (Exception e) { - e.printStackTrace(); - } - - if (teleport) { - World world = loc.getWorld(); - - player.teleport(world.getSpawnLocation()); - plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() { - - @Override - public void run() { - plugin.getGrid().homeTeleport(player); - - }}, 10L); - - } - } - */ - /** - * This method pastes a schematic. - * @param loc - * @param player - * @param oldIsland - * @param partner - */ - public void pasteSchematic(final Location loc, final Player player, boolean teleport, final PasteReason reason, Island oldIsland) { - // If this is not a file schematic, paste the default island - if (this.file == null) { - if (Settings.GAMETYPE == GameType.ACIDISLAND) { - generateIslandBlocks(loc,player, reason); - } else { - loc.getBlock().setType(Material.BEDROCK); - BSkyBlock.getPlugin().getLogger().severe("Missing schematic - using bedrock block only"); - } - return; - } - World world = loc.getWorld(); - Location blockLoc = new Location(world, loc.getX(), loc.getY(), loc.getZ()); - //Location blockLoc = new Location(world, loc.getX(), Settings.island_level, loc.getZ()); - blockLoc.subtract(bedrock); - //plugin.getLogger().info("DEBUG: blockloc = " + blockLoc); - // Paste the island blocks - //plugin.getLogger().info("DEBUG: islandBlock size (paste) = " + islandBlocks.size()); - for (IslandBlock b : islandBlocks) { - b.paste(nms, blockLoc, this.usePhysics, biome); - } - // PASTE ENTS - //Bukkit.getLogger().info("Block loc = " + blockLoc); - if (pasteEntities) { - for (EntityObject ent : entitiesList) { - // If TileX/Y/Z id defined, we have to use it (for Item Frame & Painting) - if(ent.getTileX() != null && ent.getTileY() != null && ent.getTileZ() != null){ - ent.setLocation(new BlockVector(ent.getTileX(),ent.getTileY(),ent.getTileZ())); - } - - Location entitySpot = ent.getLocation().toLocation(blockLoc.getWorld()).add(blockLoc.toVector()); - entitySpot.setPitch(ent.getPitch()); - entitySpot.setYaw(ent.getYaw()); - //Bukkit.getLogger().info("DEBUG: Entity type = " + ent.getType()); - if(ent.getType() == EntityType.PAINTING){ - - //Bukkit.getLogger().info("DEBUG: painting = " + ent.getMotive() + "; facing = " + ent.getFacing()); - //Bukkit.getLogger().info("DEBUG: spawning " + ent.getType().toString() + " at " + entitySpot); - try { - Painting painting = blockLoc.getWorld().spawn(entitySpot, Painting.class); - if (painting != null) { - if(paintingList.containsKey(ent.getMotive())){ - //painting.setArt(Art.GRAHAM); - painting.setArt(paintingList.get(ent.getMotive()), true); - } else { - // Set default - painting.setArt(Art.ALBAN, true); - } - - // http://minecraft.gamepedia.com/Painting#Data_values - if(facingList.containsKey(ent.getFacing())){ - painting.setFacingDirection(facingList.get(ent.getFacing()), true); - } else { - //set default direction - painting.setFacingDirection(BlockFace.NORTH, true); - } - //Bukkit.getLogger().info("DEBUG: Painting setFacingDirection: " + painting.getLocation().toString() + "; facing: " + painting.getFacing() + "; ent facing: " + ent.getFacing()); - //Bukkit.getLogger().info("DEBUG: Painting setArt: " + painting.getLocation().toString() + "; art: " + painting.getArt() + "; ent motive: " + ent.getMotive()); - - } - } catch (IllegalArgumentException e) { - //plugin.getLogger().warning("Cannot paste painting from schematic"); - } - } else if(ent.getType() == EntityType.ITEM_FRAME) { - - //Bukkit.getLogger().info("DEBUG: spawning itemframe at" + entitySpot.toString()); - - //Bukkit.getLogger().info("DEBUG: tileX: " + ent.getTileX() + ", tileY: " + ent.getTileY() + ", tileZ: " + ent.getTileZ()); - - ItemFrame itemFrame = (ItemFrame) blockLoc.getWorld().spawnEntity(entitySpot, EntityType.ITEM_FRAME); - if (itemFrame != null) { - // Need to improve this shity fix ... - Material material = Material.matchMaterial(ent.getId().substring(10).toUpperCase());; - - if(material == null && IslandBlock.WEtoM.containsKey(ent.getId().substring(10).toUpperCase())){ - material = IslandBlock.WEtoM.get(ent.getId().substring(10).toUpperCase()); - } - - ItemStack item; - - if(material != null){ - //Bukkit.getLogger().info("DEBUG: id: " + ent.getId() + ", material match: " + material.toString()); - if(ent.getCount() != null){ - if(ent.getDamage() != null){ - item = new ItemStack(material, ent.getCount(), ent.getDamage()); - } else { - item = new ItemStack(material, ent.getCount(), (short) 0); - } - } else { - if(ent.getDamage() != null){ - item = new ItemStack(material, 1, ent.getDamage()); - } else { - item = new ItemStack(material, 1, (short) 0); - } - } - } else { - //Bukkit.getLogger().info("DEBUG: material can't be found for: " + ent.getId() + " (" + ent.getId().substring(10).toUpperCase() + ")"); - // Set to default content - item = new ItemStack(Material.STONE, 0, (short) 4); - } - - ItemMeta itemMeta = item.getItemMeta(); - - // TODO: Implement methods to get enchantement, names, lore etc. - - item.setItemMeta(itemMeta); - itemFrame.setItem(item); - - if(facingList.containsKey(ent.getFacing())){ - itemFrame.setFacingDirection(facingList.get(ent.getFacing()), true); - } else { - //set default direction - itemFrame.setFacingDirection(BlockFace.NORTH, true); - } - - // TODO: Implements code to handle the rotation of the item in the itemframe - if(rotationList.containsKey(ent.getItemRotation())){ - itemFrame.setRotation(rotationList.get(ent.getItemRotation())); - } else { - // Set default direction - itemFrame.setRotation(Rotation.NONE); - } - } - } else { - //Bukkit.getLogger().info("Spawning " + ent.getType().toString() + " at " + entitySpot); - Entity spawned = blockLoc.getWorld().spawnEntity(entitySpot, ent.getType()); - if (spawned != null) { - spawned.setVelocity(ent.getMotion()); - if (ent.getType() == EntityType.SHEEP) { - Sheep sheep = (Sheep)spawned; - if (ent.isSheared()) { - sheep.setSheared(true); - } - DyeColor[] set = DyeColor.values(); - sheep.setColor(set[ent.getColor()]); - sheep.setAge(ent.getAge()); - } else if (ent.getType() == EntityType.HORSE) { - Horse horse = (Horse)spawned; - Horse.Color[] set = Horse.Color.values(); - horse.setColor(set[ent.getColor()]); - horse.setAge(ent.getAge()); - horse.setCarryingChest(ent.isCarryingChest()); - } else if (ent.getType() == EntityType.VILLAGER) { - Villager villager = (Villager)spawned; - villager.setAge(ent.getAge()); - Profession[] proffs = Profession.values(); - villager.setProfession(proffs[ent.getProfession()]); - } else if (!Bukkit.getServer().getVersion().contains("(MC: 1.7") && ent.getType() == EntityType.RABBIT) { - Rabbit rabbit = (Rabbit)spawned; - Rabbit.Type[] set = Rabbit.Type.values(); - rabbit.setRabbitType(set[ent.getRabbitType()]); - rabbit.setAge(ent.getAge()); - } else if (ent.getType() == EntityType.OCELOT) { - Ocelot cat = (Ocelot)spawned; - if (ent.isOwned()) { - cat.setTamed(true); - cat.setOwner(player); - } - Ocelot.Type[] set = Ocelot.Type.values(); - cat.setCatType(set[ent.getCatType()]); - cat.setAge(ent.getAge()); - cat.setSitting(ent.isSitting()); - } else if (ent.getType() == EntityType.WOLF) { - Wolf wolf = (Wolf)spawned; - if (ent.isOwned()) { - wolf.setTamed(true); - wolf.setOwner(player); - } - wolf.setAge(ent.getAge()); - wolf.setSitting(ent.isSitting()); - DyeColor[] color = DyeColor.values(); - wolf.setCollarColor(color[ent.getCollarColor()]); - } - } - } - } - } - // Find the grass spot - final Location grass; - if (topGrass != null) { - Location gr = topGrass.clone().toLocation(loc.getWorld()).subtract(bedrock); - gr.add(loc.toVector()); - gr.add(new Vector(0.5D,1.1D,0.5D)); // Center of block and a bit up so the animal drops a bit - grass = gr; - } else { - grass = null; - } - - //Bukkit.getLogger().info("DEBUG cow location " + grass); - Block blockToChange = null; - // world.spawnEntity(grass, EntityType.COW); - // Place a helpful sign in front of player - if (welcomeSign != null) { - // Bukkit.getLogger().info("DEBUG welcome sign schematic relative is:" - // + welcomeSign.toString()); - Vector ws = welcomeSign.clone().subtract(bedrock); - // Bukkit.getLogger().info("DEBUG welcome sign relative to bedrock is:" - // + welcomeSign.toString()); - ws.add(loc.toVector()); - // Bukkit.getLogger().info("DEBUG welcome sign actual position is:" - // + welcomeSign.toString()); - blockToChange = ws.toLocation(world).getBlock(); - BlockState signState = blockToChange.getState(); - if (signState instanceof Sign) { - Sign sign = (Sign) signState; - if (sign.getLine(0).isEmpty()) { - // TODO Add sign - sign.setLine(0, plugin.getLocale(player.getUniqueId()).get("sign.line1").replace("[player]", player.getName())); - } - if (sign.getLine(1).isEmpty()) { - sign.setLine(1, plugin.getLocale(player.getUniqueId()).get("sign.line2").replace("[player]", player.getName())); - } - if (sign.getLine(2).isEmpty()) { - sign.setLine(2, plugin.getLocale(player.getUniqueId()).get("sign.line3").replace("[player]", player.getName())); - } - if (sign.getLine(3).isEmpty()) { - sign.setLine(3, plugin.getLocale(player.getUniqueId()).get("sign.line4").replace("[player]", player.getName())); - } - // BlockFace direction = ((org.bukkit.material.Sign) - // sign.getData()).getFacing(); - //((org.bukkit.material.Sign) sign.getData()).setFacingDirection(BlockFace.NORTH); - sign.update(); - } - } - if (chest != null) { - Vector ch = chest.clone().subtract(bedrock); - ch.add(loc.toVector()); - // Place the chest - no need to use the safe spawn function because we - // know what this island looks like - blockToChange = ch.toLocation(world).getBlock(); - // Bukkit.getLogger().info("Chest block = " + blockToChange); - // blockToChange.setType(Material.CHEST); - // Bukkit.getLogger().info("Chest item settings = " + - // Settings.chestItems[0]); - // Bukkit.getLogger().info("Chest item settings length = " + - // Settings.chestItems.length); - if (useDefaultChest) { - // Fill the chest - if (blockToChange.getType() == Material.CHEST) { - final Chest islandChest = (Chest) blockToChange.getState(); - DoubleChest doubleChest = null; - InventoryHolder iH = islandChest.getInventory().getHolder(); - if (iH instanceof DoubleChest) { - //Bukkit.getLogger().info("DEBUG: double chest"); - doubleChest = (DoubleChest) iH; - } - if (doubleChest != null) { - Inventory inventory = doubleChest.getInventory(); - inventory.clear(); - inventory.setContents(defaultChestItems); - } else { - Inventory inventory = islandChest.getInventory(); - inventory.clear(); - inventory.setContents(defaultChestItems); - } - } - } - } - - if (teleport) { - plugin.getPlayers().setInTeleport(player.getUniqueId()); - //player.setInvulnerable(true); - // Check distance. If it's too close, warp to spawn to try to clear the client's cache - //plugin.getLogger().info("DEBUG: view dist = " + plugin.getServer().getViewDistance()); - /* - if (player.getWorld().equals(world)) { - //plugin.getLogger().info("DEBUG: same world"); - int distSq = (int)((player.getLocation().distanceSquared(loc) - (Settings.islandDistance * Settings.islandDistance)/16)); - //plugin.getLogger().info("DEBUG: distsq = " + distSq); - if (plugin.getServer().getViewDistance() * plugin.getServer().getViewDistance() < distSq) { - //plugin.getLogger().info("DEBUG: teleporting"); - player.teleport(world.getSpawnLocation()); - } - }*/ - plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() { - - @Override - public void run() { - plugin.getIslands().homeTeleport(player); - plugin.getPlayers().removeInTeleport(player.getUniqueId()); - // Reset any inventory, etc. This is done AFTER the teleport because other plugins may switch out inventory based on world - plugin.getPlayers().resetPlayer(player); - // Reset money if required - if (Settings.resetMoney) { - resetMoney(player); - } - // Show fancy titles! - /* - if (!Bukkit.getServer().getVersion().contains("(MC: 1.7")) { - if (!plugin.myLocale(player.getUniqueId()).islandSubTitle.isEmpty()) { - //plugin.getLogger().info("DEBUG: title " + player.getName() + " subtitle {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandSubTitle + "\", \"color\":\"" + plugin.myLocale(player.getUniqueId()).islandSubTitleColor + "\"}"); - plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), - "minecraft:title " + player.getName() + " subtitle {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandSubTitle.replace("[player]", player.getName()) + "\", \"color\":\"" + plugin.myLocale(player.getUniqueId()).islandSubTitleColor + "\"}"); - } - if (!plugin.myLocale(player.getUniqueId()).islandTitle.isEmpty()) { - //plugin.getLogger().info("DEBUG: title " + player.getName() + " title {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandTitle + "\", \"color\":\"" + plugin.myLocale(player.getUniqueId()).islandTitleColor + "\"}"); - plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), - "minecraft:title " + player.getName() + " title {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandTitle.replace("[player]", player.getName()) + "\", \"color\":\"" + plugin.myLocale(player.getUniqueId()).islandTitleColor + "\"}"); - } - if (!plugin.myLocale(player.getUniqueId()).islandDonate.isEmpty() && !plugin.myLocale(player.getUniqueId()).islandURL.isEmpty()) { - //plugin.getLogger().info("DEBUG: tellraw " + player.getName() + " {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandDonate + "\",\"color\":\"" + plugin.myLocale(player.getUniqueId()).islandDonateColor + "\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"" - // + plugin.myLocale(player.getUniqueId()).islandURL + "\"}}"); - plugin.getServer().dispatchCommand( - plugin.getServer().getConsoleSender(), - "minecraft:tellraw " + player.getName() + " {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandDonate.replace("[player]", player.getName()) + "\",\"color\":\"" + plugin.myLocale(player.getUniqueId()).islandDonateColor + "\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"" - + plugin.myLocale(player.getUniqueId()).islandURL + "\"}}"); - } - }*/ - if (reason.equals(PasteReason.NEW_ISLAND)) { - // Run any commands that need to be run at the start - //plugin.getLogger().info("DEBUG: First time"); - if (!player.hasPermission(Settings.PERMPREFIX + "command.newexempt")) { - //plugin.getLogger().info("DEBUG: Executing new island commands"); - //IslandCmd.runCommands(Settings.startCommands, player); - } - } else if (reason.equals(PasteReason.RESET)) { - // Run any commands that need to be run at reset - //plugin.getLogger().info("DEBUG: Reset"); - if (!player.hasPermission(Settings.PERMPREFIX + "command.resetexempt")) { - //plugin.getLogger().info("DEBUG: Executing reset island commands"); - //IslandCmd.runCommands(Settings.resetCommands, player); - } - } - - // Delete the old island if required - if (oldIsland != null) { - plugin.getLogger().info("DEBUG: Deleting old island"); - new DeleteIslandChunks(plugin, oldIsland); - try { - plugin.getIslands().getHandler().deleteObject(oldIsland); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - }}, 10L); - - } - if (!islandCompanion.isEmpty() && grass != null) { - Bukkit.getServer().getScheduler().runTaskLater(BSkyBlock.getPlugin(), new Runnable() { - @Override - public void run() { - spawnCompanion(player, grass); - } - }, 40L); - } - // Set the bedrock block meta data to the original spawn location - // Doesn't survive a server restart. TODO: change to add this info elsewhere. - /* - if (playerSpawn != null) { - blockToChange = loc.getBlock(); - if (blockToChange.getType().equals(Material.BEDROCK)) { - String spawnLoc = Util.getStringLocation(loc.clone().add(playerSpawn).add(new Vector(0.5D,0D,0.5D))); - blockToChange.setMetadata("playerSpawn", new FixedMetadataValue(plugin, spawnLoc)); - } - } - */ - } - /** - * This method prepares to pastes a schematic. - * @param blocks - * @param data - */ - @SuppressWarnings("deprecation") - public void prePasteSchematic(short[] blocks, byte[] data) { - //plugin.getLogger().info("DEBUG: prepaste "); - islandBlocks = new ArrayList(); - Map> tileEntitiesMap = this.getTileEntitiesMap(); - // Start with non-attached blocks - //plugin.getLogger().info("DEBUG: attachable size = " + attachable.size()); - //plugin.getLogger().info("DEBUG: torch = " + Material.TORCH.getId()); - //plugin.getLogger().info("DEBUG: non attachable"); - //plugin.getLogger().info("DEBUG: bedrock y = " + bedrock.getBlockY()); - //int count = 0; - for (int x = 0; x < width; ++x) { - for (int y = 0; y < height; ++y) { - for (int z = 0; z < length; ++z) { - int index = y * width * length + z * width + x; - // Only bother if this block is above ground zero and - // only bother with air if it is below sea level - // TODO: need to check max world height too? - int h = Settings.islandHeight + y - bedrock.getBlockY(); - if (h >= 0 && h < 255 && (blocks[index] != 0 || h < Settings.seaHeight)){ - // Only bother if the schematic blocks are within the range that y can be - //plugin.getLogger().info("DEBUG: height " + (count++) + ":" +h); - IslandBlock block = new IslandBlock(x, y, z); - if (!attachable.contains((int)blocks[index]) || blocks[index] == 179) { - if (Bukkit.getServer().getVersion().contains("(MC: 1.7") && blocks[index] == 179) { - // Red sandstone - use red sand instead - block.setBlock(12, (byte)1); - } else { - block.setBlock(blocks[index], data[index]); - } - // Tile Entities - if (tileEntitiesMap.containsKey(new BlockVector(x, y, z))) { - if (Util.isOnePointEight()) { - if (block.getTypeId() == Material.STANDING_BANNER.getId()) { - block.setBanner(tileEntitiesMap.get(new BlockVector(x, y, z))); - } - } - // Monster spawner blocks - if (block.getTypeId() == Material.MOB_SPAWNER.getId()) { - block.setSpawnerType(tileEntitiesMap.get(new BlockVector(x, y, z))); - } else if ((block.getTypeId() == Material.SIGN_POST.getId())) { - block.setSign(tileEntitiesMap.get(new BlockVector(x, y, z))); - } else if (block.getTypeId() == Material.CHEST.getId()) { - block.setChest(nms, tileEntitiesMap.get(new BlockVector(x, y, z))); - } - } - islandBlocks.add(block); - } - } - } - } - } - //plugin.getLogger().info("Attachable blocks"); - // Second pass - just paste attachables and deal with chests etc. - - for (int x = 0; x < width; ++x) { - for (int y = 0; y < height; ++y) { - for (int z = 0; z < length; ++z) { - int h = Settings.islandHeight + y - bedrock.getBlockY(); - if (h >= 0 && h < 255){ - int index = y * width * length + z * width + x; - IslandBlock block = new IslandBlock(x, y, z); - if (attachable.contains((int)blocks[index])) { - block.setBlock(blocks[index], data[index]); - // Tile Entities - if (tileEntitiesMap.containsKey(new BlockVector(x, y, z))) { - if (Util.isOnePointEight()) { - if (block.getTypeId() == Material.WALL_BANNER.getId()) { - block.setBanner(tileEntitiesMap.get(new BlockVector(x, y, z))); - } - } - // Wall Sign - if (block.getTypeId() == Material.WALL_SIGN.getId()) { - block.setSign(tileEntitiesMap.get(new BlockVector(x, y, z))); - } - } - islandBlocks.add(block); - } - } - } - } - } - //plugin.getLogger().info("DEBUG: islandBlocks size = " + islandBlocks.size()); - } - - /** - * @param biome the biome to set - */ - public void setBiome(Biome biome) { - this.biome = biome; - } - - /** - * @param description the description to set - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * @param heading the heading to set - */ - public void setHeading(String heading) { - this.heading = heading; - } - - public void setIcon(Material icon, int damage) { - this.icon = icon; - this.durability = damage; - } - /** - * @param icon the icon to set - */ - public void setIcon(Material icon) { - this.icon = icon; - } - - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } - - /** - * @param perm the perm to set - */ - public void setPerm(String perm) { - this.perm = perm; - } - - /** - * @param rating the rating to set - */ - public void setRating(int rating) { - this.rating = rating; - } - - /** - * @param useDefaultChest the useDefaultChest to set - */ - public void setUseDefaultChest(boolean useDefaultChest) { - this.useDefaultChest = useDefaultChest; - } - - /** - * @param usePhysics the usePhysics to set - */ - public void setUsePhysics(boolean usePhysics) { - this.usePhysics = usePhysics; - } - - - /** - * Removes all the air blocks if they are not to be pasted. - * @param pasteAir the pasteAir to set - */ - public void setPasteAir(boolean pasteAir) { - if (!pasteAir) { - Iterator it = islandBlocks.iterator(); - while (it.hasNext()) { - if (it.next().getTypeId() == 0) { - it.remove(); - } - } - } - //plugin.getLogger().info("DEBUG: islandBlocks after removing air blocks = " + islandBlocks.size()); - } - - /** - * Creates the AcidIsland default island block by block - * @param islandLoc - * @param player - * @param reason - */ - @SuppressWarnings("deprecation") - public void generateIslandBlocks(final Location islandLoc, final Player player, PasteReason reason) { - // AcidIsland - // Build island layer by layer - // Start from the base - // half sandstone; half sand - int x = islandLoc.getBlockX(); - int z = islandLoc.getBlockZ(); - World world = islandLoc.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); - b.setBiome(biome); - } - } - for (y = 1; y < Settings.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 < (Settings.islandHeight / 2)) { - b.setType(Material.SANDSTONE); - } else { - b.setType(Material.SAND); - b.setData((byte) 0); - } - } - } - } - // Then cut off the corners to make it round-ish - for (y = 0; y < Settings.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 = Settings.islandHeight + 4; y < Settings.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, Settings.islandHeight, z); - b.setType(Material.BEDROCK); - // Then add some more dirt in the classic shape - y = Settings.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 = Settings.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 = Settings.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 = Settings.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, (Settings.islandHeight + 5), z - 2); - - // Place a helpful sign in front of player - Block blockToChange = world.getBlockAt(x, Settings.islandHeight + 5, z + 3); - blockToChange.setType(Material.SIGN_POST); - Sign sign = (Sign) blockToChange.getState(); - /* - sign.setLine(0, BSkyBlock.getPlugin().myLocale(player.getUniqueId()).signLine1.replace("[player]", player.getName())); - sign.setLine(1, BSkyBlock.getPlugin().myLocale(player.getUniqueId()).signLine2.replace("[player]", player.getName())); - sign.setLine(2, BSkyBlock.getPlugin().myLocale(player.getUniqueId()).signLine3.replace("[player]", player.getName())); - sign.setLine(3, BSkyBlock.getPlugin().myLocale(player.getUniqueId()).signLine4.replace("[player]", player.getName())); - */ - ((org.bukkit.material.Sign) sign.getData()).setFacingDirection(BlockFace.NORTH); - sign.update(); - // Place the chest - no need to use the safe spawn function - // because we - // know what this island looks like - blockToChange = world.getBlockAt(x, Settings.islandHeight + 5, z + 1); - blockToChange.setType(Material.CHEST); - // Only set if the config has items in it - if (Settings.chestItems.length > 0) { - final Chest chest = (Chest) blockToChange.getState(); - final Inventory inventory = chest.getInventory(); - inventory.clear(); - inventory.setContents(Settings.chestItems); - 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); - // Teleport player - plugin.getIslands().homeTeleport(player); - // Reset any inventory, etc. This is done AFTER the teleport because other plugins may switch out inventory based on world - plugin.getPlayers().resetPlayer(player); - // Reset money if required - if (Settings.resetMoney) { - resetMoney(player); - } - // Show fancy titles! - /* - if (!Bukkit.getServer().getVersion().contains("(MC: 1.7")) { - if (!plugin.myLocale(player.getUniqueId()).islandSubTitle.isEmpty()) { - //plugin.getLogger().info("DEBUG: title " + player.getName() + " subtitle {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandSubTitle + "\", \"color\":\"" + plugin.myLocale(player.getUniqueId()).islandSubTitleColor + "\"}"); - plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), - "minecraft:title " + player.getName() + " subtitle {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandSubTitle.replace("[player]", player.getName()) + "\", \"color\":\"" + plugin.myLocale(player.getUniqueId()).islandSubTitleColor + "\"}"); - } - if (!plugin.myLocale(player.getUniqueId()).islandTitle.isEmpty()) { - //plugin.getLogger().info("DEBUG: title " + player.getName() + " title {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandTitle + "\", \"color\":\"" + plugin.myLocale(player.getUniqueId()).islandTitleColor + "\"}"); - plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), - "minecraft:title " + player.getName() + " title {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandTitle.replace("[player]", player.getName()) + "\", \"color\":\"" + plugin.myLocale(player.getUniqueId()).islandTitleColor + "\"}"); - } - if (!plugin.myLocale(player.getUniqueId()).islandDonate.isEmpty() && !plugin.myLocale(player.getUniqueId()).islandURL.isEmpty()) { - //plugin.getLogger().info("DEBUG: tellraw " + player.getName() + " {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandDonate + "\",\"color\":\"" + plugin.myLocale(player.getUniqueId()).islandDonateColor + "\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"" - // + plugin.myLocale(player.getUniqueId()).islandURL + "\"}}"); - plugin.getServer().dispatchCommand( - plugin.getServer().getConsoleSender(), - "minecraft:tellraw " + player.getName() + " {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandDonate.replace("[player]", player.getName()) + "\",\"color\":\"" + plugin.myLocale(player.getUniqueId()).islandDonateColor + "\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"" - + plugin.myLocale(player.getUniqueId()).islandURL + "\"}}"); - } - }*/ - if (reason.equals(PasteReason.NEW_ISLAND)) { - // Run any commands that need to be run at the start - //plugin.getLogger().info("DEBUG: First time 2"); - if (!player.hasPermission(Settings.PERMPREFIX + "command.newexempt")) { - //plugin.getLogger().info("DEBUG: Executing new island commands 2"); - //IslandCmd.runCommands(Settings.startCommands, player); - } - } else if (reason.equals(PasteReason.RESET)) { - // Run any commands that need to be run at reset - //plugin.getLogger().info("DEBUG: Reset"); - if (!player.hasPermission(Settings.PERMPREFIX + "command.resetexempt")) { - //plugin.getLogger().info("DEBUG: Executing reset island commands"); - // IslandCmd.runCommands(Settings.resetCommands, player); - } - } - if (!islandCompanion.isEmpty()) { - Bukkit.getServer().getScheduler().runTaskLater(BSkyBlock.getPlugin(), new Runnable() { - @Override - public void run() { - spawnCompanion(player, location); - } - }, 40L); - } - } - /** - * Get child tag of a NBT structure. - * - * @param items - * The parent tag map - * @param key - * The name of the tag to get - * @param expected - * The expected type of the tag - * @return child tag casted to the expected type - */ - private static T getChildTag(Map items, String key, Class expected) throws IllegalArgumentException { - if (!items.containsKey(key)) { - throw new IllegalArgumentException("Schematic file is missing a \"" + key + "\" tag"); - } - Tag tag = items.get(key); - if (!expected.isInstance(tag)) { - throw new IllegalArgumentException(key + " tag is not of tag type " + expected.getName()); - } - return expected.cast(tag); - } - /** - * Spawns a random companion for the player with a random name at the location given - * @param player - * @param location - */ - protected void spawnCompanion(Player player, Location location) { - // Older versions of the server require custom names to only apply to Living Entities - //Bukkit.getLogger().info("DEBUG: spawning compantion at " + location); - if (!islandCompanion.isEmpty() && location != null) { - Random rand = new Random(); - int randomNum = rand.nextInt(islandCompanion.size()); - EntityType type = islandCompanion.get(randomNum); - if (type != null) { - LivingEntity companion = (LivingEntity) location.getWorld().spawnEntity(location, type); - if (!companionNames.isEmpty()) { - randomNum = rand.nextInt(companionNames.size()); - String name = companionNames.get(randomNum).replace("[player]", player.getName()); - //plugin.getLogger().info("DEBUG: name is " + name); - companion.setCustomName(name); - companion.setCustomNameVisible(true); - } - } - } - } - - /** - * @param islandCompanion the islandCompanion to set - */ - public void setIslandCompanion(List islandCompanion) { - this.islandCompanion = islandCompanion; - } - - /** - * @param companionNames the companionNames to set - */ - public void setCompanionNames(List companionNames) { - this.companionNames = companionNames; - } - - /** - * @param defaultChestItems the defaultChestItems to set - */ - public void setDefaultChestItems(ItemStack[] defaultChestItems) { - this.defaultChestItems = defaultChestItems; - } - - /** - * @return if Biome is HELL, this is true - */ - public boolean isInNether() { - if (biome == Biome.HELL) { - return true; - } - return false; - } - - /** - * @return the partnerName - */ - public String getPartnerName() { - return partnerName; - } - - /** - * @param partnerName the partnerName to set - */ - public void setPartnerName(String partnerName) { - this.partnerName = partnerName; - } - - /** - * @return the pasteEntities - */ - public boolean isPasteEntities() { - return pasteEntities; - } - - /** - * @param pasteEntities the pasteEntities to set - */ - public void setPasteEntities(boolean pasteEntities) { - this.pasteEntities = pasteEntities; - } - - /** - * Whether the schematic is visible or not - * @return the visible - */ - public boolean isVisible() { - return visible; - } - - /** - * Sets if the schematic can be seen in the schematics GUI or not by the player - * @param visible the visible to set - */ - public void setVisible(boolean visible) { - this.visible = visible; - } - - /** - * @return the order - */ - public int getOrder() { - return order; - } - - /** - * @param order the order to set - */ - public void setOrder(int order) { - this.order = order; - } - - - /** - * @return true if player spawn exists in this schematic - */ - public boolean isPlayerSpawn() { - if (playerSpawn == null) { - return false; - } - return true; - } - - /** - * @return the playerSpawn Location given a paste location - */ - public Location getPlayerSpawn(Location pasteLocation) { - return pasteLocation.clone().add(playerSpawn); - } - - /** - * @param playerSpawnBlock the playerSpawnBlock to set - * @return true if block is found otherwise false - */ - @SuppressWarnings("deprecation") - public boolean setPlayerSpawnBlock(Material playerSpawnBlock) { - if (bedrock == null) { - return false; - } - playerSpawn = null; - // Run through the schematic and try and find the spawnBlock - for (IslandBlock islandBlock : islandBlocks) { - if (islandBlock.getTypeId() == playerSpawnBlock.getId()) { - playerSpawn = islandBlock.getVector().subtract(bedrock).add(new Vector(0.5D,0D,0.5D)); - // Set the block to air - islandBlock.setTypeId((short)0); - return true; - } - } - return false; - } - - - /** - * @return the levelHandicap - */ - public int getLevelHandicap() { - return levelHandicap; - } - - /** - * @param levelHandicap the levelHandicap to set - */ - public void setLevelHandicap(int levelHandicap) { - this.levelHandicap = levelHandicap; - } - - /** - * Set the cost - * @param cost - */ - public void setCost(double cost) { - this.cost = cost; - } - - /** - * @return the cost - */ - public double getCost() { - return cost; - } - - private void resetMoney(Player player) { - if (!Settings.useEconomy) { - return; - } - // Set player's balance in acid island to the starting balance - try { - // plugin.getLogger().info("DEBUG: " + player.getName() + " " + - // Settings.general_worldName); - if (VaultHelper.econ == null) { - // plugin.getLogger().warning("DEBUG: econ is null!"); - VaultHelper.setupEconomy(); - } - Double playerBalance = VaultHelper.econ.getBalance(player, Settings.worldName); - // plugin.getLogger().info("DEBUG: playerbalance = " + - // playerBalance); - // Round the balance to 2 decimal places and slightly down to - // avoid issues when withdrawing the amount later - BigDecimal bd = new BigDecimal(playerBalance); - bd = bd.setScale(2, RoundingMode.HALF_DOWN); - playerBalance = bd.doubleValue(); - // plugin.getLogger().info("DEBUG: playerbalance after rounding = " - // + playerBalance); - if (playerBalance != Settings.startingMoney) { - if (playerBalance > Settings.startingMoney) { - Double difference = playerBalance - Settings.startingMoney; - EconomyResponse response = VaultHelper.econ.withdrawPlayer(player, Settings.worldName, difference); - // plugin.getLogger().info("DEBUG: withdrawn"); - if (response.transactionSuccess()) { - plugin.getLogger().info( - "FYI:" + player.getName() + " had " + VaultHelper.econ.format(playerBalance) + " when they typed /island and it was set to " - + Settings.startingMoney); - } else { - plugin.getLogger().warning( - "Problem trying to withdraw " + playerBalance + " from " + player.getName() + "'s account when they typed /island!"); - plugin.getLogger().warning("Error from economy was: " + response.errorMessage); - } - } else { - Double difference = Settings.startingMoney - playerBalance; - EconomyResponse response = VaultHelper.econ.depositPlayer(player, Settings.worldName, difference); - if (response.transactionSuccess()) { - plugin.getLogger().info( - "FYI:" + player.getName() + " had " + VaultHelper.econ.format(playerBalance) + " when they typed /island and it was set to " - + Settings.startingMoney); - } else { - plugin.getLogger().warning( - "Problem trying to deposit " + playerBalance + " from " + player.getName() + "'s account when they typed /island!"); - plugin.getLogger().warning("Error from economy was: " + response.errorMessage); - } - - } - } - } catch (final Exception e) { - plugin.getLogger().severe("Error trying to zero " + player.getName() + "'s account when they typed /island!"); - plugin.getLogger().severe(e.getMessage()); - } - - } -} \ No newline at end of file diff --git a/src/main/java/us/tastybento/bskyblock/schematics/SchematicsMgr.java b/src/main/java/us/tastybento/bskyblock/schematics/SchematicsMgr.java deleted file mode 100644 index 250d75ecc..000000000 --- a/src/main/java/us/tastybento/bskyblock/schematics/SchematicsMgr.java +++ /dev/null @@ -1,185 +0,0 @@ -package us.tastybento.bskyblock.schematics; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; - -import org.bukkit.Material; -import org.bukkit.block.Biome; -import org.bukkit.entity.Player; - -import us.tastybento.bskyblock.BSkyBlock; -import us.tastybento.bskyblock.config.Settings; -import us.tastybento.bskyblock.generators.IslandWorld; -import us.tastybento.bskyblock.util.VaultHelper; - -public class SchematicsMgr { - private BSkyBlock plugin; - private static HashMap schematics = new HashMap(); - - /** - * Class to hold all schematics that are available - * @param plugin - */ - public SchematicsMgr(BSkyBlock plugin) { - this.plugin = plugin; - loadSchematics(); - } - - /** - * Loads schematics. If the default - * island is not included, it will be made - */ - public void loadSchematics() { - // Check if there is a schematic folder and make it if it does not exist - File schematicFolder = new File(plugin.getDataFolder(), "schematics"); - if (!schematicFolder.exists()) { - schematicFolder.mkdir(); - } - // Clear the schematic list that is kept in memory - schematics.clear(); - // Load the default schematic if it exists - // Set up the default schematic - File schematicFile = new File(schematicFolder, "island.schematic"); - File netherFile = new File(schematicFolder, "nether.schematic"); - if (!schematicFile.exists()) { - //plugin.getLogger().info("Default schematic does not exist..."); - // Only copy if the default exists - if (plugin.getResource("schematics/island.schematic") != null) { - plugin.getLogger().info("Default schematic does not exist, saving it..."); - plugin.saveResource("schematics/island.schematic", false); - // Add it to schematics - try { - schematics.put("default",new Schematic(plugin, schematicFile)); - } catch (IOException e) { - plugin.getLogger().severe("Could not load default schematic!"); - e.printStackTrace(); - } - // If this is repeated later due to the schematic config, fine, it will only add info - } else { - // No islands.schematic in the jar, so just make the default using - // built-in island generation - schematics.put("default",new Schematic(plugin)); - } - //plugin.getLogger().info("Loaded default nether schematic"); - } else { - // It exists, so load it - try { - schematics.put("default",new Schematic(plugin, schematicFile)); - //plugin.getLogger().info("Loaded default island schematic."); - } catch (IOException e) { - plugin.getLogger().severe("Could not load default schematic!"); - e.printStackTrace(); - } - } - // Add the nether default too - if (!netherFile.exists()) { - if (plugin.getResource("schematics/nether.schematic") != null) { - plugin.saveResource("schematics/nether.schematic", false); - - // Add it to schematics - try { - Schematic netherIsland = new Schematic(plugin, netherFile); - netherIsland.setVisible(false); - schematics.put("nether", netherIsland); - //plugin.getLogger().info("Loaded default nether schematic."); - } catch (IOException e) { - plugin.getLogger().severe("Could not load default nether schematic!"); - e.printStackTrace(); - } - } else { - plugin.getLogger().severe("Could not find default nether schematic!"); - } - } else { - // It exists, so load it - try { - Schematic netherIsland = new Schematic(plugin, netherFile); - netherIsland.setVisible(false); - schematics.put("nether", netherIsland); - //plugin.getLogger().info("Loaded default nether schematic."); - } catch (IOException e) { - plugin.getLogger().severe("Could not load default nether schematic!"); - e.printStackTrace(); - } - } - // Set up some basic settings - if (schematics.containsKey("default")) { - schematics.get("default").setName("Island"); - schematics.get("default").setDescription(""); - schematics.get("default").setPartnerName("nether"); - schematics.get("default").setBiome(Settings.defaultBiome); - schematics.get("default").setIcon(Material.GRASS); - if (Settings.chestItems.length == 0) { - schematics.get("default").setUseDefaultChest(false); - } - schematics.get("default").setOrder(0); - } - if (schematics.containsKey("nether")) { - schematics.get("nether").setName("NetherBlock Island"); - schematics.get("nether").setDescription("Nether Island"); - schematics.get("nether").setPartnerName("default"); - schematics.get("nether").setBiome(Biome.HELL); - schematics.get("nether").setIcon(Material.NETHERRACK); - schematics.get("nether").setVisible(false); - schematics.get("nether").setPasteEntities(true); - if (Settings.chestItems.length == 0) { - schematics.get("nether").setUseDefaultChest(false); - } - } - - // TODO: Load other settings from config.yml - } - - /** - * Get schematic with name - * @param name - * @return schematic or null if it does not exist - */ - public Schematic getSchematic(String name) { - return schematics.get(name); - } - - /** - * List schematics this player can access. If @param ignoreNoPermission is true, then only - * schematics with a specific permission set will be checked. I.e., no common schematics will - * be returned (including the default one). - * @param player - * @param ignoreNoPermission - * @return List of schematics this player can use based on their permission level - */ - public List getSchematics(Player player, boolean ignoreNoPermission) { - List result = new ArrayList<>(); - // Find out what schematics this player can choose from - //Bukkit.getLogger().info("DEBUG: Checking schematics for " + player.getName()); - for (Schematic schematic : schematics.values()) { - //Bukkit.getLogger().info("DEBUG: schematic name is '"+ schematic.getName() + "'"); - //Bukkit.getLogger().info("DEBUG: perm is " + schematic.getPerm()); - if ((!ignoreNoPermission && schematic.getPerm().isEmpty()) || VaultHelper.hasPerm(player, schematic.getPerm())) { - //Bukkit.getLogger().info("DEBUG: player can use this schematic"); - // Only add if it's visible - if (schematic.isVisible()) { - // Check if it's a nether island, but the nether is not enables - if (schematic.getBiome().equals(Biome.HELL)) { - if (Settings.netherGenerate && IslandWorld.getNetherWorld() != null) { - result.add(schematic); - } - } else { - result.add(schematic); - } - } - - } - } - // Sort according to order - Collections.sort(result, (s1, s2) -> (s2.getOrder() < s1.getOrder()) ? 1 : -1); - return result; - } - - public HashMap getAll() { - return schematics; - } - -} diff --git a/src/main/java/us/tastybento/bskyblock/util/Util.java b/src/main/java/us/tastybento/bskyblock/util/Util.java index 1ca0a1b4d..e51261604 100755 --- a/src/main/java/us/tastybento/bskyblock/util/Util.java +++ b/src/main/java/us/tastybento/bskyblock/util/Util.java @@ -1,7 +1,6 @@ package us.tastybento.bskyblock.util; import java.io.File; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; @@ -31,7 +30,6 @@ import org.bukkit.plugin.Plugin; import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.generators.IslandWorld; -import us.tastybento.bskyblock.util.nms.NMSAbstraction; import us.tastybento.bskyblock.util.placeholders.PlaceholderHandler; /** @@ -53,38 +51,6 @@ public class Util { } } - /** - * Checks what version the server is running and picks the appropriate NMS handler, or fallback - * @return NMSAbstraction class - * @throws ClassNotFoundException - * @throws IllegalArgumentException - * @throws SecurityException - * @throws InstantiationException - * @throws IllegalAccessException - * @throws InvocationTargetException - * @throws NoSuchMethodException - */ - public static NMSAbstraction getNMSHandler() throws ClassNotFoundException, IllegalArgumentException, - SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, - NoSuchMethodException { - String serverPackageName = plugin.getServer().getClass().getPackage().getName(); - String pluginPackageName = plugin.getClass().getPackage().getName(); - String version = serverPackageName.substring(serverPackageName.lastIndexOf('.') + 1); - Class clazz; - try { - clazz = Class.forName(pluginPackageName + ".util.nms." + version + ".NMSHandler"); - } catch (Exception e) { - plugin.getLogger().info("No NMS Handler found for " + version + ", falling back to Bukkit API."); - clazz = Class.forName(pluginPackageName + ".util.nms.fallback.NMSHandler"); - } - // Check if we have a NMSAbstraction implementing class at that location. - if (NMSAbstraction.class.isAssignableFrom(clazz)) { - return (NMSAbstraction) clazz.getConstructor().newInstance(); - } else { - throw new IllegalStateException("Class " + clazz.getName() + " does not implement NMSAbstraction"); - } - } - /** * Converts a serialized location to a Location. Returns null if string is * empty diff --git a/src/main/java/us/tastybento/bskyblock/util/nms/NMSAbstraction.java b/src/main/java/us/tastybento/bskyblock/util/nms/NMSAbstraction.java deleted file mode 100755 index 6d1ceb871..000000000 --- a/src/main/java/us/tastybento/bskyblock/util/nms/NMSAbstraction.java +++ /dev/null @@ -1,73 +0,0 @@ -package us.tastybento.bskyblock.util.nms; - -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import us.tastybento.org.jnbt.Tag; - -public interface NMSAbstraction { - - /** - * Update the low-level chunk information for the given block to the new block ID and data. This - * change will not be propagated to clients until the chunk is refreshed to them. - * @param block - * @param blockId - * @param data - * @param applyPhysics - */ - public void setBlockSuperFast(Block block, int blockId, byte data, boolean applyPhysics); - - public ItemStack setBook(Tag item); - - /** - * Sets a block to be an item stack - * @param block - * @param itemStack - */ - public void setFlowerPotBlock(Block block, ItemStack itemStack); - - boolean isPotion(ItemStack item); - - /** - * Returns a potion ItemStack - * @param itemMaterial - * @param itemTag - * @param chestItem - * @return - */ - public ItemStack setPotion(Material itemMaterial, Tag itemTag, ItemStack chestItem); - - /** - * Gets a monster egg itemstack - * @param type - * @param amount - * @return itemstack - */ - public ItemStack getSpawnEgg(EntityType type, int amount); - - /** - * Send an action bar message to player - * @param player - * @param message - */ - public void sendActionBar(Player player, String message); - - - /** - * Send a title to a player - * @param player - * @param message - */ - public void sendTitle(Player player, String message); - - - /** - * Send a subtitle to a player - * @param player - * @param message - */ - public void sendSubtitle(Player player, String message); -} diff --git a/src/main/java/us/tastybento/bskyblock/util/nms/fallback/NMSHandler.java b/src/main/java/us/tastybento/bskyblock/util/nms/fallback/NMSHandler.java deleted file mode 100755 index aee3429b9..000000000 --- a/src/main/java/us/tastybento/bskyblock/util/nms/fallback/NMSHandler.java +++ /dev/null @@ -1,142 +0,0 @@ -package us.tastybento.bskyblock.util.nms.fallback; - -import java.util.Map; - -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.inventory.meta.SpawnEggMeta; -import org.bukkit.potion.PotionData; -import org.bukkit.potion.PotionType; - -import us.tastybento.bskyblock.util.nms.NMSAbstraction; -import us.tastybento.org.jnbt.CompoundTag; -import us.tastybento.org.jnbt.StringTag; -import us.tastybento.org.jnbt.Tag; - -/** - * A fallback NMS Handler when the NMS version is not supported by BSkyBlock - * - * @author Tastybento - * @author Poslovitch - */ -public class NMSHandler implements NMSAbstraction{ - - @Override - public void sendActionBar(Player player, String message) { - // TODO Auto-generated method stub - - } - - @Override - public void sendTitle(Player player, String message) { - // TODO Auto-generated method stub - - } - - @Override - public void sendSubtitle(Player player, String message) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see com.wasteofplastic.askyblock.nms.NMSAbstraction#getSpawnEgg(org.bukkit.entity.EntityType, int) - */ - @Override - public ItemStack getSpawnEgg(EntityType type, int amount) { - ItemStack egg = new ItemStack(Material.MONSTER_EGG, amount); - SpawnEggMeta spm = (SpawnEggMeta)egg.getItemMeta(); - spm.setSpawnedType(type); - egg.setItemMeta(spm); - return egg; - } - - @Override - public boolean isPotion(ItemStack item) { - if (item.getType().equals(Material.POTION) && item.getDurability() != 0) { - return true; - } - return false; - } - - /* (non-Javadoc) - * @see com.wasteofplastic.askyblock.nms.NMSAbstraction#setBlockSuperFast(org.bukkit.block.Block, org.bukkit.Material) - */ - @SuppressWarnings("deprecation") - @Override - public void setBlockSuperFast(Block b, int blockId, byte data, boolean applyPhysics) { - b.setTypeIdAndData(blockId, data, applyPhysics); - } - - @Override - public ItemStack setBook(Tag item) { - Bukkit.getLogger().warning("Written books in schematics not supported with this version of server"); - return new ItemStack(Material.WRITTEN_BOOK); - } - - @SuppressWarnings("deprecation") - @Override - public void setFlowerPotBlock(Block block, ItemStack itemStack) { - block.setTypeIdAndData(itemStack.getTypeId(), itemStack.getData().getData(), false); - - } - - @Override - public ItemStack setPotion(Material itemMaterial, Tag itemTags, - ItemStack chestItem) { - // Try some backwards compatibility with new 1.9 schematics - Map contents = (Map) ((CompoundTag) itemTags).getValue().get("tag").getValue(); - StringTag stringTag = ((StringTag)contents.get("Potion")); - if (stringTag != null) { - String tag = stringTag.getValue().replace("minecraft:", ""); - PotionType type = null; - boolean strong = tag.contains("strong"); - boolean _long = tag.contains("long"); - //Bukkit.getLogger().info("tag = " + tag); - if(tag.equals("fire_resistance") || tag.equals("long_fire_resistance")){ - type = PotionType.FIRE_RESISTANCE; - }else if(tag.equals("harming") || tag.equals("strong_harming")){ - type = PotionType.INSTANT_DAMAGE; - }else if(tag.equals("healing") || tag.equals("strong_healing")){ - type = PotionType.INSTANT_HEAL; - }else if(tag.equals("invisibility") || tag.equals("long_invisibility")){ - type = PotionType.INVISIBILITY; - }else if(tag.equals("leaping") || tag.equals("long_leaping") || tag.equals("strong_leaping")){ - type = PotionType.JUMP; - }else if(tag.equals("night_vision") || tag.equals("long_night_vision")){ - type = PotionType.NIGHT_VISION; - }else if(tag.equals("poison") || tag.equals("long_poison") || tag.equals("strong_poison")){ - type = PotionType.POISON; - }else if(tag.equals("regeneration") || tag.equals("long_regeneration") || tag.equals("strong_regeneration")){ - type = PotionType.REGEN; - }else if(tag.equals("slowness") || tag.equals("long_slowness")){ - type = PotionType.SLOWNESS; - }else if(tag.equals("swiftness") || tag.equals("long_swiftness") || tag.equals("strong_swiftness")){ - type = PotionType.SPEED; - }else if(tag.equals("strength") || tag.equals("long_strength") || tag.equals("strong_strength")){ - type = PotionType.STRENGTH; - }else if(tag.equals("water_breathing") || tag.equals("long_water_breathing")){ - type = PotionType.WATER_BREATHING; - }else if(tag.equals("water")){ - type = PotionType.WATER; - }else if(tag.equals("weakness") || tag.equals("long_weakness")){ - type = PotionType.WEAKNESS; - }else{ - return chestItem; - } - chestItem = new ItemStack(Material.POTION, chestItem.getAmount()); - PotionMeta pm = (PotionMeta)chestItem.getItemMeta(); - PotionData pd = new PotionData(type, _long, strong); - pm.setBasePotionData(pd); - chestItem.setItemMeta(pm); - } - - return chestItem; - } - -} diff --git a/src/main/java/us/tastybento/bskyblock/util/nms/v1_12_R1/NMSHandler.java b/src/main/java/us/tastybento/bskyblock/util/nms/v1_12_R1/NMSHandler.java deleted file mode 100755 index 49a0f2e32..000000000 --- a/src/main/java/us/tastybento/bskyblock/util/nms/v1_12_R1/NMSHandler.java +++ /dev/null @@ -1,228 +0,0 @@ -package us.tastybento.bskyblock.util.nms.v1_12_R1; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import net.minecraft.server.v1_12_R1.BlockPosition; -import net.minecraft.server.v1_12_R1.IBlockData; -import net.minecraft.server.v1_12_R1.NBTTagCompound; -import net.minecraft.server.v1_12_R1.NBTTagList; -import net.minecraft.server.v1_12_R1.NBTTagString; -import net.minecraft.server.v1_12_R1.TileEntityFlowerPot; -import us.tastybento.bskyblock.util.nms.NMSAbstraction; -import us.tastybento.org.jnbt.CompoundTag; -import us.tastybento.org.jnbt.ListTag; -import us.tastybento.org.jnbt.StringTag; -import us.tastybento.org.jnbt.Tag; - -/** - * NMS Handler for v1_12_R1 - * - * @author Tastybento - * @author Poslovitch - */ -public class NMSHandler implements NMSAbstraction{ - private static HashMap bToMConversion; - - static { - bToMConversion = new HashMap (); - bToMConversion.put(EntityType.MUSHROOM_COW, "mooshroom"); - bToMConversion.put(EntityType.PIG_ZOMBIE, "zombie_pigman"); - } - - @Override - public void setBlockSuperFast(Block b, int blockId, byte data, boolean applyPhysics) { - net.minecraft.server.v1_12_R1.World w = ((CraftWorld) b.getWorld()).getHandle(); - net.minecraft.server.v1_12_R1.Chunk chunk = w.getChunkAt(b.getX() >> 4, b.getZ() >> 4); - BlockPosition bp = new BlockPosition(b.getX(), b.getY(), b.getZ()); - int combined = blockId + (data << 12); - IBlockData ibd = net.minecraft.server.v1_12_R1.Block.getByCombinedId(combined); - if (applyPhysics) { - w.setTypeAndData(bp, ibd, 3); - } else { - w.setTypeAndData(bp, ibd, 2); - } - chunk.a(bp, ibd); - } - - @Override - public ItemStack setBook(Tag item) { - ItemStack chestItem = new ItemStack(Material.WRITTEN_BOOK); - //Bukkit.getLogger().info("item data"); - //Bukkit.getLogger().info(item.toString()); - if (((CompoundTag) item).getValue().containsKey("tag")) { - Map contents = (Map) ((CompoundTag) item).getValue().get("tag").getValue(); - //BookMeta bookMeta = (BookMeta) chestItem.getItemMeta(); - String author = ""; - if (contents.containsKey("author")) { - author = ((StringTag)contents.get("author")).getValue(); - } - //Bukkit.getLogger().info("Author: " + author); - //bookMeta.setAuthor(author); - String title = ""; - if (contents.containsKey("title")) { - title = ((StringTag)contents.get("title")).getValue(); - } - //Bukkit.getLogger().info("Title: " + title); - //bookMeta.setTitle(title); - List lore = new ArrayList(); - if (contents.containsKey("display")) { - Map display = (Map) (contents.get("display")).getValue(); - List loreTag = ((ListTag)display.get("Lore")).getValue(); - for (Tag s: loreTag) { - lore.add(((StringTag)s).getValue()); - } - } - //Bukkit.getLogger().info("Lore: " + lore); - net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(chestItem); - // Pages - NBTTagCompound tag = new NBTTagCompound(); //Create the NMS Stack's NBT (item data) - tag.setString("title", title); //Set the book's title - tag.setString("author", author); - if (contents.containsKey("pages")) { - NBTTagList pages = new NBTTagList(); - List pagesTag = ((ListTag)contents.get("pages")).getValue(); - for (Tag s: pagesTag) { - pages.add(new NBTTagString(((StringTag)s).getValue())); - } - tag.set("pages", pages); //Add the pages to the tag - } - stack.setTag(tag); //Apply the tag to the item - chestItem = CraftItemStack.asCraftMirror(stack); - ItemMeta bookMeta = (ItemMeta) chestItem.getItemMeta(); - bookMeta.setLore(lore); - chestItem.setItemMeta(bookMeta); - } - return chestItem; - - } - - /* (non-Javadoc) - * @see com.wasteofplastic.askyblock.nms.NMSAbstraction#setBlock(org.bukkit.block.Block, org.bukkit.inventory.ItemStack) - */ - @Override - public void setFlowerPotBlock(final Block block, final ItemStack itemStack) { - if (block.getType().equals(Material.FLOWER_POT)) { - Location loc = block.getLocation(); - CraftWorld cw = (CraftWorld)block.getWorld(); - BlockPosition bp = new BlockPosition(loc.getX(), loc.getY(), loc.getZ()); - TileEntityFlowerPot te = (TileEntityFlowerPot)cw.getHandle().getTileEntity(bp); - //Bukkit.getLogger().info("Debug: flowerpot materialdata = " + (new ItemStack(potItem, 1,(short) potItemData).toString())); - net.minecraft.server.v1_12_R1.ItemStack cis = CraftItemStack.asNMSCopy(itemStack); - te.setContents(cis); - te.update(); - } - } - - /* (non-Javadoc) - * @see com.wasteofplastic.askyblock.nms.NMSAbstraction#isPotion(org.bukkit.inventory.ItemStack) - */ - @Override - public boolean isPotion(ItemStack item) { - //Bukkit.getLogger().info("DEBUG:item = " + item); - if (item.getType().equals(Material.POTION)) { - net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(item); - NBTTagCompound tag = stack.getTag(); - //Bukkit.getLogger().info("DEBUG: tag is " + tag); - //Bukkit.getLogger().info("DEBUG: display is " + tag.getString("display")); - /* - for (String list : tag.c()) { - Bukkit.getLogger().info("DEBUG: list = " + list); - }*/ - if (tag != null && (!tag.getString("Potion").equalsIgnoreCase("minecraft:water") || tag.getString("Potion").isEmpty())) { - return true; - } - } - return false; - } - - /* (non-Javadoc) - * @see com.wasteofplastic.acidisland.nms.NMSAbstraction#setPotion(com.wasteofplastic.org.jnbt.Tag) - */ - @SuppressWarnings({ "unchecked"}) - @Override - public ItemStack setPotion(Material material, Tag itemTags, ItemStack chestItem) { - Map cont = (Map) ((CompoundTag) itemTags).getValue(); - if (cont != null) { - if (((CompoundTag) itemTags).getValue().containsKey("tag")) { - Map contents = (Map)((CompoundTag) itemTags).getValue().get("tag").getValue(); - StringTag stringTag = ((StringTag)contents.get("Potion")); - if (stringTag != null) { - String tag = ((StringTag)contents.get("Potion")).getValue(); - //Bukkit.getLogger().info("DEBUG: potioninfo found: " + tag); - net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(chestItem); - NBTTagCompound tagCompound = stack.getTag(); - if(tagCompound == null){ - tagCompound = new NBTTagCompound(); - } - tagCompound.setString("Potion", tag); - stack.setTag(tagCompound); - return CraftItemStack.asBukkitCopy(stack); - } - } - } - // Schematic is old, the potions do not have tags - // Set it to zero so that the potion bottles don't look like giant purple and black blocks - chestItem.setDurability((short)0); - Bukkit.getLogger().warning("Potion in schematic is pre-V1.9 format and will just be water."); - return chestItem; - } - - /** - * Get spawn egg - * @param type - * @param amount - * @return - */ - public ItemStack getSpawnEgg(EntityType type, int amount) { - //Bukkit.getLogger().info("DEBUG: setting spawn egg " + type.toString()); - ItemStack item = new ItemStack(Material.MONSTER_EGG, amount); - net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(item); - NBTTagCompound tagCompound = stack.getTag(); - if(tagCompound == null){ - tagCompound = new NBTTagCompound(); - } - //Bukkit.getLogger().info("DEBUG: tag = " + tagCompound); - NBTTagCompound id = new NBTTagCompound(); - if (!bToMConversion.containsKey(type)) { - id.setString("id", "minecraft:" + type.toString().toLowerCase()); - } else { - id.setString("id", "minecraft:" + bToMConversion.get(type)); - } - tagCompound.set("EntityTag", id); - stack.setTag(tagCompound); - //Bukkit.getLogger().info("DEBUG: after tag = " + tagCompound); - return CraftItemStack.asBukkitCopy(stack); - } - - @Override - public void sendActionBar(Player player, String message) { - // TODO Auto-generated method stub - - } - - @Override - public void sendTitle(Player player, String message) { - // TODO Auto-generated method stub - - } - - @Override - public void sendSubtitle(Player player, String message) { - // TODO Auto-generated method stub - - } -} diff --git a/src/test/java/bskyblock/TestTest.java b/src/test/java/bskyblock/TestTest.java new file mode 100644 index 000000000..291a1f3bc --- /dev/null +++ b/src/test/java/bskyblock/TestTest.java @@ -0,0 +1,51 @@ +package bskyblock; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; + +import java.util.UUID; +import java.util.logging.Logger; + +import org.bukkit.Bukkit; +import org.bukkit.Server; +import org.bukkit.World; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import us.tastybento.bskyblock.api.events.team.TeamEvent; +import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason; + +public class TestTest { + private final UUID playerUUID = UUID.randomUUID(); + + @Before + public void setUp() { + World world = mock(World.class); + + + //Mockito.when(world.getWorldFolder()).thenReturn(worldFile); + + Server server = mock(Server.class); + Mockito.when(server.getLogger()).thenReturn(Logger.getAnonymousLogger()); + Mockito.when(server.getWorld("world")).thenReturn(world); + Mockito.when(server.getVersion()).thenReturn("TestTestMocking"); + Mockito.when(server.getVersion()).thenReturn("TestTestMocking"); + Bukkit.setServer(server); + } + + + @Test + public void createAndSave() { + + + TeamEvent event = TeamEvent.builder() + //.island(getIslands().getIsland(playerUUID)) + .reason(TeamReason.INFO) + .involvedPlayer(playerUUID) + .build(); + assertEquals(playerUUID, event.getPlayer()); + + } + +}