Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
Expand All @@ -46,8 +45,6 @@
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.MapMeta;
import org.bukkit.map.MapCursor;
import org.bukkit.map.MapView;
import org.bukkit.util.RayTraceResult;
Expand Down Expand Up @@ -110,21 +107,7 @@ private void editTask() {
}
Vector hitPosition = result.getHitPosition();
ItemStack itemStack = itemFrame.getItem();
if (itemStack == null || itemStack.getType().equals(Material.AIR)) {
continue;
}
if (!itemStack.hasItemMeta()) {
continue;
}
ItemMeta itemMeta = itemStack.getItemMeta();
if (!(itemMeta instanceof MapMeta)) {
continue;
}
MapMeta mapMeta = (MapMeta) itemMeta;
if (!mapMeta.hasMapView()) {
continue;
}
MapView mapView = mapMeta.getMapView();
MapView mapView = MapUtils.getItemMapView(itemStack);
if (mapView == null) {
continue;
Comment on lines 109 to 112
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MapUtils.getItemMapView() performs tryDeleteBlankDataFile(...) (filesystem existence/length checks) when Settings.TryDeleteBlankMapFiles is 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 safe MapView extraction (no blank-file cleanup) for hot paths like marker editing/raytracing.

Copilot uses AI. Check for mistakes.
}
Expand Down Expand Up @@ -194,21 +177,7 @@ public <T extends PlayerEvent & Cancellable> void handlePlayerInteract(T event)
return;
}
ItemStack itemStack = itemFrame.getItem();
if (itemStack == null || itemStack.getType().equals(Material.AIR)) {
return;
}
if (!itemStack.hasItemMeta()) {
return;
}
ItemMeta itemMeta = itemStack.getItemMeta();
if (!(itemMeta instanceof MapMeta)) {
return;
}
MapMeta mapMeta = (MapMeta) itemMeta;
if (!mapMeta.hasMapView()) {
return;
}
MapView mapView = mapMeta.getMapView();
MapView mapView = MapUtils.getItemMapView(itemStack);
if (mapView == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getMapViewSafely(MapMeta) duplicates the same hasMapView() + getMapView() try/catch logic now present in MapUtils.getItemMapView(...). To avoid the two implementations drifting over time, consider centralizing this into a shared helper (e.g., a MapUtils.getMapViewSafely(MapMeta) or an overload of getItemMapView that accepts MapMeta / skips cleanup).

Copilot uses AI. Check for mistakes.

}
26 changes: 12 additions & 14 deletions common/src/main/java/com/loohp/imageframe/utils/MapUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,22 @@ public static MapView getItemMapView(ItemStack itemStack) {
return null;
}
MapMeta mapMeta = (MapMeta) meta;
if (!mapMeta.hasMapView()) {
MapView mapView;
try {
if (!mapMeta.hasMapView()) {
return null;
}
mapView = mapMeta.getMapView();
} catch (IllegalStateException ignored) {
return null;
}
if (mapView == null) {
return null;
}
if (mapMeta.hasMapId()) {
tryDeleteBlankDataFile(getMainWorld(), mapMeta.getMapId());
}
return mapMeta.getMapView();
return mapView;
}

public static MapView getPlayerMapView(Player player) {
Expand Down Expand Up @@ -286,18 +295,7 @@ public static ImageMapHitTargetResult rayTraceTargetImageMap(Location start, Vec
}
Vector hitPosition = rayTraceResult.getHitPosition();
ItemStack itemStack = itemFrame.getItem();
if (itemStack == null || itemStack.getType().equals(Material.AIR) || !itemStack.hasItemMeta()) {
return null;
}
ItemMeta itemMeta = itemStack.getItemMeta();
if (!(itemMeta instanceof MapMeta)) {
return null;
}
MapMeta mapMeta = (MapMeta) itemMeta;
if (!mapMeta.hasMapView()) {
return null;
}
MapView mapView = mapMeta.getMapView();
MapView mapView = getItemMapView(itemStack);
if (mapView == null) {
return null;
}
Expand Down
Loading