I'm new to coding. Need some help.

Discussion in 'Programming' started by _Unbannable, Jun 30, 2015.

  1. I need some help with making a plugin. Currently I'm new to this and I'm currently learning. But I'm trying to make a Hub plugin for fun. But besides that I have a couple questions just about different things that people do when they make there own plugins.

    1. How does everyone setup there plugins? Like base code that they always put in all of there plugins. (Small, Medium & Large plugins.) (I've seen a couple of ways but I want to know what everyone uses and also know somewhat the best way. I know it could all be preference.)

    2. When you have multiple Java Classes and Packages how do you call them from the main class? I've seen a couple of ways but I want to know the best way. (Again I know it could be preference.)

    3. My last question is how does everyone setup menu's? I've seen a lot of people use IconMenu code and then they just make a class and call from the IconMenu. I've also seen people make their own Menu's like in Pogosticks videos and the BcBroz videos.
  2. Not everything is about your main class.
    The main class is what you use to start the most important things on plugin startup. The beauty of object-oriented programming is that your software turns into a sort of tree structure, in which class a calls class b, class b calls class c etc.

    The way I have it set up is:
    Main class:
    - register commands
    - register events
    - open and close MySQL connection.

    From there, I have several classes handling events and commands. These commands then use different utility classes as I like to call them. For instance my Playerdata class, which contains HashMaps and loads of methods to execute SQL queries.
    Another class is my Colour.java - since chat colours will be brutally important on my future server, I figured it warranted a dedicated class.

    Do note, however, that my way of organising code is not the best way to program in an object-oriented style. I am still relatively new to OOP and do prefer procedural code.
  3. As you just said with registering your commands and events. How do you go about doing that? I've seen many ways some that are long and some that are very short.
  4. I wouldn't learn how to code in Java from making plugins. That is just me.
    1. I always have the commands registered, and the other basic stuff. I almost never make a MySQL connection in my main class though.
    Code (Text):
    if(cmd.getName().equalsIgnoreCase("command") && sender instance of Player)
    That is how I register my commands, and check if it is a player.

    2. How to call a class:
    Code (Text):
    Class classObj = new Class();
    With a package is is pretty much the same thing. Just import the package.

    3. Honestly, for you it would be easiest to use IconMenu instead of writing a whole new script for using the Inventory as a interface.
  5. Assume you have a /bc command in BroadcastCommand.java.
    This is the easiest of the ways to register a command.

    Code (Java):

    package foo.bar.baz;
    import everything.in.the.solar.system.*;

    public class YourMainClass extends JavaPlugin implements CommandExecutor
        public void onEnable()
            getCommand("bc").setExecutor(new BroadcastCommand());