diff --git a/fml/common/cpw/mods/fml/server/FMLServerHandler.java b/fml/common/cpw/mods/fml/server/FMLServerHandler.java index ae40c7015..c94ab2d73 100644 --- a/fml/common/cpw/mods/fml/server/FMLServerHandler.java +++ b/fml/common/cpw/mods/fml/server/FMLServerHandler.java @@ -12,7 +12,18 @@ */ package cpw.mods.fml.server; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Collections; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import org.apache.commons.io.IOUtils; import com.google.common.collect.ImmutableList; import com.google.common.collect.MapDifference; @@ -23,8 +34,10 @@ import net.minecraft.network.packet.NetHandler; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet131MapData; import net.minecraft.server.MinecraftServer; +import net.minecraft.util.StringTranslate; import net.minecraft.world.World; import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.IFMLSidedHandler; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.ModContainer; @@ -193,11 +206,58 @@ public class FMLServerHandler implements IFMLSidedHandler @Override public void addModAsResource(ModContainer container) { - // NOOP on server + File source = container.getSource(); + try + { + if (source.isDirectory()) + { + searchDirForENUSLanguage(source,""); + } + else + { + searchZipForENUSLanguage(source); + } + } + catch (IOException ioe) + { + + } + } + private static final Pattern assetENUSLang = Pattern.compile("assets/(.*)/lang/en_US.lang"); + private void searchZipForENUSLanguage(File source) throws IOException + { + ZipFile zf = new ZipFile(source); + for (ZipEntry ze : Collections.list(zf.entries())) + { + Matcher matcher = assetENUSLang.matcher(ze.getName()); + if (matcher.matches()) + { + FMLLog.fine("Injecting found translation data in zip file %s at %s into language system", source.getName(), ze.getName()); + StringTranslate.inject(zf.getInputStream(ze)); + } + } + IOUtils.closeQuietly(zf); + } + private void searchDirForENUSLanguage(File source, String path) throws IOException + { + for (File file : source.listFiles()) + { + String currPath = path+file.getName(); + if (file.isDirectory()) + { + searchDirForENUSLanguage(file, currPath+'/'); + } + Matcher matcher = assetENUSLang.matcher(currPath); + if (matcher.matches()) + { + FMLLog.fine("Injecting found translation data at %s into language system", currPath); + StringTranslate.inject(new FileInputStream(file)); + } + } } @Override public void updateResourcePackList() { - // NOOP on server + } } diff --git a/fml/patches/minecraft/net/minecraft/util/StringTranslate.java.patch b/fml/patches/minecraft/net/minecraft/util/StringTranslate.java.patch index d7c87e5e9..0a593e664 100644 --- a/fml/patches/minecraft/net/minecraft/util/StringTranslate.java.patch +++ b/fml/patches/minecraft/net/minecraft/util/StringTranslate.java.patch @@ -9,7 +9,28 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import java.io.IOException; -@@ -45,7 +47,7 @@ +@@ -23,9 +25,19 @@ + + public StringTranslate() + { ++ InputStream inputstream = StringTranslate.class.getResourceAsStream("/assets/minecraft/lang/en_US.lang"); ++ localInject(inputstream); ++ } ++ ++ public static void inject(InputStream inputstream) ++ { ++ field_74817_a.localInject(inputstream); ++ } ++ ++ private void localInject(InputStream inputstream) ++ { + try + { +- InputStream inputstream = StringTranslate.class.getResourceAsStream("/assets/minecraft/lang/en_US.lang"); + Iterator iterator = IOUtils.readLines(inputstream, Charsets.UTF_8).iterator(); + + while (iterator.hasNext()) +@@ -45,7 +57,7 @@ } } }