Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#5139 added prior mapID to onChangeMap #5140

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
16 changes: 11 additions & 5 deletions src/main/java/net/rptools/maptool/events/ZoneLoadedListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.google.common.eventbus.Subscribe;
import java.util.Collections;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
import net.rptools.maptool.client.MapTool;
import net.rptools.maptool.client.events.ZoneLoaded;
Expand All @@ -30,6 +31,8 @@
public class ZoneLoadedListener {
private static final Logger LOGGER = LogManager.getLogger(EventMacroUtil.class);
public static final String ON_CHANGE_MAP_CALLBACK = "onChangeMap";
public String priorMapID =
MapTool.getFrame().getCurrentZoneRenderer().getZone().getId().toString();

public ZoneLoadedListener() {
new MapToolEventBus().getMainEventBus().register(this);
Expand All @@ -38,6 +41,12 @@ public ZoneLoadedListener() {
@Subscribe
public void OnChangedMap(ZoneLoaded event) {
ZoneRenderer currentZR = MapTool.getFrame().getCurrentZoneRenderer();
String oCMoutput = currentZR.getZone().getId().toString();
for (ZoneRenderer zr : MapTool.getFrame().getZoneRenderers()) {
if (Objects.equals(zr.getZone().getId().toString(), priorMapID)) {
oCMoutput = oCMoutput + ", " + priorMapID;
}
}
try {
var libs = new LibraryManager().getLegacyEventTargets(ON_CHANGE_MAP_CALLBACK).get();
if (libs.isEmpty()) {
Expand All @@ -47,11 +56,7 @@ public void OnChangedMap(ZoneLoaded event) {
try {
String libraryNamespace = handler.getNamespace().get();
EventMacroUtil.callEventHandler(
ON_CHANGE_MAP_CALLBACK,
libraryNamespace,
currentZR.getZone().getId().toString(),
null,
Collections.emptyMap());
ON_CHANGE_MAP_CALLBACK, libraryNamespace, oCMoutput, null, Collections.emptyMap());
} catch (InterruptedException | ExecutionException e) {
LOGGER.error(I18N.getText("library.error.notFound"), e);
throw new AssertionError("Error retrieving library namespace");
Expand All @@ -60,5 +65,6 @@ public void OnChangedMap(ZoneLoaded event) {
} catch (InterruptedException | ExecutionException e) {
LOGGER.error(I18N.getText("library.error.retrievingEventHandler"), e);
}
priorMapID = currentZR.getZone().getId().toString();
}
}
Loading