Am I being stupid here? Events not firing.

Discussion in 'Spigot Plugin Development' started by SamB440, May 29, 2016.

Thread Status:
Not open for further replies.
  1. Today I ran into an issue where my events will not fire. Seems to work on other plugins fine, so I can't seem to work out the issue here!

    I've registered my events.

    No errors are shown in console, and my debuggers for the playerjoinevent don't fire.
    Code (Text):
    package me.SamB440.NewsBoat;

    import java.util.logging.Logger;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin implements Listener {
        private static final Logger log = Logger.getLogger("Minecraft");
     
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)this);
            log.info("[NewsBoat] Enabled.");
            log.info("Done!");
        }
     
        public void onDisable() {
            log.info("[NewsBoat] Disabled.");
        }
     
        public void onJoin(PlayerJoinEvent j) {
            log.info("TEST");
            final Player p = j.getPlayer();
            p.sendMessage("Debug");
            TitleManager.sendTitle(p, ChatColor.AQUA + "" + ChatColor.UNDERLINE + "IslandEarth", ChatColor.RED + "" + ChatColor.BOLD + "SETTLERS " + ChatColor.RED + "beta 1.0", 140);
            TitleManager.sendActionBar(p, ChatColor.AQUA + "" + ChatColor.BOLD + "TIP " + ChatColor.WHITE + ChatColor.BOLD + ">> " + ChatColor.RED + "Complete missions to gain advantage over other players! Go to" + ChatColor.GREEN + "Menu" + ChatColor.WHITE + " > " + ChatColor.GREEN + "Missions.");
         
            Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
                @Override
                public void run() {
                    TitleManager.sendTitle(p, ChatColor.GREEN + "" + ChatColor.UNDERLINE + "New Storehouses", ChatColor.RED + "Levels 1 > 3", 140);
                    TitleManager.sendActionBar(p, ChatColor.AQUA + "" + ChatColor.BOLD + "TIP " + ChatColor.WHITE + ChatColor.BOLD + ">> " + ChatColor.RED + "Claim all your land otherwise players will raid you!");
            }
        }, 150L);
         
            Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
                @Override
                public void run() {
                    TitleManager.sendActionBar(p, "");
                    p.sendMessage(ChatColor.AQUA + "DEBUG" + ChatColor.WHITE + ChatColor.BOLD + " >> " + ChatColor.RED + "Cycle complete.");
                    return;
            }
        }, 300L);
         
        }

    }
     
    Code (Text):
    package me.SamB440.NewsBoat;

    import net.minecraft.server.v1_9_R2.IChatBaseComponent;
    import net.minecraft.server.v1_9_R2.Packet;
    import net.minecraft.server.v1_9_R2.PacketPlayOutChat;
    import net.minecraft.server.v1_9_R2.PacketPlayOutTitle;

    import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
    import org.bukkit.entity.Player;

    public class TitleManager {
        @SuppressWarnings("rawtypes")
        public static void sendTitle(Player player, String msgTitle, String msgSubTitle, int ticks) {
            IChatBaseComponent chatTitle = IChatBaseComponent.ChatSerializer.a((String)("{\"text\": \"" + msgTitle + "\"}"));
            IChatBaseComponent chatSubTitle = IChatBaseComponent.ChatSerializer.a((String)("{\"text\": \"" + msgSubTitle + "\"}"));
            PacketPlayOutTitle p = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TITLE, chatTitle);
            PacketPlayOutTitle p2 = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.SUBTITLE, chatSubTitle);
            ((CraftPlayer)player).getHandle().playerConnection.sendPacket((Packet)p);
            ((CraftPlayer)player).getHandle().playerConnection.sendPacket((Packet)p2);
            TitleManager.sendTime(player, ticks);
        }

        @SuppressWarnings("rawtypes")
        private static void sendTime(Player player, int ticks) {
            PacketPlayOutTitle p = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TIMES, null, 20, ticks, 20);
            ((CraftPlayer)player).getHandle().playerConnection.sendPacket((Packet)p);
        }

        @SuppressWarnings("rawtypes")
        public static void sendActionBar(Player player, String message) {
            IChatBaseComponent cbc = IChatBaseComponent.ChatSerializer.a((String)("{\"text\": \"" + message + "\"}"));
            PacketPlayOutChat ppoc = new PacketPlayOutChat(cbc, (byte) 2);
            ((CraftPlayer)player).getHandle().playerConnection.sendPacket((Packet)ppoc);
        }
    }
    [/TitleManager]

    Am I just being stupid or something. Any help appreciated, thanks.
     
  2. Above your onJoin method you forgot to add @EventHandler
     
  3. .. Thanks I'm the most stupid person ever.
     
Thread Status:
Not open for further replies.