AnimatedInventoryAPI

Feb 20, 2019
AnimatedInventoryAPI
  • [​IMG]
    Welcome!
    The AnimatedInventory API was created with the developer in mind.
    We wanted to make it as easy as possible for you to add your own touch and
    integrations with AnimatedInventory.


    Adding a Soft Dependency
    First, let's make sure that AnimatedInventory is included as a soft-dependency in your plugin.yml so that way AnimatedInventory is started before your plugin.
    Code (Text):
    name: MyTestPlugin

    version: 0.1
    main: com.zach_attack.my_plugin.Main
    softdepend: [AnimatedInventory]
    api-version: 1.13
    As you can see, we added softdepend: AnimatedInventory
    to our plugin.yml. Do note that the other variables can be changed to your liking :)

    Adding an onEnable() check
    Second, let's make sure that AnimatedInventory is available to use on this server. To do so, we will be using a boolean that we can just check if it's true before using anything.
    Code (Java):
    public class Main extends JavaPlugin implements Listener {

        boolean aiLoaded;
       
        public void onEnable() {
            if (getServer().getPluginManager().isPluginEnabled("AnimatedInventory") &&
             (getServer().getPluginManager().getPlugin("AnimatedInventory") != null))  {
                aiLoaded = true;
            } else {
                aiLoaded = false;
            }
        }
    }

    Code Explanation:
    boolean aiLoaded; - This is just a variable that is either true or false. Right now it has no setting until the onEnable() sets it to true or false.

    if (getServer().getPluginManager().isPluginEnabled("AnimatedInventory") &&
    (getServer().getPluginManager().getPlugin("AnimatedInventory")
    != null))
    - This line checks to see if AnimatedInventory is not only enabled, but also not returning null. (Basically ensuring we can use the API without any problems)

    aiLoaded = true; - This sets that boolean we told you about earlier to true. Now we can do if(aiLoaded) { } to run things only if AnimatedInventory is available.

    Adding Functionality
    Now onto the good stuff. For the sake of simplicity, we are going to check if AnimatedInventory is available using our boolean, and if(aiLoaded) is true, we will do a fortune when the player joins.

    Now, after our onEnable(), we are going to check for PlayerJoinEvent and run a fortune​
    Code (Java):

        @EventHandler
        public void onJoin(PlayerJoinEvent e)
        {
            Player player = e.getPlayer();
           
            if(aiLoaded) {  // Checks that boolean from our onEnable if AnimatedInventory is ready to use.
            AnimatedInventoryAPI.doFortune(player, false);  // Runs a fortune.
            }
                // The "false" here is a boolean if we should do checks such as if the player
                // has an active cooldown with AnimatedInventory and if they already are having a fortune etc.
                // Since this is when they join, there really isn't anything to check. So we set it to "false".
        }
    }


    [​IMG]

    Need Help? Having Trouble?

    If you're having issues using our API, please join our support discord below!

    [​IMG]
  • Loading...
  • Loading...