MucaP MucaP - 24 days ago 4
Java Question

Using multiple classes for commands in Bukkit?

recently I started a Bukkit plugin and I'm in trouble for using two classes (main and CommandExecutor). I've tried everything, but when I load my plugin, it throwns an error wich is at the end of the post.

Main (called 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 (called 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; }
}


plugin.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.


Error:


[19:19:01 ERROR]: Error occurred while enabling EKits v1.0 (Is it up to date?)
java.lang.IllegalArgumentException: Plugin already initialized!
at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:98) ~[craftbukkit.jar:git-Bukkit-7019900]
at org.bukkit.plugin.java.JavaPlugin.(JavaPlugin.java:66) ~[craftbukkit.jar:git-Bukkit-7019900]
at me.mucapapipa.ekits.NormalPlayer.(NormalPlayer.java:16) ~[?:?]
at me.mucapapipa.ekits.ekits.onEnable(ekits.java:16) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[craftbukkit.jar:git-Bukkit-7019900]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:327) [craftbukkit.jar:git-Bukkit-7019900]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404) [craftbukkit.jar:git-Bukkit-7019900]
at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin(CraftServer.java:341) [craftbukkit.jar:git-Bukkit-7019900]
at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlugins(CraftServer.java:313) [craftbukkit.jar:git-Bukkit-7019900]
at net.minecraft.server.v1_8_R1.MinecraftServer.q(MinecraftServer.java:394) [craftbukkit.jar:git-Bukkit-7019900]
at net.minecraft.server.v1_8_R1.MinecraftServer.k(MinecraftServer.java:362) [craftbukkit.jar:git-Bukkit-7019900]
at net.minecraft.server.v1_8_R1.MinecraftServer.a(MinecraftServer.java:317) [craftbukkit.jar:git-Bukkit-7019900]
at net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.java:190) [craftbukkit.jar:git-Bukkit-7019900]
at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:484) [craftbukkit.jar:git-Bukkit-7019900]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_101]
Caused by: java.lang.IllegalStateException: Initial initialization
at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:101) ~[craftbukkit.jar:git-Bukkit-7019900]
at org.bukkit.plugin.java.JavaPlugin.(JavaPlugin.java:66) ~[craftbukkit.jar:git-Bukkit-7019900]
at me.mucapapipa.ekits.ekits.(ekits.java:10) ~[?:?]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_101]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_101]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_101]
at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_101]
at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_101]
at org.bukkit.plugin.java.PluginClassLoader.(PluginClassLoader.java:52) ~[craftbukkit.jar:git-Bukkit-7019900]
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) ~[craftbukkit.jar:git-Bukkit-7019900]
at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:328) ~[craftbukkit.jar:git-Bukkit-7019900]
at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) ~[craftbukkit.jar:git-Bukkit-7019900]
at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugins(CraftServer.java:288) ~[craftbukkit.jar:git-Bukkit-7019900]
at org.bukkit.craftbukkit.v1_8_R1.CraftServer.(CraftServer.java:250) ~[craftbukkit.jar:git-Bukkit-7019900]
at net.minecraft.server.v1_8_R1.PlayerList.(PlayerList.java:69) ~[craftbukkit.jar:git-Bukkit-7019900]
at net.minecraft.server.v1_8_R1.DedicatedPlayerList.(SourceFile:14) ~[craftbukkit.jar:git-Bukkit-7019900]
at net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.java:133) ~[craftbukkit.jar:git-Bukkit-7019900]
... 2 more

Answer

public class NormalPlayer extends JavaPlugin implements CommandExecutor

Why does your command executor extend the main plugin class? That is what causes the double-init and removing that superclass will probably fix the code.