#Is there an API reference for this mod?

58 messages · Page 1 of 1 (latest)

neat hornet
wooden daggerBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

neat hornet
#

Obvious way to solve it would be to cancel the incoming event and send a message with styled username and message using the callback, but I can't see how can this be done. I don't even know what fields and methods do events and callbacks have.

ashen pebble
sharp perchBOT
#

You can load assets (resource pack files) and data (datapack files) with KubeJS, and the wiki has pages on this!

ashen pebble
#

wrong one

#

?? wiki

sharp perchBOT
# ashen pebble ?? wiki

events • recipes • tags • customitems • customblocks • customfluids • recipeviewers • itemmodification • blockmodification • windowmodification • hand • beans • fs • assetsdata • defaultoptions • itemtooltips • worldgen • loottables • components • itemingredient • painter • packets

ashen pebble
#

hmmm

#

well you can try

#

but there isnt much sorry

neat hornet
jade prawn
#

But i do not know how you would create modify and give a player a team

neat hornet
#

Guys I appreciate your efforts but I need actual scripting help

jade prawn
#

I know ai is not that good with kube js
But you could try to do

player.nameTag = Text.of(player.name.string).color(0xFF0000)
#

I can't test the script now as I am on mobile

#

But I think you can

#

And I am 99% certain it won't work

jade prawn
neat hornet
#

When a player joins a server, I want the script to check local storage if the player was assigned a color. If not, it should randomly choose a color then assign it to the player, so each message they send they will have a persistent random color so players can easily distinguish who is texting just by looking at the color

#

Hm. player.NameTag? Actually sounds good

jade prawn
#

The way I would do it as the above snipet I think wont work is by vanila minecraft teams

#

Wait a sec

neat hornet
#

I'm thinking of installing a separate mod for setting player custom colors and calling their commands from a KubeJS script which should be way simpler

#

And if I don't want to mess with storage, I could come up with some simple hashing algorithm so even if the color is reassigned, it will still assign the same color

#

It will be a dirty script, but it will also be very simple

#

And I won't have to deal with teams too

jade prawn
#

You could do that

jade prawn
neat hornet
#

So what I want here is player.logged_in. But how can I see fields of the event?

#

I.e. how do I find username of the logged in player?

jade prawn
#

In kube js easy event.player.username

neat hornet
#

Oh very cool thanks a lot. I think I'll be done in 20

jade prawn
#

20 what?

neat hornet
#

Minutes

jade prawn
#

Ok

#

I don't think that mod changes the names color I just looked în the mod page tho

neat hornet
#

It says it has full formatting support

jade prawn
#

Ok try

ashen pebble
#

is the thing that the mod links to

#

i mean this could work yea

neat hornet
#

Ye, I already checked the docs, thanks

ashen pebble
#

you could also use ftb ranks and im sure there are many other ones too

neat hornet
#

should be something like this

// priority: 0

const colors = [
    "<color:#11dddd>",
    // imagine 16 colors here
];

const hashUsername = (username) => {
    let hash = 0;
    for (let i = 0; i < username.length; i++) {
        hash = (hash * 31 + username.charCodeAt(i)) >>> 0;
    }
    return hash % 16;
};

onEvent('player.logged_in', event => {
    const username = event.player.username;
    const colorId = hashUsername(username);
    const color = colors[colorId];

    Utils.server.runCommandSilent(`styled-nicknames set ${username} ${color}${username}</color>`);
});
ashen pebble
#

ooo im curios is this would work

neat hornet
#

It works! But for some reason not with hashing. I guess I'll do it like this.

// priority: 0

const colors = [
    "<color:FF5733>", "<color:33FF57>", "<color:3357FF>", "<color:FF33A1>",
    "<color:A133FF>", "<color:33FFF5>", "<color:F5FF33>", "<color:FF8C33>",
    "<color:33FF8C>", "<color:8C33FF>", "<color:FF338C>", "<color:338CFF>",
    "<color:33A1FF>", "<color:A1FF33>", "<color:FF33F5>", "<color:F533FF>",
];

const randomColor = () => colors[Math.floor(Math.random() * colors.length)];

onEvent('player.logged_in', event => {
    const username = event.player.getName().getText();
    const color = randomColor();
    const command = `styled-nicknames set ${username} ${color}${username}</color>`;

    Utils.server.runCommandSilent(command);
})
jade prawn
#

Now you need some persistent data so that their color dosen't change

neat hornet
neat hornet
#

worked like this:

// priority: 0

const colors = [
    "<color:#FF5733>", "<color:#33FF57>", "<color:#3357FF>", "<color:#FF33A1>",
    "<color:#A133FF>", "<color:#33FFF5>", "<color:#F5FF33>", "<color:#FF8C33>",
    "<color:#33FF8C>", "<color:#8C33FF>", "<color:#FF338C>", "<color:#338CFF>",
    "<color:#33A1FF>", "<color:#A1FF33>", "<color:#FF33F5>", "<color:#F533FF>",
];

const randomColor = () => colors[Math.floor(Math.random() * colors.length)];

onEvent('player.logged_in', event => {
  let playerData = event.player.persistentData;
  if (playerData.colorSet === "yes") {
      return;
  }

    const username = event.player.getName().getText();
    const color = randomColor();
    const command = `styled-nicknames set ${username} ${color}${username}</color>`;

    Utils.server.runCommandSilent(command);
    playerData.colorSet = "yes";
})

couldnt just use boolean as colorSet i guess there aint no such type in that mapping

#

thanks everyone involved. i will keep this thread open as it's a hacky solution involving a different plugin and id like to rewrite it without using any external mods

ashen pebble
#

nice

next elm