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
029    super(new URL[]{ url }, PluginCore.instance().getClass().getClassLoader());
030  }
031
032  @Override
033  protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
034
035    try {
036      return super.loadClass(name, resolve);
037    } catch(ClassNotFoundException e) {
038      return null;
039    }
040  }
041
042  @Override
043  protected void finalize() throws Throwable {
044
045    super.finalize();
046
047    PluginCore.log().debug("ModuleOld Class Loader has been GC'd");
048  }
049}