Calendar should never be used to get current time.

This commit is contained in:
MobiusDevelopment
2022-10-15 21:08:11 +00:00
parent eff401ff2a
commit 52ce1e3676
239 changed files with 1252 additions and 1109 deletions

View File

@@ -22,7 +22,6 @@ import java.sql.ResultSet;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -526,10 +525,10 @@ public class MailBBSManager extends BaseBBSManager
public void sendLetter(String recipients, String subjectValue, String messageValue, Player activeChar)
{
// Current time.
final long currentDate = Calendar.getInstance().getTimeInMillis();
final long currentTime = System.currentTimeMillis();
// Get the current time - 1 day under timestamp format.
final Timestamp ts = new Timestamp(currentDate - 86400000);
final Timestamp ts = new Timestamp(currentTime - 86400000);
// Check sender mails based on previous timestamp. If more than 10 mails have been found for today, then cancel the use.
int count = 0;
@@ -567,7 +566,7 @@ public class MailBBSManager extends BaseBBSManager
try (Connection con = DatabaseFactory.getConnection())
{
// Get the current time under timestamp format.
final Timestamp time = new Timestamp(currentDate);
final Timestamp time = new Timestamp(currentTime);
PreparedStatement statement = null;
for (String recipientName : recipientNames)
{

View File

@@ -18,7 +18,6 @@ package org.l2jmobius.gameserver.communitybbs.Manager;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -62,12 +61,13 @@ public class TopicBBSManager extends BaseBBSManager
return;
}
final long currentTime = System.currentTimeMillis();
f.vload();
final Topic t = new Topic(TopicConstructorType.CREATE, getInstance().getMaxID(f) + 1, Integer.parseInt(ar2), ar5, Calendar.getInstance().getTimeInMillis(), player.getName(), player.getObjectId(), Topic.MEMO, 0);
final Topic t = new Topic(TopicConstructorType.CREATE, getInstance().getMaxID(f) + 1, Integer.parseInt(ar2), ar5, currentTime, player.getName(), player.getObjectId(), Topic.MEMO, 0);
f.addTopic(t);
getInstance().setMaxID(t.getID(), f);
final Post p = new Post(player.getName(), player.getObjectId(), Calendar.getInstance().getTimeInMillis(), t.getID(), f.getID(), ar4);
final Post p = new Post(player.getName(), player.getObjectId(), currentTime, t.getID(), f.getID(), ar4);
PostBBSManager.getInstance().addPostByTopic(p, t);
parseCmd("_bbsmemo", player);
}

View File

@@ -259,6 +259,8 @@ public class CastleManorManager
protected void init()
{
final long currentTime = System.currentTimeMillis();
if (APPROVE == -1)
{
final Calendar manorRefresh = Calendar.getInstance();
@@ -272,7 +274,7 @@ public class CastleManorManager
periodApprove.set(Calendar.MINUTE, NEXT_PERIOD_APPROVE_MIN);
periodApprove.set(Calendar.SECOND, 0);
periodApprove.set(Calendar.MILLISECOND, 0);
final boolean isApproved = (periodApprove.getTimeInMillis() < Calendar.getInstance().getTimeInMillis()) && (manorRefresh.getTimeInMillis() > Calendar.getInstance().getTimeInMillis());
final boolean isApproved = (periodApprove.getTimeInMillis() < currentTime) && (manorRefresh.getTimeInMillis() > currentTime);
APPROVE = isApproved ? 1 : 0;
}
@@ -280,7 +282,7 @@ public class CastleManorManager
firstDelay.set(Calendar.SECOND, 0);
firstDelay.set(Calendar.MILLISECOND, 0);
firstDelay.add(Calendar.MINUTE, 1);
ThreadPool.scheduleAtFixedRate(new ManorTask(), firstDelay.getTimeInMillis() - Calendar.getInstance().getTimeInMillis(), 60000);
ThreadPool.scheduleAtFixedRate(new ManorTask(), firstDelay.getTimeInMillis() - currentTime, 60000);
}
public void setNextPeriod()

View File

@@ -310,7 +310,7 @@ public class FourSepulchersManager extends GrandBossManager
protected void timeSelector()
{
timeCalculator();
final long currentTime = Calendar.getInstance().getTimeInMillis();
final long currentTime = System.currentTimeMillis();
// if current time >= time of entry beginning and if current time < time of entry beginning + time of entry end
if ((currentTime >= _coolDownTimeEnd) && (currentTime < _entryTimeEnd)) // entry time check
{
@@ -1695,7 +1695,7 @@ public class FourSepulchersManager extends GrandBossManager
if (_inAttackTime)
{
final Calendar tmp = Calendar.getInstance();
tmp.setTimeInMillis(Calendar.getInstance().getTimeInMillis() - _warmUpTimeEnd);
tmp.setTimeInMillis(System.currentTimeMillis() - _warmUpTimeEnd);
if ((tmp.get(Calendar.MINUTE) + 5) < Config.FS_TIME_ATTACK)
{
managerSay((byte) tmp.get(Calendar.MINUTE)); // byte because minute cannot be more than 59
@@ -1727,7 +1727,7 @@ public class FourSepulchersManager extends GrandBossManager
// if this is first launch - search time when entry time will be ended: counting difference between time when entry time ends and current time and then launching change time task
if (_firstTimeRun)
{
interval = _entryTimeEnd - Calendar.getInstance().getTimeInMillis();
interval = _entryTimeEnd - System.currentTimeMillis();
}
else
{
@@ -1758,7 +1758,7 @@ public class FourSepulchersManager extends GrandBossManager
// searching time when warmup time will be ended: counting difference between time when warmup time ends and current time and then launching change time task
if (_firstTimeRun)
{
interval = _warmUpTimeEnd - Calendar.getInstance().getTimeInMillis();
interval = _warmUpTimeEnd - System.currentTimeMillis();
}
else
{
@@ -1789,9 +1789,10 @@ public class FourSepulchersManager extends GrandBossManager
spawnMysteriousBox(31923);
spawnMysteriousBox(31924);
final long currentTime = System.currentTimeMillis();
if (!_firstTimeRun)
{
_warmUpTimeEnd = Calendar.getInstance().getTimeInMillis();
_warmUpTimeEnd = currentTime;
}
long interval = 0;
@@ -1805,7 +1806,7 @@ public class FourSepulchersManager extends GrandBossManager
{
final Calendar inter = Calendar.getInstance();
inter.set(Calendar.MINUTE, (int) min);
ThreadPool.schedule(new ManagerSay(), inter.getTimeInMillis() - Calendar.getInstance().getTimeInMillis());
ThreadPool.schedule(new ManagerSay(), inter.getTimeInMillis() - currentTime);
break;
}
}
@@ -1817,7 +1818,7 @@ public class FourSepulchersManager extends GrandBossManager
// searching time when attack time will be ended: counting difference between time when attack time ends and current time and then launching change time task
if (_firstTimeRun)
{
interval = _attackTimeEnd - Calendar.getInstance().getTimeInMillis();
interval = _attackTimeEnd - currentTime;
}
else
{
@@ -1855,7 +1856,7 @@ public class FourSepulchersManager extends GrandBossManager
_firstTimeRun = false; // cooldown phase ends event hour, so it will be not first run
}
final long interval = time.getTimeInMillis() - Calendar.getInstance().getTimeInMillis();
final long interval = time.getTimeInMillis() - System.currentTimeMillis();
_changeEntryTimeTask = ThreadPool.schedule(new ChangeEntryTime(), interval);
if (_changeCoolDownTimeTask != null)
{

View File

@@ -21,7 +21,6 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Calendar;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
@@ -189,7 +188,7 @@ public class RaidBossSpawnManager
final int RespawnMinDelay = boss.getSpawn().getRespawnMinDelay();
final int RespawnMaxDelay = boss.getSpawn().getRespawnMaxDelay();
final long respawnDelay = Rnd.get((int) (RespawnMinDelay * 1000 * Config.RAID_MIN_RESPAWN_MULTIPLIER), (int) (RespawnMaxDelay * 1000 * Config.RAID_MAX_RESPAWN_MULTIPLIER));
final long respawnTime = Calendar.getInstance().getTimeInMillis() + respawnDelay;
final long respawnTime = System.currentTimeMillis() + respawnDelay;
info.set("currentHP", boss.getMaxHp());
info.set("currentMP", boss.getMaxMp());
info.set("respawnTime", respawnTime);
@@ -229,9 +228,9 @@ public class RaidBossSpawnManager
double hp = currentHP;
final int bossId = spawnDat.getNpcId();
final long time = Calendar.getInstance().getTimeInMillis();
final long currentTime = System.currentTimeMillis();
SpawnTable.getInstance().addNewSpawn(spawnDat, false);
if ((respawnTime == 0) || (time > respawnTime))
if ((respawnTime == 0) || (currentTime > respawnTime))
{
final RaidBoss raidboss = bossId == 25328 ? DayNightSpawnManager.getInstance().handleBoss(spawnDat) : (RaidBoss) spawnDat.doSpawn();
if (raidboss != null)
@@ -260,7 +259,7 @@ public class RaidBossSpawnManager
else
{
ScheduledFuture<?> futureSpawn;
final long spawnTime = respawnTime - Calendar.getInstance().getTimeInMillis();
final long spawnTime = respawnTime - currentTime;
futureSpawn = ThreadPool.schedule(new SpawnSchedule(bossId), spawnTime);
_schedules.put(bossId, futureSpawn);
}

View File

@@ -583,7 +583,7 @@ public class Duel
*/
public int getRemainingTime()
{
return (int) (_duelEndTime.getTimeInMillis() - Calendar.getInstance().getTimeInMillis());
return (int) (_duelEndTime.getTimeInMillis() - System.currentTimeMillis());
}
/**

View File

@@ -77,15 +77,15 @@ public class Wedding
public Wedding(Player player1, Player player2)
{
final int _tempPlayer1Id = player1.getObjectId();
final int _tempPlayer2Id = player2.getObjectId();
_player1Id = _tempPlayer1Id;
_player2Id = _tempPlayer2Id;
final long currentTime = System.currentTimeMillis();
_player1Id = player1.getObjectId();
_player2Id = player2.getObjectId();
_affiancedDate = Calendar.getInstance();
_affiancedDate.setTimeInMillis(Calendar.getInstance().getTimeInMillis());
_affiancedDate.setTimeInMillis(currentTime);
_weddingDate = Calendar.getInstance();
_weddingDate.setTimeInMillis(Calendar.getInstance().getTimeInMillis());
_weddingDate.setTimeInMillis(currentTime);
try (Connection con = DatabaseFactory.getConnection())
{

View File

@@ -235,11 +235,12 @@ public class Olympiad
_nextWeeklyChange = Long.parseLong(olympiadProperties.getProperty("NextWeeklyChange", "0"));
}
final long currentTime = System.currentTimeMillis();
switch (_period)
{
case 0:
{
if ((_olympiadEnd == 0) || (_olympiadEnd < Calendar.getInstance().getTimeInMillis()))
if ((_olympiadEnd == 0) || (_olympiadEnd < currentTime))
{
setNewOlympiadEnd();
}
@@ -251,7 +252,7 @@ public class Olympiad
}
case 1:
{
if (_validationEnd > Calendar.getInstance().getTimeInMillis())
if (_validationEnd > currentTime)
{
_scheduledValdationTask = ThreadPool.schedule(new ValidationEndTask(), getMillisToValidationEnd());
}
@@ -841,7 +842,7 @@ public class Olympiad
private long getMillisToOlympiadEnd()
{
return (_olympiadEnd - Calendar.getInstance().getTimeInMillis());
return (_olympiadEnd - System.currentTimeMillis());
}
public void manualSelectHeroes()
@@ -856,9 +857,10 @@ public class Olympiad
protected long getMillisToValidationEnd()
{
if (_validationEnd > Calendar.getInstance().getTimeInMillis())
final long currentTime = System.currentTimeMillis();
if (_validationEnd > currentTime)
{
return (_validationEnd - Calendar.getInstance().getTimeInMillis());
return (_validationEnd - currentTime);
}
return 10;
}
@@ -902,14 +904,15 @@ public class Olympiad
private long getMillisToCompBegin()
{
if ((_compStart.getTimeInMillis() < Calendar.getInstance().getTimeInMillis()) && (_compEnd > Calendar.getInstance().getTimeInMillis()))
final long currentTime = System.currentTimeMillis();
if ((_compStart.getTimeInMillis() < currentTime) && (_compEnd > currentTime))
{
return 10;
}
if (_compStart.getTimeInMillis() > Calendar.getInstance().getTimeInMillis())
if (_compStart.getTimeInMillis() > currentTime)
{
return (_compStart.getTimeInMillis() - Calendar.getInstance().getTimeInMillis());
return (_compStart.getTimeInMillis() - currentTime);
}
return setNewCompBegin();
@@ -968,19 +971,20 @@ public class Olympiad
_compEnd = _compStart.getTimeInMillis() + COMP_PERIOD;
LOGGER.info("Olympiad System: New Schedule @ " + _compStart.getTime());
return (_compStart.getTimeInMillis() - Calendar.getInstance().getTimeInMillis());
return _compStart.getTimeInMillis() - System.currentTimeMillis();
}
protected long getMillisToCompEnd()
{
return (_compEnd - Calendar.getInstance().getTimeInMillis());
return _compEnd - System.currentTimeMillis();
}
private long getMillisToWeekChange()
{
if (_nextWeeklyChange > Calendar.getInstance().getTimeInMillis())
final long currentTime = System.currentTimeMillis();
if (_nextWeeklyChange > currentTime)
{
return (_nextWeeklyChange - Calendar.getInstance().getTimeInMillis());
return (_nextWeeklyChange - currentTime);
}
return 10;
}

View File

@@ -391,17 +391,19 @@ public class ClanHallAuction
World.getInstance().getPlayer(_highestBidderName).sendMessage("You have been out bidded");
}
}
final long currentTime = System.currentTimeMillis();
_highestBidderId = bidder.getClanId();
_highestBidderMaxBid = bid;
_highestBidderName = bidder.getClan().getLeaderName();
if (_bidders.get(_highestBidderId) == null)
{
_bidders.put(_highestBidderId, new Bidder(_highestBidderName, bidder.getClan().getName(), bid, Calendar.getInstance().getTimeInMillis()));
_bidders.put(_highestBidderId, new Bidder(_highestBidderName, bidder.getClan().getName(), bid, currentTime));
}
else
{
_bidders.get(_highestBidderId).setBid(bid);
_bidders.get(_highestBidderId).setTimeBid(Calendar.getInstance().getTimeInMillis());
_bidders.get(_highestBidderId).setTimeBid(currentTime);
}
bidder.sendMessage("You have bidded successfully");

View File

@@ -82,7 +82,7 @@ public class FortSiege
try
{
final long timeRemaining = _siegeEndDate.getTimeInMillis() - Calendar.getInstance().getTimeInMillis();
final long timeRemaining = _siegeEndDate.getTimeInMillis() - System.currentTimeMillis();
if (timeRemaining > 3600000)
{
ThreadPool.schedule(new ScheduleEndSiegeTask(_fortInst), timeRemaining - 3600000); // Prepare task for 1 hr left.
@@ -147,7 +147,7 @@ public class FortSiege
try
{
final long timeRemaining = getSiegeDate().getTimeInMillis() - Calendar.getInstance().getTimeInMillis();
final long timeRemaining = getSiegeDate().getTimeInMillis() - System.currentTimeMillis();
if (timeRemaining > 86400000)
{
// Prepare task for 24 before siege start to end registration
@@ -920,7 +920,7 @@ public class FortSiege
*/
public void checkAutoTask()
{
if (getFort().getSiegeDate().getTimeInMillis() < Calendar.getInstance().getTimeInMillis())
if (getFort().getSiegeDate().getTimeInMillis() < System.currentTimeMillis())
{
clearSiegeDate();
saveSiegeDate();

View File

@@ -141,7 +141,7 @@ public class Siege
try
{
final long timeRemaining = _siegeEndDate.getTimeInMillis() - Calendar.getInstance().getTimeInMillis();
final long timeRemaining = _siegeEndDate.getTimeInMillis() - System.currentTimeMillis();
if (timeRemaining > 3600000)
{
// Prepare task for 1 hr left.
@@ -209,7 +209,7 @@ public class Siege
try
{
final long timeRemaining = getSiegeDate().getTimeInMillis() - Calendar.getInstance().getTimeInMillis();
final long timeRemaining = getSiegeDate().getTimeInMillis() - System.currentTimeMillis();
if (timeRemaining > 86400000)
{
// Prepare task for 24 before siege start to end registration
@@ -1247,7 +1247,7 @@ public class Siege
private void correctSiegeDateTime()
{
boolean corrected = false;
if (getCastle().getSiegeDate().getTimeInMillis() < Calendar.getInstance().getTimeInMillis())
if (getCastle().getSiegeDate().getTimeInMillis() < System.currentTimeMillis())
{
// Since siege has past reschedule it to the next one (14 days)
// This is usually caused by server being down
@@ -1485,7 +1485,7 @@ public class Siege
/** Set the date for the next siege. */
private void setNextSiegeDate()
{
while (getCastle().getSiegeDate().getTimeInMillis() < Calendar.getInstance().getTimeInMillis())
while (getCastle().getSiegeDate().getTimeInMillis() < System.currentTimeMillis())
{
// Set next siege date if siege has passed
// Schedule to happen in 14 days

View File

@@ -18,7 +18,6 @@ package org.l2jmobius.gameserver.network.clientpackets;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -751,7 +750,7 @@ public class EnterWorld implements IClientIncomingPacket
private void onEnterAio(Player player)
{
final long now = Calendar.getInstance().getTimeInMillis();
final long now = System.currentTimeMillis();
final long endDay = player.getAioEndTime();
if (now > endDay)
{

View File

@@ -16,8 +16,6 @@
*/
package org.l2jmobius.gameserver.network.serverpackets;
import java.util.Calendar;
import org.l2jmobius.commons.network.PacketWriter;
import org.l2jmobius.gameserver.data.sql.ClanTable;
import org.l2jmobius.gameserver.model.actor.Player;
@@ -101,7 +99,7 @@ public class SiegeInfo implements IClientOutgoingPacket
packet.writeD(0); // Ally ID
packet.writeS(""); // Ally Name
}
packet.writeD((int) (Calendar.getInstance().getTimeInMillis() / 1000));
packet.writeD((int) (System.currentTimeMillis() / 1000));
packet.writeD((int) _siegeDate);
packet.writeD(0); // number of choices?
return true;