From 1d664d5c99ec0748c4fa535cc2b9aec22f886933 Mon Sep 17 00:00:00 2001 From: vaperion Date: Fri, 5 Jul 2024 00:25:48 +0200 Subject: [PATCH] fix: paper 1.21 --- build.gradle | 2 +- .../blade/bukkit/container/BukkitContainer.java | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index c9f90a9..97f8dc2 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ allprojects { } group = 'me.vaperion.blade' - version = '3.0.13' + version = '3.0.14' // workaround for gradle issue: https://github.com/gradle/gradle/issues/17236#issuecomment-894385386 tasks.withType(Copy).configureEach { diff --git a/bukkit/src/main/java/me/vaperion/blade/bukkit/container/BukkitContainer.java b/bukkit/src/main/java/me/vaperion/blade/bukkit/container/BukkitContainer.java index 85bbdd2..d8f3a48 100644 --- a/bukkit/src/main/java/me/vaperion/blade/bukkit/container/BukkitContainer.java +++ b/bukkit/src/main/java/me/vaperion/blade/bukkit/container/BukkitContainer.java @@ -77,7 +77,14 @@ private BukkitContainer(@NotNull Blade blade, @NotNull me.vaperion.blade.command if (blade.getConfiguration().isOverrideCommands()) { Map knownCommands = (Map) KNOWN_COMMANDS.get(simpleCommandMap); - Iterator> iterator = knownCommands.entrySet().iterator(); + Set> entrySet = knownCommands.entrySet(); + Iterator> iterator = entrySet.iterator(); + + List keysToRemove = new ArrayList<>(); + + // Paper 1.21 and above provides a custom HashMap implementation that "transparently" forwards to Brigadier + // Unfortunately this implementation doesn't support Iterator#remove, so we have to collect the keys + boolean lazyRemove = entrySet.getClass().toString().contains("BukkitBrigForwardingMap"); while (iterator.hasNext()) { Map.Entry entry = iterator.next(); @@ -85,9 +92,15 @@ private BukkitContainer(@NotNull Blade blade, @NotNull me.vaperion.blade.command if (doesBukkitCommandConflict(registeredCommand, alias, command)) { registeredCommand.unregister(simpleCommandMap); - iterator.remove(); + + if (!lazyRemove) + iterator.remove(); + else + keysToRemove.add(entry.getKey()); } } + + keysToRemove.forEach(knownCommands::remove); } if (!simpleCommandMap.register(blade.getConfiguration().getFallbackPrefix(), this)) {