package xyz.upperlevel.uppercore.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.configuration.serialization.ConfigurationSerializable;

import java.util.HashMap;
import java.util.Map;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Position implements Cloneable, ConfigurationSerializable {

    private double x, y, z;
    private double yaw, pitch;

    public Position(Location location) {
        x = location.getX();
        y = location.getY();
        z = location.getZ();
        yaw = location.getYaw();
        pitch = location.getPitch();
    }

    public Location toLocation(World world) {
        return new Location(world, x, y, z, (float) yaw, (float) pitch);
    }

    public Block toBlock(World world) {
        return toLocation(world).getBlock();
    }

    @Override
    public boolean equals(Object object) {
        if (object instanceof Position) {
            Position position = (Position) object;
            return position.x == x &&
                    position.y == y &&
                    position.z == z &&
                    position.yaw == yaw &&
                    position.pitch == pitch;
        }
        return super.equals(object);
    }

    @Override
    public Map<String, Object> serialize() {
        Map<String, Object> data = new HashMap<>();
        data.put("x", x);
        data.put("y", y);
        data.put("z", z);
        data.put("yaw", yaw);
        data.put("pitch", pitch);
        return data;
    }

    public static Position deserialize(Map<String, Object> data) {
        Position position = new Position();
        position.x = (double) data.get("x");
        position.y = (double) data.get("y");
        position.z = (double) data.get("z");
        position.yaw = (double) data.get("yaw");
        position.pitch = (double) data.get("pitch");
        return position;
    }

    public static Position from(Location location) {
        return new Position(location);
    }

    public static Position from(Block block) {
        return new Position(block.getLocation());
    }
}

@@ -51,78 +51,35 @@
 bok.
-AllArgsConstructor;%0Aimport lombok.Data;%0Aimport lombok.NoArgsConstructo
+Getter;%0Aimport lombok.Sette
 r;%0Ai
@@ -233,16 +233,63 @@
 lizable;
+%0Aimport xyz.upperlevel.uppercore.config.Config;
 %0A%0Aimport
@@ -335,53 +335,8 @@
 p;%0A%0A
-@Data%0A@NoArgsConstructor%0A@AllArgsConstructor%0A
 publ
@@ -367,19 +367,8 @@
 ents
- Cloneable,
  Con
@@ -392,16 +392,39 @@
 zable %7B%0A
+    @Getter%0A    @Setter
 %0A    pri
@@ -448,38 +448,288 @@
  z;%0A
-    private double yaw, pitch;
+%0A    @Getter%0A    @Setter%0A    private float yaw, pitch;%0A%0A    public Position() %7B%0A    %7D%0A%0A    public Position(double x, double y, double z, float yaw, float pitch) %7B%0A        this.x = x;%0A        this.y = y;%0A        this.z = z;%0A        this.yaw = yaw;%0A        this.pitch = pitch;%0A    %7D
 %0A%0A  
@@ -775,16 +775,21 @@
         
+this.
 x = loca
@@ -809,16 +809,21 @@
         
+this.
 y = loca
@@ -843,16 +843,21 @@
         
+this.
 z = loca
@@ -877,16 +877,21 @@
         
+this.
 yaw = lo
@@ -915,16 +915,21 @@
         
+this.
 pitch = 
@@ -1050,28 +1050,12 @@
  z, 
-(float) yaw, (float)
+yaw,
  pit
@@ -1150,32 +1150,118 @@
 Block();%0A    %7D%0A%0A
+    public Position copy() %7B%0A        return new Position(x, y, z, yaw, pitch);%0A    %7D%0A%0A
     @Override%0A  
@@ -2008,34 +2008,65 @@
         
-Position p
+Config cfg = Config.wrap(data);%0A        P
 osition 
 = new Po
@@ -2057,16 +2057,18 @@
 osition 
+r 
 = new Po
@@ -2089,174 +2089,129 @@
     
-position.x = (double) data.get(%22x%22);%0A        position.y = (double) data.get(%22y%22);%0A        position.z = (double) data.get(%22z%22);%0A        position.yaw = (double) data.ge
+r.x = cfg.getDouble(%22x%22);%0A        r.y = cfg.getDouble(%22y%22);%0A        r.z = cfg.getDouble(%22z%22);%0A        r.yaw = cfg.getFloa
 t(%22y
@@ -2220,32 +2220,25 @@
 %22);%0A        
-position
+r
 .pitch = (do
@@ -2238,24 +2238,19 @@
 h = 
-(double) data.ge
+cfg.getFloa
 t(%22p
@@ -2276,219 +2276,9 @@
 urn 
-position;%0A    %7D%0A%0A    public static Position from(Location location) %7B%0A        return new Position(location);%0A    %7D%0A%0A    public static Position from(Block block) %7B%0A        return new Position(block.getLocation())
+r
 ;%0A  

Clean Position class (remove @Data Lombok annotation)