Skip to content

Conditions Annotation

Marcin Grzywacz edited this page Oct 17, 2021 · 2 revisions

This is well broad topic these are just basically conditions that need to be checked in order to execute command it can be sitting on top of the command or on top of the class
Example:

@Conditions("creative")
class MiscCMD {
    fun killx(executor: Player, toBeKilled: Player): String {
        return "lol JK"
    }
    fun godmode(executor: Player): String {
        return "<yellow> You have been granted godmode"
    }
}

The example above is using inbuilt creative condition that checks is player in creative mode if he isn't then he gets rejected the use of the command you can add multiple of the conditions by putting "|" between them they need to be exact names or they will crash this whole command you can look up the conditions registered org.lupus.commands.core.managers.ConditionManager object it is basically a HashMap<String, ConditionFun> with each String bound to the name of condition

Your own conditions

Thats fine and all but how do i start making my own conditions? Well first i will say if you have any custom made conditions you can add them via pull request here i would be grateful for helping a developers and me!

So basically in the org.lupus.commands.core.data.ConditionFun you got class ConditionFun that you need to inherit from to get started this class is just basically abstract class that can check conditions via abstract method run it has as parameters CommandLupi object that is calling this condition and the parameters it got passed by the args: Array. It has to be registered with org.lupus.commands.core.managers.ConditionManager object The conditions are right now hard wired into CommandLupi class at the end of the scanning so you need to register them before the scanning takes place

abstract class ConditionFun() {

	// The response player receives if condition failed
	open fun getResponse(sender: CommandSender, commandLupi: CommandLupi, args: Array<Any>): Any {
		return ""
	}

	abstract fun run(sender: CommandSender, commandLupi: CommandLupi, args: Array<Any>): Boolean
}

If something isn't clear just reach out for me on discord Lupus Virtute#2167

Clone this wiki locally