From be1e5a7d95bd95b52d3f23cba1d935cb4d894ac6 Mon Sep 17 00:00:00 2001 From: "Blue (Lukas Rieger)" Date: Thu, 4 Feb 2021 01:22:40 +0100 Subject: [PATCH] Push API version and properly implement equals and hashCode for MarkerSet and Marker --- BlueMapAPI | 2 +- .../bluemap/common/api/marker/MarkerImpl.java | 21 +++++++++++++--- .../common/api/marker/MarkerSetImpl.java | 25 ++++++++++++------- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/BlueMapAPI b/BlueMapAPI index 17cbf15f..ea8d2379 160000 --- a/BlueMapAPI +++ b/BlueMapAPI @@ -1 +1 @@ -Subproject commit 17cbf15f84815205b52a7aa07f4060b4235cf45a +Subproject commit ea8d237925e4efb1e1fb17d9ec622ea9aa80b43c diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/api/marker/MarkerImpl.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/api/marker/MarkerImpl.java index 798ff77b..0222ae68 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/api/marker/MarkerImpl.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/api/marker/MarkerImpl.java @@ -24,16 +24,16 @@ */ package de.bluecolored.bluemap.common.api.marker; -import java.util.Optional; - import com.flowpowered.math.vector.Vector3d; import com.google.common.base.Preconditions; - import de.bluecolored.bluemap.api.BlueMapAPI; import de.bluecolored.bluemap.api.BlueMapMap; import de.bluecolored.bluemap.api.marker.Marker; import ninja.leaping.configurate.ConfigurationNode; +import java.util.Objects; +import java.util.Optional; + public abstract class MarkerImpl implements Marker { private final String id; @@ -205,5 +205,18 @@ private static void writePos(ConfigurationNode node, Vector3d pos) { node.getNode("y").setValue(Math.round(pos.getY() * 1000d) / 1000d); node.getNode("z").setValue(Math.round(pos.getZ() * 1000d) / 1000d); } - + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + MarkerImpl marker = (MarkerImpl) o; + return id.equals(marker.id); + } + + @Override + public int hashCode() { + return id.hashCode(); + } + } diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/api/marker/MarkerSetImpl.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/api/marker/MarkerSetImpl.java index 59ace780..518facd5 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/api/marker/MarkerSetImpl.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/api/marker/MarkerSetImpl.java @@ -24,17 +24,8 @@ */ package de.bluecolored.bluemap.common.api.marker; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - import com.flowpowered.math.vector.Vector3d; import com.google.common.collect.Sets; - import de.bluecolored.bluemap.api.BlueMapAPI; import de.bluecolored.bluemap.api.BlueMapMap; import de.bluecolored.bluemap.api.marker.Marker; @@ -43,6 +34,9 @@ import de.bluecolored.bluemap.core.logger.Logger; import ninja.leaping.configurate.ConfigurationNode; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; + public class MarkerSetImpl implements MarkerSet { private final String id; @@ -217,4 +211,17 @@ public synchronized void save(ConfigurationNode node) { this.hasUnsavedChanges = false; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + MarkerSetImpl markerSet = (MarkerSetImpl) o; + return id.equals(markerSet.id); + } + + @Override + public int hashCode() { + return id.hashCode(); + } + }