#Ambiguous calls to Scoreboard.getPlayerScores

109 messages · Page 1 of 1 (latest)

smoky forum
#
const server = Utils.server
const player = server.players[0]
const level = server.overworld();
const scoreboard = level.getScoreboard();
const objective = scoreboard.getObjective("unique_items")
player.tell(scoreboard.hasObjective("unique_items"));
var playerScores = scoreboard.getPlayerScores(objective); //(1)
// var playerScores = scoreboard.method_1184(objective); // (2)
// var playerScores = scoreboard["method_1184(net.minecraft.class_266)"]("unique_items"); //(3)
// var playerScores = scoreboard["interface java.util.Collection method_1184(net.minecraft.class_266)"]("unique_items"); //(4)
console.log(playerScores)
server.tell(Text.prettyPrintNbt(playerScores));
playerScores.put(player.uuid, score);
+ (Test 1)                                 
#7: Error loading KubeJS script: server_scripts:normal.js': The choice of Java method net.minecraft.class_269.method_1184 matching JavaScript argument types (net.minecraft.class_266) is ambiguous; candidate methods are: 
    interface java.util.Collection method_1184(net.minecraft.class_266)
    interface java.util.Map method_1166(java.lang.String) (server_scripts:normal.js#7)
+ (Test 2)                                 
#8: Error loading KubeJS script: server_scripts:normal.js': TypeError: Cannot find function method_1184 in object net.minecraft.class_2995@581fef4f. (server_scripts:normal.js#8)
+ (Test 3)                                 
#9: Error loading KubeJS script: server_scripts:normal.js': TypeError: Cannot find function method_1184(net.minecraft.class_266) in object net.minecraft.class_2995@581fef4f. (server_scripts:normal.js#9)
+ (Test 4)                                
#10: Error loading KubeJS script: server_scripts:normal.js': TypeError: Cannot find function interface java.util.Collection method_1184(net.minecraft.class_266) in object net.minecraft.class_2995@581fef4f. (server_scripts:normal.js#10)

I'm trying to figure out how to get Minecraft's scoreboard working, and KubeJS is telling me I can't use a particular method due to it being ambiguous. Here are the various syntaxes I've tried and the errors they cause; what should I do?

lean wrenBOT
#

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

stoic needle
#

nats doing fun stuff 👀

smoky forum
#

shes trying to 😭

#

kube doesn't wanna let me

stoic needle
#

try

var playerScores = scoreboard["method_1184(net.minecraft.class_266)"]("unique_items")
smoky forum
#
#7: Error loading KubeJS script: server_scripts:normal.js': TypeError: Cannot find function method_1184(net.minecraft.class_266) in object net.minecraft.class_2995@581fef4f. (server_scripts:normal.js#7)
#

(class_2995 is public class ServerScoreboard extends Scoreboard)

stoic needle
#

have you tried using mapped names?

#

wait thats what var playerScores = scoreboard.getPlayerScores(objective); is

#

what does that error with?

smoky forum
#

See (Test 1)

stoic needle
#

ah

smoky forum
#

i put comments on them ^w^

stoic needle
#

ah, i had the thread open in smol view before

#

so there was weird line wrapping

silent socket
#

hate when that happens (has no idea whats going on here)

stoic needle
#

might have to go the long way around

soft swan
#

is Arug going to show us the reflection method?

stoic needle
#

i dont do reflection

#

definitely not a vampire

soft swan
#

fight Rhino

#

with

#

his powers

stoic needle
#

if all else fails, copy code from someone else

soft swan
#

find some overload method that uses something else

stoic needle
#
const trackedPlayers = scoreboard.trackedPlayers
const scores = []
for (let player of trackedPlayers) {
  let objectiveMap = scoreboard.getPlayerScores(player)
  let score = objectiveMap.get(objective)
  if (score != null) scores.add(score) // is it add or put? ive been spending too much time in java land
}
#

this is just the code of the first getPlayerScores in the ambig method list

#

it doesnt sort it tho

soft swan
#

ngl I have no Idea what a scoreboard is, is it vanilla Minecraft stuff?

stoic needle
#

yeah

#

the thing to the right of the screen that servers use a lot

marsh forum
#

java reflection?

stoic needle
#

this thing

soft swan
#

oh

stoic needle
#

well, the thing that backs that thing

#

its complicated

soft swan
#

the f is those numbers? just cursed way to do it?

marsh forum
#

yes

stoic needle
#

the highest score goes to the top

marsh forum
#

you cant have a scoreboard name without a value

stoic needle
#

the bits on the left are technically player names

soft swan
#

so it is like a score and numbers at rank

#

are*

soft swan
stoic needle
marsh forum
#

Class.forName('blah').getMethod('blah squared', method params).invoke(instance of blah)

stoic needle
#

good luck getting a Class object heh

marsh forum
#

you can just do Class.forName('class name')

#

or do Java.loadClass('class name').class

stoic needle
#

wait wat

#

java.lang.Class isnt blocked

marsh forum
#

no

#

it specifically allowed for some reason

stoic needle
#

yeah

smoky forum
stoic needle
#

i still refuse to learn how to use reflection properly

#

its makes stuff too easy

marsh forum
smoky forum
#

you cant claim anything in kube outside custom items/recipes is easy

soft swan
#

honestly why is Rhino confused to which method to choose since Nat gave Objective as param? @stoic needle

stoic needle
#

because everything can be a string

#

and oo look, a string method!

smoky forum
stoic needle
#

there are two methods

#

hence the ambiguity

#

the other takes a string

smoky forum
#

ooh

#

QWAIT

#

WGAT

#

THE STRING IS TO SPECIFY A PLAYER?

stoic needle
#

yeah

#

the backing map is a map to a map of playerstring => { object => score}

soft swan
#

@stoic needle i remember at 1.18 we could use player (PlayerKJS) on string literals, now on 1.19+ we need to player.username, do you know what it cold be? something related to override toString method not existing on 1.19?

stoic needle
#

wat

#

can you say that again

soft swan
#

:/

stoic needle
#

oh

#

players toString changing

#

no

soft swan
#

this worked fine on 1.18, not on 1.19

event.player.tell(`My player name is ${event.player}`)
stoic needle
#

yes because kubejs no longer controls the players toString

#

but that has absolutely nothing to do with this

soft swan
#

that is what I thought

stoic needle
#

there arent even any Players here

soft swan
#

my question is not related to this topic hmmm

stoic needle
#

then make your own thread.

soft swan
#

too late, thx btw blobCozy

stoic needle
spice moth
#

wait what the fuck you can do that

stoic needle
spice moth
#

ive literally never seen that x removed y from the thread message before

stoic needle
#

you can join back tho by sending a message, i think

#

yeah

spice moth
#

yeah

stoic needle
#

it just hides it in your channel list, unless its a private thread

smoky forum
#

Ambiguous calls to Scoreboard.getPlayerScores

smoky forum
#

https://linkie.shedaniel.dev/mappings?namespace=mojang&version=1.19.2&search=class_266.method_

Okay, I've been testing for a while and figured out that the objectives aren't loading all their methods properly or something
They're coming up as strings and they don't have the methods I need like getName()

Here's the slightly unhinged script I ended up with after many iterations of changing random things:

const server = Utils.server
const player = server.players[0]
const level = server.overworld();
const scoreboard = level.getScoreboard();
const objective = scoreboard.getObjective("unique_items")
player.tell(scoreboard.hasObjective("unique_items"));
const trackedPlayers = scoreboard.trackedPlayers
player.tell(trackedPlayers)
const scores = []
for (let p of trackedPlayers) {
    let objectiveMap = scoreboard.getPlayerScores(p)
    player.tell(objectiveMap)
    for (let objective of Object.keys(objectiveMap)) {
        player.tell(objective)
        player.tell(objective[1])
        inspect(objective)
        player.tell(objective.getName())
        if (objective.getName() == "unique_items") {
            scores.push(objectiveMap[objective])
        }
    }
}
console.log(scores)
server.tell(Text.prettyPrintNbt(scores));
[11:00:04] [Server thread/INFO]: [Nat_Squared: Reloading!]
[11:00:04] [Server thread/INFO]: Loaded script server_scripts:minigame_uniqueitem_cmd.js in 0.0 s
[11:00:04] [Server thread/INFO]: server_scripts:normal.js:37: Inspecting: net.minecraft.class_266@38d438fb
=== Properties ===
  0: n
  10: a
  11: f
  12: t
  13: .
  14: c
  15: l
  16: a
  17: s
  18: s
  19: _
  1: e
  20: 2
  21: 6
  22: 6
  23: @
  24: 3
  25: 8
  26: d
  27: 4
  28: 3
  29: 8
  2: t
  30: f
  31: b
  3: .
  4: m
  5: i
  6: n
  7: e
  8: c
  9: r
=== Functions ===
[11:00:04] [Server thread/ERROR]: #50: Error loading KubeJS script: server_scripts:normal.js': TypeError: Cannot find function method_1113 in object net.minecraft.class_266@38d438fb. (server_scripts:normal.js#50)

Using the inspect() from a script i found [here](#955547566529974382 message) returns the nonsense above because it's being treated as a string

dusty rapidsBOT
#

[Quote ➤](#955547566529974382 message) someone made a really good inspect function that shows any object's methods and properties

smoky forum
#

using gnome to ping arug because they've been helpful so far >w<

stoic needle
#

gnome pings dont work in threads now

#

they broked

#

i blame fabric (for no reason other than i am annoyed they dont remap class names at runtime)

#

it seems as if the 'properties' are just a classes toString() as a char list