Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test.main;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.command.*;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.Player;
- import java.io.File;
- import java.io.IOException;
- import java.util.*;
- public class Commands implements CommandExecutor {
- File spawns = new File("plugins/Test/Locations", "Spawns.yml");
- FileConfiguration cspawns = YamlConfiguration.loadConfiguration(spawns);
- @Override
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
- Player p = (Player) sender;
- if (cmd.getName().equalsIgnoreCase("test")) {
- if (args.length == 0) {
- File game = new File("plugins/Test/Locations", "Spawns.yml");
- FileConfiguration cgame = YamlConfiguration.loadConfiguration(game);
- int totalLocs = 12;
- List<Location> locationslist = new ArrayList<>();
- for (int i = 1; i <= totalLocs; i++) {
- String world1 = cgame.getString("loc" + i + ".World");
- double x1 = cgame.getDouble("loc" + i + ".PosX");
- double y1 = cgame.getDouble("loc" + i + ".PosY");
- double z1 = cgame.getDouble("loc" + i + ".PosZ");
- double yaw1 = cgame.getDouble("loc" + i + ".PosYaw");
- double pitch1 = cgame.getDouble("loc" + i + ".PosPitch");
- Location gametel = new Location(Bukkit.getWorld(world1), x1, y1, z1);
- gametel.setPitch((float) pitch1);
- gametel.setYaw((float) yaw1);
- locationslist.add(gametel);
- }
- Random random = new Random();
- for (Player players : Bukkit.getOnlinePlayers()) {
- Location teleportloc = locationslist.get(random.nextInt(locationslist.size()));
- players.teleport(teleportloc);
- locationslist.remove(teleportloc);
- }
- } else {
- if (p.hasPermission("a.admin") || p.hasPermission("*") || p.isOp()) {
- if (args.length == 0) {
- p.sendMessage("§7Type: §6/test help");
- return true;
- }
- if (args.length == 1) {
- if (args[0].equalsIgnoreCase("help")) {
- p.sendMessage("§7§m===================================");
- p.sendMessage(" ");
- return true;
- }
- //TELEPORTING PLAYERS TO THE GAME
- if (args[0].equalsIgnoreCase("setloc1")) {
- setLocation(p.getLocation(), 1);
- p.sendMessage("§aLoc1 set!");
- return true;
- }
- if (args[0].equalsIgnoreCase("setloc2")) {
- setLocation(p.getLocation(), 2);
- p.sendMessage("§aLoc2 set!");
- return true;
- }
- if (args[0].equalsIgnoreCase("setloc3")) {
- setLocation(p.getLocation(), 3);
- p.sendMessage("§aLoc3 set!");
- return true;
- }
- if (args[0].equalsIgnoreCase("setloc4")) {
- setLocation(p.getLocation(), 4);
- p.sendMessage("§aLoc4 set!");
- return true;
- }
- if (args[0].equalsIgnoreCase("setloc5")) {
- setLocation(p.getLocation(), 5);
- p.sendMessage("§aLoc5 set!");
- return true;
- }
- if (args[0].equalsIgnoreCase("setloc6")) {
- setLocation(p.getLocation(), 6);
- p.sendMessage("§aLoc6 set!");
- return true;
- }
- //NEXT 6 PLAYERS
- if (args[0].equalsIgnoreCase("setloc7")) {
- setLocation(p.getLocation(), 7);
- p.sendMessage("§aLoc7 set!");
- return true;
- }
- if (args[0].equalsIgnoreCase("setloc8")) {
- setLocation(p.getLocation(), 8);
- p.sendMessage("§aLoc8 set!");
- return true;
- }
- if (args[0].equalsIgnoreCase("setloc9")) {
- setLocation(p.getLocation(), 9);
- p.sendMessage("§aLoc9 set!");
- return true;
- }
- if (args[0].equalsIgnoreCase("setloc10")) {
- setLocation(p.getLocation(), 10);
- p.sendMessage("§aLoc10 set!");
- return true;
- }
- if (args[0].equalsIgnoreCase("setloc11")) {
- setLocation(p.getLocation(), 11);
- p.sendMessage("§aLoc11 set!");
- return true;
- }
- if (args[0].equalsIgnoreCase("setloc12")) {
- setLocation(p.getLocation(), 12);
- p.sendMessage("§aLoc12 set!");
- return true;
- }
- }
- } else {
- p.sendMessage("§cYou don't have permissions!");
- return true;
- }
- }
- }
- return false;
- }
- private void setLocation(Location location, int index) {
- cspawns.set("loc" + index + ".World", location.getWorld().getName());
- cspawns.set("loc" + index + ".PosX", location.getX());
- cspawns.set("loc" + index + ".PosY", location.getY());
- cspawns.set("loc" + index + ".PosZ", location.getZ());
- cspawns.set("loc" + index + ".PosYaw", location.getYaw());
- cspawns.set("loc" + index + ".PosPitch", location.getPitch());
- try {
- cspawns.save(spawns);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement