Add access sharing of image maps and reworked commands

This commit is contained in:
LOOHP committed 2022-12-05 00:39:10 +00:00
1 parent 6f1538bc0a
commit 8e1da37d1b
12 files changed
+469 -697

No files matched your search

+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>com.loohp</groupId>
<artifactId>ImageFrame</artifactId>
<version>1.5.1.0</version>
<version>1.6.0.0</version>
<packaging>jar</packaging>
<name>ImageFrame</name>
File diff suppressed because it is too large. Load diff
@@ -26,6 +26,7 @@ import com.loohp.imageframe.listeners.Events;
import com.loohp.imageframe.metrics.Charts;
import com.loohp.imageframe.metrics.Metrics;
import com.loohp.imageframe.objectholders.CombinedMapItemHandler;
import com.loohp.imageframe.objectholders.ImageMap;
import com.loohp.imageframe.objectholders.ImageMapManager;
import com.loohp.imageframe.objectholders.ItemFrameSelectionManager;
import com.loohp.imageframe.objectholders.MapMarkerEditManager;
@@ -35,6 +36,7 @@ import com.loohp.imageframe.utils.MCVersion;
import com.twelvemonkeys.imageio.plugins.webp.WebPImageReaderSpi;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
@@ -43,6 +45,7 @@ import javax.imageio.spi.IIORegistry;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -68,8 +71,8 @@ public class ImageFrame extends JavaPlugin {
public static String messageImageMapDeleted;
public static String messageImageMapRenamed;
public static String messageImageMapUpdated;
public static String messageNotCreator;
public static String messageUnableToLoadMap;
public static String messageUnknownError;
public static String messageImageOverMaxFileSize;
public static String messageNotAnImageMap;
public static List<String> messageURLImageMapInfo;
@@ -77,6 +80,9 @@ public class ImageFrame extends JavaPlugin {
public static String messageNoConsole;
public static String messageInvalidUsage;
public static String messageNotEnoughSpace;
public static String messageAccessUpdated;
public static Map<ImageMap.ImageMapAccessPermissionType, String> messageAccessTypes;
public static String messageAccessNoneType;
public static String messageNotEnoughMaps;
public static String messageURLRestricted;
public static String messagePlayerCreationLimitReached;
@@ -152,6 +158,19 @@ public class ImageFrame extends JavaPlugin {
return limit;
}
public static boolean hasImageMapPermission(ImageMap imageMap, CommandSender sender, ImageMap.ImageMapAccessPermissionType permissionType) {
if (permissionType == null) {
return true;
}
if (sender.hasPermission("imageframe.adminbypass")) {
return true;
}
if (!(sender instanceof Player)) {
return false;
}
return imageMap.hasPermission(((Player) sender).getUniqueId(), permissionType);
}
@Override
public void onEnable() {
plugin = this;
@@ -223,8 +242,8 @@ public class ImageFrame extends JavaPlugin {
messageImageMapDeleted = ChatColorUtils.translateAlternateColorCodes('&', config.getConfiguration().getString("Messages.ImageMapDeleted"));
messageImageMapRenamed = ChatColorUtils.translateAlternateColorCodes('&', config.getConfiguration().getString("Messages.ImageMapRenamed"));
messageImageMapUpdated = ChatColorUtils.translateAlternateColorCodes('&', config.getConfiguration().getString("Messages.ImageMapUpdated"));
messageNotCreator = ChatColorUtils.translateAlternateColorCodes('&', config.getConfiguration().getString("Messages.NotCreator"));
messageUnableToLoadMap = ChatColorUtils.translateAlternateColorCodes('&', config.getConfiguration().getString("Messages.UnableToLoadMap"));
messageUnknownError = ChatColorUtils.translateAlternateColorCodes('&', config.getConfiguration().getString("Messages.UnknownError"));
messageImageOverMaxFileSize = ChatColorUtils.translateAlternateColorCodes('&', config.getConfiguration().getString("Messages.ImageOverMaxFileSize"));
messageNotAnImageMap = ChatColorUtils.translateAlternateColorCodes('&', config.getConfiguration().getString("Messages.NotAnImageMap"));
messageURLImageMapInfo = config.getConfiguration().getStringList("Messages.URLImageMapInfo").stream().map(each -> ChatColorUtils.translateAlternateColorCodes('&', each)).collect(Collectors.toList());
@@ -232,6 +251,12 @@ public class ImageFrame extends JavaPlugin {
messageNoConsole = ChatColorUtils.translateAlternateColorCodes('&', config.getConfiguration().getString("Messages.NoConsole"));
messageInvalidUsage = ChatColorUtils.translateAlternateColorCodes('&', config.getConfiguration().getString("Messages.InvalidUsage"));
messageNotEnoughSpace = ChatColorUtils.translateAlternateColorCodes('&', config.getConfiguration().getString("Messages.NotEnoughSpace"));
messageAccessUpdated = ChatColorUtils.translateAlternateColorCodes('&', config.getConfiguration().getString("Messages.AccessPermission.Updated"));
messageAccessTypes = new HashMap<>();
for (ImageMap.ImageMapAccessPermissionType type : ImageMap.ImageMapAccessPermissionType.values().values()) {
messageAccessTypes.put(type, ChatColorUtils.translateAlternateColorCodes('&', config.getConfiguration().getString("Messages.AccessPermission.Types." + type.name())));
}
messageAccessNoneType = ChatColorUtils.translateAlternateColorCodes('&', config.getConfiguration().getString("Messages.AccessPermission.Types.NONE"));
messageNotEnoughMaps = ChatColorUtils.translateAlternateColorCodes('&', config.getConfiguration().getString("Messages.NotEnoughMaps"));
messageURLRestricted = ChatColorUtils.translateAlternateColorCodes('&', config.getConfiguration().getString("Messages.URLRestricted"));
messagePlayerCreationLimitReached = ChatColorUtils.translateAlternateColorCodes('&', config.getConfiguration().getString("Messages.PlayerCreationLimitReached"));
@@ -44,6 +44,7 @@ import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
@@ -52,8 +53,10 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiConsumer;
import java.util.function.BiPredicate;
import java.util.function.Function;
@@ -83,11 +86,12 @@ public abstract class ImageMap {
protected final int width;
protected final int height;
protected UUID creator;
protected Map<UUID, ImageMapAccessPermissionType> hasAccess;
protected final long creationTime;
private boolean isValid;
public ImageMap(ImageMapManager manager, int imageIndex, String name, List<MapView> mapViews, List<Integer> mapIds, List<Map<String, MapCursor>> mapMarkers, int width, int height, UUID creator, long creationTime) {
public ImageMap(ImageMapManager manager, int imageIndex, String name, List<MapView> mapViews, List<Integer> mapIds, List<Map<String, MapCursor>> mapMarkers, int width, int height, UUID creator, Map<UUID, ImageMapAccessPermissionType> hasAccess, long creationTime) {
if (mapViews.size() != width * height) {
throw new IllegalArgumentException("mapViews size does not equal width * height");
}
@@ -106,9 +110,12 @@ public abstract class ImageMap {
this.width = width;
this.height = height;
this.creator = creator;
this.hasAccess = new ConcurrentHashMap<>(hasAccess);
this.creationTime = creationTime;
this.isValid = true;
this.hasAccess.remove(creator);
}
public ImageMapManager getManager() {
@@ -328,6 +335,44 @@ public abstract class ImageMap {
public void changeCreator(UUID creator) throws Exception {
this.creator = creator;
hasAccess.remove(creator);
save();
}
public ImageMapAccessPermissionType getPermission(UUID player) {
if (player.equals(creator)) {
return ImageMapAccessPermissionType.ALL;
}
return hasAccess.get(player);
}
public Map<UUID, ImageMapAccessPermissionType> getPermissions() {
return Collections.unmodifiableMap(hasAccess);
}
public boolean hasPermission(UUID player, ImageMapAccessPermissionType permissionType) {
if (permissionType == null) {
return true;
}
if (player.equals(creator)) {
return true;
}
ImageMapAccessPermissionType type = hasAccess.get(player);
if (type == null) {
return false;
}
return type.containsPermission(permissionType);
}
public void setPermission(UUID player, ImageMapAccessPermissionType permissionType) throws Exception {
if (player.equals(creator)) {
return;
}
if (permissionType == null) {
hasAccess.remove(player);
} else {
hasAccess.put(player, permissionType);
}
save();
}
@@ -406,4 +451,89 @@ public abstract class ImageMap {
}
public static class ImageMapAccessPermissionType {
public static final ImageMapAccessPermissionType GET = new ImageMapAccessPermissionType("GET");
public static final ImageMapAccessPermissionType MARKER = new ImageMapAccessPermissionType("MARKER", GET);
public static final ImageMapAccessPermissionType EDIT = new ImageMapAccessPermissionType("EDIT", MARKER);
public static final ImageMapAccessPermissionType EDIT_CLONE = new ImageMapAccessPermissionType("EDIT_CLONE", EDIT);
public static final ImageMapAccessPermissionType ALL = new ImageMapAccessPermissionType("ALL", EDIT_CLONE);
/**
* Special case type: All registered ImageMapAccessPermissionTypes inherits this
*/
public static final ImageMapAccessPermissionType BASE = new ImageMapAccessPermissionType("BASE") {
@Override
public boolean containsPermission(ImageMapAccessPermissionType type) {
return TYPES.containsKey(type.name());
}
};
private static final Map<String, ImageMapAccessPermissionType> TYPES = new HashMap<>();
static {
register(GET);
register(MARKER);
register(EDIT);
register(EDIT_CLONE);
register(ALL);
}
public static void register(ImageMapAccessPermissionType type) {
TYPES.put(type.name(), type);
}
public static ImageMapAccessPermissionType valueOf(String name) {
ImageMapAccessPermissionType type = TYPES.get(name);
if (type != null) {
return type;
}
throw new IllegalArgumentException(name + " is not a registered ImageMapAccessPermissionType");
}
public static Map<String, ImageMapAccessPermissionType> values() {
return Collections.unmodifiableMap(TYPES);
}
private final String name;
private final Set<ImageMapAccessPermissionType> inheritance;
public ImageMapAccessPermissionType(String name, ImageMapAccessPermissionType... inheritance) {
if (name == null) {
throw new IllegalArgumentException("name cannot be null");
}
this.name = name;
this.inheritance = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(inheritance)));
}
public String name() {
return name;
}
public boolean containsPermission(ImageMapAccessPermissionType type) {
if (this.equals(type)) {
return true;
}
for (ImageMapAccessPermissionType inheritedType : inheritance) {
if (!inheritedType.equals(this) && inheritedType.containsPermission(type)) {
return true;
}
}
return false;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ImageMapAccessPermissionType type = (ImageMapAccessPermissionType) o;
return name.equals(type.name) && inheritance.equals(type.inheritance);
}
@Override
public int hashCode() {
return Objects.hash(name, inheritance);
}
}
}
@@ -36,6 +36,8 @@ import java.awt.image.BufferedImage;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@@ -58,7 +60,7 @@ public class MinecraftURLOverlayImageMap extends URLStaticImageMap {
}
markers.add(new ConcurrentHashMap<>());
}
MinecraftURLOverlayImageMap map = new MinecraftURLOverlayImageMap(manager, -1, name, url, new BufferedImage[mapsCount], mapViews, mapIds, markers, width, height, creator, System.currentTimeMillis());
MinecraftURLOverlayImageMap map = new MinecraftURLOverlayImageMap(manager, -1, name, url, new BufferedImage[mapsCount], mapViews, mapIds, markers, width, height, creator, Collections.emptyMap(), System.currentTimeMillis());
for (int i = 0; i < mapViews.size(); i++) {
MapView mapView = mapViews.get(i);
mapView.addRenderer(new MinecraftURLOverlayImageMapRenderer(map, i));
@@ -79,6 +81,16 @@ public class MinecraftURLOverlayImageMap extends URLStaticImageMap {
int height = json.get("height").getAsInt();
long creationTime = json.get("creationTime").getAsLong();
UUID creator = UUID.fromString(json.get("creator").getAsString());
Map<UUID, ImageMapAccessPermissionType> hasAccess;
if (json.has("hasAccess")) {
JsonObject accessJson = json.get("hasAccess").getAsJsonObject();
hasAccess = new HashMap<>(accessJson.size());
for (Map.Entry<String, JsonElement> entry : accessJson.entrySet()) {
hasAccess.put(UUID.fromString(entry.getKey()), ImageMapAccessPermissionType.valueOf(entry.getValue().getAsString().toUpperCase()));
}
} else {
hasAccess = Collections.emptyMap();
}
JsonArray mapDataJson = json.get("mapdata").getAsJsonArray();
List<Future<MapView>> mapViewsFuture = new ArrayList<>(mapDataJson.size());
List<Integer> mapIds = new ArrayList<>(mapDataJson.size());
@@ -113,7 +125,7 @@ public class MinecraftURLOverlayImageMap extends URLStaticImageMap {
for (Future<MapView> future : mapViewsFuture) {
mapViews.add(future.get());
}
MinecraftURLOverlayImageMap map = new MinecraftURLOverlayImageMap(manager, imageIndex, name, url, cachedImages, mapViews, mapIds, markers, width, height, creator, creationTime);
MinecraftURLOverlayImageMap map = new MinecraftURLOverlayImageMap(manager, imageIndex, name, url, cachedImages, mapViews, mapIds, markers, width, height, creator, hasAccess, creationTime);
for (int u = 0; u < mapViews.size(); u++) {
MapView mapView = mapViews.get(u);
for (MapRenderer mapRenderer : mapView.getRenderers()) {
@@ -126,8 +138,8 @@ public class MinecraftURLOverlayImageMap extends URLStaticImageMap {
return map;
}
protected MinecraftURLOverlayImageMap(ImageMapManager manager, int imageIndex, String name, String url, BufferedImage[] cachedImages, List<MapView> mapViews, List<Integer> mapIds, List<Map<String, MapCursor>> mapMarkers, int width, int height, UUID creator, long creationTime) {
super(manager, imageIndex, name, url, cachedImages, mapViews, mapIds, mapMarkers, width, height, creator, creationTime);
protected MinecraftURLOverlayImageMap(ImageMapManager manager, int imageIndex, String name, String url, BufferedImage[] cachedImages, List<MapView> mapViews, List<Integer> mapIds, List<Map<String, MapCursor>> mapMarkers, int width, int height, UUID creator, Map<UUID, ImageMapAccessPermissionType> hasAccess, long creationTime) {
super(manager, imageIndex, name, url, cachedImages, mapViews, mapIds, mapMarkers, width, height, creator, hasAccess, creationTime);
}
@Override
@@ -43,6 +43,8 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@@ -88,7 +90,7 @@ public class NonUpdatableStaticImageMap extends ImageMap {
throw new RuntimeException(e);
}
}
NonUpdatableStaticImageMap map = new NonUpdatableStaticImageMap(manager, -1, name, images, mapViews, mapIds, markers, width, height, creator, System.currentTimeMillis());
NonUpdatableStaticImageMap map = new NonUpdatableStaticImageMap(manager, -1, name, images, mapViews, mapIds, markers, width, height, creator, Collections.emptyMap(), System.currentTimeMillis());
for (int i = 0; i < mapViews.size(); i++) {
MapView mapView = mapViews.get(i);
int finalI = i;
@@ -109,6 +111,16 @@ public class NonUpdatableStaticImageMap extends ImageMap {
int height = json.get("height").getAsInt();
long creationTime = json.get("creationTime").getAsLong();
UUID creator = UUID.fromString(json.get("creator").getAsString());
Map<UUID, ImageMapAccessPermissionType> hasAccess;
if (json.has("hasAccess")) {
JsonObject accessJson = json.get("hasAccess").getAsJsonObject();
hasAccess = new HashMap<>(accessJson.size());
for (Map.Entry<String, JsonElement> entry : accessJson.entrySet()) {
hasAccess.put(UUID.fromString(entry.getKey()), ImageMapAccessPermissionType.valueOf(entry.getValue().getAsString().toUpperCase()));
}
} else {
hasAccess = Collections.emptyMap();
}
JsonArray mapDataJson = json.get("mapdata").getAsJsonArray();
List<Future<MapView>> mapViewsFuture = new ArrayList<>(mapDataJson.size());
List<Integer> mapIds = new ArrayList<>(mapDataJson.size());
@@ -143,7 +155,7 @@ public class NonUpdatableStaticImageMap extends ImageMap {
for (Future<MapView> future : mapViewsFuture) {
mapViews.add(future.get());
}
NonUpdatableStaticImageMap map = new NonUpdatableStaticImageMap(manager, imageIndex, name, cachedImages, mapViews, mapIds, markers, width, height, creator, creationTime);
NonUpdatableStaticImageMap map = new NonUpdatableStaticImageMap(manager, imageIndex, name, cachedImages, mapViews, mapIds, markers, width, height, creator, hasAccess, creationTime);
for (int u = 0; u < mapViews.size(); u++) {
MapView mapView = mapViews.get(u);
int finalU = u;
@@ -161,8 +173,8 @@ public class NonUpdatableStaticImageMap extends ImageMap {
protected byte[][] cachedColors;
protected NonUpdatableStaticImageMap(ImageMapManager manager, int imageIndex, String name, BufferedImage[] cachedImages, List<MapView> mapViews, List<Integer> mapIds, List<Map<String, MapCursor>> mapMarkers, int width, int height, UUID creator, long creationTime) {
super(manager, imageIndex, name, mapViews, mapIds, mapMarkers, width, height, creator, creationTime);
protected NonUpdatableStaticImageMap(ImageMapManager manager, int imageIndex, String name, BufferedImage[] cachedImages, List<MapView> mapViews, List<Integer> mapIds, List<Map<String, MapCursor>> mapMarkers, int width, int height, UUID creator, Map<UUID, ImageMapAccessPermissionType> hasAccess, long creationTime) {
super(manager, imageIndex, name, mapViews, mapIds, mapMarkers, width, height, creator, hasAccess, creationTime);
this.cachedImages = cachedImages;
cacheColors();
}
@@ -228,6 +240,11 @@ public class NonUpdatableStaticImageMap extends ImageMap {
json.addProperty("width", width);
json.addProperty("height", height);
json.addProperty("creator", creator.toString());
JsonObject accessJson = new JsonObject();
for (Map.Entry<UUID, ImageMapAccessPermissionType> entry : hasAccess.entrySet()) {
accessJson.addProperty(entry.getKey().toString(), entry.getValue().name());
}
json.add("hasAccess", accessJson);
json.addProperty("creationTime", creationTime);
JsonArray mapDataJson = new JsonArray();
for (int i = 0; i < mapViews.size(); i++) {
@@ -45,6 +45,8 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@@ -74,7 +76,7 @@ public class URLAnimatedImageMap extends URLImageMap {
mapViews.add(mapView);
mapIds.add(mapView.getId());
}
URLAnimatedImageMap map = new URLAnimatedImageMap(manager, -1, name, url, new BufferedImage[mapsCount][], mapViews, mapIds, markers, width, height, creator, System.currentTimeMillis());
URLAnimatedImageMap map = new URLAnimatedImageMap(manager, -1, name, url, new BufferedImage[mapsCount][], mapViews, mapIds, markers, width, height, creator, Collections.emptyMap(), System.currentTimeMillis());
for (int i = 0; i < mapViews.size(); i++) {
MapView mapView = mapViews.get(i);
int finalI = i;
@@ -96,6 +98,16 @@ public class URLAnimatedImageMap extends URLImageMap {
int height = json.get("height").getAsInt();
long creationTime = json.get("creationTime").getAsLong();
UUID creator = UUID.fromString(json.get("creator").getAsString());
Map<UUID, ImageMapAccessPermissionType> hasAccess;
if (json.has("hasAccess")) {
JsonObject accessJson = json.get("hasAccess").getAsJsonObject();
hasAccess = new HashMap<>(accessJson.size());
for (Map.Entry<String, JsonElement> entry : accessJson.entrySet()) {
hasAccess.put(UUID.fromString(entry.getKey()), ImageMapAccessPermissionType.valueOf(entry.getValue().getAsString().toUpperCase()));
}
} else {
hasAccess = Collections.emptyMap();
}
JsonArray mapDataJson = json.get("mapdata").getAsJsonArray();
List<Future<MapView>> mapViewsFuture = new ArrayList<>(mapDataJson.size());
List<Integer> mapIds = new ArrayList<>(mapDataJson.size());
@@ -135,7 +147,7 @@ public class URLAnimatedImageMap extends URLImageMap {
for (Future<MapView> future : mapViewsFuture) {
mapViews.add(future.get());
}
URLAnimatedImageMap map = new URLAnimatedImageMap(manager, imageIndex, name, url, cachedImages, mapViews, mapIds, markers, width, height, creator, creationTime);
URLAnimatedImageMap map = new URLAnimatedImageMap(manager, imageIndex, name, url, cachedImages, mapViews, mapIds, markers, width, height, creator, hasAccess, creationTime);
for (int u = 0; u < mapViews.size(); u++) {
MapView mapView = mapViews.get(u);
for (MapRenderer renderer : mapView.getRenderers()) {
@@ -150,8 +162,8 @@ public class URLAnimatedImageMap extends URLImageMap {
protected byte[][][] cachedColors;
protected URLAnimatedImageMap(ImageMapManager manager, int imageIndex, String name, String url, BufferedImage[][] cachedImages, List<MapView> mapViews, List<Integer> mapIds, List<Map<String, MapCursor>> mapMarkers, int width, int height, UUID creator, long creationTime) {
super(manager, imageIndex, name, url, mapViews, mapIds, mapMarkers, width, height, creator, creationTime);
protected URLAnimatedImageMap(ImageMapManager manager, int imageIndex, String name, String url, BufferedImage[][] cachedImages, List<MapView> mapViews, List<Integer> mapIds, List<Map<String, MapCursor>> mapMarkers, int width, int height, UUID creator, Map<UUID, ImageMapAccessPermissionType> hasAccess, long creationTime) {
super(manager, imageIndex, name, url, mapViews, mapIds, mapMarkers, width, height, creator, hasAccess, creationTime);
this.cachedImages = cachedImages;
cacheColors();
}
@@ -253,6 +265,11 @@ public class URLAnimatedImageMap extends URLImageMap {
json.addProperty("width", width);
json.addProperty("height", height);
json.addProperty("creator", creator.toString());
JsonObject accessJson = new JsonObject();
for (Map.Entry<UUID, ImageMapAccessPermissionType> entry : hasAccess.entrySet()) {
accessJson.addProperty(entry.getKey().toString(), entry.getValue().name());
}
json.add("hasAccess", accessJson);
json.addProperty("creationTime", creationTime);
JsonArray mapDataJson = new JsonArray();
int u = 0;
@@ -31,8 +31,8 @@ public abstract class URLImageMap extends ImageMap {
protected String url;
public URLImageMap(ImageMapManager manager, int imageIndex, String name, String url, List<MapView> mapViews, List<Integer> mapIds, List<Map<String, MapCursor>> mapMarkers, int width, int height, UUID creator, long creationTime) {
super(manager, imageIndex, name, mapViews, mapIds, mapMarkers, width, height, creator, creationTime);
public URLImageMap(ImageMapManager manager, int imageIndex, String name, String url, List<MapView> mapViews, List<Integer> mapIds, List<Map<String, MapCursor>> mapMarkers, int width, int height, UUID creator, Map<UUID, ImageMapAccessPermissionType> hasAccess, long creationTime) {
super(manager, imageIndex, name, mapViews, mapIds, mapMarkers, width, height, creator, hasAccess, creationTime);
this.url = url;
}
@@ -44,6 +44,8 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@@ -78,7 +80,7 @@ public class URLStaticImageMap extends URLImageMap {
throw new RuntimeException(e);
}
}
URLStaticImageMap map = new URLStaticImageMap(manager, -1, name, url, new BufferedImage[mapsCount], mapViews, mapIds, markers, width, height, creator, System.currentTimeMillis());
URLStaticImageMap map = new URLStaticImageMap(manager, -1, name, url, new BufferedImage[mapsCount], mapViews, mapIds, markers, width, height, creator, Collections.emptyMap(), System.currentTimeMillis());
for (int i = 0; i < mapViews.size(); i++) {
MapView mapView = mapViews.get(i);
int finalI = i;
@@ -100,6 +102,16 @@ public class URLStaticImageMap extends URLImageMap {
int height = json.get("height").getAsInt();
long creationTime = json.get("creationTime").getAsLong();
UUID creator = UUID.fromString(json.get("creator").getAsString());
Map<UUID, ImageMapAccessPermissionType> hasAccess;
if (json.has("hasAccess")) {
JsonObject accessJson = json.get("hasAccess").getAsJsonObject();
hasAccess = new HashMap<>(accessJson.size());
for (Map.Entry<String, JsonElement> entry : accessJson.entrySet()) {
hasAccess.put(UUID.fromString(entry.getKey()), ImageMapAccessPermissionType.valueOf(entry.getValue().getAsString().toUpperCase()));
}
} else {
hasAccess = Collections.emptyMap();
}
JsonArray mapDataJson = json.get("mapdata").getAsJsonArray();
List<Future<MapView>> mapViewsFuture = new ArrayList<>(mapDataJson.size());
List<Integer> mapIds = new ArrayList<>(mapDataJson.size());
@@ -134,7 +146,7 @@ public class URLStaticImageMap extends URLImageMap {
for (Future<MapView> future : mapViewsFuture) {
mapViews.add(future.get());
}
URLStaticImageMap map = new URLStaticImageMap(manager, imageIndex, name, url, cachedImages, mapViews, mapIds, markers, width, height, creator, creationTime);
URLStaticImageMap map = new URLStaticImageMap(manager, imageIndex, name, url, cachedImages, mapViews, mapIds, markers, width, height, creator, hasAccess, creationTime);
for (int u = 0; u < mapViews.size(); u++) {
MapView mapView = mapViews.get(u);
int finalU = u;
@@ -152,8 +164,8 @@ public class URLStaticImageMap extends URLImageMap {
protected byte[][] cachedColors;
protected URLStaticImageMap(ImageMapManager manager, int imageIndex, String name, String url, BufferedImage[] cachedImages, List<MapView> mapViews, List<Integer> mapIds, List<Map<String, MapCursor>> mapMarkers, int width, int height, UUID creator, long creationTime) {
super(manager, imageIndex, name, url, mapViews, mapIds, mapMarkers, width, height, creator, creationTime);
protected URLStaticImageMap(ImageMapManager manager, int imageIndex, String name, String url, BufferedImage[] cachedImages, List<MapView> mapViews, List<Integer> mapIds, List<Map<String, MapCursor>> mapMarkers, int width, int height, UUID creator, Map<UUID, ImageMapAccessPermissionType> hasAccess, long creationTime) {
super(manager, imageIndex, name, url, mapViews, mapIds, mapMarkers, width, height, creator, hasAccess, creationTime);
this.cachedImages = cachedImages;
cacheColors();
}
@@ -222,6 +234,11 @@ public class URLStaticImageMap extends URLImageMap {
json.addProperty("width", width);
json.addProperty("height", height);
json.addProperty("creator", creator.toString());
JsonObject accessJson = new JsonObject();
for (Map.Entry<UUID, ImageMapAccessPermissionType> entry : hasAccess.entrySet()) {
accessJson.addProperty(entry.getKey().toString(), entry.getValue().name());
}
json.add("hasAccess", accessJson);
json.addProperty("creationTime", creationTime);
JsonArray mapDataJson = new JsonArray();
for (int i = 0; i < mapViews.size(); i++) {
@@ -0,0 +1,86 @@
/*
* This file is part of ImageFrame.
*
* Copyright (C) 2022. LoohpJames <jamesloohp@gmail.com>
* Copyright (C) 2022. 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.utils;
import com.loohp.imageframe.ImageFrame;
import com.loohp.imageframe.objectholders.ImageMap;
import com.loohp.imageframe.objectholders.MutablePair;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.UUID;
public class ImageMapUtils {
public static MutablePair<UUID, String> extractImageMapPlayerPrefixedName(CommandSender sender, String str) {
int index = str.indexOf(':');
if (index < 0) {
return new MutablePair<>(sender instanceof Player ? ((Player) sender).getUniqueId() : null, str);
}
String playerName = str.substring(0, index);
String imageMapName = str.substring(index + 1);
UUID playerUUID = Bukkit.getOfflinePlayer(playerName).getUniqueId();
return new MutablePair<>(playerUUID, imageMapName);
}
public static ImageMap getFromPlayerPrefixedName(CommandSender sender, String str) {
if (sender instanceof Player) {
ImageMap imageMap = ImageFrame.imageMapManager.getFromCreator(((Player) sender).getUniqueId(), str);
if (imageMap != null) {
return imageMap;
}
}
MutablePair<UUID, String> extraction = ImageMapUtils.extractImageMapPlayerPrefixedName(sender, str);
return ImageFrame.imageMapManager.getFromCreator(extraction.getFirst(), extraction.getSecond());
}
public static Set<String> getImageMapNameSuggestions(CommandSender sender, String str) {
Set<String> tab = new LinkedHashSet<>();
if (sender instanceof Player) {
for (ImageMap imageMap : ImageFrame.imageMapManager.getFromCreator(((Player) sender).getUniqueId())) {
if (imageMap.getName().toLowerCase().startsWith(str.toLowerCase())) {
tab.add(imageMap.getName());
}
}
}
if (!str.contains(":")) {
return tab;
}
MutablePair<UUID, String> extraction = extractImageMapPlayerPrefixedName(sender, str);
UUID uuid = extraction.getFirst();
if (uuid == null) {
return tab;
}
for (ImageMap imageMap : ImageFrame.imageMapManager.getFromCreator(extraction.getFirst())) {
if (ImageFrame.hasImageMapPermission(imageMap, sender, ImageMap.ImageMapAccessPermissionType.BASE)) {
String prefixedName = imageMap.getCreatorName() + ":" + imageMap.getName();
if (prefixedName.toLowerCase().startsWith(str.toLowerCase())) {
tab.add(prefixedName);
}
}
}
return tab;
}
}
+11 -1
View File
@@ -6,8 +6,8 @@ Messages:
ImageMapRenamed: "&aImageMap had been renamed!"
ImageMapUpdated: "&aImageMap had been updated!"
InvalidOverlayMap: "&cOverlay only works on Vanilla Minecraft maps and without duplicates in selection!"
NotCreator: "&cYou did not create that ImageMap"
UnableToLoadMap: "&cImageMap cannot be loaded, there is a problem while reading the image."
UnknownError: "&cAn unknown error had occurred."
ImageOverMaxFileSize: "&cImageMap cannot be loaded as it is over the max file size allowed. ({Size} bytes)"
NotAnImageMap: "&cThat is not an ImageMap"
URLImageMapInfo:
@@ -15,6 +15,7 @@ Messages:
- "&aName: {Name}"
- "&eMap Size: {Width} x {Height}"
- "&dCreator: {CreatorName} ({CreatorUUID})"
- "&fAccess: {Access}"
- "&aTime Created: {TimeCreated}"
- "&bMarkers: {Markers}"
- "&eURL: {URL}"
@@ -29,6 +30,15 @@ Messages:
MapLookup: "&bList of image maps by {CreatorName} ({CreatorUUID}):"
ItemFrameOccupied: "&cFailed to place or remove some maps on selected ItemFrame, they are either destroyed, replaced, occupied or protected."
NotEnoughSpace: "&cUnable to place Combined ImageMap as there is not enough room."
AccessPermission:
Updated: "&aUpdated access for {PlayerName} ({PlayerUUID}), they now have {Permission} permission."
Types:
NONE: "NONE"
GET: "GET"
MARKER: "MARKER"
EDIT: "EDIT"
EDIT_CLONE: "EDIT WITH CLONE"
ALL: "ALL"
Selection:
Begin: "&bRight click an Item Frame to select corner 1 and 2"
Clear: "&eLeaving selection mode"
+10 -22
View File
@@ -55,30 +55,18 @@ permissions:
imageframe.get:
default: true
description: Allow players to get an image map they've created
imageframe.adminrefresh:
default: op
description: Allow players to refresh image maps
imageframe.adminclone:
default: op
description: Allow players to make deep copies of any image map
imageframe.adminrename:
default: op
description: Allow players to rename image maps of any image id
imageframe.admininfo:
default: op
description: Allow players to view image map data of any image id
imageframe.admindelete:
default: op
description: Allow players to delete any image map with its image id
imageframe.adminget:
default: op
description: Allow players to get any image map with its image id
imageframe.adminmarker:
default: op
description: Allow players to add and remove markers on any image map
imageframe.setaccess:
default: true
description: Allow players to change access permissions of their image maps
imageframe.adminbypass:
default: true
description: Bypass all access restrictions and allow users to use and modify any image map
imageframe.adminsetcreator:
default: op
description: Allow players to change the creator of any image map
description: Allow players to change the creator of any image map via the image map id
imageframe.admindelete:
default: op
description: Allow players to delete any image map via the image map id
imageframe.adminmigrate:
default: op
description: Allow players to migrate maps from supported plugins to ImageFrame