Add method to get Plugin ClassLoader and we're 1.3
This commit is contained in:
parent
dce8edddae
commit
5ccd68db27
@ -10,7 +10,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>bukkitutils</artifactId>
|
<artifactId>bukkitutils</artifactId>
|
||||||
<version>1.2-SNAPSHOT</version>
|
<version>1.3-SNAPSHOT</version>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
@ -27,7 +27,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>eu.mikroskeem</groupId>
|
<groupId>eu.mikroskeem</groupId>
|
||||||
<artifactId>reflect</artifactId>
|
<artifactId>reflect</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.destroystokyo.paper</groupId>
|
<groupId>com.destroystokyo.paper</groupId>
|
||||||
@ -53,4 +53,4 @@
|
|||||||
<version>RELEASE</version>
|
<version>RELEASE</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -2,9 +2,13 @@ package eu.mikroskeem.utils.bukkit;
|
|||||||
|
|
||||||
import eu.mikroskeem.utils.reflect.Reflect;
|
import eu.mikroskeem.utils.reflect.Reflect;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||||
|
import org.bukkit.plugin.java.PluginClassLoader;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ServerUtils {
|
public class ServerUtils {
|
||||||
/**
|
/**
|
||||||
@ -35,4 +39,27 @@ public class ServerUtils {
|
|||||||
}
|
}
|
||||||
return new double[]{-1, -1, -1};
|
return new double[]{-1, -1, -1};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get plugin class loader. Useful when you want to add new classes on runtime
|
||||||
|
*
|
||||||
|
* @param plugin Plugin which will be used to get plugin ClassLoader
|
||||||
|
* @return Plugin ClassLoader
|
||||||
|
*/
|
||||||
|
public static ClassLoader getPluginClassLoader(JavaPlugin plugin){
|
||||||
|
JavaPluginLoader pl = (JavaPluginLoader)plugin.getPluginLoader();
|
||||||
|
Field loadersField = Reflect.getField(pl.getClass(), "loaders");
|
||||||
|
if(loadersField != null) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<PluginClassLoader> loaders = (List<PluginClassLoader>) Reflect.readField(loadersField, pl);
|
||||||
|
if(loaders != null) {
|
||||||
|
for(PluginClassLoader loader : loaders) {
|
||||||
|
if(loader.getPlugin().getName().equals(plugin.getName())){
|
||||||
|
return loader;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user