Vinetos

Task per Player

Feb 15th, 2016
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. private HashMap<BukkitTask, Player> map = new HashMap<BukkitTask, Player>();
  2.    
  3.     @SuppressWarnings("deprecation")
  4.     @EventHandler
  5.     public void onJoin(PlayerJoinEvent e){//L'event que tu veux
  6.         //Lance la tâche avec délai
  7.         BukkitTask id = Bukkit.getScheduler().runTaskLater(this, new BukkitRunnable() {
  8.             @Override
  9.             public void run() {
  10.                 /*On récupère notre BukkitTask*/
  11.                 BukkitTask t = null;
  12.                 for(BukkitTask task : Bukkit.getScheduler().getPendingTasks()){
  13.                     if(task.getTaskId() == this.getTaskId()){
  14.                         t = task;
  15.                         break;
  16.                     }
  17.                 }
  18.                 /*On récupère notre joueur associé à cette tâche*/
  19.                 Player player = map.get(t);
  20.                 player.performCommand("say Coucou");//On lui fait executer une commande
  21.                 map.remove(t);//On le supprime à la fin
  22.             }
  23.         }, 20*60*15);//Delai (ici 15 min)
  24.        
  25.         map.put(id, e.getPlayer());//On ajoute notre task à l'HashMap
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment