GlowstoneMC / Glowstone

A fast, customizable and compatible open source server for Minecraft: Java Edition
https://glowstone.net
Other
1.88k stars 271 forks source link

Executing a command throws NPE due to locale #998

Closed aramperes closed 5 years ago

aramperes commented 5 years ago

The following line throws an NPE when using a command (e.g. /gamemode c) when the player does not have permission to use the command.

https://github.com/GlowstoneMC/Glowstone/blob/2e8ce314c07e78cb241b743bb89eed1a73f58b02/src/main/java/net/glowstone/command/minecraft/GlowVanillaCommand.java#L132

This is because GlowPlayer#getLocale() returns null at the moment. The locale should default to EN_US when this is the case.

The exact stack trace:

org.bukkit.command.CommandException: Unhandled exception executing 'gamemode c' in net.glowstone.command.minecraft.GameModeCommand(gamemode)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:161)
        at net.glowstone.GlowServer.dispatchCommand(GlowServer.java:1910)
        at net.glowstone.entity.GlowPlayer.lambda$chat$15(GlowPlayer.java:2266)
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at net.glowstone.scheduler.GlowTask.run(GlowTask.java:144)
        at net.glowstone.scheduler.GlowScheduler.pulse(GlowScheduler.java:196)
        at net.glowstone.scheduler.GlowScheduler.lambda$start$0(GlowScheduler.java:122)
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
        at java.util.concurrent.FutureTask.runAndReset(Unknown Source)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
        at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:770)
        at com.google.common.cache.LocalCache.get(LocalCache.java:4153)
        at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4158)
        at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:5147)
        at net.glowstone.command.minecraft.GlowVanillaCommand.getBundle(GlowVanillaCommand.java:132)
        at net.glowstone.command.minecraft.GlowVanillaCommand.execute(GlowVanillaCommand.java:95)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:151)
        ... 14 more
Pr0methean commented 5 years ago

Testing whether af166e7baa7705cbf3126caa9a6851af173186b3 fixes this...

Pr0methean commented 5 years ago

Fixed.