Preserve title and size of vaults

This commit is contained in:
Trent Hensler
2017-12-31 23:58:22 -08:00
parent b2eb35ceeb
commit 00861205ae
@@ -8,6 +8,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import java.io.File; import java.io.File;
@@ -128,8 +129,26 @@ public class VaultManager {
* @return inventory if exists, otherwise null. * @return inventory if exists, otherwise null.
*/ */
private Inventory getInventory(YamlConfiguration playerFile, int size, int number, String title) { private Inventory getInventory(YamlConfiguration playerFile, int size, int number, String title) {
Inventory inventory = Bukkit.createInventory(null, size, title);
String data = playerFile.getString(String.format(VAULTKEY, number)); String data = playerFile.getString(String.format(VAULTKEY, number));
return Base64Serialization.fromBase64(data); Inventory deserialized = Base64Serialization.fromBase64(data);
if (deserialized == null) {
return inventory;
}
// Check if deserialized has more used slots than the limit here.
// Happens on change of permission or if people used the broken version.
// In this case, players will lose items.
if (deserialized.getContents().length > size) {
for (ItemStack stack : deserialized.getContents()) {
inventory.addItem(stack);
}
} else {
inventory.setContents(deserialized.getContents());
}
return inventory;
} }
/** /**