@@ -9,12 +9,12 @@ import org.bukkit.map.MapFont.CharacterSprite;
|
||||
import org.bukkit.map.MapPalette;
|
||||
|
||||
public class CraftMapCanvas implements MapCanvas {
|
||||
|
||||
|
||||
private final byte[] buffer = new byte[128 * 128];
|
||||
private final CraftMapView mapView;
|
||||
private byte[] base;
|
||||
private MapCursorCollection cursors = new MapCursorCollection();
|
||||
|
||||
|
||||
protected CraftMapCanvas(CraftMapView mapView) {
|
||||
this.mapView = mapView;
|
||||
Arrays.fill(buffer, (byte) -1);
|
||||
@@ -33,7 +33,8 @@ public class CraftMapCanvas implements MapCanvas {
|
||||
}
|
||||
|
||||
public void setPixel(int x, int y, byte color) {
|
||||
if (x < 0 || y < 0 || x >= 128 || y >= 128) return;
|
||||
if (x < 0 || y < 0 || x >= 128 || y >= 128)
|
||||
return;
|
||||
if (buffer[y * 128 + x] != color) {
|
||||
buffer[y * 128 + x] = color;
|
||||
mapView.worldMap.flagDirty(x, y, y);
|
||||
@@ -41,19 +42,21 @@ public class CraftMapCanvas implements MapCanvas {
|
||||
}
|
||||
|
||||
public byte getPixel(int x, int y) {
|
||||
if (x < 0 || y < 0 || x >= 128 || y >= 128) return 0;
|
||||
if (x < 0 || y < 0 || x >= 128 || y >= 128)
|
||||
return 0;
|
||||
return buffer[y * 128 + x];
|
||||
}
|
||||
|
||||
public byte getBasePixel(int x, int y) {
|
||||
if (x < 0 || y < 0 || x >= 128 || y >= 128) return 0;
|
||||
if (x < 0 || y < 0 || x >= 128 || y >= 128)
|
||||
return 0;
|
||||
return base[y * 128 + x];
|
||||
}
|
||||
|
||||
|
||||
protected void setBase(byte[] base) {
|
||||
this.base = base;
|
||||
}
|
||||
|
||||
|
||||
protected byte[] getBuffer() {
|
||||
return buffer;
|
||||
}
|
||||
@@ -73,7 +76,7 @@ public class CraftMapCanvas implements MapCanvas {
|
||||
if (!font.isValid(text)) {
|
||||
throw new IllegalArgumentException("text contains invalid characters");
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < text.length(); ++i) {
|
||||
char ch = text.charAt(i);
|
||||
if (ch == '\n') {
|
||||
@@ -91,7 +94,7 @@ public class CraftMapCanvas implements MapCanvas {
|
||||
catch (NumberFormatException ex) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CharacterSprite sprite = font.getChar(text.charAt(i));
|
||||
for (int r = 0; r < font.getHeight(); ++r) {
|
||||
for (int c = 0; c < sprite.getWidth(); ++c) {
|
||||
@@ -103,5 +106,5 @@ public class CraftMapCanvas implements MapCanvas {
|
||||
x += sprite.getWidth() + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.bukkit.map.MapView;
|
||||
import org.bukkit.map.MapCursorCollection;
|
||||
|
||||
public class CraftMapRenderer extends MapRenderer {
|
||||
|
||||
|
||||
private final CraftMapView mapView;
|
||||
private final WorldMap worldMap;
|
||||
|
||||
@@ -28,7 +28,7 @@ public class CraftMapRenderer extends MapRenderer {
|
||||
canvas.setPixel(x, y, worldMap.colors[y * 128 + x]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Cursors
|
||||
MapCursorCollection cursors = canvas.getCursors();
|
||||
while (cursors.size() > 0) {
|
||||
@@ -36,8 +36,8 @@ public class CraftMapRenderer extends MapRenderer {
|
||||
}
|
||||
for (int i = 0; i < worldMap.decorations.size(); ++i) {
|
||||
WorldMapDecoration decoration = (WorldMapDecoration) worldMap.decorations.get(i);
|
||||
cursors.addCursor(decoration.locX, decoration.locY, (byte)(decoration.rotation & 15), (byte)(decoration.type));
|
||||
cursors.addCursor(decoration.locX, decoration.locY, (byte) (decoration.rotation & 15), (byte) (decoration.type));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -16,12 +16,12 @@ import org.bukkit.map.MapRenderer;
|
||||
import org.bukkit.map.MapView;
|
||||
|
||||
public final class CraftMapView implements MapView {
|
||||
|
||||
|
||||
private final Map<CraftPlayer, RenderData> renderCache = new HashMap<CraftPlayer, RenderData>();
|
||||
private final List<MapRenderer> renderers = new ArrayList<MapRenderer>();
|
||||
private final Map<MapRenderer, Map<CraftPlayer, CraftMapCanvas>> canvases = new HashMap<MapRenderer, Map<CraftPlayer, CraftMapCanvas>>();
|
||||
protected final WorldMap worldMap;
|
||||
|
||||
|
||||
public CraftMapView(WorldMap worldMap) {
|
||||
this.worldMap = worldMap;
|
||||
addRenderer(new CraftMapRenderer(this, worldMap));
|
||||
@@ -52,7 +52,7 @@ public final class CraftMapView implements MapView {
|
||||
public void setScale(Scale scale) {
|
||||
worldMap.scale = scale.getValue();
|
||||
}
|
||||
|
||||
|
||||
public World getWorld() {
|
||||
byte dimension = worldMap.map;
|
||||
for (World world : Bukkit.getServer().getWorlds()) {
|
||||
@@ -111,51 +111,51 @@ public final class CraftMapView implements MapView {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean isContextual() {
|
||||
for (MapRenderer renderer : renderers) {
|
||||
if (renderer.isContextual()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public RenderData render(CraftPlayer player) {
|
||||
boolean context = isContextual();
|
||||
RenderData render = renderCache.get(context ? player : null);
|
||||
|
||||
|
||||
if (render == null) {
|
||||
render = new RenderData();
|
||||
renderCache.put(context ? player : null, render);
|
||||
}
|
||||
|
||||
|
||||
if (context && renderCache.containsKey(null)) {
|
||||
renderCache.remove(null);
|
||||
}
|
||||
|
||||
|
||||
Arrays.fill(render.buffer, (byte) 0);
|
||||
render.cursors.clear();
|
||||
|
||||
|
||||
for (MapRenderer renderer : renderers) {
|
||||
CraftMapCanvas canvas = canvases.get(renderer).get(renderer.isContextual() ? player : null);
|
||||
if (canvas == null) {
|
||||
canvas = new CraftMapCanvas(this);
|
||||
canvases.get(renderer).put(renderer.isContextual() ? player : null, canvas);
|
||||
}
|
||||
|
||||
|
||||
canvas.setBase(render.buffer);
|
||||
renderer.render(this, canvas, player);
|
||||
|
||||
|
||||
byte[] buf = canvas.getBuffer();
|
||||
for (int i = 0; i < buf.length; ++i) {
|
||||
if (buf[i] >= 0) render.buffer[i] = buf[i];
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < canvas.getCursors().size(); ++i) {
|
||||
render.cursors.add(canvas.getCursors().getCursor(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return render;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -4,13 +4,13 @@ import java.util.ArrayList;
|
||||
import org.bukkit.map.MapCursor;
|
||||
|
||||
public class RenderData {
|
||||
|
||||
|
||||
public final byte[] buffer;
|
||||
public final ArrayList<MapCursor> cursors;
|
||||
|
||||
|
||||
public RenderData() {
|
||||
this.buffer = new byte[128 * 128];
|
||||
this.cursors = new ArrayList<MapCursor>();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user