Created
February 7, 2013 04:17
-
-
Save natemort/4728450 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void saveChestFile(Location loc, Inventory inv, String playerName){ | |
| File file = new File(getDataFolder(), loc.toString() + ".yml"); | |
| //Create a new File if one does not exist | |
| if(!file.exists()){ | |
| try{ | |
| file.createNewFile(); | |
| }catch(IOException e){ | |
| getLogger().severe("Could not create a new chest file for chest at " + loc.toString()); | |
| } | |
| } | |
| FileConfiguration chestFile = getChestFile(loc); | |
| //Serialize the chest's inventory into a String list | |
| if(inv != null){ | |
| int slot = -1; | |
| chestFile.set("inventory", null); | |
| for(ItemStack stack : inv.getContents()){ | |
| slot++; | |
| if(stack != null) chestFile.set("inventory." + slot, stack); | |
| } | |
| } | |
| //Save the owner's name if the file does not have an owner | |
| System.out.println(chestFile); | |
| if(chestFile.getString("owner") == null) System.out.println("It is!"); | |
| //Now save the File! | |
| try{ | |
| chestFile.save(file); | |
| }catch(IOException e){ | |
| getLogger().severe("Could not save chest file for chest at " + loc.toString()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment