Skip to content

Commit c80bbd5

Browse files
committed
improve just revive and alter already set data
1 parent 9800b54 commit c80bbd5

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

Item Creator/src/main/java/org/broken/arrow/library/itemcreator/meta/MapWrapperMeta.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public MapView getMapView() {
4141
*/
4242
@Nullable
4343
public BuildMapView getMapViewBuilder() {
44-
this.getMapView();
4544
return this.mapView;
4645
}
4746

@@ -70,6 +69,29 @@ public BuildMapView createMapView(@Nonnull final World world, @Nonnull final Con
7069
return this.createOrRetrieveMapView(world, -1, action);
7170
}
7271

72+
/**
73+
* Attempts to retrieve an existing map by already set {@link BuildMapView} instance and wraps it in a {@link BuildMapView}.
74+
* <p>
75+
* Unlike {@link #createOrRetrieveMapView(World, int, Consumer)} and {@link #createMapView(World, Consumer)},
76+
* the difference is that the first method always creates a new map when one cannot be found, while the second
77+
* always creates a new map regardless. This method, however, does not create a new map if the ID is missing,
78+
* it simply returns {@code null}.
79+
* </p>
80+
*
81+
* @param action a consumer to configure the resulting {@link BuildMapView}, if found.
82+
* @return the retrieved {@link BuildMapView}, or {@code null} if no map exists for the given ID.
83+
*/
84+
@Nullable
85+
public BuildMapView getExistingMapView(@Nonnull final Consumer<BuildMapView> action) {
86+
final BuildMapView builtMapView = this.getMapViewBuilder();
87+
if(builtMapView == null) return null;
88+
final MapView mapView = (builtMapView.getId() >= 0) ? ItemCreator.getMapById(builtMapView.getId()) : null;
89+
if (mapView == null) return null;
90+
91+
action.accept(builtMapView);
92+
return builtMapView;
93+
}
94+
7395
/**
7496
* Attempts to retrieve an existing map by its ID and wraps it in a {@link BuildMapView}.
7597
* <p>
@@ -141,6 +163,9 @@ public void applyMapMeta(@Nullable final ItemStack item, @Nonnull final ItemMeta
141163

142164
if (ItemCreator.getServerVersion() < 13.0F) {
143165
final BuildMapView mapViewBuilder = this.getMapViewBuilder();
166+
if(mapViewBuilder != null)
167+
mapViewBuilder.finalizeMapView();
168+
144169
short durability = mapViewBuilder == null ? -1 : (short) mapViewBuilder.getId();
145170
if (item != null && durability >= 0) {
146171
item.setDurability(durability);

Item Creator/src/main/java/org/broken/arrow/library/itemcreator/serialization/typeadapter/MapMetaAdapter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public void write(final JsonWriter out, final MapWrapperMeta value) throws IOExc
4343

4444
final BuildMapView mapView = value.getMapViewBuilder();
4545
if (mapView != null) {
46+
mapView.finalizeMapView();
4647
final String worldUID = mapView.getWorld() == null ? null : mapView.getWorld().getUID().toString();
4748
json.value("id", mapView.getId());
4849
json.value("world", worldUID);

0 commit comments

Comments
 (0)