package cd.casic.plugin.event;

import cd.casic.plugin.*;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEvent;

@Getter
@Slf4j
public class PluginUnloadedEvent extends ApplicationEvent {

    private final PluginManager pluginManager;

    private final PluginInfo pluginInfo;

    public PluginUnloadedEvent(Object source, PluginInfo pluginInfo) {
        super(source);
        this.pluginManager = (PluginManager) source;
        this.pluginInfo = pluginInfo;

        String startErrorPluginId = this.pluginInfo.getPluginId();
        PluginCache.remove(startErrorPluginId);
        PluginClassLoaderCache.remove(startErrorPluginId);
        PluginApplicationContextManager.removePluginApplicationContext(startErrorPluginId);
    }
}
