我的Bukkit插件无效!
服务器输出:
> [17:49:00] [Server thread/INFO]: [ChatManager1] Enabling ChatManager1 v0.1
> [17:49:00] [Server thread/ERROR]: Error occurred while enabling ChatManager1 v0.1 (Is it up to date?)
> java.lang.IllegalArgumentException: Plugin already initialized!
> at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:98)
> ~[src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
> at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
> at me.whispereq.colorCodes.Main.<init>(Main.java:9) ~[?:?]
> at me.whispereq.colorCodes.Main.onEnable(Main.java:12) ~[?:?]
> at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316)
> ~[src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
> at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:324)
> [src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
> at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404)
> [src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
> at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugin(CraftServer.java:455)
> [src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
> at org.bukkit.craftbukkit.v1_7_R4.CraftServer.enablePlugins(CraftServer.java:389)
> [src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
> at net.minecraft.server.v1_7_R4.MinecraftServer.n(MinecraftServer.java:352)
> [src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
> at net.minecraft.server.v1_7_R4.MinecraftServer.g(MinecraftServer.java:326)
> [src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
> at net.minecraft.server.v1_7_R4.MinecraftServer.a(MinecraftServer.java:282)
> [src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
> at net.minecraft.server.v1_7_R4.DedicatedServer.init(DedicatedServer.java:189)
> [src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
> at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:436)
> [src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
> at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628)
> [src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
> Caused by: java.lang.IllegalStateException: Initial initialization
> at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:101)
> ~[src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
> at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
> at me.whispereq.colorCodes.Main.<init>(Main.java:9) ~[?:?]
> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_131]
> at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_131]
> at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
> Source) ~[?:1.8.0_131]
> at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_131]
> at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_131]
> at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:52)
> ~[src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
> at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:127)
> ~[src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
> at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:328)
> ~[src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
> at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251)
> ~[src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
> at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugins(CraftServer.java:364)
> ~[src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
> at org.bukkit.craftbukkit.v1_7_R4.CraftServer.<init>(CraftServer.java:326)
> ~[src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
> at net.minecraft.server.v1_7_R4.PlayerList.<init>(PlayerList.java:68)
> ~[src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
> at net.minecraft.server.v1_7_R4.DedicatedPlayerList.<init>(SourceFile:14)
> ~[src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
> at net.minecraft.server.v1_7_R4.DedicatedServer.init(DedicatedServer.java:133)
> ~[src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
> ... 2 more
> [17:49:00
我有2个类,第一个是Main,第二个是Config 这是Main类的代码:
package me.whispereq.colorCodes;
import org.bukkit.command.CommandExecutor;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin implements CommandExecutor{
public static Main instance;
public static void s(String mg){
System.out.println(mg);
}
public void onEnable(){
instance = this;
s("=======================================");
s(" CHAT MANAGER MAIN");
s("Loading Plugin chat manager by the whispereq");
s("=======================================");
getCommand("helpchat").setExecutor(new Config());
saveDefaultConfig();
}
public static Main getInst(){
return instance;
}
}
Config类中的代码:
package me.whispereq.colorCodes;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.event.player.AsyncPlayerChatEvent;
public class Config implements CommandExecutor {
public boolean onCommand(CommandSender s, Command cmd, String label, String[] args) {
if ((cmd.getName().equalsIgnoreCase("helpchat")) && (args.length == 0)){
s.sendMessage("§6-----------------------------");
s.sendMessage("§cCommands:");
s.sendMessage(" §7/help");
s.sendMessage("§cFunctions");
s.sendMessage(" §7Swear words replacement, blankfields");
s.sendMessage(" §7Color codes, swear repl character,");
s.sendMessage(" §cPlugin Includes COnfig File!");
s.sendMessage("§6-----------------------------");
}
else if (args.length > 0){
s.sendMessage("§4/help");
}
return false;
}
public static void onChat(AsyncPlayerChatEvent e){
List<?> swear = Main.getInst().getConfig().getList("swearwords");
String replacement = Main.getInst().getConfig().getString("sword-char");
String warn = Main.getInst().getConfig().getString("sword-msg");
List<?> blanks = Main.getInst().getConfig().getList("blankfields");
String bfmsg = Main.getInst().getConfig().getString("use-msg");
List<?> colors = Main.getInst().getConfig().getList("colorcodes");
String cuse = Main.getInst().getConfig().getString("coloruse");
if (e.getMessage().contains((CharSequence) swear)){
e.getMessage().replace((CharSequence) swear, replacement);
e.getPlayer().sendMessage(warn + Bukkit.getServerName());
}
else if (e.getMessage().contains((CharSequence) blanks)){
e.getMessage().replace((CharSequence) blanks, "");
e.getPlayer().sendMessage(bfmsg);
}
else if (e.getMessage().contains((CharSequence) colors)){
e.getMessage().replace((CharSequence) colors, "§");
e.getPlayer().sendMessage(cuse);
}
}
}
Config.yml文件:
###########################
# Color Codes List #
###########################
# Character, word #
colorcodes:
- '&'
coloruse: §6You have used§4§l ColorCodes§6.
###########################
# BLANK FIELDS #
###########################
# Character, word #
blankfields:
- '<BlankField>'
use-msg: §6You have used an §c§lBlank Field§6 in yours Sentence.
###########################
# SWEARING #
###########################
# String, word, character, sentence, integer #
swearwords:
- '...'
sword-char: xxxx
#WARN! after message will be inerted server Name from #
# server.properties file! #
sword-msg: §c§lHey!§7 Please dont Spam on
#----------------------------------------#
# BLankfields are replaced on the chat when
# message sent by an blank String ''
#----------------------------------------#
# Color codes are the replacements of
# Characters '§' in minecraft chat
# Color codes makes possible to write
# messages in multiple Colors!
#-----------------------------------------#
# Maybe you dont like, that a player swears
# on yours serwer, and beacuse of it
# there was added this category.
#--- ADDING AN SWEAR WORD ---#
# To add an swear word make 1 TAB in a new
# line write '-' char make space after it
# write 2 aposthrops ' and between
# it write new swear word.
# it should look like this:
#
#swearwords:
# - 'my swear word'
#
#-----------------------------------------#
# swear word repalcement: char, word,
# sentence, or other things, with it will
# be replaced the serar word.
# INFO: you can make a swear word an
# BLANK FIELD.
#-----------------------------------------#
那就是Plugin.yml文件:
name: ChatManager1
version: 0.1
main: me.whispereq.colorCodes.Main
description: Chat Management with Config
author: whispereq
commands:
help:
description: Plugin informations
请帮助我,这是一个大项目,我不知道它为什么不起作用。谢谢大家! 〜whispereq
NEW: 我删除了所有其他插件,我成了这个代码/服务器日志:
[18:28:43] [Server thread/INFO]: [ChatManager1] Enabling ChatManager1 v0.1
[18:28:43] [Server thread/INFO]: =======================================
[18:28:43] [Server thread/INFO]: CHAT MANAGER MAIN
[18:28:43] [Server thread/INFO]: Loading Plugin chat manager by the whispereq
[18:28:43] [Server thread/INFO]: =======================================
[18:28:43] [Server thread/ERROR]: Error occurred while enabling ChatManager1 v0.1 (Is it up to date?)
java.lang.NullPointerException
at me.whispereq.colorCodes.Main.onEnable(Main.java:15) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316) ~[src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:324) [src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404) [src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugin(CraftServer.java:455) [src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
at org.bukkit.craftbukkit.v1_7_R4.CraftServer.enablePlugins(CraftServer.java:389) [src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
at net.minecraft.server.v1_7_R4.MinecraftServer.n(MinecraftServer.java:352) [src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
at net.minecraft.server.v1_7_R4.MinecraftServer.g(MinecraftServer.java:326) [src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
at net.minecraft.server.v1_7_R4.MinecraftServer.a(MinecraftServer.java:282) [src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
at net.minecraft.server.v1_7_R4.DedicatedServer.init(DedicatedServer.java:189) [src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:436) [src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [src.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
[18:28:43] [Server thread/INFO]: Server
答案 0 :(得分:3)
第一个错误表明,有两个或更多插件与主类具有相同的路径(相同的包+相同的类名) - Bukkit需要那些主类路径是唯一的。
第二个错误 - 该命令未添加到plugin.yml文件中,因此getCommand()方法抛出了NullPointerException。
答案 1 :(得分:0)
第一个错误通常表示有多个具有相同名称的插件。
第二个错误指向Main.class
中的第15行。 NullPointerException
表示您使用的某个对象是null
。
确保检查了所引用的每个对象,并确保它们不为空。