aether-legacy/src/main/java/com/gildedgames/the_aether/client/gui/trivia/AetherTrivia.java

73 lines
1.7 KiB
Java
Raw Normal View History

2020-08-14 08:29:22 +02:00
package com.gildedgames.the_aether.client.gui.trivia;
2016-12-17 16:28:16 +01:00
2017-03-05 00:20:41 +01:00
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
2018-12-07 05:33:43 +01:00
import java.nio.charset.StandardCharsets;
2016-12-17 16:28:16 +01:00
import java.util.List;
import java.util.Random;
2020-08-14 08:29:22 +02:00
import com.gildedgames.the_aether.Aether;
2017-03-05 00:20:41 +01:00
import net.minecraft.client.Minecraft;
import com.google.common.collect.Lists;
2021-01-01 04:09:39 +01:00
import net.minecraft.client.resources.I18n;
2017-03-05 00:20:41 +01:00
2018-12-07 06:32:48 +01:00
public class AetherTrivia {
private static Random random = new Random();
public AetherTrivia() {
}
public static String getNewTrivia() {
2021-01-01 04:09:39 +01:00
String localization = Minecraft.getMinecraft().getLanguageManager().getCurrentLanguage().getLanguageCode();
if (getEntriesForLocalization(localization) != null)
{
return getEntriesForLocalization(localization);
}
else if (getEntriesForLocalization("en_US") != null)
{
return getEntriesForLocalization("en_US");
}
else
{
return "missingno";
}
}
public static String getEntriesForLocalization(String localization)
{
2018-12-07 06:32:48 +01:00
BufferedReader bufferedreader = null;
try {
2021-01-01 04:09:39 +01:00
List<String> list = Lists.newArrayList();
bufferedreader = new BufferedReader(new InputStreamReader(Minecraft.getMinecraft().getResourceManager().getResource(Aether.locate("texts/" + localization + ".txt")).getInputStream(), StandardCharsets.UTF_8));
2018-12-07 06:32:48 +01:00
String s;
while ((s = bufferedreader.readLine()) != null) {
s = s.trim();
if (!s.isEmpty()) {
list.add(s);
}
}
if (!list.isEmpty()) {
2021-01-01 04:09:39 +01:00
return I18n.format("gui.aether_trivia.pro_tip") + " " + list.get(random.nextInt(list.size()));
2018-12-07 06:32:48 +01:00
}
2021-01-01 04:09:39 +01:00
} catch (IOException ignore) { }
finally {
2018-12-07 06:32:48 +01:00
if (bufferedreader != null) {
try {
bufferedreader.close();
2021-01-01 04:09:39 +01:00
} catch (IOException ignore) { }
2018-12-07 06:32:48 +01:00
}
}
2021-01-01 04:09:39 +01:00
return null;
2018-12-07 06:32:48 +01:00
}
2016-12-17 16:28:16 +01:00
}