forked from TrPlugins/TrMenu
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #126 from Rubenicos/feature/function-action
Add function action
- Loading branch information
Showing
5 changed files
with
87 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
api/action/src/main/kotlin/trplugins/menu/api/action/base/ActionEval.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package trplugins.menu.api.action.base | ||
|
||
import taboolib.common.platform.ProxyPlayer | ||
|
||
/** | ||
* @author Rubenicos | ||
* @date 2024/11/21 14:42 | ||
*/ | ||
interface ActionEval { | ||
|
||
fun onEval(contents: ActionContents, player: ProxyPlayer, placeholderPlayer: ProxyPlayer = player): Boolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
plugin/src/main/kotlin/trplugins/menu/api/action/impl/script/Function.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package trplugins.menu.api.action.impl.script | ||
|
||
import taboolib.common.platform.ProxyPlayer | ||
import taboolib.common.util.subList | ||
import trplugins.menu.api.action.ActionHandle | ||
import trplugins.menu.api.action.base.ActionBase | ||
import trplugins.menu.api.action.base.ActionContents | ||
import trplugins.menu.api.action.base.ActionEval | ||
import trplugins.menu.module.display.session | ||
import trplugins.menu.util.Regexs | ||
|
||
/** | ||
* @author Rubenicos | ||
* @date 2024/11/21 14:42 | ||
*/ | ||
class Function(handle: ActionHandle) : ActionBase(handle), ActionEval { | ||
|
||
override val regex = "(run-?)?functions?|run".toRegex() | ||
|
||
override fun onExecute(contents: ActionContents, player: ProxyPlayer, placeholderPlayer: ProxyPlayer) { | ||
onEval(contents, player, placeholderPlayer) | ||
} | ||
|
||
override fun onEval(contents: ActionContents, player: ProxyPlayer, placeholderPlayer: ProxyPlayer): Boolean { | ||
val session = player.session() | ||
val menu = session.menu ?: return true | ||
val func = contents.stringContent().parseContent(placeholderPlayer).split(' ') | ||
|
||
menu.settings.internalFunctions.forEach { | ||
if (it.id == func[0]) { | ||
val args = subList(func, 1, func.size) | ||
return !it.compile(session, args).asString().lowercase().matches(Regexs.FALSE) | ||
} | ||
} | ||
return true | ||
} | ||
|
||
} |