-
Notifications
You must be signed in to change notification settings - Fork 36
fix: guard MapMeta#getMapView against IllegalStateException #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,7 +57,7 @@ public static ItemStack processImageFilledMap(ItemStack itemStack) { | |
| return null; | ||
| } | ||
| MapMeta mapMeta = (MapMeta) itemMeta; | ||
| MapView mapView = mapMeta.hasMapView() ? mapMeta.getMapView() : null; | ||
| MapView mapView = getMapViewSafely(mapMeta); | ||
| FilledMapItemInfo info = NMS.getInstance().getFilledMapItemInfo(itemStack); | ||
| if (info == null) { | ||
| if (mapView != null) { | ||
|
|
@@ -72,7 +72,17 @@ public static ItemStack processImageFilledMap(ItemStack itemStack) { | |
| } | ||
| } else { | ||
| ImageMap imageMap = ImageFrame.imageMapManager.getFromImageId(info.getImageMapIndex()); | ||
| MapView correctMapView = imageMap.getMapViews().get(info.getMapPartIndex()); | ||
| if (imageMap == null || !imageMap.isValid()) { | ||
| return null; | ||
| } | ||
| int mapPartIndex = info.getMapPartIndex(); | ||
| if (mapPartIndex < 0 || mapPartIndex >= imageMap.getMapViews().size()) { | ||
| return null; | ||
| } | ||
| MapView correctMapView = imageMap.getMapViews().get(mapPartIndex); | ||
| if (correctMapView == null) { | ||
| return null; | ||
| } | ||
| if (mapView == null || correctMapView.getId() != mapView.getId()) { | ||
| mapMeta.setMapView(correctMapView); | ||
| itemStack.setItemMeta(mapMeta); | ||
|
|
@@ -81,4 +91,15 @@ public static ItemStack processImageFilledMap(ItemStack itemStack) { | |
| return null; | ||
| } | ||
|
|
||
| private static MapView getMapViewSafely(MapMeta mapMeta) { | ||
| try { | ||
| if (!mapMeta.hasMapView()) { | ||
| return null; | ||
| } | ||
| return mapMeta.getMapView(); | ||
| } catch (IllegalStateException ignored) { | ||
| return null; | ||
| } | ||
| } | ||
|
Comment on lines
+94
to
+103
|
||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MapUtils.getItemMapView()performstryDeleteBlankDataFile(...)(filesystem existence/length checks) whenSettings.TryDeleteBlankMapFilesis enabled. Calling it from this per-tick edit task can introduce repeated IO and potential lag under that setting. Consider adding/using a variant that only does the safeMapViewextraction (no blank-file cleanup) for hot paths like marker editing/raytracing.