Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. package eu.exception.utils;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5.  
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.Location;
  8. import org.bukkit.Sound;
  9. import org.bukkit.World;
  10. import org.bukkit.configuration.file.FileConfiguration;
  11. import org.bukkit.configuration.file.YamlConfiguration;
  12. import org.bukkit.entity.Player;
  13. import org.bukkit.util.Vector;
  14.  
  15. import eu.exception.main.Main;
  16.  
  17.  
  18. public class Spawns {
  19. public static void setLocation(String name, Player p){
  20. File ordner = new File("plugins//Lobby//");
  21. File file = new File("plugins//Lobby//" + name + ".yml");
  22.  
  23. try {
  24. if(!ordner.exists()){
  25. ordner.mkdir();
  26. }
  27. if(!file.exists()){
  28. try {
  29. file.createNewFile();
  30. } catch (IOException e) {
  31. e.printStackTrace();
  32. }
  33. }
  34.  
  35. FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  36. Location loc = p.getLocation();
  37.  
  38. cfg.set("X", loc.getX());
  39. cfg.set("Y", loc.getY());
  40. cfg.set("Z", loc.getZ());
  41. cfg.set("Welt", loc.getWorld().getName());
  42. cfg.set("Yaw", loc.getYaw());
  43. cfg.set("Pitch", loc.getPitch());
  44.  
  45. try {
  46. cfg.save(file);
  47. } catch (IOException e) {
  48. e.printStackTrace();
  49. }
  50. } catch (Exception e) {
  51. // TODO: handle exception
  52. }
  53. }
  54.  
  55. public static void useLocation(Player p, String name){
  56. try {
  57. File file = new File("plugins//Lobby//" + name + ".yml");
  58.  
  59. if(!file.exists()){
  60. p.sendMessage(Main.prefix + "Die Location wurde nicht gefunden §8§l(§c§l/SETLOC§8§l)");
  61. }
  62.  
  63. FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  64.  
  65. World welt = Bukkit.getWorld(cfg.getString("Welt"));
  66. double yaw = cfg.getDouble("Yaw");
  67. double pitch = cfg.getDouble("Pitch");
  68.  
  69.  
  70.  
  71. p.teleport(new Location(welt, cfg.getDouble("X"), cfg.getDouble("Y"), cfg.getDouble("Z"), (float) yaw, (float) pitch));
  72.  
  73. Vector vec = p.getVelocity();
  74. vec.setY(1.2);
  75.  
  76.  
  77. p.setVelocity(vec);
  78. p.playSound(p.getLocation(), Sound.ENDERMAN_TELEPORT, 1.0F, 1.0F);
  79.  
  80. } catch (Exception e) {
  81. // TODO: handle exception
  82. }
  83.  
  84.  
  85. }
  86.  
  87. public static void useLocationfirst(Player p, String name){
  88. File file = new File("plugins//Lobby//" + name + ".yml");
  89.  
  90. if(!file.exists()){
  91. p.sendMessage(Main.prefix + "Die Location wurde nicht gefunden §8§l(§c§l/SETLOC§8§l)");
  92. }
  93.  
  94. FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  95.  
  96. World welt = Bukkit.getWorld(cfg.getString("Welt"));
  97. double yaw = cfg.getDouble("Yaw");
  98. double pitch = cfg.getDouble("Pitch");
  99.  
  100.  
  101. Bukkit.getScheduler().runTaskLater(Main.getPlugin(Main.class), new Runnable() {
  102.  
  103. @Override
  104. public void run() {
  105. p.teleport(new Location(welt, cfg.getDouble("X"), cfg.getDouble("Y"), cfg.getDouble("Z"), (float) yaw, (float) pitch));
  106. }
  107. }, 1);
  108.  
  109. }
  110.  
  111. public static Location getLocation(String name){
  112. File file = new File("plugins//Lobby//" + name + ".yml");
  113. FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  114.  
  115. World welt = Bukkit.getWorld(cfg.getString("Welt"));
  116. double yaw = cfg.getDouble("Yaw");
  117. double pitch = cfg.getDouble("Pitch");
  118. return new Location(welt, cfg.getDouble("X"), cfg.getDouble("Y"), cfg.getDouble("Z"), (float) yaw, (float) pitch);
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement