Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. package ru.slimechan.prison.utils;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7.  
  8. import org.bukkit.Location;
  9. import org.bukkit.World;
  10. import org.bukkit.configuration.file.FileConfiguration;
  11. import org.bukkit.configuration.file.YamlConfiguration;
  12.  
  13. import ru.slimechan.prison.Camera;
  14. import ru.slimechan.prison.Prison;
  15.  
  16. public class ConfigUtil {
  17.  
  18. public static String CAMERAS = "cameras.yml";
  19. public static String DUELS = "duels.yml";
  20.  
  21. public static FileConfiguration getConfig(String name) {
  22. FileConfiguration cfg = YamlConfiguration.loadConfiguration(new File(Prison.Instance.getDataFolder(), name));
  23. return cfg;
  24. }
  25. public static void saveDefaultConfig(String fileName) {
  26. File file = new File(Prison.Instance.getDataFolder(), fileName);
  27. if (!file.exists())
  28. Prison.Instance.saveResource(fileName, false);
  29. }
  30.  
  31. public static void saveConfig(FileConfiguration config, String fileName) {
  32. try {
  33. config.save(new File(Prison.Instance.getDataFolder(), fileName));
  34. } catch (IOException e) {
  35. e.printStackTrace();
  36. }
  37. }
  38.  
  39.  
  40. public static Location[] loadDuelArena() {
  41. Location[] pos = new Location[2];
  42. pos[0] = parseLocation(getConfig(ConfigUtil.DUELS), getConfig(ConfigUtil.DUELS).getString("pos1"));
  43. pos[1] = parseLocation(getConfig(ConfigUtil.DUELS), getConfig(ConfigUtil.DUELS).getString("pos2"));
  44. return pos;
  45. }
  46.  
  47. public static List<Camera> getCameras() {
  48. List<String> l = getConfig(ConfigUtil.CAMERAS).getStringList("Cameras");
  49. List<Camera> cameras = new ArrayList<Camera>();
  50.  
  51. for(String s : l) {
  52. //cameras.add(new Camera(parseCamLocation(s)));
  53. }
  54.  
  55. return cameras;
  56. }
  57. public static String getStringLocation(Location l) {
  58. return l.getX()+","+l.getY()+","+l.getZ()+","+l.getYaw()+","+l.getPitch();
  59. }
  60. private static Location parseLocation(FileConfiguration cfg, String location) {
  61. // Location float x, float y, float z, yaw, pitch
  62. // x, y, z, yaw, pitch
  63. World w = Prison.Instance.getServer().getWorld(cfg.getString("World"));
  64.  
  65. String[] data = location.split(",");
  66.  
  67. float x = Float.parseFloat(data[0]);
  68. float y = Float.parseFloat(data[1]);
  69. float z = Float.parseFloat(data[2]);
  70.  
  71. float yaw = Float.parseFloat(data[3]);
  72. float pitch = Float.parseFloat(data[4]);
  73.  
  74. return new Location(w, x, y, z, yaw, pitch);
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement