mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2025-02-16 20:41:57 +01:00
Implement equals and hashCode for BlueMapMap and BlueMapWorld
This commit is contained in:
parent
6e8247ae3a
commit
757979b7b4
@ -45,17 +45,20 @@ public class BlueMapMapImpl implements BlueMapMap {
|
|||||||
private final WeakReference<Plugin> plugin;
|
private final WeakReference<Plugin> plugin;
|
||||||
private final WeakReference<BmMap> map;
|
private final WeakReference<BmMap> map;
|
||||||
private final BlueMapWorldImpl world;
|
private final BlueMapWorldImpl world;
|
||||||
|
private final String mapId;
|
||||||
|
|
||||||
public BlueMapMapImpl(Plugin plugin, BmMap map) throws IOException {
|
public BlueMapMapImpl(Plugin plugin, BmMap map) throws IOException {
|
||||||
this.plugin = new WeakReference<>(plugin);
|
this.plugin = new WeakReference<>(plugin);
|
||||||
this.map = new WeakReference<>(map);
|
this.map = new WeakReference<>(map);
|
||||||
this.world = new BlueMapWorldImpl(plugin, map.getWorld());
|
this.world = new BlueMapWorldImpl(plugin, map.getWorld());
|
||||||
|
this.mapId = map.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlueMapMapImpl(Plugin plugin, BmMap map, BlueMapWorldImpl world) {
|
public BlueMapMapImpl(Plugin plugin, BmMap map, BlueMapWorldImpl world) {
|
||||||
this.plugin = new WeakReference<>(plugin);
|
this.plugin = new WeakReference<>(plugin);
|
||||||
this.map = new WeakReference<>(map);
|
this.map = new WeakReference<>(map);
|
||||||
this.world = world;
|
this.world = world;
|
||||||
|
this.mapId = map.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BmMap getBmMap() {
|
public BmMap getBmMap() {
|
||||||
@ -64,7 +67,7 @@ public BmMap getBmMap() {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return unpack(map).getId();
|
return mapId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -147,6 +150,21 @@ public boolean isFrozen() {
|
|||||||
return !unpack(plugin).getPluginState().getMapState(unpack(map)).isUpdateEnabled();
|
return !unpack(plugin).getPluginState().getMapState(unpack(map)).isUpdateEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
BlueMapMapImpl that = (BlueMapMapImpl) o;
|
||||||
|
|
||||||
|
return mapId.equals(that.mapId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return mapId.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
private <T> T unpack(WeakReference<T> ref) {
|
private <T> T unpack(WeakReference<T> ref) {
|
||||||
return Objects.requireNonNull(ref.get(), "Reference lost to delegate object. Most likely BlueMap got reloaded and this instance is no longer valid.");
|
return Objects.requireNonNull(ref.get(), "Reference lost to delegate object. Most likely BlueMap got reloaded and this instance is no longer valid.");
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,21 @@ public Collection<BlueMapMap> getMaps() {
|
|||||||
.collect(Collectors.toUnmodifiableSet());
|
.collect(Collectors.toUnmodifiableSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
BlueMapWorldImpl that = (BlueMapWorldImpl) o;
|
||||||
|
|
||||||
|
return id.equals(that.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return id.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
private <T> T unpack(WeakReference<T> ref) {
|
private <T> T unpack(WeakReference<T> ref) {
|
||||||
return Objects.requireNonNull(ref.get(), "Reference lost to delegate object. Most likely BlueMap got reloaded and this instance is no longer valid.");
|
return Objects.requireNonNull(ref.get(), "Reference lost to delegate object. Most likely BlueMap got reloaded and this instance is no longer valid.");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user