// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.server.core.plugin;

import com.hypixel.hytale.assetstore.AssetPack;
import java.util.logging.Level;
import com.hypixel.hytale.common.plugin.PluginIdentifier;
import com.hypixel.hytale.server.core.asset.AssetModule;
import javax.annotation.Nonnull;
import java.nio.file.Path;

public abstract class JavaPlugin extends PluginBase
{
    @Nonnull
    private final Path file;
    @Nonnull
    private final PluginClassLoader classLoader;
    
    public JavaPlugin(@Nonnull final JavaPluginInit init) {
        super(init);
        this.file = init.getFile();
        (this.classLoader = init.getClassLoader()).setPlugin(this);
    }
    
    @Nonnull
    public Path getFile() {
        return this.file;
    }
    
    @Override
    protected void start0() {
        super.start0();
        if (this.getManifest().includesAssetPack()) {
            final AssetModule assetModule = AssetModule.get();
            final String id = new PluginIdentifier(this.getManifest()).toString();
            final AssetPack existing = assetModule.getAssetPack(id);
            if (existing != null) {
                this.getLogger().at(Level.WARNING).log("Asset pack %s already exists, skipping embedded pack", id);
                return;
            }
            assetModule.registerPack(id, this.file, this.getManifest());
        }
    }
    
    @Nonnull
    public PluginClassLoader getClassLoader() {
        return this.classLoader;
    }
    
    @Nonnull
    @Override
    public final PluginType getType() {
        return PluginType.PLUGIN;
    }
}
