Move away from System.currentTimeMillis to System.nanoTime (more accurate, less costly)

This commit is contained in:
Pahimar 2016-05-26 16:03:40 -04:00
parent 997e981f3e
commit 22337f0bbc
2 changed files with 4 additions and 4 deletions

View File

@ -46,7 +46,7 @@ public class CommandRegenEnergyValues extends CommandBase {
if (requesterMap.containsKey(commandSenderUUID)) {
// TODO Switch to nanoTime from currentTimeMillis
long timeDifference = System.currentTimeMillis() - requesterMap.get(commandSenderUUID).longValue();
long timeDifference = (System.nanoTime() - requesterMap.get(commandSenderUUID).longValue()) / 100000;
if (timeDifference >= (ConfigurationHandler.Settings.serverSyncThreshold * 1000)) {
requesterMap.remove(commandSenderUUID);
@ -57,7 +57,7 @@ public class CommandRegenEnergyValues extends CommandBase {
}
}
else {
requesterMap.put(commandSenderUUID, System.currentTimeMillis());
requesterMap.put(commandSenderUUID, System.nanoTime() / 100000);
}
if (shouldRegen) {

View File

@ -46,7 +46,7 @@ public class CommandSyncEnergyValues extends CommandBase
if (requesterMap.containsKey(commandSenderUUID)) {
// TODO Switch to nanoTime from currentTimeMillis
long timeDifference = System.currentTimeMillis() - requesterMap.get(commandSenderUUID).longValue();
long timeDifference = (System.nanoTime() - requesterMap.get(commandSenderUUID).longValue()) / 100000;
if (timeDifference >= (ConfigurationHandler.Settings.serverSyncThreshold * 1000)) {
requesterMap.remove(commandSenderUUID);
@ -57,7 +57,7 @@ public class CommandSyncEnergyValues extends CommandBase
}
}
else {
requesterMap.put(commandSenderUUID, System.currentTimeMillis());
requesterMap.put(commandSenderUUID, System.nanoTime() / 100000);
}
if (shouldSync) {