EnchantmentView#setOffers inverted precondition

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: Minor
    • None
    • Affects Version/s: None
    • None
    • This server is running Spigot version 4622-Spigot-566f972-ce1ed6c (MC: 26.1.2) (Implementing API version 26.1.2-R0.1-SNAPSHOT)
    • Yes

      The precondition checking the length of enchantment offers is inverted, causing only arrays of lengths other than 3 to be accepted. This has been a problem since the introduction of the EnchantingView.

      Preconditions.checkArgument(offers.length != 3, "There must be 3 offers given");
      

      should be

      Preconditions.checkArgument(offers.length == 3, "There must be 3 offers given");
      

      https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/browse/src/main/java/org/bukkit/craftbukkit/inventory/view/CraftEnchantmentView.java?until=63148eeb7d6297bac295279b5f7c1aa4298ee110&untilPath=src%2Fmain%2Fjava%2Forg%2Fbukkit%2Fcraftbukkit%2Finventory%2Fview%2FCraftEnchantmentView.java#43

      Minimal reproduction:

      @EventHandler
      public void onPrepareItemEnchant(PrepareItemEnchantEvent event) {
        System.out.printf("Got %s offers%n", event.getOffers().length);
        event.getView().setOffers(event.getOffers());
      }
      

      Place any item into an enchanting table, stack trace ensues.

            Assignee:
            Unassigned
            Reporter:
            Jikoo
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: