Use TimeUnit for time calculations

This commit is contained in:
P0nk
2021-09-10 19:08:58 +02:00
parent d52aedac4f
commit cdc17ef3dd
49 changed files with 268 additions and 161 deletions
+22 -20
View File
@@ -93,6 +93,8 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static java.util.concurrent.TimeUnit.*;
public class Character extends AbstractCharacterObject { public class Character extends AbstractCharacterObject {
private static final ItemInformationProvider ii = ItemInformationProvider.getInstance(); private static final ItemInformationProvider ii = ItemInformationProvider.getInstance();
private static final String LEVEL_200 = "[Congrats] %s has reached Level %d! Congratulate %s on such an amazing achievement!"; private static final String LEVEL_200 = "[Congrats] %s has reached Level %d! Congratulate %s on such an amazing achievement!";
@@ -1255,7 +1257,7 @@ public class Character extends AbstractCharacterObject {
} }
public boolean canRecoverLastBanish() { public boolean canRecoverLastBanish() {
return System.currentTimeMillis() - this.banishTime < 5 * 60 * 1000; return System.currentTimeMillis() - this.banishTime < MINUTES.toMillis(5);
} }
public Pair<Integer, Integer> getLastBanishData() { public Pair<Integer, Integer> getLastBanishData() {
@@ -2082,7 +2084,7 @@ public class Character extends AbstractCharacterObject {
Skill battleship = SkillFactory.getSkill(Corsair.BATTLE_SHIP); Skill battleship = SkillFactory.getSkill(Corsair.BATTLE_SHIP);
int cooldown = battleship.getEffect(getSkillLevel(battleship)).getCooldown(); int cooldown = battleship.getEffect(getSkillLevel(battleship)).getCooldown();
sendPacket(PacketCreator.skillCooldown(Corsair.BATTLE_SHIP, cooldown)); sendPacket(PacketCreator.skillCooldown(Corsair.BATTLE_SHIP, cooldown));
addCooldown(Corsair.BATTLE_SHIP, Server.getInstance().getCurrentTime(), cooldown * 1000); addCooldown(Corsair.BATTLE_SHIP, Server.getInstance().getCurrentTime(), SECONDS.toMillis(cooldown));
removeCooldown(5221999); removeCooldown(5221999);
cancelEffectFromBuffStat(BuffStat.MONSTER_RIDING); cancelEffectFromBuffStat(BuffStat.MONSTER_RIDING);
} else { } else {
@@ -2369,7 +2371,7 @@ public class Character extends AbstractCharacterObject {
private static Pair<Integer, Pair<Integer, Integer>> getChairTaskIntervalRate(int maxhp, int maxmp) { private static Pair<Integer, Pair<Integer, Integer>> getChairTaskIntervalRate(int maxhp, int maxmp) {
float toHeal = Math.max(maxhp, maxmp); float toHeal = Math.max(maxhp, maxmp);
float maxDuration = YamlConfig.config.server.CHAIR_EXTRA_HEAL_MAX_DELAY * 1000; float maxDuration = SECONDS.toMillis(YamlConfig.config.server.CHAIR_EXTRA_HEAL_MAX_DELAY);
int rate = 0; int rate = 0;
int minRegen = 1, maxRegen = (256 * YamlConfig.config.server.CHAIR_EXTRA_HEAL_MULTIPLIER) - 1, midRegen = 1; int minRegen = 1, maxRegen = (256 * YamlConfig.config.server.CHAIR_EXTRA_HEAL_MULTIPLIER) - 1, midRegen = 1;
@@ -4394,7 +4396,7 @@ public class Character extends AbstractCharacterObject {
int bHealingLvl = getSkillLevel(bHealing); int bHealingLvl = getSkillLevel(bHealing);
if (bHealingLvl > 0) { if (bHealingLvl > 0) {
final StatEffect healEffect = bHealing.getEffect(bHealingLvl); final StatEffect healEffect = bHealing.getEffect(bHealingLvl);
int healInterval = healEffect.getX() * 1000; int healInterval = (int) SECONDS.toMillis(healEffect.getX());
beholderHealingSchedule = TimerManager.getInstance().register(new Runnable() { beholderHealingSchedule = TimerManager.getInstance().register(new Runnable() {
@Override @Override
public void run() { public void run() {
@@ -4412,7 +4414,7 @@ public class Character extends AbstractCharacterObject {
Skill bBuff = SkillFactory.getSkill(DarkKnight.HEX_OF_BEHOLDER); Skill bBuff = SkillFactory.getSkill(DarkKnight.HEX_OF_BEHOLDER);
if (getSkillLevel(bBuff) > 0) { if (getSkillLevel(bBuff) > 0) {
final StatEffect buffEffect = bBuff.getEffect(getSkillLevel(bBuff)); final StatEffect buffEffect = bBuff.getEffect(getSkillLevel(bBuff));
int buffInterval = buffEffect.getX() * 1000; int buffInterval = (int) SECONDS.toMillis(buffEffect.getX());
beholderBuffSchedule = TimerManager.getInstance().register(new Runnable() { beholderBuffSchedule = TimerManager.getInstance().register(new Runnable() {
@Override @Override
public void run() { public void run() {
@@ -6065,7 +6067,7 @@ public class Character extends AbstractCharacterObject {
} }
private long getNextBuybackTime() { private long getNextBuybackTime() {
return lastBuyback + YamlConfig.config.server.BUYBACK_COOLDOWN_MINUTES * 60 * 1000; return lastBuyback + MINUTES.toMillis(YamlConfig.config.server.BUYBACK_COOLDOWN_MINUTES);
} }
private boolean isBuybackInvincible() { private boolean isBuybackInvincible() {
@@ -6091,12 +6093,12 @@ public class Character extends AbstractCharacterObject {
boolean avail = true; boolean avail = true;
if (!isAlive()) { if (!isAlive()) {
long timeLapsed = timeNow - lastDeathtime; long timeLapsed = timeNow - lastDeathtime;
long timeRemaining = YamlConfig.config.server.BUYBACK_RETURN_MINUTES * 60 * 1000 - (timeLapsed + Math.max(0, getNextBuybackTime() - timeNow)); long timeRemaining = MINUTES.toMillis(YamlConfig.config.server.BUYBACK_RETURN_MINUTES) - (timeLapsed + Math.max(0, getNextBuybackTime() - timeNow));
if (timeRemaining < 1) { if (timeRemaining < 1) {
s += "Buyback #e#rUNAVAILABLE#k#n"; s += "Buyback #e#rUNAVAILABLE#k#n";
avail = false; avail = false;
} else { } else {
s += "Buyback countdown: #e#b" + getTimeRemaining(YamlConfig.config.server.BUYBACK_RETURN_MINUTES * 60 * 1000 - timeLapsed) + "#k#n"; s += "Buyback countdown: #e#b" + getTimeRemaining(MINUTES.toMillis(YamlConfig.config.server.BUYBACK_RETURN_MINUTES) - timeLapsed) + "#k#n";
} }
s += "\r\n"; s += "\r\n";
} }
@@ -6112,8 +6114,8 @@ public class Character extends AbstractCharacterObject {
} }
private static String getTimeRemaining(long timeLeft) { private static String getTimeRemaining(long timeLeft) {
int seconds = (int) Math.floor(timeLeft / 1000) % 60; int seconds = (int) Math.floor(timeLeft / SECONDS.toMillis(1)) % 60;
int minutes = (int) Math.floor(timeLeft / (1000 * 60)) % 60; int minutes = (int) Math.floor(timeLeft / MINUTES.toMillis(1)) % 60;
return (minutes > 0 ? (String.format("%02d", minutes) + " minutes, ") : "") + String.format("%02d", seconds) + " seconds"; return (minutes > 0 ? (String.format("%02d", minutes) + " minutes, ") : "") + String.format("%02d", seconds) + " seconds";
} }
@@ -6121,7 +6123,7 @@ public class Character extends AbstractCharacterObject {
public boolean couldBuyback() { // Ronan's buyback system public boolean couldBuyback() { // Ronan's buyback system
long timeNow = Server.getInstance().getCurrentTime(); long timeNow = Server.getInstance().getCurrentTime();
if (timeNow - lastDeathtime > YamlConfig.config.server.BUYBACK_RETURN_MINUTES * 60 * 1000) { if (timeNow - lastDeathtime > MINUTES.toMillis(YamlConfig.config.server.BUYBACK_RETURN_MINUTES)) {
this.dropMessage(5, "The period of time to decide has expired, therefore you are unable to buyback."); this.dropMessage(5, "The period of time to decide has expired, therefore you are unable to buyback.");
return false; return false;
} }
@@ -7247,7 +7249,7 @@ public class Character extends AbstractCharacterObject {
QuestStatus status = new QuestStatus(q, QuestStatus.Status.getById(rs.getInt("status"))); QuestStatus status = new QuestStatus(q, QuestStatus.Status.getById(rs.getInt("status")));
long cTime = rs.getLong("time"); long cTime = rs.getLong("time");
if (cTime > -1) { if (cTime > -1) {
status.setCompletionTime(cTime * 1000); status.setCompletionTime(SECONDS.toMillis(cTime));
} }
long eTime = rs.getLong("expires"); long eTime = rs.getLong("expires");
@@ -9618,7 +9620,7 @@ public class Character extends AbstractCharacterObject {
public void showUnderleveledInfo(Monster mob) { public void showUnderleveledInfo(Monster mob) {
long curTime = Server.getInstance().getCurrentTime(); long curTime = Server.getInstance().getCurrentTime();
if (nextWarningTime < curTime) { if (nextWarningTime < curTime) {
nextWarningTime = curTime + (60 * 1000); // show underlevel info again after 1 minute nextWarningTime = curTime + MINUTES.toMillis(1); // show underlevel info again after 1 minute
showHint("You have gained #rno experience#k from defeating #e#b" + mob.getName() + "#k#n (lv. #b" + mob.getLevel() + "#k)! Take note you must have around the same level as the mob to start earning EXP from it."); showHint("You have gained #rno experience#k from defeating #e#b" + mob.getName() + "#k#n (lv. #b" + mob.getLevel() + "#k)! Take note you must have around the same level as the mob to start earning EXP from it.");
} }
@@ -9627,7 +9629,7 @@ public class Character extends AbstractCharacterObject {
public void showMapOwnershipInfo(Character mapOwner) { public void showMapOwnershipInfo(Character mapOwner) {
long curTime = Server.getInstance().getCurrentTime(); long curTime = Server.getInstance().getCurrentTime();
if (nextWarningTime < curTime) { if (nextWarningTime < curTime) {
nextWarningTime = curTime + (60 * 1000); // show underlevel info again after 1 minute nextWarningTime = curTime + MINUTES.toMillis(1); // show underlevel info again after 1 minute
String medal = ""; String medal = "";
Item medalItem = mapOwner.getInventory(InventoryType.EQUIPPED).getItem((short) -49); Item medalItem = mapOwner.getInventory(InventoryType.EQUIPPED).getItem((short) -49);
@@ -9980,7 +9982,7 @@ public class Character extends AbstractCharacterObject {
public void run() { public void run() {
runQuestExpireTask(); runQuestExpireTask();
} }
}, 10 * 1000); }, SECONDS.toMillis(10));
} }
} }
} finally { } finally {
@@ -10025,7 +10027,7 @@ public class Character extends AbstractCharacterObject {
public void run() { public void run() {
runQuestExpireTask(); runQuestExpireTask();
} }
}, 10 * 1000); }, SECONDS.toMillis(10));
} }
questExpirations.put(quest, Server.getInstance().getCurrentTime() + time); questExpirations.put(quest, Server.getInstance().getCurrentTime() + time);
@@ -10035,8 +10037,8 @@ public class Character extends AbstractCharacterObject {
} }
public void questTimeLimit(final Quest quest, int seconds) { public void questTimeLimit(final Quest quest, int seconds) {
registerQuestExpire(quest, seconds * 1000); registerQuestExpire(quest, SECONDS.toMillis(seconds));
sendPacket(PacketCreator.addQuestTimeLimit(quest.getId(), seconds * 1000)); sendPacket(PacketCreator.addQuestTimeLimit(quest.getId(), (int) SECONDS.toMillis(seconds)));
} }
public void questTimeLimit2(final Quest quest, long expires) { public void questTimeLimit2(final Quest quest, long expires) {
@@ -10550,7 +10552,7 @@ public class Character extends AbstractCharacterObject {
} }
inventory = null; inventory = null;
} }
}, 5 * 60 * 1000); }, MINUTES.toMillis(5));
} }
} }
@@ -10920,7 +10922,7 @@ public class Character extends AbstractCharacterObject {
public int checkWorldTransferEligibility() { public int checkWorldTransferEligibility() {
if (getLevel() < 20) { if (getLevel() < 20) {
return 2; return 2;
} else if (getClient().getTempBanCalendar() != null && getClient().getTempBanCalendar().getTimeInMillis() + (30 * 24 * 60 * 60 * 1000) < Calendar.getInstance().getTimeInMillis()) { } else if (getClient().getTempBanCalendar() != null && getClient().getTempBanCalendar().getTimeInMillis() + (int) DAYS.toMillis(30) < Calendar.getInstance().getTimeInMillis()) {
return 3; return 3;
} else if (isMarried()) { } else if (isMarried()) {
return 4; return 4;
+4 -3
View File
@@ -75,9 +75,10 @@ import java.sql.*;
import java.util.Date; import java.util.Date;
import java.util.*; import java.util.*;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import static java.util.concurrent.TimeUnit.SECONDS;
public class Client extends ChannelInboundHandlerAdapter { public class Client extends ChannelInboundHandlerAdapter {
private static final Logger log = LoggerFactory.getLogger(Client.class); private static final Logger log = LoggerFactory.getLogger(Client.class);
@@ -1151,7 +1152,7 @@ public class Client extends ChannelInboundHandlerAdapter {
} catch (NullPointerException e) { } catch (NullPointerException e) {
e.printStackTrace(); e.printStackTrace();
} }
}, TimeUnit.SECONDS.toMillis(15)); }, SECONDS.toMillis(15));
} }
public Set<String> getMacs() { public Set<String> getMacs() {
@@ -1421,7 +1422,7 @@ public class Client extends ChannelInboundHandlerAdapter {
int targetHash = player.getTargetHpBarHash(); int targetHash = player.getTargetHpBarHash();
if (mobHash != targetHash) { if (mobHash != targetHash) {
if (timeNow - player.getTargetHpBarTime() >= 5 * 1000) { if (timeNow - player.getTargetHpBarTime() >= SECONDS.toMillis(5)) {
// is there a way to INTERRUPT this annoying thread running on the client that drops the boss bar after some time at every attack? // is there a way to INTERRUPT this annoying thread running on the client that drops the boss bar after some time at every attack?
announceDisableServerMessage(); announceDisableServerMessage();
sendPacket(packet); sendPacket(packet);
@@ -29,6 +29,9 @@ import net.server.Server;
import tools.FilePrinter; import tools.FilePrinter;
import tools.PacketCreator; import tools.PacketCreator;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
/** /**
* @author kevintjuh93 * @author kevintjuh93
*/ */
@@ -36,22 +39,22 @@ public enum AutobanFactory {
MOB_COUNT, MOB_COUNT,
GENERAL, GENERAL,
FIX_DAMAGE, FIX_DAMAGE,
DAMAGE_HACK(15, 60 * 1000), DAMAGE_HACK(15, MINUTES.toMillis(1)),
DISTANCE_HACK(10, 120 * 1000), DISTANCE_HACK(10, MINUTES.toMillis(2)),
PORTAL_DISTANCE(5, 30000), PORTAL_DISTANCE(5, SECONDS.toMillis(30)),
PACKET_EDIT, PACKET_EDIT,
ACC_HACK, ACC_HACK,
CREATION_GENERATOR, CREATION_GENERATOR,
HIGH_HP_HEALING, HIGH_HP_HEALING,
FAST_HP_HEALING(15), FAST_HP_HEALING(15),
FAST_MP_HEALING(20, 30000), FAST_MP_HEALING(20, SECONDS.toMillis(30)),
GACHA_EXP, GACHA_EXP,
TUBI(20, 15000), TUBI(20, SECONDS.toMillis(15)),
SHORT_ITEM_VAC, SHORT_ITEM_VAC,
ITEM_VAC, ITEM_VAC,
FAST_ITEM_PICKUP(5, 30000), FAST_ITEM_PICKUP(5, SECONDS.toMillis(30)),
FAST_ATTACK(10, 30000), FAST_ATTACK(10, SECONDS.toMillis(30)),
MPCON(25, 30000); MPCON(25, SECONDS.toMillis(30));
private final int points; private final int points;
private final long expiretime; private final long expiretime;
@@ -83,7 +86,7 @@ public enum AutobanFactory {
} }
public void alert(Character chr, String reason) { public void alert(Character chr, String reason) {
if (YamlConfig.config.server.USE_AUTOBAN == true) { if (YamlConfig.config.server.USE_AUTOBAN) {
if (chr != null && MapleLogger.ignored.contains(chr.getId())) { if (chr != null && MapleLogger.ignored.contains(chr.getId())) {
return; return;
} }
@@ -95,7 +98,7 @@ public enum AutobanFactory {
} }
public void autoban(Character chr, String value) { public void autoban(Character chr, String value) {
if (YamlConfig.config.server.USE_AUTOBAN == true) { if (YamlConfig.config.server.USE_AUTOBAN) {
chr.autoban("Autobanned for (" + this.name() + ": " + value + ")"); chr.autoban("Autobanned for (" + this.name() + ": " + value + ")");
//chr.sendPolice("You will be disconnected for (" + this.name() + ": " + value + ")"); //chr.sendPolice("You will be disconnected for (" + this.name() + ": " + value + ")");
} }
@@ -27,6 +27,8 @@ import client.Client;
import client.command.Command; import client.command.Command;
import net.server.Server; import net.server.Server;
import static java.util.concurrent.TimeUnit.*;
public class UptimeCommand extends Command { public class UptimeCommand extends Command {
{ {
setDescription("Show server online time."); setDescription("Show server online time.");
@@ -35,10 +37,10 @@ public class UptimeCommand extends Command {
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
long milliseconds = System.currentTimeMillis() - Server.uptime; long milliseconds = System.currentTimeMillis() - Server.uptime;
int seconds = (int) (milliseconds / 1000) % 60; int seconds = (int) (milliseconds / SECONDS.toMillis(1)) % 60;
int minutes = (int) ((milliseconds / (1000 * 60)) % 60); int minutes = (int) ((milliseconds / MINUTES.toMillis(1)) % 60);
int hours = (int) ((milliseconds / (1000 * 60 * 60)) % 24); int hours = (int) ((milliseconds / HOURS.toMillis(1)) % 24);
int days = (int) ((milliseconds / (1000 * 60 * 60 * 24))); int days = (int) ((milliseconds / DAYS.toMillis(1)));
c.getPlayer().yellowMessage("Server has been online for " + days + " days " + hours + " hours " + minutes + " minutes and " + seconds + " seconds."); c.getPlayer().yellowMessage("Server has been online for " + days + " days " + hours + " hours " + minutes + " minutes and " + seconds + " seconds.");
} }
} }
@@ -32,6 +32,8 @@ import config.YamlConfig;
import constants.inventory.ItemConstants; import constants.inventory.ItemConstants;
import server.ItemInformationProvider; import server.ItemInformationProvider;
import static java.util.concurrent.TimeUnit.DAYS;
public class ItemCommand extends Command { public class ItemCommand extends Command {
{ {
setDescription("Spawn an item into your inventory."); setDescription("Spawn an item into your inventory.");
@@ -68,7 +70,7 @@ public class ItemCommand extends Command {
if (params.length >= 2) { // thanks to istreety & TacoBell if (params.length >= 2) { // thanks to istreety & TacoBell
quantity = 1; quantity = 1;
long days = Math.max(1, Integer.parseInt(params[1])); long days = Math.max(1, Integer.parseInt(params[1]));
long expiration = System.currentTimeMillis() + (days * 24 * 60 * 60 * 1000); long expiration = System.currentTimeMillis() + DAYS.toMillis(days);
int petid = Pet.createPet(itemId); int petid = Pet.createPet(itemId);
InventoryManipulator.addById(c, itemId, quantity, player.getName(), petid, expiration); InventoryManipulator.addById(c, itemId, quantity, player.getName(), petid, expiration);
@@ -33,6 +33,8 @@ import config.YamlConfig;
import constants.inventory.ItemConstants; import constants.inventory.ItemConstants;
import server.ItemInformationProvider; import server.ItemInformationProvider;
import static java.util.concurrent.TimeUnit.DAYS;
public class ItemDropCommand extends Command { public class ItemDropCommand extends Command {
{ {
setDescription("Spawn an item onto the ground."); setDescription("Spawn an item onto the ground.");
@@ -69,7 +71,7 @@ public class ItemDropCommand extends Command {
if (params.length >= 2) { // thanks to istreety & TacoBell if (params.length >= 2) { // thanks to istreety & TacoBell
quantity = 1; quantity = 1;
long days = Math.max(1, Integer.parseInt(params[1])); long days = Math.max(1, Integer.parseInt(params[1]));
long expiration = System.currentTimeMillis() + (days * 24 * 60 * 60 * 1000); long expiration = System.currentTimeMillis() + DAYS.toMillis(days);
int petid = Pet.createPet(itemId); int petid = Pet.createPet(itemId);
Item toDrop = new Item(itemId, (short) 0, quantity, petid); Item toDrop = new Item(itemId, (short) 0, quantity, petid);
@@ -29,6 +29,8 @@ import client.command.Command;
import server.maps.MapleMap; import server.maps.MapleMap;
import server.maps.Portal; import server.maps.Portal;
import static java.util.concurrent.TimeUnit.MINUTES;
public class JailCommand extends Command { public class JailCommand extends Command {
{ {
setDescription("Move a player to the jail."); setDescription("Move a player to the jail.");
@@ -53,7 +55,7 @@ public class JailCommand extends Command {
Character victim = c.getWorldServer().getPlayerStorage().getCharacterByName(params[0]); Character victim = c.getWorldServer().getPlayerStorage().getCharacterByName(params[0]);
if (victim != null) { if (victim != null) {
victim.addJailExpirationTime(minutesJailed * 60 * 1000); victim.addJailExpirationTime(MINUTES.toMillis(minutesJailed));
int mapid = 300000012; int mapid = 300000012;
@@ -30,6 +30,8 @@ import net.server.Server;
import net.server.world.World; import net.server.world.World;
import server.TimerManager; import server.TimerManager;
import static java.util.concurrent.TimeUnit.*;
public class ShutdownCommand extends Command { public class ShutdownCommand extends Command {
{ {
setDescription("Shut down the server."); setDescription("Shut down the server.");
@@ -51,10 +53,10 @@ public class ShutdownCommand extends Command {
} }
if (time > 1) { if (time > 1) {
int seconds = (time / 1000) % 60; int seconds = (time / (int) SECONDS.toMillis(1)) % 60;
int minutes = (time / (1000 * 60)) % 60; int minutes = (time / (int) MINUTES.toMillis(1)) % 60;
int hours = (time / (1000 * 60 * 60)) % 24; int hours = (time / (int) HOURS.toMillis(1)) % 24;
int days = (time / (1000 * 60 * 60 * 24)); int days = (time / (int) DAYS.toMillis(1));
String strTime = ""; String strTime = "";
if (days > 0) { if (days > 0) {
@@ -33,6 +33,8 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import static java.util.concurrent.TimeUnit.HOURS;
/** /**
* @author Ronan - credits to Eric for showing the New Year opcodes and handler layout * @author Ronan - credits to Eric for showing the New Year opcodes and handler layout
*/ */
@@ -262,7 +264,7 @@ public class NewYearCardRecord {
if (target != null && target.isLoggedinWorld()) { if (target != null && target.isLoggedinWorld()) {
target.sendPacket(PacketCreator.onNewYearCardRes(target, NewYearCardRecord.this, 0xC, 0)); target.sendPacket(PacketCreator.onNewYearCardRes(target, NewYearCardRecord.this, 0xC, 0));
} }
}, 1000 * 60 * 60); //1 Hour }, HOURS.toMillis(1));
} }
public void stopNewYearCardTask() { public void stopNewYearCardTask() {
@@ -43,6 +43,7 @@ import java.sql.*;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
/** /**
* @author RonanLana - synchronization of Fredrick modules and operation results * @author RonanLana - synchronization of Fredrick modules and operation results
@@ -80,7 +81,7 @@ public class FredrickProcessor {
} }
public static int timestampElapsedDays(Timestamp then, long timeNow) { public static int timestampElapsedDays(Timestamp then, long timeNow) {
return (int) ((timeNow - then.getTime()) / (1000 * 60 * 60 * 24)); return (int) ((timeNow - then.getTime()) / TimeUnit.DAYS.toMillis(1));
} }
private static String fredrickReminderMessage(int daynotes) { private static String fredrickReminderMessage(int daynotes) {
+11 -9
View File
@@ -80,6 +80,8 @@ import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import static java.util.concurrent.TimeUnit.*;
public class Server { public class Server {
private static final Logger log = LoggerFactory.getLogger(Server.class); private static final Logger log = LoggerFactory.getLogger(Server.class);
private static Server instance = null; private static Server instance = null;
@@ -551,7 +553,7 @@ public class Server {
return; return;
} }
long timeClear = System.currentTimeMillis() - 14 * 24 * 60 * 60 * 1000; long timeClear = System.currentTimeMillis() - DAYS.toMillis(14);
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM nxcode WHERE expiration <= ?")) { try (PreparedStatement ps = con.prepareStatement("SELECT * FROM nxcode WHERE expiration <= ?")) {
ps.setLong(1, timeClear); ps.setLong(1, timeClear);
@@ -939,20 +941,20 @@ public class Server {
long timeLeft = getTimeLeftForNextHour(); long timeLeft = getTimeLeftForNextHour();
tMan.register(new CharacterDiseaseTask(), YamlConfig.config.server.UPDATE_INTERVAL, YamlConfig.config.server.UPDATE_INTERVAL); tMan.register(new CharacterDiseaseTask(), YamlConfig.config.server.UPDATE_INTERVAL, YamlConfig.config.server.UPDATE_INTERVAL);
tMan.register(new ReleaseLockTask(), 2 * 60 * 1000, 2 * 60 * 1000); tMan.register(new ReleaseLockTask(), MINUTES.toMillis(2), MINUTES.toMillis(2));
tMan.register(new CouponTask(), YamlConfig.config.server.COUPON_INTERVAL, timeLeft); tMan.register(new CouponTask(), YamlConfig.config.server.COUPON_INTERVAL, timeLeft);
tMan.register(new RankingCommandTask(), 5 * 60 * 1000, 5 * 60 * 1000); tMan.register(new RankingCommandTask(), MINUTES.toMillis(5), MINUTES.toMillis(5));
tMan.register(new RankingLoginTask(), YamlConfig.config.server.RANKING_INTERVAL, timeLeft); tMan.register(new RankingLoginTask(), YamlConfig.config.server.RANKING_INTERVAL, timeLeft);
tMan.register(new LoginCoordinatorTask(), 60 * 60 * 1000, timeLeft); tMan.register(new LoginCoordinatorTask(), HOURS.toMillis(1), timeLeft);
tMan.register(new EventRecallCoordinatorTask(), 60 * 60 * 1000, timeLeft); tMan.register(new EventRecallCoordinatorTask(), HOURS.toMillis(1), timeLeft);
tMan.register(new LoginStorageTask(), 2 * 60 * 1000, 2 * 60 * 1000); tMan.register(new LoginStorageTask(), MINUTES.toMillis(2), MINUTES.toMillis(2));
tMan.register(new DueyFredrickTask(), 60 * 60 * 1000, timeLeft); tMan.register(new DueyFredrickTask(), HOURS.toMillis(1), timeLeft);
tMan.register(new InvitationTask(), 30 * 1000, 30 * 1000); tMan.register(new InvitationTask(), SECONDS.toMillis(30), SECONDS.toMillis(30));
tMan.register(new RespawnTask(), YamlConfig.config.server.RESPAWN_INTERVAL, YamlConfig.config.server.RESPAWN_INTERVAL); tMan.register(new RespawnTask(), YamlConfig.config.server.RESPAWN_INTERVAL, YamlConfig.config.server.RESPAWN_INTERVAL);
timeLeft = getTimeLeftForNextDay(); timeLeft = getTimeLeftForNextDay();
ExpeditionBossLog.resetBossLogTable(); ExpeditionBossLog.resetBossLogTable();
tMan.register(new BossLogTask(), 24 * 60 * 60 * 1000, timeLeft); tMan.register(new BossLogTask(), DAYS.toMillis(1), timeLeft);
} }
public static void main(String[] args) { public static void main(String[] args) {
+10 -8
View File
@@ -55,6 +55,8 @@ import java.util.*;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import static java.util.concurrent.TimeUnit.*;
public final class Channel { public final class Channel {
private static final Logger log = LoggerFactory.getLogger(Channel.class); private static final Logger log = LoggerFactory.getLogger(Channel.class);
private static final int BASE_PORT = 7575; private static final int BASE_PORT = 7575;
@@ -865,7 +867,7 @@ public final class Channel {
ongoingStartTime = System.currentTimeMillis(); ongoingStartTime = System.currentTimeMillis();
if (weddingId != null) { if (weddingId != null) {
ScheduledFuture<?> weddingTask = TimerManager.getInstance().schedule(() -> closeOngoingWedding(cathedral), YamlConfig.config.server.WEDDING_RESERVATION_TIMEOUT * 60 * 1000); ScheduledFuture<?> weddingTask = TimerManager.getInstance().schedule(() -> closeOngoingWedding(cathedral), MINUTES.toMillis(YamlConfig.config.server.WEDDING_RESERVATION_TIMEOUT));
if (cathedral) { if (cathedral) {
cathedralReservationTask = weddingTask; cathedralReservationTask = weddingTask;
@@ -904,25 +906,25 @@ public final class Channel {
} }
byte mode = 0; byte mode = 0;
if (leftTime / (60 * 1000) > 0) { if (leftTime / (MINUTES.toMillis(1)) > 0) {
mode++; //counts minutes mode++; //counts minutes
if (leftTime / (60 * 60 * 1000) > 0) { if (leftTime / (HOURS.toMillis(1)) > 0) {
mode++; //counts hours mode++; //counts hours
} }
} }
switch (mode) { switch (mode) {
case 2: case 2:
int hours = (int) ((leftTime / (1000 * 60 * 60))); int hours = (int) ((leftTime / (HOURS.toMillis(1))));
str.append(hours + " hours, "); str.append(hours + " hours, ");
case 1: case 1:
int minutes = (int) ((leftTime / (1000 * 60)) % 60); int minutes = (int) ((leftTime / (MINUTES.toMillis(1))) % 60);
str.append(minutes + " minutes, "); str.append(minutes + " minutes, ");
default: default:
int seconds = (int) (leftTime / 1000) % 60; int seconds = (int) (leftTime / SECONDS.toMillis(1)) % 60;
str.append(seconds + " seconds"); str.append(seconds + " seconds");
} }
@@ -934,7 +936,7 @@ public final class Channel {
} }
public static long getRelativeWeddingTicketExpireTime(int resSlot) { public static long getRelativeWeddingTicketExpireTime(int resSlot) {
return (resSlot * YamlConfig.config.server.WEDDING_RESERVATION_INTERVAL * 60 * 1000); return MINUTES.toMillis((long) resSlot * YamlConfig.config.server.WEDDING_RESERVATION_INTERVAL);
} }
public String getWeddingReservationTimeLeft(Integer weddingId) { public String getWeddingReservationTimeLeft(Integer weddingId) {
@@ -962,7 +964,7 @@ public final class Channel {
return venue + " - RIGHT NOW"; return venue + " - RIGHT NOW";
} }
return venue + " - " + getTimeLeft(ongoingStartTime + (resStatus * YamlConfig.config.server.WEDDING_RESERVATION_INTERVAL * 60 * 1000)) + " from now"; return venue + " - " + getTimeLeft(ongoingStartTime + MINUTES.toMillis((long) resStatus * YamlConfig.config.server.WEDDING_RESERVATION_INTERVAL)) + " from now";
} finally { } finally {
lock.unlock(); lock.unlock();
} }
@@ -48,6 +48,9 @@ import java.awt.*;
import java.util.List; import java.util.List;
import java.util.*; import java.util.*;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
public abstract class AbstractDealDamageHandler extends AbstractPacketHandler { public abstract class AbstractDealDamageHandler extends AbstractPacketHandler {
public static class AttackInfo { public static class AttackInfo {
@@ -302,9 +305,11 @@ public abstract class AbstractDealDamageHandler extends AbstractPacketHandler {
} }
} }
} else if (attack.skill == FPArchMage.FIRE_DEMON) { } else if (attack.skill == FPArchMage.FIRE_DEMON) {
monster.setTempEffectiveness(Element.ICE, ElementalEffectiveness.WEAK, SkillFactory.getSkill(FPArchMage.FIRE_DEMON).getEffect(player.getSkillLevel(SkillFactory.getSkill(FPArchMage.FIRE_DEMON))).getDuration() * 1000); long duration = SECONDS.toMillis(SkillFactory.getSkill(FPArchMage.FIRE_DEMON).getEffect(player.getSkillLevel(SkillFactory.getSkill(FPArchMage.FIRE_DEMON))).getDuration());
monster.setTempEffectiveness(Element.ICE, ElementalEffectiveness.WEAK, duration);
} else if (attack.skill == ILArchMage.ICE_DEMON) { } else if (attack.skill == ILArchMage.ICE_DEMON) {
monster.setTempEffectiveness(Element.FIRE, ElementalEffectiveness.WEAK, SkillFactory.getSkill(ILArchMage.ICE_DEMON).getEffect(player.getSkillLevel(SkillFactory.getSkill(ILArchMage.ICE_DEMON))).getDuration() * 1000); long duration = SECONDS.toMillis(SkillFactory.getSkill(ILArchMage.ICE_DEMON).getEffect(player.getSkillLevel(SkillFactory.getSkill(ILArchMage.ICE_DEMON))).getDuration());
monster.setTempEffectiveness(Element.FIRE, ElementalEffectiveness.WEAK, duration);
} else if (attack.skill == Outlaw.HOMING_BEACON || attack.skill == Corsair.BULLSEYE) { } else if (attack.skill == Outlaw.HOMING_BEACON || attack.skill == Corsair.BULLSEYE) {
StatEffect beacon = SkillFactory.getSkill(attack.skill).getEffect(player.getSkillLevel(attack.skill)); StatEffect beacon = SkillFactory.getSkill(attack.skill).getEffect(player.getSkillLevel(attack.skill));
beacon.applyBeaconBuff(player, monster.getObjectId()); beacon.applyBeaconBuff(player, monster.getObjectId());
@@ -324,7 +329,8 @@ public abstract class AbstractDealDamageHandler extends AbstractPacketHandler {
Skill snowCharge = SkillFactory.getSkill(Aran.SNOW_CHARGE); Skill snowCharge = SkillFactory.getSkill(Aran.SNOW_CHARGE);
if (totDamageToOneMonster > 0) { if (totDamageToOneMonster > 0) {
MonsterStatusEffect monsterStatusEffect = new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.SPEED, snowCharge.getEffect(player.getSkillLevel(snowCharge)).getX()), snowCharge, null, false); MonsterStatusEffect monsterStatusEffect = new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.SPEED, snowCharge.getEffect(player.getSkillLevel(snowCharge)).getX()), snowCharge, null, false);
monster.applyStatus(player, monsterStatusEffect, false, snowCharge.getEffect(player.getSkillLevel(snowCharge)).getY() * 1000); long duration = SECONDS.toMillis(snowCharge.getEffect(player.getSkillLevel(snowCharge)).getY());
monster.applyStatus(player, monsterStatusEffect, false, duration);
} }
} }
} }
@@ -332,21 +338,24 @@ public abstract class AbstractDealDamageHandler extends AbstractPacketHandler {
Skill hamstring = SkillFactory.getSkill(Bowmaster.HAMSTRING); Skill hamstring = SkillFactory.getSkill(Bowmaster.HAMSTRING);
if (hamstring.getEffect(player.getSkillLevel(hamstring)).makeChanceResult()) { if (hamstring.getEffect(player.getSkillLevel(hamstring)).makeChanceResult()) {
MonsterStatusEffect monsterStatusEffect = new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.SPEED, hamstring.getEffect(player.getSkillLevel(hamstring)).getX()), hamstring, null, false); MonsterStatusEffect monsterStatusEffect = new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.SPEED, hamstring.getEffect(player.getSkillLevel(hamstring)).getX()), hamstring, null, false);
monster.applyStatus(player, monsterStatusEffect, false, hamstring.getEffect(player.getSkillLevel(hamstring)).getY() * 1000); long duration = SECONDS.toMillis(hamstring.getEffect(player.getSkillLevel(hamstring)).getY());
monster.applyStatus(player, monsterStatusEffect, false, duration);
} }
} }
if (player.getBuffedValue(BuffStat.SLOW) != null) { if (player.getBuffedValue(BuffStat.SLOW) != null) {
Skill slow = SkillFactory.getSkill(Evan.SLOW); Skill slow = SkillFactory.getSkill(Evan.SLOW);
if (slow.getEffect(player.getSkillLevel(slow)).makeChanceResult()) { if (slow.getEffect(player.getSkillLevel(slow)).makeChanceResult()) {
MonsterStatusEffect monsterStatusEffect = new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.SPEED, slow.getEffect(player.getSkillLevel(slow)).getX()), slow, null, false); MonsterStatusEffect monsterStatusEffect = new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.SPEED, slow.getEffect(player.getSkillLevel(slow)).getX()), slow, null, false);
monster.applyStatus(player, monsterStatusEffect, false, slow.getEffect(player.getSkillLevel(slow)).getY() * 60 * 1000); long duration = MINUTES.toMillis(slow.getEffect(player.getSkillLevel(slow)).getY());
monster.applyStatus(player, monsterStatusEffect, false, duration);
} }
} }
if (player.getBuffedValue(BuffStat.BLIND) != null) { if (player.getBuffedValue(BuffStat.BLIND) != null) {
Skill blind = SkillFactory.getSkill(Marksman.BLIND); Skill blind = SkillFactory.getSkill(Marksman.BLIND);
if (blind.getEffect(player.getSkillLevel(blind)).makeChanceResult()) { if (blind.getEffect(player.getSkillLevel(blind)).makeChanceResult()) {
MonsterStatusEffect monsterStatusEffect = new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.ACC, blind.getEffect(player.getSkillLevel(blind)).getX()), blind, null, false); MonsterStatusEffect monsterStatusEffect = new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.ACC, blind.getEffect(player.getSkillLevel(blind)).getX()), blind, null, false);
monster.applyStatus(player, monsterStatusEffect, false, blind.getEffect(player.getSkillLevel(blind)).getY() * 1000); long duration = SECONDS.toMillis(blind.getEffect(player.getSkillLevel(blind)).getY());
monster.applyStatus(player, monsterStatusEffect, false, duration);
} }
} }
if (job == 121 || job == 122) { if (job == 121 || job == 122) {
@@ -47,6 +47,8 @@ import java.util.Calendar;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static java.util.concurrent.TimeUnit.DAYS;
public final class CashOperationHandler extends AbstractPacketHandler { public final class CashOperationHandler extends AbstractPacketHandler {
@Override @Override
@@ -418,7 +420,7 @@ public final class CashOperationHandler extends AbstractPacketHandler {
c.sendPacket(PacketCreator.showCashShopMessage((byte) 0)); c.sendPacket(PacketCreator.showCashShopMessage((byte) 0));
c.enableCSActions(); c.enableCSActions();
return; return;
} else if (c.getTempBanCalendar() != null && c.getTempBanCalendar().getTimeInMillis() + (30 * 24 * 60 * 60 * 1000) > Calendar.getInstance().getTimeInMillis()) { } else if (c.getTempBanCalendar() != null && (c.getTempBanCalendar().getTimeInMillis() + DAYS.toMillis(30)) > Calendar.getInstance().getTimeInMillis()) {
c.sendPacket(PacketCreator.showCashShopMessage((byte) 0)); c.sendPacket(PacketCreator.showCashShopMessage((byte) 0));
c.enableCSActions(); c.enableCSActions();
return; return;
@@ -35,6 +35,8 @@ import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import static java.util.concurrent.TimeUnit.SECONDS;
public final class CloseRangeDamageHandler extends AbstractDealDamageHandler { public final class CloseRangeDamageHandler extends AbstractDealDamageHandler {
@Override @Override
@@ -166,7 +168,7 @@ public final class CloseRangeDamageHandler extends AbstractDealDamageHandler {
return; return;
} else { } else {
c.sendPacket(PacketCreator.skillCooldown(attack.skill, effect_.getCooldown())); c.sendPacket(PacketCreator.skillCooldown(attack.skill, effect_.getCooldown()));
chr.addCooldown(attack.skill, currentServerTime(), effect_.getCooldown() * 1000); chr.addCooldown(attack.skill, currentServerTime(), SECONDS.toMillis(effect_.getCooldown()));
} }
} }
} }
@@ -63,7 +63,7 @@ public final class ItemRewardHandler extends AbstractPacketHandler {
if (ItemConstants.getInventoryType(reward.itemid) == InventoryType.EQUIP) { if (ItemConstants.getInventoryType(reward.itemid) == InventoryType.EQUIP) {
final Item item = ii.getEquipById(reward.itemid); final Item item = ii.getEquipById(reward.itemid);
if (reward.period != -1) { if (reward.period != -1) {
item.setExpiration(currentServerTime() + (reward.period * 60 * 60 * 10)); item.setExpiration(currentServerTime() + reward.period * 60 * 60 * 10);
} }
InventoryManipulator.addFromDrop(c, item, false); InventoryManipulator.addFromDrop(c, item, false);
} else { } else {
@@ -34,6 +34,8 @@ import net.packet.Packet;
import server.StatEffect; import server.StatEffect;
import tools.PacketCreator; import tools.PacketCreator;
import static java.util.concurrent.TimeUnit.SECONDS;
public final class MagicDamageHandler extends AbstractDealDamageHandler { public final class MagicDamageHandler extends AbstractDealDamageHandler {
@Override @Override
public final void handlePacket(InPacket p, Client c) { public final void handlePacket(InPacket p, Client c) {
@@ -72,7 +74,7 @@ public final class MagicDamageHandler extends AbstractDealDamageHandler {
return; return;
} else { } else {
c.sendPacket(PacketCreator.skillCooldown(attack.skill, effect_.getCooldown())); c.sendPacket(PacketCreator.skillCooldown(attack.skill, effect_.getCooldown()));
chr.addCooldown(attack.skill, currentServerTime(), effect_.getCooldown() * 1000); chr.addCooldown(attack.skill, currentServerTime(), SECONDS.toMillis(effect_.getCooldown()));
} }
} }
applyAttack(attack, chr, effect.getAttackCount()); applyAttack(attack, chr, effect.getAttackCount());
@@ -39,6 +39,8 @@ import server.StatEffect;
import tools.PacketCreator; import tools.PacketCreator;
import tools.Randomizer; import tools.Randomizer;
import static java.util.concurrent.TimeUnit.SECONDS;
public final class RangedAttackHandler extends AbstractDealDamageHandler { public final class RangedAttackHandler extends AbstractDealDamageHandler {
@@ -214,7 +216,7 @@ public final class RangedAttackHandler extends AbstractDealDamageHandler {
return; return;
} else { } else {
c.sendPacket(PacketCreator.skillCooldown(attack.skill, effect_.getCooldown())); c.sendPacket(PacketCreator.skillCooldown(attack.skill, effect_.getCooldown()));
chr.addCooldown(attack.skill, currentServerTime(), effect_.getCooldown() * 1000); chr.addCooldown(attack.skill, currentServerTime(), SECONDS.toMillis(effect_.getCooldown()));
} }
} }
} }
@@ -36,6 +36,8 @@ import tools.PacketCreator;
import java.awt.*; import java.awt.*;
import static java.util.concurrent.TimeUnit.SECONDS;
public final class SpecialMoveHandler extends AbstractPacketHandler { public final class SpecialMoveHandler extends AbstractPacketHandler {
@Override @Override
@@ -82,7 +84,7 @@ public final class SpecialMoveHandler extends AbstractPacketHandler {
} }
c.sendPacket(PacketCreator.skillCooldown(skillid, cooldownTime)); c.sendPacket(PacketCreator.skillCooldown(skillid, cooldownTime));
chr.addCooldown(skillid, currentServerTime(), cooldownTime * 1000); chr.addCooldown(skillid, currentServerTime(), SECONDS.toMillis(cooldownTime));
} }
} }
if (skillid == Hero.MONSTER_MAGNET || skillid == Paladin.MONSTER_MAGNET || skillid == DarkKnight.MONSTER_MAGNET) { // Monster Magnet if (skillid == Hero.MONSTER_MAGNET || skillid == Paladin.MONSTER_MAGNET || skillid == DarkKnight.MONSTER_MAGNET) { // Monster Magnet
@@ -31,6 +31,8 @@ import tools.PacketCreator;
import java.sql.*; import java.sql.*;
import java.util.Calendar; import java.util.Calendar;
import static java.util.concurrent.TimeUnit.DAYS;
/** /**
* @author Ronan * @author Ronan
* @author Ubaware * @author Ubaware
@@ -54,7 +56,7 @@ public final class TransferNameHandler extends AbstractPacketHandler {
if (chr.getLevel() < 10) { if (chr.getLevel() < 10) {
c.sendPacket(PacketCreator.sendNameTransferRules(4)); c.sendPacket(PacketCreator.sendNameTransferRules(4));
return; return;
} else if (c.getTempBanCalendar() != null && c.getTempBanCalendar().getTimeInMillis() + (30 * 24 * 60 * 60 * 1000) < Calendar.getInstance().getTimeInMillis()) { } else if (c.getTempBanCalendar() != null && c.getTempBanCalendar().getTimeInMillis() + DAYS.toMillis(30) < Calendar.getInstance().getTimeInMillis()) {
c.sendPacket(PacketCreator.sendNameTransferRules(2)); c.sendPacket(PacketCreator.sendNameTransferRules(2));
return; return;
} }
@@ -50,6 +50,9 @@ import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import static java.util.concurrent.TimeUnit.DAYS;
import static java.util.concurrent.TimeUnit.SECONDS;
public final class UseCashItemHandler extends AbstractPacketHandler { public final class UseCashItemHandler extends AbstractPacketHandler {
@Override @Override
@@ -231,7 +234,7 @@ public final class UseCashItemHandler extends AbstractPacketHandler {
} }
if (period > 0) { if (period > 0) {
eq.setExpiration(currentServerTime() + (period * 60 * 60 * 24 * 1000)); eq.setExpiration(currentServerTime() + DAYS.toMillis(period));
} }
// double-remove found thanks to BHB // double-remove found thanks to BHB
@@ -444,7 +447,7 @@ public final class UseCashItemHandler extends AbstractPacketHandler {
final int world = c.getWorld(); final int world = c.getWorld();
Server.getInstance().broadcastMessage(world, PacketCreator.getAvatarMega(player, medal, c.getChannel(), itemId, strLines, (p.readByte() != 0))); Server.getInstance().broadcastMessage(world, PacketCreator.getAvatarMega(player, medal, c.getChannel(), itemId, strLines, (p.readByte() != 0)));
TimerManager.getInstance().schedule(() -> Server.getInstance().broadcastMessage(world, PacketCreator.byeAvatarMega()), 1000 * 10); TimerManager.getInstance().schedule(() -> Server.getInstance().broadcastMessage(world, PacketCreator.byeAvatarMega()), SECONDS.toMillis(10));
remove(c, position, itemId); remove(c, position, itemId);
} else if (itemType == 540) { } else if (itemType == 540) {
p.readByte(); p.readByte();
@@ -594,7 +597,7 @@ public final class UseCashItemHandler extends AbstractPacketHandler {
} }
client.sendPacket(PacketCreator.enableActions()); client.sendPacket(PacketCreator.enableActions());
}, 1000 * 3); }, SECONDS.toMillis(3));
} else { } else {
System.out.println("NEW CASH ITEM: " + itemType + "\n" + p); System.out.println("NEW CASH ITEM: " + itemType + "\n" + p);
c.sendPacket(PacketCreator.enableActions()); c.sendPacket(PacketCreator.enableActions());
@@ -34,6 +34,8 @@ import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import static java.util.concurrent.TimeUnit.MINUTES;
/** /**
* @author Ronan * @author Ronan
*/ */
@@ -61,7 +63,7 @@ public class LoginBypassCoordinator {
long expireTime = (pic ? YamlConfig.config.server.BYPASS_PIC_EXPIRATION : YamlConfig.config.server.BYPASS_PIN_EXPIRATION); long expireTime = (pic ? YamlConfig.config.server.BYPASS_PIC_EXPIRATION : YamlConfig.config.server.BYPASS_PIN_EXPIRATION);
if (expireTime > 0) { if (expireTime > 0) {
Pair<Hwid, Integer> entry = new Pair<>(hwid, accId); Pair<Hwid, Integer> entry = new Pair<>(hwid, accId);
expireTime = Server.getInstance().getCurrentTime() + expireTime * 60 * 1000; expireTime = Server.getInstance().getCurrentTime() + MINUTES.toMillis(expireTime);
try { try {
pic |= loginBypass.get(entry).getLeft(); pic |= loginBypass.get(entry).getLeft();
expireTime = Math.max(loginBypass.get(entry).getRight(), expireTime); expireTime = Math.max(loginBypass.get(entry).getRight(), expireTime);
@@ -95,7 +97,7 @@ public class LoginBypassCoordinator {
for (Entry<Pair<Hwid, Integer>, Pair<Boolean, Long>> e : loginBypass.entrySet()) { for (Entry<Pair<Hwid, Integer>, Pair<Boolean, Long>> e : loginBypass.entrySet()) {
if (onlineAccounts.contains(e.getKey().getRight())) { if (onlineAccounts.contains(e.getKey().getRight())) {
long expireTime = timeNow + 2 * 60 * 1000; long expireTime = timeNow + MINUTES.toMillis(2);
if (expireTime > e.getValue().getRight()) { if (expireTime > e.getValue().getRight()) {
loginBypass.replace(e.getKey(), new Pair<>(e.getValue().getLeft(), expireTime)); loginBypass.replace(e.getKey(), new Pair<>(e.getValue().getLeft(), expireTime));
} }
+16 -14
View File
@@ -68,6 +68,8 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import static java.util.concurrent.TimeUnit.*;
/** /**
* @author kevintjuh93 * @author kevintjuh93
* @author Ronan - thread-oriented (world schedules + guild queue + marriages + party chars) * @author Ronan - thread-oriented (world schedules + guild queue + marriages + party chars)
@@ -178,22 +180,22 @@ public class World {
} }
TimerManager tman = TimerManager.getInstance(); TimerManager tman = TimerManager.getInstance();
petsSchedule = tman.register(new PetFullnessTask(this), 60 * 1000, 60 * 1000); petsSchedule = tman.register(new PetFullnessTask(this), MINUTES.toMillis(1), MINUTES.toMillis(1));
srvMessagesSchedule = tman.register(new ServerMessageTask(this), 10 * 1000, 10 * 1000); srvMessagesSchedule = tman.register(new ServerMessageTask(this), SECONDS.toMillis(10), SECONDS.toMillis(10));
mountsSchedule = tman.register(new MountTirednessTask(this), 60 * 1000, 60 * 1000); mountsSchedule = tman.register(new MountTirednessTask(this), MINUTES.toMillis(1), MINUTES.toMillis(1));
merchantSchedule = tman.register(new HiredMerchantTask(this), 10 * 60 * 1000, 10 * 60 * 1000); merchantSchedule = tman.register(new HiredMerchantTask(this), 10 * MINUTES.toMillis(1), 10 * MINUTES.toMillis(1));
timedMapObjectsSchedule = tman.register(new TimedMapObjectTask(this), 60 * 1000, 60 * 1000); timedMapObjectsSchedule = tman.register(new TimedMapObjectTask(this), MINUTES.toMillis(1), MINUTES.toMillis(1));
charactersSchedule = tman.register(new CharacterAutosaverTask(this), 60 * 60 * 1000, 60 * 60 * 1000); charactersSchedule = tman.register(new CharacterAutosaverTask(this), HOURS.toMillis(1), HOURS.toMillis(1));
marriagesSchedule = tman.register(new WeddingReservationTask(this), YamlConfig.config.server.WEDDING_RESERVATION_INTERVAL * 60 * 1000, YamlConfig.config.server.WEDDING_RESERVATION_INTERVAL * 60 * 1000); marriagesSchedule = tman.register(new WeddingReservationTask(this), MINUTES.toMillis(YamlConfig.config.server.WEDDING_RESERVATION_INTERVAL), MINUTES.toMillis(YamlConfig.config.server.WEDDING_RESERVATION_INTERVAL));
mapOwnershipSchedule = tman.register(new MapOwnershipTask(this), 20 * 1000, 20 * 1000); mapOwnershipSchedule = tman.register(new MapOwnershipTask(this), SECONDS.toMillis(20), SECONDS.toMillis(20));
fishingSchedule = tman.register(new FishingTask(this), 10 * 1000, 10 * 1000); fishingSchedule = tman.register(new FishingTask(this), SECONDS.toMillis(10), SECONDS.toMillis(10));
partySearchSchedule = tman.register(new PartySearchTask(this), 10 * 1000, 10 * 1000); partySearchSchedule = tman.register(new PartySearchTask(this), SECONDS.toMillis(10), SECONDS.toMillis(10));
timeoutSchedule = tman.register(new TimeoutTask(this), 10 * 1000, 10 * 1000); timeoutSchedule = tman.register(new TimeoutTask(this), SECONDS.toMillis(10), SECONDS.toMillis(10));
if (YamlConfig.config.server.USE_FAMILY_SYSTEM) { if (YamlConfig.config.server.USE_FAMILY_SYSTEM) {
long timeLeft = Server.getTimeLeftForNextDay(); long timeLeft = Server.getTimeLeftForNextDay();
FamilyDailyResetTask.resetEntitlementUsage(this); FamilyDailyResetTask.resetEntitlementUsage(this);
tman.register(new FamilyDailyResetTask(this), 24 * 60 * 60 * 1000, timeLeft); tman.register(new FamilyDailyResetTask(this), DAYS.toMillis(1), timeLeft);
} }
} }
@@ -394,7 +396,7 @@ public class World {
} }
public int getTransportationTime(int travelTime) { public int getTransportationTime(int travelTime) {
return (int) Math.ceil(travelTime / travelrate); return (int) Math.ceil((double) travelTime / travelrate);
} }
public int getFishingRate() { public int getFishingRate() {
@@ -1600,7 +1602,7 @@ public class World {
activeMerchantsLock.lock(); activeMerchantsLock.lock();
try { try {
int initProc; int initProc;
if (Server.getInstance().getCurrentTime() - merchantUpdate > 5 * 60 * 1000) { if (Server.getInstance().getCurrentTime() - merchantUpdate > MINUTES.toMillis(5)) {
initProc = 1; initProc = 1;
} else { } else {
initProc = 0; initProc = 0;
@@ -54,6 +54,7 @@ import tools.Pair;
import java.awt.*; import java.awt.*;
import java.util.List; import java.util.List;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
public class AbstractPlayerInteraction { public class AbstractPlayerInteraction {
@@ -502,7 +503,8 @@ public class AbstractPlayerInteraction {
Pet evolved = null; Pet evolved = null;
Pet target; Pet target;
long period = (long) 90 * 24 * 60 * 60 * 1000; //refreshes expiration date: 90 days long period = TimeUnit.DAYS.toMillis(90); //refreshes expiration date: 90 days
target = getPlayer().getPet(slot); target = getPlayer().getPet(slot);
if (target == null) { if (target == null) {
@@ -59,6 +59,8 @@ import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import static java.util.concurrent.TimeUnit.MINUTES;
/** /**
* @author Matze * @author Matze
* @author Ronan * @author Ronan
@@ -665,7 +667,7 @@ public class EventInstanceManager {
} }
disposeLocks(); disposeLocks();
}, 60 * 1000); }, MINUTES.toMillis(1));
} }
private void disposeLocks() { private void disposeLocks() {
@@ -51,6 +51,8 @@ import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import static java.util.concurrent.TimeUnit.SECONDS;
//import jdk.nashorn.api.scripting.ScriptUtils; //import jdk.nashorn.api.scripting.ScriptUtils;
/** /**
@@ -265,7 +267,7 @@ public class EventManager {
synchronized (instances) { synchronized (instances) {
instances.remove(name); instances.remove(name);
} }
}, YamlConfig.config.server.EVENT_LOBBY_DELAY * 1000); }, SECONDS.toMillis(YamlConfig.config.server.EVENT_LOBBY_DELAY));
} }
public void setProperty(String key, String value) { public void setProperty(String key, String value) {
@@ -69,6 +69,8 @@ import java.sql.SQLException;
import java.util.List; import java.util.List;
import java.util.*; import java.util.*;
import static java.util.concurrent.TimeUnit.MINUTES;
/** /**
* @author Matze * @author Matze
*/ */
@@ -670,9 +672,9 @@ public class NPCConversationManager extends AbstractPlayerInteraction {
mc.changeMap(map, map.getPortal(0)); mc.changeMap(map, map.getPortal(0));
mc.sendPacket(PacketCreator.serverNotice(6, LanguageConstants.getMessage(mc, LanguageConstants.CPQEntryLobby))); mc.sendPacket(PacketCreator.serverNotice(6, LanguageConstants.getMessage(mc, LanguageConstants.CPQEntryLobby)));
TimerManager tMan = TimerManager.getInstance(); TimerManager tMan = TimerManager.getInstance();
tMan.schedule(() -> mapClock(3 * 60), 1500); tMan.schedule(() -> mapClock((int) MINUTES.toSeconds(3)), 1500);
mc.setCpqTimer(TimerManager.getInstance().schedule(() -> mc.changeMap(mapExit, mapExit.getPortal(0)), 3 * 60 * 1000)); mc.setCpqTimer(TimerManager.getInstance().schedule(() -> mc.changeMap(mapExit, mapExit.getPortal(0)), MINUTES.toMillis(3)));
} }
} }
} catch (Exception ex) { } catch (Exception ex) {
@@ -913,9 +915,9 @@ public class NPCConversationManager extends AbstractPlayerInteraction {
mc.changeMap(map, map.getPortal(0)); mc.changeMap(map, map.getPortal(0));
mc.sendPacket(PacketCreator.serverNotice(6, LanguageConstants.getMessage(mc, LanguageConstants.CPQEntryLobby))); mc.sendPacket(PacketCreator.serverNotice(6, LanguageConstants.getMessage(mc, LanguageConstants.CPQEntryLobby)));
TimerManager tMan = TimerManager.getInstance(); TimerManager tMan = TimerManager.getInstance();
tMan.schedule(() -> mapClock(3 * 60), 1500); tMan.schedule(() -> mapClock((int) MINUTES.toSeconds(3)), 1500);
mc.setCpqTimer(TimerManager.getInstance().schedule(() -> mc.changeMap(mapExit, mapExit.getPortal(0)), 3 * 60 * 1000)); mc.setCpqTimer(TimerManager.getInstance().schedule(() -> mc.changeMap(mapExit, mapExit.getPortal(0)), MINUTES.toMillis(3)));
} }
} }
} catch (Exception ex) { } catch (Exception ex) {
+8 -5
View File
@@ -42,6 +42,9 @@ import java.sql.SQLException;
import java.util.*; import java.util.*;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import static java.util.concurrent.TimeUnit.DAYS;
import static java.util.concurrent.TimeUnit.HOURS;
/* /*
* @author Flav * @author Flav
*/ */
@@ -101,18 +104,18 @@ public class CashShop {
if (ItemConstants.EXPIRING_ITEMS) { if (ItemConstants.EXPIRING_ITEMS) {
if (period == 1) { if (period == 1) {
if (itemId == 5211048 || itemId == 5360042) { // 4 Hour 2X coupons, the period is 1, but we don't want them to last a day. if (itemId == 5211048 || itemId == 5360042) { // 4 Hour 2X coupons, the period is 1, but we don't want them to last a day.
item.setExpiration(Server.getInstance().getCurrentTime() + (1000 * 60 * 60 * 4)); item.setExpiration(Server.getInstance().getCurrentTime() + HOURS.toMillis(4));
/* /*
} else if(itemId == 5211047 || itemId == 5360014) { // 3 Hour 2X coupons, unused as of now } else if(itemId == 5211047 || itemId == 5360014) { // 3 Hour 2X coupons, unused as of now
item.setExpiration(Server.getInstance().getCurrentTime() + (1000 * 60 * 60 * 3)); item.setExpiration(Server.getInstance().getCurrentTime() + HOURS.toMillis(3));
*/ */
} else if (itemId == 5211060) { // 2 Hour 3X coupons. } else if (itemId == 5211060) { // 2 Hour 3X coupons.
item.setExpiration(Server.getInstance().getCurrentTime() + (1000 * 60 * 60 * 2)); item.setExpiration(Server.getInstance().getCurrentTime() + HOURS.toMillis(2));
} else { } else {
item.setExpiration(Server.getInstance().getCurrentTime() + (1000 * 60 * 60 * 24)); item.setExpiration(Server.getInstance().getCurrentTime() + DAYS.toMillis(1));
} }
} else { } else {
item.setExpiration(Server.getInstance().getCurrentTime() + (1000 * 60 * 60 * 24 * period)); item.setExpiration(Server.getInstance().getCurrentTime() + DAYS.toMillis(period));
} }
} }
+3 -1
View File
@@ -26,6 +26,8 @@ import client.inventory.Item;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.Calendar; import java.util.Calendar;
import static java.util.concurrent.TimeUnit.DAYS;
public class DueyPackage { public class DueyPackage {
private String sender = null; private String sender = null;
private Item item = null; private Item item = null;
@@ -102,7 +104,7 @@ public class DueyPackage {
cal.setTimeInMillis(ts.getTime()); cal.setTimeInMillis(ts.getTime());
if (quick) { if (quick) {
if (System.currentTimeMillis() - ts.getTime() < 24 * 60 * 60 * 1000) { // thanks inhyuk for noticing quick delivery packages unavailable to retrieve from the get-go if (System.currentTimeMillis() - ts.getTime() < DAYS.toMillis(1)) { // thanks inhyuk for noticing quick delivery packages unavailable to retrieve from the get-go
cal.add(Calendar.DATE, -1); cal.add(Calendar.DATE, -1);
} }
} }
+3 -1
View File
@@ -8,6 +8,8 @@ package server.events;
import client.Character; import client.Character;
import client.SkillFactory; import client.SkillFactory;
import static java.util.concurrent.TimeUnit.DAYS;
/** /**
* @author kevintjuh93 * @author kevintjuh93
*/ */
@@ -44,7 +46,7 @@ public class RescueGaga extends Events {
skillid = 10001014; skillid = 10001014;
} }
long expiration = (System.currentTimeMillis() + 3600 * 24 * 20 * 1000);//20 days long expiration = (System.currentTimeMillis() + DAYS.toMillis(20));
if (completed < 20) { if (completed < 20) {
chr.changeSkillLevel(SkillFactory.getSkill(skillid), (byte) 1, 1, expiration); chr.changeSkillLevel(SkillFactory.getSkill(skillid), (byte) 1, 1, expiration);
chr.changeSkillLevel(SkillFactory.getSkill(skillid + 1), (byte) 1, 1, expiration); chr.changeSkillLevel(SkillFactory.getSkill(skillid + 1), (byte) 1, 1, expiration);
@@ -43,6 +43,8 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import static java.util.concurrent.TimeUnit.MINUTES;
/** /**
* @author Alan (SharpAceX) * @author Alan (SharpAceX)
*/ */
@@ -116,7 +118,7 @@ public class Expedition {
public void beginRegistration() { public void beginRegistration() {
registering = true; registering = true;
leader.sendPacket(PacketCreator.getClock(type.getRegistrationTime() * 60)); leader.sendPacket(PacketCreator.getClock((int) MINUTES.toSeconds(type.getRegistrationMinutes())));
if (!silent) { if (!silent) {
startMap.broadcastMessage(leader, PacketCreator.serverNotice(6, "[Expedition] " + leader.getName() + " has been declared the expedition captain. Please register for the expedition."), false); 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.")); 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() { private void scheduleRegistrationEnd() {
final Expedition exped = this; final Expedition exped = this;
startTime = System.currentTimeMillis() + type.getRegistrationTime() * 60 * 1000; startTime = System.currentTimeMillis() + MINUTES.toMillis(type.getRegistrationMinutes());
schedule = TimerManager.getInstance().schedule(() -> { schedule = TimerManager.getInstance().schedule(() -> {
if (registering) { if (registering) {
@@ -137,7 +139,7 @@ public class Expedition {
dispose(false); dispose(false);
} }
}, type.getRegistrationTime() * 60 * 1000); }, MINUTES.toMillis(type.getRegistrationMinutes()));
} }
public void dispose(boolean log) { public void dispose(boolean log) {
@@ -28,6 +28,9 @@ import java.util.Calendar;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import static java.util.concurrent.TimeUnit.DAYS;
import static java.util.concurrent.TimeUnit.HOURS;
/** /**
* @author Conrad * @author Conrad
* @author Ronan * @author Ronan
@@ -97,8 +100,8 @@ public class ExpeditionBossLog {
Calendar now = Calendar.getInstance(); Calendar now = Calendar.getInstance();
long weekLength = 7 * 24 * 60 * 60 * 1000; long weekLength = DAYS.toMillis(7);
long halfDayLength = 12 * 60 * 60 * 1000; long halfDayLength = HOURS.toMillis(12);
long deltaTime = now.getTime().getTime() - thursday.getTime().getTime(); // 2x time: get Date into millis long deltaTime = now.getTime().getTime() - thursday.getTime().getTime(); // 2x time: get Date into millis
deltaTime += halfDayLength; deltaTime += halfDayLength;
@@ -47,14 +47,14 @@ public enum ExpeditionType {
private final int maxSize; private final int maxSize;
private final int minLevel; private final int minLevel;
private final int maxLevel; private final int maxLevel;
private final int registrationTime; private final int registrationMinutes;
ExpeditionType(int minSize, int maxSize, int minLevel, int maxLevel, int minutes) { ExpeditionType(int minSize, int maxSize, int minLevel, int maxLevel, int minutes) {
this.minSize = minSize; this.minSize = minSize;
this.maxSize = maxSize; this.maxSize = maxSize;
this.minLevel = minLevel; this.minLevel = minLevel;
this.maxLevel = maxLevel; this.maxLevel = maxLevel;
this.registrationTime = minutes; this.registrationMinutes = minutes;
} }
public int getMinSize() { public int getMinSize() {
@@ -73,7 +73,7 @@ public enum ExpeditionType {
return maxLevel; return maxLevel;
} }
public int getRegistrationTime() { public int getRegistrationMinutes() {
return registrationTime; return registrationMinutes;
} }
} }
@@ -39,6 +39,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static java.util.concurrent.TimeUnit.SECONDS;
/** /**
* @author Danny (Leifde) * @author Danny (Leifde)
*/ */
@@ -82,8 +84,8 @@ public class MobSkillFactory {
int x = DataTool.getInt("x", skillData, 1); int x = DataTool.getInt("x", skillData, 1);
int y = DataTool.getInt("y", skillData, 1); int y = DataTool.getInt("y", skillData, 1);
int count = DataTool.getInt("count", skillData, 1); int count = DataTool.getInt("count", skillData, 1);
long duration = DataTool.getInt("time", skillData, 0) * 1000; long duration = SECONDS.toMillis(DataTool.getInt("time", skillData, 0));
long cooltime = DataTool.getInt("interval", skillData, 0) * 1000; long cooltime = SECONDS.toMillis(DataTool.getInt("interval", skillData, 0));
int iprop = DataTool.getInt("prop", skillData, 100); int iprop = DataTool.getInt("prop", skillData, 100);
float prop = iprop / 100; float prop = iprop / 100;
int limit = DataTool.getInt("limit", skillData, 0); int limit = DataTool.getInt("limit", skillData, 0);
+3 -1
View File
@@ -27,6 +27,8 @@ import net.server.Server;
import java.awt.*; import java.awt.*;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import static java.util.concurrent.TimeUnit.SECONDS;
public class SpawnPoint { public class SpawnPoint {
private final int monster; private final int monster;
private final int mobTime; private final int mobTime;
@@ -87,7 +89,7 @@ public class SpawnPoint {
public void monsterKilled(int aniTime) { public void monsterKilled(int aniTime) {
nextPossibleSpawn = Server.getInstance().getCurrentTime(); nextPossibleSpawn = Server.getInstance().getCurrentTime();
if (mobTime > 0) { if (mobTime > 0) {
nextPossibleSpawn += mobTime * 1000; nextPossibleSpawn += SECONDS.toMillis(mobTime);
} else { } else {
nextPossibleSpawn += aniTime; nextPossibleSpawn += aniTime;
} }
+3 -1
View File
@@ -41,6 +41,8 @@ import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import static java.util.concurrent.TimeUnit.SECONDS;
public class MapFactory { public class MapFactory {
private static final Data nameData; private static final Data nameData;
private static final DataProvider mapSource; private static final DataProvider mapSource;
@@ -357,7 +359,7 @@ public class MapFactory {
int y = DataTool.getInt(reactor.getChildByPath("y")); int y = DataTool.getInt(reactor.getChildByPath("y"));
myReactor.setFacingDirection(FacingDirection); myReactor.setFacingDirection(FacingDirection);
myReactor.setPosition(new Point(x, y)); myReactor.setPosition(new Point(x, y));
myReactor.setDelay(DataTool.getInt(reactor.getChildByPath("reactorTime")) * 1000); myReactor.setDelay((int) SECONDS.toMillis(DataTool.getInt(reactor.getChildByPath("reactorTime"))));
myReactor.setName(DataTool.getString(reactor.getChildByPath("name"), "")); myReactor.setName(DataTool.getString(reactor.getChildByPath("name"), ""));
myReactor.resetReactorActions(0); myReactor.resetReactorActions(0);
return myReactor; return myReactor;
+3 -1
View File
@@ -30,6 +30,8 @@ import tools.PacketCreator;
import java.awt.*; import java.awt.*;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import static java.util.concurrent.TimeUnit.SECONDS;
public class MapItem extends AbstractMapObject { public class MapItem extends AbstractMapObject {
protected Client ownerClient; protected Client ownerClient;
protected Item item; protected Item item;
@@ -128,7 +130,7 @@ public class MapItem extends AbstractMapObject {
} }
public final boolean hasExpiredOwnershipTime() { public final boolean hasExpiredOwnershipTime() {
return System.currentTimeMillis() - dropTime >= 15 * 1000; return System.currentTimeMillis() - dropTime >= SECONDS.toMillis(15);
} }
public final boolean canBePickedBy(Character chr) { public final boolean canBePickedBy(Character chr) {
+12 -9
View File
@@ -77,6 +77,9 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import java.util.function.Predicate; import java.util.function.Predicate;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
public class MapleMap { public class MapleMap {
private static final List<MapObjectType> rangedMapobjectTypes = Arrays.asList(MapObjectType.SHOP, MapObjectType.ITEM, MapObjectType.NPC, MapObjectType.MONSTER, MapObjectType.DOOR, MapObjectType.SUMMON, MapObjectType.REACTOR); private static final List<MapObjectType> rangedMapobjectTypes = Arrays.asList(MapObjectType.SHOP, MapObjectType.ITEM, MapObjectType.NPC, MapObjectType.MONSTER, MapObjectType.DOOR, MapObjectType.SUMMON, MapObjectType.REACTOR);
@@ -1880,11 +1883,11 @@ public class MapleMap {
if (selfDestruction == null) { if (selfDestruction == null) {
removeAfterAction = () -> killMonster(monster, null, false); removeAfterAction = () -> killMonster(monster, null, false);
registerMapSchedule(removeAfterAction, monster.getStats().removeAfter() * 1000); registerMapSchedule(removeAfterAction, SECONDS.toMillis(monster.getStats().removeAfter()));
} else { } else {
removeAfterAction = () -> killMonster(monster, null, false, selfDestruction.getAction()); removeAfterAction = () -> killMonster(monster, null, false, selfDestruction.getAction());
registerMapSchedule(removeAfterAction, selfDestruction.removeAfter() * 1000); registerMapSchedule(removeAfterAction, SECONDS.toMillis(selfDestruction.removeAfter()));
} }
monster.pushRemoveAfterAction(removeAfterAction); monster.pushRemoveAfterAction(removeAfterAction);
@@ -2396,7 +2399,7 @@ public class MapleMap {
} }
if (mapid == 200090060) { // To Rien if (mapid == 200090060) { // To Rien
int travelTime = getWorldServer().getTransportationTime(1 * 60 * 1000); int travelTime = getWorldServer().getTransportationTime((int) MINUTES.toMillis(1));
chr.sendPacket(PacketCreator.getClock(travelTime / 1000)); chr.sendPacket(PacketCreator.getClock(travelTime / 1000));
TimerManager.getInstance().schedule(() -> { TimerManager.getInstance().schedule(() -> {
if (chr.getMapId() == 200090060) { if (chr.getMapId() == 200090060) {
@@ -2404,7 +2407,7 @@ public class MapleMap {
} }
}, travelTime); }, travelTime);
} else if (mapid == 200090070) { // To Lith Harbor } else if (mapid == 200090070) { // To Lith Harbor
int travelTime = getWorldServer().getTransportationTime(1 * 60 * 1000); int travelTime = getWorldServer().getTransportationTime((int) MINUTES.toMillis(1));
chr.sendPacket(PacketCreator.getClock(travelTime / 1000)); chr.sendPacket(PacketCreator.getClock(travelTime / 1000));
TimerManager.getInstance().schedule(() -> { TimerManager.getInstance().schedule(() -> {
if (chr.getMapId() == 200090070) { if (chr.getMapId() == 200090070) {
@@ -2412,7 +2415,7 @@ public class MapleMap {
} }
}, travelTime); }, travelTime);
} else if (mapid == 200090030) { // To Ereve (SkyFerry) } else if (mapid == 200090030) { // To Ereve (SkyFerry)
int travelTime = getWorldServer().getTransportationTime(2 * 60 * 1000); int travelTime = getWorldServer().getTransportationTime((int) MINUTES.toMillis(2));
chr.sendPacket(PacketCreator.getClock(travelTime / 1000)); chr.sendPacket(PacketCreator.getClock(travelTime / 1000));
TimerManager.getInstance().schedule(() -> { TimerManager.getInstance().schedule(() -> {
if (chr.getMapId() == 200090030) { if (chr.getMapId() == 200090030) {
@@ -2420,7 +2423,7 @@ public class MapleMap {
} }
}, travelTime); }, travelTime);
} else if (mapid == 200090031) { // To Victoria Island (SkyFerry) } else if (mapid == 200090031) { // To Victoria Island (SkyFerry)
int travelTime = getWorldServer().getTransportationTime(2 * 60 * 1000); int travelTime = getWorldServer().getTransportationTime((int) MINUTES.toMillis(2));
chr.sendPacket(PacketCreator.getClock(travelTime / 1000)); chr.sendPacket(PacketCreator.getClock(travelTime / 1000));
TimerManager.getInstance().schedule(() -> { TimerManager.getInstance().schedule(() -> {
if (chr.getMapId() == 200090031) { if (chr.getMapId() == 200090031) {
@@ -2428,7 +2431,7 @@ public class MapleMap {
} }
}, travelTime); }, travelTime);
} else if (mapid == 200090021) { // To Orbis (SkyFerry) } else if (mapid == 200090021) { // To Orbis (SkyFerry)
int travelTime = getWorldServer().getTransportationTime(8 * 60 * 1000); int travelTime = getWorldServer().getTransportationTime((int) MINUTES.toMillis(8));
chr.sendPacket(PacketCreator.getClock(travelTime / 1000)); chr.sendPacket(PacketCreator.getClock(travelTime / 1000));
TimerManager.getInstance().schedule(() -> { TimerManager.getInstance().schedule(() -> {
if (chr.getMapId() == 200090021) { if (chr.getMapId() == 200090021) {
@@ -2436,7 +2439,7 @@ public class MapleMap {
} }
}, travelTime); }, travelTime);
} else if (mapid == 200090020) { // To Ereve From Orbis (SkyFerry) } else if (mapid == 200090020) { // To Ereve From Orbis (SkyFerry)
int travelTime = getWorldServer().getTransportationTime(8 * 60 * 1000); int travelTime = getWorldServer().getTransportationTime((int) MINUTES.toMillis(8));
chr.sendPacket(PacketCreator.getClock(travelTime / 1000)); chr.sendPacket(PacketCreator.getClock(travelTime / 1000));
TimerManager.getInstance().schedule(() -> { TimerManager.getInstance().schedule(() -> {
if (chr.getMapId() == 200090020) { if (chr.getMapId() == 200090020) {
@@ -2449,7 +2452,7 @@ public class MapleMap {
mmd.registerPlayer(chr); mmd.registerPlayer(chr);
} }
} else if (GameConstants.isAriantColiseumArena(mapid)) { } else if (GameConstants.isAriantColiseumArena(mapid)) {
int pqTimer = (10 * 60 * 1000); int pqTimer = (int) MINUTES.toMillis(10);
chr.sendPacket(PacketCreator.getClock(pqTimer / 1000)); chr.sendPacket(PacketCreator.getClock(pqTimer / 1000));
} }
+3 -1
View File
@@ -30,6 +30,8 @@ import java.util.List;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import static java.util.concurrent.TimeUnit.SECONDS;
/** /**
* @author Ronan * @author Ronan
*/ */
@@ -43,7 +45,7 @@ public class MiniDungeon {
public MiniDungeon(int base, long timeLimit) { public MiniDungeon(int base, long timeLimit) {
baseMap = base; baseMap = base;
expireTime = timeLimit * 1000; expireTime = SECONDS.toMillis(timeLimit);
timeoutTask = TimerManager.getInstance().schedule(() -> close(), expireTime); timeoutTask = TimerManager.getInstance().schedule(() -> close(), expireTime);
+3 -1
View File
@@ -31,6 +31,8 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import static java.util.concurrent.TimeUnit.MINUTES;
/** /**
* @author Matze * @author Matze
* @author Ronan (HeavenMS) * @author Ronan (HeavenMS)
@@ -284,7 +286,7 @@ public class MiniGame extends AbstractMapObject {
visitorscore += 10; visitorscore += 10;
ownerscore += 10; ownerscore += 10;
nextavailabletie = timeNow + 5 * 60 * 1000; nextavailabletie = timeNow + MINUTES.toMillis(5);
} }
this.broadcast(PacketCreator.getMiniGameTie(this)); this.broadcast(PacketCreator.getMiniGameTie(this));
@@ -33,6 +33,9 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import static java.util.concurrent.TimeUnit.MINUTES;
/** /**
* @author Ronan * @author Ronan
@@ -61,8 +64,8 @@ public class AriantColiseum {
map = eventMap; map = eventMap;
map.resetFully(); map.resetFully();
int pqTimer = 10 * 60 * 1000; long pqTimer = MINUTES.toMillis(10);
int pqTimerBoard = (9 * 60 * 1000) + 50 * 1000; long pqTimerBoard = MINUTES.toMillis(9) + TimeUnit.SECONDS.toMillis(50);
List<Character> players = exped.getActiveMembers(); List<Character> players = exped.getActiveMembers();
score = new HashMap<>(); score = new HashMap<>();
@@ -278,7 +281,7 @@ public class AriantColiseum {
score.clear(); score.clear();
exped = null; exped = null;
map = null; map = null;
}, 5 * 60 * 1000); }, MINUTES.toMillis(5));
} }
} }
} }
@@ -14,6 +14,9 @@ import tools.PacketCreator;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
/** /**
* @author Drago (Dragohe4rt) * @author Drago (Dragohe4rt)
*/ */
@@ -43,7 +46,7 @@ public class MonsterCarnival {
p1.setEnemy(p2); p1.setEnemy(p2);
p2.setEnemy(p1); p2.setEnemy(p1);
map = cs.getMapFactory().getDisposableMap(mapid); map = cs.getMapFactory().getDisposableMap(mapid);
startTime = System.currentTimeMillis() + 10 * 60 * 1000; startTime = System.currentTimeMillis() + MINUTES.toMillis(10);
int redPortal = 0; int redPortal = 0;
int bluePortal = 0; int bluePortal = 0;
if (map.isPurpleCPQMap()) { if (map.isPurpleCPQMap()) {
@@ -96,8 +99,8 @@ public class MonsterCarnival {
// thanks Atoot, Vcoc for noting double CPQ functional being sent to players in CPQ start // thanks Atoot, Vcoc for noting double CPQ functional being sent to players in CPQ start
timer = TimerManager.getInstance().schedule(() -> timeUp(), map.getTimeDefault() * 1000); // thanks Atoot for noticing an irregular "event extended" issue here timer = TimerManager.getInstance().schedule(() -> timeUp(), SECONDS.toMillis(map.getTimeDefault())); // thanks Atoot for noticing an irregular "event extended" issue here
effectTimer = TimerManager.getInstance().schedule(() -> complete(), map.getTimeDefault() * 1000 - 10 * 1000); effectTimer = TimerManager.getInstance().schedule(() -> complete(), SECONDS.toMillis(map.getTimeDefault() - 10));
respawnTask = TimerManager.getInstance().register(() -> respawn(), YamlConfig.config.server.RESPAWN_INTERVAL); respawnTask = TimerManager.getInstance().register(() -> respawn(), YamlConfig.config.server.RESPAWN_INTERVAL);
cs.initMonsterCarnival(cpq1, room); cs.initMonsterCarnival(cpq1, room);
@@ -344,12 +347,12 @@ public class MonsterCarnival {
for (Character chrMap : map.getAllPlayers()) { for (Character chrMap : map.getAllPlayers()) {
chrMap.dropMessage(5, LanguageConstants.getMessage(chrMap, LanguageConstants.CPQExtendTime)); chrMap.dropMessage(5, LanguageConstants.getMessage(chrMap, LanguageConstants.CPQExtendTime));
} }
startTime = System.currentTimeMillis() + 3 * 60 * 1000; startTime = System.currentTimeMillis() + MINUTES.toMillis(3);
map.broadcastMessage(PacketCreator.getClock(3 * 60)); map.broadcastMessage(PacketCreator.getClock((int) MINUTES.toSeconds(3)));
timer = TimerManager.getInstance().schedule(() -> timeUp(), map.getTimeExpand() * 1000); timer = TimerManager.getInstance().schedule(() -> timeUp(), SECONDS.toMillis(map.getTimeExpand()));
effectTimer = TimerManager.getInstance().schedule(() -> complete(), map.getTimeExpand() * 1000 - 10 * 1000); // thanks Vcoc for noticing a time set issue here effectTimer = TimerManager.getInstance().schedule(() -> complete(), SECONDS.toMillis(map.getTimeExpand() - 10)); // thanks Vcoc for noticing a time set issue here
} }
public void complete() { public void complete() {
+3 -1
View File
@@ -30,6 +30,8 @@ import tools.PacketCreator;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import static java.util.concurrent.TimeUnit.SECONDS;
/** /**
* @author kevintjuh93 * @author kevintjuh93
*/ */
@@ -136,7 +138,7 @@ public class Pyramid extends PartyQuest {
timer = TimerManager.getInstance().schedule(() -> { timer = TimerManager.getInstance().schedule(() -> {
stage++; stage++;
warp(map + (stage * 100));//Should work :D warp(map + (stage * 100));//Should work :D
}, value * 1000);//, 4000 }, SECONDS.toMillis(value));//, 4000
broadcastInfo("party", getParticipants().size() > 1 ? 1 : 0); broadcastInfo("party", getParticipants().size() > 1 ? 1 : 0);
broadcastInfo("hit", kill); broadcastInfo("hit", kill);
broadcastInfo("miss", miss); broadcastInfo("miss", miss);
+5 -2
View File
@@ -38,6 +38,9 @@ import tools.StringUtil;
import java.util.*; import java.util.*;
import java.util.Map.Entry; import java.util.Map.Entry;
import static java.util.concurrent.TimeUnit.HOURS;
import static java.util.concurrent.TimeUnit.SECONDS;
/** /**
* @author Matze * @author Matze
* @author Ronan - support for medal quests * @author Ronan - support for medal quests
@@ -204,7 +207,7 @@ public class Quest {
} }
IntervalRequirement ir = (IntervalRequirement) startReqs.get(QuestRequirementType.INTERVAL); IntervalRequirement ir = (IntervalRequirement) startReqs.get(QuestRequirementType.INTERVAL);
return ir.getInterval() < YamlConfig.config.server.QUEST_POINT_REPEATABLE_INTERVAL * 60 * 60 * 1000; return ir.getInterval() < HOURS.toMillis(YamlConfig.config.server.QUEST_POINT_REPEATABLE_INTERVAL);
} }
public boolean canStartQuestByStatus(Character chr) { public boolean canStartQuestByStatus(Character chr) {
@@ -343,7 +346,7 @@ public class Quest {
newStatus.setCompleted(chr.getQuest(this).getCompleted()); newStatus.setCompleted(chr.getQuest(this).getCompleted());
if (timeLimit > 0) { if (timeLimit > 0) {
newStatus.setExpirationTime(System.currentTimeMillis() + (timeLimit * 1000)); newStatus.setExpirationTime(System.currentTimeMillis() + SECONDS.toMillis(timeLimit));
chr.questTimeLimit(this, timeLimit); chr.questTimeLimit(this, timeLimit);
} }
if (timeLimit2 > 0) { if (timeLimit2 > 0) {
@@ -42,6 +42,8 @@ import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import static java.util.concurrent.TimeUnit.MINUTES;
/** /**
* @author Tyler (Twdtwd) * @author Tyler (Twdtwd)
* @author Ronan * @author Ronan
@@ -152,7 +154,7 @@ public class ItemAction extends AbstractQuestAction {
for (ItemData iEntry : giveItem) { for (ItemData iEntry : giveItem) {
int itemid = iEntry.getId(), count = iEntry.getCount(), period = iEntry.getPeriod(); // thanks Vcoc for noticing quest milestone item not getting removed from inventory after a while int itemid = iEntry.getId(), count = iEntry.getCount(), period = iEntry.getPeriod(); // thanks Vcoc for noticing quest milestone item not getting removed from inventory after a while
InventoryManipulator.addById(chr.getClient(), itemid, (short) count, "", -1, period > 0 ? (System.currentTimeMillis() + period * 60 * 1000) : -1); InventoryManipulator.addById(chr.getClient(), itemid, (short) count, "", -1, period > 0 ? (System.currentTimeMillis() + MINUTES.toMillis(period)) : -1);
chr.sendPacket(PacketCreator.getShowItemGain(itemid, (short) count, true)); chr.sendPacket(PacketCreator.getShowItemGain(itemid, (short) count, true));
} }
} }
@@ -28,11 +28,14 @@ import provider.DataTool;
import server.quest.Quest; import server.quest.Quest;
import server.quest.QuestRequirementType; import server.quest.QuestRequirementType;
import static java.util.concurrent.TimeUnit.HOURS;
import static java.util.concurrent.TimeUnit.MINUTES;
/** /**
* @author Tyler (Twdtwd) * @author Tyler (Twdtwd)
*/ */
public class IntervalRequirement extends AbstractQuestRequirement { public class IntervalRequirement extends AbstractQuestRequirement {
private int interval = -1; private long interval = -1;
private final int questID; private final int questID;
public IntervalRequirement(Quest quest, Data data) { public IntervalRequirement(Quest quest, Data data) {
@@ -41,13 +44,13 @@ public class IntervalRequirement extends AbstractQuestRequirement {
processData(data); processData(data);
} }
public int getInterval() { public long getInterval() {
return interval; return interval;
} }
@Override @Override
public void processData(Data data) { public void processData(Data data) {
interval = DataTool.getInt(data) * 60 * 1000; interval = MINUTES.toMillis(DataTool.getInt(data));
} }
private static String getIntervalTimeLeft(Character chr, IntervalRequirement r) { private static String getIntervalTimeLeft(Character chr, IntervalRequirement r) {
@@ -57,21 +60,21 @@ public class IntervalRequirement extends AbstractQuestRequirement {
long leftTime = futureTime - System.currentTimeMillis(); long leftTime = futureTime - System.currentTimeMillis();
byte mode = 0; byte mode = 0;
if (leftTime / (60 * 1000) > 0) { if (leftTime / MINUTES.toMillis(1) > 0) {
mode++; //counts minutes mode++; //counts minutes
if (leftTime / (60 * 60 * 1000) > 0) { if (leftTime / HOURS.toMillis(1) > 0) {
mode++; //counts hours mode++; //counts hours
} }
} }
switch (mode) { switch (mode) {
case 2: case 2:
int hours = (int) ((leftTime / (1000 * 60 * 60))); int hours = (int) ((leftTime / HOURS.toMillis(1)));
str.append(hours + " hours, "); str.append(hours + " hours, ");
case 1: case 1:
int minutes = (int) ((leftTime / (1000 * 60)) % 60); int minutes = (int) ((leftTime / MINUTES.toMillis(1)) % 60);
str.append(minutes + " minutes, "); str.append(minutes + " minutes, ");
default: default:
+4 -3
View File
@@ -10,7 +10,8 @@ import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.util.concurrent.TimeUnit;
import static java.util.concurrent.TimeUnit.SECONDS;
/** /**
* @author Frz (Big Daddy) * @author Frz (Big Daddy)
@@ -46,8 +47,8 @@ public class DatabaseConnection {
config.setPassword(YamlConfig.config.server.DB_PASS); config.setPassword(YamlConfig.config.server.DB_PASS);
final int initFailTimeoutSeconds = YamlConfig.config.server.INIT_CONNECTION_POOL_TIMEOUT; final int initFailTimeoutSeconds = YamlConfig.config.server.INIT_CONNECTION_POOL_TIMEOUT;
config.setInitializationFailTimeout(TimeUnit.SECONDS.toMillis(initFailTimeoutSeconds)); config.setInitializationFailTimeout(SECONDS.toMillis(initFailTimeoutSeconds));
config.setConnectionTimeout(30 * 1000); // Hikari default config.setConnectionTimeout(SECONDS.toMillis(30)); // Hikari default
config.setMaximumPoolSize(10); // Hikari default config.setMaximumPoolSize(10); // Hikari default
config.addDataSourceProperty("cachePrepStmts", true); config.addDataSourceProperty("cachePrepStmts", true);
+5 -2
View File
@@ -12,6 +12,9 @@ import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
public class LogHelper { public class LogHelper {
public static void logTrade(Trade trade1, Trade trade2) { public static void logTrade(Trade trade1, Trade trade2) {
@@ -53,8 +56,8 @@ public class LogHelper {
public static String getTimeString(long then) { public static String getTimeString(long then) {
long duration = System.currentTimeMillis() - then; long duration = System.currentTimeMillis() - then;
int seconds = (int) (duration / 1000) % 60; int seconds = (int) (duration / SECONDS.toMillis(1)) % 60;
int minutes = (int) ((duration / (1000 * 60)) % 60); int minutes = (int) ((duration / MINUTES.toMillis(1)) % 60);
return minutes + " Minutes and " + seconds + " Seconds"; return minutes + " Minutes and " + seconds + " Seconds";
} }
@@ -9,6 +9,7 @@ import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit;
/** /**
* @author RonanLana * @author RonanLana
@@ -237,7 +238,7 @@ public class CodeCouponGenerator {
generatedKeys = null; generatedKeys = null;
PreparedStatement ps = con.prepareStatement("INSERT IGNORE INTO `nxcode` (`code`, `expiration`) VALUES (?, ?)", Statement.RETURN_GENERATED_KEYS); PreparedStatement ps = con.prepareStatement("INSERT IGNORE INTO `nxcode` (`code`, `expiration`) VALUES (?, ?)", Statement.RETURN_GENERATED_KEYS);
ps.setLong(2, currentTime + ((long) recipe.duration * 60 * 60 * 1000)); ps.setLong(2, currentTime + TimeUnit.HOURS.toMillis(recipe.duration));
for (int i = 0; i < recipe.quantity; i++) { for (int i = 0; i < recipe.quantity; i++) {
ps.setString(1, generateCouponCode()); ps.setString(1, generateCouponCode());