Move away from System.currentTimeMillis to System.nanoTime (more accurate, less costly)
This commit is contained in:
parent
997e981f3e
commit
22337f0bbc
|
@ -46,7 +46,7 @@ public class CommandRegenEnergyValues extends CommandBase {
|
||||||
if (requesterMap.containsKey(commandSenderUUID)) {
|
if (requesterMap.containsKey(commandSenderUUID)) {
|
||||||
|
|
||||||
// TODO Switch to nanoTime from currentTimeMillis
|
// 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)) {
|
if (timeDifference >= (ConfigurationHandler.Settings.serverSyncThreshold * 1000)) {
|
||||||
requesterMap.remove(commandSenderUUID);
|
requesterMap.remove(commandSenderUUID);
|
||||||
|
@ -57,7 +57,7 @@ public class CommandRegenEnergyValues extends CommandBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
requesterMap.put(commandSenderUUID, System.currentTimeMillis());
|
requesterMap.put(commandSenderUUID, System.nanoTime() / 100000);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldRegen) {
|
if (shouldRegen) {
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class CommandSyncEnergyValues extends CommandBase
|
||||||
if (requesterMap.containsKey(commandSenderUUID)) {
|
if (requesterMap.containsKey(commandSenderUUID)) {
|
||||||
|
|
||||||
// TODO Switch to nanoTime from currentTimeMillis
|
// 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)) {
|
if (timeDifference >= (ConfigurationHandler.Settings.serverSyncThreshold * 1000)) {
|
||||||
requesterMap.remove(commandSenderUUID);
|
requesterMap.remove(commandSenderUUID);
|
||||||
|
@ -57,7 +57,7 @@ public class CommandSyncEnergyValues extends CommandBase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
requesterMap.put(commandSenderUUID, System.currentTimeMillis());
|
requesterMap.put(commandSenderUUID, System.nanoTime() / 100000);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldSync) {
|
if (shouldSync) {
|
||||||
|
|
Loading…
Reference in New Issue