Skip to content

Commit

Permalink
Make sure to unregister only the specific listeners
Browse files Browse the repository at this point in the history
(cherry picked from commit 88a1eda)
  • Loading branch information
edoren committed Oct 26, 2024
1 parent bd6e72b commit e963e56
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
10 changes: 10 additions & 0 deletions common/src/main/java/me/edoren/skin_changer/SkinChanger.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ public SkinChanger() {
LifecycleEvent.SETUP.register(this::onSetup);
if (Platform.getEnvironment() == Env.CLIENT) {
ClientLifecycleEvent.CLIENT_SETUP.register(this::onClientSetup);
ClientLifecycleEvent.CLIENT_STOPPING.register(this::onClientStopping);
}
LifecycleEvent.SERVER_STARTED.register(this::onServerStarted);
LifecycleEvent.SERVER_STOPPED.register(this::onServerStopped);
CommandRegistrationEvent.EVENT.register(this::onCommandRegistration);
}

Expand All @@ -34,10 +36,18 @@ void onClientSetup(Minecraft client) {
ClientController.GetInstance().initialize();
}

void onClientStopping(Minecraft client) {
ClientController.GetInstance().deinitialize();
}

void onServerStarted(MinecraftServer server) {
ServerController.GetInstance().initialize(server);
}

void onServerStopped(MinecraftServer server) {
ServerController.GetInstance().deinitialize(server);
}

void onCommandRegistration(CommandDispatcher<CommandSourceStack> commandSourceStackCommandDispatcher, CommandBuildContext commandBuildContext, Commands.CommandSelection commandSelection) {
SkinsCommand.register(commandSourceStackCommandDispatcher);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ public static ClientController GetInstance() {
}

public void initialize() {
ClientTickEvent.CLIENT_PRE.clearListeners();
ClientTickEvent.CLIENT_PRE.register(this::onClientTickEvent);
}

public void deinitialize() {
ClientTickEvent.CLIENT_PRE.unregister(this::onClientTickEvent);
}

public ResourceLocation getLocationCape(PlayerModel model) {
ISkin cape = SkinLoaderService.GetInstance().getCape(model);
if (cape != null && cape.isDataReady())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ public void initialize(MinecraftServer server) {
SkinProviderController.GetInstance().registerSkinProvider(new MineskinSkinProvider());
SkinProviderController.GetInstance().registerCapeProvider(new CrafatarCapeProvider());
}

public void deinitialize(MinecraftServer server) {
SkinProviderController.GetInstance().deinitialize();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,15 @@ public void initialize(File saveFolder) {
}
this.cacheFile = cacheFile.getPath();

PlayerEvent.PLAYER_JOIN.clearListeners();
PlayerEvent.PLAYER_QUIT.clearListeners();
PlayerEvent.PLAYER_JOIN.register(this::onPlayerLogin);
PlayerEvent.PLAYER_QUIT.register(this::onPlayerLogout);
}

public void deinitialize() {
PlayerEvent.PLAYER_JOIN.unregister(this::onPlayerLogin);
PlayerEvent.PLAYER_QUIT.unregister(this::onPlayerLogout);
}

public void registerCapeProvider(ISkinProvider provider) {
providers.get(DataType.CAPE).add(provider);
}
Expand Down

0 comments on commit e963e56

Please sign in to comment.