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;
}
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;
}
}

}
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