mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-12-30 21:07:47 +01:00
Add a lot null-pointer checks and console errors about loading null-value element from database.
This commit is contained in:
parent
7914f315f4
commit
a9abe32dbe
@ -175,7 +175,7 @@ public class ChallengesManager
|
|||||||
* @param challenge Challenge that must be loaded.
|
* @param challenge Challenge that must be loaded.
|
||||||
* @return true if successful
|
* @return true if successful
|
||||||
*/
|
*/
|
||||||
private void loadChallenge(Challenge challenge)
|
private void loadChallenge(@NonNull Challenge challenge)
|
||||||
{
|
{
|
||||||
this.loadChallenge(challenge, true, null, true);
|
this.loadChallenge(challenge, true, null, true);
|
||||||
}
|
}
|
||||||
@ -190,11 +190,17 @@ public class ChallengesManager
|
|||||||
* @param silent - if true, no messages are sent to user
|
* @param silent - if true, no messages are sent to user
|
||||||
* @return - true if imported
|
* @return - true if imported
|
||||||
*/
|
*/
|
||||||
public boolean loadChallenge(Challenge challenge,
|
public boolean loadChallenge(@NonNull Challenge challenge,
|
||||||
boolean overwrite,
|
boolean overwrite,
|
||||||
User user,
|
User user,
|
||||||
boolean silent)
|
boolean silent)
|
||||||
{
|
{
|
||||||
|
if (challenge == null)
|
||||||
|
{
|
||||||
|
this.addon.logError("Tried to load NULL element from Database. One challenge is broken and will not work.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.challengeCacheData.containsKey(challenge.getUniqueId()))
|
if (this.challengeCacheData.containsKey(challenge.getUniqueId()))
|
||||||
{
|
{
|
||||||
if (!overwrite)
|
if (!overwrite)
|
||||||
@ -235,7 +241,7 @@ public class ChallengesManager
|
|||||||
*
|
*
|
||||||
* @param level the challenge level
|
* @param level the challenge level
|
||||||
*/
|
*/
|
||||||
private void loadLevel(ChallengeLevel level)
|
private void loadLevel(@NonNull ChallengeLevel level)
|
||||||
{
|
{
|
||||||
this.loadLevel(level, true, null, true);
|
this.loadLevel(level, true, null, true);
|
||||||
}
|
}
|
||||||
@ -250,8 +256,14 @@ public class ChallengesManager
|
|||||||
* @param silent of type boolean that indicate if message to user must be sent.
|
* @param silent of type boolean that indicate if message to user must be sent.
|
||||||
* @return boolean that indicate about load status.
|
* @return boolean that indicate about load status.
|
||||||
*/
|
*/
|
||||||
public boolean loadLevel(ChallengeLevel level, boolean overwrite, User user, boolean silent)
|
public boolean loadLevel(@NonNull ChallengeLevel level, boolean overwrite, User user, boolean silent)
|
||||||
{
|
{
|
||||||
|
if (level == null)
|
||||||
|
{
|
||||||
|
this.addon.logError("Tried to load NULL element from Database. One level is broken and will not work.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.isValidLevel(level))
|
if (!this.isValidLevel(level))
|
||||||
{
|
{
|
||||||
if (user != null)
|
if (user != null)
|
||||||
@ -306,7 +318,7 @@ public class ChallengesManager
|
|||||||
* This method stores PlayerData into local cache.
|
* This method stores PlayerData into local cache.
|
||||||
* @param playerData ChallengesPlayerData that must be loaded.
|
* @param playerData ChallengesPlayerData that must be loaded.
|
||||||
*/
|
*/
|
||||||
private void loadPlayerData(ChallengesPlayerData playerData)
|
private void loadPlayerData(@NonNull ChallengesPlayerData playerData)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -352,7 +364,7 @@ public class ChallengesManager
|
|||||||
* @param level that must be validated
|
* @param level that must be validated
|
||||||
* @return true ir level is valid, otherwise false.
|
* @return true ir level is valid, otherwise false.
|
||||||
*/
|
*/
|
||||||
private boolean isValidLevel(ChallengeLevel level)
|
private boolean isValidLevel(@NonNull ChallengeLevel level)
|
||||||
{
|
{
|
||||||
if (!this.addon.getPlugin().getIWM().inWorld(Bukkit.getWorld(level.getWorld())))
|
if (!this.addon.getPlugin().getIWM().inWorld(Bukkit.getWorld(level.getWorld())))
|
||||||
{
|
{
|
||||||
@ -369,6 +381,7 @@ public class ChallengesManager
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
this.addon.logError("Cannot find " + uniqueID + " challenge for " + level.getUniqueId());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -398,7 +411,15 @@ public class ChallengesManager
|
|||||||
// Load player from database
|
// Load player from database
|
||||||
ChallengesPlayerData data = this.playersDatabase.loadObject(uniqueID);
|
ChallengesPlayerData data = this.playersDatabase.loadObject(uniqueID);
|
||||||
// Store in cache
|
// Store in cache
|
||||||
this.playerCacheData.put(uniqueID, data);
|
|
||||||
|
if (data != null)
|
||||||
|
{
|
||||||
|
this.playerCacheData.put(uniqueID, data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.addon.logError("Could not load NULL player data object.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1194,8 +1215,16 @@ public class ChallengesManager
|
|||||||
if (this.challengeDatabase.objectExists(name))
|
if (this.challengeDatabase.objectExists(name))
|
||||||
{
|
{
|
||||||
Challenge challenge = this.challengeDatabase.loadObject(name);
|
Challenge challenge = this.challengeDatabase.loadObject(name);
|
||||||
this.challengeCacheData.put(name, challenge);
|
|
||||||
return challenge;
|
if (challenge != null)
|
||||||
|
{
|
||||||
|
this.challengeCacheData.put(name, challenge);
|
||||||
|
return challenge;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.addon.logError("Tried to load NULL challenge object!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1221,8 +1250,16 @@ public class ChallengesManager
|
|||||||
if (this.challengeDatabase.objectExists(name))
|
if (this.challengeDatabase.objectExists(name))
|
||||||
{
|
{
|
||||||
Challenge challenge = this.challengeDatabase.loadObject(name);
|
Challenge challenge = this.challengeDatabase.loadObject(name);
|
||||||
this.challengeCacheData.put(name, challenge);
|
|
||||||
return true;
|
if (challenge != null)
|
||||||
|
{
|
||||||
|
this.challengeCacheData.put(name, challenge);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.addon.logError("Tried to load NULL challenge object!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1342,8 +1379,16 @@ public class ChallengesManager
|
|||||||
if (this.levelDatabase.objectExists(name))
|
if (this.levelDatabase.objectExists(name))
|
||||||
{
|
{
|
||||||
ChallengeLevel level = this.levelDatabase.loadObject(name);
|
ChallengeLevel level = this.levelDatabase.loadObject(name);
|
||||||
this.levelCacheData.put(name, level);
|
|
||||||
return level;
|
if (level != null)
|
||||||
|
{
|
||||||
|
this.levelCacheData.put(name, level);
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.addon.logError("Tried to load NULL level.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1369,8 +1414,16 @@ public class ChallengesManager
|
|||||||
if (this.levelDatabase.objectExists(name))
|
if (this.levelDatabase.objectExists(name))
|
||||||
{
|
{
|
||||||
ChallengeLevel level = this.levelDatabase.loadObject(name);
|
ChallengeLevel level = this.levelDatabase.loadObject(name);
|
||||||
this.levelCacheData.put(name, level);
|
|
||||||
return true;
|
if (level != null)
|
||||||
|
{
|
||||||
|
this.levelCacheData.put(name, level);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.addon.logError("Tried to load NULL level.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user