how to check for things like this

Discussion in 'Plugin Development' started by MrPotatoMuncher, Mar 9, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    MrPotatoMuncher

    hey, so seeings no one would make the plugin I asked for I am going to ask how to do a bit of it.
    I know how to do everything in it but the 1 thing where I check what the time format is.
    how would I make it check what the letter is that comes after the int e.g. 1d = 1 day, 1s = 1 second etc
    where:
    s = second
    m = minute
    h = hour
    d = day
    mo = month
    y = year
    how do I check for the letter after the int?
     
  2. Offline

    Elimnator

    if(string.contains("s"))
     
  3. Offline

    Dragonphase

    MrPotatoMuncher

    https://gist.github.com/Dragonphase/9458990

    Usage:

    Code:java
    1. Time time = new Time("2h5m10s");
    2. int totalMilliseconds = time.getMilliseconds();
    3. int totalSeconds = time.getSeconds();
    4. int totalMinutes = time.getMinutes();
    5. int totalHours = time.getHours();
    6. int totalDays = time.getDays();
    7. int totalMonths = time.getMonths();
    8. int totalYears = time.getYears();


    It's not perfect, but it's a decent starting point. The only issue with this is that months will always be 30, so you'll need to either use Google's answer to "1 month in days", determine the length of a month based on the current month or just use 30 or 31 as a default.

    It might also be worth mentioning that 1 second is 20 ticks in Minecraft, so you could add the following method to the Time class:

    Code:java
    1. public int getTicks(){
    2. return getSeconds()*20;
    3. }
     
Thread Status:
Not open for further replies.

Share This Page