bubbles = new ArrayList<>();
+
+ public void readFrom(InputStream stream) throws IOException {
+ try (BitInputStream bitStream = new BitInputStream(new InflaterInputStream(stream))) {
+ // Read all color RGB values
+ for (int i = 0; i < 256; i++) {
+ int r = bitStream.read();
+ int g = bitStream.read();
+ int b = bitStream.read();
+ int a = bitStream.read();
+ this.setColor((byte) i, new Color(r, g, b, a));
+ }
+
+ // Read all bubbles from the stream
+ while (true) {
+ Bubble bubble = new Bubble();
+ bubble.color = (byte) bitStream.read();
+ if (bubble.color == 0) {
+ break;
+ }
+ bubble.x = bitStream.read();
+ bubble.y = bitStream.read();
+ bubble.z_min = bitStream.read();
+ bubble.z_max = bubble.z_min + bitStream.read();
+ this.bubbles.add(bubble);
+ }
+
+ // Read bubble boundary information from the stream
+ MCSDWebbingCodec codec = new MCSDWebbingCodec();
+ for (int z = 0; z < 256; z++) {
+ Arrays.fill(this.strands[z], false);
+ codec.reset(strands[z], false);
+ while (codec.readNext(bitStream)) ;
+ }
+
+ // Initialize the colors with the bubble colors
+ this.initColors();
+
+ // Read color correction data for pixels unset (value = 0)
+ for (int i = 0; i < (1 << 24); i++) {
+ if (this.get(i) == 0) {
+ if (bitStream.readBits(1) == 0) {
+ this.set(i, this.get(i - 1));
+ } else {
+ int mode = bitStream.readBits(2);
+ if (mode == 0) {
+ this.set(i, this.get(i - 256));
+ } else if (mode == 1) {
+ this.set(i, this.get(i + 1));
+ } else if (mode == 2) {
+ this.set(i, this.get(i + 256));
+ } else {
+ this.set(i, (byte) bitStream.readBits(8));
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private void initColors() {
+ // Set initial cell colors
+ this.clearRGBData();
+ for (Bubble cell : bubbles) {
+ for (int z = cell.z_min; z <= cell.z_max; z++) {
+ this.set(cell.x, cell.y, z, cell.color);
+ }
+ }
+ spreadColors();
+ }
+
+ private void spreadColors() {
+ final boolean[] all_strands = new boolean[1 << 24];
+ for (int z = 0; z < 256; z++) {
+ System.arraycopy(this.strands[z], 0, all_strands, z << 16, 1 << 16);
+ }
+
+ boolean mode = false;
+ boolean hasChanges;
+ do {
+ hasChanges = false;
+
+ // Alternate the direction in which we process every step
+ // This prevents really slow filling when the direction is 'wrong'
+ // The below logic is partially based on the light fixing algorithm in Light Cleaner
+ final int index_end, index_delta;
+ int index;
+ byte color;
+ if (mode = !mode) {
+ index_delta = 1;
+ index = 0;
+ index_end = (1 << 24);
+ } else {
+ index_delta = -1;
+ index = (1 << 24) - 1;
+ index_end = 0;
+ }
+ do {
+ if (!all_strands[index]) {
+ all_strands[index] = true;
+
+ if ((index & 0xFF) < 0xFF) {
+ if ((color = this.get(index + 1)) != 0) {
+ this.set(index, color);
+ hasChanges = true;
+ } else if ((color = this.get(index)) != 0) {
+ this.set(index + 1, color);
+ hasChanges = true;
+ } else {
+ all_strands[index] = false; // retry
+ }
+ }
+
+ if ((index & 0xFF00) < 0xFF00) {
+ if ((color = this.get(index + 256)) != 0) {
+ this.set(index, color);
+ hasChanges = true;
+ } else if ((color = this.get(index)) != 0) {
+ this.set(index + 256, color);
+ hasChanges = true;
+ } else {
+ all_strands[index] = false; // retry
+ }
+ }
+ }
+ } while ((index += index_delta) != index_end);
+ } while (hasChanges);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) {
+ return true;
+ } else if (o instanceof MCSDBubbleFormat) {
+ MCSDBubbleFormat other = (MCSDBubbleFormat) o;
+ for (int i = 0; i < strands.length; i++) {
+ if (other.strands[i] != this.strands[i]) {
+ return false;
+ }
+ }
+ if (bubbles.size() != other.bubbles.size()) {
+ return false;
+ }
+ for (int i = 0; i < bubbles.size(); i++) {
+ if (!bubbles.get(i).equals(other.bubbles.get(i))) {
+ return false;
+ }
+ }
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public static class Bubble {
+ public int x, y;
+ public int z_min;
+ public int z_max;
+ public byte color;
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) {
+ return true;
+ } else if (o instanceof Bubble) {
+ Bubble other = (Bubble) o;
+ return other.x == x && other.y == y &&
+ other.z_min == z_min && other.z_max == z_max &&
+ other.color == color;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "cell{x=" + x + ", y=" + y + ", zmin=" + z_min + ", zmax=" + z_max + ", color=" + (color & 0xFF) + "}";
+ }
+ }
+
+}
diff --git a/src/main/java/com/bergerkiller/bukkit/common/map/color/MCSDGenBukkit.java b/src/main/java/com/bergerkiller/bukkit/common/map/color/MCSDGenBukkit.java
new file mode 100644
index 0000000..77b67c1
--- /dev/null
+++ b/src/main/java/com/bergerkiller/bukkit/common/map/color/MCSDGenBukkit.java
@@ -0,0 +1,50 @@
+/*
+ * This file is part of MapReflectionAPI.
+ * Copyright (c) 2022 inventivetalent / SBDevelopment - All Rights Reserved
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package com.bergerkiller.bukkit.common.map.color;
+
+import org.bukkit.map.MapPalette;
+
+public class MCSDGenBukkit extends MapColorSpaceData {
+
+ /**
+ * Generates the color map information by using Bukkit's algorithms.
+ */
+ @SuppressWarnings("deprecation")
+ public void generate() {
+ this.clear();
+ for (int i = 0; i < 256; i++) {
+ try {
+ setColor((byte) i, MapPalette.getColor((byte) i));
+ } catch (Exception ignored) {
+ }
+ }
+ for (int r = 0; r < 256; r++) {
+ for (int g = 0; g < 256; g++) {
+ for (int b = 0; b < 256; b++) {
+ set(r, g, b, MapPalette.matchColor(r, g, b));
+ }
+ }
+ }
+ }
+}
diff --git a/src/main/java/com/bergerkiller/bukkit/common/map/color/MCSDWebbingCodec.java b/src/main/java/com/bergerkiller/bukkit/common/map/color/MCSDWebbingCodec.java
new file mode 100644
index 0000000..752cb07
--- /dev/null
+++ b/src/main/java/com/bergerkiller/bukkit/common/map/color/MCSDWebbingCodec.java
@@ -0,0 +1,128 @@
+/*
+ * This file is part of MapReflectionAPI.
+ * Copyright (c) 2022 inventivetalent / SBDevelopment - All Rights Reserved
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package com.bergerkiller.bukkit.common.map.color;
+
+import com.bergerkiller.bukkit.common.io.BitInputStream;
+import com.bergerkiller.bukkit.common.io.BitPacket;
+
+import java.io.IOException;
+
+/**
+ * Encodes or decodes a 256x256 grid of booleans by walking down the connected lines and encoding them
+ * using drawing instructions. For example, a diagonal line in the grid may be encoded as follows:
+ *
+ * - SET_POSITION(23, 56)
+ * - SET_DX(-1)
+ * - SET_DY(1)
+ * - MOVE DX AND DRAW
+ * - MOVE DX AND DRAW
+ * - MOVE DY AND DRAW
+ * - MOVE DX AND DRAW
+ * - MOVE DX AND DRAW
+ * - MOVE DY AND DRAW
+ * - etc.
+ *
+ *
+ * For encoding the data, the follow bits are written out in sequence:
+ *
+ * - 00 -> MOVE DX AND DRAW
+ * - 01 -> MOVE DY AND DRAW
+ * - 10 -> MOVE DX+DY AND DRAW
+ * - 11 100 -> SET DX = -1
+ * - 11 101 -> SET DX = 1
+ * - 11 110 -> SET DY = -1
+ * - 11 111 -> SET DY = 1
+ * - 11 00 [byte_x][byte_y] -> SET POSITION AND DRAW
+ * - 11 01 -> STOP
+ *
+ */
+public class MCSDWebbingCodec {
+ private int last_x, last_y;
+ private int last_dx, last_dy;
+ public boolean[] strands = new boolean[1 << 16];
+ private final BitPacket[] packets = new BitPacket[1024];
+
+ public MCSDWebbingCodec() {
+ for (int i = 0; i < this.packets.length; i++) {
+ this.packets[i] = new BitPacket();
+ }
+ }
+
+ public void reset(boolean[] cells, boolean copyCells) {
+ if (copyCells) {
+ System.arraycopy(cells, 0, this.strands, 0, cells.length);
+ } else {
+ this.strands = cells;
+ }
+ this.last_x = -1000;
+ this.last_y = -1000;
+ this.last_dx = 1;
+ this.last_dy = 1;
+ }
+
+ public boolean readNext(BitInputStream stream) throws IOException {
+ int op = stream.readBits(2);
+ if (op == 0b11) {
+ if (stream.readBits(1) == 1) {
+ // Set DX/DY increment/decrement
+ int sub = stream.readBits(2);
+ if (sub == 0b00) {
+ last_dx = -1;
+ } else if (sub == 0b01) {
+ last_dx = 1;
+ } else if (sub == 0b10) {
+ last_dy = -1;
+ } else if (sub == 0b11) {
+ last_dy = 1;
+ }
+ } else {
+ // Command codes
+ if (stream.readBits(1) == 1) {
+ // End of slice
+ return false;
+ } else {
+ // Reset position
+ last_x = stream.readBits(8);
+ last_y = stream.readBits(8);
+ strands[last_x | (last_y << 8)] = true;
+ }
+ }
+ } else {
+ // Write next pixel
+ if (op == 0b00) {
+ last_x += last_dx;
+ } else if (op == 0b01) {
+ last_y += last_dy;
+ } else if (op == 0b10) {
+ last_x += last_dx;
+ last_y += last_dy;
+ } else if (op == -1) {
+ // End of stream
+ return false;
+ }
+ strands[last_x | (last_y << 8)] = true;
+ }
+ return true;
+ }
+}
diff --git a/src/main/java/com/bergerkiller/bukkit/common/map/color/MapColorSpaceData.java b/src/main/java/com/bergerkiller/bukkit/common/map/color/MapColorSpaceData.java
new file mode 100644
index 0000000..3c5e338
--- /dev/null
+++ b/src/main/java/com/bergerkiller/bukkit/common/map/color/MapColorSpaceData.java
@@ -0,0 +1,160 @@
+/*
+ * This file is part of MapReflectionAPI.
+ * Copyright (c) 2022 inventivetalent / SBDevelopment - All Rights Reserved
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package com.bergerkiller.bukkit.common.map.color;
+
+import java.awt.*;
+import java.util.Arrays;
+
+/**
+ * Stores the raw map color space data, enabling transformation between different storage methods.
+ */
+public class MapColorSpaceData implements Cloneable {
+ private final Color[] colors = new Color[256];
+ private final byte[] data = new byte[1 << 24];
+
+ public MapColorSpaceData() {
+ Arrays.fill(this.colors, new Color(0, 0, 0, 0));
+ }
+
+ /**
+ * Clears only the RGB data. Equivalent to using {@link #set(int, byte)} on all RGB colors.
+ */
+ public final void clearRGBData() {
+ Arrays.fill(this.data, (byte) 0);
+ }
+
+ /**
+ * Clears all data, setting all colors to transparent
+ */
+ public final void clear() {
+ Arrays.fill(this.colors, new Color(0, 0, 0, 0));
+ Arrays.fill(this.data, (byte) 0);
+ }
+
+ /**
+ * Sets all color data of this color space data to that from the input color space data
+ *
+ * @param data to set
+ */
+ public void readFrom(MapColorSpaceData data) {
+ System.arraycopy(data.data, 0, this.data, 0, this.data.length);
+ System.arraycopy(data.colors, 0, this.colors, 0, this.colors.length);
+ }
+
+ /**
+ * Sets a single map palette color
+ *
+ * @param code of the color
+ * @param color to set to
+ */
+ public final void setColor(byte code, Color color) {
+ this.colors[code & 0xFF] = color;
+ }
+
+ /**
+ * Gets a single map palette color
+ *
+ * @param code of the color
+ * @return map palette color
+ */
+ public final Color getColor(byte code) {
+ return this.colors[code & 0xFF];
+ }
+
+ /**
+ * Sets the map color code value for an rgb value
+ *
+ * @param r component
+ * @param g component
+ * @param b component
+ * @param code to set to
+ */
+ public final void set(int r, int g, int b, byte code) {
+ this.data[getDataIndex(r, g, b)] = code;
+ }
+
+ /**
+ * Gets the map color code value for an rgb value
+ *
+ * @param r component
+ * @param g component
+ * @param b component
+ * @return color code
+ */
+ public final byte get(int r, int g, int b) {
+ return this.data[getDataIndex(r, g, b)];
+ }
+
+ /**
+ * Sets the map color code for an rgb value
+ *
+ * @param index rgb compound value
+ * @param code to set to
+ */
+ public final void set(int index, byte code) {
+ this.data[index] = code;
+ }
+
+ /**
+ * Gets the map color code for an rgb value
+ *
+ * @param index rgb compound value
+ * @return color code
+ */
+ public final byte get(int index) {
+ return this.data[index];
+ }
+
+ @Override
+ public MapColorSpaceData clone() {
+ MapColorSpaceData clone = new MapColorSpaceData();
+ System.arraycopy(this.colors, 0, clone.colors, 0, this.colors.length);
+ System.arraycopy(this.data, 0, clone.data, 0, this.data.length);
+ return clone;
+ }
+
+ /**
+ * Gets the mapping index of an rgb value
+ *
+ * @param r component
+ * @param g component
+ * @param b component
+ * @return index
+ */
+ private static int getDataIndex(byte r, byte g, byte b) {
+ return (r & 0xFF) + ((g & 0xFF) << 8) + ((b & 0xFF) << 16);
+ }
+
+ /**
+ * Gets the mapping index of an rgb value
+ *
+ * @param r component
+ * @param g component
+ * @param b component
+ * @return index
+ */
+ private static int getDataIndex(int r, int g, int b) {
+ return (r & 0xFF) + ((g & 0xFF) << 8) + ((b & 0xFF) << 16);
+ }
+}
diff --git a/src/main/resources/com/bergerkiller/bukkit/common/internal/resources/map/map_1_12.bub b/src/main/resources/com/bergerkiller/bukkit/common/internal/resources/map/map_1_12.bub
new file mode 100644
index 0000000..23ee24d
Binary files /dev/null and b/src/main/resources/com/bergerkiller/bukkit/common/internal/resources/map/map_1_12.bub differ
diff --git a/src/main/resources/com/bergerkiller/bukkit/common/internal/resources/map/map_1_16.bub b/src/main/resources/com/bergerkiller/bukkit/common/internal/resources/map/map_1_16.bub
new file mode 100644
index 0000000..3d25c20
Binary files /dev/null and b/src/main/resources/com/bergerkiller/bukkit/common/internal/resources/map/map_1_16.bub differ
diff --git a/src/main/resources/com/bergerkiller/bukkit/common/internal/resources/map/map_1_17.bub b/src/main/resources/com/bergerkiller/bukkit/common/internal/resources/map/map_1_17.bub
new file mode 100644
index 0000000..63334a9
Binary files /dev/null and b/src/main/resources/com/bergerkiller/bukkit/common/internal/resources/map/map_1_17.bub differ
diff --git a/src/main/resources/com/bergerkiller/bukkit/common/internal/resources/map/map_1_8_8.bub b/src/main/resources/com/bergerkiller/bukkit/common/internal/resources/map/map_1_8_8.bub
new file mode 100644
index 0000000..1e22e3a
Binary files /dev/null and b/src/main/resources/com/bergerkiller/bukkit/common/internal/resources/map/map_1_8_8.bub differ
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 5d3f2fc..9418e75 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -5,7 +5,7 @@ api-version: 1.13
authors: [ inventivetalent, SBDeveloper ]
description: This API helps developer with viewing images on maps.
website: https://sbdevelopment.tech
-softdepend: [ BKCommonLib, ProtocolLib ]
+softdepend: [ ProtocolLib ]
commands:
mapmanager:
description: The main command of MapManager.