Meilleure affichage des version multiples de MC

This commit is contained in:
Marc Baloup 2016-08-26 02:13:43 +02:00
parent 87a0326932
commit 7c87b6c33a
2 changed files with 53 additions and 9 deletions

View File

@ -1,5 +1,9 @@
package fr.pandacube.java.util; package fr.pandacube.java.util;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
public enum MinecraftVersion { public enum MinecraftVersion {
v1_7_2_to_1_7_5(4, "1.7.2-1.7.5"), v1_7_2_to_1_7_5(4, "1.7.2-1.7.5"),
v1_7_6_to_1_7_10(5, "1.7.6-1.7.10"), v1_7_6_to_1_7_10(5, "1.7.6-1.7.10"),
@ -8,7 +12,7 @@ public enum MinecraftVersion {
v1_9_1(108, "1.9.1"), v1_9_1(108, "1.9.1"),
v1_9_2(109, "1.9.2"), v1_9_2(109, "1.9.2"),
v1_9_3_to_1_9_4(110, "1.9.3-1.9.4"), v1_9_3_to_1_9_4(110, "1.9.3-1.9.4"),
v1_10(210, "1.10"); v1_10(210, "1.10.x");
public final int versionNumber; public final int versionNumber;
public final String versionDisplay; public final String versionDisplay;
@ -30,4 +34,50 @@ public enum MinecraftVersion {
return null; return null;
} }
public static String displayOptimizedListOfVersions(List<MinecraftVersion> versions) {
return String.join(", ", getVersionsDisplayList(versions));
}
public static final List<String> getVersionsDisplayList(List<MinecraftVersion> versions) {
versions = new ArrayList<>(new HashSet<>(versions));
versions.sort((a, b) -> Integer.compare(a.versionNumber, b.versionNumber));
List<String> ret = new ArrayList<>();
// grouping 1.7 versions
if (versions.contains(v1_7_2_to_1_7_5) && versions.contains(v1_7_6_to_1_7_10)) {
versions.remove(v1_7_2_to_1_7_5);
versions.remove(v1_7_6_to_1_7_10);
ret.add("1.7");
}
// grouping 1.8 versions
if (versions.contains(v1_8)) {
versions.remove(v1_8);
ret.add("1.8");
}
// grouping 1.9 versions
if (versions.contains(v1_9) && versions.contains(v1_9_1) && versions.contains(v1_9_2)
&& versions.contains(v1_9_3_to_1_9_4)) {
versions.remove(v1_9);
versions.remove(v1_9_1);
versions.remove(v1_9_2);
versions.remove(v1_9_3_to_1_9_4);
ret.add("1.9");
}
// grouping 1.10 versions
if (versions.contains(v1_10)) {
versions.remove(v1_10);
ret.add("1.10");
}
for (MinecraftVersion v : versions)
ret.add(v.versionDisplay);
return ret;
}
} }

View File

@ -36,9 +36,7 @@ public class ServerPropertyFile {
* @return true si le chargement a réussi, false sinon * @return true si le chargement a réussi, false sinon
*/ */
public boolean loadFromFile() { public boolean loadFromFile() {
BufferedReader in = null; try (BufferedReader in = new BufferedReader(new FileReader(file))) {
try {
in = new BufferedReader(new FileReader(file));
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> dataFile = new Gson().fromJson(in, Map.class); Map<String, Object> dataFile = new Gson().fromJson(in, Map.class);
@ -61,13 +59,9 @@ public class ServerPropertyFile {
return true; return true;
} catch (IOException e) { } catch (IOException e) {
Log.severe(e); Log.severe(e);
} finally {
try {
in.close();
} catch (Exception e) {}
}
return false; return false;
} }
}
public boolean save() { public boolean save() {
BufferedWriter out = null; BufferedWriter out = null;