Search in sources :

Example 21 with ArmorStand

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

the class SpawnerDisplay method spawnArmorStands.

public Map<String, ArmorStand> spawnArmorStands(Block block) {
    Map<String, ArmorStand> map = new HashMap<>();
    Location origin = block.getLocation();
    Location loc = origin.clone().add(0.5, 0.2, 0.5);
    SurroundingPlaneArmorStand slot1 = new SurroundingPlaneArmorStand(loc.clone(), 0.7, pathType);
    setStand(slot1);
    map.put("1", slot1);
    PacketManager.sendArmorStandSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.HOLOGRAM, KEY), slot1);
    return map;
}
Also used : SurroundingPlaneArmorStand(com.loohp.interactionvisualizer.entityholders.SurroundingPlaneArmorStand) ArmorStand(com.loohp.interactionvisualizer.entityholders.ArmorStand) SurroundingPlaneArmorStand(com.loohp.interactionvisualizer.entityholders.SurroundingPlaneArmorStand) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Location(org.bukkit.Location)

Example 22 with ArmorStand

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

the class SpawnerDisplay method onBreakSpawner.

@EventHandler(priority = EventPriority.MONITOR)
public void onBreakSpawner(TileEntityRemovedEvent event) {
    Block block = event.getBlock();
    if (!spawnerMap.containsKey(block)) {
        return;
    }
    Map<String, Object> map = spawnerMap.get(block);
    if (map.get("1") instanceof ArmorStand) {
        ArmorStand stand = (ArmorStand) map.get("1");
        PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), stand);
    }
    spawnerMap.remove(block);
}
Also used : SurroundingPlaneArmorStand(com.loohp.interactionvisualizer.entityholders.SurroundingPlaneArmorStand) ArmorStand(com.loohp.interactionvisualizer.entityholders.ArmorStand) Block(org.bukkit.block.Block) EventHandler(org.bukkit.event.EventHandler)

Example 23 with ArmorStand

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

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

the class EnchantmentTableAnimation method playEnchantAnimation.

@SuppressWarnings("deprecation")
private CompletableFuture<Integer> playEnchantAnimation(Map<Enchantment, Integer> enchantsToAdd, Integer expCost, ItemStack itemstack) {
    CompletableFuture<Integer> future = new CompletableFuture<>();
    if (item.isPresent() && item.get().isLocked()) {
        future.complete(PLAY_ENCHANTMENT);
        return future;
    }
    this.enchanting.set(true);
    if (!this.item.isPresent()) {
        this.item = Optional.of(new Item(location.clone().add(0.5, 1.3, 0.5)));
        PacketManager.sendItemSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMDROP, KEY), item.get());
    }
    Item item = this.item.get();
    item.setItemStack(itemstack);
    item.setGravity(false);
    item.setLocked(true);
    item.setVelocity(new Vector(0.0, 0.05, 0.0));
    PacketManager.updateItem(item);
    for (Player each : InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMDROP, KEY)) {
        each.spawnParticle(Particle.PORTAL, location.clone().add(0.5, 2.6, 0.5), 200);
    }
    Bukkit.getScheduler().runTaskLater(plugin, () -> {
        item.teleport(location.clone().add(0.5, 2.3, 0.5));
        item.setVelocity(new Vector(0, 0, 0));
        PacketManager.updateItem(item);
    }, 20);
    List<ArmorStand> stands = new LinkedList<>();
    Bukkit.getScheduler().runTaskLater(plugin, () -> {
        Location standloc = item.getLocation().add(0.0, 0.5, 0.0);
        for (Entry<Enchantment, Integer> entry : enchantsToAdd.entrySet()) {
            Enchantment ench = entry.getKey();
            int level = entry.getValue();
            String str = TranslationUtils.getEnchantment(ench);
            if (!EnchantmentTableDisplay.getTranslatableEnchantments().contains(str)) {
                str = null;
            }
            Component enchantmentName = (str == null || str.equals("")) ? ComponentFont.parseFont(LegacyComponentSerializer.legacySection().deserialize(CustomStringUtils.capitalize(ench.getName().toLowerCase().replace("_", " ")))) : Component.translatable(str);
            ArmorStand stand = new ArmorStand(standloc);
            if (ench.getMaxLevel() != 1 || level != 1) {
                enchantmentName = enchantmentName.append(ComponentFont.parseFont(LegacyComponentSerializer.legacySection().deserialize(" " + ChatColor.AQUA + RomanNumberUtils.toRoman(entry.getValue()))));
            }
            if (ench.isCursed()) {
                enchantmentName = enchantmentName.color(NamedTextColor.RED);
            } else {
                enchantmentName = enchantmentName.color(NamedTextColor.AQUA);
            }
            stand.setCustomName(enchantmentName);
            stand.setCustomNameVisible(true);
            setStand(stand);
            PacketManager.sendArmorStandSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.HOLOGRAM, KEY), stand);
            stands.add(stand);
            standloc.add(0.0, 0.3, 0.0);
        }
        ArmorStand stand = new ArmorStand(standloc);
        TranslatableComponent levelTrans = Component.translatable(TranslationUtils.getLevel(expCost));
        if (expCost != 1) {
            levelTrans = levelTrans.args(Component.text(expCost));
        }
        levelTrans = levelTrans.color(NamedTextColor.GREEN);
        stand.setCustomName(levelTrans);
        stand.setCustomNameVisible(true);
        setStand(stand);
        PacketManager.sendArmorStandSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.HOLOGRAM, KEY), stand);
        stands.add(stand);
        PacketManager.updateItem(item);
    }, 50);
    Bukkit.getScheduler().runTaskLater(plugin, () -> {
        while (!stands.isEmpty()) {
            ArmorStand stand = stands.remove(0);
            PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), stand);
        }
        item.setGravity(true);
        PacketManager.updateItem(item);
    }, 90);
    Bukkit.getScheduler().runTaskLater(plugin, () -> {
        item.teleport(location.clone().add(0.5, 1.3, 0.5));
        item.setGravity(false);
        PacketManager.updateItem(item);
        item.setLocked(false);
        future.complete(PLAY_ENCHANTMENT);
        this.enchanting.set(false);
    }, 98);
    return future;
}
Also used : Player(org.bukkit.entity.Player) LinkedList(java.util.LinkedList) Item(com.loohp.interactionvisualizer.entityholders.Item) CompletableFuture(java.util.concurrent.CompletableFuture) ArmorStand(com.loohp.interactionvisualizer.entityholders.ArmorStand) TranslatableComponent(net.kyori.adventure.text.TranslatableComponent) Enchantment(org.bukkit.enchantments.Enchantment) TranslatableComponent(net.kyori.adventure.text.TranslatableComponent) Component(net.kyori.adventure.text.Component) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 25 with ArmorStand

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

the class FurnaceDisplay method spawnArmorStands.

public Map<String, ArmorStand> spawnArmorStands(Block block) {
    Map<String, ArmorStand> map = new HashMap<>();
    Location origin = block.getLocation();
    BlockFace facing = null;
    if (!InteractionVisualizer.version.isLegacy()) {
        BlockData blockData = block.getState().getBlockData();
        facing = ((Directional) blockData).getFacing();
    } else {
        facing = LegacyFacingUtils.getFacing(block);
    }
    Location target = block.getRelative(facing).getLocation();
    Vector direction = target.toVector().subtract(origin.toVector()).multiply(0.7);
    Location loc = block.getLocation().clone().add(direction).add(0.5, 0.2, 0.5);
    ArmorStand slot1 = new ArmorStand(loc.clone());
    setStand(slot1);
    map.put("Stand", slot1);
    PacketManager.sendArmorStandSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.HOLOGRAM, KEY), slot1);
    return map;
}
Also used : ArmorStand(com.loohp.interactionvisualizer.entityholders.ArmorStand) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BlockFace(org.bukkit.block.BlockFace) BlockData(org.bukkit.block.data.BlockData) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Aggregations

ArmorStand (com.loohp.interactionvisualizer.entityholders.ArmorStand)56 Location (org.bukkit.Location)30 Block (org.bukkit.block.Block)30 HashMap (java.util.HashMap)25 Vector (org.bukkit.util.Vector)24 Item (com.loohp.interactionvisualizer.entityholders.Item)23 EventHandler (org.bukkit.event.EventHandler)23 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)16 Player (org.bukkit.entity.Player)14 BlockFace (org.bukkit.block.BlockFace)9 ItemStack (org.bukkit.inventory.ItemStack)9 BlockData (org.bukkit.block.data.BlockData)8 Directional (org.bukkit.block.data.Directional)7 SurroundingPlaneArmorStand (com.loohp.interactionvisualizer.entityholders.SurroundingPlaneArmorStand)6 InventoryView (org.bukkit.inventory.InventoryView)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 Inventory (org.bukkit.inventory.Inventory)4