Search in sources :

Example 1 with ItemFrame

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

the class CartographyTableDisplay method onCloseCartographyTable.

@EventHandler
public void onCloseCartographyTable(InventoryCloseEvent event) {
    if (!playermap.containsKey((Player) event.getPlayer())) {
        return;
    }
    Block block = playermap.get((Player) event.getPlayer());
    if (!openedCTable.containsKey(block)) {
        return;
    }
    Map<String, Object> map = openedCTable.get(block);
    if (!map.get("Player").equals(event.getPlayer())) {
        return;
    }
    if (map.get("Item") instanceof ItemFrame) {
        ItemFrame entity = (ItemFrame) map.get("Item");
        PacketManager.removeItemFrame(InteractionVisualizerAPI.getPlayers(), entity);
    }
    openedCTable.remove(block);
    playermap.remove((Player) event.getPlayer());
}
Also used : Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) ItemFrame(com.loohp.interactionvisualizer.entityholders.ItemFrame) EventHandler(org.bukkit.event.EventHandler)

Example 2 with ItemFrame

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

the class PacketManager method update.

public static void update() {
    if (!plugin.isEnabled()) {
        return;
    }
    InteractionVisualizer.asyncExecutorManager.runTaskAsynchronously(() -> {
        for (Player player : Bukkit.getOnlinePlayers()) {
            try {
                Set<VisualizerEntity> activeList = playerStatus.get(player);
                if (activeList != null) {
                    Collection<Player> playerList = new HashSet<>();
                    playerList.add(player);
                    Location playerLocation = PlayerLocationManager.getPlayerLocation(player);
                    Location playerEyeLocation = PlayerLocationManager.getPlayerEyeLocation(player);
                    for (Entry<VisualizerEntity, Collection<Player>> entry : active.entrySet()) {
                        VisualizerEntity entity = entry.getKey();
                        int range = InteractionVisualizer.playerTrackingRange.getOrDefault(entity.getWorld(), 64);
                        range *= range;
                        boolean playerActive = activeList.contains(entity);
                        boolean sameWorld = entity.getWorld().equals(playerLocation.getWorld());
                        boolean inRange = sameWorld && (entity.getLocation().distanceSquared(playerLocation) <= range);
                        Boolean hasLineOfSight = InteractionVisualizer.hideIfObstructed ? null : true;
                        boolean isLoaded = loaded.getOrDefault(entity, false);
                        Location entityCenter = entity.getLocation();
                        entityCenter.setY(entityCenter.getY() + (entity instanceof Item ? (entity.getHeight() * 1.7) : (entity.getHeight() * 0.7)));
                        if (playerActive && (!sameWorld || !inRange || !(hasLineOfSight != null ? hasLineOfSight : (hasLineOfSight = LineOfSightUtils.hasLineOfSight(playerEyeLocation, entityCenter))))) {
                            if (entity instanceof ArmorStand) {
                                ArmorStand stand = (ArmorStand) entity;
                                removeArmorStand(playerList, stand, false, true);
                            } else if (entity instanceof Item) {
                                Item item = (Item) entity;
                                removeItem(playerList, item, false, true);
                            } else if (entity instanceof ItemFrame) {
                                ItemFrame frame = (ItemFrame) entity;
                                removeItemFrame(playerList, frame, false, true);
                            }
                        } else if (!playerActive && entry.getValue().contains(player) && isLoaded && sameWorld && inRange && (hasLineOfSight != null ? hasLineOfSight : (hasLineOfSight = LineOfSightUtils.hasLineOfSight(playerEyeLocation, entityCenter)))) {
                            if (entity instanceof ArmorStand) {
                                ArmorStand stand = (ArmorStand) entity;
                                sendArmorStandSpawn(playerList, stand);
                                updateArmorStand(playerList, stand);
                            } else if (entity instanceof Item) {
                                Item item = (Item) entity;
                                sendItemSpawn(playerList, item);
                                updateItem(playerList, item);
                            } else if (entity instanceof ItemFrame) {
                                ItemFrame frame = (ItemFrame) entity;
                                sendItemFrameSpawn(playerList, frame);
                                updateItemFrame(playerList, frame);
                            }
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        try {
            TimeUnit.MILLISECONDS.sleep(5);
        } catch (InterruptedException e) {
        }
        update();
    });
}
Also used : Player(org.bukkit.entity.Player) DynamicVisualizerEntity(com.loohp.interactionvisualizer.entityholders.DynamicVisualizerEntity) VisualizerEntity(com.loohp.interactionvisualizer.entityholders.VisualizerEntity) ItemFrame(com.loohp.interactionvisualizer.entityholders.ItemFrame) Item(com.loohp.interactionvisualizer.entityholders.Item) ArmorStand(com.loohp.interactionvisualizer.entityholders.ArmorStand) Collection(java.util.Collection) HashSet(java.util.HashSet) Location(org.bukkit.Location)

Example 3 with ItemFrame

use of com.loohp.interactionvisualizer.entityholders.ItemFrame 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)

Example 4 with ItemFrame

use of com.loohp.interactionvisualizer.entityholders.ItemFrame 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 5 with ItemFrame

use of com.loohp.interactionvisualizer.entityholders.ItemFrame 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)

Aggregations

ItemFrame (com.loohp.interactionvisualizer.entityholders.ItemFrame)7 Player (org.bukkit.entity.Player)6 ArmorStand (com.loohp.interactionvisualizer.entityholders.ArmorStand)4 DynamicVisualizerEntity (com.loohp.interactionvisualizer.entityholders.DynamicVisualizerEntity)4 Item (com.loohp.interactionvisualizer.entityholders.Item)4 VisualizerEntity (com.loohp.interactionvisualizer.entityholders.VisualizerEntity)4 Collection (java.util.Collection)4 HashSet (java.util.HashSet)3 Block (org.bukkit.block.Block)3 HashMap (java.util.HashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 CartographyInventory (org.bukkit.inventory.CartographyInventory)2 Map (java.util.Map)1 Location (org.bukkit.Location)1 Entity (org.bukkit.entity.Entity)1 EventHandler (org.bukkit.event.EventHandler)1 InventoryView (org.bukkit.inventory.InventoryView)1 ItemStack (org.bukkit.inventory.ItemStack)1 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)1