mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-25 09:59:49 -05:00
Optimize isAir and getNMSVersion method
This commit is contained in:
1 parent
fe900858a8
commit
e67bf53c44
1 file changed
+33
-29
@@ -841,37 +841,13 @@ public class Util {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isSupportIsAirMethod = true;
|
||||
private volatile static String nmsVersion;
|
||||
|
||||
public static boolean isDisplayAllowBlock(@NotNull Material mat) {
|
||||
return mat.isTransparent();
|
||||
}
|
||||
|
||||
public static boolean isAir(@NotNull Material mat) {
|
||||
try {
|
||||
return isAir0(mat); // For newer versions, we had better use Bukkit API
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
if (mat == Material.AIR) {
|
||||
return true;
|
||||
}
|
||||
/* For 1.13 new AIR */
|
||||
try {
|
||||
if (mat == Material.CAVE_AIR) {
|
||||
return true;
|
||||
}
|
||||
if (mat == Material.VOID_AIR) {
|
||||
return true;
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
// ignore
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("RedundantThrows")
|
||||
private static boolean isAir0(@NotNull Material mat) throws Exception {
|
||||
return mat.isAir();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a material is or not a WALL_SIGN
|
||||
*
|
||||
@@ -1237,10 +1213,38 @@ public class Util {
|
||||
return "[" + className + "-" + methodName + "] ";
|
||||
}
|
||||
|
||||
public static boolean isAir(@NotNull Material mat) {
|
||||
if (isSupportIsAirMethod) {
|
||||
try {
|
||||
return mat.isAir(); // For newer versions, we had better use Bukkit API
|
||||
} catch (Throwable ignored) {
|
||||
isSupportIsAirMethod = false;
|
||||
}
|
||||
}
|
||||
if (mat == Material.AIR) {
|
||||
return true;
|
||||
}
|
||||
/* For 1.13 new AIR */
|
||||
try {
|
||||
if (mat == Material.CAVE_AIR) {
|
||||
return true;
|
||||
}
|
||||
if (mat == Material.VOID_AIR) {
|
||||
return true;
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
// ignore
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getNMSVersion() {
|
||||
String name = Bukkit.getServer().getClass().getPackage().getName();
|
||||
return name.substring(name.lastIndexOf('.') + 1);
|
||||
if (nmsVersion == null) {
|
||||
String name = Bukkit.getServer().getClass().getPackage().getName();
|
||||
nmsVersion = name.substring(name.lastIndexOf('.') + 1);
|
||||
}
|
||||
return nmsVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user