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 033 this.module = module; 034 } 035 036 public void unload() { 037 038 try { 039 loader.close(); 040 loader = null; 041 System.gc(); 042 } catch(IOException ignore) { 043 PluginCore.log().inform("ModuleOld " + info.name() + " unloaded incorrectly."); 044 } 045 info = null; 046 } 047 048 public String name() { 049 050 if(info == null) return "unknown"; 051 return info.name(); 052 } 053 054 public String version() { 055 056 if(info == null) return "unknown"; 057 return info.version(); 058 } 059 060 public String author() { 061 062 if(info == null) return "unknown"; 063 return info.author(); 064 } 065 066 public ModuleInfo getInfo() { 067 068 return info; 069 } 070 071 public void setInfo(ModuleInfo info) { 072 073 this.info = info; 074 } 075 076 public Module getModule() { 077 078 return module; 079 } 080 081 public void setModule(Module module) { 082 083 this.module = module; 084 } 085 086 public URLClassLoader getLoader() { 087 088 return loader; 089 } 090 091 public void setLoader(URLClassLoader loader) { 092 093 this.loader = loader; 094 } 095}