-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
63 changed files
with
3,104 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="RunTestPlugin_1.20.4" type="JarApplication"> | ||
<option name="JAR_PATH" value="$PROJECT_DIR$/bukkit/test_plugin_1.20.4/server/server.jar"/> | ||
<option name="VM_PARAMETERS" value="-Dplugin.env=DEV"/> | ||
<option name="PROGRAM_PARAMETERS" value="nogui"/> | ||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/bukkit/test_plugin_1.20.4/server"/> | ||
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true"/> | ||
<option name="ALTERNATIVE_JRE_PATH" value="17"/> | ||
<method v="2"> | ||
<option name="Gradle.BeforeRunTask" enabled="false" tasks="downloadServerJar" | ||
externalProjectPath="$PROJECT_DIR$/bukkit/test_plugin_1.20.4" vmOptions="" scriptParameters=""/> | ||
<option name="Gradle.BeforeRunTask" enabled="true" tasks="build" | ||
externalProjectPath="$PROJECT_DIR$/bukkit/test_plugin_1.20.4" vmOptions="" scriptParameters=""/> | ||
<option name="Gradle.BeforeRunTask" enabled="true" tasks="copyToServer" | ||
externalProjectPath="$PROJECT_DIR$/bukkit/test_plugin_1.20.4" vmOptions="" scriptParameters=""/> | ||
</method> | ||
</configuration> | ||
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="RunTestPlugin_1.20.6" type="JarApplication"> | ||
<option name="JAR_PATH" value="$PROJECT_DIR$/bukkit/test_plugin_1.20.6/server/server.jar"/> | ||
<option name="VM_PARAMETERS" value="-Dplugin.env=DEV"/> | ||
<option name="PROGRAM_PARAMETERS" value="nogui"/> | ||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/bukkit/test_plugin_1.20.6/server"/> | ||
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true"/> | ||
<option name="ALTERNATIVE_JRE_PATH" value="21"/> | ||
<method v="2"> | ||
<option name="Gradle.BeforeRunTask" enabled="false" tasks="downloadServerJar" | ||
externalProjectPath="$PROJECT_DIR$/bukkit/test_plugin_1.20.6" vmOptions="" scriptParameters=""/> | ||
<option name="Gradle.BeforeRunTask" enabled="true" tasks="build" | ||
externalProjectPath="$PROJECT_DIR$/bukkit/test_plugin_1.20.6" vmOptions="" scriptParameters=""/> | ||
<option name="Gradle.BeforeRunTask" enabled="true" tasks="copyToServer" | ||
externalProjectPath="$PROJECT_DIR$/bukkit/test_plugin_1.20.6" vmOptions="" scriptParameters=""/> | ||
</method> | ||
</configuration> | ||
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
bukkit/src/main/java/net/kunmc/lab/commandlib/util/bukkit/VersionUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package net.kunmc.lab.commandlib.util.bukkit; | ||
|
||
import org.bukkit.Bukkit; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
public class VersionUtil { | ||
private static final Pattern MINECRAFT_VERSION_PATTERN = Pattern.compile("\\d+.\\d+.\\d+"); | ||
|
||
private static void checkMinecraftVersionFormat(String s) { | ||
if (!MINECRAFT_VERSION_PATTERN.matcher(s) | ||
.matches()) { | ||
throw new InvalidVersionFormatException("'" + s + "' is not satisfies the version format '\\d+.\\d+.\\d+'"); | ||
} | ||
} | ||
|
||
public static boolean is1_20_x() { | ||
return compareMinecraftVersion(Bukkit.getMinecraftVersion(), | ||
"1.19.99999") > 0 && compareMinecraftVersion(Bukkit.getMinecraftVersion(), | ||
"1.21.0") < 0; | ||
} | ||
|
||
/** | ||
* Compares two Minecraft Version values numerically. | ||
* | ||
* @param x the first Minecraft Version to compare | ||
* @param y the second Minecraft Version to compare | ||
* @return the value {@code 0} if {@code x == y}; | ||
* a value less than {@code 0} if {@code x < y}; and | ||
* a value greater than {@code 0} if {@code x > y} | ||
*/ | ||
public static int compareMinecraftVersion(String x, String y) { | ||
checkMinecraftVersionFormat(x); | ||
checkMinecraftVersionFormat(y); | ||
|
||
String[] xUnits = x.split("\\."); | ||
String[] yUnits = y.split("\\."); | ||
for (int i = 0; i < xUnits.length; i++) { | ||
int xn = Integer.parseInt(xUnits[i]); | ||
int yn = Integer.parseInt(yUnits[i]); | ||
|
||
if (xn < yn) { | ||
return -1; | ||
} | ||
if (xn > yn) { | ||
return 1; | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
public static class InvalidVersionFormatException extends RuntimeException { | ||
public InvalidVersionFormatException(String message) { | ||
super(message); | ||
} | ||
} | ||
|
||
private VersionUtil() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
bukkit/src/test/java/net/kunmc/lab/commandlib/util/bukkit/VersionUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package net.kunmc.lab.commandlib.util.bukkit; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class VersionUtilTest { | ||
@Nested | ||
class CompareMinecraftVersion { | ||
@Test | ||
void returns_zero_with_same_values() { | ||
int res = VersionUtil.compareMinecraftVersion("1.16.5", "1.16.5"); | ||
Assertions.assertThat(res) | ||
.isEqualTo(0); | ||
} | ||
|
||
@Test | ||
void returns_negative_when_x_is_lower() { | ||
int res = VersionUtil.compareMinecraftVersion("1.16.5", "1.20.4"); | ||
Assertions.assertThat(res) | ||
.isLessThan(0); | ||
} | ||
|
||
@Test | ||
void returns_positive_when_x_is_greater() { | ||
int res = VersionUtil.compareMinecraftVersion("1.20.4", "1.16.5"); | ||
Assertions.assertThat(res) | ||
.isGreaterThan(0); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.