Advertisement
Guest User

New Start.class

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