Search in sources :

Example 1 with StackedItem

use of dev.rosewood.rosestacker.stack.StackedItem in project RoseStacker by Rosewood-Development.

the class UltimateStackerConversionHandler method handleConversion.

@Override
public Set<Stack<?>> handleConversion(Set<ConversionData> conversionData) {
    Set<Stack<?>> stacks = new HashSet<>();
    for (ConversionData data : conversionData) {
        Item item = data.getItem();
        if (item == null)
            continue;
        int stackSize = this.getItemAmount(item);
        StackedItem stackedItem = new StackedItem(stackSize, data.getItem());
        this.stackManager.addItemStack(stackedItem);
        stacks.add(stackedItem);
    }
    return stacks;
}
Also used : Item(org.bukkit.entity.Item) StackedItem(dev.rosewood.rosestacker.stack.StackedItem) ConversionData(dev.rosewood.rosestacker.conversion.ConversionData) StackedItem(dev.rosewood.rosestacker.stack.StackedItem) Stack(dev.rosewood.rosestacker.stack.Stack) ItemStack(org.bukkit.inventory.ItemStack) HashSet(java.util.HashSet)

Example 2 with StackedItem

use of dev.rosewood.rosestacker.stack.StackedItem in project RoseStacker by Rosewood-Development.

the class ItemListener method onInventoryPickup.

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onInventoryPickup(InventoryPickupItemEvent event) {
    if (this.stackManager.isWorldDisabled(event.getItem().getWorld()))
        return;
    if (!this.stackManager.isItemStackingEnabled())
        return;
    StackedItem stackedItem = this.stackManager.getStackedItem(event.getItem());
    if (stackedItem == null)
        return;
    Inventory inventory = event.getInventory();
    if (this.applyInventoryItemPickup(inventory, stackedItem, null))
        event.setCancelled(true);
}
Also used : StackedItem(dev.rosewood.rosestacker.stack.StackedItem) Inventory(org.bukkit.inventory.Inventory) PlayerInventory(org.bukkit.inventory.PlayerInventory) EventHandler(org.bukkit.event.EventHandler)

Example 3 with StackedItem

use of dev.rosewood.rosestacker.stack.StackedItem in project RoseStacker by Rosewood-Development.

the class StackToolListener method onInteract.

/**
 * Handles Shift Left Click for StackedItems
 *
 * @param event The PlayerInteractEvent
 */
