得到一个错误,说我的绑定必须是正的。错误来自此行:return mapNames[ThreadLocalRandom.current().nextInt(mapNames.length)];
我设置mapNames的位置在这里:String[] mapNames = mapsConfiguration.getKeys(false).toArray(new String[]{});
此处设置mapsConfigurationis的位置:private ConfigurationSection mapsConfiguration;
这是我的方法,它是:
public String randomMapName()
{
String[] mapNames = mapsConfiguration.getKeys(false).toArray(new String[]{});
return mapNames[ThreadLocalRandom.current().nextInt(mapNames.length)];
}
我得到了这个堆栈:
java.lang.IllegalArgumentException: bound must be positive
at java.util.concurrent.ThreadLocalRandom.nextInt(Unknown Source) ~[?:1.8.0_301]
at com.proboxinjet.ashguardall.minigame.bedwars.config.ConfigurationManager.randomMapName(ConfigurationManager.java:47) ~[?:?]
at com.proboxinjet.ashguardall.minigame.bedwars.gamemanager.GameManager.<init>(GameManager.java:37) ~[?:?]
at com.proboxinjet.ashguardall.AshGuardAll.onEnable(AshGuardAll.java:23) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[spigot.jar:3096-Spigot-9fb885e-296df56]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:342) ~[spigot.jar:3096-Spigot-9fb885e-296df56]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:480) ~[spigot.jar:3096-Spigot-9fb885e-296df56]
at org.bukkit.craftbukkit.v1_16_R3.CraftServer.enablePlugin(CraftServer.java:492) ~[spigot.jar:3096-Spigot-9fb885e-296df56]
at org.bukkit.craftbukkit.v1_16_R3.CraftServer.enablePlugins(CraftServer.java:406) ~[spigot.jar:3096-Spigot-9fb885e-296df56]
at net.minecraft.server.v1_16_R3.MinecraftServer.loadWorld(MinecraftServer.java:554) ~[spigot.jar:3096-Spigot-9fb885e-296df56]
at net.minecraft.server.v1_16_R3.DedicatedServer.init(DedicatedServer.java:257) ~[spigot.jar:3096-Spigot-9fb885e-296df56]
at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:928) ~[spigot.jar:3096-Spigot-9fb885e-296df56]
at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$0(MinecraftServer.java:273) ~[spigot.jar:3096-Spigot-9fb885e-296df56]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_301]```
ThreadLocalRandom.nextInt(int bound)
的文档说:
绑定上限(独占)。必须是肯定的。
方法的第一行是:
if (bound <= 0)
throw new IllegalArgumentException(BAD_BOUND);
虽然我想说你的mapNames
数组是空的,你把0
传递给nextInt
,然后得到IllegalArgumentException