From 5962c73a77a808ddeeec951d18d8dfb7e5ca90c1 Mon Sep 17 00:00:00 2001 From: uberifix Date: Tue, 4 Feb 2020 23:52:45 -0500 Subject: [PATCH] Fix crash when trying to set a colour not from the list Added a check and throws an error message now --- .../java/network/pxl8/colouredchat/chat/CommandSetColour.java | 3 +++ src/main/java/network/pxl8/colouredchat/lib/LibColour.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/network/pxl8/colouredchat/chat/CommandSetColour.java b/src/main/java/network/pxl8/colouredchat/chat/CommandSetColour.java index 6c0f991..16165df 100644 --- a/src/main/java/network/pxl8/colouredchat/chat/CommandSetColour.java +++ b/src/main/java/network/pxl8/colouredchat/chat/CommandSetColour.java @@ -24,6 +24,9 @@ private static int setColour(CommandSource source, TextFormatting colour) { if (!Configuration.ALLOW_CUSTOM.get()) { source.sendErrorMessage(new StringTextComponent("Command is disabled by config").applyTextStyle(TextFormatting.RED)); return 0; + } else if (colour == null) { + source.sendErrorMessage(new StringTextComponent("Invalid colour specified").applyTextStyle(TextFormatting.RED)); + return 0; } else { ColouredChat.getCap(source.getEntity()).ifPresent(colourData -> { if (!colourData.getUsePlayerColour()) colourData.setUsePlayerColour(true); diff --git a/src/main/java/network/pxl8/colouredchat/lib/LibColour.java b/src/main/java/network/pxl8/colouredchat/lib/LibColour.java index bcf5ad5..95e2854 100644 --- a/src/main/java/network/pxl8/colouredchat/lib/LibColour.java +++ b/src/main/java/network/pxl8/colouredchat/lib/LibColour.java @@ -43,8 +43,8 @@ public static TextFormatting getColourFromName(String colour) { case("RED"): return TextFormatting.RED; case("LIGHT_PURPLE"): return TextFormatting.LIGHT_PURPLE; case("YELLOW"): return TextFormatting.YELLOW; + default: return null; } - return null; } public static TextFormatting randomFormattedColour() {