Skip to content

Commit

Permalink
Switch from nanoTime to millis
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerS1066 committed Jun 4, 2024
1 parent f15cb63 commit e16281a
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private static void loadConfig(FileConfiguration config) {
Config.Locale = config.getString("Locale", "en");
I18nSupport.init();
Config.RepairTicksPerBlock = config.getInt("RepairTicksPerBlock", 0);
Config.RepairMaxTickTime = config.getLong("RepairMaxTickTime", 5000000);
Config.RepairMaxTickTime = config.getLong("RepairMaxTickTime", 5000000) / 1000000;
Config.RepairMaxBlocksPerTick = config.getInt("RepairMaxBlocksPerTick", 2);
Config.RepairMoneyPerBlock = config.getDouble("RepairMoneyPerBlock", 0.0);
Config.RepairMaxPercent = config.getDouble("RepairMaxPercent", 50);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public class RepairManager extends BukkitRunnable {

@Override
public void run() {
long start = System.nanoTime();
long start = System.currentTimeMillis();

Set<Repair> completed = new HashSet<>();
Set<Repair> executed = new HashSet<>();
while (System.nanoTime() - start < Config.RepairMaxTickTime) {
while (System.currentTimeMillis() - start < Config.RepairMaxTickTime) {
Repair repair = repairs.peek();
if (repair == null)
break; // No repairs, jump out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Config {
public static String Locale = "en";

public static int RepairTicksPerBlock = 0;
public static long RepairMaxTickTime = 5000000;
public static long RepairMaxTickTime = 5;
public static int RepairMaxBlocksPerTick = 2;
public static double RepairMoneyPerBlock = 0.0;
public static double RepairMaxPercent = 50.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public ProtoRepair(UUID playerUUID, String name, RepairQueue queue, RepairCounte
this.materials = materials;
this.origin = origin;
this.damagedBlockCount = damagedBlockCount;
calculationTime = System.nanoTime();
calculationTime = System.currentTimeMillis();
valid = true;
}

Expand All @@ -71,7 +71,7 @@ public MovecraftLocation getOrigin() {
}

public boolean isInvalid() {
return (System.nanoTime() - calculationTime > 5000000000L) || !valid; // 5 seconds
return (System.currentTimeMillis() - calculationTime > 5000) || !valid; // 5 seconds
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public Repair(UUID playerUUID, String name, double cost, RepairQueue queue) {
this.cost = cost;
this.queue = queue;
this.size = queue.size();
lastExecution = System.nanoTime();
lastExecution = System.currentTimeMillis();
start = System.currentTimeMillis();
}

Expand Down Expand Up @@ -53,7 +53,7 @@ public int remaining() {
}

public boolean run() {
double elapsedTicks = (System.nanoTime() - lastExecution) * 20.0 / 1000000000;
double elapsedTicks = (System.currentTimeMillis() - lastExecution) * 20.0 / 1000;
int placedBlocks = 0;

while (elapsedTicks > Config.RepairTicksPerBlock && placedBlocks <= Config.RepairMaxBlocksPerTick) {
Expand All @@ -67,7 +67,7 @@ public boolean run() {
}

if (placedBlocks > 0) {
lastExecution = System.nanoTime();
lastExecution = System.currentTimeMillis();
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public class WarfareUtils extends BukkitRunnable {

@Override
public void run() {
long start = System.nanoTime();
long start = System.currentTimeMillis();

while (System.nanoTime() - start < Config.RepairMaxTickTime && !tasks.isEmpty()) {
while (System.currentTimeMillis() - start < Config.RepairMaxTickTime && !tasks.isEmpty()) {
tasks.poll().execute();
}
}
Expand Down

0 comments on commit e16281a

Please sign in to comment.