Guest User

START

a guest
Jul 7th, 2021
24
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package tk.challangesmp.toxicmine;
  2.  
  3. import org.bukkit.ChatColor;
  4. import org.bukkit.Location;
  5. import org.bukkit.command.Command;
  6. import org.bukkit.command.CommandExecutor;
  7. import org.bukkit.command.CommandSender;
  8. import org.bukkit.entity.Player;
  9.  
  10. import java.util.Scanner;
  11. import java.util.Timer;
  12. import java.util.TimerTask;
  13.  
  14. import static tk.challangesmp.toxicmine.Main.*;
  15.  
  16. public class Start implements CommandExecutor {
  17.     private Main plugin;
  18.  
  19.  
  20.     static Timer timer = new Timer();
  21.     static TimerTask timerTask = new ChallengeTimer();
  22.  
  23.     public Start(Main plugin) {
  24.         this.plugin = plugin;
  25.  
  26.         plugin.getCommand("challenge").setExecutor(this);
  27.     }
  28.  
  29.  
  30.  
  31.  
  32.     @Override
  33.     public boolean onCommand(CommandSender commandSender, Command command, String label, String[] args) {
  34.         if (!(commandSender instanceof Player)) {
  35.             if (args[0].equals("start")) {
  36.                 //Seconds for a week is 604800000
  37.                 timer.schedule(timerTask, 604800000);
  38.                 timerIsOngoing = true;
  39.                 commandSender.sendMessage("The timer has started!");
  40.                 return true;
  41.             }
  42.             if (args[0].equals("stop")) {
  43.                     timerTask.cancel();
  44.                     timer.purge();
  45.                     commandSender.sendMessage("Cancelled timer.");
  46.                 return true;
  47.             }
  48.             return true;
  49.         }
  50.  
  51.         Player player = (Player) commandSender;
  52.         if (args[0].equals("join")) {
  53.             if (competent.contains(player)) {
  54.                 player.sendMessage("You are already there in the challenge!");
  55.                 return true;
  56.             }
  57.             if (timerIsOngoing){
  58.                 competent.add(player);
  59.                 player.sendMessage("Successfully added you to the challenge!");
  60.             } else {
  61.                 player.sendMessage("The challenge timer is not ongoing.");
  62.             }
  63.             return true;
  64.         }
  65.         if (args[0].equals("quit")) {
  66.             if (!competent.contains(player)) {
  67.                 player.sendMessage("You are not there in the challenge.");
  68.                 return true;
  69.             }
  70.             if (timerIsOngoing){
  71.                 Scanner scanner = new Scanner(System.in);
  72.                 player.sendMessage("Are you sure to remove yourself from the challenge? [Yes/No]");
  73.                 String opinion = scanner.nextLine();
  74.                 if (opinion.equalsIgnoreCase("yes")) {
  75.                     competent.remove(player);
  76.                     player.sendMessage("Successfully removed you from the challenge.");
  77.                 }else {
  78.                     player.sendMessage("Aborted removal.");
  79.                 }
  80.             } else {
  81.                 competent.remove(player);
  82.                 player.sendMessage("Successfully removed you from the challenge.");
  83.             }
  84.             return true;
  85.         }
  86.         if (args[0].equals("tp")) {
  87.             if (player.isOp()) {
  88.                 Location location = player.getLocation();
  89.                 for (Player value : competent) {
  90.                     value.teleport(location);
  91.                 }
  92.                 player.sendMessage("Finished teleporting competent(s) to you!");
  93.             }
  94.             return true;
  95.         }
  96.         if (args[0].equals("challenge")) {
  97.             if(player.isOp());
  98.             player.sendMessage(ChatColor.YELLOW + "Command List");
  99.             player.sendMessage(ChatColor.BLUE + "/challenge join " + ChatColor.GRAY + "- " + ChatColor.YELLOW + "Adds player to waiting state");
  100.             player.sendMessage(ChatColor.BLUE + "/challenge quit " + ChatColor.GRAY + "- " +ChatColor.YELLOW + "Removes player to waiting state");
  101.             player.sendMessage(ChatColor.BLUE + "/challenge start(CONSOLE ONLY) " + ChatColor.GRAY + "- " + ChatColor.YELLOW + "Starts the Timer");
  102.             player.sendMessage(ChatColor.BLUE + "/challenge stop(CONSOLE ONLY) " + ChatColor.GRAY + "- " + ChatColor.YELLOW + "Stops the Timer");
  103.             player.sendMessage(ChatColor.BLUE + "/challenge tp(OP ONLY) " + ChatColor.GRAY + "- " + ChatColor.YELLOW + "Tps everyone in waiting stage to the current location of the command executor");
  104.             player.sendMessage(ChatColor.BLUE + "/challenge help " + ChatColor.GRAY + "- " + ChatColor.YELLOW + "Shows the command list");
  105.         }else{
  106.             player.sendMessage(ChatColor.YELLOW + "Command List");
  107.             player.sendMessage(ChatColor.BLUE + "/challenge join " + ChatColor.GRAY + "- " + ChatColor.YELLOW + "Adds player to waiting state");
  108.             player.sendMessage(ChatColor.BLUE + "/challenge quit " + ChatColor.GRAY + "- " +ChatColor.YELLOW + "Removes player to waiting state");
  109.             player.sendMessage(ChatColor.BLUE + "/challenge help " + ChatColor.GRAY + "- " + ChatColor.YELLOW + "Shows the command list");
  110.         }
  111.         if (args[0].equals("help")){
  112.             if(player.isOp());
  113.             player.sendMessage(ChatColor.YELLOW + "Command List");
  114.             player.sendMessage(ChatColor.BLUE + "/challenge join " + ChatColor.GRAY + "- " + ChatColor.YELLOW + "Adds player to waiting state");
  115.             player.sendMessage(ChatColor.BLUE + "/challenge quit " + ChatColor.GRAY + "- " +ChatColor.YELLOW + "Removes player to waiting state");
  116.             player.sendMessage(ChatColor.BLUE + "/challenge start(CONSOLE ONLY) " + ChatColor.GRAY + "- " + ChatColor.YELLOW + "Starts the Timer");
  117.             player.sendMessage(ChatColor.BLUE + "/challenge stop(CONSOLE ONLY) " + ChatColor.GRAY + "- " + ChatColor.YELLOW + "Stops the Timer");
  118.             player.sendMessage(ChatColor.BLUE + "/challenge tp(OP ONLY) " + ChatColor.GRAY + "- " + ChatColor.YELLOW + "Tps everyone in waiting stage to the current location of the command executor");
  119.             player.sendMessage(ChatColor.BLUE + "/challenge help " + ChatColor.GRAY + "- " + ChatColor.YELLOW + "Shows the command list");
  120.         }else{
  121.             player.sendMessage(ChatColor.YELLOW + "Command List");
  122.             player.sendMessage(ChatColor.BLUE + "/challenge join " + ChatColor.GRAY + "- " + ChatColor.YELLOW + "Adds player to waiting state");
  123.             player.sendMessage(ChatColor.BLUE + "/challenge quit " + ChatColor.GRAY + "- " +ChatColor.YELLOW + "Removes player to waiting state");
  124.             player.sendMessage(ChatColor.BLUE + "/challenge help " + ChatColor.GRAY + "- " + ChatColor.YELLOW + "Shows the command list");
  125.         }
  126.  
  127.         return true;
  128.     }
  129. }
  130.  
  131. class ChallengeTimer extends TimerTask {
  132.  
  133.     @Override
  134.     public void run() {
  135.         oneWeekOver = true;
  136.     }
  137. }
  138.  
RAW Paste Data