Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Images-Common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<groupId>net.dmulloy2</groupId>
<artifactId>ProtocolLib</artifactId>
<version>5.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* MIT License
*
* Copyright (c) 2020 Mark
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.andavin.util;

import java.util.regex.Pattern;

final class BukkitVersionParser {

private static final Pattern PAPER_BUILD_SUFFIX = Pattern.compile("\\.build(?:\\.\\d+)?$");

private BukkitVersionParser() {
}

static String normalize(String bukkitVersion) {

int qualifierIndex = bukkitVersion.indexOf('-');
String version = qualifierIndex == -1 ?
bukkitVersion :
bukkitVersion.substring(0, qualifierIndex);
return PAPER_BUILD_SUFFIX.matcher(version).replaceFirst("");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -429,16 +429,10 @@ private static String findMinorVersion() {
return packageName.substring(minorIndex);
}

String bukkitVersion = server.getBukkitVersion();
return matchVersion(bukkitVersion.substring(0, bukkitVersion.indexOf('-')));
return matchVersion(BukkitVersionParser.normalize(server.getBukkitVersion()));
}

private static String matchVersion(String version) {

if (version.endsWith(".build")) { // Paper experimental versions
version = version.substring(0, version.length() - ".build".length());
}

switch (version) {
case "1.21":
case "1.21.1":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* MIT License
*
* Copyright (c) 2020 Mark
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.andavin.util;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class BukkitVersionParserTest {

@Test
public void normalizesNumberedPaperBuildVersion() {
assertEquals("26.1.2", BukkitVersionParser.normalize("26.1.2.build.2592-stable"));
}

@Test
public void normalizesPaperBuildVersionWithoutNumber() {
assertEquals("26.1.2", BukkitVersionParser.normalize("26.1.2.build"));
}

@Test
public void normalizesStandardBukkitVersion() {
assertEquals("1.21.11", BukkitVersionParser.normalize("1.21.11-R0.1-SNAPSHOT"));
}

@Test
public void preservesPlainMinecraftVersion() {
assertEquals("26.1.2", BukkitVersionParser.normalize("26.1.2"));
}
}
4 changes: 2 additions & 2 deletions Images-Core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<groupId>net.dmulloy2</groupId>
<artifactId>ProtocolLib</artifactId>
<version>5.1.0</version>
<scope>provided</scope>
Expand Down Expand Up @@ -203,4 +203,4 @@
</dependency>
</dependencies>

</project>
</project>