Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.filipenock.supersw.Arena;
- import java.util.ArrayList;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.Player;
- import me.filipenock.supersw.Main;
- import me.filipenock.supersw.Arena.Arena.ArenaState;
- import me.filipenock.supersw.Arena.Arena.ArenaType;
- import me.filipenock.supersw.Until.Converter;
- public class Manager {
- public static ArrayList<Arena> arenas = new ArrayList<>();
- public Manager() {}
- public void load() {
- YamlConfiguration arenacfg = Main.arenas.getCfg();
- YamlConfiguration config = Main.config.getCfg();
- for (String a : arenacfg.getConfigurationSection("Arenas").getKeys(false)) {
- if (a != null) {
- Arena arena = new Arena(a);
- arena.setMinteams(arenacfg.getInt("Arenas."+a+".minteams"));
- arena.setMaxteams(arenacfg.getInt("Arenas."+a+".maxteams"));
- arena.setMaxplayersperteam(arenacfg.getInt("Arenas."+a+".maxplayersperteam"));
- arena.setLobbycountdown(config.getInt("Arena.lobbycountdown"));
- arena.setCagecountdown(config.getInt("Arena.cagecountdown"));
- arena.setIngamecountdown(config.getInt("Arena.ingamecountdown"));
- arena.setLobby(new Converter().ConvertLocation(arenacfg.getString("Arenas."+a+".lobby")));
- arena.setSpectator(new Converter().ConvertLocation(arenacfg.getString("Arenas."+a+".spectator")));
- arena.setState(ArenaState.WAITING);
- if (arena.getMaxplayersperteam() > 1) {
- arena.setType(ArenaType.TEAM);
- }
- for (String s : arenacfg.getConfigurationSection("Arenas."+a+".spawns").getKeys(false)) {
- arena.getSpawns().add(new Converter().ConvertLocation(arenacfg.getString("Arenas."+a+".spawns."+s+".spawn")));
- }
- arenas.add(arena);
- }
- }
- Bukkit.getConsoleSender().sendMessage("§6§m--------------§c[SuperSkywars]§6-----------------");
- Bukkit.getConsoleSender().sendMessage("§e");
- Bukkit.getConsoleSender().sendMessage("§e Plugin made by FilipeNock");
- Bukkit.getConsoleSender().sendMessage("§a Total of §9" + arenas.size() + " §aArenas loaded!");
- Bukkit.getConsoleSender().sendMessage("§e");
- Bukkit.getConsoleSender().sendMessage("§6§m---------------------------------------------");
- }
- public void savearena(Arena arena) {
- YamlConfiguration arenacfg = Main.arenas.getCfg();
- arenacfg.set("Arenas."+arena.getName()+".minteams", arena.getMinteams());
- arenacfg.set("Arenas."+arena.getName()+".maxteams", arena.getMaxteams());
- arenacfg.set("Arenas."+arena.getName()+".maxplayerperteam", arena.getMaxplayersperteam());
- arenacfg.set("Arenas."+arena.getName()+".lobby", new Converter().ConvertLocation(arena.getLobby()));
- arenacfg.set("Arenas."+arena.getName()+".spectator", new Converter().ConvertLocation(arena.getSpectator()));
- if (arenacfg.getConfigurationSection("Arenas."+arena.getName()+".spawns") == null) {
- arenacfg.createSection("Arenas."+arena.getName()+".spawns");
- }
- int i = 0;
- for (Location sp : arena.getSpawns()) {
- arenacfg.set("Arenas."+arena.getName()+".spawns."+i+".spawn", new Converter().ConvertLocation(sp));
- i++;
- }
- Main.arenas.save();
- }
- public void save() {
- for (Player p : Bukkit.getOnlinePlayers()) {
- if (new Manager().isinGame(p)) {
- new Manager().getPlayerArena(p).removeplayer(p);
- }
- }
- for (Arena a : arenas) {
- if (arenas.size() > 0) {
- savearena(a);
- }
- }
- }
- public static void setMainlobby(Location loc) {
- Main.config.getCfg().set("Main-Lobby", new Converter().ConvertLocation(loc));
- Main.config.save();
- }
- public static Location getMainLobby() {
- Location loc = new Converter().ConvertLocation(Main.config.getCfg().getString("Main-Lobby"));
- return loc;
- }
- public Arena getArena(String name) {
- for (Arena a : arenas) {
- if (a.getName().equalsIgnoreCase(name)) {
- return a;
- }
- }
- return null;
- }
- public Arena getPlayerArena(Player p) {
- for (Arena a : arenas) {
- if (a.getAllplayers().contains(p)) {
- return a;
- }
- }
- return null;
- }
- public boolean arenaExits(String name) {
- for (Arena a : arenas) {
- if (a.getName().equalsIgnoreCase(name)) {
- return true;
- }
- }
- return false;
- }
- public boolean isinGame(Player p) {
- for (Arena a : arenas) {
- if (a.getAllplayers().contains(p)) {
- return true;
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment