From cd430775f3a1e18a5e1dc479360e723367540aae Mon Sep 17 00:00:00 2001 From: LOOHP Date: Fri, 21 Nov 2025 22:55:29 +0000 Subject: [PATCH] Iterated design --- V1_16/pom.xml | 2 +- V1_16_2/pom.xml | 2 +- V1_16_4/pom.xml | 2 +- V1_17/pom.xml | 2 +- V1_18/pom.xml | 2 +- V1_18_2/pom.xml | 2 +- V1_19/pom.xml | 2 +- V1_19_3/pom.xml | 2 +- V1_19_4/pom.xml | 2 +- V1_20/pom.xml | 2 +- V1_20_2/pom.xml | 2 +- V1_20_3/pom.xml | 2 +- V1_20_5/pom.xml | 2 +- V1_20_6/pom.xml | 2 +- V1_21/pom.xml | 2 +- V1_21_1/pom.xml | 2 +- V1_21_10/pom.xml | 2 +- V1_21_2/pom.xml | 2 +- V1_21_3/pom.xml | 2 +- V1_21_4/pom.xml | 2 +- V1_21_5/pom.xml | 2 +- V1_21_6/pom.xml | 2 +- V1_21_7/pom.xml | 2 +- V1_21_8/pom.xml | 2 +- V1_21_9/pom.xml | 2 +- abstraction/pom.xml | 2 +- common/pom.xml | 4 +- .../java/com/loohp/imageframe/ImageFrame.java | 3 +- .../imageframe/media/ImageIOMediaLoader.java | 4 ++ .../loohp/imageframe/media/MediaFrame.java | 4 +- .../media/MediaLoadingException.java | 66 ------------------- .../FileLazyMappedBufferedImage.java | 7 +- .../objectholders/ImageMapLoader.java | 18 +++-- .../objectholders/ImageMapLoaderPriority.java | 27 ++++++++ .../objectholders/ImageMapLoaders.java | 4 +- .../LazyMappedBufferedImage.java | 38 +++++++++++ .../MinecraftURLOverlayImageMap.java | 2 +- .../MinecraftURLOverlayImageMapLoader.java | 9 ++- .../NonUpdatableStaticImageMap.java | 6 +- .../NonUpdatableStaticImageMapLoader.java | 9 ++- .../objectholders/URLAnimatedImageMap.java | 23 +++---- .../URLAnimatedImageMapLoader.java | 10 +-- .../objectholders/URLStaticImageMap.java | 6 +- .../URLStaticImageMapLoader.java | 9 ++- pom.xml | 2 +- 45 files changed, 166 insertions(+), 137 deletions(-) delete mode 100644 common/src/main/java/com/loohp/imageframe/media/MediaLoadingException.java create mode 100644 common/src/main/java/com/loohp/imageframe/objectholders/ImageMapLoaderPriority.java create mode 100644 common/src/main/java/com/loohp/imageframe/objectholders/LazyMappedBufferedImage.java diff --git a/V1_16/pom.xml b/V1_16/pom.xml index 040905a..2a8b934 100644 --- a/V1_16/pom.xml +++ b/V1_16/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-V1_16 diff --git a/V1_16_2/pom.xml b/V1_16_2/pom.xml index 48fa510..bb36095 100644 --- a/V1_16_2/pom.xml +++ b/V1_16_2/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-V1_16_2 diff --git a/V1_16_4/pom.xml b/V1_16_4/pom.xml index 6724112..15cfacb 100644 --- a/V1_16_4/pom.xml +++ b/V1_16_4/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-V1_16_4 diff --git a/V1_17/pom.xml b/V1_17/pom.xml index 3e5c5cd..d51dec8 100644 --- a/V1_17/pom.xml +++ b/V1_17/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-V1_17 diff --git a/V1_18/pom.xml b/V1_18/pom.xml index df44e73..fdb5b0f 100644 --- a/V1_18/pom.xml +++ b/V1_18/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-V1_18 diff --git a/V1_18_2/pom.xml b/V1_18_2/pom.xml index 173a9aa..cd7de93 100644 --- a/V1_18_2/pom.xml +++ b/V1_18_2/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-V1_18_2 diff --git a/V1_19/pom.xml b/V1_19/pom.xml index 73b673a..6c8d0a3 100644 --- a/V1_19/pom.xml +++ b/V1_19/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-V1_19 diff --git a/V1_19_3/pom.xml b/V1_19_3/pom.xml index f6524ca..ba682da 100644 --- a/V1_19_3/pom.xml +++ b/V1_19_3/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-V1_19_3 diff --git a/V1_19_4/pom.xml b/V1_19_4/pom.xml index ea8e81f..6661081 100644 --- a/V1_19_4/pom.xml +++ b/V1_19_4/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-V1_19_4 diff --git a/V1_20/pom.xml b/V1_20/pom.xml index 9f60b7f..bbf4c04 100644 --- a/V1_20/pom.xml +++ b/V1_20/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-V1_20 diff --git a/V1_20_2/pom.xml b/V1_20_2/pom.xml index c083f60..55dad1f 100644 --- a/V1_20_2/pom.xml +++ b/V1_20_2/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-V1_20_2 diff --git a/V1_20_3/pom.xml b/V1_20_3/pom.xml index ff7e678..6eef8f6 100644 --- a/V1_20_3/pom.xml +++ b/V1_20_3/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-V1_20_3 diff --git a/V1_20_5/pom.xml b/V1_20_5/pom.xml index 79ecb61..8004d61 100644 --- a/V1_20_5/pom.xml +++ b/V1_20_5/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-V1_20_5 diff --git a/V1_20_6/pom.xml b/V1_20_6/pom.xml index 9fd1db7..dbfcd46 100644 --- a/V1_20_6/pom.xml +++ b/V1_20_6/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-V1_20_6 diff --git a/V1_21/pom.xml b/V1_21/pom.xml index a49f78e..788e141 100644 --- a/V1_21/pom.xml +++ b/V1_21/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-V1_21 diff --git a/V1_21_1/pom.xml b/V1_21_1/pom.xml index 7661230..4079845 100644 --- a/V1_21_1/pom.xml +++ b/V1_21_1/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-V1_21_1 diff --git a/V1_21_10/pom.xml b/V1_21_10/pom.xml index 74f82a7..dcce5b8 100644 --- a/V1_21_10/pom.xml +++ b/V1_21_10/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-V1_21_10 diff --git a/V1_21_2/pom.xml b/V1_21_2/pom.xml index 782e498..b5f63d2 100644 --- a/V1_21_2/pom.xml +++ b/V1_21_2/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-V1_21_2 diff --git a/V1_21_3/pom.xml b/V1_21_3/pom.xml index c9be7b8..a39237c 100644 --- a/V1_21_3/pom.xml +++ b/V1_21_3/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-V1_21_3 diff --git a/V1_21_4/pom.xml b/V1_21_4/pom.xml index 72eaef9..288dd71 100644 --- a/V1_21_4/pom.xml +++ b/V1_21_4/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-V1_21_4 diff --git a/V1_21_5/pom.xml b/V1_21_5/pom.xml index b8cf1b4..fcdd0b6 100644 --- a/V1_21_5/pom.xml +++ b/V1_21_5/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-V1_21_5 diff --git a/V1_21_6/pom.xml b/V1_21_6/pom.xml index 643bc93..943c359 100644 --- a/V1_21_6/pom.xml +++ b/V1_21_6/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-V1_21_6 diff --git a/V1_21_7/pom.xml b/V1_21_7/pom.xml index 6d8043e..4ddf7af 100644 --- a/V1_21_7/pom.xml +++ b/V1_21_7/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-V1_21_7 diff --git a/V1_21_8/pom.xml b/V1_21_8/pom.xml index 2034970..8d3522d 100644 --- a/V1_21_8/pom.xml +++ b/V1_21_8/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-V1_21_8 diff --git a/V1_21_9/pom.xml b/V1_21_9/pom.xml index 37713bd..bf65d3b 100644 --- a/V1_21_9/pom.xml +++ b/V1_21_9/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-V1_21_9 diff --git a/abstraction/pom.xml b/abstraction/pom.xml index c4a5d93..7d53525 100644 --- a/abstraction/pom.xml +++ b/abstraction/pom.xml @@ -27,7 +27,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 ImageFrame-Abstraction diff --git a/common/pom.xml b/common/pom.xml index 8a3f687..7e0474d 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -26,7 +26,7 @@ com.loohp ImageFrame - 1.8.7.2 + 1.8.7.3 jar ImageFrame @@ -66,7 +66,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.2.4 + 3.6.1 package diff --git a/common/src/main/java/com/loohp/imageframe/ImageFrame.java b/common/src/main/java/com/loohp/imageframe/ImageFrame.java index cc3d9b8..b3c9224 100644 --- a/common/src/main/java/com/loohp/imageframe/ImageFrame.java +++ b/common/src/main/java/com/loohp/imageframe/ImageFrame.java @@ -334,7 +334,6 @@ public class ImageFrame extends JavaPlugin { combinedMapItemHandler = new CombinedMapItemHandler(); animatedFakeMapManager = new AnimatedFakeMapManager(); rateLimitedPacketSendingManager = new RateLimitedPacketSendingManager(); - Scheduler.runTaskAsynchronously(this, () -> imageMapManager.loadMaps()); invisibleFrameManager = new InvisibleFrameManager(); imageMapCreationTaskManager = new ImageMapCreationTaskManager(ImageFrame.parallelProcessingLimit); imageUploadManager = new ImageUploadManager(uploadServiceEnabled, uploadServiceServerAddress, uploadServiceServerPort); @@ -346,6 +345,8 @@ public class ImageFrame extends JavaPlugin { ImageMapLoaders.init(); + Scheduler.runTaskAsynchronously(this, () -> imageMapManager.loadMaps()); + getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "[ImageFrame] ImageFrame has been Enabled!"); } diff --git a/common/src/main/java/com/loohp/imageframe/media/ImageIOMediaLoader.java b/common/src/main/java/com/loohp/imageframe/media/ImageIOMediaLoader.java index bc75733..de44fbb 100644 --- a/common/src/main/java/com/loohp/imageframe/media/ImageIOMediaLoader.java +++ b/common/src/main/java/com/loohp/imageframe/media/ImageIOMediaLoader.java @@ -27,6 +27,7 @@ import net.kyori.adventure.key.Key; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; +import java.io.IOException; import java.util.Iterator; public class ImageIOMediaLoader implements MediaLoader { @@ -46,6 +47,9 @@ public class ImageIOMediaLoader implements MediaLoader { @Override public Iterator tryLoad(String url) throws Exception { BufferedImage image = ImageIO.read(new ByteArrayInputStream(HTTPRequestUtils.download(url, ImageFrame.maxImageFileSize))); + if (image == null) { + throw new IOException("ImageIO cannot read media type in " + url); + } return MediaLoader.staticImage(image); } } diff --git a/common/src/main/java/com/loohp/imageframe/media/MediaFrame.java b/common/src/main/java/com/loohp/imageframe/media/MediaFrame.java index 59b2ded..b0cc3f4 100644 --- a/common/src/main/java/com/loohp/imageframe/media/MediaFrame.java +++ b/common/src/main/java/com/loohp/imageframe/media/MediaFrame.java @@ -32,8 +32,8 @@ public class MediaFrame { return new MediaFrame(image, durationMs); } - public final BufferedImage image; - public final int durationMs; + private final BufferedImage image; + private final int durationMs; private MediaFrame(BufferedImage image, int durationMs) { this.image = image; diff --git a/common/src/main/java/com/loohp/imageframe/media/MediaLoadingException.java b/common/src/main/java/com/loohp/imageframe/media/MediaLoadingException.java deleted file mode 100644 index c0e44fd..0000000 --- a/common/src/main/java/com/loohp/imageframe/media/MediaLoadingException.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * This file is part of ImageFrame. - * - * Copyright (C) 2025. LoohpJames - * Copyright (C) 2025. Contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.loohp.imageframe.media; - -import net.kyori.adventure.key.Key; - -import java.io.IOException; -import java.util.List; - -public class MediaLoadingException extends IOException { - - private final List exceptions; - - public MediaLoadingException(String message, List exceptions) { - super(message); - this.exceptions = exceptions; - } - - @Override - public void printStackTrace() { - super.printStackTrace(); - System.err.println("Exceptions for each MediaLoader"); - for (MediaLoadingExceptionEntry entry : exceptions) { - System.err.println("MediaLoader " + entry.getIdentifier().asString()); - entry.getException().printStackTrace(); - } - } - - public static class MediaLoadingExceptionEntry { - - private final Key identifier; - private final Exception exception; - - public MediaLoadingExceptionEntry(Key identifier, Exception exception) { - this.identifier = identifier; - this.exception = exception; - } - - public Key getIdentifier() { - return identifier; - } - - public Exception getException() { - return exception; - } - } - -} diff --git a/common/src/main/java/com/loohp/imageframe/objectholders/FileLazyMappedBufferedImage.java b/common/src/main/java/com/loohp/imageframe/objectholders/FileLazyMappedBufferedImage.java index 24814e0..e0e6c05 100644 --- a/common/src/main/java/com/loohp/imageframe/objectholders/FileLazyMappedBufferedImage.java +++ b/common/src/main/java/com/loohp/imageframe/objectholders/FileLazyMappedBufferedImage.java @@ -26,7 +26,7 @@ import java.io.File; import java.io.IOException; import java.lang.ref.WeakReference; -public class FileLazyMappedBufferedImage { +public class FileLazyMappedBufferedImage implements LazyMappedBufferedImage { public static FileLazyMappedBufferedImage fromFile(File file) { return new FileLazyMappedBufferedImage(file, null, null); @@ -57,10 +57,12 @@ public class FileLazyMappedBufferedImage { this.weakReference = weakReference; } + @Override public File getFile() { return file; } + @Override public boolean canSetFile(File file) { if (this.file != null) { return this.file.equals(file); @@ -68,6 +70,7 @@ public class FileLazyMappedBufferedImage { return file != null; } + @Override public synchronized void setFile(File file) { if (this.file != null) { if (this.file.equals(file)) { @@ -88,6 +91,7 @@ public class FileLazyMappedBufferedImage { this.strongReference = null; } + @Override public synchronized BufferedImage get() { if (strongReference != null) { return strongReference; @@ -105,6 +109,7 @@ public class FileLazyMappedBufferedImage { return image; } + @Override public synchronized BufferedImage getIfLoaded() { if (strongReference != null) { return strongReference; diff --git a/common/src/main/java/com/loohp/imageframe/objectholders/ImageMapLoader.java b/common/src/main/java/com/loohp/imageframe/objectholders/ImageMapLoader.java index 7136594..1924d1d 100644 --- a/common/src/main/java/com/loohp/imageframe/objectholders/ImageMapLoader.java +++ b/common/src/main/java/com/loohp/imageframe/objectholders/ImageMapLoader.java @@ -23,10 +23,10 @@ package com.loohp.imageframe.objectholders; import com.google.gson.JsonObject; import com.loohp.imageframe.media.MediaFrame; import com.loohp.imageframe.media.MediaLoader; -import com.loohp.imageframe.media.MediaLoadingException; import net.kyori.adventure.key.Key; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -55,8 +55,8 @@ public abstract class ImageMapLoader tryLoadMedia(String url) throws MediaLoadingException { - List exceptions = new ArrayList<>(); + public Iterator tryLoadMedia(String url) throws IOException { + List exceptions = new ArrayList<>(); for (MediaLoader mediaLoader : mediaLoaders) { try { if (mediaLoader.shouldTryRead(url)) { return mediaLoader.tryLoad(url); } } catch (Exception e) { - exceptions.add(new MediaLoadingException.MediaLoadingExceptionEntry(mediaLoader.getIdentifier(), e)); + exceptions.add(new IOException("Unable to read or download media with MediaLoader " + mediaLoader.getIdentifier(), e)); } } - throw new MediaLoadingException("Unable to read or download media with ImageMapLoader " + getIdentifier().asString() + ", does this url directly links to the gif? (" + url + ")", exceptions); + IOException e = new IOException("Unable to read or download media with ImageMapLoader " + getIdentifier().asString() + ", does this url directly links to the gif? (" + url + ")"); + for (IOException ex : exceptions) { + e.addSuppressed(ex); + } + throw e; } public abstract Future create(C createInfo) throws Exception; diff --git a/common/src/main/java/com/loohp/imageframe/objectholders/ImageMapLoaderPriority.java b/common/src/main/java/com/loohp/imageframe/objectholders/ImageMapLoaderPriority.java new file mode 100644 index 0000000..9b48023 --- /dev/null +++ b/common/src/main/java/com/loohp/imageframe/objectholders/ImageMapLoaderPriority.java @@ -0,0 +1,27 @@ +/* + * This file is part of ImageFrame. + * + * Copyright (C) 2025. LoohpJames + * Copyright (C) 2025. Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.loohp.imageframe.objectholders; + +public enum ImageMapLoaderPriority { + + LOWEST, LOW, NORMAL, HIGH, HIGHEST; + +} diff --git a/common/src/main/java/com/loohp/imageframe/objectholders/ImageMapLoaders.java b/common/src/main/java/com/loohp/imageframe/objectholders/ImageMapLoaders.java index a1fb1ff..422622f 100644 --- a/common/src/main/java/com/loohp/imageframe/objectholders/ImageMapLoaders.java +++ b/common/src/main/java/com/loohp/imageframe/objectholders/ImageMapLoaders.java @@ -82,7 +82,7 @@ public class ImageMapLoaders { .filter(l -> createInfoClass.equals(l.getImageMapCreateInfoClass())) .filter(l -> l.isSupported(imageType)) .filter(l -> l.getExtraPermissions().stream().allMatch(p -> sender.hasPermission(p))) - .max(Comparator.comparing((ImageMapLoader l) -> l.isPreferred(imageType))) + .max(Comparator.comparing((ImageMapLoader l) -> l.getPriority(imageType))) .orElse(null); } @@ -113,7 +113,7 @@ public class ImageMapLoaders { } } - private static T registerLoader(T loader, ImageMapLoader... imageMapLoaders) { + public static T registerLoader(T loader, ImageMapLoader... imageMapLoaders) { for (ImageMapLoader imageMapLoader : imageMapLoaders) { imageMapLoader.registerMediaLoaderLast(loader); Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.GRAY + "[ImageFrame] Registered MediaLoader " + loader.getIdentifier().asString() + " to ImageMapLoader " + imageMapLoader.getIdentifier().asString()); diff --git a/common/src/main/java/com/loohp/imageframe/objectholders/LazyMappedBufferedImage.java b/common/src/main/java/com/loohp/imageframe/objectholders/LazyMappedBufferedImage.java new file mode 100644 index 0000000..032cfbc --- /dev/null +++ b/common/src/main/java/com/loohp/imageframe/objectholders/LazyMappedBufferedImage.java @@ -0,0 +1,38 @@ +/* + * This file is part of ImageFrame. + * + * Copyright (C) 2025. LoohpJames + * Copyright (C) 2025. Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.loohp.imageframe.objectholders; + +import java.awt.image.BufferedImage; +import java.io.File; + +public interface LazyMappedBufferedImage { + + File getFile(); + + boolean canSetFile(File file); + + void setFile(File file); + + BufferedImage get(); + + BufferedImage getIfLoaded(); + +} diff --git a/common/src/main/java/com/loohp/imageframe/objectholders/MinecraftURLOverlayImageMap.java b/common/src/main/java/com/loohp/imageframe/objectholders/MinecraftURLOverlayImageMap.java index 072a597..db41e15 100644 --- a/common/src/main/java/com/loohp/imageframe/objectholders/MinecraftURLOverlayImageMap.java +++ b/common/src/main/java/com/loohp/imageframe/objectholders/MinecraftURLOverlayImageMap.java @@ -35,7 +35,7 @@ import java.util.UUID; public class MinecraftURLOverlayImageMap extends URLStaticImageMap { - protected MinecraftURLOverlayImageMap(ImageMapManager manager, ImageMapLoader loader, int imageIndex, String name, String url, FileLazyMappedBufferedImage[] cachedImages, List mapViews, List mapIds, List> mapMarkers, int width, int height, DitheringType ditheringType, UUID creator, Map hasAccess, long creationTime) { + protected MinecraftURLOverlayImageMap(ImageMapManager manager, ImageMapLoader loader, int imageIndex, String name, String url, LazyMappedBufferedImage[] cachedImages, List mapViews, List mapIds, List> mapMarkers, int width, int height, DitheringType ditheringType, UUID creator, Map hasAccess, long creationTime) { super(manager, loader, imageIndex, name, url, cachedImages, mapViews, mapIds, mapMarkers, width, height, ditheringType, creator, hasAccess, creationTime); } diff --git a/common/src/main/java/com/loohp/imageframe/objectholders/MinecraftURLOverlayImageMapLoader.java b/common/src/main/java/com/loohp/imageframe/objectholders/MinecraftURLOverlayImageMapLoader.java index d135898..23c6055 100644 --- a/common/src/main/java/com/loohp/imageframe/objectholders/MinecraftURLOverlayImageMapLoader.java +++ b/common/src/main/java/com/loohp/imageframe/objectholders/MinecraftURLOverlayImageMapLoader.java @@ -77,6 +77,11 @@ public class MinecraftURLOverlayImageMapLoader extends ImageMapLoader create(MinecraftURLOverlayImageMapCreateInfo createInfo) throws Exception { int mapsCount = createInfo.getWidth() * createInfo.getHeight(); @@ -93,7 +98,7 @@ public class MinecraftURLOverlayImageMapLoader extends ImageMapLoader()); } - MinecraftURLOverlayImageMap map = new MinecraftURLOverlayImageMap(createInfo.getManager(), this, -1, createInfo.getName(), createInfo.getUrl(), new FileLazyMappedBufferedImage[mapsCount], mapViews, mapIds, markers, createInfo.getWidth(), createInfo.getHeight(), createInfo.getDitheringType(), createInfo.getCreator(), Collections.emptyMap(), System.currentTimeMillis()); + MinecraftURLOverlayImageMap map = new MinecraftURLOverlayImageMap(createInfo.getManager(), this, -1, createInfo.getName(), createInfo.getUrl(), new LazyMappedBufferedImage[mapsCount], mapViews, mapIds, markers, createInfo.getWidth(), createInfo.getHeight(), createInfo.getDitheringType(), createInfo.getCreator(), Collections.emptyMap(), System.currentTimeMillis()); return FutureUtils.callAsyncMethod(() -> { FutureUtils.callSyncMethod(() -> { for (int i = 0; i < mapViews.size(); i++) { @@ -128,7 +133,7 @@ public class MinecraftURLOverlayImageMapLoader extends ImageMapLoader> mapViewsFuture = new ArrayList<>(mapDataJson.size()); List mapIds = new ArrayList<>(mapDataJson.size()); - FileLazyMappedBufferedImage[] cachedImages = new FileLazyMappedBufferedImage[mapDataJson.size()]; + LazyMappedBufferedImage[] cachedImages = new LazyMappedBufferedImage[mapDataJson.size()]; List> markers = new ArrayList<>(mapDataJson.size()); World world = Bukkit.getWorlds().get(0); int i = 0; diff --git a/common/src/main/java/com/loohp/imageframe/objectholders/NonUpdatableStaticImageMap.java b/common/src/main/java/com/loohp/imageframe/objectholders/NonUpdatableStaticImageMap.java index 69a2927..9404a8c 100644 --- a/common/src/main/java/com/loohp/imageframe/objectholders/NonUpdatableStaticImageMap.java +++ b/common/src/main/java/com/loohp/imageframe/objectholders/NonUpdatableStaticImageMap.java @@ -43,11 +43,11 @@ import java.util.UUID; public class NonUpdatableStaticImageMap extends ImageMap { - protected final FileLazyMappedBufferedImage[] cachedImages; + protected final LazyMappedBufferedImage[] cachedImages; protected byte[][] cachedColors; - protected NonUpdatableStaticImageMap(ImageMapManager manager, ImageMapLoader loader, int imageIndex, String name, FileLazyMappedBufferedImage[] cachedImages, List mapViews, List mapIds, List> mapMarkers, int width, int height, DitheringType ditheringType, UUID creator, Map hasAccess, long creationTime) { + protected NonUpdatableStaticImageMap(ImageMapManager manager, ImageMapLoader loader, int imageIndex, String name, LazyMappedBufferedImage[] cachedImages, List mapViews, List mapIds, List> mapMarkers, int width, int height, DitheringType ditheringType, UUID creator, Map hasAccess, long creationTime) { super(manager, loader, imageIndex, name, mapViews, mapIds, mapMarkers, width, height, ditheringType, creator, hasAccess, creationTime); this.cachedImages = cachedImages; this.cacheControlTask.loadCacheIfManual(); @@ -65,7 +65,7 @@ public class NonUpdatableStaticImageMap extends ImageMap { BufferedImage combined = new BufferedImage(width * MapUtils.MAP_WIDTH, height * MapUtils.MAP_WIDTH, BufferedImage.TYPE_INT_ARGB); Graphics2D g = combined.createGraphics(); int index = 0; - for (FileLazyMappedBufferedImage image : cachedImages) { + for (LazyMappedBufferedImage image : cachedImages) { g.drawImage(image.get(), (index % width) * MapUtils.MAP_WIDTH, (index / width) * MapUtils.MAP_WIDTH, null); index++; } diff --git a/common/src/main/java/com/loohp/imageframe/objectholders/NonUpdatableStaticImageMapLoader.java b/common/src/main/java/com/loohp/imageframe/objectholders/NonUpdatableStaticImageMapLoader.java index 6bd8f11..b7ae985 100644 --- a/common/src/main/java/com/loohp/imageframe/objectholders/NonUpdatableStaticImageMapLoader.java +++ b/common/src/main/java/com/loohp/imageframe/objectholders/NonUpdatableStaticImageMapLoader.java @@ -82,6 +82,11 @@ public class NonUpdatableStaticImageMapLoader extends ImageMapLoader create(NonUpdatableImageMapCreateInfo createInfo) throws Exception { World world = MapUtils.getMainWorld(); @@ -117,7 +122,7 @@ public class NonUpdatableStaticImageMapLoader extends ImageMapLoader FileLazyMappedBufferedImage.fromImage(i)).toArray(FileLazyMappedBufferedImage[]::new), mapViews, mapIds, markers, createInfo.getWidth(), createInfo.getHeight(), createInfo.getDitheringType(), createInfo.getCreator(), Collections.emptyMap(), System.currentTimeMillis()); + NonUpdatableStaticImageMap map = new NonUpdatableStaticImageMap(createInfo.getManager(), this, -1, createInfo.getName(), Arrays.stream(images).map(i -> FileLazyMappedBufferedImage.fromImage(i)).toArray(LazyMappedBufferedImage[]::new), mapViews, mapIds, markers, createInfo.getWidth(), createInfo.getHeight(), createInfo.getDitheringType(), createInfo.getCreator(), Collections.emptyMap(), System.currentTimeMillis()); return FutureUtils.callAsyncMethod(() -> { FutureUtils.callSyncMethod(() -> { for (int i = 0; i < mapViews.size(); i++) { @@ -151,7 +156,7 @@ public class NonUpdatableStaticImageMapLoader extends ImageMapLoader> mapViewsFuture = new ArrayList<>(mapDataJson.size()); List mapIds = new ArrayList<>(mapDataJson.size()); - FileLazyMappedBufferedImage[] cachedImages = new FileLazyMappedBufferedImage[mapDataJson.size()]; + LazyMappedBufferedImage[] cachedImages = new LazyMappedBufferedImage[mapDataJson.size()]; List> markers = new ArrayList<>(mapDataJson.size()); World world = Bukkit.getWorlds().get(0); int i = 0; diff --git a/common/src/main/java/com/loohp/imageframe/objectholders/URLAnimatedImageMap.java b/common/src/main/java/com/loohp/imageframe/objectholders/URLAnimatedImageMap.java index 30f62a5..f39791d 100644 --- a/common/src/main/java/com/loohp/imageframe/objectholders/URLAnimatedImageMap.java +++ b/common/src/main/java/com/loohp/imageframe/objectholders/URLAnimatedImageMap.java @@ -49,7 +49,7 @@ import java.util.UUID; public class URLAnimatedImageMap extends URLImageMap { - protected final FileLazyMappedBufferedImage[][] cachedImages; + protected final LazyMappedBufferedImage[][] cachedImages; protected byte[][][] cachedColors; protected int[][] fakeMapIds; @@ -57,7 +57,7 @@ public class URLAnimatedImageMap extends URLImageMap { protected int pausedAt; protected int tickOffset; - protected URLAnimatedImageMap(ImageMapManager manager, ImageMapLoader loader, int imageIndex, String name, String url, FileLazyMappedBufferedImage[][] cachedImages, List mapViews, List mapIds, List> mapMarkers, int width, int height, DitheringType ditheringType, UUID creator, Map hasAccess, long creationTime, int pausedAt, int tickOffset) { + protected URLAnimatedImageMap(ImageMapManager manager, ImageMapLoader loader, int imageIndex, String name, String url, LazyMappedBufferedImage[][] cachedImages, List mapViews, List mapIds, List> mapMarkers, int width, int height, DitheringType ditheringType, UUID creator, Map hasAccess, long creationTime, int pausedAt, int tickOffset) { super(manager, loader, imageIndex, name, url, mapViews, mapIds, mapMarkers, width, height, ditheringType, creator, hasAccess, creationTime); this.cachedImages = cachedImages; this.pausedAt = pausedAt; @@ -82,10 +82,11 @@ public class URLAnimatedImageMap extends URLImageMap { } Graphics2D[] g = Arrays.stream(combined).map(i -> i.createGraphics()).toArray(Graphics2D[]::new); int index = 0; - for (FileLazyMappedBufferedImage[] images : cachedImages) { + for (LazyMappedBufferedImage[] images : cachedImages) { int f = 0; - for (FileLazyMappedBufferedImage image : images) { - g[f++].drawImage(image.get(), (index % width) * MapUtils.MAP_WIDTH, (index / width) * MapUtils.MAP_WIDTH, null); + for (LazyMappedBufferedImage image : images) { + //noinspection SuspiciousNameCombination + g[f++].drawImage(image.get(), (index % width) * MapUtils.MAP_WIDTH, (index / width) * MapUtils.MAP_WIDTH, MapUtils.MAP_WIDTH, MapUtils.MAP_WIDTH, null); } index++; } @@ -97,7 +98,7 @@ public class URLAnimatedImageMap extends URLImageMap { combinedData[i] = MapUtils.toMapPaletteBytes(combined[i], ditheringType); } int i = 0; - for (FileLazyMappedBufferedImage[] images : cachedImages) { + for (LazyMappedBufferedImage[] images : cachedImages) { byte[][] data = new byte[images.length][]; int[] mapIds = new int[data.length]; Arrays.fill(mapIds, -1); @@ -139,10 +140,10 @@ public class URLAnimatedImageMap extends URLImageMap { public void update(boolean save) throws Exception { List images = CollectionUtils.toList(new TimedMediaFrameIterator(loader.tryLoadMedia(url), 50)); for (int i = 0; i < cachedImages.length; i++) { - cachedImages[i] = new FileLazyMappedBufferedImage[images.size()]; + cachedImages[i] = new LazyMappedBufferedImage[images.size()]; } int index = 0; - Map previousImages = new HashMap<>(); + Map previousImages = new HashMap<>(); for (BufferedImage image : images) { image = MapUtils.resize(image, width, height); int i = 0; @@ -150,8 +151,8 @@ public class URLAnimatedImageMap extends URLImageMap { for (int x = 0; x < width; x++) { IntPosition intPosition = new IntPosition(x, y); BufferedImage subImage = MapUtils.getSubImage(image, x, y); - FileLazyMappedBufferedImage previousFile = previousImages.get(intPosition); - FileLazyMappedBufferedImage file; + LazyMappedBufferedImage previousFile = previousImages.get(intPosition); + LazyMappedBufferedImage file; if (previousFile == null || !MapUtils.areImagesEqual(subImage, previousFile.getIfLoaded())) { file = FileLazyMappedBufferedImage.fromImage(subImage); } else { @@ -338,7 +339,7 @@ public class URLAnimatedImageMap extends URLImageMap { JsonObject dataJson = new JsonObject(); dataJson.addProperty("mapid", mapIds.get(i)); JsonArray framesArray = new JsonArray(); - for (FileLazyMappedBufferedImage image : cachedImages[i]) { + for (LazyMappedBufferedImage image : cachedImages[i]) { int index = u++; File file = new File(folder, index + ".png"); if (image.canSetFile(file)) { diff --git a/common/src/main/java/com/loohp/imageframe/objectholders/URLAnimatedImageMapLoader.java b/common/src/main/java/com/loohp/imageframe/objectholders/URLAnimatedImageMapLoader.java index 63a883e..2c7cc72 100644 --- a/common/src/main/java/com/loohp/imageframe/objectholders/URLAnimatedImageMapLoader.java +++ b/common/src/main/java/com/loohp/imageframe/objectholders/URLAnimatedImageMapLoader.java @@ -80,8 +80,8 @@ public class URLAnimatedImageMapLoader extends ImageMapLoader { FutureUtils.callSyncMethod(() -> { for (int i = 0; i < mapViews.size(); i++) { @@ -141,7 +141,7 @@ public class URLAnimatedImageMapLoader extends ImageMapLoader> mapViewsFuture = new ArrayList<>(mapDataJson.size()); List mapIds = new ArrayList<>(mapDataJson.size()); - FileLazyMappedBufferedImage[][] cachedImages = new FileLazyMappedBufferedImage[mapDataJson.size()][]; + LazyMappedBufferedImage[][] cachedImages = new LazyMappedBufferedImage[mapDataJson.size()][]; List> markers = new ArrayList<>(mapDataJson.size()); World world = Bukkit.getWorlds().get(0); int i = 0; @@ -151,7 +151,7 @@ public class URLAnimatedImageMapLoader extends ImageMapLoader loader, int imageIndex, String name, String url, FileLazyMappedBufferedImage[] cachedImages, List mapViews, List mapIds, List> mapMarkers, int width, int height, DitheringType ditheringType, UUID creator, Map hasAccess, long creationTime) { + protected URLStaticImageMap(ImageMapManager manager, ImageMapLoader loader, int imageIndex, String name, String url, LazyMappedBufferedImage[] cachedImages, List mapViews, List mapIds, List> mapMarkers, int width, int height, DitheringType ditheringType, UUID creator, Map hasAccess, long creationTime) { super(manager, loader, imageIndex, name, url, mapViews, mapIds, mapMarkers, width, height, ditheringType, creator, hasAccess, creationTime); this.cachedImages = cachedImages; this.cacheControlTask.loadCacheIfManual(); @@ -76,7 +76,7 @@ public class URLStaticImageMap extends URLImageMap { BufferedImage combined = new BufferedImage(width * MapUtils.MAP_WIDTH, height * MapUtils.MAP_WIDTH, BufferedImage.TYPE_INT_ARGB); Graphics2D g = combined.createGraphics(); int index = 0; - for (FileLazyMappedBufferedImage image : cachedImages) { + for (LazyMappedBufferedImage image : cachedImages) { g.drawImage(resizeImageFillWidth(image.get(), MapUtils.MAP_WIDTH), (index % width) * MapUtils.MAP_WIDTH, (index / width) * MapUtils.MAP_WIDTH, null); index++; } diff --git a/common/src/main/java/com/loohp/imageframe/objectholders/URLStaticImageMapLoader.java b/common/src/main/java/com/loohp/imageframe/objectholders/URLStaticImageMapLoader.java index ccf3f53..08b740e 100644 --- a/common/src/main/java/com/loohp/imageframe/objectholders/URLStaticImageMapLoader.java +++ b/common/src/main/java/com/loohp/imageframe/objectholders/URLStaticImageMapLoader.java @@ -80,6 +80,11 @@ public class URLStaticImageMapLoader extends ImageMapLoader create(URLImageMapCreateInfo createInfo) throws Exception { World world = MapUtils.getMainWorld(); @@ -106,7 +111,7 @@ public class URLStaticImageMapLoader extends ImageMapLoader { FutureUtils.callSyncMethod(() -> { for (int i = 0; i < mapViews.size(); i++) { @@ -141,7 +146,7 @@ public class URLStaticImageMapLoader extends ImageMapLoader> mapViewsFuture = new ArrayList<>(mapDataJson.size()); List mapIds = new ArrayList<>(mapDataJson.size()); - FileLazyMappedBufferedImage[] cachedImages = new FileLazyMappedBufferedImage[mapDataJson.size()]; + LazyMappedBufferedImage[] cachedImages = new LazyMappedBufferedImage[mapDataJson.size()]; List> markers = new ArrayList<>(mapDataJson.size()); World world = Bukkit.getWorlds().get(0); int i = 0; diff --git a/pom.xml b/pom.xml index f877bf3..ce8fc61 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ com.loohp ImageFrame-Parent - 1.8.7.2 + 1.8.7.3 pom