Skip to content

Commit 89f3731

Browse files
Pr0metheanMomothereal
authored andcommitted
Partial implementation of sendMap (#605)
Fixes #572
1 parent c4b9ed6 commit 89f3731

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

src/main/java/net/glowstone/entity/GlowPlayer.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import net.glowstone.inventory.InventoryMonitor;
6262
import net.glowstone.inventory.crafting.PlayerRecipeMonitor;
6363
import net.glowstone.io.PlayerDataService.PlayerReader;
64+
import net.glowstone.map.GlowMapCanvas;
6465
import net.glowstone.net.GlowSession;
6566
import net.glowstone.net.message.play.entity.AnimateEntityMessage;
6667
import net.glowstone.net.message.play.entity.DestroyEntitiesMessage;
@@ -73,6 +74,7 @@
7374
import net.glowstone.net.message.play.game.ExperienceMessage;
7475
import net.glowstone.net.message.play.game.HealthMessage;
7576
import net.glowstone.net.message.play.game.JoinGameMessage;
77+
import net.glowstone.net.message.play.game.MapDataMessage;
7678
import net.glowstone.net.message.play.game.MultiBlockChangeMessage;
7779
import net.glowstone.net.message.play.game.NamedSoundEffectMessage;
7880
import net.glowstone.net.message.play.game.PlayEffectMessage;
@@ -2404,7 +2406,9 @@ public void sendBlockEntityChange(Location location, GlowBlockEntity type, Compo
24042406

24052407
@Override
24062408
public void sendMap(MapView map) {
2407-
throw new UnsupportedOperationException("Not supported yet.");
2409+
GlowMapCanvas mapCanvas = GlowMapCanvas.createAndRender(map, this);
2410+
session.send(new MapDataMessage(map.getId(), map.getScale().ordinal(), Collections.emptyList(),
2411+
mapCanvas.toSection()));
24082412
}
24092413

24102414
@Override

src/main/java/net/glowstone/map/GlowMapCanvas.java

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package net.glowstone.map;
22

33
import java.awt.Image;
4+
import net.glowstone.net.message.play.game.MapDataMessage.Section;
5+
import org.bukkit.entity.Player;
46
import org.bukkit.map.MapCanvas;
57
import org.bukkit.map.MapCursorCollection;
68
import org.bukkit.map.MapFont;
9+
import org.bukkit.map.MapRenderer;
10+
import org.bukkit.map.MapView;
711

812
/**
913
* Represents a canvas for drawing to a map. Each canvas is associated with a specific {@link org.bukkit.map.MapRenderer} and represents that renderer's layer on the map.
@@ -12,16 +16,25 @@ public final class GlowMapCanvas implements MapCanvas {
1216

1317
public static final int MAP_SIZE = 128;
1418
private final byte[] buffer = new byte[MAP_SIZE * MAP_SIZE];
15-
private final GlowMapView mapView;
19+
private final MapView mapView;
1620
private MapCursorCollection cursors = new MapCursorCollection();
1721
private byte[] base;
1822

19-
protected GlowMapCanvas(GlowMapView mapView) {
23+
public static GlowMapCanvas createAndRender(MapView mapView, Player player) {
24+
GlowMapCanvas out = new GlowMapCanvas(mapView);
25+
for (MapRenderer renderer : mapView.getRenderers()) {
26+
renderer.initialize(mapView);
27+
renderer.render(mapView, out, player);
28+
}
29+
return out;
30+
}
31+
32+
protected GlowMapCanvas(MapView mapView) {
2033
this.mapView = mapView;
2134
}
2235

2336
@Override
24-
public GlowMapView getMapView() {
37+
public MapView getMapView() {
2538
return mapView;
2639
}
2740

@@ -80,4 +93,7 @@ public void drawText(int x, int y, MapFont font, String text) {
8093
throw new UnsupportedOperationException("Not supported yet.");
8194
}
8295

96+
public Section toSection() {
97+
return new Section(MAP_SIZE, MAP_SIZE, mapView.getCenterX(), mapView.getCenterZ(), buffer.clone());
98+
}
8399
}

src/main/java/net/glowstone/map/GlowMapView.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.HashMap;
55
import java.util.List;
66
import java.util.Map;
7-
import net.glowstone.GlowWorld;
87
import net.glowstone.entity.GlowPlayer;
98
import org.bukkit.World;
109
import org.bukkit.map.MapRenderer;
@@ -21,9 +20,9 @@ public final class GlowMapView implements MapView {
2120
private final short id;
2221
private Scale scale;
2322
private int x, z;
24-
private GlowWorld world;
23+
private World world;
2524

26-
protected GlowMapView(GlowWorld world, short id) {
25+
protected GlowMapView(World world, short id) {
2726
this.world = world;
2827
this.id = id;
2928
x = world.getSpawnLocation().getBlockX();
@@ -76,13 +75,13 @@ public void setCenterZ(int z) {
7675
}
7776

7877
@Override
79-
public GlowWorld getWorld() {
78+
public World getWorld() {
8079
return world;
8180
}
8281

8382
@Override
8483
public void setWorld(World world) {
85-
this.world = (GlowWorld) world;
84+
this.world = world;
8685
}
8786

8887
@Override

0 commit comments

Comments
 (0)