From aae20352078fd59502b10dda0a0e0037b23c1e93 Mon Sep 17 00:00:00 2001 From: Forwolk Date: Wed, 11 Jul 2018 18:38:37 +0300 Subject: [PATCH 1/2] Location implements cloneable --- core/src/main/java/mc/core/Location.java | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/mc/core/Location.java b/core/src/main/java/mc/core/Location.java index fa1e00b..474ab1d 100644 --- a/core/src/main/java/mc/core/Location.java +++ b/core/src/main/java/mc/core/Location.java @@ -9,15 +9,17 @@ import lombok.Data; @AllArgsConstructor @Data -public class Location { +public class Location implements Cloneable { private double x, y, z; public static Location copyOf(Location location) { - return new Location( - location.x, - location.y, - location.z - ); + return location.clone(); + } + + public Location (Location location) { + this.x = location.getX(); + this.y = location.getY(); + this.z = location.getZ(); } public void set(Location location) { @@ -45,4 +47,13 @@ public class Location { public int getBlockZ() { return (int) z; } + + @Override + protected Location clone() { + try { + return (Location) super.clone(); + } catch (CloneNotSupportedException e) { + return null; + } + } } From 6143c88b52b5dd9387626d48a4f47df6f037512f Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Wed, 11 Jul 2018 19:59:26 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=97=D0=B0=D1=87=D0=B5=D0=BC=20=D0=BD?= =?UTF-8?q?=D0=B0=D0=BC=20Location.copyOf(),=20=D0=BA=D0=BE=D0=B3=D0=B4?= =?UTF-8?q?=D0=B0=20=D0=B5=D1=81=D1=82=D1=8C=20clone()=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/main/java/mc/core/Location.java | 6 +----- .../java/mc/core/network/proto_1_12_2/TeleportManager.java | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/mc/core/Location.java b/core/src/main/java/mc/core/Location.java index 474ab1d..438efd9 100644 --- a/core/src/main/java/mc/core/Location.java +++ b/core/src/main/java/mc/core/Location.java @@ -12,10 +12,6 @@ import lombok.Data; public class Location implements Cloneable { private double x, y, z; - public static Location copyOf(Location location) { - return location.clone(); - } - public Location (Location location) { this.x = location.getX(); this.y = location.getY(); @@ -49,7 +45,7 @@ public class Location implements Cloneable { } @Override - protected Location clone() { + public Location clone() { try { return (Location) super.clone(); } catch (CloneNotSupportedException e) { diff --git a/proto_1.12.2/src/main/java/mc/core/network/proto_1_12_2/TeleportManager.java b/proto_1.12.2/src/main/java/mc/core/network/proto_1_12_2/TeleportManager.java index 31424bd..90c735f 100644 --- a/proto_1.12.2/src/main/java/mc/core/network/proto_1_12_2/TeleportManager.java +++ b/proto_1.12.2/src/main/java/mc/core/network/proto_1_12_2/TeleportManager.java @@ -38,7 +38,7 @@ public class TeleportManager { teleportId = RAND.nextInt(9999); } while (teleportMap.containsKey(teleportId)); - teleportMap.put(teleportId, new TpData(player, Location.copyOf(location))); + teleportMap.put(teleportId, new TpData(player, location.clone())); return teleportId; }