Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package eu.exception.utils;
- import java.io.File;
- import java.io.IOException;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.Sound;
- import org.bukkit.World;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.util.Vector;
- import eu.exception.main.Main;
- public class Spawns {
- public static void setLocation(String name, Player p){
- File ordner = new File("plugins//Lobby//");
- File file = new File("plugins//Lobby//" + name + ".yml");
- try {
- if(!ordner.exists()){
- ordner.mkdir();
- }
- if(!file.exists()){
- try {
- file.createNewFile();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- Location loc = p.getLocation();
- cfg.set("X", loc.getX());
- cfg.set("Y", loc.getY());
- cfg.set("Z", loc.getZ());
- cfg.set("Welt", loc.getWorld().getName());
- cfg.set("Yaw", loc.getYaw());
- cfg.set("Pitch", loc.getPitch());
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- } catch (Exception e) {
- // TODO: handle exception
- }
- }
- public static void useLocation(Player p, String name){
- try {
- File file = new File("plugins//Lobby//" + name + ".yml");
- if(!file.exists()){
- p.sendMessage(Main.prefix + "Die Location wurde nicht gefunden §8§l(§c§l/SETLOC§8§l)");
- }
- FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- World welt = Bukkit.getWorld(cfg.getString("Welt"));
- double yaw = cfg.getDouble("Yaw");
- double pitch = cfg.getDouble("Pitch");
- p.teleport(new Location(welt, cfg.getDouble("X"), cfg.getDouble("Y"), cfg.getDouble("Z"), (float) yaw, (float) pitch));
- Vector vec = p.getVelocity();
- vec.setY(1.2);
- p.setVelocity(vec);
- p.playSound(p.getLocation(), Sound.ENDERMAN_TELEPORT, 1.0F, 1.0F);
- } catch (Exception e) {
- // TODO: handle exception
- }
- }
- public static void useLocationfirst(Player p, String name){
- File file = new File("plugins//Lobby//" + name + ".yml");
- if(!file.exists()){
- p.sendMessage(Main.prefix + "Die Location wurde nicht gefunden §8§l(§c§l/SETLOC§8§l)");
- }
- FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- World welt = Bukkit.getWorld(cfg.getString("Welt"));
- double yaw = cfg.getDouble("Yaw");
- double pitch = cfg.getDouble("Pitch");
- Bukkit.getScheduler().runTaskLater(Main.getPlugin(Main.class), new Runnable() {
- @Override
- public void run() {
- p.teleport(new Location(welt, cfg.getDouble("X"), cfg.getDouble("Y"), cfg.getDouble("Z"), (float) yaw, (float) pitch));
- }
- }, 1);
- }
- public static Location getLocation(String name){
- File file = new File("plugins//Lobby//" + name + ".yml");
- FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- World welt = Bukkit.getWorld(cfg.getString("Welt"));
- double yaw = cfg.getDouble("Yaw");
- double pitch = cfg.getDouble("Pitch");
- return new Location(welt, cfg.getDouble("X"), cfg.getDouble("Y"), cfg.getDouble("Z"), (float) yaw, (float) pitch);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement