2018-12-30 14:31:26 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package world.bentobox.challenges.panel;
|
|
|
|
|
|
|
|
|
2019-02-14 09:28:06 +01:00
|
|
|
import org.bukkit.GameMode;
|
2018-12-30 14:31:26 +01:00
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.World;
|
2019-01-24 22:29:56 +01:00
|
|
|
import org.bukkit.block.Block;
|
2018-12-30 14:31:26 +01:00
|
|
|
import org.bukkit.entity.EntityType;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.util.Vector;
|
2019-01-24 22:29:56 +01:00
|
|
|
import java.util.*;
|
|
|
|
import java.util.stream.Collectors;
|
2018-12-30 14:31:26 +01:00
|
|
|
|
2019-01-24 22:29:56 +01:00
|
|
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
|
|
|
import world.bentobox.bentobox.api.user.User;
|
|
|
|
import world.bentobox.bentobox.util.Util;
|
2018-12-30 14:31:26 +01:00
|
|
|
import world.bentobox.challenges.ChallengesAddon;
|
|
|
|
import world.bentobox.challenges.ChallengesManager;
|
2019-01-23 15:09:38 +01:00
|
|
|
import world.bentobox.challenges.database.object.Challenge;
|
|
|
|
import world.bentobox.challenges.database.object.Challenge.ChallengeType;
|
2019-01-24 23:54:21 +01:00
|
|
|
import world.bentobox.challenges.database.object.ChallengeLevel;
|
2019-01-24 22:29:56 +01:00
|
|
|
|
2018-12-30 14:31:26 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Run when a user tries to complete a challenge
|
|
|
|
* @author tastybento
|
|
|
|
*
|
|
|
|
*/
|
2019-01-24 22:29:56 +01:00
|
|
|
public class TryToComplete
|
|
|
|
{
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Section: Variables
|
|
|
|
// ---------------------------------------------------------------------
|
2018-12-30 14:31:26 +01:00
|
|
|
|
2019-01-24 22:29:56 +01:00
|
|
|
/**
|
|
|
|
* Challenges addon variable.
|
|
|
|
*/
|
2018-12-30 14:31:26 +01:00
|
|
|
private ChallengesAddon addon;
|
2019-01-24 22:29:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Challenges manager for addon.
|
|
|
|
*/
|
|
|
|
private ChallengesManager manager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* World where all checks are necessary.
|
|
|
|
*/
|
2018-12-30 14:31:26 +01:00
|
|
|
private World world;
|
2019-01-24 22:29:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* User who is completing challenge.
|
|
|
|
*/
|
2018-12-30 14:31:26 +01:00
|
|
|
private User user;
|
2019-01-24 22:29:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Permission prefix string.
|
|
|
|
*/
|
|
|
|
private String permissionPrefix;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Top command first label.
|
|
|
|
*/
|
|
|
|
private String topLabel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Challenge that should be completed.
|
|
|
|
*/
|
2019-01-23 15:09:38 +01:00
|
|
|
private Challenge challenge;
|
2018-12-30 14:31:26 +01:00
|
|
|
|
2019-01-24 23:28:12 +01:00
|
|
|
/**
|
|
|
|
* Variable that will be used to avoid multiple empty object generation.
|
|
|
|
*/
|
|
|
|
private final ChallengeResult EMPTY_RESULT = new ChallengeResult();
|
2019-01-24 22:29:56 +01:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Section: Builder
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
public TryToComplete label(String label)
|
|
|
|
{
|
|
|
|
this.topLabel = label;
|
2018-12-30 14:31:26 +01:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2019-01-24 22:29:56 +01:00
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
public TryToComplete user(User user)
|
|
|
|
{
|
2018-12-30 14:31:26 +01:00
|
|
|
this.user = user;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2019-01-24 22:29:56 +01:00
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
public TryToComplete manager(ChallengesManager manager)
|
|
|
|
{
|
2018-12-30 14:31:26 +01:00
|
|
|
this.manager = manager;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2019-01-24 22:29:56 +01:00
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
public TryToComplete challenge(Challenge challenge)
|
|
|
|
{
|
2018-12-30 14:31:26 +01:00
|
|
|
this.challenge = challenge;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2019-01-24 22:29:56 +01:00
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
public TryToComplete world(World world)
|
|
|
|
{
|
2018-12-30 14:31:26 +01:00
|
|
|
this.world = world;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2019-01-24 22:29:56 +01:00
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
public TryToComplete permPrefix(String prefix)
|
|
|
|
{
|
|
|
|
this.permissionPrefix = prefix;
|
2018-12-30 14:31:26 +01:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2019-01-24 22:29:56 +01:00
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
public TryToComplete(ChallengesAddon addon)
|
|
|
|
{
|
2018-12-30 14:31:26 +01:00
|
|
|
this.addon = addon;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-24 22:29:56 +01:00
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Section: Constructor
|
|
|
|
// ---------------------------------------------------------------------
|
2018-12-30 14:31:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2019-01-24 22:29:56 +01:00
|
|
|
* @param addon - Challenges Addon.
|
|
|
|
* @param user - User who performs challenge.
|
|
|
|
* @param challenge - Challenge that should be completed.
|
|
|
|
* @param world - World where completion may occur.
|
|
|
|
* @param topLabel - Label of the top command.
|
|
|
|
* @param permissionPrefix - Permission prefix for GameMode addon.
|
2018-12-30 14:31:26 +01:00
|
|
|
*/
|
2019-01-24 22:29:56 +01:00
|
|
|
public TryToComplete(ChallengesAddon addon,
|
|
|
|
User user,
|
|
|
|
Challenge challenge,
|
|
|
|
World world,
|
|
|
|
String topLabel,
|
|
|
|
String permissionPrefix)
|
|
|
|
{
|
2018-12-30 14:31:26 +01:00
|
|
|
this.addon = addon;
|
|
|
|
this.world = world;
|
2019-01-24 22:29:56 +01:00
|
|
|
this.permissionPrefix = permissionPrefix;
|
2018-12-30 14:31:26 +01:00
|
|
|
this.user = user;
|
2019-01-24 22:29:56 +01:00
|
|
|
this.manager = addon.getChallengesManager();
|
2018-12-30 14:31:26 +01:00
|
|
|
this.challenge = challenge;
|
2019-01-24 22:29:56 +01:00
|
|
|
this.topLabel = topLabel;
|
2019-01-28 20:01:26 +01:00
|
|
|
}
|
|
|
|
|
2018-12-30 14:31:26 +01:00
|
|
|
|
2019-01-28 20:01:26 +01:00
|
|
|
/**
|
|
|
|
* This static method allows complete challenge and get result about completion.
|
|
|
|
* @param addon - Challenges Addon.
|
|
|
|
* @param user - User who performs challenge.
|
|
|
|
* @param challenge - Challenge that should be completed.
|
|
|
|
* @param world - World where completion may occur.
|
|
|
|
* @param topLabel - Label of the top command.
|
|
|
|
* @param permissionPrefix - Permission prefix for GameMode addon.
|
|
|
|
* @return true, if challenge is completed, otherwise false.
|
|
|
|
*/
|
|
|
|
public static boolean complete(ChallengesAddon addon,
|
|
|
|
User user,
|
|
|
|
Challenge challenge,
|
|
|
|
World world,
|
|
|
|
String topLabel,
|
|
|
|
String permissionPrefix)
|
|
|
|
{
|
|
|
|
return new TryToComplete(addon, user, challenge, world, topLabel, permissionPrefix).
|
|
|
|
build().meetsRequirements;
|
2019-01-24 22:29:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Section: Methods
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method checks if challenge can be done, and complete it, if it is possible.
|
|
|
|
* @return ChallengeResult object, that contains completion status.
|
|
|
|
*/
|
|
|
|
public ChallengeResult build()
|
|
|
|
{
|
2018-12-30 14:31:26 +01:00
|
|
|
// Check if can complete challenge
|
2019-01-24 22:29:56 +01:00
|
|
|
ChallengeResult result = this.checkIfCanCompleteChallenge();
|
|
|
|
|
|
|
|
if (!result.meetsRequirements)
|
|
|
|
{
|
|
|
|
return result;
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
2019-01-24 22:29:56 +01:00
|
|
|
|
|
|
|
if (!result.repeat)
|
|
|
|
{
|
|
|
|
// Item rewards
|
|
|
|
for (ItemStack reward : this.challenge.getRewardItems())
|
|
|
|
{
|
2019-02-14 13:20:08 +01:00
|
|
|
// Clone is necessary because otherwise it will chane reward itemstack
|
|
|
|
// amount.
|
|
|
|
this.user.getInventory().addItem(reward.clone()).forEach((k, v) ->
|
2019-01-24 22:29:56 +01:00
|
|
|
this.user.getWorld().dropItem(this.user.getLocation(), v));
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
|
|
|
|
2019-01-24 22:29:56 +01:00
|
|
|
// Money Reward
|
|
|
|
if (this.addon.isEconomyProvided())
|
|
|
|
{
|
|
|
|
this.addon.getEconomyProvider().deposit(this.user, this.challenge.getRewardMoney());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Experience Reward
|
|
|
|
this.user.getPlayer().giveExp(this.challenge.getRewardExperience());
|
2018-12-30 14:31:26 +01:00
|
|
|
|
|
|
|
// Run commands
|
2019-01-24 22:29:56 +01:00
|
|
|
this.runCommands(this.challenge.getRewardCommands());
|
|
|
|
|
2019-02-12 00:38:16 +01:00
|
|
|
this.user.sendMessage("challenges.messages.you-completed-challenge", "[value]", this.challenge.getFriendlyName());
|
2019-01-24 22:29:56 +01:00
|
|
|
|
|
|
|
if (this.addon.getChallengesSettings().isBroadcastMessages())
|
|
|
|
{
|
2019-01-28 19:25:28 +01:00
|
|
|
for (Player player : this.addon.getServer().getOnlinePlayers())
|
2019-01-24 22:29:56 +01:00
|
|
|
{
|
2019-01-28 19:25:28 +01:00
|
|
|
// Only other players should see message.
|
|
|
|
if (!player.getUniqueId().equals(this.user.getUniqueId()))
|
|
|
|
{
|
2019-02-12 00:38:16 +01:00
|
|
|
User.getInstance(player).sendMessage("challenges.messages.name-has-completed-challenge",
|
|
|
|
"[name]", this.user.getName(),
|
|
|
|
"[value]", this.challenge.getFriendlyName());
|
2019-01-28 19:25:28 +01:00
|
|
|
}
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
|
|
|
}
|
2019-01-24 22:29:56 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Item Repeat Rewards
|
|
|
|
for (ItemStack reward : this.challenge.getRepeatItemReward())
|
|
|
|
{
|
2019-02-14 13:20:08 +01:00
|
|
|
// Clone is necessary because otherwise it will chane reward itemstack
|
|
|
|
// amount.
|
|
|
|
this.user.getInventory().addItem(reward.clone()).forEach((k, v) ->
|
2019-01-24 22:29:56 +01:00
|
|
|
this.user.getWorld().dropItem(this.user.getLocation(), v));
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
|
|
|
|
2019-01-24 22:29:56 +01:00
|
|
|
// Money Repeat Reward
|
|
|
|
if (this.addon.isEconomyProvided())
|
|
|
|
{
|
|
|
|
this.addon.getEconomyProvider().deposit(this.user, this.challenge.getRepeatMoneyReward());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Experience Repeat Reward
|
|
|
|
this.user.getPlayer().giveExp(this.challenge.getRepeatExperienceReward());
|
2018-12-30 14:31:26 +01:00
|
|
|
|
|
|
|
// Run commands
|
2019-01-24 22:29:56 +01:00
|
|
|
this.runCommands(this.challenge.getRepeatRewardCommands());
|
|
|
|
|
2019-02-12 00:38:16 +01:00
|
|
|
this.user.sendMessage("challenges.messages.you-repeated-challenge", "[value]", this.challenge.getFriendlyName());
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
2019-01-24 22:29:56 +01:00
|
|
|
|
2018-12-30 14:31:26 +01:00
|
|
|
// Mark as complete
|
2019-02-18 00:29:42 +01:00
|
|
|
this.manager.setChallengeComplete(this.user, this.world, this.challenge);
|
2019-01-24 22:29:56 +01:00
|
|
|
|
2019-01-24 23:54:21 +01:00
|
|
|
if (!result.repeat)
|
|
|
|
{
|
|
|
|
ChallengeLevel level = this.manager.getLevel(this.challenge);
|
|
|
|
|
2019-02-18 00:29:42 +01:00
|
|
|
if (!this.manager.isLevelCompleted(this.user, this.world, level))
|
2019-01-24 23:54:21 +01:00
|
|
|
{
|
2019-02-18 00:29:42 +01:00
|
|
|
if (this.manager.validateLevelCompletion(this.user, this.world, level))
|
2019-01-24 23:54:21 +01:00
|
|
|
{
|
|
|
|
// Item rewards
|
|
|
|
for (ItemStack reward : level.getRewardItems())
|
|
|
|
{
|
2019-02-14 13:20:08 +01:00
|
|
|
// Clone is necessary because otherwise it will chane reward itemstack
|
|
|
|
// amount.
|
|
|
|
this.user.getInventory().addItem(reward.clone()).forEach((k, v) ->
|
2019-01-24 23:54:21 +01:00
|
|
|
this.user.getWorld().dropItem(this.user.getLocation(), v));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Money Reward
|
|
|
|
if (this.addon.isEconomyProvided())
|
|
|
|
{
|
|
|
|
this.addon.getEconomyProvider().deposit(this.user, level.getRewardMoney());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Experience Reward
|
|
|
|
this.user.getPlayer().giveExp(level.getRewardExperience());
|
|
|
|
|
|
|
|
// Run commands
|
|
|
|
this.runCommands(level.getRewardCommands());
|
|
|
|
|
2019-02-12 00:38:16 +01:00
|
|
|
this.user.sendMessage("challenges.messages.you-completed-level", "[value]", level.getFriendlyName());
|
2019-01-24 23:54:21 +01:00
|
|
|
|
|
|
|
if (this.addon.getChallengesSettings().isBroadcastMessages())
|
|
|
|
{
|
2019-01-28 19:25:28 +01:00
|
|
|
for (Player player : this.addon.getServer().getOnlinePlayers())
|
2019-01-24 23:54:21 +01:00
|
|
|
{
|
2019-01-28 19:25:28 +01:00
|
|
|
// Only other players should see message.
|
|
|
|
if (!player.getUniqueId().equals(this.user.getUniqueId()))
|
|
|
|
{
|
2019-02-12 00:38:16 +01:00
|
|
|
User.getInstance(player).sendMessage("challenges.messages.name-has-completed-level",
|
|
|
|
"[name]", this.user.getName(), "[value]", level.getFriendlyName());
|
2019-01-28 19:25:28 +01:00
|
|
|
}
|
2019-01-24 23:54:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-18 00:29:42 +01:00
|
|
|
this.manager.setLevelComplete(this.user, this.world, level);
|
2019-01-24 23:54:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-24 22:29:56 +01:00
|
|
|
return result;
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
|
|
|
|
2019-01-24 22:29:56 +01:00
|
|
|
|
2018-12-30 14:31:26 +01:00
|
|
|
/**
|
|
|
|
* Checks if a challenge can be completed or not
|
2019-01-24 22:29:56 +01:00
|
|
|
* It returns ChallengeResult.
|
2018-12-30 14:31:26 +01:00
|
|
|
*/
|
2019-01-24 22:29:56 +01:00
|
|
|
private ChallengeResult checkIfCanCompleteChallenge()
|
|
|
|
{
|
2019-01-24 23:28:12 +01:00
|
|
|
ChallengeResult result;
|
|
|
|
|
2019-01-24 22:29:56 +01:00
|
|
|
ChallengeType type = this.challenge.getChallengeType();
|
|
|
|
|
2018-12-30 14:31:26 +01:00
|
|
|
// Check the world
|
2019-01-26 12:58:00 +01:00
|
|
|
if (!this.challenge.isDeployed())
|
|
|
|
{
|
2019-02-12 00:38:16 +01:00
|
|
|
this.user.sendMessage("challenges.errors.not-deployed");
|
2019-01-26 12:58:00 +01:00
|
|
|
result = EMPTY_RESULT;
|
|
|
|
}
|
|
|
|
else if (Util.getWorld(this.world) != Util.getWorld(this.user.getWorld()) ||
|
2019-01-26 12:47:56 +01:00
|
|
|
!this.challenge.getUniqueId().startsWith(Util.getWorld(this.world).getName()))
|
2019-01-24 22:29:56 +01:00
|
|
|
{
|
|
|
|
this.user.sendMessage("general.errors.wrong-world");
|
2019-01-24 23:28:12 +01:00
|
|
|
result = EMPTY_RESULT;
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
2019-01-26 12:47:56 +01:00
|
|
|
// Player is not on island
|
|
|
|
else if (!this.addon.getIslands().userIsOnIsland(this.user.getWorld(), this.user))
|
|
|
|
{
|
2019-02-12 00:38:16 +01:00
|
|
|
this.user.sendMessage("challenges.errors.not-on-island");
|
2019-01-26 12:47:56 +01:00
|
|
|
result = EMPTY_RESULT;
|
|
|
|
}
|
2019-01-24 22:29:56 +01:00
|
|
|
// Check if user has unlocked challenges level.
|
|
|
|
else if (!this.challenge.getLevel().equals(ChallengesManager.FREE) &&
|
2019-02-18 00:29:42 +01:00
|
|
|
!this.manager.isLevelUnlocked(this.user, this.world, this.manager.getLevel(this.challenge.getLevel())))
|
2019-01-24 22:29:56 +01:00
|
|
|
{
|
|
|
|
this.user.sendMessage("challenges.errors.challenge-level-not-available");
|
2019-01-24 23:28:12 +01:00
|
|
|
result = EMPTY_RESULT;
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
|
|
|
// Check max times
|
2019-01-24 22:29:56 +01:00
|
|
|
else if (this.challenge.isRepeatable() && this.challenge.getMaxTimes() > 0 &&
|
2019-02-18 00:29:42 +01:00
|
|
|
this.manager.getChallengeTimes(this.user, this.world, this.challenge) >= this.challenge.getMaxTimes())
|
2019-01-24 22:29:56 +01:00
|
|
|
{
|
2019-02-12 00:38:16 +01:00
|
|
|
this.user.sendMessage("challenges.errors.not-repeatable");
|
2019-01-24 23:28:12 +01:00
|
|
|
result = EMPTY_RESULT;
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
|
|
|
// Check repeatability
|
2019-02-18 00:29:42 +01:00
|
|
|
else if (!this.challenge.isRepeatable() && this.manager.isChallengeComplete(this.user, this.world, this.challenge))
|
2019-01-24 22:29:56 +01:00
|
|
|
{
|
2019-02-12 00:38:16 +01:00
|
|
|
this.user.sendMessage("challenges.errors.not-repeatable");
|
2019-01-24 23:28:12 +01:00
|
|
|
result = EMPTY_RESULT;
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
2019-01-24 22:57:50 +01:00
|
|
|
// Check environment
|
|
|
|
else if (!this.challenge.getEnvironment().isEmpty() &&
|
|
|
|
!this.challenge.getEnvironment().contains(this.user.getWorld().getEnvironment()))
|
|
|
|
{
|
2019-01-24 23:20:33 +01:00
|
|
|
this.user.sendMessage("challenges.errors.wrong-environment");
|
2019-01-24 23:28:12 +01:00
|
|
|
result = EMPTY_RESULT;
|
2019-01-24 23:20:33 +01:00
|
|
|
}
|
|
|
|
// Check permission
|
|
|
|
else if (!this.checkPermissions())
|
|
|
|
{
|
|
|
|
this.user.sendMessage("general.errors.no-permission");
|
2019-01-24 23:28:12 +01:00
|
|
|
result = EMPTY_RESULT;
|
2019-01-24 22:57:50 +01:00
|
|
|
}
|
2019-01-24 22:29:56 +01:00
|
|
|
else if (type.equals(ChallengeType.INVENTORY))
|
2018-12-30 14:31:26 +01:00
|
|
|
{
|
2019-01-24 23:28:12 +01:00
|
|
|
result = this.checkInventory();
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
2019-01-24 22:29:56 +01:00
|
|
|
else if (type.equals(ChallengeType.ISLAND))
|
2018-12-30 14:31:26 +01:00
|
|
|
{
|
2019-01-24 23:28:12 +01:00
|
|
|
result = this.checkSurrounding();
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
2019-01-24 22:29:56 +01:00
|
|
|
else if (type.equals(ChallengeType.OTHER))
|
|
|
|
{
|
2019-01-24 23:28:12 +01:00
|
|
|
result = this.checkOthers();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = EMPTY_RESULT;
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
2019-01-24 22:29:56 +01:00
|
|
|
|
|
|
|
// Everything fails till this point.
|
2019-01-24 23:28:12 +01:00
|
|
|
return result;
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-24 23:20:33 +01:00
|
|
|
/**
|
|
|
|
* This method checks if user has all required permissions.
|
|
|
|
* @return true if user has all required permissions, otherwise false.
|
|
|
|
*/
|
|
|
|
private boolean checkPermissions()
|
|
|
|
{
|
|
|
|
return this.challenge.getRequiredPermissions().isEmpty() ||
|
|
|
|
this.challenge.getRequiredPermissions().stream().allMatch(s -> this.user.hasPermission(s));
|
|
|
|
}
|
|
|
|
|
2019-01-24 22:29:56 +01:00
|
|
|
/**
|
|
|
|
* This method runs all commands from command list.
|
|
|
|
* @param commands List of commands that must be performed.
|
|
|
|
*/
|
|
|
|
private void runCommands(List<String> commands)
|
|
|
|
{
|
|
|
|
// Ignore commands with this perm
|
|
|
|
if (user.hasPermission(this.permissionPrefix + "command.challengeexempt") && !user.isOp())
|
|
|
|
{
|
|
|
|
return;
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
2019-01-24 22:29:56 +01:00
|
|
|
for (String cmd : commands)
|
|
|
|
{
|
|
|
|
if (cmd.startsWith("[SELF]"))
|
|
|
|
{
|
|
|
|
String alert = "Running command '" + cmd + "' as " + this.user.getName();
|
|
|
|
this.addon.getLogger().info(alert);
|
|
|
|
cmd = cmd.substring(6, cmd.length()).replace("[player]", this.user.getName()).trim();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (!user.performCommand(cmd))
|
|
|
|
{
|
|
|
|
this.showError(cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
this.showError(cmd);
|
|
|
|
}
|
2018-12-30 14:31:26 +01:00
|
|
|
|
2019-01-24 22:29:56 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Substitute in any references to player
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (!this.addon.getServer().dispatchCommand(this.addon.getServer().getConsoleSender(),
|
|
|
|
cmd.replace("[player]", this.user.getName())))
|
|
|
|
{
|
|
|
|
this.showError(cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
this.showError(cmd);
|
|
|
|
}
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
2019-01-24 22:29:56 +01:00
|
|
|
}
|
2018-12-30 14:31:26 +01:00
|
|
|
|
|
|
|
|
2019-01-24 22:29:56 +01:00
|
|
|
/**
|
|
|
|
* Throws error message.
|
|
|
|
* @param cmd Error message that appear after failing some command.
|
|
|
|
*/
|
|
|
|
private void showError(final String cmd)
|
|
|
|
{
|
|
|
|
this.addon.getLogger().severe("Problem executing command executed by player - skipping!");
|
|
|
|
this.addon.getLogger().severe(() -> "Command was : " + cmd);
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-24 22:29:56 +01:00
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Section: Inventory Challenge
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2018-12-30 14:31:26 +01:00
|
|
|
/**
|
2019-01-24 22:29:56 +01:00
|
|
|
* Checks if a inventory challenge can be completed or not
|
|
|
|
* It returns ChallengeResult.
|
|
|
|
*/
|
|
|
|
private ChallengeResult checkInventory()
|
2018-12-30 14:31:26 +01:00
|
|
|
{
|
2019-01-24 22:29:56 +01:00
|
|
|
// Run through inventory
|
|
|
|
List<ItemStack> required = new ArrayList<>(this.challenge.getRequiredItems());
|
2019-02-14 09:28:06 +01:00
|
|
|
|
|
|
|
// Players in creative game mode has got all items. No point to search for them.
|
|
|
|
if (this.user.getPlayer().getGameMode() != GameMode.CREATIVE)
|
2019-01-24 22:29:56 +01:00
|
|
|
{
|
2019-02-14 09:28:06 +01:00
|
|
|
for (ItemStack req : required)
|
2019-01-24 22:29:56 +01:00
|
|
|
{
|
2019-02-14 09:28:06 +01:00
|
|
|
// Check for FIREWORK_ROCKET, ENCHANTED_BOOK, WRITTEN_BOOK, POTION and
|
|
|
|
// FILLED_MAP because these have unique meta when created
|
|
|
|
switch (req.getType())
|
|
|
|
{
|
|
|
|
case FIREWORK_ROCKET:
|
|
|
|
case ENCHANTED_BOOK:
|
|
|
|
case WRITTEN_BOOK:
|
|
|
|
case FILLED_MAP:
|
|
|
|
// Get how many items are in the inventory. Item stacks amounts need to be summed
|
|
|
|
int numInInventory =
|
|
|
|
Arrays.stream(this.user.getInventory().getContents()).
|
|
|
|
filter(Objects::nonNull).
|
|
|
|
filter(i -> i.getType().equals(req.getType())).
|
|
|
|
mapToInt(ItemStack::getAmount).
|
|
|
|
sum();
|
|
|
|
|
|
|
|
if (numInInventory < req.getAmount())
|
|
|
|
{
|
|
|
|
this.user.sendMessage("challenges.errors.not-enough-items",
|
|
|
|
"[items]",
|
|
|
|
Util.prettifyText(req.getType().toString()));
|
|
|
|
return EMPTY_RESULT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// General checking
|
|
|
|
if (!this.user.getInventory().containsAtLeast(req, req.getAmount()))
|
|
|
|
{
|
|
|
|
this.user.sendMessage("challenges.errors.not-enough-items",
|
|
|
|
"[items]",
|
|
|
|
Util.prettifyText(req.getType().toString()));
|
|
|
|
return EMPTY_RESULT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2019-01-24 22:29:56 +01:00
|
|
|
}
|
|
|
|
|
2019-02-14 09:28:06 +01:00
|
|
|
// If remove items, then remove them
|
2018-12-30 14:31:26 +01:00
|
|
|
|
2019-02-14 09:28:06 +01:00
|
|
|
if (this.challenge.isTakeItems())
|
|
|
|
{
|
|
|
|
this.removeItems(required);
|
|
|
|
}
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
2019-01-24 22:29:56 +01:00
|
|
|
|
|
|
|
// Return the result
|
|
|
|
return new ChallengeResult().setMeetsRequirements().setRepeat(
|
2019-02-18 00:29:42 +01:00
|
|
|
this.manager.isChallengeComplete(this.user, this.world, this.challenge));
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes items from a user's inventory
|
|
|
|
* @param required - a list of item stacks to be removed
|
|
|
|
*/
|
2019-01-24 22:29:56 +01:00
|
|
|
Map<Material, Integer> removeItems(List<ItemStack> required)
|
|
|
|
{
|
2018-12-30 14:31:26 +01:00
|
|
|
Map<Material, Integer> removed = new HashMap<>();
|
2019-01-24 22:29:56 +01:00
|
|
|
|
|
|
|
for (ItemStack req : required)
|
|
|
|
{
|
2018-12-30 14:31:26 +01:00
|
|
|
int amountToBeRemoved = req.getAmount();
|
2019-01-24 22:29:56 +01:00
|
|
|
List<ItemStack> itemsInInv = Arrays.stream(user.getInventory().getContents()).
|
|
|
|
filter(Objects::nonNull).
|
|
|
|
filter(i -> i.getType().equals(req.getType())).
|
|
|
|
collect(Collectors.toList());
|
|
|
|
|
|
|
|
for (ItemStack i : itemsInInv)
|
|
|
|
{
|
|
|
|
if (amountToBeRemoved > 0)
|
|
|
|
{
|
2018-12-30 14:31:26 +01:00
|
|
|
// Remove either the full amount or the remaining amount
|
2019-01-24 22:29:56 +01:00
|
|
|
if (i.getAmount() >= amountToBeRemoved)
|
|
|
|
{
|
2018-12-30 14:31:26 +01:00
|
|
|
i.setAmount(i.getAmount() - amountToBeRemoved);
|
|
|
|
removed.merge(i.getType(), amountToBeRemoved, Integer::sum);
|
|
|
|
amountToBeRemoved = 0;
|
2019-01-24 22:29:56 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-30 14:31:26 +01:00
|
|
|
removed.merge(i.getType(), i.getAmount(), Integer::sum);
|
|
|
|
amountToBeRemoved -= i.getAmount();
|
|
|
|
i.setAmount(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-24 22:29:56 +01:00
|
|
|
|
|
|
|
if (amountToBeRemoved > 0)
|
|
|
|
{
|
|
|
|
this.addon.logError("Could not remove " + amountToBeRemoved + " of " + req.getType() +
|
|
|
|
" from player's inventory!");
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
|
|
|
}
|
2019-01-24 22:29:56 +01:00
|
|
|
|
2018-12-30 14:31:26 +01:00
|
|
|
return removed;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-24 22:29:56 +01:00
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Section: Island Challenge
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if a island challenge can be completed or not
|
|
|
|
* It returns ChallengeResult.
|
|
|
|
*/
|
|
|
|
private ChallengeResult checkSurrounding()
|
|
|
|
{
|
|
|
|
ChallengeResult result;
|
|
|
|
|
2019-01-26 12:47:56 +01:00
|
|
|
if (!this.addon.getIslands().userIsOnIsland(this.user.getWorld(), this.user))
|
2019-01-24 22:29:56 +01:00
|
|
|
{
|
2018-12-30 14:31:26 +01:00
|
|
|
// Player is not on island
|
2019-02-12 00:38:16 +01:00
|
|
|
this.user.sendMessage("challenges.errors.not-on-island");
|
2019-01-24 23:28:12 +01:00
|
|
|
result = EMPTY_RESULT;
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
2019-01-24 22:29:56 +01:00
|
|
|
else
|
2018-12-30 14:31:26 +01:00
|
|
|
{
|
2019-01-24 22:29:56 +01:00
|
|
|
// Check for items or entities in the area
|
|
|
|
|
|
|
|
result = this.searchForEntities(this.challenge.getRequiredEntities(), this.challenge.getSearchRadius());
|
|
|
|
|
|
|
|
if (result.meetsRequirements && !this.challenge.getRequiredBlocks().isEmpty())
|
|
|
|
{
|
|
|
|
// Search for items only if entities found
|
|
|
|
result = this.searchForBlocks(this.challenge.getRequiredBlocks(), this.challenge.getSearchRadius());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result.meetsRequirements &&
|
|
|
|
this.challenge.isRemoveEntities() &&
|
|
|
|
!this.challenge.getRequiredEntities().isEmpty())
|
|
|
|
{
|
|
|
|
this.removeEntities();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result.meetsRequirements &&
|
|
|
|
this.challenge.isRemoveBlocks() &&
|
|
|
|
!this.challenge.getRequiredBlocks().isEmpty())
|
|
|
|
{
|
|
|
|
this.removeBlocks();
|
|
|
|
}
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-01-24 22:29:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This method search required blocks in given radius from user position.
|
|
|
|
* @param map RequiredBlock Map.
|
|
|
|
* @param searchRadius Search distance
|
|
|
|
* @return ChallengeResult
|
|
|
|
*/
|
|
|
|
private ChallengeResult searchForBlocks(Map<Material, Integer> map, int searchRadius)
|
|
|
|
{
|
2018-12-30 14:31:26 +01:00
|
|
|
Map<Material, Integer> blocks = new EnumMap<>(map);
|
2019-01-24 22:29:56 +01:00
|
|
|
|
|
|
|
for (int x = -searchRadius; x <= searchRadius; x++)
|
|
|
|
{
|
|
|
|
for (int y = -searchRadius; y <= searchRadius; y++)
|
|
|
|
{
|
|
|
|
for (int z = -searchRadius; z <= searchRadius; z++)
|
|
|
|
{
|
|
|
|
Material mat = this.user.getWorld().getBlockAt(this.user.getLocation().add(new Vector(x, y, z))).getType();
|
2018-12-30 14:31:26 +01:00
|
|
|
// Remove one
|
|
|
|
blocks.computeIfPresent(mat, (b, amount) -> amount - 1);
|
|
|
|
// Remove any that have an amount of 0
|
|
|
|
blocks.entrySet().removeIf(en -> en.getValue() <= 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-24 22:29:56 +01:00
|
|
|
|
|
|
|
if (blocks.isEmpty())
|
|
|
|
{
|
2018-12-30 14:31:26 +01:00
|
|
|
return new ChallengeResult().setMeetsRequirements();
|
|
|
|
}
|
2019-01-24 22:29:56 +01:00
|
|
|
|
2019-02-12 00:38:16 +01:00
|
|
|
this.user.sendMessage("challenges.errors.not-close-enough", "[number]", String.valueOf(searchRadius));
|
2019-01-24 22:29:56 +01:00
|
|
|
|
2019-02-12 00:38:16 +01:00
|
|
|
blocks.forEach((k, v) -> user.sendMessage("challenges.errors.you-still-need",
|
2019-01-24 22:29:56 +01:00
|
|
|
"[amount]", String.valueOf(v),
|
|
|
|
"[item]", Util.prettifyText(k.toString())));
|
2018-12-30 14:31:26 +01:00
|
|
|
|
2019-01-24 23:28:12 +01:00
|
|
|
return EMPTY_RESULT;
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
|
|
|
|
2019-01-24 22:29:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This method search required entities in given radius from user position.
|
|
|
|
* @param map RequiredEntities Map.
|
|
|
|
* @param searchRadius Search distance
|
|
|
|
* @return ChallengeResult
|
|
|
|
*/
|
|
|
|
private ChallengeResult searchForEntities(Map<EntityType, Integer> map, int searchRadius)
|
|
|
|
{
|
2018-12-30 14:31:26 +01:00
|
|
|
Map<EntityType, Integer> entities = map.isEmpty() ? new EnumMap<>(EntityType.class) : new EnumMap<>(map);
|
2019-01-24 22:29:56 +01:00
|
|
|
|
|
|
|
this.user.getPlayer().getNearbyEntities(searchRadius, searchRadius, searchRadius).forEach(entity -> {
|
2018-12-30 14:31:26 +01:00
|
|
|
// Look through all the nearby Entities, filtering by type
|
|
|
|
entities.computeIfPresent(entity.getType(), (reqEntity, amount) -> amount - 1);
|
|
|
|
entities.entrySet().removeIf(e -> e.getValue() == 0);
|
|
|
|
});
|
2019-01-24 22:29:56 +01:00
|
|
|
|
|
|
|
if (entities.isEmpty())
|
|
|
|
{
|
|
|
|
return new ChallengeResult().setMeetsRequirements();
|
|
|
|
}
|
|
|
|
|
2019-02-12 00:38:16 +01:00
|
|
|
entities.forEach((reqEnt, amount) -> this.user.sendMessage("challenges.errors.you-still-need",
|
2019-01-24 22:29:56 +01:00
|
|
|
"[amount]", String.valueOf(amount),
|
|
|
|
"[item]", Util.prettifyText(reqEnt.toString())));
|
|
|
|
|
2019-01-24 23:28:12 +01:00
|
|
|
return EMPTY_RESULT;
|
2019-01-24 22:29:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method removes required block and set air instead of it.
|
|
|
|
*/
|
|
|
|
private void removeBlocks()
|
|
|
|
{
|
|
|
|
Map<Material, Integer> blocks = new EnumMap<>(this.challenge.getRequiredBlocks());
|
|
|
|
int searchRadius = this.challenge.getSearchRadius();
|
|
|
|
|
|
|
|
for (int x = -searchRadius; x <= searchRadius; x++)
|
|
|
|
{
|
|
|
|
for (int y = -searchRadius; y <= searchRadius; y++)
|
|
|
|
{
|
|
|
|
for (int z = -searchRadius; z <= searchRadius; z++)
|
|
|
|
{
|
|
|
|
Block block = this.user.getWorld().getBlockAt(this.user.getLocation().add(new Vector(x, y, z)));
|
|
|
|
|
|
|
|
if (blocks.containsKey(block.getType()))
|
|
|
|
{
|
|
|
|
blocks.computeIfPresent(block.getType(), (b, amount) -> amount - 1);
|
|
|
|
blocks.entrySet().removeIf(en -> en.getValue() <= 0);
|
|
|
|
|
|
|
|
block.setType(Material.AIR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method removes required entities.
|
|
|
|
*/
|
|
|
|
private void removeEntities()
|
|
|
|
{
|
|
|
|
Map<EntityType, Integer> entities = this.challenge.getRequiredEntities().isEmpty() ?
|
|
|
|
new EnumMap<>(EntityType.class) : new EnumMap<>(this.challenge.getRequiredEntities());
|
|
|
|
|
|
|
|
int searchRadius = this.challenge.getSearchRadius();
|
|
|
|
|
|
|
|
this.user.getPlayer().getNearbyEntities(searchRadius, searchRadius, searchRadius).forEach(entity -> {
|
|
|
|
// Look through all the nearby Entities, filtering by type
|
|
|
|
|
|
|
|
if (entities.containsKey(entity.getType()))
|
|
|
|
{
|
|
|
|
entities.computeIfPresent(entity.getType(), (reqEntity, amount) -> amount - 1);
|
|
|
|
entities.entrySet().removeIf(e -> e.getValue() == 0);
|
|
|
|
entity.remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Section: Other challenge
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if a other challenge can be completed or not
|
|
|
|
* It returns ChallengeResult.
|
|
|
|
*/
|
|
|
|
private ChallengeResult checkOthers()
|
|
|
|
{
|
2019-01-30 18:11:27 +01:00
|
|
|
if (!this.addon.isLevelProvided() &&
|
|
|
|
this.challenge.getRequiredIslandLevel() != 0)
|
|
|
|
{
|
2019-02-12 00:38:16 +01:00
|
|
|
this.user.sendMessage("challenges.errors.missing-addon");
|
2019-01-30 18:11:27 +01:00
|
|
|
}
|
|
|
|
else if (!this.addon.isEconomyProvided() &&
|
|
|
|
this.challenge.getRequiredMoney() != 0)
|
|
|
|
{
|
2019-02-12 00:38:16 +01:00
|
|
|
this.user.sendMessage("challenges.errors.missing-addon");
|
2019-01-30 18:11:27 +01:00
|
|
|
}
|
|
|
|
else if (this.addon.isEconomyProvided() && this.challenge.getRequiredMoney() < 0)
|
|
|
|
{
|
2019-02-12 00:38:16 +01:00
|
|
|
this.user.sendMessage("challenges.errors.incorrect");
|
2019-01-30 18:11:27 +01:00
|
|
|
}
|
|
|
|
else if (this.addon.isEconomyProvided() &&
|
|
|
|
!this.addon.getEconomyProvider().has(this.user, this.challenge.getRequiredMoney()))
|
2019-01-24 22:29:56 +01:00
|
|
|
{
|
2019-02-12 00:38:16 +01:00
|
|
|
this.user.sendMessage("challenges.errors.not-enough-money",
|
|
|
|
"[value]",
|
2019-01-24 22:29:56 +01:00
|
|
|
Integer.toString(this.challenge.getRequiredMoney()));
|
|
|
|
}
|
2019-01-30 18:11:27 +01:00
|
|
|
else if (this.challenge.getRequiredExperience() < 0)
|
|
|
|
{
|
2019-02-12 00:38:16 +01:00
|
|
|
this.user.sendMessage("challenges.errors.incorrect");
|
2019-01-30 18:11:27 +01:00
|
|
|
}
|
2019-02-14 09:28:06 +01:00
|
|
|
else if (this.user.getPlayer().getTotalExperience() < this.challenge.getRequiredExperience() &&
|
|
|
|
this.user.getPlayer().getGameMode() != GameMode.CREATIVE)
|
2019-01-24 22:29:56 +01:00
|
|
|
{
|
2019-02-14 09:28:06 +01:00
|
|
|
// Players in creative gamemode has infinite amount of EXP.
|
|
|
|
|
2019-02-12 00:38:16 +01:00
|
|
|
this.user.sendMessage("challenges.errors.not-enough-experience",
|
|
|
|
"[value]",
|
2019-01-24 22:29:56 +01:00
|
|
|
Integer.toString(this.challenge.getRequiredExperience()));
|
|
|
|
}
|
2019-01-30 18:11:27 +01:00
|
|
|
else if (this.addon.isLevelProvided() &&
|
|
|
|
this.addon.getLevelAddon().getIslandLevel(this.world, this.user.getUniqueId()) < this.challenge.getRequiredIslandLevel())
|
2019-01-24 22:29:56 +01:00
|
|
|
{
|
2019-02-12 00:38:16 +01:00
|
|
|
this.user.sendMessage("challenges.errors.island-level",
|
2019-01-24 22:29:56 +01:00
|
|
|
TextVariables.NUMBER,
|
|
|
|
String.valueOf(this.challenge.getRequiredIslandLevel()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (this.addon.isEconomyProvided() && this.challenge.isTakeMoney())
|
|
|
|
{
|
|
|
|
this.addon.getEconomyProvider().withdraw(this.user, this.challenge.getRequiredMoney());
|
|
|
|
}
|
|
|
|
|
2019-02-14 09:28:06 +01:00
|
|
|
if (this.challenge.isTakeExperience() &&
|
|
|
|
this.user.getPlayer().getGameMode() != GameMode.CREATIVE)
|
2019-01-24 22:29:56 +01:00
|
|
|
{
|
2019-02-14 09:28:06 +01:00
|
|
|
// Cannot take anything from creative game mode.
|
2019-01-24 22:29:56 +01:00
|
|
|
this.user.getPlayer().setTotalExperience(
|
|
|
|
this.user.getPlayer().getTotalExperience() - this.challenge.getRequiredExperience());
|
|
|
|
}
|
|
|
|
|
2018-12-30 14:31:26 +01:00
|
|
|
return new ChallengeResult().setMeetsRequirements();
|
|
|
|
}
|
2019-01-24 22:29:56 +01:00
|
|
|
|
2019-01-24 23:28:12 +01:00
|
|
|
return EMPTY_RESULT;
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-24 22:29:56 +01:00
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Section: Private classes
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2018-12-30 14:31:26 +01:00
|
|
|
/**
|
|
|
|
* Contains flags on completion of challenge
|
|
|
|
*
|
2019-01-24 22:29:56 +01:00
|
|
|
* @author tastybento
|
2018-12-30 14:31:26 +01:00
|
|
|
*/
|
2019-01-24 22:29:56 +01:00
|
|
|
private class ChallengeResult
|
|
|
|
{
|
2018-12-30 14:31:26 +01:00
|
|
|
private boolean meetsRequirements;
|
2019-01-24 22:29:56 +01:00
|
|
|
|
2018-12-30 14:31:26 +01:00
|
|
|
private boolean repeat;
|
2019-01-24 22:29:56 +01:00
|
|
|
|
|
|
|
|
2019-01-05 11:17:03 +01:00
|
|
|
/**
|
|
|
|
*/
|
2019-01-24 22:29:56 +01:00
|
|
|
ChallengeResult setMeetsRequirements()
|
|
|
|
{
|
2018-12-30 14:31:26 +01:00
|
|
|
this.meetsRequirements = true;
|
|
|
|
return this;
|
|
|
|
}
|
2019-01-24 22:29:56 +01:00
|
|
|
|
|
|
|
|
2018-12-30 14:31:26 +01:00
|
|
|
/**
|
|
|
|
* @param repeat the repeat to set
|
|
|
|
*/
|
2019-01-24 22:29:56 +01:00
|
|
|
ChallengeResult setRepeat(boolean repeat)
|
|
|
|
{
|
2018-12-30 14:31:26 +01:00
|
|
|
this.repeat = repeat;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|