Advertisement
Guest User

LocationManager

a guest
Apr 21st, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.17 KB | None | 0 0
  1. package io.coding4you.ban.util;
  2.  
  3. /*
  4.  *
  5.  * (c) by coding4you.io you are not permit to sell it!
  6.  *
  7.  */
  8.  
  9. import io.coding4you.ban.main.BanPlugin;
  10. import org.bukkit.Bukkit;
  11. import org.bukkit.Location;
  12. import org.bukkit.World;
  13. import org.bukkit.configuration.file.YamlConfiguration;
  14.  
  15. import java.io.File;
  16. import java.io.IOException;
  17.  
  18. public class LocationManager {
  19.    
  20.    Location loc;
  21.    final static String prefix = "§eLocationManager";
  22.    
  23.    public LocationManager(String name, Location location){
  24.      
  25.       File file = new File("plugins//" + BanPlugin.getInstance().getDescription().getName() + "//locations//" + name + ".yml");
  26.       YamlConfiguration configuration = YamlConfiguration.loadConfiguration(file);
  27.      
  28.       configuration.set("X", location.getX());
  29.       configuration.set("Y", location.getY());
  30.       configuration.set("Z", location.getZ());
  31.       configuration.set("Yaw", location.getYaw());
  32.       configuration.set("Pitch", location.getPitch());
  33.       configuration.set("World", location.getWorld().getName());
  34.    
  35.       World world = Bukkit.getWorld(configuration.getString("World"));
  36.       loc = new Location(world, configuration.getDouble("X"), configuration.getDouble("Y"), configuration.getDouble("Z"));
  37.    
  38.       if(! file.exists()){
  39.      
  40.          try{
  41.             configuration.save(file);
  42.          }catch(IOException e){
  43.          
  44.          }
  45.      
  46.       }
  47.      
  48.    }
  49.    
  50.    public static Location getLocation(String name){
  51.    
  52.       File file = new File("plugins//" + BanPlugin.getInstance().getDescription().getName() + "//locations//" + name + ".yml");
  53.       YamlConfiguration configuration = YamlConfiguration.loadConfiguration(file);
  54.    
  55.       if(file.exists()){
  56.    
  57.          World world = Bukkit.getWorld(configuration.getString("World"));
  58.          Location loc = new Location(world, configuration.getDouble("X"), configuration.getDouble("Y"), configuration.getDouble("Z"));
  59.    
  60.          return loc;
  61.      
  62.       }else{
  63.          
  64.          Bukkit.getConsoleSender().sendMessage(prefix + " this location does not exists! ( " + name + " )");
  65.          
  66.       }
  67.    
  68.       return null;
  69.      
  70.    }
  71.    
  72.    public static boolean locationExists(String name){
  73.    
  74.       File file = new File("plugins//" + BanPlugin.getInstance().getDescription().getName() + "//locations//" + name + ".yml");
  75.       YamlConfiguration configuration = YamlConfiguration.loadConfiguration(file);
  76.      
  77.       if(file.exists()){
  78.          
  79.          return true;
  80.          
  81.       }else {
  82.          
  83.          return false;
  84.          
  85.       }
  86.      
  87.    }
  88.    
  89.    public double getX(){
  90.      
  91.       return loc.getX();
  92.      
  93.    }
  94.    
  95.    public double getY(){
  96.      
  97.       return loc.getY();
  98.      
  99.    }
  100.    
  101.    public double getZ(){
  102.      
  103.       return loc.getZ();
  104.      
  105.    }
  106.    
  107.    public float getYaw(){
  108.      
  109.       return loc.getYaw();
  110.      
  111.    }
  112.    
  113.    
  114.    public float getPitch(){
  115.      
  116.       return loc.getPitch();
  117.      
  118.    }
  119.    
  120.    public World getWorld(){
  121.      
  122.       return loc.getWorld();
  123.      
  124.    }
  125.    
  126.    public String getWorldName(){
  127.      
  128.       return loc.getWorld().getName();
  129.      
  130.    }
  131.    
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement