Skip to content

UndefinedCreations/UndefinedAPI

Repository files navigation

Warning

This API is still in pre-release there might be bugs. If you find any please create an issue

UndefinedAPI

UndefinedAPI is a papermc api to make the life of developers easier. This is a multi use library from small util classes to a GUI manager.

Imports

Maven:

<repository>
    <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>
<dependency>
    <groupId>com.github.TheRedMagic</groupId>
    <artifactId>UndefinedAPI</artifactId>
    <version>Version+</version>
</dependency>

Gradle:

repositories {
    maven { url 'https://jitpack.io' }
}
dependencies {
    implementation 'com.github.TheRedMagic:UndefinedAPI:Version'
}

Setup

To set up UndefinedAPI you will need to put this in onEnable.

UndefinedAPI(this)

After that you are ready to go.

Commands

To be able to create a command with UndefinedAPI you will need to extend the UndefinedCommand Class (See below) The UndefinedCommand class has 5 parameter.

Note

The Command Name var is also be the command name in game

commandName

The name of the command

Note

Default is ALL

commandType

The commandType is an enum to be able to select for who the command to pointed for.

Note

Optional

description

The description of the command

Note

Optional

A list of all the aliases of the command you want

Note

Optional

The permission to be able to run the command

Kotlin:

class FunCommand: UndefinedCommand("Test") {
    override fun execute(sender: CommandSender, args: Array<out String>) {
        sender.sendMessage("FUN!!")
    }
}

Java

public class FunCommand extends UndefinedCommand {
    public FunCommand() {
        super("Test", CommandType.ALL, "A command", List.of(), "");
    }

    @Override
    public void execute(CommandSender sender, String[] args) {
        sender.sendMessage("FUN!!");
    }
}

Tab Completion

To be able to tab complete with the UndefinedCommand you will need to extend the tabComplete method. With this method you will be able to use it just like the default tab complete in spigot except you won't need to use StringUtil to be able to sort it. (See below)

Kotlin

override fun tabComplete(sender: CommandSender, args: Array<out String>): CommandTabUtil {
        
    val nameList: MutableList<String> = mutableListOf()
        
    Bukkit.getOnlinePlayers().forEach{ nameList.add(it.name) }
        
    return CommandTabUtil(nameList, 0)
}

Java

@Override
public CommandTabUtil tabComplete(CommandSender sender, String[] args) {
    ArrayList<String> nameList = new ArrayList<>();

    Bukkit.getOnlinePlayers().forEach(player -> nameList.add(player.getName()));
        
    return new CommandTabUtil(nameList, 0);
}

Menu/GUI

Caution

KOTLIN ONLY

The menu part of this api is a powerful tool to help you make and use GUIS.

Opening GUI

To be able to open a GUI you will need a GUI Object and a Player Object then you can use the openMenu(Menu) method (See below)

player.openMenu(SettingsGUI())

Menu Creation

You can start creating one by extending the UndefinedMenu class. This class only has 2 parameters.

title

This is the title of the GUI

Note

Optional. Default : LARGE If you what to manually choose the size you can use an int

MenuSize

This is an enum to be able to choose the size of the GUI

To be able to create a GUI you have to extend the generateInventory method where you need to return a Inventory. There is a method for this called createInventory. (See below)

class FunMenu: UndefinedMenu("FUN") {
    override fun generateInventory() = createInventory {
        
    }
}

Buttons

After you have created the Inventory you will be able to add buttons using the method Inventory.addButton(Button). The button class needs to parameters slot and consumer The consumer will run then the button is pressed. (See below)

class FunGUI: UndefinedMenu("Fun") {
    override fun generateInventory() = createInventory {

        addButton(Button(10){
            Bukkit.broadcastMessage("Button yeeeeee")
        })

    }
}
Menu Button

An menu button is a button when press it will change menus. (See below)

class FunGUI: UndefinedMenu("Fun") {
    override fun generateInventory() = createInventory {

        addButton(MenuButton(10, DifferntMenu()){
            Bukkit.broadcastMessage("Menu button")
        })

    }
}

Shared

A shared GUI is an gui that can be opened by multiple players, it will update for all players as wel.

Example

Lets say you have a minion GUI that you what to be shared. You can have a minion object and in that object have a var of your GUI. (See below)

Main Class

class Minion {
    val menu = MinionGUI()
}

Menu Class

class MinionGUI: UndefinedMenu("Minion") {
    override fun generateInventory() = createInventory { 
        //Creates GUI
    }
}

Per Player

A per player GUI is an GUI that is that the gui can be different for every player. You can do this by creating a new instance of the Menu class when opening it (See below)

Opening

player.openMenu(SettingsGUI())

Menu Class

class SettingsGUI: UndefinedMenu("Settings") {
    override fun generateInventory() = createInventory {
        //Creates GUI
    }
}

Paged Menu

Caution

KOTLIN ONLY

To be able to create a custom paged Menu you will need to extend the UndefinedPageMenu. Its never the same as a normal Menu but you will need to pase a List of itemStacks witch will be sorted into pages. When the same as the normal Menu you will to extend the generateInventory method with createPageInventory method. After that put in your back button and next button using the setBackButton and setNextButton. You are able to shape the inventory to your liking. (See below)

Note

You need to have the setBackButton and setNextButton for the gui to work.

class FunGui(list: List<ItemStack>): UndefinedPageMenu("Fun", MenuSize.LARGE, list) {
    override fun generateInventory(): Inventory = createPageInventory {

        setBackButton(PageButton(45, ItemStack(Material.RED_STAINED_GLASS_PANE), ItemStack(Material.GRAY_STAINED_GLASS_PANE)))
        setNextButton(PageButton(53, ItemStack(Material.LIME_STAINED_GLASS_PANE), ItemStack(Material.GRAY_STAINED_GLASS_PANE)))

        setColumn(6, ItemBuilder(Material.LIGHT_GRAY_STAINED_GLASS_PANE).setName(" ").build())
    }
}

When lastly extend the clickData: ClickData.() witch will run then the gui is pressed. (See below)

override var clickData: ClickData.() -> Unit = {
    println("DIAMONDS")
}

Events

Caution

KOTLIN ONLY

When using this API you won't need to do and registering of event or even extending the Listener class. Even creating custom events is easier.

Listening

Listening to an event is straight forward and easy. You need to create a method called event<EventType>. (See below)

event<PlayerJoinEvent> { 
    //Player Join
}

To be able to unregister the listener you can very easily put .unregister at the end. (See below)

event<PlayerJoinEvent> {
    //Player Join
}.unregister()

Custom Event

Creating a custom event using this API you extend the UndefinedEvent class (See below)

class AsyncCustomEvent: UndefinedEvent(true) {
    //Async event
}

class SyncCustomEvent: UndefinedEvent() {
    //Sync event
}

Scheduler

Caution

KOTLIN ONLY

Note

TimeUntil class was taken from TwilightAPI

This API makes it easier to create tasks by make methods that be accessed any were. We are going to start by running code sync and async by using this. (See below)

sync { 
    //Run sync code
}
        
async { 
    //Run async code
}

Delay

Next is delaying a task. This is not much different. (See below)

delay(20) {
    //This task will be run in 20 ticks
}

delay(20, true) {
    //This task will be run in 20 ticks async
}
        
delay(1, TimeUnit.SECONDS, false){
    //This task will be run is 20 ticks sync
}

Repeating

Last one is creating repeating tasks. With this you will be able to give in how many times the task will run as wel. (See below)

repeatingTask(1) {
    //This will run every tick
}

repeatingTask(20, 5){
    //This will run every 20 ticks 5 times
}

repeatingTask(1, true){
    //This will run every tick async
}

repeatingTask(20, true, 5){
    //This will run every 20 ticks 5 times async
}

repeatingTask(1, TimeUnit.SECONDS){
    //This will run every second
}

repeatingTask(1, TimeUnit.SECONDS, 5){
    //This will run every second 5 times
}

repeatingTask(1, TimeUnit.SECONDS, true){
    //This will run every second async
}

repeatingTask(1, TimeUnit.SECONDS, 5, true){
    //This will run every second 5 times async
}