Cooldowns and events..

Discussion in 'Plugin Development' started by SenseTheGod, Feb 9, 2014.

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

    SenseTheGod

    Basically im coding this plugin right now... and it kinda works? im getting 0 errors in the cmd
    Code:java
    1.  
    2. package me.sensethegod;
    3.  
    4. import java.util.ArrayList;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.Material;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.block.Action;
    13. import org.bukkit.event.player.PlayerInteractEvent;
    14.  
    15. public class falcon
    16. implements Listener
    17. {
    18. ArrayList<Player> cooldown = new ArrayList<Player>();
    19. ArrayList<Player> soar = new ArrayList<Player>();
    20.  
    21. rKits plugin;
    22.  
    23. public falcon(rKits instance)
    24. {
    25. this.plugin = instance;
    26. }
    27.  
    28. @EventHandler
    29. public void onClick(PlayerInteractEvent e) {
    30. final Player p = e.getPlayer();
    31. if (p.getItemInHand().getType() == Material.FEATHER) {
    32. if (e.getAction() == Action.RIGHT_CLICK_AIR || (e.getAction() == Action.RIGHT_CLICK_BLOCK)) {
    33. if (cooldown.contains(p)) {
    34. e.setCancelled(true);
    35. p.sendMessage(ChatColor.RED + "You cannot fly right now, you are on cooldown!");
    36. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    37. public void run() {
    38. cooldown.remove(p);
    39. }
    40. }, 300L);
    41. }
    42. if (soar.contains(p)) {
    43. e.setCancelled(true);
    44. p.sendMessage(ChatColor.RED + "You are already flying!");
    45. }
    46. }
    47. else {
    48. p.setAllowFlight(true);
    49. p.setFlying(true);
    50. p.sendMessage(ChatColor.AQUA + "You have 5 seconds to soar the skys!");
    51. soar.add(p);
    52. Bukkit.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
    53. public void run() {
    54. p.setAllowFlight(false);
    55. p.setFlying(false);
    56. soar.remove(p);
    57. cooldown.add(p);
    58. p.sendMessage(ChatColor.RED + "Your wings have broken on you!");
    59. }
    60. }, 100L);
    61. }
    62. }
    63.  
    64.  
    65.  
    66.  
    67. }
    68. }
    69.  
     
  2. Offline

    HungerCraftNL

    So, what's the problem?
     
  3. Offline

    Gater12

    SenseTheGod
    If you are looking if the code is alright, one thing that jumps at me, is you are storing the Player object in a list. It's a big no no and you are going to run into trouble with this. Instead just store the Player's name.
     
Thread Status:
Not open for further replies.

Share This Page