Add api to get the build version of jail

More for future api usage for other plugins, to determine if the running
version has certain features.
This commit is contained in:
graywolf336 2015-06-03 11:59:20 -05:00
parent 68e35ed271
commit 89f709390a
3 changed files with 23 additions and 1 deletions

View File

@ -20,6 +20,22 @@ public class JailsAPI {
protected JailsAPI(JailMain plugin) {
pl = plugin;
}
/**
* Returns the build number, it will return <strong>-1</strong> if an errors occurs.
*
* @return the build number of jail or -1 if an error occurred.
*/
public static int getBuildNumber() {
String v = pl.getDescription().getVersion();
String[] split = v.split("-");
try {
return Integer.parseInt(split[split.length - 1].replace("b", ""));
}catch(NumberFormatException e) {
return -1;
}
}
/**
* The instance of the {@link JailManager} which contains all the jails and in return prisoners.

View File

@ -5,6 +5,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@ -45,6 +46,11 @@ public class TestJailAPI {
creator.tearDown();
main = null;
}
@Test
public void testBuildNumber() {
assertSame("The build version from the api was not 0.", 0, JailsAPI.getBuildNumber());
}
@Test
public void testManagersAreThere() {

View File

@ -92,7 +92,7 @@ public class TestInstanceCreator {
suppress(constructor(JailMain.class));
main = PowerMockito.spy(new JailMain());
PluginDescriptionFile pdf = PowerMockito.spy(new PluginDescriptionFile("Jail", "3.0.0-Test", "com.graywolf336.jail.JailMain"));
PluginDescriptionFile pdf = PowerMockito.spy(new PluginDescriptionFile("Jail", "3.0.0-SNAPSHOT-b0", "com.graywolf336.jail.JailMain"));
when(pdf.getPrefix()).thenReturn("Jail");
List<String> authors = new ArrayList<String>();
authors.add("matejdro");