Search in sources :

Example 6 with ChestData

use of com.bgsoftware.wildchests.api.objects.data.ChestData in project WildChests by BG-Software-LLC.

the class ChestUtils method trySellItem.

public static boolean trySellItem(OfflinePlayer player, Chest chest, ItemStack toSell) {
    if (toSell == null || toSell.getType() == Material.AIR)
        return false;
    ProvidersHandler.TransactionResult<Double> transactionResult = plugin.getProviders().canSellItem(player, toSell);
    if (!transactionResult.isSuccess())
        return false;
    ChestData chestData = chest.getData();
    SellChestTaskEvent sellChestTaskEvent = new SellChestTaskEvent(chest, toSell, chestData.getMultiplier());
    Bukkit.getPluginManager().callEvent(sellChestTaskEvent);
    double finalPrice = transactionResult.getData() * sellChestTaskEvent.getMultiplier();
    if (finalPrice <= 0)
        return false;
    boolean successDeposit;
    if (plugin.getSettings().sellCommand.isEmpty()) {
        successDeposit = plugin.getProviders().depositPlayer(player, chestData.getDepositMethod(), finalPrice);
    } else {
        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), plugin.getSettings().sellCommand.replace("{player-name}", player.getName()).replace("{price}", String.valueOf(finalPrice)));
        successDeposit = true;
    }
    if (successDeposit)
        NotifierTask.addTransaction(player.getUniqueId(), toSell, toSell.getAmount(), finalPrice);
    return successDeposit;
}
Also used : ProvidersHandler(com.bgsoftware.wildchests.handlers.ProvidersHandler) ChestData(com.bgsoftware.wildchests.api.objects.data.ChestData) WChestData(com.bgsoftware.wildchests.objects.data.WChestData) SellChestTaskEvent(com.bgsoftware.wildchests.api.events.SellChestTaskEvent)

Example 7 with ChestData

use of com.bgsoftware.wildchests.api.objects.data.ChestData in project WildChests by BG-Software-LLC.

the class BlockListener method onChestExplode.

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onChestExplode(EntityExplodeEvent e) {
    List<Block> blockList = new ArrayList<>(e.blockList());
    Player sourcePlayer = null;
    if (e.getEntity() instanceof TNTPrimed && ((TNTPrimed) e.getEntity()).getSource() instanceof Player) {
        sourcePlayer = (Player) ((TNTPrimed) e.getEntity()).getSource();
    }
    for (Block block : blockList) {
        Chest chest = plugin.getChestsManager().getChest(block.getLocation());
        if (chest == null)
            continue;
        e.blockList().remove(block);
        if (plugin.getSettings().explodeDropChance > 0 && (plugin.getSettings().explodeDropChance == 100 || ThreadLocalRandom.current().nextInt(101) <= plugin.getSettings().explodeDropChance)) {
            ChestData chestData = chest.getData();
            ItemUtils.dropOrCollect(null, chestData.getItemStack(), false, chest.getLocation());
        }
        chest.onBreak(new BlockBreakEvent(block, sourcePlayer));
        plugin.getProviders().notifyChestBreakListeners(sourcePlayer, chest);
        chest.remove();
        block.setType(Material.AIR);
    }
}
Also used : Chest(com.bgsoftware.wildchests.api.objects.chests.Chest) Player(org.bukkit.entity.Player) ChestData(com.bgsoftware.wildchests.api.objects.data.ChestData) ArrayList(java.util.ArrayList) TNTPrimed(org.bukkit.entity.TNTPrimed) Block(org.bukkit.block.Block) BlockBreakEvent(org.bukkit.event.block.BlockBreakEvent) EventHandler(org.bukkit.event.EventHandler)

Example 8 with ChestData

use of com.bgsoftware.wildchests.api.objects.data.ChestData in project WildChests by BG-Software-LLC.

the class BlockListener method onChestPlace.

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onChestPlace(BlockPlaceEvent e) {
    if (e.getBlockPlaced().getType() != Material.CHEST && e.getBlockPlaced().getType() != Material.TRAPPED_CHEST)
        return;
    boolean hasNearbyChest = false;
    for (BlockFace blockFace : blockFaces) {
        Block block = e.getBlockPlaced().getRelative(blockFace);
        Material blockMaterial = block.getType();
        if (blockMaterial == Material.CHEST || blockMaterial == Material.TRAPPED_CHEST) {
            hasNearbyChest = true;
            if (plugin.getChestsManager().getChest(block.getLocation()) != null) {
                e.setCancelled(true);
                return;
            }
        }
    }
    ChestData chestData = plugin.getChestsManager().getChestData(e.getItemInHand());
    if (chestData == null)
        return;
    if (hasNearbyChest) {
        e.setCancelled(true);
        return;
    }
    Chest chest = plugin.getChestsManager().addChest(e.getPlayer().getUniqueId(), e.getBlockPlaced().getLocation(), chestData);
    plugin.getProviders().notifyChestPlaceListeners(chest);
    // chest.onPlace(e);
    Locale.CHEST_PLACED.send(e.getPlayer(), chestData.getName(), e.getItemInHand().getItemMeta().getDisplayName());
}
Also used : Chest(com.bgsoftware.wildchests.api.objects.chests.Chest) ChestData(com.bgsoftware.wildchests.api.objects.data.ChestData) BlockFace(org.bukkit.block.BlockFace) Block(org.bukkit.block.Block) Material(org.bukkit.Material) EventHandler(org.bukkit.event.EventHandler)

Example 9 with ChestData

use of com.bgsoftware.wildchests.api.objects.data.ChestData in project WildChests by BG-Software-LLC.

the class BlockListener method onChestBreak.

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onChestBreak(BlockBreakEvent e) {
    Chest chest = plugin.getChestsManager().getChest(e.getBlock().getLocation());
    if (chest == null)
        return;
    e.setCancelled(true);
    if (e.getPlayer().getGameMode() != GameMode.CREATIVE) {
        ChestData chestData = chest.getData();
        ItemUtils.dropOrCollect(e.getPlayer(), chestData.getItemStack(), chestData.isAutoCollect(), chest.getLocation());
    }
    chest.onBreak(e);
    plugin.getProviders().notifyChestBreakListeners(e.getPlayer(), chest);
    chest.remove();
    e.getBlock().setType(Material.AIR);
}
Also used : Chest(com.bgsoftware.wildchests.api.objects.chests.Chest) ChestData(com.bgsoftware.wildchests.api.objects.data.ChestData) EventHandler(org.bukkit.event.EventHandler)

Example 10 with ChestData

use of com.bgsoftware.wildchests.api.objects.data.ChestData in project WildChests by BG-Software-LLC.

the class CommandInfo method perform.

@Override
public void perform(WildChestsPlugin plugin, CommandSender sender, String[] args) {
    ChestData chestData = plugin.getChestsManager().getChestData(args[1]);
    if (chestData == null) {
        Locale.INVALID_CHEST.send(sender, args[1]);
        return;
    }
    // Header
    Locale.CHEST_INFO_HEADER.send(sender);
    // Sections which applied to all chests
    Locale.CHEST_INFO_NAME.send(sender, chestData.getName(), ((WChestData) chestData).getItemRaw().getItemMeta().getDisplayName());
    Locale.CHEST_INFO_TYPE.send(sender, chestData.getChestType());
    Locale.CHEST_INFO_SIZE.send(sender, chestData.getDefaultSize());
    Locale.CHEST_INFO_DEFAULT_TITLE.send(sender, chestData.getDefaultTitle());
    Locale.CHEST_INFO_SELL_MODE.send(sender, chestData.isSellMode());
    // Optional sections
    if (chestData.isAutoCrafter())
        Locale.CHEST_INFO_RECIPES.send(sender, getRecipesAsString(chestData.getRecipes()));
    // Footer
    Locale.CHEST_INFO_FOOTER.send(sender);
}
Also used : ChestData(com.bgsoftware.wildchests.api.objects.data.ChestData) WChestData(com.bgsoftware.wildchests.objects.data.WChestData)

Aggregations

ChestData (com.bgsoftware.wildchests.api.objects.data.ChestData)12 Chest (com.bgsoftware.wildchests.api.objects.chests.Chest)5 WChest (com.bgsoftware.wildchests.objects.chests.WChest)4 WChestData (com.bgsoftware.wildchests.objects.data.WChestData)3 UUID (java.util.UUID)3 Location (org.bukkit.Location)3 Player (org.bukkit.entity.Player)3 EventHandler (org.bukkit.event.EventHandler)3 LinkedChest (com.bgsoftware.wildchests.api.objects.chests.LinkedChest)2 StorageChest (com.bgsoftware.wildchests.api.objects.chests.StorageChest)2 InventoryData (com.bgsoftware.wildchests.api.objects.data.InventoryData)2 WLinkedChest (com.bgsoftware.wildchests.objects.chests.WLinkedChest)2 WRegularChest (com.bgsoftware.wildchests.objects.chests.WRegularChest)2 WStorageChest (com.bgsoftware.wildchests.objects.chests.WStorageChest)2 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 Material (org.bukkit.Material)2 Block (org.bukkit.block.Block)2 ItemStack (org.bukkit.inventory.ItemStack)2