Skip to content
This repository was archived by the owner on Mar 12, 2024. It is now read-only.

Getting Started

Chaffic edited this page May 1, 2021 · 1 revision

Making a custom Item

Connecting your plugin to CAPI

  1. Setup CAPI project with maven or gradle
  2. Add an auto-download
public class Main extends JavaPlugin {
    private final String CrucialAPIVersion = "1.2";

    @Override
    public void onLoad(){
        if(getServer().getPluginManager().getPlugin("CrucialAPI") == null){
            try {
                URL website = new URL("https://github.com/Chafficui/CrucialAPI/releases/download/v" + CrucialAPIVersion + "/CrucialAPI-v" + CrucialAPIVersion + ".jar");
                ReadableByteChannel rbc = Channels.newChannel(website.openStream());
                FileOutputStream fos = new FileOutputStream("plugins/CrucialAPI.jar");
                fos.getChannel().transferFrom(rbc, 0L, Long.MAX_VALUE);
                Bukkit.getPluginManager().loadPlugin(new File("plugins/CrucialAPI.jar"));
            } catch (IOException | InvalidDescriptionException | org.bukkit.plugin.InvalidPluginException e) {
                e.printStackTrace();
                Bukkit.getPluginManager().disablePlugin(this);
            }
        }
    }
}
  1. Add an auto-updater
public class Main extends JavaPlugin {
    private final String CrucialAPIVersion = "1.2";

    /** Auto-update CrucialAPI */
    @Override
    public void onEnable(){
        if(Server.checkVersion(new String[]{"1.16", "1.15"})){
            Crucial.getVersion(CrucialAPIVersion, this);
        } else {
            //CrucialAPI only supports 1.16 and 1.15
            Bukkit.getPluginManager().disablePlugin(this);
        }
    }
}
  1. Add a new costom item
    @Override
    public void onEnable() {
        //...
        new CrucialItem("Super shovel", Material.DIAMOND_SHOVEL, "item").setCrafting(new String[]{"Air", "AIR", "AIR", "DIAMOND", "DIAMOND", "DIAMOND", "AIR", "AIR", "AIR"});
}

Clone this wiki locally