GadgetAPI 1.0

Create your own Gadgets!

  1. ctd
    GadgetAPI by ctd

    Introduction

    (this is not a plugin)
    This is a very simple and easy to use Gadget API. Included with the download is the FULL example of the following code I'm about to walk you through. On many big servers you'll see that they have some sort of "Gadget" menu, and this is my approach to its implementation. If you look at the source for the example, I've also included a basic creation of the menu. This however, does not have support for multiple pages, since it's not needed for example purposes. But feel free to add it in yourself if you're going to make a bunch of these. Keep in mind that there are several things that aren't handled by listeners, as again, it's not needed for example purposes. NOTE: This release is only the API. I included the example to get you started!

    Just a heads up: I went with a more instance based design rather than static.

    How to use:

    First create a new instance -

    Code (Text):
    GadgetAPI gadgetAPI = new GadgetAPI(<JavaPlugin>);
    You can store this however you'd like. I instantiated mine in my onEnable and stored it as a private field with a Getter method.

    Have a look at Gadget.java for reference -
    Code (Text):
    /**
    * This class represents a Gadget
    *
    * @author ctd
    * @version 1.0
    * 12 Dec, 2015
    */
    public abstract class Gadget {
     
        private final int COOL_DOWN_TIME;
        private String name;
        private ItemStack displayItem;
     
        /**
         * Gadget constructor
         *
         * @param name the name
         * @param COOL_DOWN_TIME the cool down time
         * @param displayItem the display item
         */
        public Gadget(String name, final int COOL_DOWN_TIME, ItemStack displayItem) {
            this.name = name;
            this.COOL_DOWN_TIME = COOL_DOWN_TIME;
            this.displayItem = displayItem.clone();
        }
     
        /**
         * Get the name of the Gadget
         *
         * @return the name
         */
        public String getName() {
            return name;
        }
     
        /**
         * Get the cool down of the Gadget
         *
         * @return the cool down
         */
        public int getCoolDownTime() {
            return COOL_DOWN_TIME;
        }
     
        /**
         * Get the display item of the Gadget
         *
         * @return the display item
         */
        public ItemStack getDisplayItem() {
            return displayItem;
        }
     
        /**
         * Apply the Gadget's use to the player
         *
         * @param player the Player that used the Gadget
         */
        public abstract void useGadget(Player player);
    }

    Now let's create a simple gadget that gives you speed -
    Code (Text):

    public class TheFlashGadget extends Gadget {

        private GadgetExampleMain plugin;

        public TheFlashGadget(GadgetExampleMain plugin) {
            super("The Flash", 60, ItemUtil.makeTheFlashGadgetItem());
         
            this.plugin = plugin;
        }

        @Override
        public void useGadget(Player player) {
            GadgetAPI gadgetAPI = plugin.getGadgetAPI();
         
            if (!gadgetAPI.hasCooldown(player)) {
                PotionEffect speed = new PotionEffect(PotionEffectType.SPEED, 15 * 20, 3);
                speed.apply(player);
                gadgetAPI.setCooldown(player, getCoolDownTime());
            } else {
                player.sendMessage(ChatUtil.colorize("&cYou must wait for your cooldown to complete!"));
            }
        }
    }
     


    Implementation:
    Have a look at the full example project source code for my menu implementation. Click here for just the example code.

    Installation:
    I'd recommend that you just take the two classes from GadgetAPI.jar and add them as a package to your project source. If not, you can simply add the Jar to your project's build path. However, by doing this, you'll need to either export with dependencies or shade the jar.

    Bugs and Suggestions:
    Feel free to leave suggestions or bug reports in the discussion section. You can also submit issues here.
    Skaiz likes this.

Recent Reviews

  1. Aditya
    Aditya
    5/5,
    Version: 1.0
    Good, I like this, simple but actually makes the world a lot easier and faster. Thanks for sharing this to public! <3
  2. Denver
    Denver
    5/5,
    Version: 1.0
    AMAZING! This plugin works flawlessly and does exactly what it is meant to do! Thanks for making this!
    1. ctd
      Author's Response
      This isn't a plugin. This is an API!