Schematics paste error! Need Help ASAP!

Discussion in 'Plugin Development' started by FluffyNarwhals, May 1, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    FluffyNarwhals

    When I try to paste a schematic file with this code:

    Code:java
    1. public Schematic loadSchematic(File file) throws IOException
    2. {
    3. FileInputStream stream = new FileInputStream(file);
    4. NBTInputStream nbtStream = new NBTInputStream(new GZIPInputStream(stream));
    5.  
    6. CompoundTag schematicTag = (CompoundTag) nbtStream.readTag();
    7. if (!schematicTag.getName().equals("Schematic")) {
    8. nbtStream.close();
    9. throw new IllegalArgumentException("Tag \"Schematic\" does not exist or is not first");
    10. }
    11.  
    12. @SuppressWarnings("unchecked")
    13. Map<String, Tag> schematic = schematicTag.getValue();
    14. if (!schematic.containsKey("Blocks")) {
    15. nbtStream.close();
    16. throw new IllegalArgumentException("Schematic file is missing a \"Blocks\" tag");
    17. }
    18.  
    19. short width = getChildTag(schematic, "Width", ShortTag.class).getValue();
    20. short length = getChildTag(schematic, "Length", ShortTag.class).getValue();
    21. short height = getChildTag(schematic, "Height", ShortTag.class).getValue();
    22.  
    23. String materials = getChildTag(schematic, "Materials", StringTag.class).getValue();
    24. if (!materials.equals("Alpha")) {
    25. nbtStream.close();
    26. throw new IllegalArgumentException("Schematic file is not an Alpha schematic");
    27. }
    28.  
    29. byte[] blocks = getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue();
    30. byte[] blockData = getChildTag(schematic, "Data", ByteArrayTag.class).getValue();
    31.  
    32. nbtStream.close();
    33.  
    34. return new Schematic(blocks, blockData, width, length, height);
    35. }
    36.  
    37. /**
    38.   * Get child tag of a NBT structure.
    39.   *
    40.   * @param items The parent tag map
    41.   * @param key The name of the tag to get
    42.   * @param expected The expected type of the tag
    43.   * @return child tag casted to the expected type
    44.   * @throws DataException if the tag does not exist or the tag is not of the
    45.   * expected type
    46.   */
    47. private static <T extends Tag> T getChildTag(Map<String, Tag> items, String key, Class<T> expected) throws IllegalArgumentException
    48. {
    49. if (!items.containsKey(key)) {
    50. throw new IllegalArgumentException("Schematic file is missing a \"" + key + "\" tag");
    51. }
    52. Tag tag = items.get(key);
    53. if (!expected.isInstance(tag)) {
    54. throw new IllegalArgumentException(key + " tag is not of tag type " + expected.getName());
    55. }
    56. return expected.cast(tag);
    57. }
    58.  
    59. public void pasteSchematic(World world, Location loc, Schematic schematic)
    60. {
    61. byte[] blocks = schematic.getBlocks();
    62. byte[] blockData = schematic.getData();
    63.  
    64. short length = schematic.getLenght();
    65. short width = schematic.getWidth();
    66. short height = schematic.getHeight();
    67.  
    68. for (int x = 0; x < width; ++x) {
    69. for (int y = 0; y < height; ++y) {
    70. for (int z = 0; z < length; ++z) {
    71. int index = y * width * length + z * width + x;
    72. Block block = new Location(world, x + loc.getX(), y + loc.getY(), z + loc.getZ()).getBlock();
    73. block.setTypeIdAndData(blocks[index], blockData[index], true);
    74. }
    75. }
    76. }
    77. }


    It gives me this error, even though the schematic file isn't corrupted!

    Code:
    2013-05-01 15:38:53 [SEVERE] java.util.zip.ZipException: Not in GZIP format
    2013-05-01 15:38:53 [SEVERE]    at java.util.zip.GZIPInputStream.readHeader(Unknown Source)
    2013-05-01 15:38:53 [SEVERE]    at java.util.zip.GZIPInputStream.<init>(Unknown Source)
    2013-05-01 15:38:53 [SEVERE]    at java.util.zip.GZIPInputStream.<init>(Unknown Source)
    2013-05-01 15:38:53 [SEVERE]    at org.jnbt.NBTInputStream.<init>(NBTInputStream.java:25)
    2013-05-01 15:38:53 [SEVERE]    at me.Noah.KingdomCraft.KingdomCraft.loadSchematic(KingdomCraft.java:373)
    2013-05-01 15:38:53 [SEVERE]    at me.Noah.KingdomCraft.KingdomCraft.onCommand(KingdomCraft.java:266)
    2013-05-01 15:38:53 [SEVERE]    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    2013-05-01 15:38:53 [SEVERE]    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:187)
    2013-05-01 15:38:53 [SEVERE]    at org.bukkit.craftbukkit.v1_5_R2.CraftServer.dispatchCommand(CraftServer.java:523)
    2013-05-01 15:38:53 [SEVERE]    at net.minecraft.server.v1_5_R2.PlayerConnection.handleCommand(PlayerConnection.java:967)
    2013-05-01 15:38:53 [SEVERE]    at net.minecraft.server.v1_5_R2.PlayerConnection.chat(PlayerConnection.java:885)
    2013-05-01 15:38:53 [SEVERE]    at net.minecraft.server.v1_5_R2.PlayerConnection.a(PlayerConnection.java:840)
    2013-05-01 15:38:53 [SEVERE]    at net.minecraft.server.v1_5_R2.Packet3Chat.handle(Packet3Chat.java:44)
    2013-05-01 15:38:53 [SEVERE]    at net.minecraft.server.v1_5_R2.NetworkManager.b(NetworkManager.java:292)
    2013-05-01 15:38:53 [SEVERE]    at net.minecraft.server.v1_5_R2.PlayerConnection.d(PlayerConnection.java:113)
    2013-05-01 15:38:53 [SEVERE]    at net.minecraft.server.v1_5_R2.ServerConnection.b(SourceFile:35)
    2013-05-01 15:38:53 [SEVERE]    at net.minecraft.server.v1_5_R2.DedicatedServerConnection.b(SourceFile:30)
    2013-05-01 15:38:53 [SEVERE]    at net.minecraft.server.v1_5_R2.MinecraftServer.r(MinecraftServer.java:580)
    2013-05-01 15:38:53 [SEVERE]    at net.minecraft.server.v1_5_R2.DedicatedServer.r(DedicatedServer.java:225)
    2013-05-01 15:38:53 [SEVERE]    at net.minecraft.server.v1_5_R2.MinecraftServer.q(MinecraftServer.java:476)
    2013-05-01 15:38:53 [SEVERE]    at net.minecraft.server.v1_5_R2.MinecraftServer.run(MinecraftServer.java:409)
    2013-05-01 15:38:53 [SEVERE]    at net.minecraft.server.v1_5_R2.ThreadServerApplication.run(SourceFile:573)
    Any help? Thanks in advance!
     
  2. Code:
    2013-05-01 15:38:53 [SEVERE] java.util.zip.ZipException: Not in GZIP format
    2013-05-01 15:38:53 [SEVERE]    at java.util.zip.GZIPInputStream.readHeader(Unknown Source)
    2013-05-01 15:38:53 [SEVERE]    at java.util.zip.GZIPInputStream.<init>(Unknown Source)
    2013-05-01 15:38:53 [SEVERE]    at java.util.zip.GZIPInputStream.<init>(Unknown Source)
    2013-05-01 15:38:53 [SEVERE]    at org.jnbt.NBTInputStream.<init>(NBTInputStream.java:25)
    
    Remove the GZipInputStream your feeding into it? It might be making a GZipInputStream inside the NBTstream.

    Either that or yes, the schematic is indeed corrupted.
     
  3. Offline

    FluffyNarwhals

    That worked thanks! But now, it's only pasting about 1 or 2 chunks of it, do you know any solution?
     
Thread Status:
Not open for further replies.

Share This Page