Minecraft Plugin
別のクラスからコマンドを読み込ませたいのですが動きません
Error Code:
[16:10:46 INFO]: [test_plugin] Enabling test_plugin v0.0.1
[16:10:46 ERROR]: Error occurred while enabling test_plugin v0.0.1 (Is it up to date?)
java.lang.IllegalArgumentException: Plugin already initialized!
at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:183) ~[spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:60) ~[spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
at grass.command.Grass_Command.<init>(Grass_Command.java:13) ~[?:?]
at grass.plugin.Grass.onEnable(Grass.java:16) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:403) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:381) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:330) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
at net.minecraft.server.v1_12_R1.MinecraftServer.t(MinecraftServer.java:422) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
at net.minecraft.server.v1_12_R1.MinecraftServer.l(MinecraftServer.java:383) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
at net.minecraft.server.v1_12_R1.MinecraftServer.a(MinecraftServer.java:338) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:272) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:545) [spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_191]
Caused by: java.lang.IllegalStateException: Initial initialization
at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:186) ~[spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:60) ~[spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
at grass.plugin.Grass.<init>(Grass.java:12) ~[?:?]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_191]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_191]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_191]
at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_191]
at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_191]
at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:90) ~[spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) ~[spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:327) ~[spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:248) ~[spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
at org.bukkit.craftbukkit.v1_12_R1.CraftServer.loadPlugins(CraftServer.java:305) ~[spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:205) ~[spigot-1.12.2.jar:git-Spigot-79a30d7-acbc348]
... 2 more
Code [Main]:
package grass.plugin;
import java.util.Collection;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import grass.command.Grass_Command;
public class Grass extends JavaPlugin {
@Override
public void onEnable() {
Grass_Command commands = new Grass_Command(this);
getCommand("save").setExecutor(commands);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (command.getName().equalsIgnoreCase("kickall")) {
Collection<? extends Player> players = getServer().getOnlinePlayers();
for(Player player:players){
player.kickPlayer("Kicked");
}
}
return true;
}
@Override
public void onDisable() {
System.out.println("プラグインが無効になりました");
}
}
Code [Command Class]:
package grass.command;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import grass.plugin.Grass;
public class Grass_Command extends JavaPlugin {
public Grass_Command(Grass grass) {
// TODO 自動生成されたコンストラクター・スタブ
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("save")) {
sender.sendMessage("セーブしています...");
for(World worlds: Bukkit.getWorlds()) {
worlds.save();
}
}
return false;
}
}