[solved] Plugin Help

Discussion in 'Spigot Plugin Development' started by dyenxunit, May 22, 2015.

  1. What i am trying to do is convert seconds to minutes but it isnt working with something like player.getRemainingTime because the formate that i have setup is secToMin(int) and i want to add something like player.getRemainingTime can someone help me please.

    Code (Text):

    ERROR:404 Code not found
    #1 dyenxunit, May 22, 2015
    Last edited: May 22, 2015
  2. Try using String.format().

    EDIT: String.format("%d:%02d", seconds / 60, seconds % 60);
    #2 Jesseee, May 22, 2015
    Last edited: May 22, 2015
  3. How would i use this String.format thing sorry i am still a new to the java lan
  4. Code (Text):

    // Formats seconds into an MM:SS format.
    String.format("%d:%02d", seconds / 60, seconds % 60);
    tl;dr each "%" corresponds to a variable (seconds / 60, seconds % 60 in this case). The "d, and 02d" corresponds to a formatting type. You can find a full list, as well as a much better tutorial here.
  5. Is their an easier way because what i am trying to do is this: secToMin(player.getTimeRemaining) which doesnt work because it isnt an int i was wondering if there was some way for me to create it so that i can do this: secToMin(player.getTimeRemaining) to get the remaining time of the player which is converted from seconds to minutes
  6. You can convert it to an int.

    Casting is used to convert primitives to different types, or an object to its super (or sub) class.
    Note, casting can and will cause data to be truncated.

    ex 1. In this case, the class Dog is converted into the subclass "RedDog".
    Code (Text):

    Dog dog = new Dog("woof");
    RedDog redDog = (RedDog) dog;
    ex 2. This will print "The number is: 3!" Note how when the double is converted into an int, it loses the ".58385"
    Code (Text):

    double number1 = 3.58385;
    int number2 = (int) number1;
    System.out.println("The number is: " + number2 + "!");
    P.S. Copy the String.format() code I gave you earlier in the thread. It does exactly what you want.
    #6 Jesseee, May 22, 2015
    Last edited: May 22, 2015
  7. Thx man i figured it all out :D
  8. It may surprise you to hear that casting does in fact not convert an object into a new object, and that in your code snippet - given the provided details - the cast is completely redundant.
  9. I understand the cast was redundant, I just wanted to make a point.