Some of my commands arent working for my Core plugin

Discussion in 'Plugin Development' started by GodzillaFlame42, Jul 15, 2016.

Thread Status:
Not open for further replies.
  1. So for some reason one of the only some of the commands work in my core plugin.

    Here is my Core
    Code:
    package me.godzilla.Main;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Core extends JavaPlugin {
        public void onEnable() {
            Bukkit.getConsoleSender().sendMessage(ChatColor.GRAY + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
            Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "            Enabling Core...");
            Bukkit.getConsoleSender().sendMessage(ChatColor.GRAY + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
          
            new Plugin(this);
          
            getCommand("Sethome").setExecutor(new Home.Sethome());
            getCommand("Delhome").setExecutor(new Home.Delhome());
            getCommand("Home").setExecutor(new Home.Home());
          
            getCommand("Clear").setExecutor(new Inventory.Clear());
            getCommand("CI").setExecutor(new Inventory.Clear());
            getCommand("ClearInventory").setExecutor(new Inventory.Clear());
            getCommand("Give").setExecutor(new Inventory.Give());
          
            getCommand("Setspawn").setExecutor(new Spawn.Setspawn());
            getCommand("Spawn").setExecutor(new Spawn.Spawn());
          
            getCommand("Heal").setExecutor(new Health.Heal());
            getCommand("Feed").setExecutor(new Health.Feed());
            getCommand("Suicide").setExecutor(new Health.Suicide());
          
            getCommand("Cc").setExecutor(new Chat.Clearchat());
            getCommand("Msg").setExecutor(new Chat.Message());
            getCommand("Announce").setExecutor(new Chat.Announce());
            getCommand("Broadcast").setExecutor(new Chat.Announce());
          
            getCommand("Gm").setExecutor(new Player.GameMode());
            getCommand("Gms").setExecutor(new Player.GameModeS());
          
            saveConfig();
          
            Bukkit.getConsoleSender().sendMessage(ChatColor.GRAY + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
            Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "             Core Enabled!");
            Bukkit.getConsoleSender().sendMessage(ChatColor.GRAY + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
          
          
        }
    
    }
    Here is my console error

    [12:41:02 ERROR]: Error occurred while enabling Core v1.0 (Is it up to date?)
    java.lang.NullPointerException
    at me.godzilla.Main.Core.onEnable(Core.java:22) ~[?:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.reload(CraftServer.java:741) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.Bukkit.reload(Bukkit.java:535) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1162) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:997) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_73]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_73]
    at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_73]

    Here is my plugin.yml
     
  2. Offline

    thapengwin

    You should make the entire class the commandexecutor, and only then, in the onCommand, check what command it was and deal with it accordingly.
     
  3. When i change it to commandexecutor it makes an error on getCommand. Is there any other way to do the getCommand if i change it to commandexector?
     
  4. Offline

    thapengwin

    Try splitting different commands to different classes, that's the method that I use for all of my plugins.
     
  5. I have every command in a different class
     
  6. Offline

    thapengwin

    From what you posted, you have every command in different functions, not classes.
     
  7. ok so what do i need to do to make these work?
     
  8. Offline

    thapengwin

    Just make a CommandExecutor class for every command you have.
     
  9. All of them are command executor and some of them are still not working. @thapengwin
     
  10. Offline

    thapengwin

    Can you show me your core class and the command classes please?
     
  11. What do you mean in the command classes? I really dont want to show them all cause people might come along and copy and paste them but change up the messages and stuff. Also the core is in the original post.
     
  12. No one is here to steal your code. We're here to help you. To add on to this, your idea has probably been done before.

    As for your actual problem, it's probably the mismatch of capitilizations in the plugin.yml and main class. I recommend changing it all to lower case.
     
  13. Offline

    thapengwin

    Then I can't tell if you're doing it correctly, and thus help you either. Besides, if you make your content open source, you can more easily prove that you're the owner of the code.
    Anyways, you can check out my plugin Credits for an example of how you should do this. All you need are the command classes and the main class.
     
  14. Offline

    ArsenArsen

    You look up their aliases or wrong cased names. You need to look up their full and exact (case sensitive!) name!

    Please just read the docs and the errors you have. Its an obvious mistake.
     
  15. Offline

    thapengwin

    Actually, I just noticed that he added the aliases along with the default commands... I am so unobservant.
    But then again, he bound commands to functions at the start.
     
  16. @GodzillaFlame42 Trust me if you need to post here people won't want to steal your code. We can't help without code, and most of us here can code this stuff already, it's not exactly hard to do we would not need to steal code.
     
  17. @GodzillaFlame42 No go into the Inventory class let's say and see how you are getting them commands because it seems you are doing some static abuse. Also please follow naming conventions in class names, variables and packages. Your package should be me.<username>.<project>

    Copy and paste the code from the Inventory class into the [code=java][/code] tags
     
  18. Offline

    DarkenCake

    No matter
    Also that is because you need to create timer for 1 tick before getting ConsoleSender by Bukkit.getScheulder()
    Edit: double post, forgot sorry.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 16, 2016
  19. Offline

    thapengwin

    It does matter, because if another programmer that does not know of package naming convention decides to use the exact same package and class names, the world explodes.
    ...the world won't actually explode, but there will be a lot of incompatibilities and if any other developer might want to use a function from both of the plugins, there will be issues.
     
  20. @thapengwin No he was saying that the guy should be doing this. He posted a picture of file structure and I believe meant it as "No matter the issue, " the quote about package for format
     
  21. Offline

    thapengwin

    That's still an issue nonetheless, and a noticed issue should always be a fixed issue!
     
  22. @thapengwin I know? Hence why I said it in my post and why he quoted me also saying it.
     
  23. Offline

    DarkenCake

    @GodzillaFlame42
    Code:
    public void onEnable() {
            Bukkit.getConsoleSender().sendMessage(ChatColor.GRAY + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
            Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "            Enabling Core...");
            Bukkit.getConsoleSender().sendMessage(ChatColor.GRAY + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
         
    Why you getting console sender and send message for players when server is not started up? Also, that returns null pointer because sender can not be null, so you need to create a timer for 1 tick before getting console sender!
    Also if its command error, you need to show us one of your classes because we cant do anything without code!
     
  24. This is not true. The Bukkit.getConsoleSender() returns the CommandSender for the console, which can be sent messages to just fine. Although what you are really supposed to do is use this.getLogger(). And to add on to that, those lines are completely unnecessary and creates console spam since bukkit already logs your plugins for you.
     
  25. There's too much to complain about in your classes so I'll just point out what's throwing your error. In your main class, line 22 is trying to get the command "Give" and set the executor as your command that you have. Problem is, is that you don't even define the command "Give" in your plugin.yml
    Please check the log before coming to the forums to ask us what's wrong, it could save you and the rest of us some typing. ;)
     
Thread Status:
Not open for further replies.

Share This Page