lucko / helper

A collection of utilities and extended APIs to support the rapid and easy development of Bukkit plugins.
MIT License
456 stars 87 forks source link

Expose Hologram ArmorStands #74

Closed FerusGrim closed 4 years ago

FerusGrim commented 4 years ago

Currently, setClickCallback doesn't work (at least for BukkitHologramFactory.BukkitHologram).

I'm going to be making a PR soon which will fix this, but for now, this is part of my hotfix, as I needed something quicker than I could implement the fix.

Before

    private static final Field SPAWNED_ENTITIES_FIELD;
    static {
        Field spawnedEntitiesField = null;
        try {
            Class<?> clazz = Class.forName("me.lucko.helper.hologram.BukkitHologramFactory$BukkitHologram");
            spawnedEntitiesField = clazz.getDeclaredField("spawnedEntities");
            spawnedEntitiesField.setAccessible(true);
        } catch (Throwable e) {
            e.printStackTrace();
        }
        SPAWNED_ENTITIES_FIELD = spawnedEntitiesField;
    }

    private List<UUID> getHologramEntityIds(Hologram hologram) {
        try {
            return ((List<ArmorStand>) SPAWNED_ENTITIES_FIELD.get(hologram)).stream()
                    .map(Entity::getUniqueId)
                    .collect(Collectors.toList());
        } catch (IllegalAccessException e) {
            e.printStackTrace();
            return Lists.newArrayList();
        }
    }

After

    private List<UUID> getHologramEntityIds(Hologram hologram) {
        return hologram.getArmorStands().stream()
                .map(Entity::getUniqueId)
                .collect(Collectors.toList());
    }