Search in sources :

Example 36 with Item

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

the class ShulkerBoxDisplay method onCloseShulkerbox.

@EventHandler
public void onCloseShulkerbox(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());
    Iterator<Item> itr = list.iterator();
    while (itr.hasNext()) {
        Item item = itr.next();
        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)

Example 37 with Item

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

the class SmithingTableDisplay method process.

@Override
public void process(Player player) {
    if (VanishUtils.isVanished(player)) {
        return;
    }
    if (!playermap.containsKey(player)) {
        if (player.getGameMode().equals(GameMode.SPECTATOR)) {
            return;
        }
        if (!(player.getOpenInventory().getTopInventory() instanceof SmithingInventory)) {
            return;
        }
        Block block = player.getTargetBlockExact(7, FluidCollisionMode.NEVER);
        if (block == null || !block.getType().equals(Material.SMITHING_TABLE)) {
            return;
        }
        playermap.put(player, block);
    }
    InventoryView view = player.getOpenInventory();
    Block block = playermap.get(player);
    Location loc = block.getLocation();
    if (!openedSTables.containsKey(block)) {
        Map<String, Object> map = new HashMap<>();
        map.put("Player", player);
        map.put("2", "N/A");
        map.putAll(spawnArmorStands(player, block));
        openedSTables.put(block, map);
    }
    Map<String, Object> map = openedSTables.get(block);
    if (!map.get("Player").equals(player)) {
        return;
    }
    ItemStack[] items = new ItemStack[] { view.getItem(0), view.getItem(1) };
    if (view.getItem(2) != null) {
        ItemStack itemstack = view.getItem(2);
        if (itemstack == null || itemstack.getType().equals(Material.AIR)) {
            itemstack = null;
        }
        Item item = null;
        if (map.get("2") instanceof String) {
            if (itemstack != null) {
                item = new Item(loc.clone().add(0.5, 1.2, 0.5));
                item.setItemStack(itemstack);
                item.setVelocity(new Vector(0, 0, 0));
                item.setPickupDelay(32767);
                item.setGravity(false);
                map.put("2", item);
                PacketManager.sendItemSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMDROP, KEY), item);
                PacketManager.updateItem(item);
            } else {
                map.put("2", "N/A");
            }
        } else {
            item = (Item) map.get("2");
            if (itemstack != null) {
                if (!item.getItemStack().equals(itemstack)) {
                    item.setItemStack(itemstack);
                    PacketManager.updateItem(item);
                }
            } else {
                map.put("2", "N/A");
                PacketManager.removeItem(InteractionVisualizerAPI.getPlayers(), item);
            }
        }
    }
    for (int i = 0; i < 2; i++) {
        ArmorStand stand = (ArmorStand) map.get(String.valueOf(i));
        ItemStack item = items[i];
        if (item == null || item.getType().equals(Material.AIR)) {
            item = null;
        }
        if (item != null) {
            boolean changed = true;
            if (MaterialUtils.getMaterialType(item.getType()).equals(MaterialMode.BLOCK) && !standMode(stand).equals(MaterialMode.BLOCK)) {
                toggleStandMode(stand, "Block");
            } else if (MaterialUtils.getMaterialType(item.getType()).equals(MaterialMode.TOOL) && !standMode(stand).equals(MaterialMode.TOOL)) {
                toggleStandMode(stand, "Tool");
            } else if (MaterialUtils.getMaterialType(item.getType()).equals(MaterialMode.ITEM) && !standMode(stand).equals(MaterialMode.ITEM)) {
                toggleStandMode(stand, "Item");
            } else if (MaterialUtils.getMaterialType(item.getType()).equals(MaterialMode.STANDING) && !standMode(stand).equals(MaterialMode.STANDING)) {
                toggleStandMode(stand, "Standing");
            } else if (MaterialUtils.getMaterialType(item.getType()).equals(MaterialMode.LOWBLOCK) && !standMode(stand).equals(MaterialMode.LOWBLOCK)) {
                toggleStandMode(stand, "LowBlock");
            } else {
                changed = false;
            }
            if (!item.getType().equals(stand.getItemInMainHand().getType())) {
                changed = true;
                stand.setItemInMainHand(item);
            }
            if (changed) {
                PacketManager.updateArmorStand(stand);
            }
        } else {
            if (!stand.getItemInMainHand().getType().equals(Material.AIR)) {
                stand.setItemInMainHand(new ItemStack(Material.AIR));
                PacketManager.updateArmorStand(stand);
            }
        }
    }
    Location loc1 = ((ArmorStand) map.get("0")).getLocation();
    InteractionVisualizer.lightManager.deleteLight(loc1);
    int skylight = loc1.getBlock().getRelative(BlockFace.UP).getLightFromSky();
    int blocklight = loc1.getBlock().getRelative(BlockFace.UP).getLightFromBlocks() - 1;
    blocklight = Math.max(blocklight, 0);
    if (skylight > 0) {
        InteractionVisualizer.lightManager.createLight(loc1, skylight, LightType.SKY);
    }
    if (blocklight > 0) {
        InteractionVisualizer.lightManager.createLight(loc1, blocklight, LightType.BLOCK);
    }
}
Also used : HashMap(java.util.HashMap) SmithingInventory(org.bukkit.inventory.SmithingInventory) Item(com.loohp.interactionvisualizer.entityholders.Item) InventoryView(org.bukkit.inventory.InventoryView) ArmorStand(com.loohp.interactionvisualizer.entityholders.ArmorStand) Block(org.bukkit.block.Block) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 38 with Item

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

