HomeJavaModsKeyCard API
KeyCard API
KeyCard
Purpose: KeyCard is a card scanning API. You create an unpaired keycard and an unpaired scanner, pair them, and then you can scan the keycard at that scanner and interact with it through other add-on plugins.

Requirements:

Add-Ons (If you want yours added, just let me know):

Items

Items are by default crafted using '/kc craft' to open the RecipesRedone crafting system.
Unpaired Key Card:
[​IMG]


Unpaired Scanner:
[​IMG]

User Tutorial
Step 1: Place down your scanner. Each add-on might utilize their own scanner so if you want an add-on's scanner, make sure you craft that instead of the default.
[​IMG]

Step 2: Holding your unpaired key card, right click the scanner to pair them.
[​IMG]

Step 3: You will now be left with an unnamed key card. Type '/kc name <name>' to name it. Note: The name is to be without spaces.
[​IMG]

Step 4: Now they are linked! Right click to scan and utilize the add-ons!

Duplication: To duplicate key cards for friends/players, hold the card to be duped in your hand and also have unpaired key cards in your inventory. /kc duplicate will use up an unpaired key card to form a copy of the card in your hand.

API Tutorial
If you want to make a plugin that uses this API, you must be sure to edit your plugin.yml before doing anything else. In your plugin.yml, make sure to add 'depend: [KeyCard]' and KeyCard.jar to your build path.
Creating a custom scanner : To create a custom scanner, first you must create the ItemStack that you want the scanner to be. As in the user tutorial shows a stone button, you can replace that with whatever you want.
Code (Text):
APIUtils.registerScannerItem(scannerItemStack);
//Registers an ItemStack as a pairable scanner
ScannerPairEvent : Just like you would listen for any other bukkit event, you can listen for this event. It is called when an unpaired key card and scanner from any plugin are paired. If using it you should check the scannerItemStack against your custom one before doing anything.
Code (Text):
  @EventHandler
  public void onScannerPair(ScannerPairEvent e)
  {
    if (e.getScannerItem().isSimilar(scannerItemStack))
    {
      //Do stuff such as save scanner location to a file
    }
  }
KeyCardScanEvent : Same as above but this event is fired when a player scans a paired key card and scanner. My recommendation is to save the scanner location during the ScannerPairEvent to a file and check if the location of the KeyCardScanEvent is the same to know if your custom scanner is being scanned.
Code (Text):
  @EventHandler
  public void onScan(KeyCardScanEvent e)
  {
  /*
   * What happens here is I am scanning a file of saved scanner locations to see if one of my custom scanners is being scanned. If it is, then I collect the information and do what I want with it.
   */
    List<String> locStrings = this.scannerFile.contains("data") ? this.scannerFile.getStringList("data") : new ArrayList();
    if (locStrings.contains(StringUtils.toLocString(e.getFrame().getLocation())))
    {
//StringUtils is a private library that I use
      Location loc = e.getFrame().getLocation()
      ItemFrame frame = e.getFrame();
      BlockFace face = frame.getAttachedFace();
      Block b = loc.add(face.getModX(), face.getModY(), face.getModZ()).getBlock();
      //This should be enough information to do whatever you need to do
    }
  }

Commands

Plugin details

Read from the plugin's own plugin.yml.

Quick facts

Install steps are the general flow for this file type — How to install Minecraft Java mods & modpacks walks through it step by step.

KeyCard API is a free Minecraft Java mod. Compatible with Minecraft 1.8, 1.9, 1.10, 1.11 and newer. Downloaded 5,214 times (via Spigot). Download it and open it directly in the game.

Explore more