public static ImmutableContextSet convertContexts(Set<Context> contexts) {
        Objects.requireNonNull(contexts, "contexts");

        if (contexts instanceof ForwardingContextSet) {
            return ((ForwardingContextSet) contexts).delegate().immutableCopy();
        }

        if (contexts.isEmpty()) {
            return ImmutableContextSetImpl.EMPTY;
        }

        ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl();
        for (Map.Entry<String, String> entry : contexts) {
            builder.add(new ContextImpl(entry.getKey(), entry.getValue()));
        }
        return builder.build();
    }
Utility class for converting between Sponge and LuckPerms context and tristate classes
sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/CompatibilityUtil.java