英文:
Plugin cannot be null Error - Spigot Coding
问题
抱歉,我理解您只需要翻译内容,以下是您提供的内容的翻译:
我在重新加载插件时遇到了“插件不能为空”的错误。实际上,我试图自己解决这个“错误”,但我觉得没有成功... 希望你能帮助我...
以下是一些相关的内容:
错误信息:
无法在文件夹“plugins”中加载“plugins/OwnChallenges-1.0.jar”
org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: 插件不能为空
...
导致于: java.lang.IllegalArgumentException: 插件不能为空
...
位于 com.fabo0814.ownchallenges.utils.Utils.delayIt(Utils.java:9) ~[?:?]
Main.class:
// ... 一些代码 ...
public static Main main;
PluginManager pm = Bukkit.getPluginManager();
Position pos = new Position();
@Override
public void onEnable() {
main = this;
SQL.connect();
listeners();
commands();
tab();
new Config();
new RanksConfig();
doWorldStuff();
}
// ... 一些代码 ...
Utils.class:
// ... 一些代码 ...
public static void delayIt(Runnable run, int delay) {
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getPlugin(Main.class), run, delay);
}
// ... 一些代码 ...
感谢您的任何帮助
编辑:如果我在启动服务器后重新加载插件,它在某种程度上可以正常运行。
英文:
I have the error 'Plugin cannot be null' occuring while reloading my Plugin. Actually i tried to solve this 'Bug' for myself, but I think that didn't worked... Hopefully you can help me...
Here are some relevant things:
The Error-Message:
Could not load 'plugins/OwnChallenges-1.0.jar' in folder 'plugins'
org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: Plugin cannot be null
...
Caused by: java.lang.IllegalArgumentException: Plugin cannot be null
...
at com.fabo0814.ownchallenges.utils.Utils.delayIt(Utils.java:9) ~[?:?]
Main.class:
// ... Some stuff ...
public static Main main;
PluginManager pm = Bukkit.getPluginManager();
Position pos = new Position();
@Override
public void onEnable() {
main = this;
SQL.connect();
listeners();
commands();
tab();
new Config();
new RanksConfig();
doWorldStuff();
}
// ... Some Stuff ...
Utils.class:
// ... Some Stuff ...
public static void delayIt(Runnable run, int delay) {
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getPlugin(Main.class), run, delay);
}
// ... Some Stuff ...
Thanks for any help
EDIT: If i reload the plugin after i started the server, it functions somehow.
答案1
得分: 0
不要使用 Main.getPlugin(Main.class)
,尝试使用 JavaPlugin.getPlugin(Main.class)
。另外,你为什么要创建 Main
类的实例?在Bukkit插件中不需要单例模式(实际上它并不是真正的单例,因为你无法将构造函数的访问级别设置为私有)。另外,尝试将插件的主类命名为插件的名称,例如:如果你的插件名是AchievementsX,那么将你的主类命名为AchievementsX,通过这种命名方式,你可以轻松地将你的插件集成到其他插件中。
英文:
instead of using Main.getPlugin(Main.class)
try using JavaPlugin.getPlugin(Main.class)
. Also, why do you create an Instance of your Main
class? You dont need singletons in Bukkit plugins (in fact it isnt a real singleton, because you cant set the access of your constructor to private). Also, try naming your Main class of a plugin as the name of your plugin, example: Your plugins name is AchievementsX, then name your main class AchievementsX, with this naming you can easily implement your plugin into other plugins.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论