Advertisement
Guest User

ConfigUtil

a guest
Nov 14th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. package de.thefaces.secrets;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.Location;
  5. import org.bukkit.World;
  6. import org.bukkit.configuration.file.FileConfiguration;
  7.  
  8. import de.thefaces.main.Main;
  9.  
  10. public class ConfigLocationUtil {
  11.  
  12. private Main plugin;
  13. private Location location;
  14. private String root;
  15.  
  16. public ConfigLocationUtil(Main plugin, Location location, String root) {
  17. this.plugin = plugin;
  18. this.location = location;
  19. this.root = root;
  20. }
  21.  
  22. public ConfigLocationUtil(Main plugin, String root) {
  23. this(plugin, null, root);
  24.  
  25. }
  26.  
  27. public void saveLocation() {
  28. FileConfiguration config = plugin.getConfig();
  29. config.set(root + ".World", location.getWorld().getName());
  30. config.set(root + ".X", location.getX());
  31. config.set(root + ".Y", location.getY());
  32. config.set(root + ".Z", location.getZ());
  33. config.set(root + ".Yaw", location.getYaw());
  34. config.set(root + ".Pitch", location.getPitch());
  35. plugin.saveConfig();
  36.  
  37. }
  38.  
  39. public Location loadLocation() {
  40. FileConfiguration config = plugin.getConfig();
  41. if(config.contains(root)) {
  42. World world = Bukkit.getWorld(config.getString(root + ".World"));
  43. double x = config.getDouble(root + ".X"),
  44. y = config.getDouble(root + ".Y"),
  45. z = config.getDouble(root + ".Z");
  46. float yaw = (float) config.getDouble(root + ".Yaw"),
  47. pitch = (float) config.getDouble(root + ".Pitch");
  48. return new Location(world, x, y, z, yaw, pitch);
  49. } else
  50. return null;
  51.  
  52.  
  53.  
  54.  
  55. }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement