From 4b34ea3cf52829c05aa44e42e317d90aa71b9ef0 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Thu, 25 Nov 2021 03:25:22 +0100 Subject: [PATCH] Fixes a potential exception when a gate's open-block or closed-block is not a block --- .../portal/property/gate/GateHandler.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/knarcraft/stargate/portal/property/gate/GateHandler.java b/src/main/java/net/knarcraft/stargate/portal/property/gate/GateHandler.java index 4aec3b7..0596ed1 100644 --- a/src/main/java/net/knarcraft/stargate/portal/property/gate/GateHandler.java +++ b/src/main/java/net/knarcraft/stargate/portal/property/gate/GateHandler.java @@ -188,14 +188,25 @@ public class GateHandler { * @return

True if the gate is valid. False otherwise

*/ private static boolean validateGate(Gate gate, String fileName) { + String failString = String.format("Could not load Gate %s", fileName) + " - %s"; + if (gate.getLayout().getControls().length != 2) { - Stargate.logSevere(String.format("Could not load Gate %s - Gates must have exactly 2 control points.", - fileName)); + Stargate.logSevere(String.format(failString, "Gates must have exactly 2 control points.")); return false; } if (!MaterialHelper.isButtonCompatible(gate.getPortalButton())) { - Stargate.logSevere(String.format("Could not load Gate %s - Gate button must be a type of button.", fileName)); + Stargate.logSevere(String.format(failString, "Gate button must be a type of button.")); + return false; + } + + if (!gate.getPortalOpenBlock().isBlock()) { + Stargate.logSevere(String.format(failString, "Gate open block must be a type of block.")); + return false; + } + + if (!gate.getPortalClosedBlock().isBlock()) { + Stargate.logSevere(String.format(failString, "Gate closed block must be a type of block.")); return false; } return true;