@@ -1,14 +0,0 @@
|
||||
package com.drtshock.playervaults.commands;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class DeleteCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.drtshock.playervaults.commands;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class SignCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package com.drtshock.playervaults.commands;
|
||||
|
||||
import com.drtshock.playervaults.util.Lang;
|
||||
import com.drtshock.playervaults.vaults.VaultManagement;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public class VaultCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(Lang.PLAYER_ONLY.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
if (args.length > 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String vaultNumber = args.length == 1 ? args[0] : "1"; // so they can do /pv and open the first vault.
|
||||
try {
|
||||
Integer.valueOf(vaultNumber);
|
||||
} catch (NumberFormatException e) {
|
||||
openOtherVault(player, args[0], Integer.valueOf(args[1])); // TODO: better logic for checking args.
|
||||
return true;
|
||||
}
|
||||
|
||||
Integer num = Integer.valueOf(vaultNumber);
|
||||
Inventory inv = VaultManagement.
|
||||
return true;
|
||||
}
|
||||
|
||||
private void openOtherVault(Player player, String target, int num) {
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(target);
|
||||
if (offlinePlayer == null) {
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.VAULT_DOES_NOT_EXIST.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
Inventory vault = VaultManagement.getVault(offlinePlayer, num);
|
||||
if (vault == null) {
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.VAULT_DOES_NOT_EXIST.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
player.openInventory(vault); // TODO: Don't allow same vault to be opened multiple times.
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package com.drtshock.playervaults.util;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PermissionChecks {
|
||||
|
||||
/**
|
||||
* Check if a player can open a request vault.
|
||||
*
|
||||
* @param player - player in question.
|
||||
* @param number - vault number in question
|
||||
*
|
||||
* @return - true if permitted, otherwise false.
|
||||
*/
|
||||
public static boolean canOpenVault(Player player, int number) {
|
||||
if (player.isOp() && player.hasPermission("playervaults.admin") && player.hasPermission("playervaults.amount." + String.valueOf(number))) {
|
||||
return true;
|
||||
}
|
||||
for (int x = number; x <= 99; x++) {
|
||||
if (player.hasPermission("playervaults.amount." + String.valueOf(x))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the max size vault a player is allowed to have.
|
||||
*
|
||||
* @param player that is having his permissions checked.
|
||||
*
|
||||
* @return max size as int. If no max size is set then it will default to 54.
|
||||
*/
|
||||
public static int getMaxVaultSize(Player player) {
|
||||
if (player == null) {
|
||||
return 54;
|
||||
}
|
||||
for (int i = 6; i != 0; i--) {
|
||||
if (player.hasPermission("playervaults.size." + i)) {
|
||||
return i * 9;
|
||||
}
|
||||
}
|
||||
return 54;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public class Serialization {
|
||||
}
|
||||
|
||||
public static Map<String, Object> serialize(ConfigurationSerializable cs) {
|
||||
Map<String, Object> returnVal = handleSerialization(cs.serialize());
|
||||
Map<String,Object> returnVal = handleSerialization(cs.serialize());
|
||||
returnVal.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(cs.getClass()));
|
||||
return returnVal;
|
||||
}
|
||||
@@ -129,14 +129,13 @@ public class Serialization {
|
||||
newList.add(object);
|
||||
}
|
||||
entry.setValue(newList);
|
||||
} else if (entry.getValue() instanceof Map<?, ?>) {
|
||||
} else if (entry.getValue() instanceof Map<?,?>) {
|
||||
// unchecked cast here. If you're serializing to a non-standard Map you deserve ClassCastExceptions
|
||||
entry.setValue(handleSerialization((Map<String, Object>) entry.getValue()));
|
||||
}
|
||||
}
|
||||
return serialized;
|
||||
}
|
||||
|
||||
public static Map<String, Object> recreateMap(Map<String, Object> original) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.putAll(original);
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
package com.drtshock.playervaults.vaults;
|
||||
|
||||
import com.drtshock.playervaults.PlayerVaults;
|
||||
import com.drtshock.playervaults.util.Lang;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Handles files for Vaults.
|
||||
*/
|
||||
public class VaultFiles {
|
||||
|
||||
public static YamlConfiguration getVaultFile(OfflinePlayer player) {
|
||||
return getVaultFile(player.getUniqueId());
|
||||
}
|
||||
|
||||
public static YamlConfiguration getVaultFile(UUID uuid) {
|
||||
File file = new File(PlayerVaults.getInstance().getDataFolder(), "files" + File.separator + uuid.toString() + ".yml");
|
||||
if (!file.exists()) file.mkdirs();
|
||||
return YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
|
||||
public static boolean serializeVault(Inventory inventory, UUID owner, int vaultNumber) {
|
||||
YamlConfiguration yaml = getVaultFile(owner);
|
||||
List<ConfigurationSerializable> items = new ArrayList<>();
|
||||
for (ItemStack is : inventory.getContents()) {
|
||||
items.add(is);
|
||||
}
|
||||
for (int i = 0; i <= items.size(); i++) {
|
||||
yaml.set("vault" + vaultNumber + "." + i, items.get(i));
|
||||
}
|
||||
saveFile(owner);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Inventory deserializeVault(UUID owner, int vaultNumber) {
|
||||
YamlConfiguration yaml = getVaultFile(owner);
|
||||
Inventory inv = Bukkit.createInventory(null, 54, Lang.VAULT_TITLE.toString()); // TODO get correct size.
|
||||
for (int i = 0; i <= 54; i++) {
|
||||
ItemStack is = yaml.getItemStack("vault" + vaultNumber + "." + i);
|
||||
if (is != null) inv.addItem(is);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void saveFile(UUID uuid) {
|
||||
File file = new File(PlayerVaults.getInstance().getDataFolder(), "files" + File.separator + uuid.toString() + ".yml");
|
||||
if (!file.exists()) file.mkdirs();
|
||||
saveFile(file, YamlConfiguration.loadConfiguration(file));
|
||||
}
|
||||
|
||||
public static void saveFile(File file, YamlConfiguration yaml) {
|
||||
try {
|
||||
yaml.save(file);
|
||||
} catch (IOException e) {
|
||||
PlayerVaults.getInstance().getLogger().log(Level.SEVERE, "Failed to save file: " + file.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.drtshock.playervaults.vaults;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Handles opening and getting Vaults.
|
||||
*/
|
||||
public class VaultManagement {
|
||||
|
||||
public static Inventory getVault(OfflinePlayer player, int num) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void saveVault(Inventory inv, OfflinePlayer player, int num) {
|
||||
saveVault(inv, player.getUniqueId(), num);
|
||||
}
|
||||
|
||||
public static void saveVault(Inventory inv, UUID owner, int num) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user