Advertisement
Guest User

Untitled

a guest
Apr 8th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.25 KB | None | 0 0
  1. package KillBattle;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.Location;
  8. import org.bukkit.World;
  9. import org.bukkit.entity.Player;
  10. import org.bukkit.event.Listener;
  11.  
  12.  
  13. public class MapConfig implements Listener{
  14.  
  15.     public static Location CoordenadasLobby;
  16.    
  17.     public static int jugadoresMaximos, jugadoresMinimos, duracionSegundosPartida, distanciaProteccionSpawn, partidasAntesDelReinicio, mysqlPort;
  18.     public static String mysqlDatabase, mysqlHost, mysqlUsername, mysqlPassword;
  19.     public static List<Location> locs = new ArrayList<>();
  20.     public static List<Location> locs2 = new ArrayList<>();
  21.     public static List<Location> locs3 = new ArrayList<>();
  22.     public static List<Location> locs4 = new ArrayList<>();
  23.     public static List<Location> respawn1Locs = new ArrayList<>();
  24.     public static List<Location> respawn2Locs = new ArrayList<>();
  25.     public static List<Location> respawn3Locs = new ArrayList<>();
  26.     public static List<Location> respawn4Locs = new ArrayList<>();
  27.    
  28.     /**Metodo para cargar la configuración del fichero, si no existe se creará
  29.      * la carpeta y se copiará la plantilla**/
  30.     public static void loadConfig(){
  31.         mainClass.getInstance().getConfig().options().copyDefaults(true);
  32.         mainClass.getInstance().saveConfig();
  33.        
  34.         /* Mi edici§n empieza AQU§ (Todo el resto es de DarkMein) */
  35.         // Le decimos a bukkit que el mundo es el Principal
  36.         World mundo = Bukkit.getWorlds().get(0);
  37.        
  38.         // Variables Extraídas De La Configuración
  39.         CoordenadasLobby = getLocation("CoordenadasLobby", mundo);
  40.         jugadoresMinimos = mainClass.getInstance().getConfig().getInt("jugadoresMinimos");
  41.         jugadoresMaximos = mainClass.getInstance().getConfig().getInt("jugadoresMaximos");
  42.         distanciaProteccionSpawn = mainClass.getInstance().getConfig().getInt("distanciaProteccionSpawn");
  43.         duracionSegundosPartida = mainClass.getInstance().getConfig().getInt("duracionSegundosPartida");
  44.         partidasAntesDelReinicio = mainClass.getInstance().getConfig().getInt("partidasAntesDelReinicio");
  45.        
  46.         // Mysql
  47.         mysqlPort = mainClass.getInstance().getConfig().getInt("Mysql.Puerto");
  48.         mysqlDatabase = mainClass.getInstance().getConfig().getString("Mysql.Database");
  49.         mysqlHost = mainClass.getInstance().getConfig().getString("Mysql.Host");
  50.         mysqlUsername = mainClass.getInstance().getConfig().getString("Mysql.Username");
  51.         mysqlPassword = mainClass.getInstance().getConfig().getString("Mysql.Password");
  52.        
  53.         // Cargamos las coords de los 4 mapas
  54.         locs.clear();
  55.         for (String str : mainClass.getInstance().getConfig().getStringList("Coords")){
  56.             locs.add(getLocationFromString(str, mundo));
  57.         }
  58.        
  59.         locs2.clear();
  60.         for (String str : mainClass.getInstance().getConfig().getStringList("Coords2")){
  61.             locs2.add(getLocationFromString(str, mundo));
  62.         }
  63.        
  64.         locs3.clear();
  65.         for (String str : mainClass.getInstance().getConfig().getStringList("Coords3")){
  66.             locs3.add(getLocationFromString(str, mundo));
  67.         }
  68.        
  69.         locs4.clear();
  70.         for (String str : mainClass.getInstance().getConfig().getStringList("Coords4")){
  71.             locs4.add(getLocationFromString(str, mundo));
  72.         }
  73.        
  74.         resetLocs(0);
  75.        
  76.         resetLocs(1);
  77.        
  78.         resetLocs(2);
  79.        
  80.         resetLocs(3);
  81.         /* Mi edici§n termina AQU§ (Todo el resto es de DarkMein) */
  82.     }
  83.    
  84.     public static void resetLocs(int i) {
  85.         if (i == 0) {
  86.             respawn1Locs.clear();
  87.            
  88.             for (Location loc : locs) {
  89.                 respawn1Locs.add(loc);
  90.             }
  91.         } else if (i == 1) {
  92.             respawn2Locs.clear();
  93.            
  94.             for (Location loc : locs2) {
  95.                 respawn2Locs.add(loc);
  96.             }  
  97.         } else if (i == 2) {
  98.             respawn3Locs.clear();
  99.            
  100.             for (Location loc : locs3) {
  101.                 respawn3Locs.add(loc);
  102.             }
  103.         } else if (i == 3) {
  104.             respawn4Locs.clear();
  105.            
  106.             for (Location loc : locs4) {
  107.                 respawn4Locs.add(loc);
  108.             }
  109.         }
  110.     }
  111.    
  112.     public static void añadirLocation(Location loc, String map){
  113.        
  114.         if(map.equalsIgnoreCase("MapaUno")) {
  115.             locs.add(loc);
  116.         } else if(map.equalsIgnoreCase("MapaDos")) {
  117.             locs2.add(loc);
  118.         }if(map.equalsIgnoreCase("MapaTres")) {
  119.             locs3.add(loc);
  120.         }if(map.equalsIgnoreCase("MapaCuatro")) {
  121.             locs4.add(loc);
  122.         }
  123.         guardarArray(map);
  124.     }
  125.    
  126.    
  127.     public static void guardarArray(String map) {
  128.        
  129.         if(map.equalsIgnoreCase("MapaUno")) {
  130.             List<String> listaaGuardar = new ArrayList<>();
  131.             for (Location loc : locs) {
  132.                 listaaGuardar.add(convertLocationToString(loc));
  133.             }
  134.             mainClass.getInstance().getConfig().set("Coords", listaaGuardar);
  135.         } else if(map.equalsIgnoreCase("MapaDos")) {
  136.             List<String> listaaGuardar = new ArrayList<>();
  137.             for (Location loc : locs2) {
  138.                 listaaGuardar.add(convertLocationToString(loc));
  139.             }
  140.             mainClass.getInstance().getConfig().set("Coords2", listaaGuardar);
  141.         } else if(map.equalsIgnoreCase("MapaTres")) {
  142.             List<String> listaaGuardar = new ArrayList<>();
  143.             for (Location loc : locs3) {
  144.                 listaaGuardar.add(convertLocationToString(loc));
  145.             }
  146.             mainClass.getInstance().getConfig().set("Coords3", listaaGuardar);
  147.         } else if(map.equalsIgnoreCase("MapaCuatro")) {
  148.             List<String> listaaGuardar = new ArrayList<>();
  149.             for (Location loc : locs4) {
  150.                 listaaGuardar.add(convertLocationToString(loc));
  151.             }
  152.             for(Player player : Bukkit.getOnlinePlayers()) {
  153.                   player.sendMessage("Guardado coord map 4");
  154.               }
  155.             mainClass.getInstance().getConfig().set("Coords4", listaaGuardar);
  156.         }
  157.        
  158.        
  159.        
  160.     }
  161.    
  162.    
  163.     /**Procesa una location guardada en formato texto y devuelve una Location*/
  164.     public static Location getLocationFromString(String locString, World world){
  165.         double x, y, z; // 0,0,0,0,0
  166.         float yaw = 0, pitch = 0;
  167.         String coords[] = locString.split(", ");
  168.        
  169.         x = Double.parseDouble(coords[0]);
  170.         y = Double.parseDouble(coords[1]);
  171.         z = Double.parseDouble(coords[2]);
  172.        
  173.         if (coords.length > 3){
  174.             yaw = Float.parseFloat(coords[3]);
  175.             pitch = Float.parseFloat(coords[4]);
  176.         }
  177.         return new Location(world, x, y, z, yaw, pitch);
  178.     }
  179.    
  180.     /**Extrae una unica Location de la config especificandole la ruta*/
  181.     public static Location getLocation(String ruta, World world){
  182.         double x = 0, y = 0, z = 0;
  183.         float yaw = 0, pitch = 0;
  184.         System.out.println(ruta);
  185.         System.out.println(mainClass.getInstance().getConfig().getString(ruta));
  186.        
  187.         String[] coords = mainClass.getInstance().getConfig().getString(ruta).split(", ");
  188.        
  189.         x = Double.parseDouble(coords[0]);
  190.         y = Double.parseDouble(coords[1]);
  191.         z = Double.parseDouble(coords[2]);
  192.        
  193.         if (coords.length > 3){
  194.             yaw = Float.parseFloat(coords[3]);
  195.             pitch = Float.parseFloat(coords[4]);
  196.         }
  197.         return new Location(world, x, y, z, yaw, pitch);
  198.     }
  199.    
  200.     /**Guarda una location en la configuración*/
  201.     public static void saveLocation(Location loc, String ruta){
  202.         mainClass.getInstance().getConfig().set(ruta, convertLocationToString(loc));
  203.         mainClass.getInstance().saveConfig();
  204.     }
  205.    
  206.     /**Convierte una location en un String para ser guardado en la configuración*/
  207.     public static String convertLocationToString(Location loc){
  208.         String locString = loc.getX() + ", " + loc.getY() + ", " + loc.getZ() + ", " + loc.getYaw() + ", " + loc.getPitch();
  209.         return locString;
  210.     }
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement