title

Discussion in 'Plugin Development' started by jarnedeclercq, Feb 9, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    jarnedeclercq

    hello!

    i want to something in my plugin that shows up a title if you join.
    I came up with an idea but it didnt work anny help?


    Code:
    public class PlayerJoin implements Listener {
        private JDCplugin plugin;
    
        public PlayerJoin(JDCplugin pl) {
            plugin = pl;
        }
    
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
         
            sendTitle(player, "Title", "subtitle", 10, 20, 10);
    
    }
    } 
    no hate plz im a beginner



    before i had something that worked but only the other players got the title
    and i want that only the player that joins a title has like mineplex.

    ty
     
    Last edited by a moderator: Feb 10, 2017
  2. Offline

    JanTuck

    Player#sendTitle?

    Sendt fra min ALE-L21 med Tapatalk
     
  3. Offline

    DoggyCode™

    Did you register the listener? Can we see the sendTitle method? Any errors? If it worked before, then the only thing I can see is the problem is the listener not being registered with Bukkit.getPluginManager().registerListeners


    Sent from my iPhone using Tapatalk
     
  4. Offline

    Zombie_Striker

  5. Offline

    jarnedeclercq

    never mind it is not working xD

    Code:
    package com.jdc6910169.events;
    
    import org.bukkit.Bukkit;
    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;
    
    import com.jdc6910169.JDCplugin;
    
    public class PlayerJoin extends BukkitRunnable implements Listener  {
        private JDCplugin plugin;
        private Player player;
    
        public PlayerJoin(JDCplugin pl) {
            plugin = pl;
        }
    
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
            player = event.getPlayer();
            run();
    
    
    }
    
        @Override
        public void run() {
            // TODO Auto-generated method stub
            Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "title" + player.getName() + "title [{\"text\":\"Blah blah\",\"color\":\"gold\"}]");
            plugin.getServer().broadcastMessage(ChatColor.DARK_GREEN + player.getName() + " has joined the server!");
        }
    }

    thats the code i dont know why it is not working i thougt it was easyer to do the title thisway

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Feb 10, 2017
  6. Offline

    Zombie_Striker

    @jarnedeclercq
    Why are you dispatching a command? Why not use Player#sendTitle() like I recommended.

    Also, you're not delaying the task. You need to call the scheduler and create a delayed task like what is in the wiki.
     
  7. Offline

    jarnedeclercq

    i thougt it was only for spigot
     
  8. Offline

    Zombie_Striker

    @jarnedeclercq
    Are you using a version higher than 1.8? If so it should be there.
     
  9. Offline

    FlightBlaze

    Try

    Code:
    
    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "title "+player.getName()+" title {\"text\":\"Welcome!\"}");
    
    
    It works great!
     
Thread Status:
Not open for further replies.

Share This Page