Remove package.xml requirement for SubServers.Host

This commit is contained in:
ME1312 2018-02-19 17:59:51 -05:00
parent 92c649eabe
commit 56f8d3dfba
26 changed files with 156 additions and 103 deletions

View File

@ -289,7 +289,7 @@
<br> <br>
<div class="footer"> <div class="footer">
<hr> <hr>
<a href="javascript:void(0)" draggable="false"><img src="https://src.ME1312.net/img/me1312.net.inverted.png" draggable="false" /></a> <a href="https://www.ME1312.net" draggable="false"><img src="https://src.ME1312.net/img/me1312.net.inverted.png" draggable="false" /></a>
<div><a href="https://github.com/ME1312/SubServers-2/tree/master/Artifacts" target="_blank" draggable="false">Download not working?</a></div> <div><a href="https://github.com/ME1312/SubServers-2/tree/master/Artifacts" target="_blank" draggable="false">Download not working?</a></div>
</div> </div>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script> <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -703,6 +703,8 @@
<dd> <dd>
<div class="block">Gets this Plugin's data folder</div> <div class="block">Gets this Plugin's data folder</div>
</dd> </dd>
<dt><span class="memberNameLink"><a href="net/ME1312/SubServers/Host/Library/PluginClassLoader.html#getDefaultClass--">getDefaultClass()</a></span> - Method in class net.ME1312.SubServers.Host.Library.<a href="net/ME1312/SubServers/Host/Library/PluginClassLoader.html" title="class in net.ME1312.SubServers.Host.Library">PluginClassLoader</a></dt>
<dd>&nbsp;</dd>
<dt><span class="memberNameLink"><a href="net/ME1312/SubServers/Host/Library/Config/YAMLValue.html#getDefiningSection--">getDefiningSection()</a></span> - Method in class net.ME1312.SubServers.Host.Library.Config.<a href="net/ME1312/SubServers/Host/Library/Config/YAMLValue.html" title="class in net.ME1312.SubServers.Host.Library.Config">YAMLValue</a></dt> <dt><span class="memberNameLink"><a href="net/ME1312/SubServers/Host/Library/Config/YAMLValue.html#getDefiningSection--">getDefiningSection()</a></span> - Method in class net.ME1312.SubServers.Host.Library.Config.<a href="net/ME1312/SubServers/Host/Library/Config/YAMLValue.html" title="class in net.ME1312.SubServers.Host.Library.Config">YAMLValue</a></dt>
<dd> <dd>
<div class="block">Get the YAML Section this Object was defined in</div> <div class="block">Get the YAML Section this Object was defined in</div>
@ -1997,6 +1999,8 @@
<dd> <dd>
<div class="block">Sets the Command to be Sent</div> <div class="block">Sets the Command to be Sent</div>
</dd> </dd>
<dt><span class="memberNameLink"><a href="net/ME1312/SubServers/Host/Library/PluginClassLoader.html#setDefaultClass-java.lang.Class-">setDefaultClass(Class&lt;?&gt;)</a></span> - Method in class net.ME1312.SubServers.Host.Library.<a href="net/ME1312/SubServers/Host/Library/PluginClassLoader.html" title="class in net.ME1312.SubServers.Host.Library">PluginClassLoader</a></dt>
<dd>&nbsp;</dd>
<dt><span class="memberNameLink"><a href="net/ME1312/SubServers/Host/Executable/SubCreator.ServerTemplate.html#setDisplayName-java.lang.String-">setDisplayName(String)</a></span> - Method in class net.ME1312.SubServers.Host.Executable.<a href="net/ME1312/SubServers/Host/Executable/SubCreator.ServerTemplate.html" title="class in net.ME1312.SubServers.Host.Executable">SubCreator.ServerTemplate</a></dt> <dt><span class="memberNameLink"><a href="net/ME1312/SubServers/Host/Executable/SubCreator.ServerTemplate.html#setDisplayName-java.lang.String-">setDisplayName(String)</a></span> - Method in class net.ME1312.SubServers.Host.Executable.<a href="net/ME1312/SubServers/Host/Executable/SubCreator.ServerTemplate.html" title="class in net.ME1312.SubServers.Host.Executable">SubCreator.ServerTemplate</a></dt>
<dd> <dd>
<div class="block">Sets the Display Name for this Template</div> <div class="block">Sets the Display Name for this Template</div>

View File

@ -17,6 +17,12 @@
catch(err) { catch(err) {
} }
//--> //-->
var methods = {"i0":10,"i1":10};
var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]};
var altColor = "altColor";
var rowColor = "rowColor";
var tableTab = "tableTab";
var activeTableTab = "activeTableTab";
</script> </script>
<noscript> <noscript>
<div>JavaScript is disabled on your browser.</div> <div>JavaScript is disabled on your browser.</div>
@ -69,13 +75,13 @@
<li>Nested&nbsp;|&nbsp;</li> <li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li> <li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li> <li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#methods.inherited.from.class.java.net.URLClassLoader">Method</a></li> <li><a href="#method.summary">Method</a></li>
</ul> </ul>
<ul class="subNavList"> <ul class="subNavList">
<li>Detail:&nbsp;</li> <li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li> <li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li> <li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li>
<li>Method</li> <li><a href="#method.detail">Method</a></li>
</ul> </ul>
</div> </div>
<a name="skip.navbar.top"> <a name="skip.navbar.top">
@ -160,6 +166,21 @@ extends java.net.URLClassLoader</pre>
<!-- --> <!-- -->
</a> </a>
<h3>Method Summary</h3> <h3>Method Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
<caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd">&nbsp;</span></span><span id="t2" class="tableTab"><span><a href="javascript:show(2);">Instance Methods</a></span><span class="tabEnd">&nbsp;</span></span><span id="t4" class="tableTab"><span><a href="javascript:show(8);">Concrete Methods</a></span><span class="tabEnd">&nbsp;</span></span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Method and Description</th>
</tr>
<tr id="i0" class="altColor">
<td class="colFirst"><code>java.lang.Class&lt;?&gt;</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../net/ME1312/SubServers/Host/Library/PluginClassLoader.html#getDefaultClass--">getDefaultClass</a></span>()</code>&nbsp;</td>
</tr>
<tr id="i1" class="rowColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../net/ME1312/SubServers/Host/Library/PluginClassLoader.html#setDefaultClass-java.lang.Class-">setDefaultClass</a></span>(java.lang.Class&lt;?&gt;&nbsp;clazz)</code>&nbsp;</td>
</tr>
</table>
<ul class="blockList"> <ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.java.net.URLClassLoader"> <li class="blockList"><a name="methods.inherited.from.class.java.net.URLClassLoader">
<!-- --> <!-- -->
@ -227,6 +248,37 @@ extends java.net.URLClassLoader</pre>
</ul> </ul>
</li> </li>
</ul> </ul>
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method.detail">
<!-- -->
</a>
<h3>Method Detail</h3>
<a name="setDefaultClass-java.lang.Class-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>setDefaultClass</h4>
<pre>public&nbsp;void&nbsp;setDefaultClass(java.lang.Class&lt;?&gt;&nbsp;clazz)</pre>
</li>
</ul>
<a name="getDefaultClass--">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>getDefaultClass</h4>
<pre>public&nbsp;java.lang.Class&lt;?&gt;&nbsp;getDefaultClass()
throws java.lang.ClassNotFoundException</pre>
<dl>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code>java.lang.ClassNotFoundException</code></dd>
</dl>
</li>
</ul>
</li>
</ul>
</li> </li>
</ul> </ul>
</div> </div>
@ -280,13 +332,13 @@ extends java.net.URLClassLoader</pre>
<li>Nested&nbsp;|&nbsp;</li> <li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li> <li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li> <li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#methods.inherited.from.class.java.net.URLClassLoader">Method</a></li> <li><a href="#method.summary">Method</a></li>
</ul> </ul>
<ul class="subNavList"> <ul class="subNavList">
<li>Detail:&nbsp;</li> <li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li> <li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li> <li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li>
<li>Method</li> <li><a href="#method.detail">Method</a></li>
</ul> </ul>
</div> </div>
<a name="skip.navbar.bottom"> <a name="skip.navbar.bottom">

Binary file not shown.

Binary file not shown.

View File

