AnimatedInventoryAPI

Sep 8, 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.14
    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".
        }
    }
    Code Explanation:
    @EventHandler - Tells our plugin to listen to the event we are about to declare below.

    public void onJoin(PlayerJoinEvent e) - This is us saying that we want to do what's below on PlayerJoinEvent, AKA, when the player joins the server.

    if(aiLoaded) - This tells the plugin, only do what's below if AnimatedInventory is loaded. You can get this to work by doing the code put above where we specify the boolean in the onEnable(). While optional, it's a nice thing to have to prevent any errors on every single join if the plugin is ever not found.

    Player player = e.getPlayer(); - This just helps us not have to type e.getPlayer() everytime we want the player from the event. Also is a bit more efficient.

    AnimatedInventoryAPI.doClear(player, false) - Similar to AnimatedInventoryAPI.doClear(player, false), this false/true statement is if AnimatedInventory should do all the checks to see if the player can actually clear their inventory. Since this is on join, there are no checks really to do, so to save time we set it to false. If you are hooking this to something else, you should set this to true.

    Events
    AnimatedInventory also has 3 events you can listen to. I'm going to assume you understand how events typically work. If you don't understand, I layed the basics out above for you. (Just replace PlayerJoinEvent with these events)
    • PlayerClearEvent - Fires when a player has passed all checks and is about to get their inventory cleared. This event can be cancelled and supports getting the player who is about to be clearing.
    • PlayerFortuneEvent- Fires when a players fortune is about to begin. This event can also be cancelled and supports getting the player who requested the fortune.
    • PlayerFortuneEndEvent- Fires after the result of the fortune has been determined. This is about 60 or so ticks until the end of the animation. This event can not be cancelled, and supports getting the player who got the fortune, and their result. You can get the result with e.isYes() or e.isNo() booleans.
    [​IMG]

    Need Help? Having Trouble?

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

    [​IMG]


    Click to view our GitHub
  • Loading...
  • Loading...