Solved Broadcast sends before Message

Discussion in 'Plugin Development' started by 87pen, Jun 18, 2015.

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

    87pen

    How would I make it so my broadcast, broadcast's after the players message is sent. Because currently this is what happens, [​IMG]
    Code:
       
        ArrayList<String> start = new ArrayList<String>();
       
       
        public void onEnable(){
            start.add("yo juiz");
            start.add("hey juiz");
            start.add("juiz I have a request");
            start.add("juiz");
            Bukkit.getPluginManager().registerEvents(this, this);
        }
       
        @EventHandler
        public void onChat(AsyncPlayerChatEvent e){
            Player p = e.getPlayer();
            if(start.contains(e.getMessage())){
               
                p.setDisplayName(p.getName());
               
                Random rand = new Random();
               
                int id = rand.nextInt(2);
               
                if(id == 0){
                    Bukkit.getServer().broadcastMessage(ChatColor.DARK_GRAY + "[" + ChatColor.LIGHT_PURPLE + "Juiz" + ChatColor.DARK_GRAY + "] " + ChatColor.WHITE + "Yes " + p.getName() + "?");
                }
                if(id == 1){
                    Bukkit.getServer().broadcastMessage(ChatColor.DARK_GRAY + "[" + ChatColor.LIGHT_PURPLE + "Juiz" + ChatColor.DARK_GRAY + "] " + ChatColor.WHITE + "What is your request " + p.getName() + "?");
                }
                if(id == 2){
                    Bukkit.getServer().broadcastMessage(ChatColor.DARK_GRAY + "[" + ChatColor.LIGHT_PURPLE + "Juiz" + ChatColor.DARK_GRAY + "] " + ChatColor.WHITE + "What do you need " + p.getName() + "?");
                }
            }
        }
    }
    
     
  2. Offline

    Ruptur

    @87pen
    The chat event is called before it is chat to the players.
    All you need to do is to add the broadcast as a delayed task.
    Code:
    Bukkit.getScheduler().scheduleDelayedTask(new Runnable() {
        @Override
        public void run() {
            // Your broadcast message
        }
    }, ticks);
    
    The 'ticks' is how long you want to wait before the broadcast is sent

    Hope this solved your problem. :)
    Leave a like if i helped
     
  3. Offline

    87pen

  4. Offline

    Ruptur

    @87pen
    No problem you should set the Thread prefix to [Solved].

    Leave a like if you think i helped :D
     
Thread Status:
Not open for further replies.

Share This Page