Nullpointer exception with /marry setcolor
cdohara opened this issue · 1 comments
Information
Environment information
Plugin + server version info:
Marriage Master: 2.5.4-Release
Server: git-Paper-"5883773" (MC: 1.18.1)
Java: 17
Online mode: no
BungeeCord: no
Server/crash log
29.12 05:52:42 [Server] ERROR Exception when squidrew2 attempted to tab complete marry setcolor
29.12 05:52:42 [Server] INFO org.bukkit.command.CommandException: Unhandled exception during tab completion for command '/marry setcolor ' in plugin MarriageMaster v2.5.4-Release
29.12 05:52:42 [Server] INFO at at.pcgamingfreaks.MarriageMasterStandalone.libs.at.pcgamingfreaks.Bukkit.Command.RegisterablePluginCommand.tabComplete(RegisterablePluginCommand.java:244) ~[MarriageMaster.jar:?]
29.12 05:52:42 [Server] INFO at org.bukkit.command.Command.tabComplete(Command.java:93) ~[paper-api-1.18.1-R0.1-SNAPSHOT.jar:?]
29.12 05:52:42 [Server] INFO at org.bukkit.command.SimpleCommandMap.tabComplete(SimpleCommandMap.java:244) ~[paper-api-1.18.1-R0.1-SNAPSHOT.jar:?]
29.12 05:52:42 [Server] INFO at org.bukkit.craftbukkit.v1_18_R1.CraftServer.tabCompleteCommand(CraftServer.java:2201) ~[paper-1.18.1.jar:git-Paper-"5883773"]
29.12 05:52:42 [Server] INFO at org.bukkit.craftbukkit.v1_18_R1.CraftServer.tabComplete(CraftServer.java:2173) ~[paper-1.18.1.jar:git-Paper-"5883773"]
29.12 05:52:42 [Server] INFO at org.bukkit.craftbukkit.v1_18_R1.command.BukkitCommandWrapper.getSuggestions(BukkitCommandWrapper.java:58) ~[paper-1.18.1.jar:git-Paper-"5883773"]
29.12 05:52:42 [Server] INFO at com.mojang.brigadier.tree.ArgumentCommandNode.listSuggestions(ArgumentCommandNode.java:71) ~[brigadier-1.0.18.jar:git-Paper-"5883773"]
29.12 05:52:42 [Server] INFO at com.mojang.brigadier.CommandDispatcher.getCompletionSuggestions(CommandDispatcher.java:600) ~[paper-1.18.1.jar:?]
29.12 05:52:42 [Server] INFO at com.mojang.brigadier.CommandDispatcher.getCompletionSuggestions(CommandDispatcher.java:580) ~[paper-1.18.1.jar:?]
29.12 05:52:42 [Server] INFO at net.minecraft.server.network.ServerGamePacketListenerImpl.lambda$handleCustomCommandSuggestions$5(ServerGamePacketListenerImpl.java:824) ~[?:?]
29.12 05:52:42 [Server] INFO at net.minecraft.server.TickTask.run(TickTask.java:18) ~[paper-1.18.1.jar:git-Paper-"5883773"]
29.12 05:52:42 [Server] INFO at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:149) ~[?:?]
29.12 05:52:42 [Server] INFO at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:23) ~[?:?]
29.12 05:52:42 [Server] INFO at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:1413) ~[paper-1.18.1.jar:git-Paper-"5883773"]
29.12 05:52:42 [Server] INFO at net.minecraft.server.MinecraftServer.c(MinecraftServer.java:189) ~[paper-1.18.1.jar:git-Paper-"5883773"]
29.12 05:52:42 [Server] INFO at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:122) ~[?:?]
29.12 05:52:42 [Server] INFO at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1391) ~[paper-1.18.1.jar:git-Paper-"5883773"]
29.12 05:52:42 [Server] INFO at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1384) ~[paper-1.18.1.jar:git-Paper-"5883773"]
29.12 05:52:42 [Server] INFO at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:132) ~[?:?]
29.12 05:52:42 [Server] INFO at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:1362) ~[paper-1.18.1.jar:git-Paper-"5883773"]
29.12 05:52:42 [Server] INFO at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1268) ~[paper-1.18.1.jar:git-Paper-"5883773"]
29.12 05:52:42 [Server] INFO at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:317) ~[paper-1.18.1.jar:git-Paper-"5883773"]
29.12 05:52:42 [Server] INFO at java.lang.Thread.run(Thread.java:831) ~[?:?]
29.12 05:52:42 [Server] INFO Caused by: java.lang.NullPointerException: Cannot invoke "String.startsWith(String)" because the return value of "at.pcgamingfreaks.MarriageMasterStandalone.libs.at.pcgamingfreaks.Message.MessageColor.name()" is null
29.12 05:52:42 [Server] INFO at at.pcgamingfreaks.MarriageMasterStandalone.Bukkit.Commands.SetColorCommand.tabComplete(SetColorCommand.java:102) ~[MarriageMaster.jar:?]
29.12 05:52:42 [Server] INFO at at.pcgamingfreaks.MarriageMasterStandalone.Bukkit.Commands.SetColorCommand.tabComplete(SetColorCommand.java:37) ~[MarriageMaster.jar:?]
29.12 05:52:42 [Server] INFO at at.pcgamingfreaks.MarriageMasterStandalone.Bukkit.API.MarryCommand.doTabComplete(MarryCommand.java:171) ~[MarriageMaster.jar:?]
29.12 05:52:42 [Server] INFO at at.pcgamingfreaks.MarriageMasterStandalone.Bukkit.API.MarryCommand.doTabComplete(MarryCommand.java:35) ~[MarriageMaster.jar:?]
29.12 05:52:42 [Server] INFO at at.pcgamingfreaks.MarriageMasterStandalone.libs.at.pcgamingfreaks.Bukkit.Command.CommandExecutorWithSubCommandsGeneric.onTabComplete(CommandExecutorWithSubCommandsGeneric.java:61) ~[MarriageMaster.jar:?]
29.12 05:52:42 [Server] INFO at at.pcgamingfreaks.MarriageMasterStandalone.Bukkit.Commands.CommandManagerImplementation.onTabComplete(CommandManagerImplementation.java:291) ~[MarriageMaster.jar:?]
29.12 05:52:42 [Server] INFO at at.pcgamingfreaks.MarriageMasterStandalone.libs.at.pcgamingfreaks.Bukkit.Command.RegisterablePluginCommand.tabComplete(RegisterablePluginCommand.java:229) ~[MarriageMaster.jar:?]
29.12 05:52:42 [Server] INFO ... 22 more
Plugin config: Default config for version 2.5.4-release
Details
Description
Error occurs during tab completion as evident by the console logs.
Steps to reproduce
Use /marry setcolor
to reproduce.
Expected behavior
I expected it to not produce an error.
Other information (e.g. detailed explanation, related issues, suggestions how to fix, links for us to have context, screenshots, etc.)
This is just a guess since I'm not familiar with the code nor the Spigot API, but it seems the MessageColor class could be the culprit.
@Override
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String mainCommandAlias, @NotNull String alias, @NotNull String[] args)
{
if(args.length!=1 && args.length!=2) return null;
List<String> complete = getMarriagePlugin().getCommandManager().getSimpleTabComplete(sender, args);
if(complete == null) complete = new ArrayList<>(16);
{
String arg = args[args.length - 1].toUpperCase(Locale.ENGLISH);
for(MessageColor color : MessageColor.values())
{
if(color.name().startsWith(arg)) complete.add(color.name());
}
}
return complete;
}
Upon disassembling MessageColor.class
, I noticed the following:
public static at.pcgamingfreaks.Message.MessageColor[] values() {
return null;
}
Instead, relying on Spigot's ChatColor (https://hub.spigotmc.org/javadocs/spigot/org/bukkit/ChatColor.html) may potentially work.
Should be fixed with this build.
I don't know which decompiler you have used, but this looks like it is failing to correctly read the class.
In case you are interested, the problem was that I for some reason forgot to set a name for the RESET color code in the MessageColor class.
I started replacing all usages of Bukkit's ChatColor with my own MessageColor back when RGB support was added, so that I can start adding support for RGB colors, I haven't had the time to add it everywhere, but for most parts it should work already. Also since the plugin still supports MC 1.8 relying on a lot of features from Bukkit/Spigot becomes more and more of an issue.