forked from mirror/BlueMap
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<BmMap> map;
|
||||
private final BlueMapWorldImpl world;
|
||||
private final String mapId;
|
||||
|
||||
public BlueMapMapImpl(Plugin plugin, BmMap map) throws IOException {
|
||||
this.plugin = new WeakReference<>(plugin);
|
||||
this.map = new WeakReference<>(map);
|
||||
this.world = new BlueMapWorldImpl(plugin, map.getWorld());
|
||||
this.mapId = map.getId();
|
||||
}
|
||||
|
||||
public BlueMapMapImpl(Plugin plugin, BmMap map, BlueMapWorldImpl world) {
|
||||
this.plugin = new WeakReference<>(plugin);
|
||||
this.map = new WeakReference<>(map);
|
||||
this.world = world;
|
||||
this.mapId = map.getId();
|
||||
}
|
||||
|
||||
public BmMap getBmMap() {
|
||||
@ -64,7 +67,7 @@ public BmMap getBmMap() {
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return unpack(map).getId();
|
||||
return mapId;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -147,6 +150,21 @@ public boolean isFrozen() {
|
||||
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) {
|
||||
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());
|
||||
}
|
||||
|
||||
@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) {
|
||||
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