mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-11-29 14:05:14 +01:00
Create EMPTY_RESULT variable to avoid so many new ChallengeResult object initializations.
This commit is contained in:
parent
e0f38206aa
commit
2a4b892ed7
@ -69,6 +69,10 @@ public class TryToComplete
|
|||||||
*/
|
*/
|
||||||
private Challenge challenge;
|
private Challenge challenge;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Variable that will be used to avoid multiple empty object generation.
|
||||||
|
*/
|
||||||
|
private final ChallengeResult EMPTY_RESULT = new ChallengeResult();
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Builder
|
// Section: Builder
|
||||||
@ -249,57 +253,69 @@ public class TryToComplete
|
|||||||
*/
|
*/
|
||||||
private ChallengeResult checkIfCanCompleteChallenge()
|
private ChallengeResult checkIfCanCompleteChallenge()
|
||||||
{
|
{
|
||||||
|
ChallengeResult result;
|
||||||
|
|
||||||
ChallengeType type = this.challenge.getChallengeType();
|
ChallengeType type = this.challenge.getChallengeType();
|
||||||
|
|
||||||
// Check the world
|
// Check the world
|
||||||
if (!this.challenge.getUniqueId().startsWith(Util.getWorld(this.world).getName()))
|
if (!this.challenge.getUniqueId().startsWith(Util.getWorld(this.world).getName()))
|
||||||
{
|
{
|
||||||
this.user.sendMessage("general.errors.wrong-world");
|
this.user.sendMessage("general.errors.wrong-world");
|
||||||
|
result = EMPTY_RESULT;
|
||||||
}
|
}
|
||||||
// Check if user has unlocked challenges level.
|
// Check if user has unlocked challenges level.
|
||||||
else if (!this.challenge.getLevel().equals(ChallengesManager.FREE) &&
|
else if (!this.challenge.getLevel().equals(ChallengesManager.FREE) &&
|
||||||
!this.manager.isLevelUnlocked(this.user, this.world, this.manager.getLevel(this.challenge.getLevel())))
|
!this.manager.isLevelUnlocked(this.user, this.world, this.manager.getLevel(this.challenge.getLevel())))
|
||||||
{
|
{
|
||||||
this.user.sendMessage("challenges.errors.challenge-level-not-available");
|
this.user.sendMessage("challenges.errors.challenge-level-not-available");
|
||||||
|
result = EMPTY_RESULT;
|
||||||
}
|
}
|
||||||
// Check max times
|
// Check max times
|
||||||
else if (this.challenge.isRepeatable() && this.challenge.getMaxTimes() > 0 &&
|
else if (this.challenge.isRepeatable() && this.challenge.getMaxTimes() > 0 &&
|
||||||
this.manager.getChallengeTimes(this.user, this.challenge) >= this.challenge.getMaxTimes())
|
this.manager.getChallengeTimes(this.user, this.challenge) >= this.challenge.getMaxTimes())
|
||||||
{
|
{
|
||||||
this.user.sendMessage("challenges.not-repeatable");
|
this.user.sendMessage("challenges.not-repeatable");
|
||||||
|
result = EMPTY_RESULT;
|
||||||
}
|
}
|
||||||
// Check repeatability
|
// Check repeatability
|
||||||
else if (this.manager.isChallengeComplete(this.user, this.challenge)
|
else if (this.manager.isChallengeComplete(this.user, this.challenge)
|
||||||
&& (!this.challenge.isRepeatable() || type.equals(ChallengeType.ISLAND)))
|
&& (!this.challenge.isRepeatable() || type.equals(ChallengeType.ISLAND)))
|
||||||
{
|
{
|
||||||
this.user.sendMessage("challenges.not-repeatable");
|
this.user.sendMessage("challenges.not-repeatable");
|
||||||
|
result = EMPTY_RESULT;
|
||||||
}
|
}
|
||||||
// Check environment
|
// Check environment
|
||||||
else if (!this.challenge.getEnvironment().isEmpty() &&
|
else if (!this.challenge.getEnvironment().isEmpty() &&
|
||||||
!this.challenge.getEnvironment().contains(this.user.getWorld().getEnvironment()))
|
!this.challenge.getEnvironment().contains(this.user.getWorld().getEnvironment()))
|
||||||
{
|
{
|
||||||
this.user.sendMessage("challenges.errors.wrong-environment");
|
this.user.sendMessage("challenges.errors.wrong-environment");
|
||||||
|
result = EMPTY_RESULT;
|
||||||
}
|
}
|
||||||
// Check permission
|
// Check permission
|
||||||
else if (!this.checkPermissions())
|
else if (!this.checkPermissions())
|
||||||
{
|
{
|
||||||
this.user.sendMessage("general.errors.no-permission");
|
this.user.sendMessage("general.errors.no-permission");
|
||||||
|
result = EMPTY_RESULT;
|
||||||
}
|
}
|
||||||
else if (type.equals(ChallengeType.INVENTORY))
|
else if (type.equals(ChallengeType.INVENTORY))
|
||||||
{
|
{
|
||||||
return this.checkInventory();
|
result = this.checkInventory();
|
||||||
}
|
}
|
||||||
else if (type.equals(ChallengeType.ISLAND))
|
else if (type.equals(ChallengeType.ISLAND))
|
||||||
{
|
{
|
||||||
return this.checkSurrounding();
|
result = this.checkSurrounding();
|
||||||
}
|
}
|
||||||
else if (type.equals(ChallengeType.OTHER))
|
else if (type.equals(ChallengeType.OTHER))
|
||||||
{
|
{
|
||||||
return this.checkOthers();
|
result = this.checkOthers();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = EMPTY_RESULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Everything fails till this point.
|
// Everything fails till this point.
|
||||||
return new ChallengeResult();
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -407,7 +423,7 @@ public class TryToComplete
|
|||||||
this.user.sendMessage("challenges.error.not-enough-items",
|
this.user.sendMessage("challenges.error.not-enough-items",
|
||||||
"[items]",
|
"[items]",
|
||||||
Util.prettifyText(req.getType().toString()));
|
Util.prettifyText(req.getType().toString()));
|
||||||
return new ChallengeResult();
|
return EMPTY_RESULT;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -417,7 +433,7 @@ public class TryToComplete
|
|||||||
this.user.sendMessage("challenges.error.not-enough-items",
|
this.user.sendMessage("challenges.error.not-enough-items",
|
||||||
"[items]",
|
"[items]",
|
||||||
Util.prettifyText(req.getType().toString()));
|
Util.prettifyText(req.getType().toString()));
|
||||||
return new ChallengeResult();
|
return EMPTY_RESULT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -500,7 +516,7 @@ public class TryToComplete
|
|||||||
{
|
{
|
||||||
// Player is not on island
|
// Player is not on island
|
||||||
this.user.sendMessage("challenges.error.not-on-island");
|
this.user.sendMessage("challenges.error.not-on-island");
|
||||||
result = new ChallengeResult();
|
result = EMPTY_RESULT;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -569,7 +585,7 @@ public class TryToComplete
|
|||||||
"[amount]", String.valueOf(v),
|
"[amount]", String.valueOf(v),
|
||||||
"[item]", Util.prettifyText(k.toString())));
|
"[item]", Util.prettifyText(k.toString())));
|
||||||
|
|
||||||
return new ChallengeResult();
|
return EMPTY_RESULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -598,7 +614,7 @@ public class TryToComplete
|
|||||||
"[amount]", String.valueOf(amount),
|
"[amount]", String.valueOf(amount),
|
||||||
"[item]", Util.prettifyText(reqEnt.toString())));
|
"[item]", Util.prettifyText(reqEnt.toString())));
|
||||||
|
|
||||||
return new ChallengeResult();
|
return EMPTY_RESULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -703,7 +719,7 @@ public class TryToComplete
|
|||||||
return new ChallengeResult().setMeetsRequirements();
|
return new ChallengeResult().setMeetsRequirements();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ChallengeResult();
|
return EMPTY_RESULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user