From bb18f3dab539a170f89383f0b58a229ef85d6637 Mon Sep 17 00:00:00 2001 From: Pablete1234 Date: Fri, 4 Nov 2022 21:14:15 +0100 Subject: [PATCH] Fix unsafe substring calls Signed-off-by: Pablete1234 --- .../java/tc/oc/pgm/inventory/ViewInventoryMatchModule.java | 7 +++++-- util/src/main/java/tc/oc/pgm/util/StringUtils.java | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/tc/oc/pgm/inventory/ViewInventoryMatchModule.java b/core/src/main/java/tc/oc/pgm/inventory/ViewInventoryMatchModule.java index be7a3e8d79..99053308a4 100644 --- a/core/src/main/java/tc/oc/pgm/inventory/ViewInventoryMatchModule.java +++ b/core/src/main/java/tc/oc/pgm/inventory/ViewInventoryMatchModule.java @@ -50,6 +50,7 @@ import tc.oc.pgm.events.PlayerPartyChangeEvent; import tc.oc.pgm.kits.WalkSpeedKit; import tc.oc.pgm.spawns.events.ParticipantSpawnEvent; +import tc.oc.pgm.util.StringUtils; import tc.oc.pgm.util.attribute.Attribute; import tc.oc.pgm.util.bukkit.BukkitUtils; import tc.oc.pgm.util.named.NameStyle; @@ -298,8 +299,10 @@ protected void previewPlayerInventory(Player viewer, PlayerInventory inventory) // Ensure that the title of the inventory is <= 32 characters long to appease Minecraft's // restrictions on inventory titles String title = - TextTranslations.translateLegacy(player(holder, NameStyle.CONCISE, viewer), viewer) - .substring(0, 32); + StringUtils.substring( + TextTranslations.translateLegacy(player(holder, NameStyle.CONCISE, viewer), viewer), + 0, + 32); Inventory preview = Bukkit.getServer().createInventory(viewer, 45, title); diff --git a/util/src/main/java/tc/oc/pgm/util/StringUtils.java b/util/src/main/java/tc/oc/pgm/util/StringUtils.java index 618b214ba6..950c735879 100644 --- a/util/src/main/java/tc/oc/pgm/util/StringUtils.java +++ b/util/src/main/java/tc/oc/pgm/util/StringUtils.java @@ -102,9 +102,9 @@ public static String[] splitIntoTeamPrefixAndSuffix(String text) { } // Split and truncate the text, and restore the color in the suffix - String prefix = text.substring(0, split); + String prefix = substring(text, 0, split); String lastColors = ChatColor.getLastColors(prefix); - String suffix = lastColors + text.substring(split, split + MAX_SUFFIX - lastColors.length()); + String suffix = lastColors + substring(text, split, split + MAX_SUFFIX - lastColors.length()); return new String[] {prefix, suffix}; } }