This repository has been archived on 2026-08-17. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
PlaytimeRewards/src/main/java/dev/astridlabs/playtimerewardsplus/MasterClock.java
T
2020-04-09 14:40:43 -05:00

53 lines
1.5 KiB
Java

package dev.astridlabs.playtimerewardsplus;
import dev.astridlabs.playtimerewardsplus.DataTypes.PlayerData;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.logging.Level;
public class MasterClock extends BukkitRunnable {
private final Plugin plugin;
private Integer clockTicks = 0;
public MasterClock(Plugin plugin){
this.plugin = plugin;
}
@Override
public void run() {
clockTicks++;
if((clockTicks/72000) > 1){
this.plugin.config.savePlayers();
this.plugin.getServer().getLogger().log(Level.INFO, "Hourly save completed! Data loss avoided");
}
// What you want to schedule goes here
for(Player p : plugin.getServer().getOnlinePlayers()) {
updatePlaytime(p);
updatePlayerLocations(p);
}
}
public void updatePlaytime(Player pl){
PlayerData player = plugin.db.getPlayer(pl.getUniqueId());
Integer playtime = player.getPlaytime();
Integer newplaytime = playtime+1;
player.setPlaytime(newplaytime);
}
public void updatePlayerLocations(Player pl){
PlayerData player = plugin.db.getPlayer(pl.getUniqueId());
if(player.getCurrentLocation() == null){
player.setCurrentLocation(pl.getLocation());
}else{
player.setLastLocation(player.getCurrentLocation());
player.setCurrentLocation(pl.getLocation());
}
}
}