Advertisement
Guest User

Untitled

a guest
Aug 1st, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.55 KB | None | 0 0
  1. package lilian.xteam.listener;
  2.  
  3. import java.util.HashMap;
  4.  
  5. import lilian.xteam.Main;
  6. import lilian.xteam.utils.Utils;
  7.  
  8. import org.bukkit.Bukkit;
  9. import org.bukkit.ChatColor;
  10. import org.bukkit.Material;
  11. import org.bukkit.entity.Player;
  12. import org.bukkit.event.EventHandler;
  13. import org.bukkit.event.Listener;
  14. import org.bukkit.event.block.Action;
  15. import org.bukkit.event.player.PlayerInteractEvent;
  16. import org.bukkit.scoreboard.Score;
  17.  
  18. public class EnderPearlListener implements Listener {
  19.    
  20.    
  21.    
  22.     final HashMap<String, Long> cooldown = new HashMap<String, Long>();
  23.    
  24.     int countdown = 15; //This is how long(in secs) you want the countdown to be!
  25.      
  26.     private Main plugin; //Making it so we can access the scoreboard board and objective o
  27.      
  28.     public EnderPearlListener(Main Plugin) {
  29.     this.plugin = plugin;
  30.     }
  31.    
  32.    
  33.    
  34.    
  35.  
  36.     @EventHandler
  37.     public void onclickeventtt(PlayerInteractEvent e) {
  38.         Player p = e.getPlayer();
  39.         final String s = p.getName();
  40.         if (((e.getAction() == Action.RIGHT_CLICK_AIR) || (e.getAction() == Action.RIGHT_CLICK_BLOCK)) && e.getPlayer().getItemInHand().getType().equals(Material.ENDER_PEARL)) {
  41.  
  42.                
  43.                     Long useTime = cooldown.get(s);
  44.                     if(useTime != null) {
  45.                         final int time = 15;
  46.                         useTime = (System.currentTimeMillis() - useTime) / 1000;
  47.                         if(useTime < time) {
  48.                             e.setCancelled(true);
  49.                             Utils.send(p,"Tu dois encore attendre " + ChatColor.GOLD+(time - useTime) + ChatColor.DARK_GREEN+" secondes avant de pouvoir à nouveau utiliser une enderpearl.");
  50.                             return;
  51.                         }
  52.                     }
  53.                    
  54.                     p.setScoreboard(plugin.timerBoard); //Making it so the player can see the scoreboard
  55.                     Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
  56.                     @SuppressWarnings("deprecation")
  57.                     public void run() {
  58.                     countdown --; //Taking away 1 from countdown every 1 second
  59.                      
  60.                     final Score score = plugin.o.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Délai EnderPearl: ")); //Making a offline player called "Time:" with a green name and adding it to the scoreboard
  61.                     score.setScore(countdown); //Making it so after "Time:" it displays the int countdown(So how long it has left in seconds.)
  62.                      
  63.                     if(countdown == 0) { //If countdown == 0.
  64.                    
  65.                     plugin.getServer().getScheduler().cancelTasks(plugin); //Stopping it from running. You can also add another scoreboard to take over the timer one!
  66.                     }
  67.                     }
  68.                     }, 0L, 20L); //Repeating it every second
  69.                     }
  70.                    
  71.                    
  72.                     cooldown.put(s, System.currentTimeMillis());
  73.            
  74.         }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement