Iterated design
This commit is contained in:
1 parent
d035989df5
commit
cd430775f3
45 files changed
+166
-137
No files matched your search
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-V1_16</artifactId>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-V1_16_2</artifactId>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-V1_16_4</artifactId>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-V1_17</artifactId>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-V1_18</artifactId>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-V1_18_2</artifactId>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-V1_19</artifactId>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-V1_19_3</artifactId>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-V1_19_4</artifactId>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-V1_20</artifactId>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-V1_20_2</artifactId>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-V1_20_3</artifactId>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-V1_20_5</artifactId>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-V1_20_6</artifactId>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-V1_21</artifactId>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-V1_21_1</artifactId>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-V1_21_10</artifactId>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-V1_21_2</artifactId>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-V1_21_3</artifactId>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-V1_21_4</artifactId>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-V1_21_5</artifactId>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-V1_21_6</artifactId>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-V1_21_7</artifactId>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-V1_21_8</artifactId>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-V1_21_9</artifactId>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
<parent>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame-Parent</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ImageFrame-Abstraction</artifactId>
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@
|
||||
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>ImageFrame</artifactId>
|
||||
<version>1.8.7.2</version>
|
||||
<version>1.8.7.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>ImageFrame</name>
|
||||
@@ -66,7 +66,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<version>3.6.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
|
||||
@@ -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!");
|
||||
}
|
||||
|
||||
|
||||
@@ -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<MediaFrame> 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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* This file is part of ImageFrame.
|
||||
*
|
||||
* Copyright (C) 2025. LoohpJames <jamesloohp@gmail.com>
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<MediaLoadingExceptionEntry> exceptions;
|
||||
|
||||
public MediaLoadingException(String message, List<MediaLoadingExceptionEntry> 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+6
-1
@@ -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;
|
||||
|
||||
@@ -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<T extends ImageMap, C extends ImageMapCreat
|
||||
|
||||
public abstract boolean isSupported(String imageType);
|
||||
|
||||
public boolean isPreferred(String imageType) {
|
||||
return false;
|
||||
public ImageMapLoaderPriority getPriority(String imageType) {
|
||||
return ImageMapLoaderPriority.NORMAL;
|
||||
}
|
||||
|
||||
public void registerMediaLoaderFirst(MediaLoader mediaLoader) {
|
||||
@@ -94,18 +94,22 @@ public abstract class ImageMapLoader<T extends ImageMap, C extends ImageMapCreat
|
||||
return -1;
|
||||
}
|
||||
|
||||
public Iterator<MediaFrame> tryLoadMedia(String url) throws MediaLoadingException {
|
||||
List<MediaLoadingException.MediaLoadingExceptionEntry> exceptions = new ArrayList<>();
|
||||
public Iterator<MediaFrame> tryLoadMedia(String url) throws IOException {
|
||||
List<IOException> 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<T> create(C createInfo) throws Exception;
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* This file is part of ImageFrame.
|
||||
*
|
||||
* Copyright (C) 2025. LoohpJames <jamesloohp@gmail.com>
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.loohp.imageframe.objectholders;
|
||||
|
||||
public enum ImageMapLoaderPriority {
|
||||
|
||||
LOWEST, LOW, NORMAL, HIGH, HIGHEST;
|
||||
|
||||
}
|
||||
@@ -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 extends MediaLoader> T registerLoader(T loader, ImageMapLoader<?, ?>... imageMapLoaders) {
|
||||
public static <T extends MediaLoader> 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());
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* This file is part of ImageFrame.
|
||||
*
|
||||
* Copyright (C) 2025. LoohpJames <jamesloohp@gmail.com>
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
+1
-1
@@ -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<MapView> mapViews, List<Integer> mapIds, List<Map<String, MapCursor>> mapMarkers, int width, int height, DitheringType ditheringType, UUID creator, Map<UUID, ImageMapAccessPermissionType> hasAccess, long creationTime) {
|
||||
protected MinecraftURLOverlayImageMap(ImageMapManager manager, ImageMapLoader<?, ?> loader, int imageIndex, String name, String url, LazyMappedBufferedImage[] cachedImages, List<MapView> mapViews, List<Integer> mapIds, List<Map<String, MapCursor>> mapMarkers, int width, int height, DitheringType ditheringType, UUID creator, Map<UUID, ImageMapAccessPermissionType> hasAccess, long creationTime) {
|
||||
super(manager, loader, imageIndex, name, url, cachedImages, mapViews, mapIds, mapMarkers, width, height, ditheringType, creator, hasAccess, creationTime);
|
||||
}
|
||||
|
||||
|
||||
+7
-2
@@ -77,6 +77,11 @@ public class MinecraftURLOverlayImageMapLoader extends ImageMapLoader<MinecraftU
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageMapLoaderPriority getPriority(String imageType) {
|
||||
return ImageMapLoaderPriority.LOWEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<MinecraftURLOverlayImageMap> create(MinecraftURLOverlayImageMapCreateInfo createInfo) throws Exception {
|
||||
int mapsCount = createInfo.getWidth() * createInfo.getHeight();
|
||||
@@ -93,7 +98,7 @@ public class MinecraftURLOverlayImageMapLoader extends ImageMapLoader<MinecraftU
|
||||
}
|
||||
markers.add(new ConcurrentHashMap<>());
|
||||
}
|
||||
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<MinecraftU
|
||||
JsonArray mapDataJson = json.get("mapdata").getAsJsonArray();
|
||||
List<Future<MapView>> mapViewsFuture = new ArrayList<>(mapDataJson.size());
|
||||
List<Integer> mapIds = new ArrayList<>(mapDataJson.size());
|
||||
FileLazyMappedBufferedImage[] cachedImages = new FileLazyMappedBufferedImage[mapDataJson.size()];
|
||||
LazyMappedBufferedImage[] cachedImages = new LazyMappedBufferedImage[mapDataJson.size()];
|
||||
List<Map<String, MapCursor>> markers = new ArrayList<>(mapDataJson.size());
|
||||
World world = Bukkit.getWorlds().get(0);
|
||||
int i = 0;
|
||||
|
||||
+3
-3
@@ -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<MapView> mapViews, List<Integer> mapIds, List<Map<String, MapCursor>> mapMarkers, int width, int height, DitheringType ditheringType, UUID creator, Map<UUID, ImageMapAccessPermissionType> hasAccess, long creationTime) {
|
||||
protected NonUpdatableStaticImageMap(ImageMapManager manager, ImageMapLoader<?, ?> loader, int imageIndex, String name, LazyMappedBufferedImage[] cachedImages, List<MapView> mapViews, List<Integer> mapIds, List<Map<String, MapCursor>> mapMarkers, int width, int height, DitheringType ditheringType, UUID creator, Map<UUID, ImageMapAccessPermissionType> 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++;
|
||||
}
|
||||
|
||||
+7
-2
@@ -82,6 +82,11 @@ public class NonUpdatableStaticImageMapLoader extends ImageMapLoader<NonUpdatabl
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageMapLoaderPriority getPriority(String imageType) {
|
||||
return ImageMapLoaderPriority.LOWEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<NonUpdatableStaticImageMap> create(NonUpdatableImageMapCreateInfo createInfo) throws Exception {
|
||||
World world = MapUtils.getMainWorld();
|
||||
@@ -117,7 +122,7 @@ public class NonUpdatableStaticImageMapLoader extends ImageMapLoader<NonUpdatabl
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
NonUpdatableStaticImageMap map = new NonUpdatableStaticImageMap(createInfo.getManager(), this, -1, createInfo.getName(), Arrays.stream(images).map(i -> 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<NonUpdatabl
|
||||
JsonArray mapDataJson = json.get("mapdata").getAsJsonArray();
|
||||
List<Future<MapView>> mapViewsFuture = new ArrayList<>(mapDataJson.size());
|
||||
List<Integer> mapIds = new ArrayList<>(mapDataJson.size());
|
||||
FileLazyMappedBufferedImage[] cachedImages = new FileLazyMappedBufferedImage[mapDataJson.size()];
|
||||
LazyMappedBufferedImage[] cachedImages = new LazyMappedBufferedImage[mapDataJson.size()];
|
||||
List<Map<String, MapCursor>> markers = new ArrayList<>(mapDataJson.size());
|
||||
World world = Bukkit.getWorlds().get(0);
|
||||
int i = 0;
|
||||
|
||||
@@ -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<MapView> mapViews, List<Integer> mapIds, List<Map<String, MapCursor>> mapMarkers, int width, int height, DitheringType ditheringType, UUID creator, Map<UUID, ImageMapAccessPermissionType> hasAccess, long creationTime, int pausedAt, int tickOffset) {
|
||||
protected URLAnimatedImageMap(ImageMapManager manager, ImageMapLoader<?, ?> loader, int imageIndex, String name, String url, LazyMappedBufferedImage[][] cachedImages, List<MapView> mapViews, List<Integer> mapIds, List<Map<String, MapCursor>> mapMarkers, int width, int height, DitheringType ditheringType, UUID creator, Map<UUID, ImageMapAccessPermissionType> 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<BufferedImage> 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<IntPosition, FileLazyMappedBufferedImage> previousImages = new HashMap<>();
|
||||
Map<IntPosition, LazyMappedBufferedImage> 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)) {
|
||||
|
||||
+5
-5
@@ -80,8 +80,8 @@ public class URLAnimatedImageMapLoader extends ImageMapLoader<URLAnimatedImageMa
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPreferred(String imageType) {
|
||||
return isSupported(imageType);
|
||||
public ImageMapLoaderPriority getPriority(String imageType) {
|
||||
return isSupported(imageType) ? ImageMapLoaderPriority.LOW : super.getPriority(imageType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -106,7 +106,7 @@ public class URLAnimatedImageMapLoader extends ImageMapLoader<URLAnimatedImageMa
|
||||
mapViews.add(mapView);
|
||||
mapIds.add(mapView.getId());
|
||||
}
|
||||
URLAnimatedImageMap map = new URLAnimatedImageMap(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(), -1, 0);
|
||||
URLAnimatedImageMap map = new URLAnimatedImageMap(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(), -1, 0);
|
||||
return FutureUtils.callAsyncMethod(() -> {
|
||||
FutureUtils.callSyncMethod(() -> {
|
||||
for (int i = 0; i < mapViews.size(); i++) {
|
||||
@@ -141,7 +141,7 @@ public class URLAnimatedImageMapLoader extends ImageMapLoader<URLAnimatedImageMa
|
||||
JsonArray mapDataJson = json.get("mapdata").getAsJsonArray();
|
||||
List<Future<MapView>> mapViewsFuture = new ArrayList<>(mapDataJson.size());
|
||||
List<Integer> mapIds = new ArrayList<>(mapDataJson.size());
|
||||
FileLazyMappedBufferedImage[][] cachedImages = new FileLazyMappedBufferedImage[mapDataJson.size()][];
|
||||
LazyMappedBufferedImage[][] cachedImages = new LazyMappedBufferedImage[mapDataJson.size()][];
|
||||
List<Map<String, MapCursor>> markers = new ArrayList<>(mapDataJson.size());
|
||||
World world = Bukkit.getWorlds().get(0);
|
||||
int i = 0;
|
||||
@@ -151,7 +151,7 @@ public class URLAnimatedImageMapLoader extends ImageMapLoader<URLAnimatedImageMa
|
||||
mapIds.add(mapId);
|
||||
mapViewsFuture.add(MapUtils.getMapOrCreateMissing(world, mapId));
|
||||
JsonArray framesArray = jsonObject.get("images").getAsJsonArray();
|
||||
FileLazyMappedBufferedImage[] images = new FileLazyMappedBufferedImage[framesArray.size()];
|
||||
LazyMappedBufferedImage[] images = new LazyMappedBufferedImage[framesArray.size()];
|
||||
int u = 0;
|
||||
for (JsonElement element : framesArray) {
|
||||
images[u++] = FileLazyMappedBufferedImage.fromFile(new File(folder, element.getAsString()));
|
||||
|
||||
@@ -45,11 +45,11 @@ import static com.loohp.imageframe.utils.ImageUtils.resizeImageFillWidth;
|
||||
|
||||
public class URLStaticImageMap extends URLImageMap {
|
||||
|
||||
protected final FileLazyMappedBufferedImage[] cachedImages;
|
||||
protected final LazyMappedBufferedImage[] cachedImages;
|
||||
|
||||
protected byte[][] cachedColors;
|
||||
|
||||
protected URLStaticImageMap(ImageMapManager manager, ImageMapLoader<?, ?> loader, int imageIndex, String name, String url, FileLazyMappedBufferedImage[] cachedImages, List<MapView> mapViews, List<Integer> mapIds, List<Map<String, MapCursor>> mapMarkers, int width, int height, DitheringType ditheringType, UUID creator, Map<UUID, ImageMapAccessPermissionType> hasAccess, long creationTime) {
|
||||
protected URLStaticImageMap(ImageMapManager manager, ImageMapLoader<?, ?> loader, int imageIndex, String name, String url, LazyMappedBufferedImage[] cachedImages, List<MapView> mapViews, List<Integer> mapIds, List<Map<String, MapCursor>> mapMarkers, int width, int height, DitheringType ditheringType, UUID creator, Map<UUID, ImageMapAccessPermissionType> 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++;
|
||||
}
|
||||
|
||||
+7
-2
@@ -80,6 +80,11 @@ public class URLStaticImageMapLoader extends ImageMapLoader<URLStaticImageMap, U
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageMapLoaderPriority getPriority(String imageType) {
|
||||
return ImageMapLoaderPriority.LOWEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<URLStaticImageMap> create(URLImageMapCreateInfo createInfo) throws Exception {
|
||||
World world = MapUtils.getMainWorld();
|
||||
@@ -106,7 +111,7 @@ public class URLStaticImageMapLoader extends ImageMapLoader<URLStaticImageMap, U
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
URLStaticImageMap map = new URLStaticImageMap(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());
|
||||
URLStaticImageMap map = new URLStaticImageMap(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++) {
|
||||
@@ -141,7 +146,7 @@ public class URLStaticImageMapLoader extends ImageMapLoader<URLStaticImageMap, U
|
||||
JsonArray mapDataJson = json.get("mapdata").getAsJsonArray();
|
||||
List<Future<MapView>> mapViewsFuture = new ArrayList<>(mapDataJson.size());
|
||||
List<Integer> mapIds = new ArrayList<>(mapDataJson.size());
|
||||
FileLazyMappedBufferedImage[] cachedImages = new FileLazyMappedBufferedImage[mapDataJson.size()];
|
||||
LazyMappedBufferedImage[] cachedImages = new LazyMappedBufferedImage[mapDataJson.size()];
|
||||
List<Map<String, MapCursor>> markers = new ArrayList<>(mapDataJson.size());
|
||||
World world = Bukkit.getWorlds().get(0);
|
||||
int i = 0;
|
||||
|
||||
Reference in new issue
Block a user