mirror of
https://github.com/WiIIiam278/HuskSync.git
synced 2025-12-19 14:59:21 +00:00
refactor(paper): improve handling of locked maps in item frames
This commit is contained in:
@@ -135,7 +135,7 @@ public class BukkitEventListener extends EventListener implements BukkitJoinEven
|
|||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onMapInitialize(@NotNull MapInitializeEvent event) {
|
public void onMapInitialize(@NotNull MapInitializeEvent event) {
|
||||||
if (plugin.getSettings().getSynchronization().isPersistLockedMaps() && event.getMap().isLocked()) {
|
if (plugin.getSettings().getSynchronization().isPersistLockedMaps() && event.getMap().isLocked()) {
|
||||||
getPlugin().runAsync(() -> ((BukkitHuskSync) plugin).renderPersistedMap(event.getMap()));
|
getPlugin().runAsync(() -> ((BukkitHuskSync) plugin).renderInitializingLockedMap(event.getMap()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -335,8 +335,21 @@ public interface BukkitMapHandler {
|
|||||||
getPlugin().debug("Bound map to view (#%s) on server %s".formatted(id, currentServer));
|
getPlugin().debug("Bound map to view (#%s) on server %s".formatted(id, currentServer));
|
||||||
}
|
}
|
||||||
|
|
||||||
default void renderPersistedMap(@NotNull MapView view) {
|
// Render a persisted locked map that is initializing (i.e. in an item frame)
|
||||||
if (getMapView(view.getId()).isPresent()) return;
|
default void renderInitializingLockedMap(@NotNull MapView view) {
|
||||||
|
if (view.isVirtual()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final Optional<MapView> optionalView = getMapView(view.getId());
|
||||||
|
if (optionalView.isPresent()) {
|
||||||
|
view.getRenderers().clear();
|
||||||
|
view.getRenderers().addAll(optionalView.get().getRenderers());
|
||||||
|
view.setLocked(true);
|
||||||
|
view.setScale(MapView.Scale.NORMAL);
|
||||||
|
view.setTrackingPosition(false);
|
||||||
|
view.setUnlimitedTracking(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Map.Entry<MapData, Boolean> data = readMapData(getPlugin().getServerName(), view.getId());
|
Map.Entry<MapData, Boolean> data = readMapData(getPlugin().getServerName(), view.getId());
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
@@ -345,12 +358,13 @@ public interface BukkitMapHandler {
|
|||||||
|
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
World world = view.getWorld() == null ? getDefaultMapWorld() : view.getWorld();
|
World world = view.getWorld() == null ? getDefaultMapWorld() : view.getWorld();
|
||||||
getPlugin().debug("Not rendering map: no data in DB for world %s, map #%s.".formatted(world.getName(), view.getId()));
|
getPlugin().debug("Not rendering map: no data in DB for world %s, map #%s."
|
||||||
|
.formatted(world.getName(), view.getId()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (data.getValue()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.getValue()) return;
|
|
||||||
|
|
||||||
renderMapView(view, data.getKey());
|
renderMapView(view, data.getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user