use of com.bgsoftware.wildchests.api.objects.data.ChestData in project WildChests by BG-Software-LLC.
the class InventoryListener method handleUpgrade.
private void handleUpgrade(Player player, boolean confirm) {
try {
Chest chest = WChest.viewers.get(player.getUniqueId());
ChestData chestData = chest.getData();
InventoryData inventoryData = buyNewPage.get(player.getUniqueId());
int pageIndex = chest.getPagesAmount() - 1;
if (!chestData.getPagesData().containsKey(pageIndex + 2)) {
Locale.EXPAND_FAILED.send(player);
} else {
if (confirm) {
if (plugin.getProviders().withdrawPlayer(player, inventoryData.getPrice())) {
Locale.EXPAND_PURCHASED.send(player);
chest.setPage(++pageIndex, chestData.getDefaultSize(), inventoryData.getTitle());
} else {
Locale.EXPAND_FAILED.send(player);
}
} else {
Locale.EXPAND_FAILED.send(player);
}
}
final int PAGE = pageIndex;
Executor.sync(() -> chest.openPage(player, PAGE));
} catch (Exception ex) {
Locale.EXPAND_FAILED_CHEST_BROKEN.send(player);
}
buyNewPage.remove(player.getUniqueId());
}
use of com.bgsoftware.wildchests.api.objects.data.ChestData in project WildChests by BG-Software-LLC.
the class CommandGive method perform.
@Override
public void perform(WildChestsPlugin plugin, CommandSender sender, String[] args) {
Player target = Bukkit.getPlayer(args[1]);
if (target == null) {
Locale.INVALID_PLAYER.send(sender, args[1]);
return;
}
ChestData chestData = plugin.getChestsManager().getChestData(args[2]);
if (chestData == null) {
Locale.INVALID_CHEST.send(sender, args[2]);
return;
}
ItemStack chestItem = chestData.getItemStack();
if (args.length == 4) {
try {
chestItem.setAmount(Integer.valueOf(args[3]));
} catch (IllegalArgumentException ex) {
Locale.INVALID_AMOUNT.send(sender);
return;
}
}
ItemUtils.addItem(chestItem, target.getInventory(), target.getLocation());
Locale.CHEST_GIVE_PLAYER.send(sender, target.getName(), chestItem.getAmount(), chestData.getName(), chestItem.getItemMeta().getDisplayName());
Locale.CHEST_RECIEVE.send(target, chestItem.getAmount(), chestData.getName(), sender.getName(), chestItem.getItemMeta().getDisplayName());
}
use of com.bgsoftware.wildchests.api.objects.data.ChestData in project WildChests by BG-Software-LLC.
the class WChest method onInteract.
@Override
public boolean onInteract(InventoryClickEvent event) {
if (event.getSlotType() != InventoryType.SlotType.OUTSIDE)
return false;
ChestData chestData = getData();
int index = getPageIndex(event.getWhoClicked().getOpenInventory().getTopInventory());
if (event.getClick() == ClickType.LEFT) {
// Making sure he's not in the first page
if (index != 0) {
// movingBetweenPages.add(event.getWhoClicked().getUniqueId());
openPage((Player) event.getWhoClicked(), index - 1);
// movingBetweenPages.remove(event.getWhoClicked().getUniqueId());
}
} else if (event.getClick() == ClickType.RIGHT) {
// Making sure it's not the last page
if (index + 1 < getPagesAmount()) {
// movingBetweenPages.add(event.getWhoClicked().getUniqueId());
openPage((Player) event.getWhoClicked(), index + 1);
} else // Making sure next page is purchasble
if (chestData.getPagesData().containsKey(++index + 1)) {
InventoryData inventoryData = chestData.getPagesData().get(index + 1);
InventoryListener.buyNewPage.put(event.getWhoClicked().getUniqueId(), inventoryData);
if (plugin.getSettings().confirmGUI) {
event.getWhoClicked().openInventory(guiConfirm);
} else {
Locale.EXPAND_CHEST.send(event.getWhoClicked(), inventoryData.getPrice());
event.getWhoClicked().closeInventory();
}
}
}
return true;
}
use of com.bgsoftware.wildchests.api.objects.data.ChestData in project WildChests by BG-Software-LLC.
the class DataHandler method loadOldDatabase.
private void loadOldDatabase() {
File dataFolder = new File(plugin.getDataFolder(), "data");
if (!dataFolder.exists())
return;
YamlConfiguration cfg;
for (File chestFile : dataFolder.listFiles()) {
try {
cfg = YamlConfiguration.loadConfiguration(chestFile);
UUID placer = UUID.fromString(cfg.getString("placer"));
Location location = LocationUtils.fromString(chestFile.getName().replace(".yml", ""));
ChestData chestData = plugin.getChestsManager().getChestData(cfg.getString("data"));
WChest chest = (WChest) plugin.getChestsManager().addChest(placer, location, chestData);
chest.loadFromFile(cfg);
chestFile.delete();
} catch (Exception ex) {
WildChestsPlugin.log("Looks like the file " + chestFile.getName() + " is corrupted. Creating a backup file...");
File backupFile = new File(plugin.getDataFolder(), "data-backup/" + chestFile.getName());
copyFiles(chestFile, backupFile);
ex.printStackTrace();
}
}
if (dataFolder.listFiles().length == 0)
dataFolder.delete();
}
use of com.bgsoftware.wildchests.api.objects.data.ChestData in project WildChests by BG-Software-LLC.
the class DataHandler method loadResultSet.
private void loadResultSet(ResultSet resultSet, String tableName, List<Chest> updateContentsChests) throws SQLException {
while (resultSet.next()) {
UUID placer = UUID.fromString(resultSet.getString("placer"));
String stringLocation = resultSet.getString("location");
String errorMessage = null;
try {
if (Bukkit.getWorld(stringLocation.split(", ")[0]) == null) {
errorMessage = "Null world.";
} else {
Location location = LocationUtils.fromString(stringLocation);
ChestData chestData = plugin.getChestsManager().getChestData(resultSet.getString("chest_data"));
WChest chest = plugin.getChestsManager().loadChest(placer, location, chestData);
if (chest instanceof StorageChest) {
String item = resultSet.getString("item");
String amount = resultSet.getString("amount");
String maxAmount = resultSet.getString("max_amount");
((WStorageChest) chest).loadFromData(item, amount, maxAmount);
} else {
String serialized = resultSet.getString("inventories");
if (chest instanceof LinkedChest) {
String linkedChest = resultSet.getString("linked_chest");
((WLinkedChest) chest).loadFromData(serialized, linkedChest);
} else {
((WRegularChest) chest).loadFromData(serialized);
}
if (serialized.toCharArray()[0] != '*')
updateContentsChests.add(chest);
}
}
} catch (Exception ex) {
errorMessage = ex.getMessage();
}
if (errorMessage != null) {
WildChestsPlugin.log("Couldn't load the location " + stringLocation);
WildChestsPlugin.log(errorMessage);
if (errorMessage.contains("Null") && plugin.getSettings().invalidWorldDelete) {
SQLHelper.executeUpdate("DELETE FROM " + tableName + " WHERE location = '" + stringLocation + "';");
WildChestsPlugin.log("Deleted spawner (" + stringLocation + ") from database.");
}
}
}
}
Aggregations