Sueta
CR

CraftKit | Spigot

1.2.4.2

Utility kit for Spigot and Bungeecord plugins | GUI, NPC, NBT, Skin and more

·Plugin

What is this? CraftKit is a utility kit that aims to speed up the development time. With this library, the developers don't have to write duplicated codes or concerns about multi-version support.

#Manual

If you are a server owner:
Simply put this library into your server's plugin folder. Your server must have an Internet connection to allow the library to download internal modules.
Command: /ck (or /craftkit)

For servers running on Java 9+, please add the following parameter to your server startup command:

--add-opens java.base/java.net=ALL-UNNAMED

If you are a developer and want to use this library:
Repo:

<repositories>
   <repository>
       <id>jitpack.io</id>
       <url>https://jitpack.io</url>
   </repository>
</repositories>

Spigot side:

<dependency>
   <groupId>com.github.anhcraft.CraftKit</groupId>
   <artifactId>craftkit.spigot</artifactId>
   <version>VERSION</version>
</dependency>

Bungeecord side:

<dependency>
   <groupId>com.github.anhcraft.CraftKit</groupId>
   <artifactId>craftkit.bungee</artifactId>
   <version>VERSION</version>
</dependency>

Example:
You can look here to know the basic usages of this library.

ItemBuilder
var itemStack = new ItemBuilder(Material.PAPER).name("&aVoucher").lore("&aRight-click to receive &b10 coins").build();
Make a NPC!
var gameProfile = new GameProfileBuilder("anhcraft");
NPC.spawn(gameProfile, location).addViewer(player);
Set skin for skull item
ItemNBTHelper helper = ItemNBTHelper.of(skull);
helper.setSkin(Skin.MHF_CAKE);
skull = helper.save();
Change skin with Bungeecord
BungeeUtil.changeSkin("anhcraft", new Skin(value, signature));
Use PlayerJumpEvent to count jumps
@EventHandler
private void jump(PlayerJumpEvent event){
    if(JUMP_COUNT.containsKey(event.getPlayer())) JUMP_COUNT.get(event.getPlayer()).incrementAndGet();
    else JUMP_COUNT.put(event.getPlayer(), new AtomicInteger(1));
}
Get latest resource version with Spiget API
SpigetApiUtil.getResourceLatestVersion("39007");
Custom NBT Tag for ItemStack
var root = CompoundTag.of(itemStack);
var tag = root.getOrCreateDefault("tag", CompoundTag.class);
tag.put("custom_tag", new IntTag(1));
root.put("tag", tag);
itemStack = root.save(itemStack);
Create a GUI with callbacks!
// init the extension here!
// CraftExtension.of(<YOUR PLUGIN'S MAIN CLASS>)
private CraftExtension extension;

public void open(Player player){
    CustomGUI cg = extension.createCustomGUI(null, 45, ChatUtil.formatColorCodes("&aRainbow &fInventory"));
    InventoryUtil.fillAll(cg, new ItemBuilder(Material.APPLE)
            .name("&a")
            .build());
    cg.addContentCallback(SlotCallback.PREVENT_MODIFY);
    cg.addContentCallback(new SlotCallback() {
        @Override
        public void click(InventoryClickEvent event, Player player, BaseGUI gui) {
            InventoryUtil.fillAll(cg, new ItemBuilder(RandomUtil.pickRandom(MaterialUtil.getStainedGlassPaneTypes())).name("&a").build());
            player.damage(0.0001);
        }
    });
    player.openInventory(cg);
    // another_player.openInventory(cg);
}
Create an anvil GUI with callbacks!
// init the extension here!
// CraftExtension.of(<YOUR PLUGIN'S MAIN CLASS>)
CraftExtension extension;
AnvilGUI ag = extension.createAnvilGUI(player, "Title");
ag.setItem(AnvilSlot.INPUT_LEFT, new ItemStack(Material.EMERALD, 1), SlotCallback.PREVENT_MODIFY);
ag.setItem(AnvilSlot.OUTPUT, new ItemStack(Material.EMERALD, 1), SlotCallback.PREVENT_MODIFY, new SlotCallback() {
    @Override
    public void click(InventoryClickEvent event, Player player, BaseGUI gui) {
        System.out.println(((AnvilGUI) gui).getInputText());
    }
});
// the GUI is opened automatically! (only for one player)
Create a fake armor stand [Lagless]
// init the extension here!
// CraftExtension.of(<YOUR PLUGIN'S MAIN CLASS>)
CraftExtension extension;
ArmorStand as = ArmorStand.spawn(player.getLocation());
as.setArms(true);
as.setEquipment(EquipmentSlot.HEAD, new ItemStack(Material.IRON_HELMET, 1));
as.setEquipment(EquipmentSlot.HAND, new ItemStack(Material.DIAMOND_AXE, 1));
TrackedEntity<ArmorStand> te = extension.trackEntity(as);
te.setViewDistance(5);
te.addViewer(player);

Similar projects

Plugin →