the class SmokerDisplay method onBreakSmoker.

@EventHandler(priority = EventPriority.MONITOR)
public void onBreakSmoker(BlockBreakEvent event) {
    Block block = event.getBlock();
    if (!smokerMap.containsKey(block)) {
        return;
    }
    Map<String, Object> map = smokerMap.get(block);
    if (map.get("Item") instanceof Item) {
        Item item = (Item) map.get("Item");
        PacketManager.removeItem(InteractionVisualizerAPI.getPlayers(), item);
    }
    if (map.get("Stand") instanceof ArmorStand) {
        ArmorStand stand = (ArmorStand) map.get("Stand");
        PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), stand);
    }
    smokerMap.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 39 with Item

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

the class SmokerDisplay method onSmoker.

@EventHandler(priority = EventPriority.MONITOR)
public void onSmoker(InventoryClickEvent event) {
    if (VanishUtils.isVanished((Player) event.getWhoClicked())) {
        return;
    }
    if (event.isCancelled()) {
        return;
    }
    if (event.getRawSlot() != 0 && event.getRawSlot() != 2) {
        return;
    }
    if (event.getCurrentItem() == null) {
        return;
    }
    if (event.getCurrentItem().getType().equals(Material.AIR)) {
        return;
    }
    if (event.getRawSlot() == 2) {
        if (event.getCursor() != null) {
            if (!event.getCursor().getType().equals(Material.AIR)) {
                if (event.getCursor().getAmount() >= event.getCursor().getType().getMaxStackSize()) {
                    return;
                }
            }
        }
    } else {
        if (event.getCursor() != null) {
            if (event.getCursor().getType().equals(event.getCurrentItem().getType())) {
                return;
            }
        }
    }
    if (event.isShiftClick()) {
        if (!InventoryUtils.stillHaveSpace(event.getWhoClicked().getInventory(), event.getView().getItem(event.getRawSlot()).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().equals(Material.SMOKER)) {
        return;
    }
    Block block = event.getView().getTopInventory().getLocation().getBlock();
    if (!smokerMap.containsKey(block)) {
        return;
    }
    Map<String, Object> map = smokerMap.get(block);
    int slot = event.getRawSlot();
    ItemStack itemstack = event.getCurrentItem().clone();
    Location loc = block.getLocation();
    Player player = (Player) event.getWhoClicked();
    Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> {
        if (player.getOpenInventory().getItem(slot) == null || (itemstack.isSimilar(player.getOpenInventory().getItem(slot)) && itemstack.getAmount() == player.getOpenInventory().getItem(slot).getAmount())) {
            return;
        }
        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");
        map.put("Item", "N/A");
        item.setItemStack(itemstack);
        item.setLocked(true);
        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 : Player(org.bukkit.entity.Player) Item(com.loohp.interactionvisualizer.entityholders.Item) Block(org.bukkit.block.Block) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 40 with Item

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

the class PacketManager method removeAll.

public static void removeAll(Player theplayer) {
    playerStatus.put(theplayer, Collections.newSetFromMap(new ConcurrentHashMap<>()));
    if (!plugin.isEnabled()) {
        return;
    }
    InteractionVisualizer.asyncExecutorManager.runTaskAsynchronously(() -> {
        Collection<Player> player = new HashSet<>();
        player.add(theplayer);
        int count = 0;
        int delay = 1;
        for (Entry<VisualizerEntity, Collection<Player>> entry : active.entrySet()) {
            count++;
            if (count > 5) {
                delay++;
                count = 0;
            }
            VisualizerEntity entity = entry.getKey();
            if (entity instanceof ArmorStand) {
                Bukkit.getScheduler().runTaskLater(plugin, () -> removeArmorStand(player, (ArmorStand) entity, false, false), delay);
            }
            if (entity instanceof Item) {
                Bukkit.getScheduler().runTaskLater(plugin, () -> removeItem(player, (Item) entity, false, false), delay);
            }
            if (entity instanceof ItemFrame) {
                Bukkit.getScheduler().runTaskLater(plugin, () -> removeItemFrame(player, (ItemFrame) entity, false, false), delay);
            }
        }
    });
}
Also used : Item(com.loohp.interactionvisualizer.entityholders.Item) Player(org.bukkit.entity.Player) ArmorStand(com.loohp.interactionvisualizer.entityholders.ArmorStand) DynamicVisualizerEntity(com.loohp.interactionvisualizer.entityholders.DynamicVisualizerEntity) VisualizerEntity(com.loohp.interactionvisualizer.entityholders.VisualizerEntity) Collection(java.util.Collection) ItemFrame(com.loohp.interactionvisualizer.entityholders.ItemFrame) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashSet(java.util.HashSet)

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