Solved Get a World full time?

Discussion in 'Spigot Plugin Development' started by SebazCRC, Aug 13, 2019.

  1. Hi, bassically the title, but I want to convert:
    Code (Java):
    Bukkit.getWorld("worldName").getFullTime();
    In to Days and months, and years, I tried this but doesnt works so good:

    Code (Java):
    public String getWorldFullTime() {

            String day = getDay(true);
            String month = getMonth();
            String year = getYear();

            int i = 0;

            return ChatUtil.format(day + " de " + month);
        }

        public String getYear() {

            int worldFull = Integer.valueOf(String.valueOf(plugin.getWorld().getFullTime()));
            int years = 0;

            if (worldFull >= 8760001) {

                years = worldFull % 8760000;
            }

            return String.valueOf(years);
        }

        public String getMonth() {

            String month = "";
            int i = Integer.valueOf(getDay(true));

            if (i == 0) {

                i = 1;
            }

            if (i >= 1 && i <= 30) {

                month = "Enero";

            }else if (i >= 31 && i <= 60) {

                month = "Febrero";
            } else if (i >= 61 && i <= 90) {

                month = "Marzo";
            } else if (i >= 91 && i <= 120) {

                month = "Abril";
            } else if (i >= 121 && i <= 150) {

                month = "Mayo";
            } else if (i >= 151 && i <= 180) {

                month = "Junio";
            } else if (i >= 181 && i <= 210) {

                month = "Julio";
            } else if (i >= 211 && i <= 240) {

                month = "Agosto";
            } else if (i >= 241 && i <= 270) {

                month = "Septiembre";
            } else if (i >= 271 && i <= 300) {

                month = "Octubre";
            } else if (i >= 301 && i <= 330) {

                month = "Noviembre";
            } else if (i >= 331 && i <= 365) {

                month = "Diciembre";
            }

            return month;
        }

        public String getDay(boolean b) {

            long full = plugin.getWorld().getFullTime();
            int tday = 24000;

            long days = full % tday;
            String day = "" + days;

            int i = Integer.valueOf(day);

            if (b) {

                if (i >= 31) {

                    return String.valueOf(i % 30);
                }
            } else {

                return day;
            }
            return null;
        }

    PD: The months are in spanish.
     
    • Useful Useful x 1
  2. What's wrong with using the calendar?
     
  3. Im making something like Hypixel Skyblock, here is the scoreboard running that method

    I want get custom world calendar
     

    Attached Files:

    #4 SebazCRC, Aug 14, 2019
    Last edited by a moderator: Aug 15, 2019
  4. You can get the world's time and use it in a calendar to get the hour, minute and whatever time really.
     
  5. I used that code, and did not work, whats wrong?

    The numbers start to change from 1 to 30 and the month is null
     

    Attached Files:

    #6 SebazCRC, Aug 14, 2019
    Last edited by a moderator: Aug 15, 2019
  6. Can you actually share some code?
     
  7. Yes watch the first post, there is my code

    Code (Java):
    public String getWorldFullTime() {

            String day = getDay(true);
            String month = getMonth();
            String year = getYear();

            int i = 0;

            return ChatUtil.format(day + " de " + month);
        }

        public String getYear() {

            int worldFull = Integer.valueOf(String.valueOf(plugin.getWorld().getFullTime()));
            int years = 0;

            if (worldFull >= 8760001) {

                years = worldFull % 8760000;
            }

            return String.valueOf(years);
        }

        public String getMonth() {

            String month = "";
            int i = Integer.valueOf(getDay(true));

            if (i == 0) {

                i = 1;
            }

            if (i >= 1 && i <= 30) {

                month = "Enero";

            }else if (i >= 31 && i <= 60) {

                month = "Febrero";
            } else if (i >= 61 && i <= 90) {

                month = "Marzo";
            } else if (i >= 91 && i <= 120) {

                month = "Abril";
            } else if (i >= 121 && i <= 150) {

                month = "Mayo";
            } else if (i >= 151 && i <= 180) {

                month = "Junio";
            } else if (i >= 181 && i <= 210) {

                month = "Julio";
            } else if (i >= 211 && i <= 240) {

                month = "Agosto";
            } else if (i >= 241 && i <= 270) {

                month = "Septiembre";
            } else if (i >= 271 && i <= 300) {

                month = "Octubre";
            } else if (i >= 301 && i <= 330) {

                month = "Noviembre";
            } else if (i >= 331 && i <= 365) {

                month = "Diciembre";
            }

            return month;
        }

        public String getDay(boolean b) {

            long full = plugin.getWorld().getFullTime();
            int tday = 24000;

            long days = full % tday;
            String day = "" + days;

            int i = Integer.valueOf(day);

            if (b) {

                if (i >= 31) {

                    return String.valueOf(i % 30);
                }
            } else {

                return day;
            }
            return null;
        }
     
    #8 SebazCRC, Aug 14, 2019
    Last edited by a moderator: Aug 15, 2019
  8. I'm talking about the calendar way which I provided.
     
  9. Is that working with World time?, I dont use Calendar for now
     
  10. It should work with any time format.
     
  11. So how I use it?
     
  12. I already provided you with examples.
     
  13. I have a question, how can I get the months in another lang, I have to make it String and then, use #replace
    ?

    Or check if the month its 1 and return "Enero" (in spanish January)
     
    #14 SebazCRC, Aug 14, 2019
    Last edited by a moderator: Aug 15, 2019
  14. I dont understand, can you please send me Code example with a Explanation.

    When I get month, I got int, is that the month???
     
    #16 SebazCRC, Aug 14, 2019
    Last edited by a moderator: Aug 15, 2019
  15. Yes. And please refrain from double posting. Use the edit button on your latest reply instead.
     
    #17 Shin1gamiX, Aug 14, 2019
    Last edited: Aug 14, 2019
  16. Yeah, now it works thanks for your help.

    Got a problem, now the days keep same, it says 31 all time

    When the day finish, does not nothing.

    Code:
    Code (Java):
    public String getCalendar() {

            Calendar c = Calendar.getInstance();

            c.setTimeInMillis(plugin.getWorld().getFullTime());

            int day = c.get(Calendar.DAY_OF_MONTH);
            int wday = c.get(Calendar.DAY_OF_WEEK);
            int fmonth = c.get(Calendar.MONTH);

            String weekday = "Lunes";
            String month = "Enero";

            if (wday == 1) {

                weekday = "Lunes";

            } else if (wday == 2) {

                weekday = "Martes";
            } else if (wday == 3){

                weekday = "Miércoles";
            } else if (wday == 4){

                weekday = "Jueves";

            } else if (wday == 5){

                weekday = "Viernes";

            } else if (wday == 6){

                weekday = "Sábado";

            } else if (wday == 7){

                weekday = "Domingo";

            }

            if (fmonth == 1) {

                month = "Enero";
            } else if (fmonth == 2) {

                month = "Febrero";
            } else if (fmonth == 3) {

                month = "Marzo";
            } else if (fmonth == 4) {

                month = "Abril";
            } else if (fmonth == 5) {

                month = "Mayo";
            } else if (fmonth == 6) {

                month = "Junio";
            } else if (fmonth == 7) {

                month = "Julio";
            } else if (fmonth == 8) {

                month = "Agosto";
            } else if (fmonth == 9) {

                month = "Septiembre";
            } else if (fmonth == 10) {

                month = "Octubre";
            } else if (fmonth == 11) {

                month = "Noviembre";
            } else if (fmonth == 12) {

                month = "Diciembre";
            }

            return weekday + " " + day +" de " + month;
        }
     

    Attached Files:

    #18 SebazCRC, Aug 14, 2019
    Last edited by a moderator: Aug 15, 2019
  17. SebazCRC, you should probably learn java. Spigot is just an API, you can use other java methods and other java classes. Calendar being one of them.
     
    • Agree Agree x 1
  18. Ikr, but calendar returns me only one date and hour it doesnt update, can you help me please?