Search in sources :

Example 1 with ShulkerBox

use of org.bukkit.block.ShulkerBox in project SwissKnife by EgirlsNationDev.

the class DebugStickDupe method blockBreak.

@EventHandler
private void blockBreak(BlockBreakEvent e) {
    if (!isEnabled())
        return;
    if (e.getPlayer().getGameMode().equals(GameMode.CREATIVE))
        return;
    if (e.getBlock().getState() instanceof ShulkerBox) {
        if (e.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.DEBUG_STICK)) {
            Long cooldown = cooldownMap.get(e.getPlayer().getUniqueId());
            if (cooldown != null) {
                if ((cooldown + 8500) > System.currentTimeMillis()) {
                    e.setCancelled(true);
                    return;
                }
            }
            cooldownMap.remove(e.getPlayer().getUniqueId());
            for (ItemStack item : e.getBlock().getDrops()) {
                e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), item);
            }
            e.getBlock().breakNaturally();
            cooldownMap.put(e.getPlayer().getUniqueId(), System.currentTimeMillis());
        }
    }
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) ShulkerBox(org.bukkit.block.ShulkerBox) EventHandler(org.bukkit.event.EventHandler)

Example 2 with ShulkerBox

use of org.bukkit.block.ShulkerBox in project FluffyMachines by NCBPFluffyBear.

the class EnderChestExtractionNode method tick.

private void tick(@Nonnull Block b) {
    ItemStack transferItemStack;
    BlockFace face;
    if (b.getRelative(BlockFace.NORTH).getType() == material) {
        face = BlockFace.SOUTH;
    } else if (b.getRelative(BlockFace.SOUTH).getType() == material) {
        face = BlockFace.NORTH;
    } else if (b.getRelative(BlockFace.EAST).getType() == material) {
        face = BlockFace.WEST;
    } else if (b.getRelative(BlockFace.WEST).getType() == material) {
        face = BlockFace.EAST;
    } else {
        return;
    }
    BlockState state = PaperLib.getBlockState(b.getRelative(face), false).getState();
    if (state instanceof InventoryHolder) {
        Player p = Bukkit.getOfflinePlayer(UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner"))).getPlayer();
        // Ender chest null check necessary because Bukkit yes.
        if (p != null) {
            boolean enderValid = false;
            boolean containerValid = false;
            int enderIndex = -1;
            int containerIndex = -1;
            Inventory enderInv = p.getEnderChest();
            for (int i = 0; i < enderInv.getSize(); i++) {
                ItemStack enderItem = enderInv.getItem(i);
                // Ignore null items
                if (enderItem == null) {
                    continue;
                }
                // Prevent putting shulkers in shulkers
                if (state instanceof ShulkerBox && !Tag.SHULKER_BOXES.isTagged(enderItem.getType())) {
                    continue;
                }
                SlimefunItem sfEnderItem = SlimefunItem.getByItem(enderItem);
                // Ignore Talismen
                if (sfEnderItem instanceof Talisman) {
                    continue;
                }
                enderIndex = i;
                enderValid = true;
                break;
            }
            Inventory containerInv = ((InventoryHolder) state).getInventory();
            for (int i = 0; i < containerInv.getSize(); i++) {
                if (containerInv.getItem(i) == null) {
                    containerIndex = i;
                    containerValid = true;
                    break;
                }
            }
            if (enderValid && containerValid) {
                transferItemStack = enderInv.getItem(enderIndex);
                enderInv.setItem(enderIndex, null);
                containerInv.setItem(containerIndex, transferItemStack);
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) BlockState(org.bukkit.block.BlockState) BlockFace(org.bukkit.block.BlockFace) Talisman(io.github.thebusybiscuit.slimefun4.implementation.items.magical.talismans.Talisman) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) InventoryHolder(org.bukkit.inventory.InventoryHolder) Inventory(org.bukkit.inventory.Inventory) ShulkerBox(org.bukkit.block.ShulkerBox)

Example 3 with ShulkerBox

use of org.bukkit.block.ShulkerBox in project ItemJoin by RockinChaos.

the class ItemMap method setContents.

/**
 * Sets the item contents for the storage box.
 */
private void setContents(final Player player) {
    if (this.contents != null && !this.contents.isEmpty() && ServerUtils.hasSpecificUpdate("1_11")) {
        ShulkerBox box = (ShulkerBox) ((BlockStateMeta) this.tempMeta).getBlockState();
        box.getInventory().clear();
        for (String node : this.contents) {
            boolean isNull = true;
            for (ItemMap item : ItemUtilities.getUtilities().getItems()) {
                if (item != null && item.getConfigName().equalsIgnoreCase(node)) {
                    isNull = false;
                    if (StringUtils.isInt(item.getSlot()) && Integer.parseInt(item.getSlot()) <= 26) {
                        box.getInventory().setItem(Integer.parseInt(item.getSlot()), item.getItemStack(player));
                    } else if (item.getSlot().equalsIgnoreCase("ARBITRARY")) {
                        box.getInventory().addItem(item.getItemStack(player));
                    } else if (StringUtils.isInt(item.getSlot()) && Integer.parseInt(item.getSlot()) > 26) {
                        ServerUtils.logWarn("{ItemMap} The item " + node + " cannot have the slot " + item.getSlot() + " as the slot cannot be higher than 26 to be set as contents for the item " + this.getConfigName() + ", the item will not be set.");
                    } else if (!StringUtils.isInt(item.getSlot())) {
                        ServerUtils.logWarn("{ItemMap} The item " + node + " cannot have the slot " + item.getSlot() + " as the item " + this.getConfigName() + " does not support it, the item will not be set.");
                    }
                }
            }
            if (isNull) {
                ServerUtils.logWarn("{ItemMap} The item " + node + " does not exist and will not be set as contents for " + this.getConfigName() + ".");
            }
        }
        ((BlockStateMeta) this.tempMeta).setBlockState(box);
        box.update();
    }
}
Also used : BlockStateMeta(org.bukkit.inventory.meta.BlockStateMeta) ShulkerBox(org.bukkit.block.ShulkerBox)

Example 4 with ShulkerBox

use of org.bukkit.block.ShulkerBox in project Auction-House by kiranhart.

the class GUIConfirmPurchase method draw.

private void draw() {
    ItemStack deserializeItem = this.auctionItem.getItem();
    setItems(this.buyingSpecificQuantity ? 9 : 0, this.buyingSpecificQuantity ? 12 : 3, new TItemBuilder(Objects.requireNonNull(Settings.GUI_CONFIRM_BUY_YES_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_CONFIRM_BUY_YES_NAME.getString()).setLore(Settings.GUI_CONFIRM_BUY_YES_LORE.getStringList()).toItemStack());
    setItem(this.buyingSpecificQuantity ? 1 : 0, 4, deserializeItem);
    setItems(this.buyingSpecificQuantity ? 14 : 5, this.buyingSpecificQuantity ? 17 : 8, new TItemBuilder(Objects.requireNonNull(Settings.GUI_CONFIRM_BUY_NO_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_CONFIRM_BUY_NO_NAME.getString()).setLore(Settings.GUI_CONFIRM_BUY_NO_LORE.getStringList()).toItemStack());
    setAction(this.buyingSpecificQuantity ? 1 : 0, 4, ClickType.LEFT, e -> {
        if (deserializeItem.getItemMeta() instanceof BlockStateMeta) {
            if (((BlockStateMeta) deserializeItem.getItemMeta()).getBlockState() instanceof ShulkerBox) {
                AuctionHouse.getInstance().getTransactionManager().getPrePurchaseHolding().remove(e.player);
                e.manager.showGUI(e.player, new GUIContainerInspect(e.clickedItem, this.auctionPlayer, this.auctionItem, this.buyingSpecificQuantity));
            }
        }
    });
    setActionForRange(this.buyingSpecificQuantity ? 14 : 5, this.buyingSpecificQuantity ? 17 : 8, ClickType.LEFT, e -> {
        e.gui.close();
    });
    setActionForRange(this.buyingSpecificQuantity ? 9 : 0, this.buyingSpecificQuantity ? 12 : 3, ClickType.LEFT, e -> {
        // Re-select the item to ensure that it's available
        try {
            // if the item is in the garbage then just don't continue
            if (AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().containsKey(this.auctionItem.getId()))
                return;
            AuctionedItem located = AuctionHouse.getInstance().getAuctionItemManager().getItem(this.auctionItem.getId());
            if (located == null || located.isExpired()) {
                AuctionHouse.getInstance().getLocale().getMessage("auction.itemnotavailable").sendPrefixedMessage(e.player);
                e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
                return;
            }
            double buyNowPrice = this.buyingSpecificQuantity ? this.purchaseQuantity * this.pricePerItem : located.getBasePrice();
            double tax = Settings.TAX_ENABLED.getBoolean() ? (Settings.TAX_SALES_TAX_BUY_NOW_PERCENTAGE.getDouble() / 100) * buyNowPrice : 0D;
            // Check economy
            if (!EconomyManager.hasBalance(e.player, buyNowPrice + (Settings.TAX_CHARGE_SALES_TAX_TO_BUYER.getBoolean() ? tax : 0D))) {
                AuctionHouse.getInstance().getLocale().getMessage("general.notenoughmoney").sendPrefixedMessage(e.player);
                SoundManager.getInstance().playSound(e.player, Settings.SOUNDS_NOT_ENOUGH_MONEY.getString(), 1.0F, 1.0F);
                e.gui.close();
                return;
            }
            AuctionEndEvent auctionEndEvent = new AuctionEndEvent(Bukkit.getOfflinePlayer(this.auctionItem.getOwner()), e.player, this.auctionItem, AuctionSaleType.WITHOUT_BIDDING_SYSTEM, false);
            Bukkit.getServer().getPluginManager().callEvent(auctionEndEvent);
            if (auctionEndEvent.isCancelled())
                return;
            if (!Settings.ALLOW_PURCHASE_IF_INVENTORY_FULL.getBoolean() && e.player.getInventory().firstEmpty() == -1) {
                AuctionHouse.getInstance().getLocale().getMessage("general.noroom").sendPrefixedMessage(e.player);
                return;
            }
            if (this.buyingSpecificQuantity) {
                // the original item stack
                ItemStack item = auctionItem.getItem().clone();
                ItemStack toGive = auctionItem.getItem().clone();
                if (item.getAmount() - this.purchaseQuantity >= 1) {
                    item.setAmount(item.getAmount() - this.purchaseQuantity);
                    toGive.setAmount(this.purchaseQuantity);
                    if (!located.isInfinite()) {
                        located.setItem(item);
                        located.setBasePrice(Settings.ROUND_ALL_PRICES.getBoolean() ? Math.round(located.getBasePrice() - buyNowPrice) : located.getBasePrice() - buyNowPrice);
                    }
                    transferFunds(e.player, buyNowPrice);
                } else {
                    transferFunds(e.player, buyNowPrice);
                    if (!located.isInfinite())
                        AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(located);
                }
                PlayerUtils.giveItem(e.player, toGive);
                sendMessages(e, located, true, buyNowPrice, this.purchaseQuantity);
            } else {
                transferFunds(e.player, buyNowPrice);
                if (!located.isInfinite())
                    AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(located);
                PlayerUtils.giveItem(e.player, located.getItem());
                sendMessages(e, located, false, 0, -1);
            }
            if (Settings.BROADCAST_AUCTION_SALE.getBoolean()) {
                final OfflinePlayer seller = Bukkit.getOfflinePlayer(auctionItem.getOwner());
                Bukkit.getOnlinePlayers().forEach(player -> AuctionHouse.getInstance().getLocale().getMessage("auction.broadcast.sold").processPlaceholder("player", e.player.getName()).processPlaceholder("player_displayname", AuctionAPI.getInstance().getDisplayName(e.player)).processPlaceholder("seller", auctionItem.getOwnerName()).processPlaceholder("seller_displayname", AuctionAPI.getInstance().getDisplayName(seller)).processPlaceholder("amount", auctionItem.getItem().getAmount()).processPlaceholder("item", AuctionAPI.getInstance().getItemName(auctionItem.getItem())).processPlaceholder("price", AuctionAPI.getInstance().formatNumber(auctionItem.getCurrentPrice())).sendPrefixedMessage(player));
            }
            AuctionHouse.getInstance().getTransactionManager().getPrePurchasePlayers(auctionItem.getId()).forEach(player -> {
                AuctionHouse.getInstance().getTransactionManager().removeAllRelatedPlayers(auctionItem.getId());
                player.closeInventory();
            });
            e.gui.close();
        } catch (ItemNotFoundException exception) {
            AuctionHouse.getInstance().getLogger().info("Tried to purchase item that was bought, or does not exist");
        }
    });
    if (this.buyingSpecificQuantity) {
        drawPurchaseInfo(this.maxStackSize);
        // Decrease Button
        setButton(3, 3, new TItemBuilder(Settings.GUI_CONFIRM_DECREASE_QTY_ITEM.getMaterial().parseMaterial()).setName(Settings.GUI_CONFIRM_DECREASE_QTY_NAME.getString()).setLore(Settings.GUI_CONFIRM_DECREASE_QTY_LORE.getStringList()).toItemStack(), e -> {
            if ((this.purchaseQuantity - 1) <= 0)
                return;
            this.purchaseQuantity -= 1;
            drawPurchaseInfo(this.purchaseQuantity);
        });
        // Increase Button
        setButton(3, 5, new TItemBuilder(Settings.GUI_CONFIRM_INCREASE_QTY_ITEM.getMaterial().parseMaterial()).setName(Settings.GUI_CONFIRM_INCREASE_QTY_NAME.getString()).setLore(Settings.GUI_CONFIRM_INCREASE_QTY_LORE.getStringList()).toItemStack(), e -> {
            if ((this.purchaseQuantity + 1) > this.maxStackSize)
                return;
            this.purchaseQuantity += 1;
            drawPurchaseInfo(this.purchaseQuantity);
        });
    }
}
Also used : TItemBuilder(ca.tweetzy.core.utils.items.TItemBuilder) BlockStateMeta(org.bukkit.inventory.meta.BlockStateMeta) AuctionEndEvent(ca.tweetzy.auctionhouse.api.events.AuctionEndEvent) AuctionedItem(ca.tweetzy.auctionhouse.auction.AuctionedItem) OfflinePlayer(org.bukkit.OfflinePlayer) ItemStack(org.bukkit.inventory.ItemStack) GUIAuctionHouse(ca.tweetzy.auctionhouse.guis.GUIAuctionHouse) GUIContainerInspect(ca.tweetzy.auctionhouse.guis.GUIContainerInspect) ShulkerBox(org.bukkit.block.ShulkerBox) ItemNotFoundException(ca.tweetzy.auctionhouse.exception.ItemNotFoundException)

Example 5 with ShulkerBox

use of org.bukkit.block.ShulkerBox in project BlackMarket by MinecraftDorado.

the class dbMySQL method addBlackItem.

public static void addBlackItem(BlackItem bItem) {
    try {
        if (con == null || con.isClosed())
            con = sql.getConnection();
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        PreparedStatement preparedStatement = null;
        StringBuilder queryBuilder = new StringBuilder();
        queryBuilder.append("SELECT * FROM `blackitems` WHERE id = ?");
        preparedStatement = con.prepareStatement(queryBuilder.toString());
        preparedStatement.setInt(1, bItem.getId());
        ResultSet resultSet = preparedStatement.executeQuery();
        if (resultSet != null && resultSet.next()) {
            updateStatus(bItem);
            updateNotified(bItem);
            return;
        }
        resultSet.close();
        preparedStatement.close();
        queryBuilder = new StringBuilder();
        queryBuilder.append("INSERT INTO `blackitems` ");
        queryBuilder.append("(`owner`,`value`,`date`,`status`,`item`,`content`) ");
        queryBuilder.append("VALUES ");
        queryBuilder.append("(?,?,?,?,?,?);");
        preparedStatement = con.prepareStatement(queryBuilder.toString());
        preparedStatement.setString(1, bItem.getOwner().toString());
        preparedStatement.setDouble(2, bItem.getValue());
        preparedStatement.setLong(3, bItem.getDate().getTime());
        preparedStatement.setString(4, bItem.getStatus().name());
        preparedStatement.setString(5, ItemStackSerializer.serialize(bItem.getOriginal()));
        Object content = null;
        if (bItem.getOriginal().getType().name().contains("SHULKER_BOX"))
            if (bItem.getOriginal().getItemMeta() instanceof BlockStateMeta) {
                BlockStateMeta meta = (BlockStateMeta) bItem.getOriginal().getItemMeta();
                if (meta.getBlockState() instanceof ShulkerBox) {
                    ShulkerBox shulker = (ShulkerBox) meta.getBlockState();
                    content = SerializeInventory.itemStackArrayToBase64(shulker.getInventory().getContents());
                }
            }
        preparedStatement.setObject(6, content != null ? content : null);
        preparedStatement.executeUpdate();
        preparedStatement.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Also used : BlockStateMeta(org.bukkit.inventory.meta.BlockStateMeta) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) ShulkerBox(org.bukkit.block.ShulkerBox)

Aggregations

ShulkerBox (org.bukkit.block.ShulkerBox)25 ItemStack (org.bukkit.inventory.ItemStack)18 BlockStateMeta (org.bukkit.inventory.meta.BlockStateMeta)18 Inventory (org.bukkit.inventory.Inventory)5 Block (org.bukkit.block.Block)4 Player (org.bukkit.entity.Player)4 BlockState (org.bukkit.block.BlockState)3 EventHandler (org.bukkit.event.EventHandler)3 BlockMock (be.seeseemelk.mockbukkit.block.BlockMock)2 BookMeta (org.bukkit.inventory.meta.BookMeta)2 ItemMeta (org.bukkit.inventory.meta.ItemMeta)2 AuctionEndEvent (ca.tweetzy.auctionhouse.api.events.AuctionEndEvent)1 AuctionedItem (ca.tweetzy.auctionhouse.auction.AuctionedItem)1 ItemNotFoundException (ca.tweetzy.auctionhouse.exception.ItemNotFoundException)1 GUIAuctionHouse (ca.tweetzy.auctionhouse.guis.GUIAuctionHouse)1 GUIContainerInspect (ca.tweetzy.auctionhouse.guis.GUIContainerInspect)1 TItemBuilder (ca.tweetzy.core.utils.items.TItemBuilder)1 LongHashSet (com.bergerkiller.bukkit.common.wrappers.LongHashSet)1 LightingService (com.bergerkiller.bukkit.lightcleaner.lighting.LightingService)1 ScheduleArguments (com.bergerkiller.bukkit.lightcleaner.lighting.LightingService.ScheduleArguments)1