Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.venusiamc.traque.commands;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Random;
- import org.bukkit.Bukkit;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandExecutor;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.ItemStack;
- import fr.venusiamc.traque.VenusiaTraque;
- import fr.venusiamc.traque.events.PlayerKillEvents;
- import fr.venusiamc.traque.utils.ItemStackList;
- public class TraqueCMD implements CommandExecutor {
- PlayerKillEvents pkevents;
- private static VenusiaTraque vtraque = VenusiaTraque.getInstance();
- private long cooldownTime = 5*60*60*1000L;
- List<Player> onlinePlayers = new ArrayList<>(Bukkit.getOnlinePlayers());
- @Override
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
- Player p = (Player) sender;
- String random = onlinePlayers.get(new Random().nextInt(onlinePlayers.size())).getName();
- ItemStack paper = ItemStackList.getPaper(random);
- if(random == p.getName()){
- return false;
- }
- if(Bukkit.getOnlinePlayers().size() < 2){
- p.sendMessage("§cIl n'a pas assez de joueurs connectés pour pouvoir utiliser cette commande !");
- } else if(sender instanceof Player){
- p.getInventory().addItem(paper);
- vtraque.playerTarget.put(p, Bukkit.getPlayer(random));
- p.sendMessage("§f§m--------------------------------------------");
- p.sendMessage(" ");
- p.sendMessage("§cSuivez§c§l " + random + "§c jusqu'à sa§c§l mort !");
- p.sendMessage("§eCette commande est disponible tout les§e§l 5 heures !");
- p.sendMessage(" ");
- p.sendMessage("§f§m--------------------------------------------");
- }
- if(!vtraque.commandCooldown.containsKey(p.getName())){
- executeCommand(p);
- } else if((vtraque.commandCooldown.get(p.getName()) + cooldownTime) >= System.currentTimeMillis()){
- vtraque.commandCooldown.remove(p.getName());
- executeCommand(p);
- } else {
- long timeRemaining = (vtraque.commandCooldown.get(p.getName()) + cooldownTime) - System.currentTimeMillis();
- long seconds = (timeRemaining / 1000) % 60;
- long minutes = (timeRemaining / (1000*60)) % 60;
- long hours = (timeRemaining / (1000*60*60)) % 24;
- p.sendMessage("§cIl reste " + String.format("%02dh%02dm%02ds", hours, minutes, seconds) + " avant que tu puisses refaire la commande");
- }
- return true;
- }
- public void executeCommand(Player p){
- vtraque.commandCooldown.put(p.getName(), System.currentTimeMillis());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement