Search in sources :

Example 1 with Container

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

the class ExpDispenser method onInteract.

@Override
public void onInteract(Player p, Block b) {
    Block dispenser = b.getRelative(0, -1, 0);
    Container container = (Container) dispenser.getState();
    int experience = 0;
    for (ItemStack bottle : container.getInventory().getContents()) {
        if (bottle != null && bottle.getType() == Material.EXPERIENCE_BOTTLE) {
            // Search for xp bottles
            // Collect experience from bottle
            experience += EXP_PER_BOTTLE * bottle.getAmount();
            // Delete bottle
            bottle.setAmount(0);
        }
    }
    Block barrel = dispenser.getRelative(((Directional) dispenser.getBlockData()).getFacing());
    SlimefunItem sfItem = BlockStorage.check(barrel);
    if (sfItem instanceof Barrel) {
        Barrel sfBarrel = (Barrel) sfItem;
        if (sfBarrel.getStoredItem(barrel).getType() == Material.EXPERIENCE_BOTTLE) {
            experience += sfBarrel.getStored(barrel) * EXP_PER_BOTTLE;
            sfBarrel.setStored(barrel, 0);
            sfBarrel.updateMenu(barrel, BlockStorage.getInventory(barrel), true);
        }
    }
    if (experience == 0) {
        Utils.send(p, "&cThere were no experience bottles in the dispenser!");
    } else {
        p.giveExp(experience);
        Utils.send(p, "&a+" + experience + " XP");
    }
}
Also used : Container(org.bukkit.block.Container) Block(org.bukkit.block.Block) Barrel(io.ncbpfluffybear.fluffymachines.items.Barrel) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack)

Example 2 with Container

use of org.bukkit.block.Container in project kit-api by HGLabor.

the class DiggerKit method onPlayerRightClickKitItem.

@KitEvent
@Override
public void onPlayerRightClickKitItem(PlayerInteractEvent event, KitPlayer kitPlayer) {
    Block clickedBlock = event.getClickedBlock();
    Player player = event.getPlayer();
    if (clickedBlock != null) {
        // Reduce Digger item
        if (player.getInventory().getItemInMainHand().isSimilar(mainKitItem)) {
            player.getInventory().getItemInMainHand().subtract();
        } else if (player.getInventory().getItemInOffHand().isSimilar(mainKitItem)) {
            player.getInventory().getItemInOffHand().subtract();
        }
        Block block = clickedBlock.getLocation().add(0, 1, 0).getBlock();
        kitPlayer.activateKitCooldown(this);
        new BukkitRunnable() {

            @Override
            public void run() {
                int dist = (int) Math.ceil((double) (radius - 1) / 2);
                for (int y = -1; y >= -radius; y--) {
                    for (int x = -dist; x <= dist; x++) {
                        for (int z = -dist; z <= dist; z++) {
                            if (block.getY() + y <= 0) {
                                continue;
                            }
                            Block b = block.getWorld().getBlockAt(block.getX() + x, block.getY() + y, block.getZ() + z);
                            if (b.hasMetadata("feastBlock")) {
                                continue;
                            }
                            if (b.hasMetadata(KitMetaData.GLADIATOR_BLOCK.getKey())) {
                                continue;
                            }
                            if (!b.getType().equals(Material.BEDROCK)) {
                                if (b instanceof Container) {
                                    b.breakNaturally();
                                } else {
                                    b.setType(Material.AIR);
                                }
                            }
                        }
                    }
                }
                player.getWorld().playSound(player.getLocation(), sound, volume, 1);
            }
        }.runTaskLater(KitApi.getInstance().getPlugin(), 15);
    }
}
Also used : KitPlayer(de.hglabor.plugins.kitapi.player.KitPlayer) Player(org.bukkit.entity.Player) Container(org.bukkit.block.Container) Block(org.bukkit.block.Block) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) KitEvent(de.hglabor.plugins.kitapi.kit.events.KitEvent)

Example 3 with Container

use of org.bukkit.block.Container in project PrettySimpleShop by MLG-Fortress.

the class ShopListener method onBreakShop.

@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
private void onBreakShop(BlockBreakEvent event) {
    Block block = event.getBlock();
    if (!config.isShopBlock(block.getType()))
        return;
    Container container = (Container) block.getState();
    if (!shopAPI.isShop(container))
        return;
    instance.getServer().getPluginManager().callEvent(new ShopBreakEvent(event.getPlayer(), new ShopInfo(shopAPI.getLocation(container), shopAPI.getItemStack(container), shopAPI.getPrice(container)), event));
    double deposit = shopAPI.getRevenue(container, true);
    if (deposit <= 0)
        return;
    Player player = event.getPlayer();
    economy.depositPlayer(player, deposit);
    config.sendMessage(player, "collectRevenue", economy.format(deposit));
}
Also used : Container(org.bukkit.block.Container) Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) ShopBreakEvent(com.robomwm.prettysimpleshop.event.ShopBreakEvent) EventHandler(org.bukkit.event.EventHandler)

Example 4 with Container

use of org.bukkit.block.Container in project PrettySimpleShop by MLG-Fortress.

the class ShopListener method selectShop.

