Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-7267

EntityType#getTranslationKey() throws an exception due to incorrect key string

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • None
    • git-Bukkit-76d5e8e
    • Yes

      A recent API addition to get translation keys of blocks, items, and entities, specifically `EntityType#getTranslationKey()`, will throw a `NoSuchElementException` due to an improper lookup in implementation. The lookup incorrectly uses `#name()` (the name of the enum, which is uppercased) rather than the entity's actual key. The exception is as follows:

      [10:11:51] [Server thread/WARN]: java.util.NoSuchElementException: No value present
      [10:11:51] [Server thread/WARN]:        at java.base/java.util.Optional.orElseThrow(Optional.java:377)
      [10:11:51] [Server thread/WARN]:        at org.bukkit.craftbukkit.v1_19_R2.util.CraftMagicNumbers.getTranslationKey(CraftMagicNumbers.java:381)
      [10:11:51] [Server thread/WARN]:        at org.bukkit.entity.EntityType.getTranslationKey(EntityType.java:434)
      [10:11:51] [Server thread/WARN]:        at wtf.choco.test.TestPlugin.onEnable(TestPlugin.java:23)
      [10:11:51] [Server thread/WARN]:        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264)
      [10:11:51] [Server thread/WARN]:        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:334)
      [10:11:51] [Server thread/WARN]:        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:479)
      [10:11:51] [Server thread/WARN]:        at org.bukkit.craftbukkit.v1_19_R2.CraftServer.enablePlugin(CraftServer.java:525)
      [10:11:51] [Server thread/WARN]:        at org.bukkit.craftbukkit.v1_19_R2.CraftServer.enablePlugins(CraftServer.java:451)
      [10:11:51] [Server thread/WARN]:        at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:579)
      [10:11:51] [Server thread/WARN]:        at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:404)
      [10:11:51] [Server thread/WARN]:        at net.minecraft.server.dedicated.DedicatedServer.e(DedicatedServer.java:237)
      [10:11:51] [Server thread/WARN]:        at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:952)
      [10:11:51] [Server thread/WARN]:        at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:293) 

      Worth noting also that this method will also throw a NoSuchElementException for `EntityType.UNKNOWN` which I don't think is the appropriate exception here. An earlier exception from CraftBukkit is preferred. Perhaps an IllegalArgumentException from Preconditions if the type is `UNKNOWN`.

            Doc Doc
            2008Choco Parker Hawke
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: