Search in sources :

Example 51 with Item

use of com.loohp.interactionvisualizer.entityholders.Item in project InteractionVisualizer by LOOHP.

the class StonecutterDisplay method onStonecutter.

@EventHandler(priority = EventPriority.MONITOR)
public void onStonecutter(InventoryClickEvent event) {
    if (VanishUtils.isVanished((Player) event.getWhoClicked())) {
        return;
    }
    if (event.isCancelled()) {
        return;
    }
    if (event.getRawSlot() != 1) {
        return;
    }
    if (event.getCurrentItem() == null) {
        return;
    }
    if (event.getCurrentItem().getType().equals(Material.AIR)) {
        return;
    }
    if (event.getCursor() != null) {
        if (!event.getCursor().getType().equals(Material.AIR)) {
            if (event.getCursor().getAmount() >= event.getCursor().getType().getMaxStackSize()) {
                return;
            }
        }
    }
    if (event.isShiftClick()) {
        if (!InventoryUtils.stillHaveSpace(event.getWhoClicked().getInventory(), event.getView().getItem(1).getType())) {
            return;
        }
    }
    if (event.getAction().equals(InventoryAction.HOTBAR_MOVE_AND_READD)) {
        if (event.getWhoClicked().getInventory().getItem(event.getHotbarButton()) != null && !event.getWhoClicked().getInventory().getItem(event.getHotbarButton()).getType().equals(Material.AIR)) {
            return;
        }
    }
    if (!playermap.containsKey((Player) event.getWhoClicked())) {
        return;
    }
    Block block = playermap.get((Player) event.getWhoClicked());
    if (!openedStonecutter.containsKey(block)) {
        return;
    }
    Map<String, Object> map = openedStonecutter.get(block);
    if (!map.get("Player").equals(event.getWhoClicked())) {
        return;
    }
    ItemStack itemstack = event.getCurrentItem().clone();
    Location loc = block.getLocation();
    Player player = (Player) event.getWhoClicked();
    if (map.get("Item") instanceof String) {
        map.put("Item", new Item(block.getLocation().clone().add(0.5, 1.2, 0.5)));
    }
    Item item = (Item) map.get("Item");
    Inventory before = Bukkit.createInventory(null, 9);
    before.setItem(0, player.getOpenInventory().getItem(0).clone());
    Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> {
        Inventory after = Bukkit.createInventory(null, 9);
        after.setItem(0, player.getOpenInventory().getItem(0).clone());
        if (InventoryUtils.compareContents(before, after)) {
            return;
        }
        item.setLocked(true);
        openedStonecutter.remove(block);
        item.setItemStack(itemstack);
        Vector lift = new Vector(0.0, 0.15, 0.0);
        Vector pickup = player.getEyeLocation().add(0.0, -0.5, 0.0).add(0.0, InteractionVisualizer.playerPickupYOffset, 0.0).toVector().subtract(loc.clone().add(0.5, 1.2, 0.5).toVector()).multiply(0.15).add(lift);
        item.setVelocity(pickup);
        item.setGravity(true);
        item.setPickupDelay(32767);
        PacketManager.updateItem(item);
        Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> {
            SoundManager.playItemPickup(item.getLocation(), InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMDROP, KEY));
            PacketManager.removeItem(InteractionVisualizerAPI.getPlayers(), item);
        }, 8);
    }, 1);
}
Also used : Item(com.loohp.interactionvisualizer.entityholders.Item) Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) Inventory(org.bukkit.inventory.Inventory) StonecutterInventory(org.bukkit.inventory.StonecutterInventory) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 52 with Item

use of com.loohp.interactionvisualizer.entityholders.Item in project InteractionVisualizer by LOOHP.

the class VillagerDisplay method onVillageTrade.

@EventHandler(priority = EventPriority.MONITOR)
public void onVillageTrade(InventoryClickEvent event) {
    if (event.isCancelled()) {
        return;
    }
    if (VanishUtils.isVanished((Player) event.getWhoClicked())) {
        return;
    }
    if (!(event.getView().getTopInventory() instanceof MerchantInventory)) {
        return;
    }
    if (event.getRawSlot() != 2) {
        return;
    }
    if (event.getCurrentItem() == null) {
        return;
    }
    if (event.getCurrentItem().getType().equals(Material.AIR)) {
        return;
    }
    if (event.getCursor() != null) {
        if (!event.getCursor().getType().equals(Material.AIR)) {
            if (event.getCursor().getAmount() >= event.getCursor().getType().getMaxStackSize()) {
                return;
            }
        }
    }
    if (event.isShiftClick()) {
        if (!InventoryUtils.stillHaveSpace(event.getWhoClicked().getInventory(), event.getView().getItem(2).getType())) {
            return;
        }
    }
    ItemStack item0 = null;
    if (event.getView().getItem(0) != null) {
        if (!event.getView().getItem(0).getType().equals(Material.AIR)) {
            item0 = event.getView().getItem(0).clone();
        }
    }
    ItemStack item1 = null;
    if (event.getView().getItem(1) != null) {
        if (!event.getView().getItem(1).getType().equals(Material.AIR)) {
            item1 = event.getView().getItem(1).clone();
        }
    }
    ItemStack item2 = event.getCurrentItem().clone();
    Player player = (Player) event.getWhoClicked();
    MerchantInventory tradeinv = (MerchantInventory) event.getView().getTopInventory();
    if (InteractionVisualizer.version.isNewerOrEqualTo(MCVersion.V1_14)) {
        if (!(tradeinv.getHolder() instanceof org.bukkit.entity.AbstractVillager)) {
            return;
        }
    } else {
        if (!(tradeinv.getHolder() instanceof Villager)) {
            return;
        }
    }
    NPC villager = (NPC) tradeinv.getHolder();
    Vector lift = new Vector(0.0, 0.20, 0.0);
    if (item0 != null) {
        Item in = new Item(player.getEyeLocation());
        Vector vector = villager.getEyeLocation().add(0.0, -0.5, 0.0).toVector().subtract(player.getEyeLocation().toVector()).multiply(0.12).add(lift);
        in.setItemStack(item0);
        in.setGravity(true);
        in.setVelocity(vector);
        PacketManager.sendItemSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMDROP, KEY), in);
        PacketManager.updateItem(in);
        Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> PacketManager.removeItem(InteractionVisualizerAPI.getPlayers(), in), 14);
    }
    ItemStack item1final = item1;
    Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> {
        if (item1final != null) {
            Item in = new Item(player.getEyeLocation());
            Vector vector = villager.getEyeLocation().add(0.0, -0.5, 0.0).toVector().subtract(player.getEyeLocation().toVector()).multiply(0.12).add(lift);
            in.setItemStack(item1final);
            in.setGravity(true);
            in.setVelocity(vector);
            PacketManager.sendItemSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMDROP, KEY), in);
            PacketManager.updateItem(in);
            Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> PacketManager.removeItem(InteractionVisualizerAPI.getPlayers(), in), 14);
        }
    }, 8);
    Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> {
        Item out = new Item(villager.getEyeLocation());
        Vector vector = player.getEyeLocation().add(0.0, -0.5, 0.0).toVector().subtract(villager.getEyeLocation().toVector()).multiply(0.10).add(lift);
        out.setItemStack(item2);
        out.setGravity(true);
        out.setVelocity(vector);
        PacketManager.sendItemSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMDROP, KEY), out);
        PacketManager.updateItem(out);
        Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> PacketManager.removeItem(InteractionVisualizerAPI.getPlayers(), out), 12);
    }, 40);
}
Also used : NPC(org.bukkit.entity.NPC) Item(com.loohp.interactionvisualizer.entityholders.Item) Player(org.bukkit.entity.Player) MerchantInventory(org.bukkit.inventory.MerchantInventory) Villager(org.bukkit.entity.Villager) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) EventHandler(org.bukkit.event.EventHandler)

Example 53 with Item

use of com.loohp.interactionvisualizer.entityholders.Item in project InteractionVisualizer by LOOHP.

the class AnvilDisplay method onAnvil.

@EventHandler(priority = EventPriority.MONITOR)
public void onAnvil(InventoryClickEvent event) {
    if (VanishUtils.isVanished((Player) event.getWhoClicked())) {
        return;
    }
    if (event.isCancelled()) {
        return;
    }
    if (event.getRawSlot() != 2) {
        return;
    }
    if (event.getCurrentItem() == null) {
        return;
    }
    if (event.getCurrentItem().getType().equals(Material.AIR)) {
        return;
    }
    if (event.getCursor() != null) {
        if (!event.getCursor().getType().equals(Material.AIR)) {
            if (event.getCursor().getAmount() >= event.getCursor().getType().getMaxStackSize()) {
                return;
            }
        }
    }
    if (event.isShiftClick()) {
        if (!InventoryUtils.stillHaveSpace(event.getWhoClicked().getInventory(), event.getView().getItem(2).getType())) {
            return;
        }
    }
    if (event.getAction().equals(InventoryAction.HOTBAR_MOVE_AND_READD)) {
        if (event.getWhoClicked().getInventory().getItem(event.getHotbarButton()) != null && !event.getWhoClicked().getInventory().getItem(event.getHotbarButton()).getType().equals(Material.AIR)) {
            return;
        }
    }
    if (event.getView().getTopInventory() == null) {
        return;
    }
    try {
        if (event.getView().getTopInventory().getLocation() == null) {
            return;
        }
    } catch (Exception | AbstractMethodError e) {
        return;
    }
    if (event.getView().getTopInventory().getLocation().getBlock() == null) {
        return;
    }
    if (!event.getView().getTopInventory().getLocation().getBlock().getType().toString().toUpperCase().contains("ANVIL")) {
        return;
    }
    Block block = event.getView().getTopInventory().getLocation().getBlock();
    if (!openedAnvil.containsKey(block)) {
        return;
    }
    Map<String, Object> map = openedAnvil.get(block);
    if (!map.get("Player").equals(event.getWhoClicked())) {
        return;
    }
    ItemStack itemstack = event.getCurrentItem();
    Location loc = block.getLocation();
    Player player = (Player) event.getWhoClicked();
    ArmorStand slot0 = (ArmorStand) map.get("0");
    ArmorStand slot1 = (ArmorStand) map.get("1");
    if (map.get("2") instanceof String) {
        map.put("2", new Item(block.getLocation().clone().add(0.5, 1.2, 0.5)));
    }
    Item item = (Item) map.get("2");
    Inventory before = Bukkit.createInventory(null, 9);
    before.setItem(0, player.getOpenInventory().getItem(0).clone());
    before.setItem(1, player.getOpenInventory().getItem(1).clone());
    Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> {
        Inventory after = Bukkit.createInventory(null, 9);
        after.setItem(0, player.getOpenInventory().getItem(0).clone());
        after.setItem(1, player.getOpenInventory().getItem(1).clone());
        if (InventoryUtils.compareContents(before, after)) {
            return;
        }
        slot0.setLocked(true);
        slot1.setLocked(true);
        item.setLocked(true);
        openedAnvil.remove(block);
        float yaw = getCardinalDirection(player);
        Vector vector = new Location(slot0.getWorld(), slot0.getLocation().getX(), slot0.getLocation().getY(), slot0.getLocation().getZ(), yaw, 0).getDirection().normalize();
        slot0.teleport(slot0.getLocation().add(rotateVectorAroundY(vector.clone(), 90).multiply(0.1)));
        slot1.teleport(slot1.getLocation().add(rotateVectorAroundY(vector.clone(), -90).multiply(0.1)));
        PacketManager.updateArmorStand(slot0);
        PacketManager.updateArmorStand(slot1);
        Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> {
            for (Player each : InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMDROP, KEY)) {
                each.spawnParticle(Particle.CLOUD, loc.clone().add(0.5, 1.1, 0.5), 10, 0.05, 0.05, 0.05, 0.05);
            }
        }, 6);
        Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> {
            Vector lift = new Vector(0.0, 0.15, 0.0);
            Vector pickup = player.getEyeLocation().add(0.0, -0.5, 0.0).add(0.0, InteractionVisualizer.playerPickupYOffset, 0.0).toVector().subtract(loc.clone().add(0.5, 1.2, 0.5).toVector()).multiply(0.15).add(lift);
            item.setItemStack(itemstack);
            item.setVelocity(pickup);
            item.setGravity(true);
            item.setPickupDelay(32767);
            PacketManager.updateItem(item);
            Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> {
                SoundManager.playItemPickup(item.getLocation(), InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMDROP, KEY));
                PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), slot0);
                PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), slot1);
                PacketManager.removeItem(InteractionVisualizerAPI.getPlayers(), item);
            }, 8);
        }, 10);
    }, 1);
}
Also used : Player(org.bukkit.entity.Player) Item(com.loohp.interactionvisualizer.entityholders.Item) ArmorStand(com.loohp.interactionvisualizer.entityholders.ArmorStand) Block(org.bukkit.block.Block) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) Inventory(org.bukkit.inventory.Inventory) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 54 with Item

use of com.loohp.interactionvisualizer.entityholders.Item in project InteractionVisualizer by LOOHP.

the class AnvilDisplay method onCloseAnvil.

@EventHandler
public void onCloseAnvil(InventoryCloseEvent event) {
    if (event.getView().getTopInventory() == null) {
        return;
    }
    try {
        if (event.getView().getTopInventory().getLocation() == null) {
            return;
        }
    } catch (Exception | AbstractMethodError e) {
        return;
    }
    if (event.getView().getTopInventory().getLocation().getBlock() == null) {
        return;
    }
    Block block = event.getView().getTopInventory().getLocation().getBlock();
    if (!openedAnvil.containsKey(block)) {
        return;
    }
    Map<String, Object> map = openedAnvil.get(block);
    if (!map.get("Player").equals(event.getPlayer())) {
        return;
    }
    for (int i = 0; i <= 2; i++) {
        if (!(map.get(String.valueOf(i)) instanceof String)) {
            Object entity = map.get(String.valueOf(i));
            if (entity instanceof Item) {
                PacketManager.removeItem(InteractionVisualizerAPI.getPlayers(), (Item) entity);
            } else if (entity instanceof ArmorStand) {
                PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), (ArmorStand) entity);
            }
        }
    }
    openedAnvil.remove(block);
}
Also used : Item(com.loohp.interactionvisualizer.entityholders.Item) ArmorStand(com.loohp.interactionvisualizer.entityholders.ArmorStand) Block(org.bukkit.block.Block) EventHandler(org.bukkit.event.EventHandler)

Example 55 with Item

use of com.loohp.interactionvisualizer.entityholders.Item in project InteractionVisualizer by LOOHP.

the class BarrelDisplay method onCloseBarrel.

@EventHandler
public void onCloseBarrel(InventoryCloseEvent event) {
    if (event.getView().getTopInventory() == null) {
        return;
    }
    try {
        if (event.getView().getTopInventory().getLocation() == null) {
            return;
        }
    } catch (Exception | AbstractMethodError e) {
        return;
    }
    if (!LocationUtils.isLoaded(event.getView().getTopInventory().getLocation())) {
        return;
    }
    if (event.getView().getTopInventory().getLocation().getBlock() == null) {
        return;
    }
    if (!link.containsKey((Player) event.getPlayer())) {
        return;
    }
    List<Item> list = link.get((Player) event.getPlayer());
    for (Item item : list) {
        PacketManager.removeItem(InteractionVisualizerAPI.getPlayers(), item);
    }
    link.remove((Player) event.getPlayer());
}
Also used : Item(com.loohp.interactionvisualizer.entityholders.Item) Player(org.bukkit.entity.Player) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Item (com.loohp.interactionvisualizer.entityholders.Item)62 EventHandler (org.bukkit.event.EventHandler)48 Player (org.bukkit.entity.Player)47 Block (org.bukkit.block.Block)43 Vector (org.bukkit.util.Vector)37 Location (org.bukkit.Location)34 ItemStack (org.bukkit.inventory.ItemStack)33 ArmorStand (com.loohp.interactionvisualizer.entityholders.ArmorStand)23 Inventory (org.bukkit.inventory.Inventory)22 HashMap (java.util.HashMap)7 InventoryView (org.bukkit.inventory.InventoryView)5 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)5 DynamicVisualizerEntity (com.loohp.interactionvisualizer.entityholders.DynamicVisualizerEntity)4 ItemFrame (com.loohp.interactionvisualizer.entityholders.ItemFrame)4 VisualizerEntity (com.loohp.interactionvisualizer.entityholders.VisualizerEntity)4 Collection (java.util.Collection)4 Chest (org.bukkit.block.Chest)4 DoubleChest (org.bukkit.block.DoubleChest)4 InventoryHolder (org.bukkit.inventory.InventoryHolder)4 HashSet (java.util.HashSet)3