public boolean selectShop(Player player, Block block, boolean wantToBuy) {
    if (!config.isShopBlock(block.getType()))
        return false;
    Container container = (Container) block.getState();
    if (!shopAPI.isShop(container))
        return false;
    ItemStack item = shopAPI.getItemStack(container);
    double price = shopAPI.getPrice(container);
    if (price < 0) {
        config.sendMessage(player, "noPrice");
        return true;
    } else if (item == null) {
        config.sendMessage(player, "noStock");
        config.sendTip(player, "noStock");
        return true;
    }
    ShopInfo shopInfo = new ShopInfo(shopAPI.getLocation(container), item, price);
    ShopSelectEvent shopSelectEvent = new ShopSelectEvent(player, shopInfo, shopInfo.equals(selectedShop.get(player)) || wantToBuy);
    selectedShop.put(player, shopInfo);
    // Refactor: put this in the ShopInfo constructor instead
    String textToSend = config.getString("saleInfo", PrettySimpleShop.getItemName(item), economy.format(price), Integer.toString(item.getAmount()));
    String json;
    item.setAmount(1);
    try {
        // CraftItemStack#asNMSCopy(itemStack); //nms version of the ItemStack
        Object nmsItemStack = asNMSCopy.invoke(null, item);
        // new NBTTagCompoundClazz(); //get a new NBTTagCompound, which will contain the nmsItemStack.
        Object nbtTagCompound = NBTTagCompoundClazz.newInstance();
        // nmsItemStack#save(nbtTagCompound); //saves nmsItemStack into our new NBTTagCompound
        nbtTagCompound = saveNMSItemStack.invoke(nmsItemStack, nbtTagCompound);
        json = nbtTagCompound.toString();
    } catch (Throwable rock) {
        // print stacktrace in debug
        // https://howtodoinjava.com/java/string/convert-stacktrace-to-string/
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        rock.printStackTrace(pw);
        PrettySimpleShop.debug(sw.toString());
        player.sendMessage(textToSend);
        instance.getServer().getPluginManager().callEvent(shopSelectEvent);
        return true;
    }
    BaseComponent[] hoverEventComponents = new BaseComponent[] { new TextComponent(json) };
    HoverEvent hover = new HoverEvent(HoverEvent.Action.SHOW_ITEM, hoverEventComponents);
    TextComponent text = new TextComponent(textToSend);
    text.setHoverEvent(hover);
    text.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/buy " + container.getLocation().getWorld().getName() + " " + container.getLocation().getX() + " " + container.getLocation().getBlockY() + " " + container.getLocation().getBlockZ()));
    player.spigot().sendMessage(text);
    shopInfo.setHoverableText(text);
    config.sendTip(player, "saleInfo");
    instance.getServer().getPluginManager().callEvent(shopSelectEvent);
    return true;
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) ShopSelectEvent(com.robomwm.prettysimpleshop.event.ShopSelectEvent) Container(org.bukkit.block.Container) StringWriter(java.io.StringWriter) ItemStack(org.bukkit.inventory.ItemStack) PrintWriter(java.io.PrintWriter)

Example 5 with Container

use of org.bukkit.block.Container in project RoseLoot by Rosewood-Development.

the class LootGenerateListener method onLootGenerate.

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onLootGenerate(LootGenerateEvent event) {
    if (!(event.getInventoryHolder() instanceof Container))
        return;
    Block block = ((Container) event.getInventoryHolder()).getBlock();
    if (Setting.DISABLED_WORLDS.getStringList().stream().anyMatch(x -> x.equalsIgnoreCase(block.getWorld().getName())))
        return;
    LivingEntity looter = null;
    if (event.getEntity() instanceof LivingEntity)
        looter = (LivingEntity) event.getEntity();
    LootContext lootContext = LootContext.builder(LootUtils.getEntityLuck(looter)).put(LootContextParams.ORIGIN, block.getLocation()).put(LootContextParams.LOOTER, looter).put(LootContextParams.LOOTED_BLOCK, block).put(LootContextParams.VANILLA_LOOT_TABLE_KEY, event.getLootTable().getKey()).build();
    LootResult lootResult = this.lootTableManager.getLoot(LootTableTypes.CONTAINER, lootContext);
    LootContents lootContents = lootResult.getLootContents();
    // Overwrite existing loot if applicable
    if (lootResult.shouldOverwriteItems())
        event.getLoot().clear();
    // Set items and drop experience
    event.getLoot().addAll(lootResult.getLootContents().getItems());
    int experience = lootContents.getExperience();
    if (experience > 0) {
        Location location = looter == null ? block.getLocation() : looter.getLocation();
        block.getWorld().spawn(location, ExperienceOrb.class, x -> x.setExperience(experience));
    }
    lootContents.triggerExtras(block.getLocation());
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Container(org.bukkit.block.Container) LootResult(dev.rosewood.roseloot.loot.LootResult) LootContext(dev.rosewood.roseloot.loot.context.LootContext) LootContents(dev.rosewood.roseloot.loot.LootContents) Block(org.bukkit.block.Block) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Container (org.bukkit.block.Container)26 EventHandler (org.bukkit.event.EventHandler)14 Block (org.bukkit.block.Block)13 ItemStack (org.bukkit.inventory.ItemStack)13 Player (org.bukkit.entity.Player)9 BlockState (org.bukkit.block.BlockState)6 Location (org.bukkit.Location)5 ArrayList (java.util.ArrayList)3 ShopOpenCloseEvent (com.robomwm.prettysimpleshop.event.ShopOpenCloseEvent)2 ApiError (eelfloat.replcraft.exceptions.ApiError)2 BaseComponent (net.md_5.bungee.api.chat.BaseComponent)2 TextComponent (net.md_5.bungee.api.chat.TextComponent)2 Banner (org.bukkit.block.Banner)2 Skull (org.bukkit.block.Skull)2 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)2 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)2 ItemMeta (org.bukkit.inventory.meta.ItemMeta)2 AutomatedCrafting (com.aeltumn.autocraft.AutomatedCrafting)1 ConfigFile (com.aeltumn.autocraft.ConfigFile)1 com.aeltumn.autocraft.api (com.aeltumn.autocraft.api)1