Skip to content

Instantly share code, notes, and snippets.

@natemort
Created February 7, 2013 04:17
Show Gist options
  • Select an option

  • Save natemort/4728450 to your computer and use it in GitHub Desktop.

Select an option

Save natemort/4728450 to your computer and use it in GitHub Desktop.
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