001package net.tnemc.plugincore.core.module;
002
003import net.tnemc.plugincore.PluginCore;
004
005import java.net.URL;
006import java.net.URLClassLoader;
007
008/*
009 * The New Plugin Core
010 * Copyright (C) 2022 - 2024 Daniel "creatorfromhell" Vidmar
011 *
012 * This program is free software: you can redistribute it and/or modify
013 * it under the terms of the GNU Affero General Public License as published by
014 * the Free Software Foundation, either version 3 of the License, or
015 * (at your option) any later version.
016 *
017 * This program is distributed in the hope that it will be useful,
018 * but WITHOUT ANY WARRANTY; without even the implied warranty of
019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
020 * GNU Affero General Public License for more details.
021 *
022 * You should have received a copy of the GNU Affero General Public License
023 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
024 */
025public class ModuleClassLoader extends URLClassLoader {
026
027  public ModuleClassLoader(URL url) {
028    super(new URL[]{url}, PluginCore.instance().getClass().getClassLoader());
029  }
030
031  @Override
032  protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
033    try {
034      return super.loadClass(name, resolve);
035    } catch (ClassNotFoundException e) {
036      return null;
037    }
038  }
039
040  @Override
041  protected void finalize() throws Throwable {
042    super.finalize();
043
044    PluginCore.log().debug("ModuleOld Class Loader has been GC'd");
045  }
046}