Upstream and debugging changes.

This commit is contained in:
MattBDev
2020-01-02 16:30:44 -05:00
parent 9efdd886c5
commit 0d1e32efcb
16 changed files with 196 additions and 117 deletions

View File

@ -86,6 +86,27 @@ public final class Closer implements Closeable {
return zipFile;
}
/**
* Call {@link #rethrow(Throwable)} with the given exception, but before throwing the exception,
* also close this Closer. Exceptions from closing are added to {@code t} as suppressed
* exceptions.
*
* @param t the throwable that should be re-thrown
* @throws IOException if {@code t} is an IOException, or one occurs
*/
public RuntimeException rethrowAndClose(Throwable t) throws IOException {
// bit of a hack here
try {
throw rethrow(t);
} finally {
try {
close();
} catch (Throwable closeThrown) {
t.addSuppressed(closeThrown);
}
}
}
/**
* Stores the given throwable and rethrows it. It will be rethrown as is if it is an
* {@code IOException}, {@code RuntimeException} or {@code Error}. Otherwise, it will be rethrown

View File

@ -19,6 +19,9 @@
package com.sk89q.worldedit.util.translation;
import static java.util.stream.Collectors.toMap;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
@ -26,7 +29,6 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.renderer.FriendlyComponentRenderer;
import com.sk89q.worldedit.util.io.ResourceLoader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@ -76,8 +78,10 @@ public class TranslationManager {
}
private Map<String, String> filterTranslations(Map<String, String> translations) {
translations.entrySet().removeIf(entry -> entry.getValue().isEmpty());
return translations;
return translations.entrySet().stream()
.filter(e -> !e.getValue().isEmpty())
.map(e -> Maps.immutableEntry(e.getKey(), e.getValue().replace("'", "''")))
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
}
private Map<String, String> parseTranslationFile(InputStream inputStream) {
@ -156,4 +160,4 @@ public class TranslationManager {
public Locale getDefaultLocale() {
return defaultLocale;
}
}
}