unldenis / holoeasy

a simple and modern Java and Kotlin minecraft hologram library for 1.8-1.20.4 servers.
https://unldenis.github.io/holoeasy/
GNU Lesser General Public License v3.0
86 stars 26 forks source link

Doesn't work in 1.8.0 -1.8.8 #47

Closed Guarmanda closed 9 months ago

Guarmanda commented 9 months ago

causes this:

[09:20:36 WARN]: Exception in thread "Craft Scheduler Thread - 1"
[09:20:36 WARN]: org.apache.commons.lang.UnhandledException: Plugin LootChest v2.3.6 generated an exception while executing task 13
        at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:56)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: FieldAccessException: Field index 0 is out of bounds for length 0
        at com.comphenix.protocol.reflect.FieldAccessException.fromFormat(FieldAccessException.java:49)
        at com.comphenix.protocol.reflect.StructureModifier.write(StructureModifier.java:315)
        at org.holoeasy.ext.StructureModifierExtKt.set(StructureModifierExt.kt:6)
        at org.holoeasy.packet.spawn.SpawnPacketA$spawn$1.invoke(SpawnPacketA.kt:51)
        at org.holoeasy.packet.spawn.SpawnPacketA$spawn$1.invoke(SpawnPacketA.kt:37)
        at org.holoeasy.packet.PacketBuilderKt.packet(PacketBuilder.kt:8)
        at org.holoeasy.packet.spawn.SpawnPacketA.spawn(SpawnPacketA.kt:37)
        at org.holoeasy.line.Line.spawn(Line.kt:28)
        at org.holoeasy.line.TextLine.show(TextLine.kt:103)
        at org.holoeasy.hologram.Hologram.show(Hologram.kt:58)
        at org.holoeasy.pool.HologramPool.hologramTick$lambda$5(HologramPool.kt:112)
        at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:71)
        at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:53)
        ... 3 more
Guarmanda commented 9 months ago

As a workaround I use your old API in 1.8 lol

    private static IHologramPool pool;

    //for 1.8
    private static HologramPool pool1_8;

    private static HologramPool getPool1_8() {
        if(pool1_8 == null) {
            pool1_8 = new HologramPool((Plugin)Main.getInstance(), 1200);
        }
        return pool1_8;
    }

    private static IHologramPool getPool() {
        if(pool == null) {
            pool = HoloEasy.startPool((Plugin)Main.getInstance(), 1200);
        }
        return pool;
    }

    private Hologram hologram;
    private com.github.unldenis.hologram.Hologram hologram1_8;

    /**
     * Kills the hologram
     */
    public void remove() {
        if(Main.getVersion()>7){
            if(runnable != null) {
                runnable.cancel();
                runnable = null;
            }
            if(hologram == null && hologram1_8 == null) return;
            if(Main.getVersion()>8 && hologram!=null) {
                pool.remove(hologram.getKey());
                hologram = null;
            }
            else if(hologram1_8!=null && Main.getVersion()==8) {
                getPool1_8().remove(hologram1_8);
                hologram1_8 = null;
            }
        }
    }

    /**
     * @param name The text displayed by the hologram
     */
    public void setText(String name) {
        if(!NULL_NAME.contains(name)) {
            getHologram();
            setLine(Utils.color(name));
        }else {
            remove();
        }
    }

    /**
     * Manage hologram lines to display / change its name
     * @param name
     */
    private void setLine(String name){
        // compose a TextLine hologram
        if(Main.getVersion()>8) {
            TextLine textLine = new TextLine((Plugin)Main.getInstance(), name, null, false);
            hologram.load(textLine);
        }
        else {
            Line line = new Line((Plugin)Main.getInstance());
            com.github.unldenis.hologram.line.TextLine textLine = new com.github.unldenis.hologram.line.TextLine(line, name, null, false);
            hologram1_8.load(textLine);
        }
    }

    /**
     * @return Creates the hologram 
     */
    private Object createHologram() {
        if(Main.getVersion()>8){
            HologramKey key = new HologramKey(getPool(), chest.getName());
            hologram =  new Hologram(key, location, new TextSequentialLoader());
            return hologram;
        }
        else {
            hologram1_8 =  new com.github.unldenis.hologram.Hologram((Plugin)Main.getInstance(), location, new com.github.unldenis.hologram.line.hologram.TextSequentialLoader());
            getPool1_8().takeCareOf(hologram1_8);
            return hologram1_8;
        }

    }

    /**
     * @return The hologram
     */
    private Object getHologram() {
        if(hologram==null && hologram1_8==null) {
            createHologram();
        }
        if(Main.getVersion()>8)
            return hologram;
        else
            return hologram1_8;
    }
unldenis commented 9 months ago

Fixed in 3.1.1 .