Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.77 KB | None | 0 0
  1. package test.main;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.Location;
  5. import org.bukkit.command.*;
  6. import org.bukkit.configuration.file.FileConfiguration;
  7. import org.bukkit.configuration.file.YamlConfiguration;
  8. import org.bukkit.entity.Player;
  9.  
  10. import java.io.File;
  11. import java.io.IOException;
  12. import java.util.*;
  13.  
  14. public class Commands implements CommandExecutor {
  15.    
  16.     File spawns = new File("plugins/Test/Locations", "Spawns.yml");
  17.     FileConfiguration cspawns = YamlConfiguration.loadConfiguration(spawns);
  18.    
  19.     @Override
  20.     public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  21.         Player p = (Player) sender;
  22.         if (cmd.getName().equalsIgnoreCase("test")) {
  23.             if (args.length == 0) {
  24.                 File game = new File("plugins/Test/Locations", "Spawns.yml");
  25.                 FileConfiguration cgame = YamlConfiguration.loadConfiguration(game);
  26.                 int totalLocs = 12;
  27.                 List<Location> locationslist = new ArrayList<>();
  28.                 for (int i = 1; i <= totalLocs; i++) {
  29.                     String world1 = cgame.getString("loc" + i + ".World");
  30.                     double x1 = cgame.getDouble("loc" + i + ".PosX");
  31.                     double y1 = cgame.getDouble("loc" + i + ".PosY");
  32.                     double z1 = cgame.getDouble("loc" + i + ".PosZ");
  33.                     double yaw1 = cgame.getDouble("loc" + i + ".PosYaw");
  34.                     double pitch1 = cgame.getDouble("loc" + i + ".PosPitch");
  35.                     Location gametel = new Location(Bukkit.getWorld(world1), x1, y1, z1);
  36.                     gametel.setPitch((float) pitch1);
  37.                     gametel.setYaw((float) yaw1);
  38.                     locationslist.add(gametel);
  39.                 }
  40.                
  41.                 Random random = new Random();
  42.                
  43.                 for (Player players : Bukkit.getOnlinePlayers()) {
  44.                     Location teleportloc = locationslist.get(random.nextInt(locationslist.size()));
  45.                     players.teleport(teleportloc);
  46.                     locationslist.remove(teleportloc);
  47.                 }
  48.             } else {
  49.                 if (p.hasPermission("a.admin") || p.hasPermission("*") || p.isOp()) {
  50.                     if (args.length == 0) {
  51.                         p.sendMessage("§7Type: §6/test help");
  52.                         return true;
  53.                     }
  54.                     if (args.length == 1) {
  55.                         if (args[0].equalsIgnoreCase("help")) {
  56.                             p.sendMessage("§7§m===================================");
  57.                             p.sendMessage(" ");
  58.                             return true;
  59.                         }
  60.                        
  61.                         //TELEPORTING PLAYERS TO THE GAME
  62.                         if (args[0].equalsIgnoreCase("setloc1")) {
  63.                             setLocation(p.getLocation(), 1);
  64.                             p.sendMessage("§aLoc1 set!");
  65.                             return true;
  66.                         }
  67.                         if (args[0].equalsIgnoreCase("setloc2")) {
  68.                             setLocation(p.getLocation(), 2);
  69.                             p.sendMessage("§aLoc2 set!");
  70.                             return true;
  71.                         }
  72.                         if (args[0].equalsIgnoreCase("setloc3")) {
  73.                             setLocation(p.getLocation(), 3);
  74.                             p.sendMessage("§aLoc3 set!");
  75.                             return true;
  76.                         }
  77.                        
  78.                         if (args[0].equalsIgnoreCase("setloc4")) {
  79.                             setLocation(p.getLocation(), 4);
  80.                             p.sendMessage("§aLoc4 set!");
  81.                             return true;
  82.                         }
  83.                         if (args[0].equalsIgnoreCase("setloc5")) {
  84.                             setLocation(p.getLocation(), 5);
  85.                             p.sendMessage("§aLoc5 set!");
  86.                             return true;
  87.                         }
  88.                         if (args[0].equalsIgnoreCase("setloc6")) {
  89.                             setLocation(p.getLocation(), 6);
  90.                             p.sendMessage("§aLoc6 set!");
  91.                             return true;
  92.                         }
  93.                         //NEXT 6 PLAYERS
  94.                         if (args[0].equalsIgnoreCase("setloc7")) {
  95.                             setLocation(p.getLocation(), 7);
  96.                             p.sendMessage("§aLoc7 set!");
  97.                             return true;
  98.                         }
  99.                         if (args[0].equalsIgnoreCase("setloc8")) {
  100.                             setLocation(p.getLocation(), 8);
  101.                             p.sendMessage("§aLoc8 set!");
  102.                             return true;
  103.                         }
  104.                         if (args[0].equalsIgnoreCase("setloc9")) {
  105.                             setLocation(p.getLocation(), 9);
  106.                             p.sendMessage("§aLoc9 set!");
  107.                             return true;
  108.                         }
  109.                        
  110.                         if (args[0].equalsIgnoreCase("setloc10")) {
  111.                             setLocation(p.getLocation(), 10);
  112.                             p.sendMessage("§aLoc10 set!");
  113.                             return true;
  114.                         }
  115.                         if (args[0].equalsIgnoreCase("setloc11")) {
  116.                             setLocation(p.getLocation(), 11);
  117.                             p.sendMessage("§aLoc11 set!");
  118.                             return true;
  119.                         }
  120.                         if (args[0].equalsIgnoreCase("setloc12")) {
  121.                             setLocation(p.getLocation(), 12);
  122.                             p.sendMessage("§aLoc12 set!");
  123.                             return true;
  124.                         }
  125.                     }
  126.                 } else {
  127.                     p.sendMessage("§cYou don't have permissions!");
  128.                     return true;
  129.                 }
  130.             }
  131.         }
  132.         return false;
  133.     }
  134.    
  135.     private void setLocation(Location location, int index) {
  136.         cspawns.set("loc" + index + ".World", location.getWorld().getName());
  137.         cspawns.set("loc" + index + ".PosX", location.getX());
  138.         cspawns.set("loc" + index + ".PosY", location.getY());
  139.         cspawns.set("loc" + index + ".PosZ", location.getZ());
  140.         cspawns.set("loc" + index + ".PosYaw", location.getYaw());
  141.         cspawns.set("loc" + index + ".PosPitch", location.getPitch());
  142.         try {
  143.             cspawns.save(spawns);
  144.         } catch (IOException e) {
  145.             e.printStackTrace();
  146.         }
  147.     }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement