Solved [1.11.2] Error using TitleAPI and BukkitScheduler in an event

Discussion in 'Spigot Plugin Development' started by Roofah, May 6, 2017.

  1. Hello! I am attempting to create a plugin for my hub server, am trying to create a title for each player as soon as they join the server. Unfortunately, I could not find a way to create titles via the Spigot API so I have resorted to a public resource known as TitleAPI(https://www.spigotmc.org/resources/titleapi-1-8-1-9-1-10-1-11.1325/). I am running into and error with the message:
    Code (Text):
    [21:41:46 ERROR]: Could not pass event PlayerJoinEvent to Hub v1.0-SNAPSHOT

    I believe I have correct syntax for the title, and the code is:
    Code (Text):
    TitleAPI.sendTitle(player, 40, 100, 20, color("&eWelcome to *******, " + player), "Visit the website: *******.com");
    Here is the entire class, in which this is included in:
    Code (Text):
    package io.Darwin.hub.titles;

    import com.connorlinfoot.titleapi.TitleAPI;
    import io.Darwin.hub.Main;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.scheduler.BukkitRunnable;

    public class JoinTitle implements Listener {

        public static String color(String t){
            return ChatColor.translateAlternateColorCodes('&', t);
        }

        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e){
            Player player = e.getPlayer();
            e.setJoinMessage(color("&8[&a+&8] &7" + player));
            TitleAPI.sendTitle(player, 40, 100, 20, color("&eWelcome to *****, " + player), "Visit the website: *******.com");
            new BukkitRunnable(){
                int seconds = 5;
                @Override
                public void run(){
                    seconds--;
                    TitleAPI.sendTitle(player, 40 , 100, 20, color("&eNew Minigame:"), color("********"));
                }
            }.runTaskTimer(new Main(), 0l, 20l);


        }

    }


    ///// The *******'s are chars, just removed because privacy
     


    To be able to call the API, the resource recommends this where player is a player, fadeIn and fadeOut are integers, and Title/Subtitle are strings:
    Code (Text):
    TitleAPI.sendTitle(player,fadeIn,stay,fadeOut,"Title","Subtitle");

    The plugin is successfully enabled on Start Up, but the following error occurs:
    Code (Text):
    [21:41:46 ERROR]: Could not pass event PlayerJoinEvent to Hub v1.0-SNAPSHOT
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-38ddb34-c19c293]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-38ddb34-c19c293]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-38ddb34-c19c293]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-38ddb34-c19c293]
            at net.minecraft.server.v1_11_R1.PlayerList.onPlayerJoin(PlayerList.java:327) [spigot.jar:git-Spigot-38ddb34-c19c293]
            at net.minecraft.server.v1_11_R1.PlayerList.a(PlayerList.java:160) [spigot.jar:git-Spigot-38ddb34-c19c293]
            at net.minecraft.server.v1_11_R1.LoginListener.b(LoginListener.java:147) [spigot.jar:git-Spigot-38ddb34-c19c293]
            at net.minecraft.server.v1_11_R1.LoginListener.F_(LoginListener.java:57) [spigot.jar:git-Spigot-38ddb34-c19c293]
            at net.minecraft.server.v1_11_R1.NetworkManager.a(NetworkManager.java:233) [spigot.jar:git-Spigot-38ddb34-c19c293]
            at net.minecraft.server.v1_11_R1.ServerConnection.c(ServerConnection.java:140) [spigot.jar:git-Spigot-38ddb34-c19c293]
            at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:842) [spigot.jar:git-Spigot-38ddb34-c19c293]
            at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:399) [spigot.jar:git-Spigot-38ddb34-c19c293]
            at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:678) [spigot.jar:git-Spigot-38ddb34-c19c293]
            at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:576) [spigot.jar:git-Spigot-38ddb34-c19c293]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_121]
    Caused by: java.lang.NoClassDefFoundError: com/connorlinfoot/titleapi/TitleAPI
            at io.Darwin.hub.titles.JoinTitle.onPlayerJoin(JoinTitle.java:25) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_121]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_121]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot.jar:git-Spigot-38ddb34-c19c293]
            ... 14 more
    Caused by: java.lang.ClassNotFoundException: com.connorlinfoot.titleapi.TitleAPI
            at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_121]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:101) ~[spigot.jar:git-Spigot-38ddb34-c19c293]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:86) ~[spigot.jar:git-Spigot-38ddb34-c19c293]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_121]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_121]
            at io.Darwin.hub.titles.JoinTitle.onPlayerJoin(JoinTitle.java:25) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_121]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_121]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot.jar:git-Spigot-38ddb34-c19c293]
            ... 14 more

    Any help would be appreciated! Thanks :)
     
  2. Actually took the time to read the error thoroughly, and the issue is on line 25 and I'm guessing it cannot find the class for the TitleAPI. Here is an image of the API in my external libraries.

    [​IMG]

    I am unsure what could have gone wrong.

    Again, thanks to anyone for the help
     
  3. You need to include the TitleAPI jar in your server's plugin directory. If it's already there, it may be broken for your version.
     
    • Informative Informative x 1
  4. Huh, I always thought it would export with it. Thanks though! Fixed my issue