mojira.dev
MC-182362

Score callbacks with a too long name break callback chain

The bug

If a score callback corresponding to /execute store (result|success) score <targets> <objective> contains targets with 41 or more characters, it throws java.lang.IllegalArgumentException while executing the chained callbacks.
This causes the remaining callbacks not to be executed.

How to reproduce

  1. /scoreboard objectives add mc-182362 dummy
    /scoreboard objectives add mc-182362 dummy
  2. /execute store success score a mc-182362 store success score _________________________________________ mc-182362 store success score b mc-182362 run me *
    /execute store success score a mc-182362 store success score _________________________________________ mc-182362 store success score b mc-182362 run me *

    → ❌ An unexpected error occurred trying to execute that command (The player name '_________________________________________' is too long!)

  3. /scoreboard players get a mc-182362
    /scoreboard players get a mc-182362

    → ✔ a has 1 [mc-182362], the callback corresponding to /execute store success score a mc-182362 is successfully executed.

  4. /scoreboard players get b mc-182362
    /scoreboard players get b mc-182362

    → ❌ Can't get value of mc-182362 for b; none is set, the callback corresponding to /execute store success score b mc-182362 is not executed.

Code analysis

Scoreboard#getOrCreatePlayerScore throws IllegalArgumentException iff target.length() > 40 at runtime. This breaks the callback chain created by CALLBACK_CHAINER.

// net.minecraft.server.commands.ExecuteCommand

private static CommandSourceStack storeValue(CommandSourceStack source, Collection<String> targets, Objective objective, boolean result) {
    Scoreboard scoreboard = source.getServer().getScoreboard();
    return source.withCallback((c, s, r) -> {
        for (String target : targets) {
            Score score = scoreboard.getOrCreatePlayerScore(target, objective);
            int count = result ? r : (s ? 1 : 0);
            score.setScore(count);
        }
    }, CALLBACK_CHAINER);
}
// net.minecraft.server.commands.ExecuteCommand

private static CommandSourceStack storeValue(CommandSourceStack source, Collection<String> targets, Objective objective, boolean result) {
    Scoreboard scoreboard = source.getServer().getScoreboard();
    return source.withCallback((c, s, r) -> {
        for (String target : targets) {
            Score score = scoreboard.getOrCreatePlayerScore(target, objective);
            int count = result ? r : (s ? 1 : 0);
            score.setScore(count);
        }
    }, CALLBACK_CHAINER);
}

Comments 0

No comments.

intsuc

boq

Confirmed

Commands

/execute, scoreboard

1.15.2, 20w18a, 20w20b, 1.16 Pre-release 5, 1.16.1, ..., 21w16a, 21w19a, 1.17 Pre-release 1, 1.17, 1.17.1

21w37a

Retrieved