001package net.tnemc.plugincore.core.module; 002 003import net.tnemc.plugincore.PluginCore; 004 005import java.io.IOException; 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 ModuleWrapper { 026 027 ModuleInfo info; 028 Module module; 029 URLClassLoader loader; 030 031 public ModuleWrapper(Module module) { 032 this.module = module; 033 } 034 035 public void unload() { 036 try { 037 loader.close(); 038 loader = null; 039 System.gc(); 040 } catch (IOException ignore) { 041 PluginCore.log().inform("ModuleOld " + info.name() + " unloaded incorrectly."); 042 } 043 info = null; 044 } 045 046 public String name() { 047 if(info == null) return "unknown"; 048 return info.name(); 049 } 050 051 public String version() { 052 if(info == null) return "unknown"; 053 return info.version(); 054 } 055 056 public String author() { 057 if(info == null) return "unknown"; 058 return info.author(); 059 } 060 061 public ModuleInfo getInfo() { 062 return info; 063 } 064 065 public void setInfo(ModuleInfo info) { 066 this.info = info; 067 } 068 069 public Module getModule() { 070 return module; 071 } 072 073 public void setModule(Module module) { 074 this.module = module; 075 } 076 077 public URLClassLoader getLoader() { 078 return loader; 079 } 080 081 public void setLoader(URLClassLoader loader) { 082 this.loader = loader; 083 } 084}