How do you use multiple packages?

Discussion in 'Plugin Development' started by DefaultSyntax, Dec 18, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    DefaultSyntax

    Hi, I'm fairly new to Bukkit programming and I was wondering, how do I use multiple packages? As my plugins get more extensive, I'd like top get more organized in things. I already know how to create a package, but I don't understand is, where do I create it? Do I create it under my src, or under my main default package?
     
  2. Offline

    Skionz

    @DefaultSyntax This seems like more of an IDE question. When using eclipse you can create it anywhere. The path is determined by the actual name of the package.
     
  3. Offline

    Evaluations

    1. Right click on your main package.

    2. New -> Package

    3. Insert a name after the "." that was given after your main package.

    And yes, this is for Eclipse. Unsure about any other IDE.
     
  4. Offline

    Funergy

  5. Offline

    DefaultSyntax

    @Skionz @Evaluations Ok, so I did that. Then I created a class within a package that contains a command executor. How would I "exectute" that command in my main class?

    @Funergy How would I set it to a hierarchy exactly?
     
  6. Offline

    Skionz

    @DefaultSyntax
    JavaPlugin#getCommand(String)
    PluginCommand#setExecutor(CommandExecutor)
     
  7. Offline

    mythbusterma

    @DefaultSyntax

    The packages in Eclipse work just fine for me in default.

    Also, just instantiate the command executor, it's not difficult.
     
  8. Offline

    Funergy

    @DefaultSyntax in the
    Package Explorer / View Menu / Package Presentation... / Hierarchical

    The "View Menu" can be opened with Ctrl + F10, or the small arrow-down icon in the top-right corner of the Package Explorer.

    @mythbusterma Are you using the kepler version?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
    VG.Developments likes this.
  9. Offline

    Evaluations

    getCommand("mycommand").setExecutor(new ClassName());

    Insert your command in the plugin.yml as well.
     
  10. Offline

    mythbusterma

    @Funergy

    Doesn't matter, in one version they don't stack, and in the other way it does, it honestly does not make an difference whatsoever in the effectiveness of said packages.
     
  11. Offline

    Skionz

    Note that your command class must implement the CommandExecutor interface.
     
  12. Offline

    Funergy

    @mythbusterma Well it looks a bit weird if you show packages 'flat' hierarchical looks a better for me.
     
  13. Offline

    DefaultSyntax

    @mythbusterma@Evauluations@Funergy@Skionz

    So this is my code to execute the command

    Code:
    @Override
        public void onEnable() {
    
            //Command Executor
            getCommand("TestingThisPlugin").setExecutor(new Test());
        }
    An this is my code for the actual command, in another class under another package.
    Code:
    @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    
            if(cmd.getLabel().equalsIgnoreCase("TestingThisPlugin")){
    
                sender.sendMessage("This plugin is working fine!");
            }
    
            return false;
        }
    I also have the command in my plugin.yml. When I run this plugin on my server, it says that there's an error on the line that executes the command in my main class.
     
  14. Offline

    Evaluations

    Did you implement CommandExecutor in your command class?

    Also, did you import your command class?
     
  15. Offline

    DefaultSyntax

  16. Offline

    Evaluations

    What's the error?
     
  17. Offline

    DefaultSyntax

    @Evaluations The type of error is java.lang.NullPointerException
     
  18. Offline

    Evaluations

    Change your cmd getter to if (cmd.getName().equalsIgnoreCase("TestingThisPlugin"))

    If this doesn't fix it, post your whole main class.
     
  19. Offline

    DefaultSyntax

    @Evaluations It didn't work, so here's my entire main class.

    Code:
    package com.Girithium.GirithiumManager;
    
    import com.Girithium.GirithiumManager.Chat.Test;
    import org.bukkit.plugin.java.JavaPlugin;
    
    /**
    * Created by Girithium.
    */
    public class Core extends JavaPlugin {
    
    
        @Override
        public void onEnable() {
    
            //Command Executor
            getCommand("TestingThisPlugin").setExecutor(new Test());
        }
    
        @Override
        public void onDisable() {
    
    
        }
    }
     
  20. Offline

    Evaluations

    Remove the @Override (s) in both classes.
     
  21. Offline

    DefaultSyntax

  22. Offline

    mythbusterma

    @Evaluations

    Why the hell would that help at all? That's just making the code worse.


    @DefaultSyntax

    Sorry, he doesn't know what he's talking about. Post the entire class of the class that has the NullPointerException, and yes, capitalization is extremely important, otherwise your code is nearly unreadable.
     
  23. Offline

    Evaluations

    I guess
     
  24. Offline

    DefaultSyntax

    @mythbusterma My main class is the class that has the NullPointerException
     
  25. Offline

    mythbusterma

  26. Offline

    teej107

  27. Offline

    DefaultSyntax

    @mythbusterma

    Code:
    oading libraries, please wait...
    20:56:20 INFO]: Starting minecraft server version 1.7.10
    20:56:20 INFO]: Loading properties
    20:56:20 INFO]: Default game type: SURVIVAL
    20:56:20 INFO]: Generating keypair
    20:56:20 INFO]: Starting Minecraft server on *:25565
    20:56:20 INFO]: This server is running CraftBukkit version git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks (MC: 1.7.10) (Implementing API version 1.7.10-R0.1-SNAPSHOT)
    20:56:20 INFO]: [GirithiumManager] Loading GirithiumManager v1.0
    20:56:20 INFO]: Preparing level "world"
    20:56:21 INFO]: Preparing start region for level 0 (Seed: -4128062865688294663)
    20:56:21 WARN]: Could not get information about this CraftBukkit version; perhaps you are running a custom one?: IOException
    20:56:21 WARN]: Could not get latest artifact information: IOException
    20:56:22 INFO]: Preparing spawn area: 91%
    20:56:22 INFO]: Preparing start region for level 1 (Seed: -4128062865688294663)
    20:56:22 INFO]: Preparing start region for level 2 (Seed: -4128062865688294663)
    20:56:22 INFO]: [GirithiumManager] Enabling GirithiumManager v1.0
    20:56:22 ERROR]: Error occurred while enabling GirithiumManager v1.0 (Is it up to date?)
    ava.lang.NullPointerException
           at com.Girithium.GirithiumManager.Core.onEnable(Core.java:15) ~[?:?]
           at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
           at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:324) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
           at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
           at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugin(CraftServer.java:455) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
           at org.bukkit.craftbukkit.v1_7_R4.CraftServer.enablePlugins(CraftServer.java:389) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
           at net.minecraft.server.v1_7_R4.MinecraftServer.n(MinecraftServer.java:352) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
           at net.minecraft.server.v1_7_R4.MinecraftServer.g(MinecraftServer.java:326) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
           at net.minecraft.server.v1_7_R4.MinecraftServer.a(MinecraftServer.java:282) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
           at net.minecraft.server.v1_7_R4.DedicatedServer.init(DedicatedServer.java:189) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
           at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:436) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
           at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    20:56:22 INFO]: Server permissions file permissions.yml is empty, ignoring it
    20:56:23 INFO]: Done (2.069s)! For help, type "help" or "?"
    
     
  28. Offline

    mythbusterma

    @DefaultSyntax

    Something tells me it isn't line 15, as line 15 is a comment. Perhaps it is line 16? Which is getCommand(.... and it is quite possible that you never defined that command in your plugin.yml, meaning that that function would likely return null.
     
  29. Offline

    DefaultSyntax

    Code:
    name: GirithiumManager
    author: DefaultSyntax
    version: 1.0
    main: com.Girithium.GirithiumManager.Core
    commmands:
      TestingThisPlugin:
    This is my plugin.yml @mythbusterma
     
  30. Offline

    Webbeh

    There is no way the code you gave earlier is the "full" code. If you want to have decent bug tracking, you have to post the stack trace AND the source code in the exact same state it has been used when compiling the jar producing the error.
     
Thread Status:
Not open for further replies.

Share This Page