Skip to main content

Vextension

NSG will/can use https://github.com/VironLab/Vextension, to make things easier. This will show key examples that will be used.

ItemAPI#

The ItemAPI is as it name says, an item api. It makes creating and listening to items easier. Currently, there are these types:

  • Normal Items (static)
  • Dynamic Items (created based on player)

Both of them inherit from ItemStackLike, but are not the same. Normal Items are created with the createItem function and return a normal ItemStack, but the Dynamic Items are created with dynamicItem and return their Factory instead of a ready to go item. You get a ItemStack from a ItemStackLike class through using the get(UUID?) function, which may be null.

Normal Items#

You can create these items with:

createItem(Material.ENDER_PEARL) {    setName("<gray>Hallo!".parseMini()) // Sets the name which is a component    setAmound(1) // Sets the amount of the items    setDamage(0) // Sets the durability to (maxdurability - damage) if its damageable    setLore(           mutableListOf(               "Willkommen zu Vextension!".parseMini()        ) // Sets the lore which is a list of components    )    setUnbreakable(false) // Makes item unbreakable    setBlockInteract(true)    setBlockClick(true)    setBlockDrop(true) // Cancels either interact, click or drop event    setBlockAll(true) // sums up the last 3 lines in one
    setInteractHandler { item, uuid, optional ->        println("$uuid tried to ${optional.get()} ${item.name}!")    }    setDropHandler { item, uuid ->         println("$uuid tried to drop ${item.name}")    }    setClickHandler { item, uuid ->        println("$uuid tried to move ${item.name}")    }    setPermission("random.permission") // Sets a permission, if player is missing it,                                       // the item will not be added to his inventory    setSkullOwner(UUID.fromString("7c79c553-56ef-497a-b9b8-87aafbdb3e28"))            // Sets a skull (will only work if player has previously joined server, see             // setFallbackTexture() for a fallback    setFallbackTexture("TEXTURE URL OR BASE64") // more info below     setProperties(        mutableMapOf("timeCreated" to System.currentTimeMillis().toString())    ) // Adds custom properties to the item that can be gotten for other purposes                                       }

Fallback Skulls#

setFallbackTexture is optional to SkullOwner. If you know/have the SkinURL or the Base64 Data of the player, you can pass it to make one request less, because if the player never joined the server, you cannot get the skull in normal ways. Vextension automatically gets it if this is the case and shades it into the item.

Dynamic Item#

Dynamic items are purely functional, the reason being to adapt to a Player (e.g. colors, properties etc.). Every function will have the Player UUID passed for customisation, which can be null, because it is decided by the API that uses it. You can create one like this:

dynamicItem({ Material.ENDER_PEARL }) {    name { "<pcolor>Hallo".parseMini(it) }    amount { 0 }    blockAll { true }    skullOwner { it?.uniqueId } // No fallback texture needed, because it is the Player that                                // gets the item    clickHandler { item, uuid ->        println("No Changes to Handlers :D")     }
}

Inventory API#

Vextension also has Inventory API, which uses the aforementioned ItemAPI as the Implementation for it. Because the server will use the BukkitGUI and BukkitDataGUI, we will leave the Sponge parts out, because they are unfinished as well.

BukkitGUI#

The BukkitGUI is just a normal GUI. You can create one with:

val exampleInventory: BukkitGUI = BukkitGUI(    6, // Number of lines, can be 1 to 9 (9 slots to 81 slots)    "<purple>Navigator".parseMini() // Header of the Inv; Component).setBorder(createItem(Material.BLACK_STAINED_GLASS_PANE) { // Sets the item around      setName(Component.empty())                              // the inventory    setBlockAll(true)}).setItem(30, createItem(Material.ENDER_PEARL) {    TODO() // create your item that's set to index slot 30})

After the creation you can open it for a player with:

exampleInventory.open(uuid)

You can also customize the Inventory (if it's not a dynamicItem) on open for the Player with:

exampleInventory.open(uuid) { it -> // passes a clone as this and  uuid of player as it,                                    // needs a BukkitGUI in return    name = "<pcolor>$name".parseMini(it)    this}

BukkitDataGUI#

BukkitDataGUI is meant for a collection of items, which can be sorted or left unsorted (e.g. party/clan/friend list) You can either pass a comparator to sort the collection of items or you can pass a default list of items, in case that no list has been passed. You can create one with:

val exampleDataInv = BukkitDataGUI(    6,                                 // Lines; has to be between 2 and 9    "<purple>Your Friends".parseMini() // Title of the Inventory).setComparator { f, s ->    f.properties["x"].toInt().compareTo(s.properties["x"].toInt()) //Sorts the list with properties}.setDefaultList(    mutableListOf(dynamicItem({ Material.PLAYER_HEAD }) {        skull {            it!!        }        properties { mutableMapOf("x", 0) }    }))exampleDataInv.open(uuid, mutableListOf(), customOptionalComparator)

You can set the layout of the Inventory as well, they won't be counted as list items:

exampleDataInv.setLayout(mutableMapOf<Int, ItemStackLike>(    BukkitGUI(6, "tmpToGetBorder").setBorder(createItem(Material.BLACK_STAINED_GLASS_PANE) {        setName(Component.empty())        setBlockAll(true)    })))