1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-26 04:25:15 +01:00

Use getOrDefault in some cases to make less code

This commit is contained in:
montlikadani 2020-03-26 11:21:44 +01:00
parent 06db89af5e
commit 40648f2701
13 changed files with 29 additions and 59 deletions

View File

@ -523,9 +523,7 @@ public class Jobs extends JavaPlugin {
* @return the number of slots
*/
public static int getUsedSlots(Job job) {
if (usedSlots.containsKey(job))
return usedSlots.get(job);
return 0;
return usedSlots.getOrDefault(job, 0);
}
/**

View File

@ -94,8 +94,7 @@ public class PermissionManager {
}
private int getDelay(String perm) {
Integer delay = permDelay.get(perm);
return delay == null ? 1 : delay;
return permDelay.getOrDefault(perm, 1);
}
public PermissionManager() {
@ -167,8 +166,8 @@ public class PermissionManager {
jPlayer.setPermissionsCache(permissions);
jPlayer.setLastPermissionUpdate(System.currentTimeMillis());
}
Boolean resul = permissions.get(perm);
return resul == null ? false : resul;
return permissions.getOrDefault(perm, false);
}
}

View File

@ -119,16 +119,16 @@ public class PlayerManager {
}
public void addPlayerToCache(JobsPlayer jPlayer) {
if (jPlayer.getName() != null && playersCache.get(jPlayer.getName().toLowerCase()) == null)
if (jPlayer.getName() != null && !playersCache.containsKey(jPlayer.getName().toLowerCase()))
playersCache.put(jPlayer.getName().toLowerCase(), jPlayer);
if (jPlayer.getUniqueId() != null && playersUUIDCache.get(jPlayer.getUniqueId()) == null)
if (jPlayer.getUniqueId() != null && !playersUUIDCache.containsKey(jPlayer.getUniqueId()))
playersUUIDCache.put(jPlayer.getUniqueId(), jPlayer);
}
public void addPlayer(JobsPlayer jPlayer) {
if (jPlayer.getName() != null && players.get(jPlayer.getName().toLowerCase()) == null)
if (jPlayer.getName() != null && !players.containsKey(jPlayer.getName().toLowerCase()))
players.put(jPlayer.getName().toLowerCase(), jPlayer);
if (jPlayer.getUniqueId() != null && playersUUID.get(jPlayer.getUniqueId()) == null)
if (jPlayer.getUniqueId() != null && !playersUUID.containsKey(jPlayer.getUniqueId()))
playersUUID.put(jPlayer.getUniqueId(), jPlayer);
}
@ -136,10 +136,10 @@ public class PlayerManager {
if (player == null)
return null;
if (players.get(player.getName()) != null)
if (players.containsKey(player.getName()))
players.remove(player.getName().toLowerCase());
JobsPlayer jPlayer = playersUUID.get(player.getUniqueId()) != null ? playersUUID.remove(player.getUniqueId()) : null;
JobsPlayer jPlayer = playersUUID.containsKey(player.getUniqueId()) ? playersUUID.remove(player.getUniqueId()) : null;
return jPlayer;
}
@ -790,11 +790,8 @@ public class PlayerManager {
* @return True if he have permission
*/
public boolean getJobsLimit(JobsPlayer jPlayer, Short currentCount) {
Double max = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.max");
max = max == null ? Jobs.getGCManager().getMaxJobs() : max;
if (max > currentCount)
return true;

View File

@ -60,18 +60,14 @@ public class BlockProtectionManager {
public BlockProtection addP(Location loc, Long time, boolean paid, boolean cache) {
String v = loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ();
HashMap<String, HashMap<String, HashMap<String, BlockProtection>>> regions = map.get(loc.getWorld());
if (regions == null)
regions = new HashMap<>();
String region = locToRegion(loc);
HashMap<String, HashMap<String, BlockProtection>> chunks = regions.get(region);
if (chunks == null)
chunks = new HashMap<>();
String chunk = locToChunk(loc);
HashMap<String, BlockProtection> Bpm = chunks.get(chunk);
if (Bpm == null)
Bpm = new HashMap<>();
HashMap<String, HashMap<String, HashMap<String, BlockProtection>>> regions = map.getOrDefault(loc.getWorld(), new HashMap<>());
String region = locToRegion(loc);
HashMap<String, HashMap<String, BlockProtection>> chunks = regions.getOrDefault(region, new HashMap<>());
String chunk = locToChunk(loc);
HashMap<String, BlockProtection> Bpm = chunks.getOrDefault(chunk, new HashMap<>());
BlockProtection Bp = Bpm.get(v);
if (Bp == null)

View File

@ -55,9 +55,7 @@ public class BossBarManager {
if (!Jobs.getGCManager().BossBarsMessageByDefault)
return;
Boolean show = ToggleBarHandling.getBossBarToggle().get(playerUUID) == null ? true :
ToggleBarHandling.getBossBarToggle().get(playerUUID);
Boolean show = ToggleBarHandling.getBossBarToggle().getOrDefault(playerUUID, true);
if (!show)
return;

View File

@ -20,9 +20,7 @@ public class Boost {
}
public BoostMultiplier get(BoostOf boostoff) {
if (!map.containsKey(boostoff))
return new BoostMultiplier();
return map.get(boostoff);
return map.getOrDefault(boostoff, new BoostMultiplier());
}
public double get(BoostOf boostoff, CurrencyType BT) {

View File

@ -51,10 +51,7 @@ public class BoostMultiplier {
}
public double get(CurrencyType type) {
if (!map.containsKey(type))
return 0D;
return map.get(type);
return map.getOrDefault(type, 0D);
}
public Long getTime() {

View File

@ -19,18 +19,14 @@ public final class Log {
}
public void add(String item, HashMap<CurrencyType, Double> amounts) {
LogAmounts LAmount = this.amountMap.get(item);
if (LAmount == null)
LAmount = new LogAmounts(item);
LogAmounts LAmount = amountMap.getOrDefault(item, new LogAmounts(item));
LAmount.addCount();
LAmount.add(amounts);
this.amountMap.put(item, LAmount);
}
public void add(String item, int count, HashMap<CurrencyType, Double> amounts) {
LogAmounts LAmount = this.amountMap.get(item);
if (LAmount == null)
LAmount = new LogAmounts(item);
LogAmounts LAmount = amountMap.getOrDefault(item, new LogAmounts(item));
LAmount.setCount(count);
LAmount.add(amounts);
LAmount.setNewEntry(false);

View File

@ -40,16 +40,13 @@ public final class LogAmounts {
public void add(CurrencyType type, Double amount) {
if (amount == null)
return;
Double a = amounts.get(type);
if (a == null)
a = 0D;
Double a = amounts.getOrDefault(type, 0D);
amounts.put(type, a + amount);
}
public Double get(CurrencyType type) {
Double a = amounts.get(type);
if (a == null)
a = 0D;
Double a = amounts.getOrDefault(type, 0D);
return ((int) (a * 100D)) / 100D;
}

View File

@ -49,8 +49,7 @@ public class QuestProgression {
}
public int getAmountDone(QuestObjective objective) {
Integer amountDone = done.get(objective);
return amountDone == null ? 0 : amountDone;
return done.getOrDefault(objective, 0);
}
public void setAmountDone(QuestObjective objective, int amountDone) {

View File

@ -795,10 +795,7 @@ public abstract class JobsDAO {
private HashMap<Integer, ArrayList<JobsDAOData>> map = new HashMap<>();
public List<JobsDAOData> getAllJobs(PlayerInfo pInfo) {
List<JobsDAOData> list = map.get(pInfo.getID());
if (list != null)
return list;
return new ArrayList<JobsDAOData>();
return map.getOrDefault(pInfo.getID(), new ArrayList<JobsDAOData>());
}
public void cleanUsers() {

View File

@ -225,8 +225,7 @@ public class BufferedEconomy {
String playerUUID = payment.getOfflinePlayer().getUniqueId().toString();
Boolean show = ToggleBarHandling.getActionBarToggle().get(playerUUID) == null ? true :
ToggleBarHandling.getActionBarToggle().get(playerUUID);
Boolean show = ToggleBarHandling.getActionBarToggle().getOrDefault(playerUUID, true);
Player abp = Bukkit.getPlayer(payment.getOfflinePlayer().getUniqueId());
if ((abp != null) && (show.booleanValue())) {
String Message = Jobs.getLanguage().getMessage("command.toggle.output.paid.main");

View File

@ -81,8 +81,7 @@ public class BufferedPayment {
}
public Double get(CurrencyType type) {
Double amount = this.payments.get(type);
return amount == null ? 0 : amount;
return payments.getOrDefault(type, 0d);
}
public Double set(CurrencyType type, double amount) {