Skip to content

Commit

Permalink
fix: paper 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
vaperion committed Jul 4, 2024
1 parent 88ed2be commit 1d664d5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,30 @@ private BukkitContainer(@NotNull Blade blade, @NotNull me.vaperion.blade.command

if (blade.getConfiguration().isOverrideCommands()) {
Map<String, Command> knownCommands = (Map<String, Command>) KNOWN_COMMANDS.get(simpleCommandMap);
Iterator<Map.Entry<String, Command>> iterator = knownCommands.entrySet().iterator();
Set<Map.Entry<String, Command>> entrySet = knownCommands.entrySet();
Iterator<Map.Entry<String, Command>> iterator = entrySet.iterator();

List<String> 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<String, Command> entry = iterator.next();
Command registeredCommand = entry.getValue();

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)) {
Expand Down

0 comments on commit 1d664d5

Please sign in to comment.