SHARE
TWEET

Untitled

a guest Jan 21st, 2020 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package net.reflex.practice.commands;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.command.Command;
  6. import org.bukkit.command.CommandSender;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.scheduler.BukkitRunnable;
  9. import org.bukkit.scheduler.BukkitTask;
  10.  
  11. import lombok.Getter;
  12. import lombok.RequiredArgsConstructor;
  13. import net.reflex.practice.Practice;
  14. import net.reflex.practice.ffa.listener.TeleportListener;
  15. import net.reflex.practice.profile.Profile;
  16. import net.reflex.practice.util.PlayerUtil;
  17. import net.reflex.practice.profile.PlayerState;
  18.  
  19. import java.util.ArrayList;
  20. import java.util.Arrays;
  21.  
  22. public class FFALeaveCommand extends Command {
  23.  
  24.     private final Practice plugin = Practice.getInstance();
  25.  
  26.     public FFALeaveCommand() {
  27.         super("ffaleave");
  28.         this.setDescription("Leave the ffa arena.");
  29.         this.setUsage(ChatColor.RED + "Usage: /ffaleave");
  30.     }
  31.    
  32.     ArrayList<Player> teleport = TeleportListener.teleport;
  33.  
  34.     @Override
  35.     public boolean execute(CommandSender sender, String alias, String[] args) {
  36.         if (!(sender instanceof Player)) {
  37.             return true;
  38.         }
  39.  
  40.         Player player = (Player) sender;
  41.  
  42.         if (!(plugin.getPlayerManager().getPlayerData(player.getUniqueId()).getPlayerState() == PlayerState.FFA)) {
  43.             return true;
  44.         }      
  45.        
  46.         teleport.add(player);
  47.         BukkitTask task = new TeleportCountdownTask(player).runTaskTimer(plugin, 0, 20);
  48.        
  49.             teleport.add(player);//Add player to arraylist on command
  50.             Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin,
  51.                             new Runnable() {
  52.                                     public void run() {
  53.                                             // Teleportation code here
  54.                                             teleport.remove(player);
  55.                                             plugin.getFfaManager().removePlayer(player);
  56.                                             //Remove player on sucessful teleport
  57.                                     }
  58.                             }, 20L * 5); // 10 seconds
  59.            
  60.         return true;
  61.     }
  62.    
  63.     @Getter
  64.     @RequiredArgsConstructor
  65.     public class TeleportCountdownTask extends BukkitRunnable {
  66.        
  67.         private final Player player;
  68.         private int time = 5;
  69.  
  70.         @Override
  71.         public void run() {
  72.            
  73.             Player player = null;
  74.            
  75.             if (time == 5) {
  76.                 if (!teleport.contains(player)) return;
  77.                 PlayerUtil.sendMessage(ChatColor.RED + "Teleporting in 5", player);
  78.             } else if (time == 4) {
  79.                 if (!teleport.contains(player)) return;
  80.                 PlayerUtil.sendMessage(ChatColor.RED + "Teleporting in 4", player);
  81.             } else if (time == 3) {
  82.                 if (!teleport.contains(player)) return;
  83.                 PlayerUtil.sendMessage(ChatColor.RED + "Teleporting in 3", player);
  84.             } else if (time == 2) {
  85.                 if (!teleport.contains(player)) return;
  86.                 PlayerUtil.sendMessage(ChatColor.RED + "Teleporting in 2", player);
  87.             } else if (time == 1) {
  88.                 if (!teleport.contains(player)) return;
  89.                 PlayerUtil.sendMessage(ChatColor.RED + "Teleporting in 1", player);
  90.             } else if (time == 0) {
  91.                 if (!teleport.contains(player)) return;
  92.                 PlayerUtil.sendMessage(ChatColor.RED + "You left the ffa arena.", player);
  93.             }
  94.            
  95.             time--;
  96.         }      
  97.  
  98.     }
  99. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top