001package com.ericlam.mc.eld.misc;
002
003import com.fasterxml.jackson.annotation.JsonProperty;
004import org.bukkit.Bukkit;
005import org.bukkit.Location;
006
007/**
008 * 由於 Location 無法在 onload 的時候加載,因此創建此 Wrapper
009 */
010public final class LocationWrapper {
011
012    @JsonProperty
013    private String world;
014    @JsonProperty
015    private double x, y, z;
016    @JsonProperty
017    private float yaw, pitch;
018
019    /**
020     * 創建 wrapper
021     * @param location 原本的 location
022     */
023    public LocationWrapper(Location location) {
024        this.setLocation(location);
025    }
026
027    public LocationWrapper() {
028    }
029
030    /**
031     * 設定 location
032     * @param location 原本的 location
033     */
034    public void setLocation(Location location){
035        this.world = location.getWorld().getName();
036        this.x = location.getX();
037        this.y = location.getY();
038        this.z = location.getZ();
039        this.yaw = location.getYaw();
040        this.pitch = location.getPitch();
041    }
042
043    /**
044     * 取得 location
045     * @return location
046     */
047    public Location toLocation() {
048        return new Location(Bukkit.getWorld(world), x, y, z,  yaw, pitch);
049    }
050}