Search in sources :

Example 41 with Item

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

the class PacketManager method sendPlayerPackets.

public static void sendPlayerPackets(Player theplayer) {
    playerStatus.put(theplayer, Collections.newSetFromMap(new ConcurrentHashMap<VisualizerEntity, Boolean>()));
    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()) {
            VisualizerEntity entity = entry.getKey();
            if (entry.getValue().contains(theplayer)) {
                Boolean isLoaded = loaded.get(entity);
                if (isLoaded != null && isLoaded) {
                    count++;
                    if (count > 5) {
                        delay++;
                        count = 0;
                    }
                    if (entity instanceof ArmorStand) {
                        Bukkit.getScheduler().runTaskLater(plugin, () -> {
                            sendArmorStandSpawn(player, (ArmorStand) entity);
                            updateArmorStand(player, (ArmorStand) entity, true);
                        }, delay);
                    }
                    if (entity instanceof Item) {
                        Bukkit.getScheduler().runTaskLater(plugin, () -> {
                            sendItemSpawn(player, (Item) entity);
                            updateItem(player, (Item) entity, true);
                        }, delay);
                    }
                    if (entity instanceof ItemFrame) {
                        Bukkit.getScheduler().runTaskLater(plugin, () -> {
                            sendItemFrameSpawn(player, (ItemFrame) entity);
                            updateItemFrame(player, (ItemFrame) entity, true);
                        }, 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)

Example 42 with Item

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

the class PacketManager method run.

public static void run() {
    if (!plugin.isEnabled()) {
        return;
    }
    InteractionVisualizer.asyncExecutorManager.runTaskAsynchronously(() -> {
        for (Entry<VisualizerEntity, Boolean> entry : loaded.entrySet()) {
            VisualizerEntity entity = entry.getKey();
            if (entity instanceof ArmorStand) {
                ArmorStand stand = (ArmorStand) entity;
                if (PlayerLocationManager.hasPlayerNearby(stand.getLocation())) {
                    if (entry.getValue()) {
                        Collection<Player> players = active.get(entity);
                        if (players != null) {
                            SyncUtils.runAsyncWithSyncCondition(() -> LocationUtils.isLoaded(stand.getLocation()) && isOccluding(stand.getLocation().getBlock().getType()), 200, () -> {
                                if (active.containsKey(entity)) {
                                    removeArmorStand(InteractionVisualizerAPI.getPlayers(), stand, false, false);
                                    loaded.put(entity, false);
                                }
                            });
                        }
                    } else {
                        Collection<Player> players = active.get(entity);
                        if (players != null) {
                            SyncUtils.runAsyncWithSyncCondition(() -> LocationUtils.isLoaded(stand.getLocation()) && !isOccluding(stand.getLocation().getBlock().getType()), 200, () -> {
                                if (active.containsKey(entity)) {
                                    sendArmorStandSpawn(players, stand);
                                    updateArmorStand(stand);
                                    loaded.put(entity, true);
                                }
                            });
                        }
                    }
                }
            } else if (entity instanceof Item) {
                Item item = (Item) entity;
                if (PlayerLocationManager.hasPlayerNearby(item.getLocation())) {
                    if (entry.getValue()) {
                        Collection<Player> players = active.get(entity);
                        if (players != null) {
                            if (item.getVelocity().equals(VECTOR_ZERO) && !item.hasGravity()) {
                                updateItemAsync(item, true);
                            }
                            SyncUtils.runAsyncWithSyncCondition(() -> LocationUtils.isLoaded(item.getLocation()) && isOccluding(item.getLocation().getBlock().getType()), 200, () -> {
                                if (active.containsKey(entity)) {
                                    removeItem(InteractionVisualizerAPI.getPlayers(), item, false, false);
                                    loaded.put(entity, false);
                                }
                            });
                        }
                    } else {
                        Collection<Player> players = active.get(entity);
                        if (players != null) {
                            SyncUtils.runAsyncWithSyncCondition(() -> LocationUtils.isLoaded(item.getLocation()) && !isOccluding(item.getLocation().getBlock().getType()), 200, () -> {
                                if (active.containsKey(entity)) {
                                    sendItemSpawn(players, item);
                                    updateItem(item);
                                    loaded.put(entity, true);
                                }
                            });
                        }
                    }
                }
            } else if (entity instanceof ItemFrame) {
                ItemFrame frame = (ItemFrame) entity;
                if (PlayerLocationManager.hasPlayerNearby(frame.getLocation())) {
                    if (entry.getValue()) {
                        Collection<Player> players = active.get(entity);
                        if (players != null) {
                            SyncUtils.runAsyncWithSyncCondition(() -> LocationUtils.isLoaded(frame.getLocation()) && isOccluding(frame.getLocation().getBlock().getType()), 200, () -> {
                                if (active.containsKey(entity)) {
                                    removeItemFrame(InteractionVisualizerAPI.getPlayers(), frame, false, false);
                                    loaded.put(entity, false);
                                }
                            });
                        }
                    } else {
                        Collection<Player> players = active.get(entity);
                        if (players != null) {
                            SyncUtils.runAsyncWithSyncCondition(() -> LocationUtils.isLoaded(frame.getLocation()) && !isOccluding(frame.getLocation().getBlock().getType()), 200, () -> {
                                if (active.containsKey(entity)) {
                                    sendItemFrameSpawn(players, frame);
                                    updateItemFrame(frame);
                                    loaded.put(entity, true);
                                }
                            });
                        }
                    }
                }
            }
        }
        try {
            TimeUnit.MILLISECONDS.sleep(5);
        } catch (InterruptedException e) {
        }
        run();
    });
}
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)

Example 43 with Item

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

the class CraftingTableDisplay method onCraft.

@EventHandler(priority = EventPriority.MONITOR)
public void onCraft(InventoryClickEvent event) {
    if (event.isCancelled()) {
        return;
    }
    if (VanishUtils.isVanished((Player) event.getWhoClicked())) {
        return;
    }
    if (event.getRawSlot() != 0) {
        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(0).getType())) {
            return;
        }
    }
    if (event.getAction().equals(InventoryAction.HOTBAR_MOVE_AND_READD)) {
        int button = event.getHotbarButton();
        if (button < 0 || (event.getWhoClicked().getInventory().getItem(button) != null && !event.getWhoClicked().getInventory().getItem(button).getType().equals(Material.AIR))) {
            return;
        }
    }
    if (!playermap.containsKey((Player) event.getWhoClicked())) {
        return;
    }
    Block block = playermap.get((Player) event.getWhoClicked());
    if (!openedBenches.containsKey(block)) {
        return;
    }
    Map<String, Object> map = openedBenches.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("0") instanceof String) {
        map.put("0", new Item(block.getLocation().clone().add(0.5, 1.2, 0.5)));
    }
    Item item = (Item) map.get("0");
    ArmorStand slot1 = (ArmorStand) map.get("1");
    ArmorStand slot2 = (ArmorStand) map.get("2");
    ArmorStand slot3 = (ArmorStand) map.get("3");
    ArmorStand slot4 = (ArmorStand) map.get("4");
    ArmorStand slot5 = (ArmorStand) map.get("5");
    ArmorStand slot6 = (ArmorStand) map.get("6");
    ArmorStand slot7 = (ArmorStand) map.get("7");
    ArmorStand slot8 = (ArmorStand) map.get("8");
    ArmorStand slot9 = (ArmorStand) map.get("9");
    Inventory before = Bukkit.createInventory(null, 9);
    for (int i = 1; i < 10; i++) {
        before.setItem(i - 1, player.getOpenInventory().getItem(i).clone());
    }
    Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> {
        Inventory after = Bukkit.createInventory(null, 9);
        for (int i = 1; i < 10; i++) {
            after.setItem(i - 1, player.getOpenInventory().getItem(i).clone());
        }
        if (InventoryUtils.compareContents(before, after)) {
            return;
        }
        item.setLocked(true);
        slot1.setLocked(true);
        slot2.setLocked(true);
        slot3.setLocked(true);
        slot4.setLocked(true);
        slot5.setLocked(true);
        slot6.setLocked(true);
        slot7.setLocked(true);
        slot8.setLocked(true);
        slot9.setLocked(true);
        openedBenches.remove(block);
        float yaw = getCardinalDirection(player);
        Vector vector = new Location(slot8.getWorld(), slot8.getLocation().getX(), slot8.getLocation().getY(), slot8.getLocation().getZ(), yaw, 0).getDirection().normalize();
        slot1.teleport(slot1.getLocation().add(rotateVectorAroundY(vector.clone(), 135).multiply(0.2828)));
        slot2.teleport(slot2.getLocation().add(rotateVectorAroundY(vector.clone(), 180).multiply(0.2)));
        slot3.teleport(slot3.getLocation().add(rotateVectorAroundY(vector.clone(), 225).multiply(0.2828)));
        slot4.teleport(slot4.getLocation().add(rotateVectorAroundY(vector.clone(), 90).multiply(0.2)));
        slot6.teleport(slot6.getLocation().add(rotateVectorAroundY(vector.clone(), -90).multiply(0.2)));
        slot7.teleport(slot7.getLocation().add(rotateVectorAroundY(vector.clone(), 45).multiply(0.2828)));
        slot8.teleport(slot8.getLocation().add(vector.clone().multiply(0.2)));
        slot9.teleport(slot9.getLocation().add(rotateVectorAroundY(vector.clone(), -45).multiply(0.2828)));
        PacketManager.updateArmorStand(slot1);
        PacketManager.updateArmorStand(slot2);
        PacketManager.updateArmorStand(slot3);
        PacketManager.updateArmorStand(slot4);
        PacketManager.updateArmorStand(slot5);
        PacketManager.updateArmorStand(slot6);
        PacketManager.updateArmorStand(slot7);
        PacketManager.updateArmorStand(slot8);
        PacketManager.updateArmorStand(slot9);
        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(), slot1);
                PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), slot2);
                PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), slot3);
                PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), slot4);
                PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), slot5);
                PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), slot6);
                PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), slot7);
                PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), slot8);
                PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), slot9);
                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) CraftingInventory(org.bukkit.inventory.CraftingInventory) Inventory(org.bukkit.inventory.Inventory) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 44 with Item

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

the class CraftingTableDisplay method run.

@Override
public int run() {
    return new BukkitRunnable() {

        public void run() {
            Iterator<Block> itr = openedBenches.keySet().iterator();
            int count = 0;
            int maxper = (int) Math.ceil((double) openedBenches.size() / (double) 5);
            int delay = 1;
            while (itr.hasNext()) {
                count++;
                if (count > maxper) {
                    count = 0;
                    delay++;
                }
                Block block = itr.next();
                new BukkitRunnable() {

                    public void run() {
                        if (!openedBenches.containsKey(block)) {
                            return;
                        }
                        Map<String, Object> map = openedBenches.get(block);
                        Player player = (Player) map.get("Player");
                        if (!player.getGameMode().equals(GameMode.SPECTATOR)) {
                            if (player.getOpenInventory() != null) {
                                if (player.getOpenInventory().getTopInventory() != null) {
                                    if (!InteractionVisualizer.version.isLegacy()) {
                                        if (!InteractionVisualizer.version.equals(MCVersion.V1_13) && !InteractionVisualizer.version.equals(MCVersion.V1_13_1)) {
                                            if (player.getOpenInventory().getTopInventory().getLocation().getBlock().getType().toString().equalsIgnoreCase("CRAFTING_TABLE")) {
                                                return;
                                            }
                                        } else {
                                            if (player.getOpenInventory().getTopInventory() instanceof CraftingInventory) {
                                                if (((CraftingInventory) player.getOpenInventory().getTopInventory()).getMatrix().length == 9) {
                                                    return;
                                                }
                                            }
                                        }
                                    } else {
                                        if (player.getOpenInventory().getTopInventory() instanceof CraftingInventory) {
                                            if (((CraftingInventory) player.getOpenInventory().getTopInventory()).getMatrix().length == 9) {
                                                return;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        for (int i = 0; i <= 9; i++) {
                            if (!(map.get(String.valueOf(i)) instanceof String)) {
                                Object entity = map.get(String.valueOf(i));
                                if (i == 5) {
                                    InteractionVisualizer.lightManager.deleteLight(((ArmorStand) entity).getLocation());
                                }
                                if (entity instanceof Item) {
                                    PacketManager.removeItem(InteractionVisualizerAPI.getPlayers(), (Item) entity);
                                } else if (entity instanceof ArmorStand) {
                                    PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), (ArmorStand) entity);
                                }
                            }
                        }
                        openedBenches.remove(block);
                    }
                }.runTaskLater(InteractionVisualizer.plugin, delay);
            }
        }
    }.runTaskTimer(InteractionVisualizer.plugin, 0, 5).getTaskId();
}
Also used : CraftingInventory(org.bukkit.inventory.CraftingInventory) Item(com.loohp.interactionvisualizer.entityholders.Item) Player(org.bukkit.entity.Player) ArmorStand(com.loohp.interactionvisualizer.entityholders.ArmorStand) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Block(org.bukkit.block.Block) HashMap(java.util.HashMap) Map(java.util.Map)

Example 45 with Item

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

the class CraftingTableDisplay method onCloseCraftingBench.

@EventHandler
public void onCloseCraftingBench(InventoryCloseEvent event) {
    if (!playermap.containsKey((Player) event.getPlayer())) {
        return;
    }
    Block block = playermap.get((Player) event.getPlayer());
    if (!openedBenches.containsKey(block)) {
        return;
    }
    Map<String, Object> map = openedBenches.get(block);
    if (!map.get("Player").equals(event.getPlayer())) {
        return;
    }
    for (int i = 0; i <= 9; 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) {
                if (!((ArmorStand) entity).isLocked()) {
                    PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), (ArmorStand) entity);
                }
                int finalI = i;
                new BukkitRunnable() {

                    public void run() {
                        if (finalI == 5) {
                            InteractionVisualizer.lightManager.deleteLight(((ArmorStand) entity).getLocation());
                        }
                    }
                }.runTaskLater(InteractionVisualizer.plugin, 20);
            }
        }
    }
    openedBenches.remove(block);
    playermap.remove((Player) event.getPlayer());
}
Also used : Item(com.loohp.interactionvisualizer.entityholders.Item) Player(org.bukkit.entity.Player) ArmorStand(com.loohp.interactionvisualizer.entityholders.ArmorStand) Block(org.bukkit.block.Block) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) 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