Fix missing static imports of TimeUnit

This commit is contained in:
P0nk
2021-09-10 19:18:20 +02:00
parent cdc17ef3dd
commit 8b60684103
10 changed files with 40 additions and 28 deletions

View File

@@ -43,7 +43,8 @@ import java.sql.*;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import static java.util.concurrent.TimeUnit.DAYS;
/**
* @author RonanLana - synchronization of Fredrick modules and operation results
@@ -81,7 +82,7 @@ public class FredrickProcessor {
}
public static int timestampElapsedDays(Timestamp then, long timeNow) {
return (int) ((timeNow - then.getTime()) / TimeUnit.DAYS.toMillis(1));
return (int) ((timeNow - then.getTime()) / DAYS.toMillis(1));
}
private static String fredrickReminderMessage(int daynotes) {

View File

@@ -63,6 +63,7 @@ public final class ItemRewardHandler extends AbstractPacketHandler {
if (ItemConstants.getInventoryType(reward.itemid) == InventoryType.EQUIP) {
final Item item = ii.getEquipById(reward.itemid);
if (reward.period != -1) {
// TODO is this a bug, meant to be 60 * 60 * 1000?
item.setExpiration(currentServerTime() + reward.period * 60 * 60 * 10);
}
InventoryManipulator.addFromDrop(c, item, false);

View File

@@ -3,7 +3,8 @@ package net.server.coordinator.session;
import net.server.Server;
import java.time.Instant;
import java.util.concurrent.TimeUnit;
import static java.util.concurrent.TimeUnit.DAYS;
record HostHwid(Hwid hwid, Instant expiry) {
static HostHwid createWithDefaultExpiry(Hwid hwid) {
@@ -11,6 +12,6 @@ record HostHwid(Hwid hwid, Instant expiry) {
}
private static Instant getDefaultExpiry() {
return Instant.ofEpochMilli(Server.getInstance().getCurrentTime() + TimeUnit.DAYS.toMillis(7));
return Instant.ofEpochMilli(Server.getInstance().getCurrentTime() + DAYS.toMillis(7));
}
}

View File

@@ -3,7 +3,9 @@ package net.server.coordinator.session;
import net.server.Server;
import java.time.Instant;
import java.util.concurrent.TimeUnit;
import static java.util.concurrent.TimeUnit.DAYS;
import static java.util.concurrent.TimeUnit.HOURS;
public class HwidAssociationExpiry {
public static Instant getHwidAccountExpiry(int relevance) {
@@ -15,9 +17,9 @@ public class HwidAssociationExpiry {
final long baseHours = switch (degree) {
case 0 -> 2;
case 1 -> TimeUnit.DAYS.toHours(1);
case 2 -> TimeUnit.DAYS.toHours(7);
default -> TimeUnit.DAYS.toHours(70);
case 1 -> DAYS.toHours(1);
case 2 -> DAYS.toHours(7);
default -> DAYS.toHours(70);
};
int subdegreeTime = (degree * 3) + 1;
@@ -25,7 +27,7 @@ public class HwidAssociationExpiry {
subdegreeTime = 10;
}
return TimeUnit.HOURS.toMillis(baseHours + subdegreeTime);
return HOURS.toMillis(baseHours + subdegreeTime);
}
private static int getHwidExpirationDegree(int relevance) {

View File

@@ -54,7 +54,8 @@ import tools.Pair;
import java.awt.*;
import java.util.List;
import java.util.*;
import java.util.concurrent.TimeUnit;
import static java.util.concurrent.TimeUnit.DAYS;
public class AbstractPlayerInteraction {
@@ -503,7 +504,7 @@ public class AbstractPlayerInteraction {
Pet evolved = null;
Pet target;
long period = TimeUnit.DAYS.toMillis(90); //refreshes expiration date: 90 days
long period = DAYS.toMillis(90); //refreshes expiration date: 90 days
target = getPlayer().getPet(slot);

View File

@@ -48,10 +48,10 @@ import javax.script.Invocable;
import javax.script.ScriptException;
import java.util.*;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
//import jdk.nashorn.api.scripting.ScriptUtils;
@@ -392,7 +392,7 @@ public class EventManager {
}
try {
if (!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, TimeUnit.MILLISECONDS)) {
if (!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, MILLISECONDS)) {
playerPermit.add(leader.getId());
startLock.lock();
@@ -464,7 +464,7 @@ public class EventManager {
}
try {
if (!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, TimeUnit.MILLISECONDS)) {
if (!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, MILLISECONDS)) {
playerPermit.add(leader.getId());
startLock.lock();
@@ -536,7 +536,7 @@ public class EventManager {
}
try {
if (!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, TimeUnit.MILLISECONDS)) {
if (!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, MILLISECONDS)) {
playerPermit.add(leader.getId());
startLock.lock();
@@ -608,7 +608,7 @@ public class EventManager {
}
try {
if (!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, TimeUnit.MILLISECONDS)) {
if (!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, MILLISECONDS)) {
playerPermit.add(leader.getId());
startLock.lock();
@@ -684,7 +684,7 @@ public class EventManager {
}
try {
if (!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, TimeUnit.MILLISECONDS)) {
if (!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, MILLISECONDS)) {
playerPermit.add(leader.getId());
startLock.lock();

View File

@@ -21,6 +21,9 @@ package server;
import java.util.concurrent.*;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
/**
* @author Ronan
*/
@@ -53,13 +56,13 @@ public class ThreadManager {
RejectedExecutionHandler reh = new RejectedExecutionHandlerImpl();
ThreadFactory tf = Executors.defaultThreadFactory();
tpe = new ThreadPoolExecutor(20, 1000, 77, TimeUnit.SECONDS, new ArrayBlockingQueue<>(50), tf, reh);
tpe = new ThreadPoolExecutor(20, 1000, 77, SECONDS, new ArrayBlockingQueue<>(50), tf, reh);
}
public void stop() {
tpe.shutdown();
try {
tpe.awaitTermination(5, TimeUnit.MINUTES);
tpe.awaitTermination(5, MINUTES);
} catch (InterruptedException ie) {
}
}

View File

@@ -30,9 +30,11 @@ import java.lang.management.ManagementFactory;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.MINUTES;
public class TimerManager implements TimerManagerMBean {
private static final TimerManager instance = new TimerManager();
@@ -69,7 +71,7 @@ public class TimerManager implements TimerManagerMBean {
stpe.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
stpe.setRemoveOnCancelPolicy(true);
stpe.setKeepAliveTime(5, TimeUnit.MINUTES);
stpe.setKeepAliveTime(5, MINUTES);
stpe.allowCoreThreadTimeOut(true);
ses = stpe;
@@ -87,15 +89,15 @@ public class TimerManager implements TimerManagerMBean {
}
public ScheduledFuture<?> register(Runnable r, long repeatTime, long delay) {
return ses.scheduleAtFixedRate(new LoggingSaveRunnable(r), delay, repeatTime, TimeUnit.MILLISECONDS);
return ses.scheduleAtFixedRate(new LoggingSaveRunnable(r), delay, repeatTime, MILLISECONDS);
}
public ScheduledFuture<?> register(Runnable r, long repeatTime) {
return ses.scheduleAtFixedRate(new LoggingSaveRunnable(r), 0, repeatTime, TimeUnit.MILLISECONDS);
return ses.scheduleAtFixedRate(new LoggingSaveRunnable(r), 0, repeatTime, MILLISECONDS);
}
public ScheduledFuture<?> schedule(Runnable r, long delay) {
return ses.schedule(new LoggingSaveRunnable(r), delay, TimeUnit.MILLISECONDS);
return ses.schedule(new LoggingSaveRunnable(r), delay, MILLISECONDS);
}
public ScheduledFuture<?> scheduleAtTimestamp(Runnable r, long timestamp) {

View File

@@ -33,9 +33,9 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
/**
* @author Ronan
@@ -65,7 +65,7 @@ public class AriantColiseum {
map.resetFully();
long pqTimer = MINUTES.toMillis(10);
long pqTimerBoard = MINUTES.toMillis(9) + TimeUnit.SECONDS.toMillis(50);
long pqTimerBoard = MINUTES.toMillis(9) + SECONDS.toMillis(50);
List<Character> players = exped.getActiveMembers();
score = new HashMap<>();

View File

@@ -9,7 +9,8 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import static java.util.concurrent.TimeUnit.HOURS;
/**
* @author RonanLana
@@ -238,7 +239,7 @@ public class CodeCouponGenerator {
generatedKeys = null;
PreparedStatement ps = con.prepareStatement("INSERT IGNORE INTO `nxcode` (`code`, `expiration`) VALUES (?, ?)", Statement.RETURN_GENERATED_KEYS);
ps.setLong(2, currentTime + TimeUnit.HOURS.toMillis(recipe.duration));
ps.setLong(2, currentTime + HOURS.toMillis(recipe.duration));
for (int i = 0; i < recipe.quantity; i++) {
ps.setString(1, generateCouponCode());