Tutorial Get the craftbukkit version (+ little regex tut)

Discussion in 'Resources' started by FisheyLP, Mar 12, 2015.

Thread Status:
Not open for further replies.
  1. Code:java
    1. String version = Bukkit.getVersion();
    this would return something like: git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks (MC: 1.7.5)

    But we want to get rid of the rest and just keep the version (in this case 1.7.5). Use regexes and the replace method:
    Code:java
    1. .replaceAll(".+ \\(MC: ", "").replace(")", "")


    Final code:
    Code:java
    1. String version = Bukkit.getVersion().replaceAll(".+ \\(MC: ", "").replace(")", "");

    Thats how the regex works:
    .+ the . is for every character and the + extends the 'every char' until a whitespace.
    Next is a whitespace.
    Next we use the escaped char for ( -> \\( because (http://www.regular-expressions.info/named.html)
    Next just the characters '
    MC: '
    And finally use the
    .replace method to remove the last )
    For a more detailed regex tutorial visit this site: http://regexone.com :D
     
    ChipDev likes this.
  2. Offline

    mrCookieSlime

    Locked.

    Java is a requirement for Bukkit.
    And because of that basic Java Tutorials are unnecessary here.
    And the modification of Strings is basic Java.
     
    mine-care, xTrollxDudex and Totom3 like this.
Thread Status:
Not open for further replies.

Share This Page