I Need help in a Timer.

Discussion in 'Plugin Development' started by InPaniCsz, Jan 27, 2015.

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

    InPaniCsz

    Well, I want to make this, when a player do /fps they have to wait 3 Seconds, and if they are attacked by anyone, or if they move, the teleport is cancelled.
    This is the code I have:
    Code:java
    1.  
    2. if(commandLabel.equalsIgnoreCase("fps")){
    3. PlayerListener.plugin.oneKit.remove(p.getName());
    4. if(plugin.getConfig().getString("fps.world") == null){
    5. p.sendMessage("§3Fps is not set, do §a/setfps§3 first.");
    6. return true;
    7. }
    8. if(!plugin.fps.contains(p.getName())){
    9. World w = Bukkit.getServer().getWorld(plugin.getConfig().getString("fps.world"));
    10. p.sendMessage("§cEntraste no FPS.");
    11. plugin.fps.add(p.getName());
    12. p.getInventory().clear();
    13. p.getInventory().setArmorContents(null);
    14. PlayerListener.plugin.oneKit.remove(p.getName());
    15.  
    16. double x = plugin.getConfig().getDouble("fps.x");
    17. double y = plugin.getConfig().getDouble("fps.y");
    18. double z = plugin.getConfig().getDouble("fps.z");
    19. swmeta.setDisplayName("§cFPS Sword");
    20. sw.setItemMeta(swmeta);
    21. sw.addEnchantment(Enchantment.DAMAGE_ALL, 1);
    22. p.teleport(new Location(w, x, y, z));
    23. p.getInventory().setHelmet(helmet);
    24. p.getInventory().setChestplate(chest);
    25. p.getInventory().setLeggings(leg);
    26. p.getInventory().setBoots(boots);
    27. p.getInventory().setItem(0, sw);
    28. p.setGameMode(GameMode.ADVENTURE);
    29. for (int i = 0; i <= 35; i++)
    30. p.getInventory().addItem(new ItemStack[] { sopa });
    31. return true;
    32. }else{
    33. plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    34.  
    35. public void run() {
    36. World w = Bukkit.getServer().getWorld(plugin.getConfig().getString("spawn.world"));
    37. double x = plugin.getConfig().getDouble("spawn.x");
    38. double y = plugin.getConfig().getDouble("spawn.y");
    39. double z = plugin.getConfig().getDouble("spawn.z");
    40. p.teleport(new Location(w, x, y, z));
    41. p.sendMessage("§cSaiste do FPS.");
    42. PlayerListener.plugin.oneKit.remove(p.getName());
    43. p.getInventory().clear();
    44. p.getInventory().setArmorContents(null);
    45. plugin.fps.remove(p.getName());
    46.  
    47. }
    48. }, 60L);
    49. return true;
    50. }
    51.  
    52. }
    53. return false;
    54. }
     
  2. Offline

    WinX64

    Schedule your task(the 3 second teleport in this case), get the task id and store it somewhere where it can be accessed later(Map, Custom player object, etc). Then you can listen for the damage event, and if the task id for the teleport is set, cancel the teleport(and maybe give them a message about the teleport being cancelled).
     
Thread Status:
Not open for further replies.

Share This Page