From 3e99f90eb1bb6304f21ccbe70a6af1883eae959d Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Wed, 9 Dec 2020 22:45:47 +0100 Subject: [PATCH] Don't spit NPEs on NonNull values --- .../src/main/java/com/plotsquared/core/command/Command.java | 2 +- .../com/plotsquared/core/configuration/caption/Caption.java | 2 -- .../core/configuration/caption/LocalizedCaptionMap.java | 6 +++++- Core/src/main/resources/lang/messages_en.json | 6 +++--- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/command/Command.java b/Core/src/main/java/com/plotsquared/core/command/Command.java index ef325eec0..74d82aaa5 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Command.java +++ b/Core/src/main/java/com/plotsquared/core/command/Command.java @@ -401,9 +401,9 @@ public abstract class Command { public int getMatch(String[] args, Command cmd, PlotPlayer player) { String perm = cmd.getPermission(); - HashSet desc = new HashSet<>(); int count = cmd.getAliases().stream().filter(alias -> alias.startsWith(args[0])) .mapToInt(alias -> 5).sum(); + HashSet desc = new HashSet<>(); Collections.addAll(desc, cmd.getDescription().getComponent(player).split(" ")); for (String arg : args) { if (perm.startsWith(arg)) { diff --git a/Core/src/main/java/com/plotsquared/core/configuration/caption/Caption.java b/Core/src/main/java/com/plotsquared/core/configuration/caption/Caption.java index f826b7ed2..ffc9a8ef8 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/caption/Caption.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/caption/Caption.java @@ -25,8 +25,6 @@ */ package com.plotsquared.core.configuration.caption; -import com.plotsquared.core.configuration.caption.LocaleHolder; - import javax.annotation.Nonnull; /** diff --git a/Core/src/main/java/com/plotsquared/core/configuration/caption/LocalizedCaptionMap.java b/Core/src/main/java/com/plotsquared/core/configuration/caption/LocalizedCaptionMap.java index 8412e21c9..e46838d3e 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/caption/LocalizedCaptionMap.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/caption/LocalizedCaptionMap.java @@ -42,7 +42,11 @@ public class LocalizedCaptionMap implements CaptionMap { } @Override @Nonnull public String getMessage(@Nonnull final TranslatableCaption caption) { - return this.captions.get(caption); + String message = this.captions.get(caption); + if (message == null) { + throw new NoSuchCaptionException(caption); + } + return message; } @Override @Nonnull public String getMessage(@Nonnull final TranslatableCaption caption, diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index 26a574dce..b56724841 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -675,7 +675,6 @@ "commands.description.backup.save": "Create a plot backup.", "commands.description.backup.list": "List available plot backups.", "commands.description.backup.load": "Restore a plot backup", - "commands.description.biome": "Set the plot biome.", "commands.description.buy": "Buy the plot you are standing on.", "commands.description.caps": "Show plot entity caps.", "commands.description.chat": "Toggles plot chat on or off.", @@ -699,7 +698,6 @@ "commands.description.debugsavetest": "This command will force the recreation of all plots in the database.", "commands.description.delete": "Delete the plot you stand on.", "commands.description.deny": "Deny a user from entering a plot.", - "commands.description.desc": "Set the plot description.", "commands.description.dislike": "Dislike the plot.", "commands.description.done": "Continue a plot that was previously marked as done.", "commands.description.download": "Download your plot.", @@ -724,7 +722,6 @@ "commands.description.move": "Move a plot.", "commands.description.music": "Play music in your plot.", "commands.description.near": "Display nearby players.", - "commands.description.owner": "Set the plot owner.", "commands.description.plugin": "Show plugin information.", "commands.description.purge": "Purge all plots for a world.", "commands.description.rate": "Rate a plot.", @@ -735,7 +732,10 @@ "commands.description.save": "Save your plot.", "commands.description.schematic": "Manage schematics.", "commands.description.set": "Set a plot value.", + "commands.description.setbiome": "Set the plot biome.", + "commands.description.setdescription": "Set the plot description.", "commands.description.sethome": "Set the plot home.", + "commands.description.setowner": "Set the plot owner.", "commands.description.setup": "Setup wizard for plot worlds.", "commands.description.swap": "Swap two plots.", "commands.description.target": "Target a plot with your compass.",