SpigotMap implements PlatformMap { @Override public @Nullable DispatcherCommand unregister(String name) { var commands = map.getKnownCommands(); var command = commands.get(name); if (!(command instanceof DispatcherCommand)) { return null; } commands.remove(name, command); commands.remove(prefix + ":" + name, command); for (var alias : command.getAliases()) { commands.remove(alias, command); commands.remove(prefix + ":" + alias, command); } command.unregister(map); return (DispatcherCommand) command; } SpigotMap(String prefix, Plugin plugin, CraftCommandMap map); @Override @Nullable DispatcherCommand register(LiteralCommandNode<CommandSender> command); @Override @Nullable DispatcherCommand unregister(String name);  }
@Test void unregister_unknown() { craftmap.getKnownCommands().put("something", mock(Command.class)); assertNull(map.unregister("something")); }
@Test void unregister_aliasable() { DispatcherCommand command = when(mock(DispatcherCommand.class).getAliases()).thenReturn(List.of("a", "b")).getMock(); var other = mock(Command.class); var commands = craftmap.getKnownCommands(); commands.clear(); commands.put("literal", command); commands.put(PREFIX + ":literal", command); commands.put("a", command); commands.put(PREFIX + ":a", command); commands.put("b", other); commands.put(PREFIX + ":a", command); assertEquals(command, map.unregister("literal")); assertEquals(Map.of("b", other), commands); verify(command).unregister(craftmap); }