From 78dd53411cb576fa90cfdcbc13adbbc3e85faad3 Mon Sep 17 00:00:00 2001 From: asdanjer Date: Sun, 18 Jun 2023 12:56:27 +0200 Subject: [PATCH] =?UTF-8?q?The=20way=20Item=20stacks=20get=20merged=20can?= =?UTF-8?q?=20cause=20an=20incredibly=20long=20runtime=20if=20there=20is?= =?UTF-8?q?=20a=20large=20amount=20of=20times.=20this=20can=20take=20hours?= =?UTF-8?q?=20or=20days=20if=20the=20ItemStack=20array=20is=20large=20enou?= =?UTF-8?q?gh.=20This=20doesn=E2=80=99t=20happen=20during=20regular=20game?= =?UTF-8?q?play.=20But=20it=20can=20be=20caused=20by=20crafting=20continuo?= =?UTF-8?q?usly=20with=20a=20mod=20like=20Itemscroller.=20Like=20this=20th?= =?UTF-8?q?e=20main=20Consumer=20while=20loop=20gets=20stuck=20in=20the=20?= =?UTF-8?q?merge.=20(as=20it=20causes=20100k+=20stacks=20to=20be=20process?= =?UTF-8?q?ed)=20This=20causes=20an=20indefinite=20(depending=20on=20how?= =?UTF-8?q?=20long=20you=20crafted)=20halt=20of=20all=20database=20pushes.?= =?UTF-8?q?=20This=20can=20not=20only=20render=20these=20mods=20basically?= =?UTF-8?q?=20unusable,=20but=20it=20also=20generates=20a=20memory=20leek?= =?UTF-8?q?=20(as=20the=20que=20is=20stacked=20up)=20and=20also=20prevents?= =?UTF-8?q?=20logging=20till=20the=20merge=20is=20done.=20which,=20not=20o?= =?UTF-8?q?nly=20prevents=20proper=20restarts,=20but=20can=20also=20lose?= =?UTF-8?q?=20data=20when=20forcefully=20restarted.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/net/coreprotect/utility/Util.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/coreprotect/utility/Util.java b/src/main/java/net/coreprotect/utility/Util.java index 1bfdfee8..8cc1dfcc 100755 --- a/src/main/java/net/coreprotect/utility/Util.java +++ b/src/main/java/net/coreprotect/utility/Util.java @@ -457,16 +457,20 @@ public static void mergeItems(Material material, ItemStack[] items) { try { int c1 = 0; for (ItemStack o1 : items) { - int c2 = 0; - for (ItemStack o2 : items) { - if (o1 != null && o2 != null && c2 > c1 && o1.isSimilar(o2) && !Util.isAir(o1.getType())) { // Ignores amount - int namount = o1.getAmount() + o2.getAmount(); - o1.setAmount(namount); - o2.setAmount(0); + if (o1 != null) { + if (o1.getAmount() != 0) { + int c2 = 0; + for (ItemStack o2 : items) { + if (o2 != null && c2 > c1 && o1.isSimilar(o2) && !Util.isAir(o1.getType())) { // Ignores amount + int namount = o1.getAmount() + o2.getAmount(); + o1.setAmount(namount); + o2.setAmount(0); + } + c2++; + } } - c2++; } - c1++; + c1++; } } catch (Exception e) {