Use TimeUnit for time calculations

This commit is contained in:
P0nk
2021-09-10 18:56:03 +02:00
parent d52aedac4f
commit cdc17ef3dd
49 changed files with 268 additions and 161 deletions

View File

@@ -43,6 +43,8 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ScheduledFuture;
import static java.util.concurrent.TimeUnit.MINUTES;
/**
* @author Alan (SharpAceX)
*/
@@ -116,7 +118,7 @@ public class Expedition {
public void beginRegistration() {
registering = true;
leader.sendPacket(PacketCreator.getClock(type.getRegistrationTime() * 60));
leader.sendPacket(PacketCreator.getClock((int) MINUTES.toSeconds(type.getRegistrationMinutes())));
if (!silent) {
startMap.broadcastMessage(leader, PacketCreator.serverNotice(6, "[Expedition] " + leader.getName() + " has been declared the expedition captain. Please register for the expedition."), false);
leader.sendPacket(PacketCreator.serverNotice(6, "[Expedition] You have become the expedition captain. Gather enough people for your team then talk to the NPC to start."));
@@ -126,7 +128,7 @@ public class Expedition {
private void scheduleRegistrationEnd() {
final Expedition exped = this;
startTime = System.currentTimeMillis() + type.getRegistrationTime() * 60 * 1000;
startTime = System.currentTimeMillis() + MINUTES.toMillis(type.getRegistrationMinutes());
schedule = TimerManager.getInstance().schedule(() -> {
if (registering) {
@@ -137,7 +139,7 @@ public class Expedition {
dispose(false);
}
}, type.getRegistrationTime() * 60 * 1000);
}, MINUTES.toMillis(type.getRegistrationMinutes()));
}
public void dispose(boolean log) {

View File

@@ -28,6 +28,9 @@ import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;
import static java.util.concurrent.TimeUnit.DAYS;
import static java.util.concurrent.TimeUnit.HOURS;
/**
* @author Conrad
* @author Ronan
@@ -97,8 +100,8 @@ public class ExpeditionBossLog {
Calendar now = Calendar.getInstance();
long weekLength = 7 * 24 * 60 * 60 * 1000;
long halfDayLength = 12 * 60 * 60 * 1000;
long weekLength = DAYS.toMillis(7);
long halfDayLength = HOURS.toMillis(12);
long deltaTime = now.getTime().getTime() - thursday.getTime().getTime(); // 2x time: get Date into millis
deltaTime += halfDayLength;

View File

@@ -47,14 +47,14 @@ public enum ExpeditionType {
private final int maxSize;
private final int minLevel;
private final int maxLevel;
private final int registrationTime;
private final int registrationMinutes;
ExpeditionType(int minSize, int maxSize, int minLevel, int maxLevel, int minutes) {
this.minSize = minSize;
this.maxSize = maxSize;
this.minLevel = minLevel;
this.maxLevel = maxLevel;
this.registrationTime = minutes;
this.registrationMinutes = minutes;
}
public int getMinSize() {
@@ -73,7 +73,7 @@ public enum ExpeditionType {
return maxLevel;
}
public int getRegistrationTime() {
return registrationTime;
public int getRegistrationMinutes() {
return registrationMinutes;
}
}