KubeJS

KubeJS

69M Downloads

event.server.runCommand() and event.server.runCommandSilent() suddenly stopped working as expected.

Coyote21 opened this issue ยท 7 comments

commented

Minecraft Version

1.18.2

KubeJS Version

kubejs-fabric-1802.5.4-build.533

Rhino Version

rhino-fabric-1802.1.14-build.209

Architectury Version

architectury-4.8.80-fabric

Forge/Fabric Version

Fabric 0.14.9

Describe your issue

Any kubejs script that uses either event.server.runCommand() or event.server.runCommandSilent() with a backticked argument seems to be ignored.

I use very slightly modified Valhelsia scripts to award points/skills in the Levelz mod for certain advancements. This is done using the advancement event and runCommandSilent() to execute the Levelz command that adds skills/points
e.g.

event.server.runCommand(`/playerstats ${event.player.name} add ${rewardData.skill} ${rewardData.points}`);

but this line does not do anything, no errors, no points, no chat messages, no log messages, nothing.
(debug is set to true in config)

However

event.server.runCommand(`/playerstats PLAYERNAME add smithing 1`);

(replacing PLAYERNAME with actual playername)
does work exactly as expected so the issue must be in the backticked string parsing.

I have attached my entire kubejs folder b/c it contains all the scripts that are no longer working, in context.

(If you're at all familiar with Valhelsia, you will recognise them as slightly modified valhelsia scripts but I have not changed anything that would affect this.)
I have left my troubleshooting code in, in case it's of any use.

The two important scripts are server_scripts/first_start.js which gives players their starting 3 points and server_scripts/advancements/rewards.js which gives players points based on advancements earned.

This was all working fine back in March and only became an issue after updating mods at the start of August. I have since tried rolling back the kubejs/rhino/architectury/levelz mods to their pre August versions but the problem remains.

I'm now totally lost without some sort of error message or log output telling me what might be wrong.

kubejs.zip

Crash report/logs

No response

commented

event.player.name returns a Component rather than a String now (it used to be a Text iirc), you can use Component.getString() to get the name as a string (that's event.player.name.string in total)

commented

Using ${event.player.name.string} instead of ${event.player.name} as suggested, fixes the issue.

e.g
event.server.runCommand(`/playerstats ${event.player.name.string} add ${rewardData.skill} ${rewardData.points}`);

Thanks for very quick reply.

commented

Also, please note that these scripts aren't allowed to be used in public modpacks

You should clarify that in the repo with a license file or README.

commented

Also, please note that these scripts aren't allowed to be used in public modpacks

You should clarify that in the repo with a license file or README.

Well, there is no license. It's just plain old copyright law (which defaults to "All rights reserved" in 90% of countries - it doesn't need to be explicitly stated). If I ever get around to cleaning up and making a generic version of that script then I'll probably put it up on a separate repo under an MIT license or something similar, but it'd need to be stripped of all the Valhelsia-specific stuff (since the actual advancement reward data isn't mine to license out).

A readme file is on my to-do list though, since there's several other things that are worth mentioning (including contact details if people want to get permission, which I'll usually grant after some discussion)... unfortunately my escalating health issues have basically stalled me working on any packs at all for quite a while, so it might take a while to get that done.

commented

We updated that script a few months ago to resolve both that issue and another related one. https://github.com/ValhelsiaTeam/Valhelsia-Enhanced-Vanilla/blob/1.18/kubejs/server_scripts/advancements/rewards.js

You should actually use event.player.profile.getName() (or I think event.player.profile.name with the shortcuts that KubeJS adds to get methods, haven't tested that though) since that works with mods that happen to change players' display names.

Also, please note that these scripts aren't allowed to be used in public modpacks without getting explicit permission from us first. We don't mind them being used for private use (such as on a server with friends) or for educational purposes, but please don't just copy our scripts and then upload a public modpack to CurseForge (no idea what you're personally doing with them, this is just a blanket statement).

commented

We updated that script a few months ago to resolve both that issue and another related one.

Another related issue? Any chance of more details? I went through all my/your other scripts looking for other problems but couldn't find any.

Also, please note that these scripts aren't allowed to be used in public modpacks

Just using them for my own private server, being used by a few friends (< 5), for a little while, and it will never be distributed publicly.

But since I have your attention, I really admire and appreciate all the work you guys put into your modpack and I have learned a lot from examining your work. So I just wanted to say thanks for all your hard work in building and maintaining a truly fantastic modpack.

And if I ever did use your work in a public forum I'll do my best to make sure it was well known where I got it from. As evidenced in my posts above.

commented

We updated that script a few months ago to resolve both that issue and another related one.

Another related issue? Any chance of more details? I went through all my/your other scripts looking for other problems but couldn't find any.

The old rewards script broke when people were using a mod to change their nickname in-game. That's why I mentioned using the name from the player profile instead of the display name, since that will always work with the playerstats command no matter what their display name is set to. It didn't impact the stock pack, but there are several common datapacks and mods that modify names (such as adding nicknames or ranks to chat), and I wanted it to be more resilient in those situations.

Also, please note that these scripts aren't allowed to be used in public modpacks

Just using them for my own private server, being used by a few friends (< 5), for a little while, and it will never be distributed publicly.

No problem! That's something that I love to encourage.

But since I have your attention, I really admire and appreciate all the work you guys put into your modpack and I have learned a lot from examining your work. So I just wanted to say thanks for all your hard work in building and maintaining a truly fantastic modpack.

Thanks. :) I will say that some of the older scripts aren't the best learning examples, since I was learning both KubeJS and JavaScript itself while writing them, and I wasn't always aware of best practices at the time... but I'm glad they could be of some use.

And if I ever did use your work in a public forum I'll do my best to make sure it was well known where I got it from. As evidenced in my posts above.

The main thing (if that ever did happen) would just be to chat to me first to discuss it. The majority of the stuff that I've written can be separated out to be usable, but since there are multiple contributors to the pack, I can't license out their work, only my own (some contributors have specific agreements in place too).