Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HologramManager is null & line width is 0 #1

Closed
7FULL opened this issue Aug 4, 2023 · 40 comments
Closed

HologramManager is null & line width is 0 #1

7FULL opened this issue Aug 4, 2023 · 40 comments
Assignees
Labels
bug Something isn't working

Comments

@7FULL
Copy link

7FULL commented Aug 4, 2023

``@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();

    //Para que no salga cuando se une un jugador
    event.setJoinMessage("");

    TextHologram hologram = new TextHologram(player.getUniqueId().toString())
            .setText(ChatColor.AQUA + "Hello world!")
            .addLine(ChatColor.RED + "Second line")
            .addLine("Third line")
            .addLine("Another line...") // You can add as many lines as you want
            .setBillboard(Display.Billboard.CENTER)
            .setTextShadow(true)
            .setBackgroundColor(Color.fromARGB(0/*Opacity*/, 255/*Red*/, 236/*Green*/, 222/*Blue*/)) // You can use the https://htmlcolorcodes.com/color-picker/ to get the RGB color you want!
            .spawn(player.getLocation().add(0, 2, 0));

    hologramManager = HologramAPI.getHologramManager();
}

//Jugador se va del servidor
@EventHandler
public void onPlayerLeave(PlayerQuitEvent event) {
    Player player = event.getPlayer();

    hologramManager.removeAll(player.getUniqueId().toString());
}
``
@7FULL
Copy link
Author

7FULL commented Aug 4, 2023

Caused by: java.lang.NullPointerException: Cannot invoke "com.maximfiedler.hologramapi.hologram.HologramManager.removeAll(String)" because "this.hologramManager" is null
at com.prueba.prueba.listeners.PlayerListeners.onPlayerLeave(PlayerListeners.java:62) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-api-1.19.4-R0.1-SNAPSHOT.jar:?]

@max1mde
Copy link
Owner

max1mde commented Aug 4, 2023

So you have a global variable hologramManager right? Are you sure that first someone joined (to initilize the hologramManager variable) before someone left?
You can just init that variable on the top because the plugin is anyways loaded after the api...
private HologramManager hologramManager = HologramAPI.getHologramManager(); (on top)
Also add HologramAPI to your plugin.yml (depend: [HologramAPI]) and make sure that you have also uploaded the plugin jar from the releases or spigotmc on to your server.

@max1mde
Copy link
Owner

max1mde commented Aug 4, 2023

image

@max1mde
Copy link
Owner

max1mde commented Aug 4, 2023

I described how to do everything in the wiki
https://github.com/MaximFiedler/HologramAPI/wiki

@7FULL
Copy link
Author

7FULL commented Aug 4, 2023

I have It all. The plugon the dependency, all. The holograma is shown whe Simeone joins but when Simeone leaves It tells that. Sorry for my english btw im fron Spain

@max1mde
Copy link
Owner

max1mde commented Aug 4, 2023

And are you sure that you did not compile the api directly into your plugin (for example by using the shadow plugin)? You can open the .jar using winrar for example and look you have there a com package which contains a maximfiedler packages and if so remove it. Can you maybe also show me your pom or build.gradle file?

Reason why this is a problem:
If you use the TextHologram class there is no problem because you create a new Instance of that class
But if you use the HologramAPI.getHologramManager() method and it uses the code in your jar it will return null
because its inizilized in the onEnable() method which gets only called if it only runs on the server thats why you need to use the data from the plugin
instead of the code in the jar so look that you only compile your plugin with the api but the jar should not contain the code of the hologram api

@max1mde
Copy link
Owner

max1mde commented Aug 4, 2023

You can also take a look at my example plugin which uses the hologram api
https://github.com/MaximFiedler/ExampleHologramPlugin

@max1mde max1mde self-assigned this Aug 4, 2023
@max1mde
Copy link
Owner

max1mde commented Aug 4, 2023

If you want i can add a check to the getter method and initilize the hologram api variable if its null even without the onEnable
So after that it should work without removing it from the jar

But the animations will still not work because they need the plugin instance

@max1mde
Copy link
Owner

max1mde commented Aug 4, 2023

I have It all. The plugon the dependency, all. The holograma is shown whe Simeone joins but when Simeone leaves It tells that. Sorry for my english btw im fron Spain

If thats to complicated you can maybe just sent me your pom.xml file or build.gradle file and i can take a look

@max1mde
Copy link
Owner

max1mde commented Aug 4, 2023

¿Todavía estás aquí? Creo que tengo una solución para ti: Actualiza a la última versión de la api (1.1.4) en pom.xml o build.gradle o actualiza el jar que usas como librería en tu IDE/editor de código y elimina el plugin hologramapi de tu servidor.

@7FULL
Copy link
Author

7FULL commented Aug 4, 2023

Than you so much for the effort or answering me Ill be back home in 20 min and Ill let you know

@7FULL
Copy link
Author

7FULL commented Aug 4, 2023

Code:
` HologramManager hologramManager = HologramAPI.getHologramManager();

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
    Player player = event.getPlayer();

    //Para que no salga cuando se une un jugador
    event.setJoinMessage("");

    TextHologram hologram = new TextHologram(player.getUniqueId().toString())
            .setText(ChatColor.AQUA + "Hello world!")
            .addLine(ChatColor.RED + "Second line")
            .addLine("Third line")
            .addLine("Another line...") // You can add as many lines as you want
            .setBillboard(Display.Billboard.VERTICAL)
            .setTextShadow(true)
            .setBackgroundColor(Color.fromARGB(0/*Opacity*/, 255/*Red*/, 236/*Green*/, 222/*Blue*/)) // You can use the https://htmlcolorcodes.com/color-picker/ to get the RGB color you want!
            .spawn(player.getLocation().add(0, 2, 0));

    player.sendMessage("Hola " + player.getName());

    if (player.hasPlayedBefore()){
        //Displayname basicamente es el nombre que se muestra en el chat pero puede que haya sido personalizado
        player.sendMessage("Bienvenido de nuevo " + player.getDisplayName());
    } else {
        player.sendMessage("Bienvenido por primera vez");
    }
}

//Jugador se va del servidor
@EventHandler
public void onPlayerLeave(PlayerQuitEvent event) {
    Player player = event.getPlayer();

    System.out.println("Adios " + player.getName());

    event.setQuitMessage("");

    player.sendMessage("Adios " + player.getName());

    hologramManager.removeAll(player.getUniqueId().toString());
}`

Pom.xml
`

4.0.0

<groupId>com.prueba</groupId>
<artifactId>Prueba</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Prueba</name>

<properties>
    <java.version>16</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
    <plugins>
        <!-- Configuración del plugin maven-compiler-plugin para compilar el código fuente -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>16</source>
                <target>16</target>
            </configuration>
        </plugin>

        <!-- Configuración del plugin maven-shade-plugin para crear un JAR sombreado (shaded JAR) -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.2.4</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <createDependencyReducedPom>false</createDependencyReducedPom>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <!-- Configuración del plugin maven-resources-plugin para copiar el JAR generado -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <id>copy-plugin</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <!-- Aquí se define la carpeta de destino, reemplaza la ruta a tu carpeta de plugins -->
                        <outputDirectory>C:/Users/phgfu/staff/MCServers/1.19.4/plugins</outputDirectory>
                        <resources>
                            <resource>
                                <!-- El archivo JAR generado se copiará a la carpeta de destino con el mismo nombre -->
                                <directory>${project.build.directory}</directory>
                                <includes>
                                    <include>Prueba-1.0-SNAPSHOT.jar</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

<repositories>
    <repository>
        <id>spigotmc-repo</id>
        <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
    </repository>
    <repository>
        <id>sonatype</id>
        <url>https://oss.sonatype.org/content/groups/public/</url>
    </repository>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>org.spigotmc</groupId>
        <artifactId>spigot-api</artifactId>
        <version>1.19.4-R0.1-SNAPSHOT</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.github.MaximFiedler</groupId>
        <artifactId>HologramAPI</artifactId>
        <version>1.1.4</version>
    </dependency>
</dependencies>

`

Error:
org.bukkit.event.EventException: null at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-api-1.19.4-R0.1-SNAPSHOT.jar:?] at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[spigot-api-1.19.4-R0.1-SNAPSHOT.jar:?] at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:589) ~[spigot-api-1.19.4-R0.1-SNAPSHOT.jar:?] at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:576) ~[spigot-api-1.19.4-R0.1-SNAPSHOT.jar:?] at net.minecraft.server.players.PlayerList.remove(PlayerList.java:521) ~[spigot-1.19.4-R0.1-SNAPSHOT.jar:3763-Spigot-7d7b241-5a5e43e] at net.minecraft.server.network.PlayerConnection.a(PlayerConnection.java:1790) ~[spigot-1.19.4-R0.1-SNAPSHOT.jar:3763-Spigot-7d7b241-5a5e43e] at net.minecraft.network.NetworkManager.m(NetworkManager.java:444) ~[spigot-1.19.4-R0.1-SNAPSHOT.jar:3763-Spigot-7d7b241-5a5e43e] at net.minecraft.server.network.ServerConnection.c(ServerConnection.java:195) ~[spigot-1.19.4-R0.1-SNAPSHOT.jar:3763-Spigot-7d7b241-5a5e43e] at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1326) ~[spigot-1.19.4-R0.1-SNAPSHOT.jar:3763-Spigot-7d7b241-5a5e43e] at net.minecraft.server.dedicated.DedicatedServer.b(DedicatedServer.java:388) ~[spigot-1.19.4-R0.1-SNAPSHOT.jar:3763-Spigot-7d7b241-5a5e43e] at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:1200) ~[spigot-1.19.4-R0.1-SNAPSHOT.jar:3763-Spigot-7d7b241-5a5e43e] at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:1017) ~[spigot-1.19.4-R0.1-SNAPSHOT.jar:3763-Spigot-7d7b241-5a5e43e] at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:304) ~[spigot-1.19.4-R0.1-SNAPSHOT.jar:3763-Spigot-7d7b241-5a5e43e] at java.lang.Thread.run(Thread.java:833) ~[?:?] Caused by: java.lang.NullPointerException: Cannot invoke "com.maximfiedler.hologramapi.hologram.HologramManager.removeAll(String)" because "this.hologramManager" is null at com.prueba.prueba.listeners.PlayerListeners.onPlayerLeave(PlayerListeners.java:60) ~[?:?] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-api-1.19.4-R0.1-SNAPSHOT.jar:?] ... 13 more

@7FULL
Copy link
Author

7FULL commented Aug 4, 2023

Btw with that code I see them like this
2023-08-04_14 02 47

Forgot to mention when compiling this appears in console

image

@max1mde
Copy link
Owner

max1mde commented Aug 4, 2023

Ok one moment please i need to read and understand everything first...

@7FULL
Copy link
Author

7FULL commented Aug 4, 2023

Sorry

@max1mde
Copy link
Owner

max1mde commented Aug 4, 2023

Okay so... you use the shade plugin you just need to exclude my api from it

@max1mde
Copy link
Owner

max1mde commented Aug 4, 2023

image

@max1mde
Copy link
Owner

max1mde commented Aug 4, 2023

<createDependencyReducedPom>false</createDependencyReducedPom>
<artifactSet>
    <excludes>
        <!-- Exclude HologramAPI from shading -->
        <exclude>com.github.MaximFiedler:HologramAPI</exclude>
    </excludes>
</artifactSet>

put this into the < configuration > tag

@max1mde
Copy link
Owner

max1mde commented Aug 4, 2023

Also if you already removed the hologramapi plugin jar from your server add it again

