What do I put for the plugin parameter?


#1

So I’m attempting to create a custom inventory by using Inventory.Builder. In order to create an inventory I tried to do Inventory inv = Inventory.builder().build(); but in the build method it requires an object parameter for the plugin. I used this before in my main class by just putting “this” in for that parameter but this is in a different class so I’m not really sure how to go about getting an instance of the main class. I tried making an instance of my main class (which is called KitPvP) by doing KitPvP instance; but it keeps returning null. I also tried just making the inventory as Inventory inv; but that didn’t work either. If anyone can fill me in that would be great.


#2

Hi,

you have two main choices. You can :

  • create a static instance of your Main class.
  • give a reference of your Main class to your Inventory class when you call-it.

To use the static instance method, you should add this to your Main class :

private static KitPvp instance;

public static KitPvp getInstance() {
    return instance;
}

and, don’t forget to add instance = this; when your plugin load.

Using the reference method is simple, simply passed this as a parameter when you call your Inventory class.