Fix duplicate cursor creation, close #185

feat/data-edit-commands
William278 1 year ago
parent 6fc827dedf
commit b205643fdd

@ -211,7 +211,8 @@ public interface BukkitMapPersister {
} }
// Create a new map view renderer with the map data color at each pixel // Create a new map view renderer with the map data color at each pixel
view.getRenderers().clear(); // use view.removeRenderer() to remove all this maps renderers
view.getRenderers().forEach(view::removeRenderer);
view.addRenderer(new PersistentMapRenderer(canvasData)); view.addRenderer(new PersistentMapRenderer(canvasData));
view.setLocked(true); view.setLocked(true);
view.setScale(MapView.Scale.NORMAL); view.setScale(MapView.Scale.NORMAL);
@ -306,6 +307,10 @@ public interface BukkitMapPersister {
// Set the map banners and markers // Set the map banners and markers
final MapCursorCollection cursors = canvas.getCursors(); final MapCursorCollection cursors = canvas.getCursors();
while (cursors.size() > 0) {
cursors.removeCursor(cursors.getCursor(0));
}
canvasData.getBanners().forEach(banner -> cursors.addCursor(createBannerCursor(banner))); canvasData.getBanners().forEach(banner -> cursors.addCursor(createBannerCursor(banner)));
canvas.setCursors(cursors); canvas.setCursors(cursors);
} }
@ -412,12 +417,13 @@ public interface BukkitMapPersister {
@NotNull @NotNull
private MapData extractMapData() { private MapData extractMapData() {
final List<MapBanner> banners = new ArrayList<>(); final List<MapBanner> banners = new ArrayList<>();
final String BANNER_PREFIX = "banner_";
for (int i = 0; i < getCursors().size(); i++) { for (int i = 0; i < getCursors().size(); i++) {
final MapCursor cursor = getCursors().getCursor(i); final MapCursor cursor = getCursors().getCursor(i);
final String type = cursor.getType().name().toLowerCase(Locale.ENGLISH); final String type = cursor.getType().name().toLowerCase(Locale.ENGLISH);
if (type.startsWith("banner_")) { if (type.startsWith(BANNER_PREFIX)) {
banners.add(new MapBanner( banners.add(new MapBanner(
type.replaceAll("banner_", ""), type.replaceAll(BANNER_PREFIX, ""),
cursor.getCaption() == null ? "" : cursor.getCaption(), cursor.getCaption() == null ? "" : cursor.getCaption(),
cursor.getX(), cursor.getX(),
mapView.getWorld() != null ? mapView.getWorld().getSeaLevel() : 128, mapView.getWorld() != null ? mapView.getWorld().getSeaLevel() : 128,

Loading…
Cancel
Save