Commit 4cc2bb00c8eff08863c9f7625be08983951546a5

Authored by Mumfrey
1 parent 74e458a3

Fix snooper branding application when Forge is present

src/main/java/com/mumfrey/liteloader/core/LiteLoaderBootstrap.java
... ... @@ -15,6 +15,7 @@ import java.io.Serializable;
15 15 import java.lang.reflect.Field;
16 16 import java.util.List;
17 17 import java.util.Map;
  18 +import java.util.Map.Entry;
18 19 import java.util.Properties;
19 20  
20 21 import org.apache.commons.io.Charsets;
... ... @@ -25,6 +26,7 @@ import org.apache.logging.log4j.core.layout.PatternLayout;
25 26 import org.spongepowered.asm.mixin.MixinEnvironment;
26 27  
27 28 import com.google.common.collect.ImmutableMap;
  29 +import com.google.common.collect.ImmutableMap.Builder;
28 30 import com.mumfrey.liteloader.api.LiteAPI;
29 31 import com.mumfrey.liteloader.api.manager.APIAdapter;
30 32 import com.mumfrey.liteloader.api.manager.APIProvider;
... ... @@ -813,13 +815,27 @@ class LiteLoaderBootstrap implements LoaderBootstrap, LoaderEnvironment, LoaderP
813 815 Field fdProperties = clLoader.getDeclaredField("fmlBrandingProperties");
814 816 fdProperties.setAccessible(true);
815 817  
  818 + // Build a new immutable property set, but remove any existing
  819 + // snooperbranding because the immutable map builder doesn't like
  820 + // duplicate keys!
  821 + Builder<String, String> newProperties = ImmutableMap.<String, String>builder();
  822 + for (Entry<String, String> property : properties.entrySet())
  823 + {
  824 + if (!"snooperbranding".equals(property.getKey()))
  825 + {
  826 + newProperties.put(property);
  827 + }
  828 + }
  829 +
  830 + newProperties.put("snooperbranding", branding);
  831 +
816 832 // Set new properties into field
817   - fdProperties.set(instance, ImmutableMap.<String, String>builder().putAll(properties).put("snooperbranding", branding).build());
  833 + fdProperties.set(instance, newProperties.build());
818 834 }
819 835 catch (Exception ex)
820 836 {
821   - // Oh well, we tried
822   - ex.printStackTrace();
  837 + LiteLoaderLogger.info("Unable to apply snooper branding, servers will not receive LiteLoader in branding packets from this client: %s %s",
  838 + ex.getClass().getName(), ex.getMessage());
823 839 }
824 840 }
825 841  
... ...