Skip to content

Commit

Permalink
减少嵌套
Browse files Browse the repository at this point in the history
  • Loading branch information
Saukiya committed Oct 22, 2024
1 parent 5128545 commit 37ab490
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
29 changes: 15 additions & 14 deletions Module-Base/src/main/java/github/saukiya/util/nms/NMS.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ class Data {
protected static final Map<Class<? extends NMS>, NMS> INST_MAP = new HashMap<>();
protected static final Map<Class<?>, Map<String, Field>> FIELD_CACHE_MAP = new HashMap<>();
protected static final Map<Class<?>, Class<?>> CLASS_WRAPS_MAP = new HashMap<>();
protected static final String VERSION;
protected static final Pattern VERSION_PATTERN = Pattern.compile("v(\\d+)_(\\d+)_R(\\d+)");
protected static final int[] thisVersionSplit;
protected static final Map<String, String> REVERSION = new HashMap<String, String>() {{
put("1.20.5", "v1_20_R4");
put("1.20.6", "v1_20_R4");
put("1.21", "v1_21_R1");
}};
protected static final String VERSION;
protected static final int[] thisVersionSplit;

static {
CLASS_WRAPS_MAP.put(void.class, Void.class);
Expand Down Expand Up @@ -173,19 +173,20 @@ class Data {
private static int[] getVersion() {
String versionSource = Bukkit.getServer() != null ? Bukkit.getServer().getClass().getPackage().getName().split("^.+\\.")[1] : "v1_17_R1";
Matcher matcher = VERSION_PATTERN.matcher(versionSource);
if (!matcher.matches()) {
versionSource = Bukkit.getServer().getBukkitVersion().split("-")[0];
if (REVERSION.containsKey(versionSource)) {
versionSource = REVERSION.get(versionSource);
} else {
String[] split = versionSource.split("\\.");
versionSource = "v" + split[0] + "_" + split[1] + "_R" + (split.length > 2 ? split[2] : "1");
}
Matcher reMatcher = VERSION_PATTERN.matcher(versionSource);
reMatcher.matches();
return IntStream.range(0, reMatcher.groupCount()).map(i -> Integer.parseInt(reMatcher.group(i + 1))).toArray();
if (matcher.matches()) {
return IntStream.range(0, matcher.groupCount()).map(i -> Integer.parseInt(matcher.group(i + 1))).toArray();
}
// paper
versionSource = Bukkit.getServer().getBukkitVersion().split("-")[0];
if (REVERSION.containsKey(versionSource)) {
versionSource = REVERSION.get(versionSource);
} else {
String[] split = versionSource.split("\\.");
versionSource = "v" + split[0] + "_" + split[1] + "_R" + (split.length > 2 ? split[2] : "1");
}
return IntStream.range(0, matcher.groupCount()).map(i -> Integer.parseInt(matcher.group(i + 1))).toArray();
Matcher reMatcher = VERSION_PATTERN.matcher(versionSource);
reMatcher.matches();
return IntStream.range(0, reMatcher.groupCount()).map(i -> Integer.parseInt(reMatcher.group(i + 1))).toArray();
}

protected static boolean checkClass(@Nonnull Class<?> c1, @NonNull Class<?> c2) {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ allprojects { project ->
apply plugin: 'java'

group 'io.github.saukiya'
version '4.2.1'
version '4.2.2'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand Down

0 comments on commit 37ab490

Please sign in to comment.