From 400f856c9ad0678242fe9e014260ad6de3322980 Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Wed, 9 Feb 2022 10:32:07 +0100 Subject: [PATCH] fix: Handle an empty component GUI gracefully --- .../core/components/ComponentPresetManager.java | 8 +++++++- Core/src/main/resources/lang/messages_en.json | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java b/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java index 0b514996f..7ac0db4b8 100644 --- a/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java +++ b/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java @@ -181,7 +181,13 @@ public class ComponentPresetManager { } allowedPresets.add(componentPreset); } - final int size = (int) Math.ceil((double) allowedPresets.size() / 9.0D); + final int size; + if (allowedPresets.isEmpty()) { + player.sendMessage(TranslatableCaption.of("preset.empty")); + return null; + } else { + size = (int) Math.ceil((double) allowedPresets.size() / 9.0D); + } final PlotInventory plotInventory = new PlotInventory(this.inventoryUtil, player, size, TranslatableCaption.of("preset.title").getComponent(player)) { @Override diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index 6ca0e0229..6ffe3b3e2 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -463,6 +463,7 @@ "preset.preset_lore_cost": "Cost: ", "preset.preset_lore_component": "Component: ", "preset.title": "Plot Components", + "preset.empty": "No plot component presets available.", "generic.generic_other": "other", "generic.generic_merged": "merged", "generic.generic_unowned": "unowned",