PolyhedralDev / Terra

Voxel world generation modding platform
MIT License
638 stars 83 forks source link

Prevent exception with other world generators #449

Closed Browsit closed 6 months ago

Browsit commented 6 months ago

Pull Request

Description

When defining generators for worlds that Bukkit loads by default, other plugins may trigger an exception within Terra as they, of course, do not use colons followed by pack IDs. Here is an example of such using PlotSquared on Paper 1.20.4:

[11:45:46] [Server thread/WARN]: java.lang.IllegalArgumentException: No such config pack ""
[11:45:46] [Server thread/WARN]:    at Terra-bukkit-6.4.3-BETA+ab60f14ff-shaded.jar//com.dfsek.terra.bukkit.TerraBukkitPlugin.lambda$getDefaultWorldGenerator$2(TerraBukkitPlugin.java:194)
[11:45:46] [Server thread/WARN]:    at java.base/java.util.Optional.orElseThrow(Optional.java:403)
[11:45:46] [Server thread/WARN]:    at Terra-bukkit-6.4.3-BETA+ab60f14ff-shaded.jar//com.dfsek.terra.bukkit.TerraBukkitPlugin.lambda$getDefaultWorldGenerator$3(TerraBukkitPlugin.java:193)
[11:45:46] [Server thread/WARN]:    at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1220)
[11:45:46] [Server thread/WARN]:    at Terra-bukkit-6.4.3-BETA+ab60f14ff-shaded.jar//com.dfsek.terra.bukkit.TerraBukkitPlugin.getDefaultWorldGenerator(TerraBukkitPlugin.java:192)
[11:45:46] [Server thread/WARN]:    at plotsquared-bukkit-7.3.2-Premium.jar//com.plotsquared.bukkit.util.BukkitSetupUtils.updateGenerators(BukkitSetupUtils.java:80)
[11:45:46] [Server thread/WARN]:    at plotsquared-bukkit-7.3.2-Premium.jar//com.plotsquared.bukkit.BukkitPlatform.lambda$onEnable$1(BukkitPlatform.java:444)
[11:45:46] [Server thread/WARN]:    at plotsquared-bukkit-7.3.2-Premium.jar//com.plotsquared.bukkit.util.task.BukkitPlotSquaredTask.runTask(BukkitPlotSquaredTask.java:39)
[11:45:46] [Server thread/WARN]:    at plotsquared-bukkit-7.3.2-Premium.jar//com.plotsquared.core.util.task.PlotSquaredTask.run(PlotSquaredTask.java:44)
[11:45:46] [Server thread/WARN]:    at org.bukkit.craftbukkit.v1_20_R3.scheduler.CraftTask.run(CraftTask.java:101)
[11:45:46] [Server thread/WARN]:    at org.bukkit.craftbukkit.v1_20_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:480)
[11:45:46] [Server thread/WARN]:    at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:1143)
[11:45:46] [Server thread/WARN]:    at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:321)
[11:45:46] [Server thread/WARN]:    at java.base/java.lang.Thread.run(Thread.java:833)

This PR resolves the issue by simply returning null when the generator being identified lacks an ID.

Fixes https://discord.com/channels/715448651786485780/1106498518807494676

Checklist

Mandatory checks

Types of changes

Compatibility

Documentation

Testing

Licensing