A Minecraft Kit API written in Kotlin

Related tags

App hglabor-kits
Overview

hglabor-kits

Dependency

The library is available on Maven Central, add the following dependencies:

implementation("net.axay:hglabor-kits:$version")

hglabor-kits also depends on spigot-language-kotlin and KSpigot.

Make sure to add spigot-language-kotlin as a "compileOnly" dependency and provide its plugin at runtime. Also, do not forget to read the setup guide of KSpigot.

Usage

Kit properties

A kit will likely need some variable properties, which can be changed in the config or via commands. Let us create a class representing these properties:

class NinjaProperties : KitProperties() {
    val maxDistance by int(30)
}

A lot of kits do also need a cooldown of some kind, therefore there is a special CooldownProperties class, let us use that one for our Ninja kit instead.

class NinjaProperties : CooldownProperties(30 * 1000) {
    val maxDistance by int(30)
}

Now we do have a cooldown property automatically, which opens up the possibility to use some nice extensions functions.

Access the properties

Inside the kit body (see below), you can access the properties via kit.properties.yourProperty. In our example that would be kit.properties.maxDistance.

Kit logic

Create the kit

A kit can be created by calling the invoke() operator function of the Kit companion object. You have to pass a reference to the properties:

val Ninja = Kit("Ninja", ::NinjaProperties) {
    // inside the kit body
}

Manage state

It is best practice handling the state inside the kit body, therefore let us create a list to keep track of whom the kit player damaged last.

val Ninja = Kit("Ninja", ::NinjaProperties) {
    val lastDamaged = OnlinePlayerMap<Player>()
}

The following code snippets will all be inside the kit body.

Kit events

hglabor-kits can automatically check if a player (of a PlayerEvent has the kit).

kitPlayerEvent<PlayerToggleSneakEvent> {
    it.player.sendMessage("You definitely have the ${kit.key} kit!")
}

If the event is not a PlayerEvent, you have to provide some logic for getting the player for whom the check should be performed.

With this knowledge, let us create an event to find out who the kit player damages:

kitPlayerEvent<EntityDamageByEntityEvent>(
    // the playerGetter:
    { it.damager as? Player }
) { it, player ->
    lastDamaged[player] = it.entity as? Player ?: return@kitPlayerEvent
}

Note: You can return null in that playerGetter, this will mean that there is no kit player and therefore the kit event won't be executed.

Cooldown

You can apply the cooldown your CooldownProperties very easily if you are inside the kit body, by using the applyCooldown function and passing the PlayerEvent or the Player to it.

Let us actually implement the teleport functionality of the Ninja kit, with our cooldown applied:

kitPlayerEvent<PlayerToggleSneakEvent> {
    applyCooldown(it) {
        val toPlayer = lastDamaged[it.player]
        if (toPlayer == null || !toPlayer.isOnline) {
            cancelCooldown()
        } else {
            if (it.player.location.distance(toPlayer.location) <= kit.properties.maxDistance)
                it.player.teleport(toPlayer)
        }
    }
}
Final result of Ninja kit example

You can view the final implementation of the Ninja kit here .

Going further, there are features which we did not use when creating the Ninja kit:

Kit items

Simple

Just give an item to the player:

simpleItem(ItemStack(Material.NETHERITE_SWORD))

Clickable

Execute code when the player clicks his kit item:

clickableItem(
    itemStack(Material.SPONGE) {
        meta { setDisplayName("Jump") }
    }
) {
    // it is the PlayerInteractEvent here
    it.player.velocity = it.player.velocity.add(vecY(4))
}
You might also like...
Android Contacts API Library written in Kotlin with Java interoperability.
Android Contacts API Library written in Kotlin with Java interoperability.

Android Contacts API Library written in Kotlin with Java interoperability. No more ContentProviders and cursors. Say goodbye to ContactsContract. Build your own contacts app!

A simple android app written in Kotlin to get defination of word entered from Free Dictionary API.
A simple android app written in Kotlin to get defination of word entered from Free Dictionary API.

FlashCard A simple android app written in Kotlin to get defination of word entered from Free Dictionary API. Problem Statement Many of students don't

🚧 A fully open-source project for creating and maintaining a Kotlin-based Minecraft: Java Edition server.

Hexalite: Java Edition ⚠️ WARNING: The Hexalite Network is a work in progress. It is not yet ready for production. You may encounter bugs and other is

🚧 A fully open-source project for creating and maintaining a Kotlin-based Minecraft: Java Edition server.

Hexalite: Java Edition ⚠️ WARNING: The Hexalite Network is a work in progress. It is not yet ready for production. You may encounter bugs and other is

Minecraft JE Server Programming with JS like Skript, Trigger Reactor

mine.js(Developing) Minecraft Java Edition Scripting with JS(V8 Engine) by Netherald How to apply? Download Paper or Bungee Version. and put it to plu

Experience Minecraft in a different way

tesseract Experience Minecraft in a different way. Tesseract is a server software for Minecraft: Bedrock Edition. But it uses a different concept then

Application for downloading and installing skins for minecraft.
Application for downloading and installing skins for minecraft.

Minecraft skins Application for downloading and installing skins for minecraft. Also user can choose favourites skins. Table of Contents Screenshots G

Share your minecraft-adventure with your friends in nation-party.

Nation Party Make your adventure as shared with your friends and family in Nation Party. Features * Create your own party with your own name; * Invite

IMCL is a Minecraft launcher which supports Mod managment, game customizing and so on.

IDEA Minecraft Launcher A simple Minecraft launcher 简体中文 日本語 Esperanto Introduction IMCL is a Minecraft launcher which supports Mod managment, game cu

Comments
  • Mage can't mage bedrock blocks

    Mage can't mage bedrock blocks

    Probably an artifact of a time where you could replace bedrock with endstone to create a voidtrap. Now, its a pretty much useless feature that doesn't fix any bugs. Also, as someone who likes to trap on bedrock level, its a bit frustrating because im not able to mage down a teammate properly.

    opened by stompman 5
  • Purpur is a drop-in replacement for Paper servers designed for config…

    Purpur is a drop-in replacement for Paper servers designed for config…

    …urability, new fun and exciting gameplay features, and high performance built on top of Tuinity and Airplane.

    Purpur is a drop-in replacement for Paper servers designed for configurability, new fun and exciting gameplay features, and high performance built on top of Tuinity and Airplane.

    opened by copyandexecute 1
Owner
Jakob K
Kotlin @HGLabor administrator
Jakob K
Android barcode scanner with ML-Kit vision api

MLBarcodeScanner A demo project to show how to implement barcode scanner using Google ML-Kit Vision api Supported barcode types 2D formats: QR Code, A

Mahdi Javaheri 5 Dec 26, 2022
Text Recognizer App Using the ML Kit

Features Detects text in images Using the ML Kit Text Recognition API Uses the CameraX to show a viewfinder and display the camera preview Provides a

krishna chaitanya 9 Nov 5, 2022
Native android application that scans for text in images. Uses ML kit under the hood.

Scannerate - Ad free Text Recognition Android application built using Kotlin to extract text from images. Uses Google's ML kit library under the hood.

null 24 Dec 1, 2022
WalletConnect Kit is the Swiss Army toolkit for WalletConnect!

WalletConnectKit WalletConnectKit is the Swiss Army toolkit for WalletConnect! It will allow you to connect your DApp with an Ethereum Wallet in a few

Pink Room 52 Nov 24, 2022
SmartLens uses Google's ML Kit for Barcode scanning, Face recognition, Text recognition, and Image labeling.

SmartLens SmartLens uses Google's ML Kit for Barcode scanning, Face recognition, Text recognition, and Image labeling. ?? Screen Shots ?? Features It

Prince Fahad 2 Sep 14, 2022
Face Detector Using Firebase ML Kit

Face Detector (Using Firebase ML Kit) Detects Facial Expression ------> Overlays

Sachin Kumar 1 Jan 4, 2022
This application uses Google Play Services Vision library to scan barcodes. It uses Google's on device ML kit to scan for barcodes.

Barcode-Scanner This application showcases use of Google Play Services Vision library It uses Google's on device machine learning kit to scan for barc

Soumik 2 Apr 28, 2022
Lightning Dev Kit Android Demo Wallet

uMlando-wallet Lightning Dev Kit Android Demo Wallet This project uses a .aar package for the Android platforms that provide language bindings for the

Conor Okus 6 Dec 23, 2022
Mole Analysis Use Case for HMS ML Kit Custom Model

Mole Analysis Mole Analysis Use Case for HMS ML Kit Custom Model Introduction What is Melanoma? Melanoma is the most serious among skin cancers becaus

null 15 Aug 23, 2022
A powerful library for easy implementation of HMS Location Kit.

AdvancedLocation A powerful library for easy implementation of HMS Location Kit. ?? Request location with couple lines of code (no more boilerplate) C

null 2 Aug 4, 2022