Page 1 of 1

Bukkit Plugins: Auto Ranking System

Posted: Fri May 25, 2012 4:46 pm
by Samuel98
Content Deleted

Re: Bukkit Plugins: Auto Ranking System

Posted: Fri May 25, 2012 5:23 pm
by Temor
I'm not familiar with Java or Bukkit at all, but the principle of this seems really easy.
Set a timestamp when the user first joins the server, and then create a variable with the value of the first timestamp + 30 minutes.
Then check to see if current timestamp > original timestamp+30 minutes every minute or so. Whenever current timestamp is greater than timestamp+30 minutes, upgrade user rank.

And for the /timeremaining command, just check to see if current timestamp > timestamp+30 minutes. If not, show timestamp+30 minutes minus current timestamp.

Just brainstorming here, but in my mind, this would work :)

Re: Bukkit Plugins: Auto Ranking System

Posted: Fri May 25, 2012 6:07 pm
by Samuel98
Content Deleted

Re: Bukkit Plugins: Auto Ranking System

Posted: Fri May 25, 2012 6:14 pm
by Samuel98
Content Deleted

Re: Bukkit Plugins: Auto Ranking System

Posted: Fri May 25, 2012 7:22 pm
by Temor
I'm not entirely sure how java or bukkit works but I guess there's some way to run code every game tick. Figure out how long one of those ticks are and then figure out how many ticks there are in a minute and create a loop.
I'll try to write an example. Keep in mind I have no idea what the proper Java syntax is so don't copy paste my code as it will not work :P
i = 1
//Run loop while i is less than or equal to the number of ticks in one minute.
while i<=xTicks {
//Add one each time the loop runs i.e each game tick.
i++
// if i is greater than the or equal to the number of game ticks in one minute, reset i back to 0 and check the timestamp again.
if i>=xTicks {
 i = 0
//if current time is greater than the original timestamp + 30 minutes, upgrade user.
if currentTimestamp >= timestamp+30minutes{ 
upgrade user
  } // end if

                  } //end if

}// end while loop

I hope you got the idea :P Sorry if I confused you. I really know nothing about java.

Re: Bukkit Plugins: Auto Ranking System

Posted: Sat May 26, 2012 11:17 pm
by jacek
SamzRulez wrote:Question how can I make it check every minute?
Depends how precise you wan tot be. If it doesn’t have to be exactly every 60 seconds then you can use the BukkitScheduler.

so in your main plugin class you can set up a repeating task that is called every 60 seconds like this
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new YourTask(this), 0L, 1200L);
The 1200 here comes from 60 * 20 because there are 20 ticks in each second.

The class YourTask() is one which implements Runnable and has a run() method, that method will be called roughly every 60 seconds. I say roughly because the tick rate is not a steady 20 ticks/second as we assume here.

If you want it to be exactly on the 60 second mark you will have to do somethign a bit more like Temor said above, using the system time.