

別のクラスからコマンドを読み込ませたいのですが動きません  
Error Code:

[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]

Code [Main]:

[code]

    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]

Code [Command Class]:

[code]

    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;
    
        }
      }
    
[/code]


CC BY-SA 4.0
2019-07-26T07:16:44.770
56912
2020-06-20T17:02:50.280
29457
question
java
Minecraft Plugin


`setExecutor`の引数は@Nullable `CommandExecutor` executorとなってます。  
で、あれば

> `public class Grass_Command extends JavaPlugin`

の`extends JavaPlugin`はおかしいですね。

この程度の内容は公式の「Creating a Simple Command」にもかいてあるのでそちら確認して下さい。  
<https://www.spigotmc.org/wiki/create-a-simple-command/>

Javadocも確認を。  
<https://hub.spigotmc.org/javadocs/spigot/org/bukkit/command/PluginCommand.html#setExecutor-
org.bukkit.command.CommandExecutor->


CC BY-SA 4.0
2019-07-30T09:51:13.090
57034
2019-07-30T09:51:13.090
35308
56912
answer