2016-02-16 20:07:51 +01:00
|
|
|
package fr.pandacube.java.util;
|
|
|
|
|
2016-08-26 02:13:43 +02:00
|
|
|
import java.util.ArrayList;
|
2019-01-18 18:12:02 +01:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.HashMap;
|
2016-08-26 02:13:43 +02:00
|
|
|
import java.util.List;
|
2019-01-18 18:12:02 +01:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import com.google.common.collect.ImmutableList;
|
2016-08-26 02:13:43 +02:00
|
|
|
|
2016-02-16 20:07:51 +01:00
|
|
|
public enum MinecraftVersion {
|
2016-06-17 17:19:10 +02:00
|
|
|
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_8(47, "1.8.x"),
|
|
|
|
v1_9(107, "1.9"),
|
|
|
|
v1_9_1(108, "1.9.1"),
|
|
|
|
v1_9_2(109, "1.9.2"),
|
2019-01-18 18:12:02 +01:00
|
|
|
v1_9_3_to_1_9_4(110, "1.9.3", "1.9.4"),
|
2016-11-23 00:59:13 +01:00
|
|
|
v1_10(210, "1.10.x"),
|
2016-12-31 17:54:59 +01:00
|
|
|
v1_11(315, "1.11"),
|
2019-01-18 18:12:02 +01:00
|
|
|
v1_11_1_to_1_11_2(316, "1.11.1", "1.11.2"),
|
2017-08-08 23:33:02 +02:00
|
|
|
v1_12(335, "1.12"),
|
2018-03-13 13:26:47 +01:00
|
|
|
v1_12_1(338, "1.12.1"),
|
2018-07-23 23:06:51 +02:00
|
|
|
v1_12_2(340, "1.12.2"),
|
2019-01-17 00:22:19 +01:00
|
|
|
v1_13(393, "1.13"),
|
|
|
|
v1_13_1(401, "1.13.1"),
|
2019-05-10 23:12:01 +02:00
|
|
|
v1_13_2(404, "1.13.2"),
|
2019-06-01 20:58:54 +02:00
|
|
|
v1_14(477, "1.14"),
|
|
|
|
v1_14_1(480, "1.14.1"),
|
2019-07-05 22:16:09 +02:00
|
|
|
v1_14_2(485, "1.14.2"),
|
|
|
|
v1_14_3(490, "1.14.3");
|
2019-01-18 18:12:02 +01:00
|
|
|
// IMPORTANT: don't forget to update the versionMergeDisplay value when adding a new version;
|
|
|
|
|
|
|
|
private static Map<EnumSet<MinecraftVersion>, List<String>> versionMergeDisplay;
|
|
|
|
|
|
|
|
static {
|
|
|
|
versionMergeDisplay = new HashMap<>();
|
|
|
|
|
|
|
|
versionMergeDisplay.put(EnumSet.of(v1_7_2_to_1_7_5, v1_7_6_to_1_7_10),
|
|
|
|
ImmutableList.of("1.7.2-1.7.10"));
|
|
|
|
|
|
|
|
versionMergeDisplay.put(EnumSet.of(v1_9, v1_9_1, v1_9_2, v1_9_3_to_1_9_4),
|
|
|
|
ImmutableList.of("1.9.x"));
|
|
|
|
versionMergeDisplay.put(EnumSet.of(v1_9, v1_9_1, v1_9_2),
|
|
|
|
ImmutableList.of("1.9-1.9.2"));
|
|
|
|
versionMergeDisplay.put(EnumSet.of(v1_9, v1_9_1),
|
|
|
|
ImmutableList.of("1.9", "1.9.1"));
|
|
|
|
versionMergeDisplay.put(EnumSet.of(v1_9_1, v1_9_2, v1_9_3_to_1_9_4),
|
|
|
|
ImmutableList.of("1.9.1-1.9.4"));
|
|
|
|
versionMergeDisplay.put(EnumSet.of(v1_9_1, v1_9_2),
|
|
|
|
ImmutableList.of("1.9.1", "1.9.2"));
|
|
|
|
versionMergeDisplay.put(EnumSet.of(v1_9_2, v1_9_3_to_1_9_4),
|
|
|
|
ImmutableList.of("1.9.2-1.9.4"));
|
|
|
|
|
|
|
|
versionMergeDisplay.put(EnumSet.of(v1_11, v1_11_1_to_1_11_2),
|
|
|
|
ImmutableList.of("1.11.x"));
|
|
|
|
|
|
|
|
versionMergeDisplay.put(EnumSet.of(v1_12, v1_12_1, v1_12_2),
|
|
|
|
ImmutableList.of("1.12.x"));
|
|
|
|
versionMergeDisplay.put(EnumSet.of(v1_12, v1_12_1),
|
|
|
|
ImmutableList.of("1.12", "1.12.1"));
|
|
|
|
versionMergeDisplay.put(EnumSet.of(v1_12_1, v1_12_2),
|
|
|
|
ImmutableList.of("1.12.1", "1.12.2"));
|
|
|
|
|
|
|
|
versionMergeDisplay.put(EnumSet.of(v1_13, v1_13_1, v1_13_2),
|
|
|
|
ImmutableList.of("1.13.x"));
|
|
|
|
versionMergeDisplay.put(EnumSet.of(v1_13, v1_13_1),
|
|
|
|
ImmutableList.of("1.13", "1.13.1"));
|
|
|
|
versionMergeDisplay.put(EnumSet.of(v1_13_1, v1_13_2),
|
|
|
|
ImmutableList.of("1.13.1", "1.13.2"));
|
2019-06-01 20:58:54 +02:00
|
|
|
|
2019-07-05 22:16:09 +02:00
|
|
|
versionMergeDisplay.put(EnumSet.of(v1_14, v1_14_1, v1_14_2, v1_14_3),
|
2019-06-01 20:58:54 +02:00
|
|
|
ImmutableList.of("1.14.x"));
|
2019-07-05 22:16:09 +02:00
|
|
|
versionMergeDisplay.put(EnumSet.of(v1_14, v1_14_1, v1_14_2),
|
|
|
|
ImmutableList.of("1.14-1.14.2"));
|
2019-06-01 20:58:54 +02:00
|
|
|
versionMergeDisplay.put(EnumSet.of(v1_14, v1_14_1),
|
|
|
|
ImmutableList.of("1.14", "1.14.1"));
|
2019-07-05 22:16:09 +02:00
|
|
|
versionMergeDisplay.put(EnumSet.of(v1_14_1, v1_14_2, v1_14_3),
|
|
|
|
ImmutableList.of("1.14.1-1.14.3"));
|
2019-06-01 20:58:54 +02:00
|
|
|
versionMergeDisplay.put(EnumSet.of(v1_14_1, v1_14_2),
|
|
|
|
ImmutableList.of("1.14.1", "1.14.2"));
|
2019-07-05 22:16:09 +02:00
|
|
|
versionMergeDisplay.put(EnumSet.of(v1_14_2, v1_14_3),
|
|
|
|
ImmutableList.of("1.14.2", "1.14.3"));
|
2019-01-18 18:12:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-07-14 14:22:23 +02:00
|
|
|
|
2016-02-16 20:07:51 +01:00
|
|
|
public final int versionNumber;
|
2019-01-18 18:12:02 +01:00
|
|
|
public final List<String> versionDisplay;
|
2016-07-14 14:22:23 +02:00
|
|
|
|
2019-01-18 18:12:02 +01:00
|
|
|
private MinecraftVersion(int v, String... d) {
|
2016-02-16 20:07:51 +01:00
|
|
|
versionNumber = v;
|
2019-01-18 18:12:02 +01:00
|
|
|
versionDisplay = Arrays.asList(d);
|
2016-06-02 18:10:47 +02:00
|
|
|
}
|
2016-07-14 14:22:23 +02:00
|
|
|
|
|
|
|
@Override
|
2016-06-02 18:10:47 +02:00
|
|
|
public String toString() {
|
2019-01-18 18:12:02 +01:00
|
|
|
return StringUtil.joinGrammatically(", ", " et ", versionDisplay);
|
2016-02-16 20:07:51 +01:00
|
|
|
}
|
2016-07-14 14:22:23 +02:00
|
|
|
|
2016-02-16 20:07:51 +01:00
|
|
|
public static MinecraftVersion getVersion(int v) {
|
2019-01-18 18:12:02 +01:00
|
|
|
for (MinecraftVersion mcV : values())
|
2016-07-14 14:22:23 +02:00
|
|
|
if (mcV.versionNumber == v) return mcV;
|
|
|
|
|
2016-02-16 20:07:51 +01:00
|
|
|
return null;
|
|
|
|
}
|
2016-08-26 02:13:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String displayOptimizedListOfVersions(List<MinecraftVersion> versions) {
|
2019-01-18 18:12:02 +01:00
|
|
|
return StringUtil.joinGrammatically(", ", " et ", getVersionsDisplayList(versions));
|
2016-08-26 02:13:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-18 18:12:02 +01:00
|
|
|
public static final List<String> getVersionsDisplayList(List<MinecraftVersion> vList) {
|
|
|
|
Set<MinecraftVersion> vSet = EnumSet.copyOf(vList);
|
2016-08-26 02:13:43 +02:00
|
|
|
|
|
|
|
List<String> ret = new ArrayList<>();
|
|
|
|
|
2019-01-18 18:12:02 +01:00
|
|
|
for (int i = 0; i < values().length; i++) {
|
|
|
|
if (!vSet.contains(values()[i]))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
EnumSet<MinecraftVersion> vSubSet = EnumSet.of(values()[i]);
|
|
|
|
while (i + 1 < values().length && vSet.contains(values()[i + 1])) {
|
|
|
|
i++;
|
|
|
|
vSubSet.add(values()[i]);
|
|
|
|
if (!versionMergeDisplay.containsKey(vSubSet)) {
|
|
|
|
vSubSet.remove(values()[i]);
|
|
|
|
i--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vSubSet.size() == 1) {
|
|
|
|
ret.addAll(values()[i].versionDisplay);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ret.addAll(versionMergeDisplay.get(vSubSet));
|
|
|
|
}
|
2016-08-26 02:13:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
2016-07-14 14:22:23 +02:00
|
|
|
|
2016-02-16 20:07:51 +01:00
|
|
|
}
|