Creating Different Classes

Discussion in 'Programming' started by bmac20, May 19, 2016.

  1. Hello. I am pretty new to Java, and I was wondering how to have multiple classes in one plugin. So if I wanted a plugin where it had /spawn and /msg for example, how would I have these in different classes, but all work into one plugin?
  2. All command classes need to implement CommandExecutor, which, in simple terms, allows you to use the infamous onCommand method. Separating into other classes is really just making a new class with your IDE, implementing CommandExecutor, then adding your logic into the onCommand method. You can then register the commands in your main class by adding something like this to your onEnable method:
    Code (Text):
    getCommand("foobar").setExecutor(new FooBar());
    • Useful Useful x 1
  3. I would not advise having a class for every command, unless you need it for organizational purposes in a huge plugin (it gets extremely messy).

    Try not to over-use OOP features just because they exist, you really do not need a class for every 15 lines of code.