2

Using the bukkit API, is it possible to make a call that would do something like the following pseudocode:

Bukkit.getPluginManager().getPlugin("PluginName").getJarFile();

Where for a plugin like MobBountyReloaded, it would return plugins/MobBountyReloaded_v235.jar.

I tried just looking for files using well-known naming-schemes like just appending .jar or <version>.jar to the name of the plugin, but that doesn't always yield correct results. The above example fails because the version number in the plugin.yml file is just 235 and not _v235, and some plugins use schemes like <PluginName>-<Version>-<buildnumber>.jar.

Is there a simple way to accomplish this? The File information for every loaded plugin must be somewhere in memory, no?

4

2 回答 2

6

If you have a class loaded from the plugin, you can use the code source feature to get the jar from which the class was loaded.

Bukkit.getPluginManager().getPlugin("PluginName").getClass().getProtectionDomain().getCodeSource().getLocation();
于 2012-09-06T15:44:01.543 回答
1

in your org.bukkit.plugin.java.JavaPlugin subclass,

this.getFile().getAbsoluteFile();

returns full jar file name with path where just this.getFile() returns something like this: "plugins\clj-minecraft-1.0.1-SNAPSHOT-standalone.jar"

in my case I needed this: "file:/S:/cb/plugins/memorystone-2.0.0-SNAPSHOT.jar" as an URL(not URI) which was: this.getFile().toURI().toURL();

tested in [org.bukkit/bukkit "1.4.5-R0.3-SNAPSHOT"]

于 2012-12-04T06:49:52.780 回答