@EventHandler(priority = EventPriority.LOWEST)
public void onInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    ItemStack tool = player.getInventory().getItemInMainHand();
    if (event.getAction() == Action.PHYSICAL || !ItemUtils.isStackingTool(tool))
        return;
    event.setCancelled(true);
    if (!player.isSneaking() || event.getHand() != EquipmentSlot.HAND)
        return;
    if (!player.hasPermission("rosestacker.stacktool")) {
        this.localeManager.sendMessage(player, "command-stacktool-no-permission");
        return;
    }
    if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
        for (Entity entity : player.getNearbyEntities(3, 3, 3)) {
            if (entity.getType() != EntityType.DROPPED_ITEM)
                continue;
            Item item = (Item) entity;
            if (!EntityUtils.isLookingAtItem(player, item))
                continue;
            StackedItem stackedItem = this.stackManager.getStackedItem(item);
            if (stackedItem == null)
                continue;
            ItemMeta itemMeta = item.getItemStack().getItemMeta();
            this.localeManager.sendMessage(player, "command-stacktool-info");
            this.localeManager.sendSimpleMessage(player, "command-stacktool-info-uuid", StringPlaceholders.single("uuid", item.getUniqueId().toString()));
            this.localeManager.sendSimpleMessage(player, "command-stacktool-info-entity-id", StringPlaceholders.single("id", item.getEntityId()));
            this.localeManager.sendSimpleMessage(player, "command-stacktool-info-item-type", StringPlaceholders.single("type", item.getItemStack().getType().name()));
            this.localeManager.sendSimpleMessage(player, "command-stacktool-info-stack-size", StringPlaceholders.single("amount", stackedItem.getStackSize()));
            if (itemMeta != null && itemMeta.hasDisplayName())
                this.localeManager.sendSimpleMessage(player, "command-stacktool-info-custom-name", StringPlaceholders.single("name", itemMeta.getDisplayName()));
            this.localeManager.sendSimpleMessage(player, "command-stacktool-info-location", StringPlaceholders.builder("x", item.getLocation().getBlockX()).addPlaceholder("y", item.getLocation().getBlockY()).addPlaceholder("z", item.getLocation().getBlockZ()).addPlaceholder("world", item.getWorld().getName()).build());
            this.localeManager.sendSimpleMessage(player, "command-stacktool-info-chunk", StringPlaceholders.builder("x", item.getLocation().getChunk().getX()).addPlaceholder("z", item.getLocation().getChunk().getZ()).build());
            return;
        }
    }
    if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
        Block clickedBlock = event.getClickedBlock();
        if (clickedBlock == null)
            return;
        if (clickedBlock.getType() != Material.SPAWNER) {
            StackedBlock stackedBlock = this.stackManager.getStackedBlock(clickedBlock);
            if (stackedBlock == null)
                return;
            this.localeManager.sendMessage(player, "command-stacktool-info");
            this.localeManager.sendSimpleMessage(player, "command-stacktool-info-block-type", StringPlaceholders.single("type", clickedBlock.getType().name()));
            this.localeManager.sendSimpleMessage(player, "command-stacktool-info-stack-size", StringPlaceholders.single("amount", stackedBlock.getStackSize()));
            this.localeManager.sendSimpleMessage(player, "command-stacktool-info-location", StringPlaceholders.builder("x", clickedBlock.getX()).addPlaceholder("y", clickedBlock.getY()).addPlaceholder("z", clickedBlock.getZ()).addPlaceholder("world", clickedBlock.getWorld().getName()).build());
            this.localeManager.sendSimpleMessage(player, "command-stacktool-info-chunk", StringPlaceholders.builder("x", clickedBlock.getChunk().getX()).addPlaceholder("z", clickedBlock.getChunk().getZ()).build());
        } else {
            StackedSpawner stackedSpawner = this.stackManager.getStackedSpawner(clickedBlock);
            if (stackedSpawner == null)
                return;
            this.localeManager.sendMessage(player, "command-stacktool-info");
            this.localeManager.sendSimpleMessage(player, "command-stacktool-info-spawner-type", StringPlaceholders.single("type", stackedSpawner.getSpawnerTile().getSpawnedType().name()));
            this.localeManager.sendSimpleMessage(player, "command-stacktool-info-stack-size", StringPlaceholders.single("amount", stackedSpawner.getStackSize()));
            this.localeManager.sendSimpleMessage(player, "command-stacktool-info-location", StringPlaceholders.builder("x", clickedBlock.getX()).addPlaceholder("y", clickedBlock.getY()).addPlaceholder("z", clickedBlock.getZ()).addPlaceholder("world", clickedBlock.getWorld().getName()).build());
            this.localeManager.sendSimpleMessage(player, "command-stacktool-info-chunk", StringPlaceholders.builder("x", clickedBlock.getChunk().getX()).addPlaceholder("z", clickedBlock.getChunk().getZ()).build());
        }
    }
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        Block clickedBlock = event.getClickedBlock();
        if (clickedBlock == null || clickedBlock.getType() != Material.SPAWNER)
            return;
        StackedSpawner stackedSpawner = this.stackManager.getStackedSpawner(clickedBlock);
        if (stackedSpawner == null) {
            CreatureSpawner creatureSpawner = (CreatureSpawner) clickedBlock.getState();
            creatureSpawner.setDelay(5);
            creatureSpawner.update();
        } else {
            stackedSpawner.getSpawnerTile().setDelay(5);
        }
        int points = 50;
        for (int i = 0; i < points; i++) {
            double dx = Math.cos(Math.PI * 2 * ((double) i / points)) * 0.25;
            double dy = 0.5;
            double dz = Math.sin(Math.PI * 2 * ((double) i / points)) * 0.25;
            double angle = Math.atan2(dz, dx);
            double xAng = Math.cos(angle);
            double zAng = Math.sin(angle);
            clickedBlock.getWorld().spawnParticle(Particle.END_ROD, clickedBlock.getLocation().add(0.5 + dx, dy, 0.5 + dz), 0, xAng, 0, zAng, 0.15);
        }
    }
    // Make the item bob a little bit
    player.updateInventory();
}
Also used : StackedEntity(dev.rosewood.rosestacker.stack.StackedEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Item(org.bukkit.entity.Item) StackedItem(dev.rosewood.rosestacker.stack.StackedItem) Player(org.bukkit.entity.Player) StackedSpawner(dev.rosewood.rosestacker.stack.StackedSpawner) StackedBlock(dev.rosewood.rosestacker.stack.StackedBlock) Block(org.bukkit.block.Block) StackedBlock(dev.rosewood.rosestacker.stack.StackedBlock) ItemStack(org.bukkit.inventory.ItemStack) StackedItem(dev.rosewood.rosestacker.stack.StackedItem) ItemMeta(org.bukkit.inventory.meta.ItemMeta) CreatureSpawner(org.bukkit.block.CreatureSpawner) EventHandler(org.bukkit.event.EventHandler)

Example 4 with StackedItem

use of dev.rosewood.rosestacker.stack.StackedItem in project RoseStacker by Rosewood-Development.

the class DataUtils method readStackedItem.

public static StackedItem readStackedItem(Item item) {
    PersistentDataContainer pdc = item.getPersistentDataContainer();
    byte[] data = pdc.get(ITEM_KEY, PersistentDataType.BYTE_ARRAY);
    if (data == null)
        return new StackedItem(item.getItemStack().getAmount(), item);
    try (ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
        ObjectInputStream dataInput = new ObjectInputStream(inputStream)) {
        int dataVersion = dataInput.readInt();
        if (dataVersion == 1) {
            int stackSize = dataInput.readInt();
            return new StackedItem(stackSize, item);
        }
    } catch (Exception e) {
        e.printStackTrace();
        pdc.remove(ITEM_KEY);
    }
    return null;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StackedItem(dev.rosewood.rosestacker.stack.StackedItem) PersistentDataContainer(org.bukkit.persistence.PersistentDataContainer) ObjectInputStream(java.io.ObjectInputStream)

Example 5 with StackedItem

use of dev.rosewood.rosestacker.stack.StackedItem in project RoseStacker by Rosewood-Development.

the class ItemConversionHandler method handleConversion.

@Override
public Set<Stack<?>> handleConversion(Set<ConversionData> conversionData) {
    Set<Stack<?>> stacks = new HashSet<>();
    for (ConversionData data : conversionData) {
        StackedItem stackedItem = new StackedItem(data.getStackSize(), data.getItem());
        this.stackManager.addItemStack(stackedItem);
        stacks.add(stackedItem);
    }
    return stacks;
}
Also used : ConversionData(dev.rosewood.rosestacker.conversion.ConversionData) StackedItem(dev.rosewood.rosestacker.stack.StackedItem) Stack(dev.rosewood.rosestacker.stack.Stack) HashSet(java.util.HashSet)

Aggregations

StackedItem (dev.rosewood.rosestacker.stack.StackedItem)8 Item (org.bukkit.entity.Item)4 EventHandler (org.bukkit.event.EventHandler)4 ConversionData (dev.rosewood.rosestacker.conversion.ConversionData)3 Stack (dev.rosewood.rosestacker.stack.Stack)3 HashSet (java.util.HashSet)3 ItemStack (org.bukkit.inventory.ItemStack)3 StackedEntity (dev.rosewood.rosestacker.stack.StackedEntity)2 Entity (org.bukkit.entity.Entity)2 LivingEntity (org.bukkit.entity.LivingEntity)2 Player (org.bukkit.entity.Player)2 Inventory (org.bukkit.inventory.Inventory)2 PlayerInventory (org.bukkit.inventory.PlayerInventory)2 PersistentDataContainer (org.bukkit.persistence.PersistentDataContainer)2 StackedBlock (dev.rosewood.rosestacker.stack.StackedBlock)1 StackedSpawner (dev.rosewood.rosestacker.stack.StackedSpawner)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 Block (org.bukkit.block.Block)1 CreatureSpawner (org.bukkit.block.CreatureSpawner)1