mirror of
https://github.com/Zrips/Jobs.git
synced 2024-12-01 23:13:48 +01:00
Use getOrDefault in some cases to make less code
This commit is contained in:
parent
06db89af5e
commit
40648f2701
@ -523,9 +523,7 @@ public class Jobs extends JavaPlugin {
|
|||||||
* @return the number of slots
|
* @return the number of slots
|
||||||
*/
|
*/
|
||||||
public static int getUsedSlots(Job job) {
|
public static int getUsedSlots(Job job) {
|
||||||
if (usedSlots.containsKey(job))
|
return usedSlots.getOrDefault(job, 0);
|
||||||
return usedSlots.get(job);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,8 +94,7 @@ public class PermissionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int getDelay(String perm) {
|
private int getDelay(String perm) {
|
||||||
Integer delay = permDelay.get(perm);
|
return permDelay.getOrDefault(perm, 1);
|
||||||
return delay == null ? 1 : delay;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PermissionManager() {
|
public PermissionManager() {
|
||||||
@ -167,8 +166,8 @@ public class PermissionManager {
|
|||||||
jPlayer.setPermissionsCache(permissions);
|
jPlayer.setPermissionsCache(permissions);
|
||||||
jPlayer.setLastPermissionUpdate(System.currentTimeMillis());
|
jPlayer.setLastPermissionUpdate(System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
Boolean resul = permissions.get(perm);
|
|
||||||
return resul == null ? false : resul;
|
return permissions.getOrDefault(perm, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -119,16 +119,16 @@ public class PlayerManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addPlayerToCache(JobsPlayer jPlayer) {
|
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);
|
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);
|
playersUUIDCache.put(jPlayer.getUniqueId(), jPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPlayer(JobsPlayer 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);
|
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);
|
playersUUID.put(jPlayer.getUniqueId(), jPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,10 +136,10 @@ public class PlayerManager {
|
|||||||
if (player == null)
|
if (player == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (players.get(player.getName()) != null)
|
if (players.containsKey(player.getName()))
|
||||||
players.remove(player.getName().toLowerCase());
|
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;
|
return jPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -790,11 +790,8 @@ public class PlayerManager {
|
|||||||
* @return True if he have permission
|
* @return True if he have permission
|
||||||
*/
|
*/
|
||||||
public boolean getJobsLimit(JobsPlayer jPlayer, Short currentCount) {
|
public boolean getJobsLimit(JobsPlayer jPlayer, Short currentCount) {
|
||||||
|
|
||||||
Double max = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.max");
|
Double max = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.max");
|
||||||
|
|
||||||
max = max == null ? Jobs.getGCManager().getMaxJobs() : max;
|
max = max == null ? Jobs.getGCManager().getMaxJobs() : max;
|
||||||
|
|
||||||
if (max > currentCount)
|
if (max > currentCount)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -60,18 +60,14 @@ public class BlockProtectionManager {
|
|||||||
|
|
||||||
public BlockProtection addP(Location loc, Long time, boolean paid, boolean cache) {
|
public BlockProtection addP(Location loc, Long time, boolean paid, boolean cache) {
|
||||||
String v = loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ();
|
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);
|
BlockProtection Bp = Bpm.get(v);
|
||||||
|
|
||||||
if (Bp == null)
|
if (Bp == null)
|
||||||
|
@ -55,9 +55,7 @@ public class BossBarManager {
|
|||||||
if (!Jobs.getGCManager().BossBarsMessageByDefault)
|
if (!Jobs.getGCManager().BossBarsMessageByDefault)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Boolean show = ToggleBarHandling.getBossBarToggle().get(playerUUID) == null ? true :
|
Boolean show = ToggleBarHandling.getBossBarToggle().getOrDefault(playerUUID, true);
|
||||||
ToggleBarHandling.getBossBarToggle().get(playerUUID);
|
|
||||||
|
|
||||||
if (!show)
|
if (!show)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -20,9 +20,7 @@ public class Boost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BoostMultiplier get(BoostOf boostoff) {
|
public BoostMultiplier get(BoostOf boostoff) {
|
||||||
if (!map.containsKey(boostoff))
|
return map.getOrDefault(boostoff, new BoostMultiplier());
|
||||||
return new BoostMultiplier();
|
|
||||||
return map.get(boostoff);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public double get(BoostOf boostoff, CurrencyType BT) {
|
public double get(BoostOf boostoff, CurrencyType BT) {
|
||||||
|
@ -51,10 +51,7 @@ public class BoostMultiplier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public double get(CurrencyType type) {
|
public double get(CurrencyType type) {
|
||||||
if (!map.containsKey(type))
|
return map.getOrDefault(type, 0D);
|
||||||
return 0D;
|
|
||||||
|
|
||||||
return map.get(type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getTime() {
|
public Long getTime() {
|
||||||
|
@ -19,18 +19,14 @@ public final class Log {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void add(String item, HashMap<CurrencyType, Double> amounts) {
|
public void add(String item, HashMap<CurrencyType, Double> amounts) {
|
||||||
LogAmounts LAmount = this.amountMap.get(item);
|
LogAmounts LAmount = amountMap.getOrDefault(item, new LogAmounts(item));
|
||||||
if (LAmount == null)
|
|
||||||
LAmount = new LogAmounts(item);
|
|
||||||
LAmount.addCount();
|
LAmount.addCount();
|
||||||
LAmount.add(amounts);
|
LAmount.add(amounts);
|
||||||
this.amountMap.put(item, LAmount);
|
this.amountMap.put(item, LAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(String item, int count, HashMap<CurrencyType, Double> amounts) {
|
public void add(String item, int count, HashMap<CurrencyType, Double> amounts) {
|
||||||
LogAmounts LAmount = this.amountMap.get(item);
|
LogAmounts LAmount = amountMap.getOrDefault(item, new LogAmounts(item));
|
||||||
if (LAmount == null)
|
|
||||||
LAmount = new LogAmounts(item);
|
|
||||||
LAmount.setCount(count);
|
LAmount.setCount(count);
|
||||||
LAmount.add(amounts);
|
LAmount.add(amounts);
|
||||||
LAmount.setNewEntry(false);
|
LAmount.setNewEntry(false);
|
||||||
|
@ -40,16 +40,13 @@ public final class LogAmounts {
|
|||||||
public void add(CurrencyType type, Double amount) {
|
public void add(CurrencyType type, Double amount) {
|
||||||
if (amount == null)
|
if (amount == null)
|
||||||
return;
|
return;
|
||||||
Double a = amounts.get(type);
|
|
||||||
if (a == null)
|
Double a = amounts.getOrDefault(type, 0D);
|
||||||
a = 0D;
|
|
||||||
amounts.put(type, a + amount);
|
amounts.put(type, a + amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double get(CurrencyType type) {
|
public Double get(CurrencyType type) {
|
||||||
Double a = amounts.get(type);
|
Double a = amounts.getOrDefault(type, 0D);
|
||||||
if (a == null)
|
|
||||||
a = 0D;
|
|
||||||
return ((int) (a * 100D)) / 100D;
|
return ((int) (a * 100D)) / 100D;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,8 +49,7 @@ public class QuestProgression {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getAmountDone(QuestObjective objective) {
|
public int getAmountDone(QuestObjective objective) {
|
||||||
Integer amountDone = done.get(objective);
|
return done.getOrDefault(objective, 0);
|
||||||
return amountDone == null ? 0 : amountDone;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAmountDone(QuestObjective objective, int amountDone) {
|
public void setAmountDone(QuestObjective objective, int amountDone) {
|
||||||
|
@ -795,10 +795,7 @@ public abstract class JobsDAO {
|
|||||||
private HashMap<Integer, ArrayList<JobsDAOData>> map = new HashMap<>();
|
private HashMap<Integer, ArrayList<JobsDAOData>> map = new HashMap<>();
|
||||||
|
|
||||||
public List<JobsDAOData> getAllJobs(PlayerInfo pInfo) {
|
public List<JobsDAOData> getAllJobs(PlayerInfo pInfo) {
|
||||||
List<JobsDAOData> list = map.get(pInfo.getID());
|
return map.getOrDefault(pInfo.getID(), new ArrayList<JobsDAOData>());
|
||||||
if (list != null)
|
|
||||||
return list;
|
|
||||||
return new ArrayList<JobsDAOData>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cleanUsers() {
|
public void cleanUsers() {
|
||||||
|
@ -225,8 +225,7 @@ public class BufferedEconomy {
|
|||||||
|
|
||||||
String playerUUID = payment.getOfflinePlayer().getUniqueId().toString();
|
String playerUUID = payment.getOfflinePlayer().getUniqueId().toString();
|
||||||
|
|
||||||
Boolean show = ToggleBarHandling.getActionBarToggle().get(playerUUID) == null ? true :
|
Boolean show = ToggleBarHandling.getActionBarToggle().getOrDefault(playerUUID, true);
|
||||||
ToggleBarHandling.getActionBarToggle().get(playerUUID);
|
|
||||||
Player abp = Bukkit.getPlayer(payment.getOfflinePlayer().getUniqueId());
|
Player abp = Bukkit.getPlayer(payment.getOfflinePlayer().getUniqueId());
|
||||||
if ((abp != null) && (show.booleanValue())) {
|
if ((abp != null) && (show.booleanValue())) {
|
||||||
String Message = Jobs.getLanguage().getMessage("command.toggle.output.paid.main");
|
String Message = Jobs.getLanguage().getMessage("command.toggle.output.paid.main");
|
||||||
|
@ -81,8 +81,7 @@ public class BufferedPayment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Double get(CurrencyType type) {
|
public Double get(CurrencyType type) {
|
||||||
Double amount = this.payments.get(type);
|
return payments.getOrDefault(type, 0d);
|
||||||
return amount == null ? 0 : amount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double set(CurrencyType type, double amount) {
|
public Double set(CurrencyType type, double amount) {
|
||||||
|
Loading…
Reference in New Issue
Block a user