granny / Pl3xMap

Pl3xMap is a minimalistic and lightweight world map viewer for Minecraft servers using the vanilla Minecraft rendering style
https://modrinth.com/plugin/pl3xmap
MIT License
64 stars 85 forks source link

Pl3xMapEnabledEvent gets called too early #23

Closed gjorgdy closed 7 months ago

gjorgdy commented 7 months ago

I'm trying to load in markers on start with this event, but when the event is called. The WorldRegistry (Pl3xMap.api().getWorldRegistry()) is still empty. Meaning I can't make a layer and thus not register markers.

Main class;

@Override
public void onInitializeServer() {
    ServerLifecycleEvents.SERVER_STARTING.register(server -> {
        SERVER = server;
        Pl3xMap.api().getEventRegistry().register(new Pl3xMapStart());
    });
}

Event;


private static class Pl3xMapStart implements EventListener {
    @EventHandler
    public void onEnable(Pl3xMapEnabledEvent event) {
            // initialize manager
            MARKER_MANAGER.loadLodestones(); // this creates markers and tries to register them
        }
    }
}```
granny commented 7 months ago

WorldLoadedEvent and WorldUnloadedEvent Pl3xMap events exist for this reason. You can register/unregister your layers through those events.