@max1mde
Copy link
Owner

max1mde commented Aug 4, 2023

Here is the full edited pom.xml (I did not tested it so if there is a problem tell me)

<groupId>com.prueba</groupId>
<artifactId>Prueba</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Prueba</name>

<properties>
    <java.version>16</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
    <plugins>
        <!-- Configuración del plugin maven-compiler-plugin para compilar el código fuente -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>16</source>
                <target>16</target>
            </configuration>
        </plugin>

        <!-- Configuración del plugin maven-shade-plugin para crear un JAR sombreado (shaded JAR) -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.2.4</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <createDependencyReducedPom>false</createDependencyReducedPom>
                        <artifactSet>
                            <excludes>
                                <!-- Exclude HologramAPI from shading -->
                                <exclude>com.github.MaximFiedler:HologramAPI</exclude>
                            </excludes>
                        </artifactSet>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <!-- Configuración del plugin maven-resources-plugin para copiar el JAR generado -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <id>copy-plugin</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <!-- Aquí se define la carpeta de destino, reemplaza la ruta a tu carpeta de plugins -->
                        <outputDirectory>C:/Users/phgfu/staff/MCServers/1.19.4/plugins</outputDirectory>
                        <resources>
                            <resource>
                                <!-- El archivo JAR generado se copiará a la carpeta de destino con el mismo nombre -->
                                <directory>${project.build.directory}</directory>
                                <includes>
                                    <include>Prueba-1.0-SNAPSHOT.jar</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

<repositories>
    <repository>
        <id>spigotmc-repo</id>
        <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
    </repository>
    <repository>
        <id>sonatype</id>
        <url>https://oss.sonatype.org/content/groups/public/</url>
    </repository>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>org.spigotmc</groupId>
        <artifactId>spigot-api</artifactId>
        <version>1.19.4-R0.1-SNAPSHOT</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.github.MaximFiedler</groupId>
        <artifactId>HologramAPI</artifactId>
        <version>1.1.4</version>
    </dependency>
</dependencies>

@7FULL
Copy link
Author

7FULL commented Aug 4, 2023

WORKS PERFECTLY!!!! Thank you so much and excuse me for bothering you. Btw any idea why they look like that?

@max1mde
Copy link
Owner

max1mde commented Aug 4, 2023

No problem! Actually i dont know why they look like that... which client are you using? Can you add this line after the hologram creation for debugging in the join event? player.sendMessage(hologram.getText()); and show me that message?

@7FULL
Copy link
Author

7FULL commented Aug 4, 2023

image

@max1mde
Copy link
Owner

max1mde commented Aug 4, 2023

Thats how it should look... can i join your server maybe and look by myself?

@max1mde
Copy link
Owner

max1mde commented Aug 4, 2023

Like how the holograms are there using my client

@max1mde
Copy link
Owner

max1mde commented Aug 4, 2023

Or can you stand nearby a hologram (max 2 blocks away) and use this command: /data get entity @e[type=minecraft:text_display,distance=..2,limit=1]

@7FULL
Copy link
Author

7FULL commented Aug 4, 2023

It is running in localhost how do I change the ip

@7FULL
Copy link
Author

7FULL commented Aug 4, 2023

image

It doesnt found the entity

@max1mde
Copy link
Owner

max1mde commented Aug 4, 2023

image

Increase the distance in the command from 2 to like 10

@max1mde
Copy link
Owner

max1mde commented Aug 4, 2023

/data get entity @e[type=minecraft:text_display,distance=..10,limit=1]

@max1mde
Copy link
Owner

max1mde commented Aug 4, 2023

It is running in localhost how do I change the ip

You can use ngrok (port tunnel), open the port on the router or find a host/rent or buy a root, v or dedicated server.. But you dont have to do that I just thought the server is already public that's why I asked

@max1mde
Copy link
Owner

max1mde commented Aug 4, 2023

I mean i could host the server for you as long as i still have server capacity in surplus (but it would be a bit complicated i would need to give you access in some way)

@7FULL
Copy link
Author

7FULL commented Aug 4, 2023

image

If you need the server anyways after this Ill do it

image

@max1mde
Copy link
Owner

max1mde commented Aug 4, 2023

I will try to solve this problem tomorrow then I come back here again

@max1mde
Copy link
Owner

max1mde commented Aug 6, 2023

I think i have found the problem...
image
In the screenshot you have sent me the line width is set to 0 and if i spawn such a display manually it looks like your display.
On the left a display with the line width of 0 and on the right side a display with the line width of 200
image

@max1mde
Copy link
Owner

max1mde commented Aug 6, 2023

Add this line to your code:
.setLineWidth(200)

Or

hologram.setLineWidth(200);
hologram.update();

Also use /version HologramAPI and check the version of the plugin
if its not 1.1.4 update it.

@max1mde max1mde changed the title HologramManeger null HologramManager is null & line width is 0 Aug 6, 2023
@7FULL
Copy link
Author

7FULL commented Aug 6, 2023

Still the same and it is 1.1.4

@max1mde
Copy link
Owner

max1mde commented Aug 6, 2023

Can you share the code for spawning the hologram again?

@7FULL
Copy link
Author

7FULL commented Aug 6, 2023

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
    Player player = event.getPlayer();

    //Para que no salga cuando se une un jugador

    // Create the event here
    CustomEvent customEvent = new CustomEvent("Sample Message");
    // Call the event
    Bukkit.getServer().getPluginManager().callEvent(customEvent);
    // Now you do the event
    Bukkit.getServer().broadcastMessage(customEvent.getMessage());

    event.setJoinMessage("");

    ScoreboardManager manager = Bukkit.getScoreboardManager();
    Scoreboard scoreboard = manager.getNewScoreboard();

    Objective objective = scoreboard.registerNewObjective("Title", "dummy");
    objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    objective.setDisplayName(ChatColor.BLUE + "Scoreboard Title");

    Score score = objective.getScore(ChatColor.GOLD + "Money: $" + ChatColor.GREEN + 1); //create a line for the board
    Score s2 = objective.getScore(""); //blank space
    Score s3 = objective.getScore(ChatColor.DARK_PURPLE + "https://google.com");

    score.setScore(3);
    s2.setScore(2);
    s3.setScore(1);
    s2.setScore(0);

    player.setScoreboard(scoreboard);


    TextHologram hologram = new TextHologram(player.getUniqueId().toString())
            .setText(ChatColor.AQUA + "Hello world!")
            .addLine(ChatColor.RED + "Second line")
            .addLine("Third line")
            .addLine("Another line...") // You can add as many lines as you want
            .setBillboard(Display.Billboard.VERTICAL)
            .setTextShadow(true)
            .setBackgroundColor(Color.fromARGB(0/*Opacity*/, 255/*Red*/, 236/*Green*/, 222/*Blue*/)) // You can use the https://htmlcolorcodes.com/color-picker/ to get the RGB color you want!
            .spawn(player.getLocation().add(0, 2, 0))
            .setLineWidth(200);

    player.sendMessage(hologram.getText());

    player.sendMessage("Hola " + player.getName());

    if (player.hasPlayedBefore()){
        //Displayname basicamente es el nombre que se muestra en el chat pero puede que haya sido personalizado
        player.sendMessage("Bienvenido de nuevo " + player.getDisplayName());
    } else {
        player.sendMessage("Bienvenido por primera vez");
    }
}

@max1mde
Copy link
Owner

max1mde commented Aug 6, 2023

You need to set the line width before the spawn method call
because otherwise it will not be updated anymore unless you call the .update() method

.setLineWidth(200)
.spawn(player.getLocation().add(0, 2, 0));

@max1mde max1mde closed this as completed Mar 19, 2024
@max1mde max1mde added the bug Something isn't working label Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants