Hi , I would like the playing time of each player to be saved in a yml file and display it in String format, if I set the variables in Long it tells me that I cannot cast them in Int and if I put them in Int he tells me I can't cast them long. the RunBukkit class called every 5 seconds: Code (Java): public class PlayedTime extends BukkitRunnable { private FileConfiguration config; private Main main; public PlayedTime(FileConfiguration config, Main main) { this.config = config; this.main = main; } @Override public void run() { for(Player p : Bukkit.getOnlinePlayers()) { if(config.get("played-time." + p.getUniqueId()) == null) { config.set("played-time." + p.getUniqueId(), 0); main.saveConfig(); } int time = (int) config.get("played-time." + p.getUniqueId()); time += 5; config.set("played-time." + p.getUniqueId(), time); } main.saveConfig(); } } I use this to get the time: Code (Text): long time = (long) config.get("played-time." + player.getUniqueId()); playerHeadLore.add("§4Temps de jeu: §f" + convertToDateFormat(time)); The convert to string method: Code (Text): private String convertToDateFormat(long time) { long seconds = time; long minutes = 0; long hours = 0; long days = 0; if(seconds > 60) { minutes = (long) seconds / 60; seconds = (long) seconds % 60; if(minutes > 60) { hours = (long) minutes / 60; minutes = (long) minutes % 60; if (hours > 24) { days = (long) hours / 24; hours = hours % 60; } } } return Long.toString(days) + " Jours " + Long.toString(hours) + " Heures " + Long.toString(minutes) + " Minutes " + Long.toString(seconds) + " Secondes"; }
You can always cast an int to long and most of the time a long to int, where exactly do you have problems with that and what exactly is your problem? Also, this: Code (Java): if(config.get("played-time." + p.getUniqueId()) == null) { config.set("played-time." + p.getUniqueId(), 0); main.saveConfig(); } int time = (int) config.get("played-time." + p.getUniqueId()); can be simplified to this: Code (Text): int time = config.get("played_time" + p.getUniqueId(), 0); Also, there is a util-class called DateTimeFormatter that does exactly your conversion
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Statistic.html#PLAY_ONE_MINUTE records how long someone has played in ticks, Player#getStatistic