Package org.jnbt

Examples of org.jnbt.NBTInputStream


   * @throws IOException
   * @author Corrodias
   */
  protected static Coordinates getSpawn(final File level) throws IOException {
    try {
      final NBTInputStream input = new NBTInputStream(new FileInputStream(level));
      final CompoundTag originalTopLevelTag = (CompoundTag) input.readTag();
      input.close();

      final Map<String, Tag> originalData =
          ((CompoundTag) originalTopLevelTag.getValue().get("Data")).getValue();
      // This is our map of data. It is an unmodifiable map, for some
      // reason, so we have to make a copy.
View Full Code Here


   * @author Corrodias
   */
  protected static void setSpawn(final File level, final Coordinates xyz) throws IOException {

    try {
      final NBTInputStream input = new NBTInputStream(new FileInputStream(level));
      final CompoundTag originalTopLevelTag = (CompoundTag) input.readTag();
      input.close();

      //@formatter:off

            //Note: The Following Information is Old (from 2010), compared to the Data inside a current "level.dat".
            //However, What we look at (SpawnX,Y,Z and RandomSeed) have not changed.
View Full Code Here

    if (multi) {
      String outPath = file.getParent() + "/players/" + name +".dat";
      out = new File(outPath);
      backupFile(out);
      try {
        NBTInputStream inStream = new NBTInputStream(new FileInputStream(out));
        CompoundTag root = (CompoundTag)inStream.readTag();
        inStream.close();
       
        HashMap<String, Tag> rootMap = new HashMap<String, Tag>(root.getValue());
        ArrayList<Tag> posTag = new ArrayList<Tag>(((ListTag)rootMap.get("Pos")).getValue());
        posTag.set(0, new DoubleTag("x", x));
        posTag.set(1, new DoubleTag("y", 120));
        posTag.set(2, new DoubleTag("z", y));
        rootMap.put("Pos", new ListTag("Pos", DoubleTag.class, posTag));
        root = new CompoundTag("Data", rootMap);
        NBTOutputStream outStream = new NBTOutputStream(new FileOutputStream(out));
        outStream.writeTag(root);
        outStream.close();
      } catch (Exception e) {
        e.printStackTrace();
      }
     
    } else {
      out = file;
      backupFile(out);
      try {
        NBTInputStream inStream = new NBTInputStream(new FileInputStream(out));
        CompoundTag root = (CompoundTag)(((CompoundTag)inStream.readTag()).getValue().get("Data"));
        inStream.close();
       
        HashMap<String, Tag> rootMap = new HashMap<String, Tag>(root.getValue());
        HashMap<String, Tag> playerMap = new HashMap<String, Tag>(((CompoundTag)rootMap.get("Player")).getValue());
        ArrayList<Tag> posTag = new ArrayList<Tag>(((ListTag)playerMap.get("Pos")).getValue());
        posTag.set(0, new DoubleTag("x", x));
View Full Code Here

  public SaveLoader(File f) {
    file = f;
    players = new ArrayList<MapObjectPlayer>();
    back = new ArrayList<String>();
    try {
      NBTInputStream inStream = new NBTInputStream(new FileInputStream(f));
      CompoundTag root = (CompoundTag) ((CompoundTag)inStream.readTag()).getValue().get("Data");
      inStream.close();
      seed = (Long)(root.getValue().get("RandomSeed").getValue());
      if (root.getValue().get("generatorName") != null) {
        genType = Type.fromMixedCase((String)(root.getValue().get("generatorName").getValue()));
       
        if (genType == Type.CUSTOMIZED)
          generatorOptions = (String)root.getValue().get("generatorOptions").getValue();
      }
      CompoundTag playerTag = (CompoundTag)root.getValue().get("Player");
     
      File playersFolder = new File(f.getParent(), "players");
      boolean multi = (playersFolder.exists() && (playersFolder.listFiles().length > 0));
     
      if (multi)
        Log.i("Multiplayer map detected.");
      else
        Log.i("Singleplayer map detected.");
     
      if (!multi) {
        addPlayer("Player", playerTag);
      } else {
        File[] listing = playersFolder.listFiles();
        for (int i = 0; i < (listing != null ? listing.length : 0); i++) {
          if (listing[i].isFile()) {
            NBTInputStream playerInputStream = new NBTInputStream(new FileInputStream(listing[i]));
            addPlayer(listing[i].getName().split("\\.")[0], (CompoundTag) ((CompoundTag)playerInputStream.readTag()));
            playerInputStream.close();
          }
        }
       
      }
    } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.jnbt.NBTInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.