最近我启动了一个 Bukkit 插件,但由于使用两个类(main 和 CommandExecutor)而遇到了麻烦。我已经尝试了所有方法,但是当我加载插件时,它会抛出一个错误,该错误位于帖子末尾。
主要(称为 ekits.java):
package me.mucapapipa.ekits;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class ekits extends JavaPlugin implements Listener {
@Override
public void onEnable() {
System.out.println("Main plugin enabled");
getCommand("pvp").setExecutor(new NormalPlayer(this));
getServer().getPluginManager().registerEvents(this, this);
}
@Override
public void onDisable() {
System.out.println("Main plugin disabled");
}
}
CommandExecutor(称为NormalPlayer):
package me.mucapapipa.ekits;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
public class NormalPlayer extends JavaPlugin implements CommandExecutor {
@SuppressWarnings("unused")
private ekits core;
public NormalPlayer(ekits core) {
this.core = core;
}
private String kit;
public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;
if (cmd.getName().equalsIgnoreCase("pvp")) {
kit = "PvP";
player.getInventory().clear();
player.getInventory().addItem(new ItemStack(Material.DIAMOND_SWORD));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
/* We then set the armor */
player.getInventory().setBoots(new ItemStack(Material.IRON_BOOTS));
player.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
player.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
player.getInventory().setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
player.sendMessage(ChatColor.GRAY + "~ " + ChatColor.AQUA + "Kit: " + kit);
}
else {
sender.sendMessage("The console should not play. It would be so OP.");
}
}
return true; }
}
插件.yml:
name: EKits
author: Mucapapipa
main: me.mucapapipa.ekits.ekits
version: 1.0
description: The server's main plugin.
commands:
pvp:
usage: /<command>
aliases: [kitpvp]
description: Uses the kit PvP.
错误:
[19:19:01 ERROR]:启用 EKits v1.0 时发生错误(它是最新的吗?) java.lang.IllegalArgumentException:插件已初始化! 在 org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:98) ~[craftbukkit.jar:git-Bukkit-7019900] 在 org.bukkit.plugin.java.JavaPlugin.(JavaPlugin.java:66) ~[craftbukkit.jar:git-Bukkit-7019900] 在 me.mucapapipa.ekits.NormalPlayer.(NormalPlayer.java:16) ~[?:?] 在 me.mucapapipa.ekits.ekits.onEnable(ekits.java:16) ~[?:?] 在 org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[craftbukkit.jar:git-Bukkit-7019900] 在 org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:327) [craftbukkit.jar:git-Bukkit-7019900] 在 org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404) [craftbukkit.jar:git-Bukkit-7019900] 在 org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin(CraftServer.java:341) [craftbukkit.jar:git-Bukkit-7019900] 在 org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlugins(CraftServer.java:313) [craftbukkit.jar:git-Bukkit-7019900] 在 net.minecraft.server.v1_8_R1.MinecraftServer.q(MinecraftServer.java:394) [craftbukkit.jar:git-Bukkit-7019900] 在 net.minecraft.server.v1_8_R1.MinecraftServer.k(MinecraftServer.java:362) [craftbukkit.jar:git-Bukkit-7019900] 在 net.minecraft.server.v1_8_R1.MinecraftServer.a(MinecraftServer.java:317) [craftbukkit.jar:git-Bukkit-7019900] 在net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.java:190) [craftbukkit.jar:git-Bukkit-7019900] 在 net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:484) [craftbukkit.jar:git-Bukkit-7019900] 在java.lang.Thread.run(来源未知)[?:1.8.0_101] 引起原因:java.lang.IllegalStateException:初始初始化 在 org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:101) ~[craftbukkit.jar:git-Bukkit-7019900] 在 org.bukkit.plugin.java.JavaPlugin.(JavaPlugin.java:66) ~[craftbukkit.jar:git-Bukkit-7019900] 在 me.mucapapipa.ekits.ekits.(ekits.java:10) ~[?:?] 在 sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法) ~[?:1.8.0_101] 在 sun.reflect.NativeConstructorAccessorImpl.newInstance(来源未知)~[?:1.8.0_101] 在 sun.reflect.DelegatingConstructorAccessorImpl.newInstance(来源未知)~[?:1.8.0_101] 在 java.lang.reflect.Constructor.newInstance(来源未知)~[?:1.8.0_101] 在 java.lang.Class.newInstance(来源未知)~[?:1.8.0_101] 在 org.bukkit.plugin.java.PluginClassLoader.(PluginClassLoader.java:52) ~[craftbukkit.jar:git-Bukkit-7019900] 在 org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) ~[craftbukkit.jar:git-Bukkit-7019900] 在 org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:328) ~[craftbukkit.jar:git-Bukkit-7019900] 在 org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) ~[craftbukkit.jar:git-Bukkit-7019900] 在 org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugins(CraftServer.java:288) ~[craftbukkit.jar:git-Bukkit-7019900] 在 org.bukkit.craftbukkit.v1_8_R1.CraftServer.(CraftServer.java:250) ~[craftbukkit.jar:git-Bukkit-7019900] 在 net.minecraft.server.v1_8_R1.PlayerList.(PlayerList.java:69) ~[craftbukkit.jar:git-Bukkit-7019900] 在 net.minecraft.server.v1_8_R1.DedicatedPlayerList.(SourceFile:14) ~[craftbukkit.jar:git-Bukkit-7019900] 在 net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.java:133) ~[craftbukkit.jar:git-Bukkit-7019900] ...还有2个
public class NormalPlayer extends JavaPlugin implements CommandExecutor
为什么你的命令执行器要扩展主插件类?这就是导致双重初始化的原因,删除该超类可能会修复代码。