Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ep12;
- import java.util.HashMap;
- import org.bukkit.Material;
- import org.bukkit.Sound;
- import org.bukkit.World;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.Inventory;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Main extends JavaPlugin{
- public HashMap<String, Long> cooldowns = new HashMap <String, Long>();
- public int cooldown = 120;
- public void add(Player p){
- cooldowns.put(p.getName(), System.currentTimeMillis());
- }
- public boolean has(Player p){
- return cooldowns.containsKey(p.getName()) ? true : false;
- }
- public void remove(Player p){
- cooldowns.remove(p.getName());
- }
- public Long scnd(Player p){
- long scndleft = ((cooldowns.get (p.getName()) /1000) + cooldown) - System.currentTimeMillis() / 1000;
- /* /12 > Ajouter a l'HashMap avec NAME + TEMPS 1
- * On recupere le NAME + TEMPS 1
- * On ajoute le temps d'attente (cooldown) auquel on suprime le TEMPS 2 (temps actuel)
- *
- * Name + Temps 1 + Temps d'attente
- * Vinetos + 08:29:00 + 120 - 08:30:00 = 1
- */
- return scndleft;
- }
- public Long min(Player p){
- long minleft = ((((cooldowns.get (p.getName()) /1000) + cooldown) - System.currentTimeMillis() / 1000) / 60) +1;
- return minleft;
- }
- public boolean onCommand(CommandSender send, Command cmd, String label, String[] args){
- if(!(send instanceof Player)){
- send.sendMessage("§cTu dois etre un joueur pour effectuer cette commande !");
- }
- Player p = (Player) send;
- Inventory inv = p.getInventory();
- ItemStack is = new ItemStack(Material.OBSIDIAN);
- World w = p.getWorld();
- if(cmd.getName().equalsIgnoreCase("12")||send.isOp()){
- if(has(p)){
- if(scnd(p) <= 0){
- remove(p);
- return true;
- }
- if(scnd(p) >= 60){
- p.sendMessage("§2Vous devez patientez§4 "+min(p)+" minutes §2!");
- return true;
- }
- if(scnd(p) <= 59){
- p.sendMessage("§2Vous devez patientez§4 "+scnd(p)+" secondes §2!");
- return true;
- }
- }else{
- inv.addItem(is);
- p.sendMessage("§2Vous avez recus un block d'obsidienne !");
- w.playSound(p.getLocation(), Sound.ITEM_PICKUP, 10, 1);
- add(p);
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment