Пример #1
0
 @Override
 public void doCommand(ItemStack duplicator, EntityPlayerMP sender, String[] arguments) {
   try {
     String name = arguments.length == 2 ? arguments[1] : sender.getCommandSenderName();
     File file =
         new File(
             DimensionManager.getCurrentSaveRootDirectory().getPath()
                 + File.separator
                 + "managers"
                 + File.separator
                 + name
                 + ".nbt");
     if (!file.exists()) {
       throw new CommandException("Couldn't access file: " + name + ".nbt");
     }
     NBTTagCompound tagCompound = CompressedStreamTools.read(file);
     duplicator.setTagCompound(unstripBaseNBT(tagCompound));
     CommandBase.getCommandSenderAsPlayer(sender)
         .addChatComponentMessage(
             new ChatComponentText(
                 LocalizationHelper.translateFormatted(
                     "stevesaddons.command.loadSuccess", name + ".nbt")));
   } catch (IOException e) {
     throw new CommandException("stevesaddons.command.loadFailed");
   }
 }
Пример #2
0
  public static DataContainer readDataFromRegion(DataInputStream stream) throws IOException {
    if (stream == null) {
      return null;
    }
    NBTTagCompound data = CompressedStreamTools.read(stream);

    // Checks are based on AnvilChunkLoader#checkedReadChunkFromNBT

    if (!data.hasKey(NbtDataUtil.CHUNK_DATA_LEVEL, NbtDataUtil.TAG_COMPOUND)) {
      return null;
    }
    NBTTagCompound level = data.getCompoundTag(NbtDataUtil.CHUNK_DATA_LEVEL);
    if (!level.hasKey(NbtDataUtil.CHUNK_DATA_SECTIONS, NbtDataUtil.TAG_LIST)) {
      return null;
    }
    return NbtTranslator.getInstance().translateFrom(level);
  }
Пример #3
0
 public static NBTTagCompound readNBT(File file) throws IOException {
   if (!file.exists()) {
     return null;
   }
   FileInputStream in = new FileInputStream(file);
   NBTTagCompound tag;
   try {
     tag = CompressedStreamTools.readCompressed(in);
   } catch (ZipException e) {
     if (e.getMessage().equals("Not in GZIP format")) {
       tag = CompressedStreamTools.read(file);
     } else {
       throw e;
     }
   }
   in.close();
   return tag;
 }
Пример #4
0
 @SuppressWarnings("unchecked")
 public void loadPlayer(EntityPlayerMP player) {
   File saveDirPath = new File(getSaveFolder(player));
   if (!saveDirPath.exists()) saveDirPath.mkdirs();
   File playerFile = new File(getSaveFolder(player) + player.username + ".pk");
   if (playerFile.exists()) {
     PlayerStorage p = new PlayerStorage(player);
     try {
       p.readFromNBT(
           CompressedStreamTools.read(new DataInputStream(new FileInputStream(playerFile))));
     } catch (FileNotFoundException e) {
       System.out.println("Couldn't read player data file for " + player.username);
     } catch (IOException e) {
       System.out.println("Couldn't read player data file for " + player.username);
     }
     playerPokemonList.add(p);
   } else {
     PlayerStorage p = new PlayerStorage(player);
     playerPokemonList.add(p);
   }
 }