Skip to content

Events rehaul - #16

Open
Nuutrai wants to merge 37 commits into
LuaRocket:mainfrom
Nuutrai:events-rehaul
Open

Events rehaul#16
Nuutrai wants to merge 37 commits into
LuaRocket:mainfrom
Nuutrai:events-rehaul

Conversation

@Nuutrai

@NuutraiNuutrai commented Mar 10, 2025

Copy link
Copy Markdown
Contributor

This is a big event rehaul focused on allowing for dynamic events

I'm writing this in a sort of a rush as I need to go to sleep, however if you have any questions, feel free to ask as many as you need, and I'll get back to you as soon as I can.

Thank you!

@Nuutrai

Copy link
Copy Markdown
ContributorAuthor

The class loading also needs to disable loading for abstract classes, but that can wait

@zNotChill

Copy link
Copy Markdown
Contributor

from and to are part of the PlayerMoveEvent event.

Nuutraiand others added 5 commits March 10, 2025 22:39
Co-authored-by: zNotChill <znotchill@znci.dev>
Co-authored-by: mibers <midaswoah2@gmail.com>
# Conflicts:
#	src/main/kotlin/dev/znci/rocket/scripting/events/EventListener.kt
When first experimenting with this type of event handling, I found that there was an issue where every event was called regardless of whether it appeared in any scripts. This fixes this. Note that currently, disabling does not yet remove events from the handler, so that will be next
@Nuutrai

Nuutrai commented Mar 14, 2025

Copy link
Copy Markdown
ContributorAuthor

Note that currently, disabling does not yet remove events from the handler, so that will be one of the next parts

@Nuutrai
Nuutrai marked this pull request as ready for review March 16, 2025 15:07
@Nuutrai
Nuutrai requested a review from zNotChill as a code ownerMarch 16, 2025 15:07

@zNotChillzNotChill left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty much looks good to me, however unnecessary prints should be removed.

@Nuutrai

Copy link
Copy Markdown
ContributorAuthor

Whoops, should I just revert the debug commit altogether?

@zNotChill

Copy link
Copy Markdown
Contributor

If you want to, as long as it doesn't break anything. You could just commit again with the debugs removed. Either way would work as long as nothing breaks.

@Nuutrai

Copy link
Copy Markdown
ContributorAuthor

Let me know if that's better

@Nuutrai
Nuutrai requested a review from zNotChillMarch 18, 2025 20:49
zNotChill
zNotChill previously approved these changes Mar 21, 2025
@gibbiemonster

Copy link
Copy Markdown
Contributor

Merging is blocked pending #32.
There are also new merge conflicts with the New API. Please resolve these how you see fit!

@gibbiemonster
gibbiemonster marked this pull request as draft April 8, 2025 12:18
# Conflicts:
#	build.gradle.kts
#	src/main/kotlin/dev/znci/rocket/Rocket.kt
#	src/main/kotlin/dev/znci/rocket/scripting/ScriptManager.kt
@Nuutrai

Copy link
Copy Markdown
ContributorAuthor

I'm not entirely sure what other things need to be changed regarding the API since most of it is mainly file stuff

@gibbiemonster

Copy link
Copy Markdown
Contributor

@Nuutrai is this ready for review?

@Nuutrai
Nuutrai marked this pull request as ready for review April 10, 2025 15:31
Comment threadbuild.gradle.kts
implementation("net.luckperms:api:5.4")
implementation("org.jetbrains.kotlin:kotlin-reflect")
// TODO check if needed
implementation("com.google.guava:guava:32.0.1-jre")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blockarchitech said not to use guava, he should also comment here

var previousChar: Char? = null
var record = false
for (char in function.toString()) {
if ((previousChar ?: ' ') == ':' && char == ':') if (record == false) record = true else break

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solve the Qodana issue

@zNotChillzNotChill left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good to me, obviously needs to be tested, however there is some issues that should be addressed first

@gibbiemonstergibbiemonster left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More info in the comments. I would generally ignore the Guava comments, on the condition we're planning to use Guava in the future.

Otherwise, do also solve the Qodana issues. There aren't a whole lot, though 🙂

Nice work!

Comment threadbuild.gradle.kts
implementation("net.luckperms:api:5.4")
implementation("org.jetbrains.kotlin:kotlin-reflect")
// TODO check if needed
implementation("com.google.guava:guava:32.0.1-jre")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think guava is a welcome addition but I see not usages of it here.

Comment threadsrc/main/kotlin/dev/znci/rocket/Rocket.kt Outdated
val action = args[0].lowercase()
val scriptName = if (!args[1].endsWith(".lua")) "${args[1]}.lua" else args[1]
val rawScriptName = args[1]
val scriptName = if (!rawScriptName.endsWith(".lua")) "${rawScriptName}.lua" else rawScriptName

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to sanitize this to prevent directory traversal.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain that further?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain that further?

Directory traversal can mostly be prevented by removing any /es from the start, and ../ from the entire path. ./ is fine because it doesn't move to any directory

Comment threadsrc/main/kotlin/dev/znci/rocket/commands/RocketCommand.kt Outdated
val results = ScriptManager.loadAll()
if (results.isNotEmpty()) {
results.forEach { error ->
sender.sendMessage(LocaleManager.getMessageAsComponent("generic_error", error ?: "Unknown error"))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zNotChill - we need better error handling 🙂

Want to open a ticket for that?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zNotChill - we need better error handling 🙂

Want to open a ticket for that?

On my new branch (not yet published), I have already mostly done this. Anywhere you use a RocketError will now work, whereas before it would not, and it would just produce a error calling _: nil error. Now it actually shows you what you did wrong.

eventCallbacks.forEach { callback ->
val luaTable = convertEventToLua(event)
callback.call(luaTable)
println(callback)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid println.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be removed before merging as it was mainly for debugging

private fun getSupportedEvents(): HashSet<Class<out Event>> {
val set = hashSetOf<Class<out Event>>()
for (eventClass in getBukkitEventClasses()) {
// TODO Add a debug setting to show these kinds of things

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leads to some of the QoL things I bug @zNotChill about 😁

There is a way to check if a debugger is attached, and thus, add some trace logs, but I haven't looked too much into implementation.

* Maybe for a different PR, it depends on what znci is feeling
*/

private fun convertEventToLua(event: Event): RocketTable {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not like this. Can we convert to using a class so it's more portable? I defer to the greater team however this looks like a testing nightmare and I do not like how much this still uses the old API. I also am not a fan of the giant switch statement.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in a class rather than an event? I'm still looking into the new API, so I'll try to get those changed soon. What would you prefer instead of the switch statement?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I don't really see what could be changed about the switch statement..

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should rethink how this entire class works. It should be rewritten with the New API's capabilities in mind. I will elaborate in #dev...


return luaTable
})
table.setmetatable(meta)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall a while ago we decided not to use the metatable for some reason?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the meta table, users can't have dynamic event values, or at least stringified event values. We'll hopefully add support for conversions though (just a thought)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant directly. The new API fills out a lot of this stuff for you.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@Nuutrai@zNotChill@gibbiemonster