[SOLVED] How to check if message is sent while scheduleSyncDelayedTask in progress

Discussion in 'Plugin Development' started by CRAZYxMUNK3Y, Aug 2, 2012.

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

    CRAZYxMUNK3Y

    I was wondering how, and if it's possible to check if a message has been sent within a x amount of time of another message, and if it is, stop the message from being sent.

    Current code:
    Code:java
    1.  
    2. package me.crazy.noshout;
    3.  
    4. import org.bukkit.event.Listener;
    5. import org.bukkit.event.player.PlayerChatEvent;
    6. import org.bukkit.plugin.PluginManager;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class NoShout extends JavaPlugin implements Listener {
    10.  
    11. public void onEnable(){
    12. PluginManager pm = getServer().getPluginManager();
    13. pm.registerEvents(this, this);
    14. }
    15.  
    16. public void playerChat(PlayerChatEvent e){
    17. if(e.getMessage().contains("!")){
    18. getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    19. @Override
    20. public void run() {
    21. // Don't know what to do here
    22. }
    23.  
    24. },30 * 20L); //30 seconds
    25. }
    26. }
    27. }
    28.  


    Just ask if you need anymore information.
     
  2. Offline

    r0306

    CRAZYxMUNK3Y
    You can add the player to a list and check if the player is already in the list before sending.
    Code:
    ArrayList<String> pending = new ArrayList<String>();
    //outside the method
     
    //inside the method
    if (pending.contains(e.getPlayer().getName()) {
    pending.add(e.getPlayer().getName());
    getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    @Override
    public void run() {
    //send the message
    pending.remove(e.getPlayer().getName());
    }
    }
     
  3. Offline

    CRAZYxMUNK3Y

    r0306
    Thanks for the reply, will use that, but could that also allow some players to chat after 2 seconds because of when the scheduler is run?
     
  4. Offline

    r0306

  5. Offline

    CRAZYxMUNK3Y

    Ok then, thanks.
     
  6. Offline

    r0306

    Np.
     
Thread Status:
Not open for further replies.

Share This Page