@ -205,8 +205,10 @@ public class Client {
*/ */
public void disconnect() throws IOException { public void disconnect() throws IOException {
if (!socket.isClosed()) getConnection().close(); if (!socket.isClosed()) getConnection().close();
if (handler != null && handler.getSubData() != null && equals(handler.getSubData())) setHandler(null); if (handler != null) {
handler = null; setHandler(null);
handler = null;
}
closed = true; closed = true;
if (subdata.getClients().contains(this)) subdata.removeClient(this); if (subdata.getClients().contains(this)) subdata.removeClient(this);
} }

View File

@ -68,7 +68,7 @@ public class PacketLinkExHost implements PacketIn, PacketOut {
client.sendPacket(new PacketLinkExHost(4, "That host does not support a network interface")); client.sendPacket(new PacketLinkExHost(4, "That host does not support a network interface"));
} }
} else { } else {
client.sendPacket(new PacketLinkExHost(2, "There is no host with that name")); client.sendPacket(new PacketLinkExHost(2, "There is no host with name: " + data.getString("name")));
} }
} catch (Exception e) { } catch (Exception e) {
client.sendPacket(new PacketLinkExHost(1, e.getClass().getCanonicalName() + ": " + e.getMessage())); client.sendPacket(new PacketLinkExHost(1, e.getClass().getCanonicalName() + ": " + e.getMessage()));

View File

@ -2,7 +2,6 @@ package net.ME1312.SubServers.Bungee.Network.Packet;
import net.ME1312.SubServers.Bungee.Host.Server; import net.ME1312.SubServers.Bungee.Host.Server;
import net.ME1312.SubServers.Bungee.Host.SubServer; import net.ME1312.SubServers.Bungee.Host.SubServer;
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
import net.ME1312.SubServers.Bungee.Library.Util; import net.ME1312.SubServers.Bungee.Library.Util;
import net.ME1312.SubServers.Bungee.Library.Version.Version; import net.ME1312.SubServers.Bungee.Library.Version.Version;
import net.ME1312.SubServers.Bungee.Network.Client; import net.ME1312.SubServers.Bungee.Network.Client;
@ -12,7 +11,6 @@ import net.ME1312.SubServers.Bungee.SubPlugin;
import org.json.JSONObject; import org.json.JSONObject;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -67,9 +65,9 @@ public class PacketLinkServer implements PacketIn, PacketOut {
} else if ((server = searchIP(new InetSocketAddress(client.getAddress().getAddress(), data.getInt("port")))) != null) { } else if ((server = searchIP(new InetSocketAddress(client.getAddress().getAddress(), data.getInt("port")))) != null) {
link(client, server); link(client, server);
} else if (data.keySet().contains("name")) { } else if (data.keySet().contains("name")) {
client.sendPacket(new PacketLinkServer(null, 2, "There is no server with that name")); client.sendPacket(new PacketLinkServer(null, 2, "There is no server with name: " + data.getString("name")));
} else { } else {
client.sendPacket(new PacketLinkServer(null, 2, "Could not find server with address: " + client.getAddress().getAddress().getHostAddress() + ':' + data.getInt("port"))); client.sendPacket(new PacketLinkServer(null, 2, "There is no server with address: " + client.getAddress().getAddress().getHostAddress() + ':' + data.getInt("port")));
} }
} catch (Exception e) { } catch (Exception e) {
client.sendPacket(new PacketLinkServer(null, 1, e.getClass().getCanonicalName() + ": " + e.getMessage())); client.sendPacket(new PacketLinkServer(null, 1, e.getClass().getCanonicalName() + ": " + e.getMessage()));
@ -92,7 +90,7 @@ public class PacketLinkServer implements PacketIn, PacketOut {
Server server = null; Server server = null;
for (Server s : plugin.api.getServers().values()) { for (Server s : plugin.api.getServers().values()) {
if (s.getAddress().equals(address)) { if (s.getAddress().equals(address)) {
if (server != null) throw new InvalidServerException("Multiple servers match address: " + address.getAddress().getHostAddress() + ':' + address.getPort()); if (server != null) throw new IllegalStateException("Multiple servers match address: " + address.getAddress().getHostAddress() + ':' + address.getPort());
server = s; server = s;
} }
} }

View File

@ -70,7 +70,7 @@ public final class SubCommand extends CommandX {
if (plugin.bversion == null) { if (plugin.bversion == null) {
new Thread(() -> { new Thread(() -> {
try { try {
Document updxml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(Util.readAll(new BufferedReader(new InputStreamReader(new URL("http://src.me1312.net/maven/net/ME1312/SubServers/SubServers.Bungee/maven-metadata.xml").openStream(), Charset.forName("UTF-8"))))))); Document updxml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://src.me1312.net/maven/net/ME1312/SubServers/SubServers.Bungee/maven-metadata.xml").openStream(), Charset.forName("UTF-8")))))));
NodeList updnodeList = updxml.getElementsByTagName("version"); NodeList updnodeList = updxml.getElementsByTagName("version");
Version updversion = plugin.version; Version updversion = plugin.version;

Binary file not shown.

View File

@ -54,8 +54,10 @@ public class PacketLinkServer implements PacketIn, PacketOut {
} else { } else {
try { try {
if (data.getInt("r") == 2) { if (data.getInt("r") == 2) {
plugin.config.get().getSection("Settings").getSection("SubData").set("Name", "undefined"); if (!plugin.config.get().getSection("Settings").getSection("SubData").contains("Name")) {
plugin.config.save(); plugin.config.get().getSection("Settings").getSection("SubData").set("Name", "undefined");
plugin.config.save();
}
} }
} catch (Exception e) {} } catch (Exception e) {}
Bukkit.getLogger().info("SubData > Could not link name with server: " + data.getString("m")); Bukkit.getLogger().info("SubData > Could not link name with server: " + data.getString("m"));

View File

@ -52,7 +52,7 @@ public final class SubCommand implements CommandExecutor {
if (plugin.bversion == null) { if (plugin.bversion == null) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try { try {
Document updxml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(Util.readAll(new BufferedReader(new InputStreamReader(new URL("http://src.me1312.net/maven/net/ME1312/SubServers/SubServers.Client.Bukkit/maven-metadata.xml").openStream(), Charset.forName("UTF-8"))))))); Document updxml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://src.me1312.net/maven/net/ME1312/SubServers/SubServers.Client.Bukkit/maven-metadata.xml").openStream(), Charset.forName("UTF-8")))))));
NodeList updnodeList = updxml.getElementsByTagName("version"); NodeList updnodeList = updxml.getElementsByTagName("version");
Version updversion = plugin.version; Version updversion = plugin.version;

Binary file not shown.

View File

@ -182,13 +182,11 @@ public final class ExHost {
* Find Jars * Find Jars
*/ */
UniversalFile pldir = new UniversalFile(dir, "Plugins"); UniversalFile pldir = new UniversalFile(dir, "Plugins");
LinkedList<URL> jars = new LinkedList<URL>(); LinkedList<File> pljars = new LinkedList<File>();
if (pldir.exists() && pldir.isDirectory()) for (File file : pldir.listFiles()) { if (pldir.exists() && pldir.isDirectory()) for (File file : pldir.listFiles()) {
if (file.getName().endsWith(".jar")) { if (file.getName().endsWith(".jar")) pljars.add(file);
jars.add(file.toURI().toURL());
}
} }
if (jars.size() > 0) { if (pljars.size() > 0) {
long begin = Calendar.getInstance().getTime().getTime(); long begin = Calendar.getInstance().getTime().getTime();
log.info.println("Loading SubAPI Plugins..."); log.info.println("Loading SubAPI Plugins...");
@ -196,97 +194,71 @@ public final class ExHost {
* Load Jars & Find Main Classes * Load Jars & Find Main Classes
* (Unordered) * (Unordered)
*/ */
URLClassLoader superloader = new URLClassLoader(jars.toArray(new URL[jars.size()]), this.getClass().getClassLoader()); LinkedHashMap<PluginClassLoader, NamedContainer<LinkedList<String>, LinkedHashMap<String, String>>> classes = new LinkedHashMap<PluginClassLoader, NamedContainer<LinkedList<String>, LinkedHashMap<String, String>>>();
LinkedHashMap<String, NamedContainer<LinkedList<String>, LinkedHashMap<String, String>>> classes = new LinkedHashMap<String, NamedContainer<LinkedList<String>, LinkedHashMap<String, String>>>(); for (File file : pljars) {
for (File file : pldir.listFiles()) { try {
if (file.getName().endsWith(".jar")) { JarFile jar = new JarFile(file);
try { Enumeration<JarEntry> entries = jar.entries();
JarFile jar = new JarFile(file); PluginClassLoader loader = new PluginClassLoader(this.getClass().getClassLoader(), file.toURI().toURL());
Enumeration<JarEntry> entries = jar.entries(); List<String> contents = new ArrayList<String>();
LinkedList<String> mains = new LinkedList<String>();
List<String> contents = new ArrayList<String>();
if (jar.getJarEntry("package.xml") != null) { boolean isplugin = false;
loader.setDefaultClass(ClassNotFoundException.class);
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
String cname = entry.getName().substring(0, entry.getName().length() - 6).replace('/', '.');
contents.add(cname);
try { try {
NodeList xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(jar.getInputStream(jar.getJarEntry("package.xml"))).getElementsByTagName("class"); Class<?> clazz = loader.loadClass(cname);
if (xml.getLength() > 0) { if (clazz.isAnnotationPresent(SubPlugin.class)) {
for (int i = 0; i < xml.getLength(); i++) { NamedContainer<LinkedList<String>, LinkedHashMap<String, String>> jarmap = (classes.keySet().contains(loader))?classes.get(loader):new NamedContainer<LinkedList<String>, LinkedHashMap<String, String>>(new LinkedList<String>(), new LinkedHashMap<>());
mains.add(xml.item(i).getTextContent()); for (String dependancy : clazz.getAnnotation(SubPlugin.class).dependencies()) jarmap.name().add(dependancy);
} for (String dependancy : clazz.getAnnotation(SubPlugin.class).softDependencies()) jarmap.name().add(dependancy);
jarmap.get().put(clazz.getAnnotation(SubPlugin.class).name(), cname);
classes.put(loader, jarmap);
isplugin = true;
} }
} catch (Exception e) { } catch (Throwable e) {
log.error.println(new IllegalPluginException(e, "Couldn't load package.xml for " + file.getName())); log.error.println(new IllegalPluginException(e, "Couldn't load class: " + cname));
} }
} }
boolean isplugin = false;
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
String cname = entry.getName().substring(0, entry.getName().length() - 6).replace('/', '.');
contents.add(cname);
if (mains.contains(cname)) {
mains.remove(cname);
try {
Class<?> clazz = superloader.loadClass(cname);
if (!clazz.isAnnotationPresent(SubPlugin.class))
throw new ClassCastException("Cannot find plugin descriptor");
NamedContainer<LinkedList<String>, LinkedHashMap<String, String>> jarmap = (classes.keySet().contains(file.getName()))?classes.get(file.getName()):new NamedContainer<LinkedList<String>, LinkedHashMap<String, String>>(new LinkedList<String>(), new LinkedHashMap<>());
for (String dependancy : clazz.getAnnotation(SubPlugin.class).dependencies()) jarmap.name().add(dependancy);
for (String dependancy : clazz.getAnnotation(SubPlugin.class).softDependencies()) jarmap.name().add(dependancy);
jarmap.get().put(clazz.getAnnotation(SubPlugin.class).name(), cname);
classes.put(file.getName(), jarmap);
isplugin = true;
} catch (ClassCastException e) {
log.error.println(new IllegalPluginException(e, "Main class isn't annotated as a SubPlugin: " + cname));
} catch (Throwable e) {
log.error.println(new IllegalPluginException(e, "Couldn't load main class: " + cname));
}
}
}
}
for (String main : mains) {
log.error.println(new IllegalPluginException(new ClassNotFoundException(), "Couldn't find main class: " + main));
}
if (!isplugin) {
new PluginClassLoader(this.getClass().getClassLoader(), file.toURI().toURL());
log.info.println("Loaded Library: " + file.getName());
}
api.knownClasses.addAll(contents);
jar.close();
} catch (Throwable e) {
log.error.println(new InvocationTargetException(e, "Problem searching plugin jar: " + file.getName()));
} }
loader.setDefaultClass(null);
if (!isplugin) {
new PluginClassLoader(this.getClass().getClassLoader(), file.toURI().toURL());
log.info.println("Loaded Library: " + file.getName());
}
api.knownClasses.addAll(contents);
jar.close();
} catch (Throwable e) {
log.error.println(new InvocationTargetException(e, "Problem searching plugin jar: " + file.getName()));
} }
} }
superloader.close();
/* /*
* Load Main Classes & Plugin Descriptions * Load Main Classes & Plugin Descriptions
* (Ordered by Known Dependencies) * (Ordered by Known Dependencies)
*/ */
int progress = 1; int progress = 1;
HashMap<String, PluginClassLoader> loaders = new HashMap<String, PluginClassLoader>();
HashMap<String, SubPluginInfo> plugins = new LinkedHashMap<String, SubPluginInfo>(); HashMap<String, SubPluginInfo> plugins = new LinkedHashMap<String, SubPluginInfo>();
while (classes.size() > 0) { while (classes.size() > 0) {
LinkedHashMap<String, LinkedList<String>> loaded = new LinkedHashMap<String, LinkedList<String>>(); LinkedHashMap<PluginClassLoader, LinkedList<String>> loaded = new LinkedHashMap<PluginClassLoader, LinkedList<String>>();
for (String jar : classes.keySet()) { for (PluginClassLoader loader : classes.keySet()) {
LinkedList<String> loadedlist = new LinkedList<String>(); LinkedList<String> loadedlist = new LinkedList<String>();
if (!loaders.keySet().contains(jar)) loaders.put(jar, new PluginClassLoader(this.getClass().getClassLoader(), new File(pldir, jar).toURI().toURL())); for (String name : classes.get(loader).get().keySet()) {
for (String name : classes.get(jar).get().keySet()) {
boolean load = true; boolean load = true;
for (String depend : classes.get(jar).name()) { for (String depend : classes.get(loader).name()) {
if (!plugins.keySet().contains(depend.toLowerCase())) { if (!plugins.keySet().contains(depend.toLowerCase())) {
load = progress <= 0; load = progress <= 0;
} }
} }
if (load) { if (load) {
String main = classes.get(jar).get().get(name); String main = classes.get(loader).get().get(name);
try { try {
Class<?> clazz = loaders.get(jar).loadClass(main); Class<?> clazz = loader.loadClass(main);
if (!clazz.isAnnotationPresent(SubPlugin.class)) if (!clazz.isAnnotationPresent(SubPlugin.class))
throw new ClassCastException("Cannot find plugin descriptor"); throw new ClassCastException("Cannot find plugin descriptor");
@ -313,17 +285,17 @@ public final class ExHost {
loadedlist.add(name); loadedlist.add(name);
} }
} }
if (loadedlist.size() > 0) loaded.put(jar, loadedlist); if (loadedlist.size() > 0) loaded.put(loader, loadedlist);
} }
progress = 0; progress = 0;
for (String jar : loaded.keySet()) { for (PluginClassLoader loader : loaded.keySet()) {
NamedContainer<LinkedList<String>, LinkedHashMap<String, String>> jarmap = classes.get(jar); NamedContainer<LinkedList<String>, LinkedHashMap<String, String>> jarmap = classes.get(loader);
progress++; progress++;
for (String main : loaded.get(jar)) jarmap.get().remove(main); for (String main : loaded.get(loader)) jarmap.get().remove(main);
if (jarmap.get().size() > 0) { if (jarmap.get().size() > 0) {
classes.put(jar, jarmap); classes.put(loader, jarmap);
} else { } else {
classes.remove(jar); classes.remove(loader);
} }
} }
} }

View File

@ -10,7 +10,8 @@ import java.util.concurrent.CopyOnWriteArraySet;
* Plugin ClassLoader Class * Plugin ClassLoader Class
*/ */
public class PluginClassLoader extends URLClassLoader { public class PluginClassLoader extends URLClassLoader {
private static final Set<PluginClassLoader> loaders = new CopyOnWriteArraySet<PluginClassLoader>(); private static Set<PluginClassLoader> loaders = new CopyOnWriteArraySet<PluginClassLoader>();
private Class<?> defaultClass = null;
/** /**
* Load Classes from URLs * Load Classes from URLs
@ -33,6 +34,26 @@ public class PluginClassLoader extends URLClassLoader {
loaders.add(this); loaders.add(this);
} }
public void setDefaultClass(Class<?> clazz) {
this.defaultClass = clazz;
}
public Class<?> getDefaultClass() throws ClassNotFoundException {
if (defaultClass == null) {
throw new ClassNotFoundException();
} else {
return defaultClass;
}
}
private Class<?> getDefaultClass(String name) throws ClassNotFoundException {
try {
return getDefaultClass();
} catch (ClassNotFoundException e) {
throw new ClassNotFoundException(name);
}
}
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
return this.loadClass(name, resolve, true); return this.loadClass(name, resolve, true);
} }
@ -40,7 +61,7 @@ public class PluginClassLoader extends URLClassLoader {
private Class<?> loadClass(String name, boolean resolve, boolean check) throws ClassNotFoundException { private Class<?> loadClass(String name, boolean resolve, boolean check) throws ClassNotFoundException {
try { try {
return super.loadClass(name, resolve); return super.loadClass(name, resolve);
} catch (ClassNotFoundException e) { } catch (NoClassDefFoundError | ClassNotFoundException e) {
if (check) { if (check) {
Iterator i = loaders.iterator(); Iterator i = loaders.iterator();
@ -48,17 +69,17 @@ public class PluginClassLoader extends URLClassLoader {
PluginClassLoader loader; PluginClassLoader loader;
do { do {
if (!i.hasNext()) { if (!i.hasNext()) {
throw new ClassNotFoundException(name); return getDefaultClass(name);
} }
loader = (PluginClassLoader) i.next(); loader = (PluginClassLoader) i.next();
} while (loader == this); } while (loader == this);
try { try {
return loader.loadClass(name, resolve, false); return loader.loadClass(name, resolve, false);
} catch (ClassNotFoundException ex) {} } catch (NoClassDefFoundError | ClassNotFoundException ex) {}
} }
} else { } else {
throw new ClassNotFoundException(name); return getDefaultClass(name);
} }
} }
} }

View File

@ -37,7 +37,7 @@ public class SubCommand {
if (host.bversion == null) { if (host.bversion == null) {
new Thread(() -> { new Thread(() -> {
try { try {
Document updxml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(Util.readAll(new BufferedReader(new InputStreamReader(new URL("http://src.me1312.net/maven/net/ME1312/SubServers/SubServers.Host/maven-metadata.xml").openStream(), Charset.forName("UTF-8"))))))); Document updxml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://src.me1312.net/maven/net/ME1312/SubServers/SubServers.Host/maven-metadata.xml").openStream(), Charset.forName("UTF-8")))))));
NodeList updnodeList = updxml.getElementsByTagName("version"); NodeList updnodeList = updxml.getElementsByTagName("version");
Version updversion = host.version; Version updversion = host.version;

Binary file not shown.

View File

@ -45,8 +45,10 @@ public class PacketLinkProxy implements PacketIn, PacketOut {
} else { } else {
try { try {
if (data.getInt("r") == 2) { if (data.getInt("r") == 2) {
plugin.config.get().getSection("Settings").getSection("SubData").set("Name", "undefined"); if (!plugin.config.get().getSection("Settings").getSection("SubData").contains("Name")) {
plugin.config.save(); plugin.config.get().getSection("Settings").getSection("SubData").set("Name", "undefined");
plugin.config.save();
}
} }
} catch (Exception e) {} } catch (Exception e) {}
System.out.println("SubData > Could not link name with server: " + data.getString("m")); System.out.println("SubData > Could not link name with server: " + data.getString("m"));

View File

@ -70,7 +70,7 @@ public final class SubCommand extends CommandX {
if (plugin.bversion == null) { if (plugin.bversion == null) {
new Thread(() -> { new Thread(() -> {
try { try {
Document updxml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(Util.readAll(new BufferedReader(new InputStreamReader(new URL("http://src.me1312.net/maven/net/ME1312/SubServers/SubServers.Sync/maven-metadata.xml").openStream(), Charset.forName("UTF-8"))))))); Document updxml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://src.me1312.net/maven/net/ME1312/SubServers/SubServers.Sync/maven-metadata.xml").openStream(), Charset.forName("UTF-8")))))));
NodeList updnodeList = updxml.getElementsByTagName("version"); NodeList updnodeList = updxml.getElementsByTagName("version");
Version updversion = plugin.version; Version updversion = plugin.version;