lNockl

Manager

Jun 27th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.36 KB | None | 0 0
  1. package me.filipenock.supersw.Arena;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.Location;
  7. import org.bukkit.configuration.file.YamlConfiguration;
  8. import org.bukkit.entity.Player;
  9.  
  10. import me.filipenock.supersw.Main;
  11. import me.filipenock.supersw.Arena.Arena.ArenaState;
  12. import me.filipenock.supersw.Arena.Arena.ArenaType;
  13. import me.filipenock.supersw.Until.Converter;
  14.  
  15. public class Manager {
  16.    
  17.     public static ArrayList<Arena> arenas = new ArrayList<>();
  18.    
  19.     public Manager() {}
  20.    
  21.     public void load() {
  22.         YamlConfiguration arenacfg = Main.arenas.getCfg();
  23.         YamlConfiguration config = Main.config.getCfg();
  24.         for (String a : arenacfg.getConfigurationSection("Arenas").getKeys(false)) {
  25.             if (a != null) {
  26.                 Arena arena = new Arena(a);
  27.                 arena.setMinteams(arenacfg.getInt("Arenas."+a+".minteams"));
  28.                 arena.setMaxteams(arenacfg.getInt("Arenas."+a+".maxteams"));
  29.                 arena.setMaxplayersperteam(arenacfg.getInt("Arenas."+a+".maxplayersperteam"));
  30.                 arena.setLobbycountdown(config.getInt("Arena.lobbycountdown"));
  31.                 arena.setCagecountdown(config.getInt("Arena.cagecountdown"));
  32.                 arena.setIngamecountdown(config.getInt("Arena.ingamecountdown"));
  33.                 arena.setLobby(new Converter().ConvertLocation(arenacfg.getString("Arenas."+a+".lobby")));
  34.                 arena.setSpectator(new Converter().ConvertLocation(arenacfg.getString("Arenas."+a+".spectator")));
  35.                 arena.setState(ArenaState.WAITING);
  36.                 if (arena.getMaxplayersperteam() > 1) {
  37.                     arena.setType(ArenaType.TEAM);
  38.                 }
  39.                 for (String s : arenacfg.getConfigurationSection("Arenas."+a+".spawns").getKeys(false)) {
  40.                     arena.getSpawns().add(new Converter().ConvertLocation(arenacfg.getString("Arenas."+a+".spawns."+s+".spawn")));
  41.                 }
  42.                 arenas.add(arena); 
  43.             }
  44.         }
  45.         Bukkit.getConsoleSender().sendMessage("§6§m--------------§c[SuperSkywars]§6-----------------");
  46.         Bukkit.getConsoleSender().sendMessage("§e");
  47.         Bukkit.getConsoleSender().sendMessage("§e         Plugin made by FilipeNock");
  48.         Bukkit.getConsoleSender().sendMessage("§a         Total of §9" + arenas.size() + " §aArenas loaded!");
  49.         Bukkit.getConsoleSender().sendMessage("§e");
  50.         Bukkit.getConsoleSender().sendMessage("§6§m---------------------------------------------");
  51.     }
  52.    
  53.     public void savearena(Arena arena) {
  54.         YamlConfiguration arenacfg = Main.arenas.getCfg();
  55.         arenacfg.set("Arenas."+arena.getName()+".minteams", arena.getMinteams());
  56.         arenacfg.set("Arenas."+arena.getName()+".maxteams", arena.getMaxteams());
  57.         arenacfg.set("Arenas."+arena.getName()+".maxplayerperteam", arena.getMaxplayersperteam());
  58.         arenacfg.set("Arenas."+arena.getName()+".lobby", new Converter().ConvertLocation(arena.getLobby()));
  59.         arenacfg.set("Arenas."+arena.getName()+".spectator", new Converter().ConvertLocation(arena.getSpectator()));
  60.         if (arenacfg.getConfigurationSection("Arenas."+arena.getName()+".spawns") == null) {
  61.             arenacfg.createSection("Arenas."+arena.getName()+".spawns");
  62.         }
  63.         int i = 0;
  64.         for (Location sp : arena.getSpawns()) {
  65.             arenacfg.set("Arenas."+arena.getName()+".spawns."+i+".spawn", new Converter().ConvertLocation(sp));
  66.             i++;
  67.         }
  68.         Main.arenas.save();
  69.     }
  70.    
  71.     public void save() {
  72.         for (Player p : Bukkit.getOnlinePlayers()) {
  73.             if (new Manager().isinGame(p)) {
  74.                 new Manager().getPlayerArena(p).removeplayer(p);
  75.             }
  76.         }
  77.         for (Arena a : arenas) {
  78.             if (arenas.size() > 0) {
  79.                 savearena(a);
  80.             }
  81.         }
  82.     }
  83.    
  84.     public static void setMainlobby(Location loc) {
  85.         Main.config.getCfg().set("Main-Lobby", new Converter().ConvertLocation(loc));
  86.         Main.config.save();
  87.     }
  88.    
  89.     public static Location getMainLobby() {
  90.         Location loc = new Converter().ConvertLocation(Main.config.getCfg().getString("Main-Lobby"));
  91.         return loc;
  92.     }
  93.    
  94.     public Arena getArena(String name) {
  95.         for (Arena a : arenas) {
  96.             if (a.getName().equalsIgnoreCase(name)) {
  97.                 return a;
  98.             }
  99.         }
  100.         return null;
  101.     }
  102.    
  103.     public Arena getPlayerArena(Player p) {
  104.         for (Arena a : arenas) {
  105.             if (a.getAllplayers().contains(p)) {
  106.                 return a;
  107.             }
  108.         }
  109.         return null;
  110.     }
  111.    
  112.     public boolean arenaExits(String name) {
  113.         for (Arena a : arenas) {
  114.             if (a.getName().equalsIgnoreCase(name)) {
  115.                 return true;
  116.             }
  117.         }
  118.         return false;
  119.     }
  120.    
  121.     public boolean isinGame(Player p) {
  122.         for (Arena a : arenas) {
  123.             if (a.getAllplayers().contains(p)) {
  124.                 return true;
  125.             }
  126.         }
  127.         return false;
  128.     }
  129.    
  130.  
  131. }
Advertisement
Add Comment
Please, Sign In to add comment