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;
}
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);
}
}
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());
}
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);
}
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);
}
Aggregations