Getting Player's Ptime

Discussion in 'Plugin Development' started by Kevinzuman22, Dec 22, 2015.

Thread Status:
Not open for further replies.
  1. I've made a plugin that shows the time of the server and from real timezones on a sign. But I've tried several times to also make it possible to let it show a player's ptime. Someone told me I could do that by getting the player's geolocation, but I'm not really familiar with geolocations. Could someone please help me?

    Here's for an example the class for the server's time clock:

    Code:
    package net.Greenadine.ClockSign.Clocks;
    
    import java.util.Date;
    import java.util.GregorianCalendar;
    
    import org.bukkit.block.Block;
    import org.bukkit.block.Sign;
    
    public class GameClock extends Clock {
    
        public GameClock(Block signBlock) {
            super(signBlock);
        }
    
        public void update() {
            if (!isValid())
                return;
    
            Sign s = sign();
    
            s.setLine(0, "");
            if (!m_label.isEmpty()) {
                s.setLine(1, m_label);
            } else {
                s.setLine(1, "Time");
            }
            s.setLine(2, m_formatter.format(getGameTime()));
            s.setLine(3, "");
    
            s.update();
        }
    
        public Date getGameTime() {
            int hours = (int) ((m_signBlock.getWorld().getTime() / 1000 + 6) % 24); // 0
                                                                                    // time
                                                                                    // is
                                                                                    // 6am
            int minutes = (int) (60 * (m_signBlock.getWorld().getTime() % 1000) / 1000);
    
            GregorianCalendar cal = new GregorianCalendar(4012, 6, 11, hours,
                    minutes, 0); // An arbitrary date
    
            return cal.getTime();
        }
    
    }
    
     
  2. Offline

    Zombie_Striker

  3. @Kevinzuman22 Do you mean play time ? Or what do you mean with ptime ?
     
  4. With ptime I mean what Essentials also manipulates with /ptime.
     
  5. Offline

    Xerox262

    Last edited: Dec 22, 2015
  6. Yep, that's why I asked, wasn't sure what you referred to :) since you said a player's ptime and not a players time
    Remember to mark as solved, and next time try check https://jd.bukkit.org/org/bukkit/entity/Player.html
    Edit: Oh, thought it was OK replying xD
     
  7. @Xerox262 I have used that, and now I got this as my PlayerTimeClock.java class:

    Code:
    package com.greenadine.clocksign.clocks;
    
    import java.util.Date;
    import java.util.GregorianCalendar;
    
    import org.bukkit.block.Block;
    import org.bukkit.block.Sign;
    
    public class PlayerTimeClock extends Clock {
    
        public PlayerTimeClock(Block signBlock) {
            super(signBlock);
        }
     
        public void update() {
            if (!isValid()) return;
         
            Sign s = sign();
         
            s.setLine(0, "");
            if (!m_label.isEmpty()) {
                s.setLine(1, m_label);
            } else {
                s.setLine(1, "Time");
            }
            s.setLine(2, m_formatter.format(getPlayerTime()));
            s.setLine(3, "");
         
            s.update();
        }
     
        @SuppressWarnings("deprecation")
        public Date getPlayerTime() {
            int hours = (int)((getPlayerTime().getHours() / 1000 + 6 ) % 24);
            int minutes = (int) (60 * (getPlayerTime().getMinutes() % 1000) / 1000);
         
            GregorianCalendar cal = new GregorianCalendar(4012, 6, 11, hours, minutes, 0); // An arbitrary date
         
            return cal.getTime();
        }
     
    }
    Now, to place one of those clocks, I have to place a sign with "[playertimeclock]" as the first line. But as soon as I do that, I get tons of errors saying:
    [15:08:19 WARN] TimeClock.java:34)
    at com.greenadine.clocksign.clocks.PlayerTimeClock.getPlayerTime(PlayerTimeClock.java:34)

    And that over and over again. And when I remove it, the errors stop. Any idea on how to use getPlayerTime properly?

    And also, how could I make the sign show the player's time for every single player differently. As in that the sign displays a different time for me compared to another player. Sorry, I still am kind of new to all of this.
     
    Last edited: Dec 23, 2015
  8. Offline

    Xerox262

    For the sign different for each player you have to use sign packets.

    And what kind of error is that and what is line 34? (AKA Post full error)

    Nevermind, StacktraceOverflow. You have to do player.getPlayerTime() to get the player's time in ticks. You cannot call your method inside itself or it will throw that error.


    Code:
    public Date getPlayerTime() {
            int hours = (int)((getPlayerTime().getHours() / 1000 + 6 ) % 24);
    What you told this to do is to call itself when it starts. Why are you doing it like that?
     
Thread Status:
Not open for further replies.

Share This Page