Base64 vault management
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package com.drtshock.playervaults.vaultmanagement;
|
||||
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.io.BukkitObjectInputStream;
|
||||
import org.bukkit.util.io.BukkitObjectOutputStream;
|
||||
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
/**
|
||||
* Created by Lax on 6/6/2017.
|
||||
*/
|
||||
public class Base64Serialization {
|
||||
|
||||
public static String toBase64(Inventory inventory) {
|
||||
try {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
|
||||
|
||||
// Write the size of the inventory
|
||||
dataOutput.writeInt(inventory.getSize());
|
||||
|
||||
// Save every element in the list
|
||||
for (int i = 0; i < inventory.getSize(); i++) {
|
||||
dataOutput.writeObject(inventory.getItem(i));
|
||||
}
|
||||
|
||||
// Serialize that array
|
||||
dataOutput.close();
|
||||
return Base64Coder.encodeLines(outputStream.toByteArray());
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Cannot into itemstacksz!", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String toBase64(ItemStack[] is, int size) {
|
||||
Inventory inventory = Bukkit.createInventory(null, size);
|
||||
inventory.setContents(is);
|
||||
return toBase64(inventory);
|
||||
}
|
||||
|
||||
public static Inventory fromBase64(String data) {
|
||||
try {
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
|
||||
BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
|
||||
Inventory inventory = Bukkit.getServer().createInventory(null, dataInput.readInt());
|
||||
|
||||
// Read the serialized inventory
|
||||
for (int i = 0; i < inventory.getSize(); i++) {
|
||||
inventory.setItem(i, (ItemStack) dataInput.readObject());
|
||||
}
|
||||
dataInput.close();
|
||||
return inventory;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public class EconomyOperations {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!UUIDVaultManager.getInstance().vaultExists(player.getUniqueId().toString(), number)) {
|
||||
if (!VaultManager.getInstance().vaultExists(player.getUniqueId(), number)) {
|
||||
return payToCreate(player);
|
||||
} else {
|
||||
double cost = BUKKIT_CONFIG.getDouble("economy.cost-to-open", 10);
|
||||
|
||||
@@ -39,9 +39,10 @@ import org.json.simple.JSONValue;
|
||||
*
|
||||
* @author evilmidget38, gomeow
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class Serialization {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Deprecated
|
||||
public static Map<String, Object> toMap(JSONObject object) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
|
||||
@@ -56,6 +57,7 @@ public class Serialization {
|
||||
return map;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private static Object fromJson(Object json) {
|
||||
if (json == null) {
|
||||
return null;
|
||||
@@ -68,6 +70,7 @@ public class Serialization {
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static List<Object> toList(JSONArray array) {
|
||||
List<Object> list = new ArrayList<>();
|
||||
for (Object value : array) {
|
||||
@@ -76,6 +79,7 @@ public class Serialization {
|
||||
return list;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static List<String> toString(Inventory inv) {
|
||||
List<String> result = new ArrayList<>();
|
||||
List<ConfigurationSerializable> items = new ArrayList<>();
|
||||
@@ -90,6 +94,7 @@ public class Serialization {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Inventory toInventory(List<String> stringItems, int number, int size, String title) {
|
||||
VaultHolder holder = new VaultHolder(number);
|
||||
Inventory inv = Bukkit.createInventory(holder, size, title);
|
||||
@@ -110,13 +115,14 @@ public class Serialization {
|
||||
return inv;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Map<String, Object> serialize(ConfigurationSerializable cs) {
|
||||
Map<String, Object> returnVal = handleSerialization(cs.serialize());
|
||||
returnVal.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(cs.getClass()));
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Deprecated
|
||||
private static Map<String, Object> handleSerialization(Map<String, Object> map) {
|
||||
Map<String, Object> serialized = recreateMap(map);
|
||||
for (Entry<String, Object> entry : serialized.entrySet()) {
|
||||
@@ -139,13 +145,14 @@ public class Serialization {
|
||||
return serialized;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Map<String, Object> recreateMap(Map<String, Object> original) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.putAll(original);
|
||||
return map;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Deprecated
|
||||
public static Object deserialize(Map<String, Object> map) {
|
||||
List<?> itemflags = null;
|
||||
for (Entry<String, Object> entry : map.entrySet()) {
|
||||
@@ -183,6 +190,7 @@ public class Serialization {
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private static List<?> convertIterable(Iterable<?> iterable) {
|
||||
List<Object> newList = new ArrayList<>();
|
||||
for (Object object : iterable) {
|
||||
@@ -198,6 +206,7 @@ public class Serialization {
|
||||
return newList;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private static Number convertNumber(Number number) {
|
||||
if (number instanceof Long) {
|
||||
Long longObj = (Long) number;
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.drtshock.playervaults.util.Lang;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
@@ -22,6 +23,7 @@ import java.util.logging.Level;
|
||||
/**
|
||||
* Class to handle vault operations with new UUIDs.
|
||||
*/
|
||||
@Deprecated
|
||||
public class UUIDVaultManager {
|
||||
|
||||
private static UUIDVaultManager instance;
|
||||
@@ -30,7 +32,7 @@ public class UUIDVaultManager {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
private final File directory = PlayerVaults.getInstance().getVaultData();
|
||||
private final File directory = PlayerVaults.getInstance().getUuidData();
|
||||
private final Map<String, YamlConfiguration> cachedVaultFiles = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
@@ -135,7 +137,6 @@ public class UUIDVaultManager {
|
||||
* @param playerFile the YamlConfiguration file.
|
||||
* @param size the size of the vault.
|
||||
* @param number the vault number.
|
||||
*
|
||||
* @return inventory if exists, otherwise null.
|
||||
*/
|
||||
private Inventory getInventory(YamlConfiguration playerFile, int size, int number, String title) {
|
||||
@@ -156,24 +157,28 @@ public class UUIDVaultManager {
|
||||
*
|
||||
* @param holder The holder of the vault.
|
||||
* @param number The vault number.
|
||||
*
|
||||
* @return The inventory of the specified holder and vault number.
|
||||
*/
|
||||
public Inventory getVault(UUID holder, int number) {
|
||||
YamlConfiguration playerFile = getPlayerVaultFile(holder);
|
||||
List<String> data = playerFile.getStringList("vault" + number);
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(holder);
|
||||
if (player == null || !player.hasPlayedBefore()) {
|
||||
return null;
|
||||
}
|
||||
String title = Lang.VAULT_TITLE.toString().replace("%number", String.valueOf(number)).replace("%p", Bukkit.getOfflinePlayer(holder).getName());
|
||||
if (data == null) {
|
||||
ConfigurationSection section = playerFile.getConfigurationSection("vault" + number);
|
||||
int maxSize = VaultOperations.getMaxVaultSize(holder);
|
||||
|
||||
String title = Lang.VAULT_TITLE.toString().replace("%number", String.valueOf(number));
|
||||
|
||||
if (section == null) {
|
||||
VaultHolder vaultHolder = new VaultHolder(number);
|
||||
Inventory inv = Bukkit.createInventory(vaultHolder, VaultOperations.getMaxVaultSize(player), Lang.VAULT_TITLE.toString().replace("%number", String.valueOf(number)).replace("%p", player.getName()));
|
||||
Inventory inv = Bukkit.createInventory(vaultHolder, maxSize, title);
|
||||
vaultHolder.setInventory(inv);
|
||||
return inv;
|
||||
} else {
|
||||
return Serialization.toInventory(data, number, VaultOperations.getMaxVaultSize(player), title);
|
||||
List<String> data = new ArrayList<>();
|
||||
for (String s : section.getKeys(false)) {
|
||||
String value = section.getString(s);
|
||||
data.add(value);
|
||||
}
|
||||
|
||||
return Serialization.toInventory(data, number, maxSize, title);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,7 +187,6 @@ public class UUIDVaultManager {
|
||||
*
|
||||
* @param holder holder of the vault.
|
||||
* @param number vault number.
|
||||
*
|
||||
* @return true if the vault file and vault number exist in that file, otherwise false.
|
||||
*/
|
||||
public boolean vaultExists(String holder, int number) {
|
||||
@@ -200,7 +204,6 @@ public class UUIDVaultManager {
|
||||
* @param sender The sender of whom to send messages to.
|
||||
* @param holder The vault holder.
|
||||
* @param number The vault number.
|
||||
*
|
||||
* @throws IOException Uh oh!
|
||||
*/
|
||||
public void deleteVault(CommandSender sender, final String holder, final int number) throws IOException {
|
||||
@@ -264,7 +267,6 @@ public class UUIDVaultManager {
|
||||
* Get the holder's vault file. Create if doesn't exist.
|
||||
*
|
||||
* @param holder The vault holder.
|
||||
*
|
||||
* @return The holder's vault config file.
|
||||
*/
|
||||
public YamlConfiguration getPlayerVaultFile(String holder) {
|
||||
|
||||
@@ -0,0 +1,286 @@
|
||||
package com.drtshock.playervaults.vaultmanagement;
|
||||
|
||||
import com.drtshock.playervaults.PlayerVaults;
|
||||
import com.drtshock.playervaults.util.Lang;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class VaultManager {
|
||||
|
||||
private static VaultManager instance;
|
||||
private static final String VAULTKEY = "vault%d";
|
||||
|
||||
public VaultManager() {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
private final File directory = PlayerVaults.getInstance().getVaultData();
|
||||
private final Map<UUID, YamlConfiguration> cachedVaultFiles = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* Saves the inventory to the specified player and vault number.
|
||||
*
|
||||
* @param inventory The inventory to be saved.
|
||||
* @param target The player of whose file to save to.
|
||||
* @param number The vault number.
|
||||
*/
|
||||
public void saveVault(Inventory inventory, UUID target, int number) {
|
||||
YamlConfiguration yaml = getPlayerVaultFile(target);
|
||||
String serialized = Base64Serialization.toBase64(inventory);
|
||||
yaml.set(String.format(VAULTKEY, number), serialized);
|
||||
saveFileSync(target, yaml);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the player's vault and return it.
|
||||
*
|
||||
* @param player The holder of the vault.
|
||||
* @param number The vault number.
|
||||
*/
|
||||
public Inventory loadOwnVault(Player player, int number, int size) {
|
||||
if (size % 9 != 0) {
|
||||
size = 54;
|
||||
}
|
||||
|
||||
String title = Lang.VAULT_TITLE.toString().replace("%number", String.valueOf(number)).replace("%p", player.getName());
|
||||
VaultViewInfo info = new VaultViewInfo(player.getUniqueId(), number);
|
||||
if (PlayerVaults.getInstance().getOpenInventories().containsKey(info.toString())) {
|
||||
return PlayerVaults.getInstance().getOpenInventories().get(info.toString());
|
||||
}
|
||||
|
||||
Inventory inv;
|
||||
YamlConfiguration playerFile = getPlayerVaultFile(player.getUniqueId());
|
||||
if (playerFile.getString(String.format(VAULTKEY, number)) == null) {
|
||||
VaultHolder vaultHolder = new VaultHolder(number);
|
||||
if (EconomyOperations.payToCreate(player)) {
|
||||
inv = Bukkit.createInventory(vaultHolder, size, title);
|
||||
vaultHolder.setInventory(inv);
|
||||
} else {
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.INSUFFICIENT_FUNDS.toString());
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
Inventory i = getInventory(playerFile, size, number, title);
|
||||
if (i == null) {
|
||||
return null;
|
||||
} else {
|
||||
inv = i;
|
||||
}
|
||||
}
|
||||
PlayerVaults.getInstance().getOpenInventories().put(info.toString(), inv);
|
||||
|
||||
return inv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the player's vault and return it.
|
||||
*
|
||||
* @param holder The holder of the vault.
|
||||
* @param number The vault number.
|
||||
*/
|
||||
public Inventory loadOtherVault(UUID holder, int number, int size) {
|
||||
if (size % 9 != 0) {
|
||||
size = 54;
|
||||
}
|
||||
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(holder);
|
||||
String name = "null";
|
||||
if (offlinePlayer != null) {
|
||||
name = offlinePlayer.getName();
|
||||
}
|
||||
|
||||
String title = Lang.VAULT_TITLE.toString().replace("%number", String.valueOf(number)).replace("%p", name);
|
||||
VaultViewInfo info = new VaultViewInfo(holder, number);
|
||||
Inventory inv;
|
||||
if (PlayerVaults.getInstance().getOpenInventories().containsKey(info.toString())) {
|
||||
inv = PlayerVaults.getInstance().getOpenInventories().get(info.toString());
|
||||
} else {
|
||||
YamlConfiguration playerFile = getPlayerVaultFile(holder);
|
||||
Inventory i = getInventory(playerFile, size, number, title);
|
||||
if (i == null) {
|
||||
return null;
|
||||
} else {
|
||||
inv = i;
|
||||
}
|
||||
PlayerVaults.getInstance().getOpenInventories().put(info.toString(), inv);
|
||||
}
|
||||
return inv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an inventory from file. Returns null if the inventory doesn't exist. SHOULD ONLY BE USED INTERNALLY
|
||||
*
|
||||
* @param playerFile the YamlConfiguration file.
|
||||
* @param size the size of the vault.
|
||||
* @param number the vault number.
|
||||
* @return inventory if exists, otherwise null.
|
||||
*/
|
||||
private Inventory getInventory(YamlConfiguration playerFile, int size, int number, String title) {
|
||||
String data = playerFile.getString(String.format(VAULTKEY, number));
|
||||
return Base64Serialization.fromBase64(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an inventory without storing references to it. Used for dropping a players inventories on death.
|
||||
*
|
||||
* @param holder The holder of the vault.
|
||||
* @param number The vault number.
|
||||
* @return The inventory of the specified holder and vault number. Can be null.
|
||||
*/
|
||||
public Inventory getVault(UUID holder, int number) {
|
||||
YamlConfiguration playerFile = getPlayerVaultFile(holder);
|
||||
String serialized = playerFile.getString(String.format(VAULTKEY, number));
|
||||
return Base64Serialization.fromBase64(serialized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a vault exists.
|
||||
*
|
||||
* @param holder holder of the vault.
|
||||
* @param number vault number.
|
||||
* @return true if the vault file and vault number exist in that file, otherwise false.
|
||||
*/
|
||||
public boolean vaultExists(UUID holder, int number) {
|
||||
File file = new File(directory, holder + ".yml");
|
||||
if (!file.exists()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return getPlayerVaultFile(holder).contains(String.format(VAULTKEY, number));
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a players vault.
|
||||
*
|
||||
* @param sender The sender of whom to send messages to.
|
||||
* @param holder The vault holder.
|
||||
* @param number The vault number.
|
||||
* @throws IOException Uh oh!
|
||||
*/
|
||||
public void deleteVault(CommandSender sender, final UUID holder, final int number) throws IOException {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
File file = new File(directory, holder + ".yml");
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
YamlConfiguration playerFile = YamlConfiguration.loadConfiguration(file);
|
||||
if (file.exists()) {
|
||||
playerFile.set(String.format(VAULTKEY, number), null);
|
||||
if (cachedVaultFiles.containsKey(holder)) {
|
||||
cachedVaultFiles.put(holder, playerFile);
|
||||
}
|
||||
try {
|
||||
playerFile.save(file);
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(PlayerVaults.getInstance());
|
||||
|
||||
OfflinePlayer player = Bukkit.getPlayer(holder);
|
||||
if (player != null) {
|
||||
if (sender.getName().equalsIgnoreCase(player.getName())) {
|
||||
sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_VAULT.toString().replace("%v", String.valueOf(number)));
|
||||
} else {
|
||||
sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_OTHER_VAULT.toString().replace("%v", String.valueOf(number)).replaceAll("%p", player.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
PlayerVaults.getInstance().getOpenInventories().remove(new VaultViewInfo(holder, number).toString());
|
||||
}
|
||||
|
||||
// Should only be run asynchronously
|
||||
public void cachePlayerVaultFile(UUID holder) {
|
||||
YamlConfiguration config = this.loadPlayerVaultFile(holder, false);
|
||||
if (config != null) {
|
||||
this.cachedVaultFiles.put(holder, config);
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
public void removeCachedPlayerVaultFile(UUID holder) {
|
||||
if (cachedVaultFiles.containsKey(holder)) {
|
||||
cachedVaultFiles.remove(holder);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the holder's vault file. Create if doesn't exist.
|
||||
*
|
||||
* @param holder The vault holder.
|
||||
* @return The holder's vault config file.
|
||||
*/
|
||||
public YamlConfiguration getPlayerVaultFile(UUID holder) {
|
||||
if (cachedVaultFiles.containsKey(holder)) {
|
||||
return cachedVaultFiles.get(holder);
|
||||
}
|
||||
return loadPlayerVaultFile(holder);
|
||||
}
|
||||
|
||||
public YamlConfiguration loadPlayerVaultFile(UUID holder) {
|
||||
return this.loadPlayerVaultFile(holder, true);
|
||||
}
|
||||
|
||||
public YamlConfiguration loadPlayerVaultFile(UUID uniqueId, boolean createIfNotFound) {
|
||||
if (!this.directory.exists()) {
|
||||
this.directory.mkdir();
|
||||
}
|
||||
|
||||
File file = new File(this.directory, uniqueId.toString() + ".yml");
|
||||
if (!file.exists()) {
|
||||
if (createIfNotFound) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
|
||||
public void saveFileSync(final UUID holder, final YamlConfiguration yaml) {
|
||||
if (cachedVaultFiles.containsKey(holder)) {
|
||||
cachedVaultFiles.put(holder, yaml);
|
||||
}
|
||||
|
||||
final boolean backups = PlayerVaults.getInstance().isBackupsEnabled();
|
||||
final File backupsFolder = PlayerVaults.getInstance().getBackupsFolder();
|
||||
final File file = new File(directory, holder.toString() + ".yml");
|
||||
if (file.exists() && backups) {
|
||||
file.renameTo(new File(backupsFolder, holder.toString() + ".yml"));
|
||||
}
|
||||
try {
|
||||
yaml.save(file);
|
||||
} catch (IOException e) {
|
||||
PlayerVaults.getInstance().getLogger().log(Level.SEVERE, "Failed to save vault file for: " + holder.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the instance of this class.
|
||||
*
|
||||
* @return - instance of this class.
|
||||
*/
|
||||
public static VaultManager getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
@@ -88,18 +88,11 @@ public class VaultOperations {
|
||||
/**
|
||||
* Get the max size vault a player is allowed to have.
|
||||
*
|
||||
* @param target that is having his permissions checked.
|
||||
* @param uuid that is having his permissions checked.
|
||||
*
|
||||
* @return max size as integer. If no max size is set then it will default to 54.
|
||||
*/
|
||||
public static int getMaxVaultSize(String target) {
|
||||
UUID uuid;
|
||||
try {
|
||||
uuid = UUID.fromString(target);
|
||||
} catch (Exception e) {
|
||||
return 54;
|
||||
}
|
||||
|
||||
public static int getMaxVaultSize(UUID uuid) {
|
||||
return getMaxVaultSize(Bukkit.getOfflinePlayer(uuid));
|
||||
}
|
||||
|
||||
@@ -147,7 +140,7 @@ public class VaultOperations {
|
||||
|
||||
if (checkPerms(player, number)) {
|
||||
if (EconomyOperations.payToOpen(player, number)) {
|
||||
Inventory inv = UUIDVaultManager.getInstance().loadOwnVault(player, number, getMaxVaultSize(player));
|
||||
Inventory inv = VaultManager.getInstance().loadOwnVault(player, number, getMaxVaultSize(player));
|
||||
player.openInventory(inv);
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.OPEN_VAULT.toString().replace("%v", arg));
|
||||
return true;
|
||||
@@ -187,14 +180,13 @@ public class VaultOperations {
|
||||
*
|
||||
* @return Whether or not the player was allowed to open it.
|
||||
*/
|
||||
public static boolean openOtherVault(Player player, String holder, String arg) {
|
||||
public static boolean openOtherVault(Player player, UUID holder, String arg) {
|
||||
if (isLocked()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
String nicename = holder;
|
||||
int number = 0;
|
||||
try {
|
||||
number = Integer.parseInt(arg);
|
||||
@@ -206,21 +198,15 @@ public class VaultOperations {
|
||||
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
|
||||
}
|
||||
|
||||
// Try to get the vault of an OfflinePlayer if we don't find one with the name first.
|
||||
if (!UUIDVaultManager.getInstance().vaultExists(holder, number)) {
|
||||
OfflinePlayer targetPlayer = Bukkit.getOfflinePlayer(holder);
|
||||
if (targetPlayer.hasPlayedBefore()) {
|
||||
holder = targetPlayer.getUniqueId().toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Inventory inv = UUIDVaultManager.getInstance().loadOtherVault(holder, number, getMaxVaultSize(holder));
|
||||
Inventory inv = VaultManager.getInstance().loadOtherVault(holder, number, getMaxVaultSize(holder));
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(holder);
|
||||
String name = offlinePlayer != null ? offlinePlayer.getName() : "";
|
||||
if (inv == null) {
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.VAULT_DOES_NOT_EXIST.toString());
|
||||
} else {
|
||||
player.openInventory(inv);
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.OPEN_OTHER_VAULT.toString().replace("%v", arg).replace("%p", nicename));
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.OPEN_OTHER_VAULT.toString().replace("%v", arg).replace("%p", name));
|
||||
PlayerVaults.debug("opening other vault", time);
|
||||
return true;
|
||||
}
|
||||
@@ -253,7 +239,7 @@ public class VaultOperations {
|
||||
|
||||
try {
|
||||
if (EconomyOperations.refundOnDelete(player, number)) {
|
||||
UUIDVaultManager.getInstance().deleteVault(player, player.getUniqueId().toString(), number);
|
||||
VaultManager.getInstance().deleteVault(player, player.getUniqueId(), number);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.DELETE_VAULT_ERROR);
|
||||
@@ -288,7 +274,7 @@ public class VaultOperations {
|
||||
}
|
||||
|
||||
try {
|
||||
UUIDVaultManager.getInstance().deleteVault(sender, holder.getUniqueId().toString(), number);
|
||||
VaultManager.getInstance().deleteVault(sender, holder.getUniqueId(), number);
|
||||
} catch (IOException e) {
|
||||
sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_VAULT_ERROR);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user