feat: broke down if statement for the getHead() to refactor Complex Conditional Code smell

This commit is contained in:
rabiaa 2023-11-24 20:21:29 -04:00
parent ec6dd42efe
commit 0137f8395c
1 changed files with 7 additions and 3 deletions

View File

@ -80,9 +80,13 @@ public class HeadGetter {
// just check if requested cache exists and compare it with value from plugin settings.
// If timestamp is set to 0, then it must be kept forever.
// If settings time is set to 0, then always use cache.
if (cache != null &&
(cache.getTimestamp() == 0 || cacheTimeout == 0 ||
System.currentTimeMillis() - cache.getTimestamp() <= cacheTimeout))
long cacheTimeStampDifference = System.currentTimeMillis() - cache.getTimestamp();
boolean cacheRequestTimeCondition = cache.getTimestamp() == 0 || cacheTimeout == 0 ||
(cacheTimeStampDifference <= cacheTimeout);
if (cache != null && (cacheRequestTimeCondition))
{
panelItem.setHead(cachedHeads.get(panelItem.getPlayerHeadName()).getPlayerHead());
requester.setHead(panelItem);