Programming Minecraft plugin, how do I have a player perform an action only once a day?

Ka
- in Plugins
3

Does anyone happen to know how I can have a player execute a command only once a day?

Greeting, can

Va

I would have two ideas:

Database variant

You save this in a database table that contains whether a player has already executed a command. For example:

player | command | last_executed
pattern12 | home | 21-04-2020 20:18:32

Then you could compare the time from the last_executed column with the current time. If the player has never executed a command, you create the database entry (you must of course check with an SQL query).

YML variant

You could also do the same with a config file called exec_commands.yml for example.

In the Command Executor you then call a method that checks whether the player is already saved in the file. With a scheduled task, you could delete the file once a day at exactly 23:59:59.

Optimally - if you program one on a Communits project - the player has the possibility to choose between one of the two possibilities.

Ka

First of all thanks for the quick answer, I'm currently in the process of programming a plugin for my community project, with which you can collect your wages with / wages. I only had one problem: How do I have the config reset at 23:59:59?

Va

That would be possible with a cron job. First of all, I would first implement an admin command with which this can be done manually.

If the functionality is there, I would like to see that I can call it up using a cron job. The server then runs a script, which in turn deletes the YML file.