From 36bd8c0fade68995c0c9d5b44f9d64c0407934c4 Mon Sep 17 00:00:00 2001 From: Video Date: Tue, 29 Jun 2021 21:52:46 -0600 Subject: [PATCH] 2 bugfixes - Fixes FS-309 by checking if a material provided is actually a block before caging someone. - Fixes a bug that causes the command to throw an ArrayOutOfBoundsException if one were to use a command like `/cage player1 block`. --- .../totalfreedommod/command/Command_cage.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cage.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cage.java index 933181c9..c7992547 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cage.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cage.java @@ -77,13 +77,26 @@ public class Command_cage extends FreedomCommand } case "block": { - if (Material.matchMaterial(args[2]) != null) + if (args.length >= 3) { - outerMaterial = Material.matchMaterial(args[2]); - break; + // Checks the validity of the Material and checks if it's a block. + // This is incredibly inefficient, as Spigot's isBlock() method in Material is an actual + // nightmare of switch-cases. + if (Material.matchMaterial(args[2]) != null && Material.matchMaterial(args[2]).isBlock()) + { + outerMaterial = Material.matchMaterial(args[2]); + break; + } + else + { + msg("Invalid block!", ChatColor.RED); + return true; + } + } + else + { + return false; } - msg("Invalid block!", ChatColor.RED); - break; } default: {