#Hardcore Timer

1 messages · Page 1 of 1 (latest)

lapis pike
#

Ok let me rephrase it

little tendon
#

yep^^

#

explain again from the beginning pls

mild carbon
#

not granted

lapis pike
#

I have a server, I coded it so when a player dies they turn into spectator mode

#

Now another player can either redeem their totem at the hub to respawn them or they respawn automatically after 24 hours

#

I already did the totem part, I just need some help knowing how I can check and run something after 24 hours

#

If the player is offline or online

little tendon
#

to respawn them automatically after 24 hours, I'd just use a scheduled timer that runs every second and checks if any "ban" has expired

lapis pike
#

Would that cause performance?

little tendon
#

no

#

it's no problem. you're simply comparing a few numbers every second

#

you will not notice ANY performance problems

delicate prairie
#

every few seconds or minute would be fine. You don;t need such accuracy

lapis pike
#

But how would I have a timer for each player

#

Because they don't all get the same timer

delicate prairie
#

you only use one timer

mild carbon
#

you should make sure to cache it instead of rereading the file every second

little tendon
#

where Long is the timestamp when the ban expires

lapis pike
#

Ok thank you all

little tendon
lapis pike
#

So with a HashMap

little tendon
#

load the file on startup and save it on shutdown

lapis pike
#

So I also have to create a file for the players?

delicate prairie
#

only 1

lapis pike
#

Ye

#

A json file?

delicate prairie
#

stored player UUID and a Long for the time

#

any file

lapis pike
#

kk

delicate prairie
#

Spigot has built in support for YAML and Json

lapis pike
#

What is "YAML"?

delicate prairie
#

YAML would be easier to implement as its in teh API, Json is shaded in Spigot but no API

#

YAML is the language used for Spigots configs and plugin.yml files

lapis pike
#

Ok so everytime a player dies, I add them to my file and cache from the file to check if their timer is up every minute or so

delicate prairie
#

FileConfiguration

little tendon
#

YAML is easier to use within spigot. I'd simply use a YamlConfiguration object

#

of course JSON is fine too

lapis pike
#

Then when I run the "respawn" event

#

I get rid of the players UUID and Long

little tendon
#

but if you never used neither of them, I'd start with YAML

lapis pike
#

I know how to use JSON

#

But I think I prefer YAML from what you guys are saying

delicate prairie
delicate prairie
#

Is your respawn event somethign you manually trigger?

lapis pike
#

I can do that

#

I can trigger it when the timer is up

delicate prairie
#

What I'm sayign is, after the 24 hours are up for a player, shoudl they automatically respawn, or are they stuck in spectator untill an event happens>?

lapis pike
#

They should automatically respawn

#

So I can run the respawn event in the part I check if their time is up

delicate prairie
#

ok, so respawn happens when their timer expires, OR they are revived, or you run a respawn for everyone?

lapis pike
#

No they respawn automatically

#

I already have a respawn event

#

Because of my totem system, when another player claims a players totem I make them respawn

#

So I think in my checking if timer is up event

#

I can run the respawn function right? @delicate prairie

delicate prairie
#

yes

#

if time has expired, remove them from the Map, save Map, respawn player

lapis pike
#

Ok thank you

little tendon
#

and pls remember: iterating over a small map (I assume that you do not have more than 10,000 players) and comparing some timestamps is really no problem at all performance-wise

#

so no problem in doing it every second or every X seconds

lapis pike
#

Ok thank you :))

little tendon
#

np!

lapis pike
#

I will check it every minute it doesn't need to be that accurate

little tendon
#

okidoki