Rework Challenge, ChallengeLevel and ChallengesPlayerData classes.

Challenge now will not know their world, as it is not necessary.
Remove ICON type, as it is useless.
Rename Level to Other, as under it will be not only level things.
Rename slot to order, as it was weird that users could define slot but not order. Order is easier to understand and use.

ChallengesLevel now knows all their levels.
Each challenge level only will be for single world.
Rename some variables.

ChallengesPlayerData was just adapted with changes in challenges and level classes.
This commit is contained in:
BONNe1704 2019-01-23 16:33:33 +02:00
parent dba5a44461
commit f75e4e080c
12 changed files with 1664 additions and 986 deletions

View File

@ -16,10 +16,13 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import world.bentobox.bentobox.util.ItemParser;
import world.bentobox.challenges.database.object.ChallengeLevel; import world.bentobox.challenges.database.object.ChallengeLevel;
import world.bentobox.challenges.database.object.Challenge; import world.bentobox.challenges.database.object.Challenge;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;
import world.bentobox.challenges.utils.GuiUtils;
/** /**
* Imports challenges * Imports challenges
@ -64,13 +67,13 @@ public class ChallengesImportManager
user.sendMessage("challenges.admin.import.no-load","[message]", e.getMessage()); user.sendMessage("challenges.admin.import.no-load","[message]", e.getMessage());
return false; return false;
} }
makeLevels(user); makeLevels(user, world, overwrite);
makeChallenges(user, world, overwrite); makeChallenges(user, world, overwrite);
addon.getChallengesManager().save(); addon.getChallengesManager().save();
return true; return true;
} }
private void makeLevels(User user) { private void makeLevels(User user, World world, boolean overwrite) {
// Parse the levels // Parse the levels
String levels = chal.getString("challenges.levels", ""); String levels = chal.getString("challenges.levels", "");
if (!levels.isEmpty()) { if (!levels.isEmpty()) {
@ -82,15 +85,16 @@ public class ChallengesImportManager
challengeLevel.setFriendlyName(level); challengeLevel.setFriendlyName(level);
challengeLevel.setUniqueId(level); challengeLevel.setUniqueId(level);
challengeLevel.setOrder(order++); challengeLevel.setOrder(order++);
challengeLevel.setWaiveramount(chal.getInt("challenges.waiveramount")); challengeLevel.setWorld(Util.getWorld(world).getName());
challengeLevel.setWaiverAmount(chal.getInt("challenges.waiveramount"));
// Check if there is a level reward // Check if there is a level reward
ConfigurationSection unlock = chal.getConfigurationSection("challenges.levelUnlock." + level); ConfigurationSection unlock = chal.getConfigurationSection("challenges.levelUnlock." + level);
if (unlock != null) { if (unlock != null) {
challengeLevel.setUnlockMessage(unlock.getString("message")); challengeLevel.setUnlockMessage(unlock.getString("message"));
challengeLevel.setRewardDescription(unlock.getString("rewardDesc","")); challengeLevel.setRewardText(unlock.getString("rewardDesc",""));
challengeLevel.setRewardItems(parseItems(unlock.getString("itemReward",""))); challengeLevel.setRewardItems(parseItems(unlock.getString("itemReward","")));
challengeLevel.setMoneyReward(unlock.getInt("moneyReward")); challengeLevel.setRewardMoney(unlock.getInt("moneyReward"));
challengeLevel.setExpReward(unlock.getInt("expReward")); challengeLevel.setRewardExperience(unlock.getInt("expReward"));
challengeLevel.setRewardCommands(unlock.getStringList("commands")); challengeLevel.setRewardCommands(unlock.getStringList("commands"));
} }
addon.getChallengesManager().storeLevel(challengeLevel); addon.getChallengesManager().storeLevel(challengeLevel);
@ -103,7 +107,6 @@ public class ChallengesImportManager
/** /**
* Imports challenges * Imports challenges
* @param overwrite * @param overwrite
* @param args
*/ */
private void makeChallenges(User user, World world, boolean overwrite) { private void makeChallenges(User user, World world, boolean overwrite) {
int size = 0; int size = 0;
@ -115,41 +118,42 @@ public class ChallengesImportManager
newChallenge.setDeployed(true); newChallenge.setDeployed(true);
ConfigurationSection details = chals.getConfigurationSection(challenge); ConfigurationSection details = chals.getConfigurationSection(challenge);
newChallenge.setFriendlyName(details.getString("friendlyname", challenge)); newChallenge.setFriendlyName(details.getString("friendlyname", challenge));
newChallenge.setWorld(Util.getWorld(world).getName());
newChallenge.setDescription(addon.getChallengesManager().stringSplit(details.getString("description", ""))); newChallenge.setDescription(addon.getChallengesManager().stringSplit(details.getString("description", "")));
newChallenge.setIcon(new ParseItem(addon, details.getString("icon") + ":1").getItem()); newChallenge.setIcon(ItemParser.parse(details.getString("icon") + ":1"));
newChallenge.setLevel(details.getString("level", ChallengesManager.FREE));
newChallenge.setChallengeType(Challenge.ChallengeType.valueOf(details.getString("type","INVENTORY").toUpperCase())); newChallenge.setChallengeType(Challenge.ChallengeType.valueOf(details.getString("type","INVENTORY").toUpperCase()));
newChallenge.setTakeItems(details.getBoolean("takeItems",true)); newChallenge.setTakeItems(details.getBoolean("takeItems",true));
newChallenge.setRewardText(details.getString("rewardText", "")); newChallenge.setRewardText(details.getString("rewardText", ""));
newChallenge.setRewardCommands(details.getStringList("rewardcommands")); newChallenge.setRewardCommands(details.getStringList("rewardcommands"));
newChallenge.setRewardMoney(details.getInt("moneyReward",0)); newChallenge.setRewardMoney(details.getInt("moneyReward",0));
newChallenge.setRewardExp(details.getInt("expReward")); newChallenge.setRewardExperience(details.getInt("expReward"));
newChallenge.setRepeatable(details.getBoolean("repeatable")); newChallenge.setRepeatable(details.getBoolean("repeatable"));
newChallenge.setRepeatRewardText(details.getString("repeatRewardText","")); newChallenge.setRepeatRewardText(details.getString("repeatRewardText",""));
newChallenge.setRepeatMoneyReward(details.getInt("repearMoneyReward")); newChallenge.setRepeatMoneyReward(details.getInt("repearMoneyReward"));
newChallenge.setRepeatExpReward(details.getInt("repeatExpReward")); newChallenge.setRepeatExperienceReward(details.getInt("repeatExpReward"));
newChallenge.setRepeatRewardCommands(details.getStringList("repeatrewardcommands")); newChallenge.setRepeatRewardCommands(details.getStringList("repeatrewardcommands"));
newChallenge.setMaxTimes(details.getInt("maxtimes")); newChallenge.setMaxTimes(details.getInt("maxtimes"));
// TODO reset allowed // TODO reset allowed
newChallenge.setReqMoney(details.getInt("requiredMoney")); newChallenge.setRequiredMoney(details.getInt("requiredMoney"));
newChallenge.setReqExp(details.getInt("requiredExp")); newChallenge.setRequiredExperience(details.getInt("requiredExp"));
String reqItems = details.getString("requiredItems",""); String reqItems = details.getString("requiredItems","");
if (newChallenge.getChallengeType().equals(Challenge.ChallengeType.INVENTORY)) { if (newChallenge.getChallengeType().equals(Challenge.ChallengeType.INVENTORY)) {
newChallenge.setRequiredItems(parseItems(reqItems)); newChallenge.setRequiredItems(parseItems(reqItems));
} else if (newChallenge.getChallengeType().equals(Challenge.ChallengeType.LEVEL)) { } else if (newChallenge.getChallengeType().equals(Challenge.ChallengeType.OTHER)) {
newChallenge.setReqIslandlevel(Long.parseLong(reqItems)); newChallenge.setRequiredIslandLevel(Long.parseLong(reqItems));
} else if (newChallenge.getChallengeType().equals(Challenge.ChallengeType.ISLAND)) { } else if (newChallenge.getChallengeType().equals(Challenge.ChallengeType.ISLAND)) {
parseEntities(newChallenge, reqItems); parseEntities(newChallenge, reqItems);
} }
newChallenge.setRewardItems(parseItems(details.getString("itemReward"))); newChallenge.setRewardItems(parseItems(details.getString("itemReward")));
newChallenge.setRepeatItemReward(parseItems(details.getString("repeatItemReward"))); newChallenge.setRepeatItemReward(parseItems(details.getString("repeatItemReward")));
// Save // Save
this.addon.getChallengesManager().addChallengeToLevel(newChallenge,
addon.getChallengesManager().getLevel(Util.getWorld(world).getName() + "_" + details.getString("level")));
if (addon.getChallengesManager().storeChallenge(newChallenge, overwrite, user, false)) { if (addon.getChallengesManager().storeChallenge(newChallenge, overwrite, user, false)) {
size++; size++;
} }
} }
addon.getChallengesManager().sortChallenges();
user.sendMessage("challenges.admin.import.number", "[number]", String.valueOf(size)); user.sendMessage("challenges.admin.import.number", "[number]", String.valueOf(size));
} }
@ -180,7 +184,7 @@ public class ChallengesImportManager
List<ItemStack> result = new ArrayList<>(); List<ItemStack> result = new ArrayList<>();
if (!reqList.isEmpty()) { if (!reqList.isEmpty()) {
for (String s : reqList.split(" ")) { for (String s : reqList.split(" ")) {
ItemStack item = new ParseItem(addon,s).getItem(); ItemStack item = ItemParser.parse(s);
if (item != null) { if (item != null) {
result.add(item); result.add(item);
} }
@ -188,7 +192,4 @@ public class ChallengesImportManager
} }
return result; return result;
} }
}
}

View File

@ -80,7 +80,7 @@ public class ChallengesManager {
*/ */
public long checkChallengeTimes(User user, Challenge challenge, World world) { public long checkChallengeTimes(User user, Challenge challenge, World world) {
addPlayer(user); addPlayer(user);
return playerData.get(user.getUniqueId()).getTimes(world, challenge.getUniqueId()); return playerData.get(user.getUniqueId()).getTimes(challenge.getUniqueId());
} }
/** /**
@ -189,7 +189,7 @@ public class ChallengesManager {
*/ */
public List<String> getAllChallengesList(World world) { public List<String> getAllChallengesList(World world) {
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
challengeMap.values().forEach(ch -> ch.stream().filter(c -> c.getWorld().equals(Util.getWorld(world).getName())).forEach(c -> result.add(c.getUniqueId()))); challengeMap.values().forEach(ch -> ch.stream().filter(c -> c.getUniqueId().startsWith(Util.getWorld(world).getName())).forEach(c -> result.add(c.getUniqueId())));
return result; return result;
} }
@ -230,10 +230,10 @@ public class ChallengesManager {
for (Entry<ChallengeLevel, Set<Challenge>> entry : this.challengeMap.entrySet()) for (Entry<ChallengeLevel, Set<Challenge>> entry : this.challengeMap.entrySet())
{ {
// Check how much challenges must be done in previous level. // Check how much challenges must be done in previous level.
int challengesToDo = Math.max(0, entry.getKey().getWaiveramount() - doneChallengeCount); int challengesToDo = Math.max(0, entry.getKey().getWaiverAmount() - doneChallengeCount);
doneChallengeCount = (int) entry.getValue().stream().filter( doneChallengeCount = (int) entry.getValue().stream().filter(
ch -> playerData.isChallengeDone(world, ch.getUniqueId())).count(); ch -> playerData.isChallengeDone(ch.getUniqueId())).count();
// Create result class with the data // Create result class with the data
result.add(new LevelStatus( result.add(new LevelStatus(
@ -270,7 +270,7 @@ public class ChallengesManager {
Optional<ChallengeLevel> lv = challengeMap.keySet().stream().filter(l -> l.getUniqueId().equalsIgnoreCase(level)).findFirst(); Optional<ChallengeLevel> lv = challengeMap.keySet().stream().filter(l -> l.getUniqueId().equalsIgnoreCase(level)).findFirst();
// Get the challenges applicable to this world // Get the challenges applicable to this world
return lv.isPresent() ? challengeMap.get(lv.get()).stream() return lv.isPresent() ? challengeMap.get(lv.get()).stream()
.filter(c -> c.getWorld().equalsIgnoreCase(worldName) || c.getWorld().isEmpty()).collect(Collectors.toSet()) .filter(c -> c.getUniqueId().startsWith(worldName)).collect(Collectors.toSet())
: new HashSet<>(); : new HashSet<>();
} }
@ -319,7 +319,7 @@ public class ChallengesManager {
*/ */
public boolean isChallenge(World world, String name) { public boolean isChallenge(World world, String name) {
for (Set<Challenge> ch : challengeMap.values()) { for (Set<Challenge> ch : challengeMap.values()) {
if (ch.stream().filter(c -> c.getWorld().equals(Util.getWorld(world).getName())).anyMatch(c -> c.getUniqueId().equalsIgnoreCase(name))) { if (ch.stream().filter(c -> c.getUniqueId().startsWith(Util.getWorld(world).getName())).anyMatch(c -> c.getUniqueId().equalsIgnoreCase(name))) {
return true; return true;
} }
} }
@ -328,13 +328,12 @@ public class ChallengesManager {
/** /**
* Checks if a challenge is complete or not * Checks if a challenge is complete or not
* @param uniqueId - unique ID - player's UUID
* @param challengeName - Challenge uniqueId * @param challengeName - Challenge uniqueId
* @return - true if completed * @return - true if completed
*/ */
public boolean isChallengeComplete(User user, String challengeName, World world) { public boolean isChallengeComplete(User user, String challengeName, World world) {
addPlayer(user); addPlayer(user);
return playerData.get(user.getUniqueId()).isChallengeDone(world, challengeName); return playerData.get(user.getUniqueId()).isChallengeDone(challengeName);
} }
/** /**
@ -396,7 +395,7 @@ public class ChallengesManager {
*/ */
public void setChallengeComplete(User user, String challengeUniqueId, World world) { public void setChallengeComplete(User user, String challengeUniqueId, World world) {
addPlayer(user); addPlayer(user);
playerData.get(user.getUniqueId()).setChallengeDone(world, challengeUniqueId); playerData.get(user.getUniqueId()).setChallengeDone(challengeUniqueId);
// Save // Save
savePlayer(user.getUniqueId()); savePlayer(user.getUniqueId());
} }
@ -409,7 +408,7 @@ public class ChallengesManager {
*/ */
public void setResetChallenge(User user, String challengeUniqueId, World world) { public void setResetChallenge(User user, String challengeUniqueId, World world) {
addPlayer(user); addPlayer(user);
playerData.get(user.getUniqueId()).setChallengeTimes(world, challengeUniqueId, 0); playerData.get(user.getUniqueId()).setChallengeTimes(challengeUniqueId, 0);
// Save // Save
savePlayer(user.getUniqueId()); savePlayer(user.getUniqueId());
} }
@ -637,4 +636,17 @@ public class ChallengesManager {
return playerList; return playerList;
} }
public ChallengeLevel getLevel(String level)
{
return null;
}
public void addChallengeToLevel(Challenge newChallenge, ChallengeLevel level)
{
}
} }

View File

@ -1,9 +1,13 @@
package world.bentobox.challenges.database.object; package world.bentobox.challenges.database.object;
import com.google.gson.annotations.Expose;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import world.bentobox.bentobox.api.configuration.ConfigComment; import world.bentobox.bentobox.api.configuration.ConfigComment;
import world.bentobox.bentobox.database.objects.DataObject; import world.bentobox.bentobox.database.objects.DataObject;
@ -14,223 +18,455 @@ import world.bentobox.challenges.ChallengesManager;
* @author tastybento * @author tastybento
* *
*/ */
public class ChallengeLevel implements DataObject, Comparable<ChallengeLevel> { public class ChallengeLevel implements DataObject, Comparable<ChallengeLevel>
{
/**
* Constructor ChallengeLevel creates a new ChallengeLevel instance.
*/
public ChallengeLevel()
{
}
public ChallengeLevel() {}
@ConfigComment("A friendly name for the level. If blank, level name is used.") // ---------------------------------------------------------------------
private String friendlyName = ""; // Section: Variables
// ---------------------------------------------------------------------
@ConfigComment("Worlds that this level applies in. String list.")
private List<String> worlds = new ArrayList<>();
@ConfigComment("Commands to run when this level is completed") @ConfigComment("")
private List<String> rewardCommands = new ArrayList<>();
@ConfigComment("Level name") @ConfigComment("Level name")
@Expose
private String uniqueId = ChallengesManager.FREE; private String uniqueId = ChallengesManager.FREE;
@ConfigComment("The number of undone challenges that can be left on this level before unlocking next level") @ConfigComment("")
private int waiveramount = 1; @ConfigComment("A friendly name for the level. If blank, level name is used.")
@Expose
@ConfigComment("The ordering of the levels, lowest to highest") private String friendlyName = "";
private int order = 0;
@ConfigComment("")
@ConfigComment("The message shown when unlocking this level") @ConfigComment("ItemStack that represents current level. Will be used as icon in GUIs.")
@Expose
private ItemStack icon = new ItemStack(Material.BOOK);
@ConfigComment("")
@ConfigComment("World that this level applies in. String.")
@Expose
private String world = "";
@ConfigComment("")
@ConfigComment("The ordering of the level, lowest to highest")
@Expose
private int order;
@ConfigComment("")
@ConfigComment("The number of undone challenges that can be left on this level before")
@ConfigComment("unlocking next level.")
@Expose
private int waiverAmount = 1;
@ConfigComment("")
@ConfigComment("The message shown when unlocking this level. Single line string.")
@Expose
private String unlockMessage = ""; private String unlockMessage = "";
@ConfigComment("Unlock reward description")
private String rewardDescription = "";
@ConfigComment("List of reward itemstacks")
private List<ItemStack> rewardItems;
@ConfigComment("Unlock experience reward")
private int expReward;
@ConfigComment("Unlock money reward")
private int moneyReward;
public String getFriendlyName() {
return friendlyName;
}
public List<String> getRewardCommands() { @ConfigComment("")
return rewardCommands = new ArrayList<>(); @ConfigComment("")
} @ConfigComment("If this is blank, the reward text will be auto-generated, otherwise")
@ConfigComment("this will be used.")
@Expose
private String rewardText = "";
@ConfigComment("")
@ConfigComment("List of items the player will receive on completing level.")
@ConfigComment("ItemStack List.")
@Expose
private List<ItemStack> rewardItems = new ArrayList<>();
@ConfigComment("")
@ConfigComment("Experience point reward on completing level.")
@Expose
private int rewardExperience = 0;
@ConfigComment("")
@ConfigComment("Money reward. Economy plugin or addon required for this option.")
@Expose
private int rewardMoney = 0;
@ConfigComment("")
@ConfigComment("Commands to run when the player completes all challenges in current")
@ConfigComment("level. String List")
@Expose
private List<String> rewardCommands = new ArrayList<>();
@ConfigComment("")
@ConfigComment("Set of all challenges that is linked with current level.")
@ConfigComment("String Set")
@Expose
private Set<String> challenges = new HashSet<>();
// ---------------------------------------------------------------------
// Section: Getters
// ---------------------------------------------------------------------
/**
* This method returns the uniqueId value.
* @return the value of uniqueId.
* @see DataObject#getUniqueId()
*/
@Override @Override
public String getUniqueId() { public String getUniqueId()
{
return uniqueId; return uniqueId;
} }
/** /**
* Get the number of undone tasks that can be left on a level before unlocking next level * This method returns the friendlyName value.
* @return * @return the value of friendlyName.
*/ */
public int getWaiveramount() { public String getFriendlyName()
return waiveramount; {
return friendlyName;
} }
public void setFriendlyName(String friendlyName) {
this.friendlyName = friendlyName; /**
* This method returns the icon value.
* @return the value of icon.
*/
public ItemStack getIcon()
{
return icon;
} }
public void setRewardCommands(List<String> rewardCommands) {
this.rewardCommands = rewardCommands; /**
* This method returns the world value.
* @return the value of world.
*/
public String getWorld()
{
return world;
} }
@Override
public void setUniqueId(String uniqueId) {
this.uniqueId = uniqueId;
}
public void setWaiveramount(int waiveramount) { /**
this.waiveramount = waiveramount; * This method returns the order value.
} * @return the value of order.
*/
public int getOrder() { public int getOrder()
{
return order; return order;
} }
public void setOrder(int order) {
this.order = order;
}
@Override
public int compareTo(ChallengeLevel o) {
return Integer.compare(this.order, o.order);
}
/**
* @return the rewardDescription
*/
public String getRewardDescription() {
return rewardDescription;
}
/** /**
* @param rewardDescription the rewardDescription to set * This method returns the waiverAmount value.
* @return the value of waiverAmount.
*/ */
public void setRewardDescription(String rewardDescription) { public int getWaiverAmount()
this.rewardDescription = rewardDescription; {
return waiverAmount;
} }
/**
* @return the rewardItems
*/
public List<ItemStack> getRewardItems() {
return rewardItems;
}
/** /**
* @param rewardItems the rewardItems to set * This method returns the unlockMessage value.
* @return the value of unlockMessage.
*/ */
public void setRewardItems(List<ItemStack> rewardItems) { public String getUnlockMessage()
this.rewardItems = rewardItems; {
}
/**
* @return the expReward
*/
public int getExpReward() {
return expReward;
}
/**
* @param expReward the expReward to set
*/
public void setExpReward(int expReward) {
this.expReward = expReward;
}
/**
* @return the moneyReward
*/
public int getMoneyReward() {
return moneyReward;
}
/**
* @param moneyReward the moneyReward to set
*/
public void setMoneyReward(int moneyReward) {
this.moneyReward = moneyReward;
}
/**
* @return the unlockMessage
*/
public String getUnlockMessage() {
return unlockMessage; return unlockMessage;
} }
/** /**
* @param unlockMessage the unlockMessage to set * This method returns the rewardText value.
* @return the value of rewardText.
*/ */
public void setUnlockMessage(String unlockMessage) { public String getRewardText()
{
return rewardText;
}
/**
* This method returns the rewardItems value.
* @return the value of rewardItems.
*/
public List<ItemStack> getRewardItems()
{
return rewardItems;
}
/**
* This method returns the rewardExperience value.
* @return the value of rewardExperience.
*/
public int getRewardExperience()
{
return rewardExperience;
}
/**
* This method returns the rewardMoney value.
* @return the value of rewardMoney.
*/
public int getRewardMoney()
{
return rewardMoney;
}
/**
* This method returns the rewardCommands value.
* @return the value of rewardCommands.
*/
public List<String> getRewardCommands()
{
return rewardCommands;
}
/**
* This method returns the challenges value.
* @return the value of challenges.
*/
public Set<String> getChallenges()
{
return challenges;
}
// ---------------------------------------------------------------------
// Section: Setters
// ---------------------------------------------------------------------
/**
* This method sets the uniqueId value.
* @param uniqueId the uniqueId new value.
*
* @see DataObject#setUniqueId(String)
*/
@Override
public void setUniqueId(String uniqueId)
{
this.uniqueId = uniqueId;
}
/**
* This method sets the friendlyName value.
* @param friendlyName the friendlyName new value.
*
*/
public void setFriendlyName(String friendlyName)
{
this.friendlyName = friendlyName;
}
/**
* This method sets the icon value.
* @param icon the icon new value.
*
*/
public void setIcon(ItemStack icon)
{
this.icon = icon;
}
/**
* This method sets the world value.
* @param world the world new value.
*
*/
public void setWorld(String world)
{
this.world = world;
}
/**
* This method sets the order value.
* @param order the order new value.
*
*/
public void setOrder(int order)
{
this.order = order;
}
/**
* This method sets the waiverAmount value.
* @param waiverAmount the waiverAmount new value.
*
*/
public void setWaiverAmount(int waiverAmount)
{
this.waiverAmount = waiverAmount;
}
/**
* This method sets the unlockMessage value.
* @param unlockMessage the unlockMessage new value.
*
*/
public void setUnlockMessage(String unlockMessage)
{
this.unlockMessage = unlockMessage; this.unlockMessage = unlockMessage;
} }
/**
* @return the worlds
*/
public List<String> getWorlds() {
return worlds;
}
/** /**
* @param worlds the worlds to set * This method sets the rewardText value.
* @param rewardText the rewardText new value.
*
*/ */
public void setWorlds(List<String> worlds) { public void setRewardText(String rewardText)
this.worlds = worlds; {
this.rewardText = rewardText;
} }
/* (non-Javadoc)
* @see java.lang.Object#hashCode() /**
* This method sets the rewardItems value.
* @param rewardItems the rewardItems new value.
*
*/
public void setRewardItems(List<ItemStack> rewardItems)
{
this.rewardItems = rewardItems;
}
/**
* This method sets the rewardExperience value.
* @param rewardExperience the rewardExperience new value.
*
*/
public void setRewardExperience(int rewardExperience)
{
this.rewardExperience = rewardExperience;
}
/**
* This method sets the rewardMoney value.
* @param rewardMoney the rewardMoney new value.
*
*/
public void setRewardMoney(int rewardMoney)
{
this.rewardMoney = rewardMoney;
}
/**
* This method sets the rewardCommands value.
* @param rewardCommands the rewardCommands new value.
*
*/
public void setRewardCommands(List<String> rewardCommands)
{
this.rewardCommands = rewardCommands;
}
/**
* This method sets the challenges value.
* @param challenges the challenges new value.
*
*/
public void setChallenges(Set<String> challenges)
{
this.challenges = challenges;
}
// ---------------------------------------------------------------------
// Section: Other methods
// ---------------------------------------------------------------------
/**
* {@inheritDoc}
*/ */
@Override @Override
public int hashCode() { public int compareTo(ChallengeLevel o)
{
if (this.equals(o))
{
return 0;
}
else
{
if (this.getWorld().equals(o.getWorld()))
{
if (this.order == o.getOrder())
{
return this.getUniqueId().compareTo(o.getUniqueId());
}
else
{
return Integer.compare(this.order, o.getOrder());
}
}
else
{
return this.getWorld().compareTo(o.getWorld());
}
}
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode()
{
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode()); result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode());
return result; return result;
} }
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
/**
* {@inheritDoc}
*/ */
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj)
if (this == obj) { {
if (this == obj)
{
return true; return true;
} }
if (obj == null) {
return false; if (!(obj instanceof ChallengeLevel))
} {
if (!(obj instanceof ChallengeLevel)) {
return false; return false;
} }
ChallengeLevel other = (ChallengeLevel) obj; ChallengeLevel other = (ChallengeLevel) obj;
if (uniqueId == null) {
if (other.uniqueId != null) { if (uniqueId == null)
return false; {
} return other.uniqueId == null;
} else if (!uniqueId.equals(other.uniqueId)) { }
return false; else
{
return uniqueId.equals(other.uniqueId);
} }
return true;
} }
}
public ItemStack getIcon()
{
return null;
}
public void setIcon(ItemStack newIcon)
{
}
}

View File

@ -1,6 +1,3 @@
/**
*
*/
package world.bentobox.challenges.database.object; package world.bentobox.challenges.database.object;
import java.util.HashMap; import java.util.HashMap;
@ -20,173 +17,265 @@ import world.bentobox.bentobox.util.Util;
* @author tastybento * @author tastybento
* *
*/ */
public class ChallengesPlayerData implements DataObject { public class ChallengesPlayerData implements DataObject
{
/**
* Constructor ChallengesPlayerData creates a new ChallengesPlayerData instance.
*/
public ChallengesPlayerData()
{
}
@Expose
private String uniqueId = "";
/**
* Challenge map, where key = unique challenge name and Value = number of times completed
*/
@Expose
private Map<String, Integer> challengeStatus = new HashMap<>();
@Expose
private Map<String, Long> challengesTimestamp = new HashMap<>();
@Expose
private Set<String> levelsDone = new HashSet<>();
// Required for bean instantiation /**
public ChallengesPlayerData() {} * Creates a player data entry
*
* @param uniqueId - the player's UUID in string format
*/
public ChallengesPlayerData(String uniqueId)
{
this.uniqueId = uniqueId;
}
/**
* Mark a challenge as having been completed. Will increment the number of times and timestamp
* @param world - world of challenge
* @param challengeName - unique challenge name
*/
public void setChallengeDone(World world, String challengeName) {
String name = Util.getWorld(world).getName() + challengeName;
int times = challengeStatus.getOrDefault(name, 0) + 1;
challengeStatus.put(name, times);
challengesTimestamp.put(name, System.currentTimeMillis());
}
/** // ---------------------------------------------------------------------
* Set the number of times a challenge has been done // Section: Variables
* @param world - world of challenge // ---------------------------------------------------------------------
* @param challengeName - unique challenge name
* @param times - the number of times to set
*
*/
public void setChallengeTimes(World world, String challengeName, int times) {
String name = Util.getWorld(world).getName() + challengeName;
challengeStatus.put(name, times);
challengesTimestamp.put(name, System.currentTimeMillis());
}
/**
* Check if a challenge has been done
* @param challengeName - unique challenge name
* @return true if done at least once
*/
public boolean isChallengeDone(World world, String challengeName) {
return getTimes(world, challengeName) > 0;
}
/** /**
* Check how many times a challenge has been done * This variable stores each player UUID as string.
* @param challengeName - unique challenge name */
* @return - number of times @Expose
*/ private String uniqueId = "";
public int getTimes(World world, String challengeName) {
return challengeStatus.getOrDefault(Util.getWorld(world).getName() + challengeName, 0);
}
/** /**
* Creates a player data entry * Challenge map, where key = unique challenge name and Value = number of times
* @param uniqueId - the player's UUID in string format * completed
*/ */
public ChallengesPlayerData(String uniqueId) { @Expose
this.uniqueId = uniqueId; private Map<String, Integer> challengeStatus = new HashMap<>();
}
/* (non-Javadoc) /**
* @see world.bentobox.bbox.database.objects.DataObject#getUniqueId() * Map of challenges completion time where key is challenges unique id and value is
*/ * timestamp when challenge was completed last time.
@Override */
public String getUniqueId() { @Expose
return uniqueId; private Map<String, Long> challengesTimestamp = new HashMap<>();
}
/* (non-Javadoc) /**
* @see world.bentobox.bbox.database.objects.DataObject#setUniqueId(java.lang.String) * Set of Strings that contains all challenge levels that are completed.
*/ */
@Override @Expose
public void setUniqueId(String uniqueId) { private Set<String> levelsDone = new HashSet<>();
this.uniqueId = uniqueId;
}
/**
* @return the challengeStatus
*/
public Map<String, Integer> getChallengeStatus() {
return challengeStatus;
}
/**
* @param challengeStatus the challengeStatus to set
*/
public void setChallengeStatus(Map<String, Integer> challengeStatus) {
this.challengeStatus = challengeStatus;
}
/**
* @return the challengesTimestamp
*/
public Map<String, Long> getChallengesTimestamp() {
return challengesTimestamp;
}
/**
* @param challengesTimestamp the challengesTimestamp to set
*/
public void setChallengesTimestamp(Map<String, Long> challengesTimestamp) {
this.challengesTimestamp = challengesTimestamp;
}
/**
* @return the levelsDone
*/
public Set<String> getLevelsDone() {
return levelsDone;
}
/** // ---------------------------------------------------------------------
* @param levelsDone the levelsDone to set // Section: Getters
*/ // ---------------------------------------------------------------------
public void setLevelsDone(Set<String> levelsDone) {
this.levelsDone = levelsDone;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode());
return result;
}
/* (non-Javadoc) /**
* @see java.lang.Object#equals(java.lang.Object) * @return uniqueID
*/ * @see DataObject#getUniqueId()
@Override */
public boolean equals(Object obj) { @Override
if (this == obj) { public String getUniqueId()
return true; {
} return uniqueId;
if (obj == null) { }
return false;
}
if (!(obj instanceof ChallengesPlayerData)) {
return false;
}
ChallengesPlayerData other = (ChallengesPlayerData) obj;
if (uniqueId == null) {
if (other.uniqueId != null) {
return false;
}
} else if (!uniqueId.equals(other.uniqueId)) {
return false;
}
return true;
}
/**
* Resets all challenges and levels in world for this player
* @param world
*/
public void reset(World world) {
String worldName = Util.getWorld(world).getName();
challengeStatus.keySet().removeIf(n -> n.startsWith(worldName));
challengesTimestamp.keySet().removeIf(n -> n.startsWith(worldName));
levelsDone.removeIf(n -> n.startsWith(worldName));
}
} /**
* This method returns the challengeStatus value.
* @return the value of challengeStatus.
*/
public Map<String, Integer> getChallengeStatus()
{
return challengeStatus;
}
/**
* This method returns the challengesTimestamp value.
* @return the value of challengesTimestamp.
*/
public Map<String, Long> getChallengesTimestamp()
{
return challengesTimestamp;
}
/**
* This method returns the levelsDone value.
* @return the value of levelsDone.
*/
public Set<String> getLevelsDone()
{
return levelsDone;
}
// ---------------------------------------------------------------------
// Section: Setters
// ---------------------------------------------------------------------
/**
* @param uniqueId - unique ID the uniqueId to set
* @see DataObject#setUniqueId(String)
*/
@Override
public void setUniqueId(String uniqueId)
{
this.uniqueId = uniqueId;
}
/**
* This method sets the challengeStatus value.
* @param challengeStatus the challengeStatus new value.
*
*/
public void setChallengeStatus(Map<String, Integer> challengeStatus)
{
this.challengeStatus = challengeStatus;
}
/**
* This method sets the challengesTimestamp value.
* @param challengesTimestamp the challengesTimestamp new value.
*
*/
public void setChallengesTimestamp(Map<String, Long> challengesTimestamp)
{
this.challengesTimestamp = challengesTimestamp;
}
/**
* This method sets the levelsDone value.
* @param levelsDone the levelsDone new value.
*
*/
public void setLevelsDone(Set<String> levelsDone)
{
this.levelsDone = levelsDone;
}
// ---------------------------------------------------------------------
// Section: Other Methods
// ---------------------------------------------------------------------
/**
* Resets all challenges and levels in world for this player
*
* @param world world which challenges must be reset.
*/
public void reset(World world)
{
String worldName = Util.getWorld(world).getName();
challengeStatus.keySet().removeIf(n -> n.startsWith(worldName));
challengesTimestamp.keySet().removeIf(n -> n.startsWith(worldName));
levelsDone.removeIf(n -> n.startsWith(worldName));
}
/**
* Mark a challenge as having been completed. Will increment the number of times and
* timestamp
*
* @param challengeName - unique challenge name
*/
public void setChallengeDone(String challengeName)
{
int times = challengeStatus.getOrDefault(challengeName, 0) + 1;
challengeStatus.put(challengeName, times);
challengesTimestamp.put(challengeName, System.currentTimeMillis());
}
/**
* Set the number of times a challenge has been done
*
* @param challengeName - unique challenge name
* @param times - the number of times to set
*/
public void setChallengeTimes(String challengeName, int times)
{
challengeStatus.put(challengeName, times);
challengesTimestamp.put(challengeName, System.currentTimeMillis());
}
/**
* Check if a challenge has been done
*
* @param challengeName - unique challenge name
* @return true if done at least once
*/
public boolean isChallengeDone(String challengeName)
{
return this.getTimes(challengeName) > 0;
}
/**
* Check how many times a challenge has been done
*
* @param challengeName - unique challenge name
* @return - number of times
*/
public int getTimes(String challengeName)
{
return challengeStatus.getOrDefault(challengeName, 0);
}
/**
* @see Object#hashCode()
* @return object hashCode value.
*/
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode());
return result;
}
/**
* @see java.lang.Object#equals(java.lang.Object)
* @param obj Other object.
* @return boolean that indicate if objects are equals.
*/
@Override
public boolean equals(Object obj)
{
if (this == obj)
{
return true;
}
if (!(obj instanceof ChallengesPlayerData))
{
return false;
}
ChallengesPlayerData other = (ChallengesPlayerData) obj;
if (uniqueId == null)
{
return other.uniqueId == null;
}
else
{
return uniqueId.equals(other.uniqueId);
}
}
}

View File

@ -85,7 +85,6 @@ public class ChallengesPanels {
* Creates a panel item for challenge if appropriate and adds it to panelBuilder * Creates a panel item for challenge if appropriate and adds it to panelBuilder
* @param panelBuilder * @param panelBuilder
* @param challenge * @param challenge
* @param user
*/ */
private void createItem(PanelBuilder panelBuilder, Challenge challenge) { private void createItem(PanelBuilder panelBuilder, Challenge challenge) {
// Check completion // Check completion
@ -100,16 +99,13 @@ public class ChallengesPanels {
.description(challengeDescription(challenge)) .description(challengeDescription(challenge))
.glow(completed) .glow(completed)
.clickHandler((panel, player, c, s) -> { .clickHandler((panel, player, c, s) -> {
if (!challenge.getChallengeType().equals(ChallengeType.ICON)) { new TryToComplete(addon).user(player).manager(manager).challenge(challenge)
new TryToComplete(addon).user(player).manager(manager).challenge(challenge)
.world(world).permPrefix(permPrefix).label(label).build(); .world(world).permPrefix(permPrefix).label(label).build();
//new TryToComplete(addon, player, manager, challenge, world, permPrefix, label);
}
return true; return true;
}) })
.build(); .build();
if (challenge.getSlot() >= 0) { if (challenge.getOrder() >= 0) {
panelBuilder.item(challenge.getSlot(),item); panelBuilder.item(challenge.getOrder(),item);
} else { } else {
panelBuilder.item(item); panelBuilder.item(item);
} }
@ -161,7 +157,6 @@ public class ChallengesPanels {
* Creates the challenge description for the "item" in the inventory * Creates the challenge description for the "item" in the inventory
* *
* @param challenge * @param challenge
* @param player
* @return List of strings splitting challenge string into 25 chars long * @return List of strings splitting challenge string into 25 chars long
*/ */
private List<String> challengeDescription(Challenge challenge) { private List<String> challengeDescription(Challenge challenge) {
@ -210,7 +205,7 @@ public class ChallengesPanels {
// First time // First time
moneyReward = challenge.getRewardMoney(); moneyReward = challenge.getRewardMoney();
rewardText = challenge.getRewardText(); rewardText = challenge.getRewardText();
expReward = challenge.getRewardExp(); expReward = challenge.getRewardExperience();
if (!rewardText.isEmpty()) { if (!rewardText.isEmpty()) {
result.addAll(splitTrans(user, "challenges.first-time-rewards")); result.addAll(splitTrans(user, "challenges.first-time-rewards"));
} }
@ -218,7 +213,7 @@ public class ChallengesPanels {
// Repeat challenge // Repeat challenge
moneyReward = challenge.getRepeatMoneyReward(); moneyReward = challenge.getRepeatMoneyReward();
rewardText = challenge.getRepeatRewardText(); rewardText = challenge.getRepeatRewardText();
expReward = challenge.getRepeatExpReward(); expReward = challenge.getRepeatExperienceReward();
if (!rewardText.isEmpty()) { if (!rewardText.isEmpty()) {
result.addAll(splitTrans(user, "challenges.repeat-rewards")); result.addAll(splitTrans(user, "challenges.repeat-rewards"));
} }

View File

@ -107,7 +107,6 @@ public class ChallengesPanels2 {
* Creates a panel item for challenge if appropriate and adds it to panelBuilder * Creates a panel item for challenge if appropriate and adds it to panelBuilder
* @param panelBuilder * @param panelBuilder
* @param challenge * @param challenge
* @param requester
*/ */
private void createItem(PanelBuilder panelBuilder, Challenge challenge) { private void createItem(PanelBuilder panelBuilder, Challenge challenge) {
// For admin, glow means activated. For user, glow means done // For admin, glow means activated. For user, glow means done
@ -138,33 +137,27 @@ public class ChallengesPanels2 {
if (mode.equals(Mode.ADMIN)) { if (mode.equals(Mode.ADMIN)) {
// Admin click // Admin click
itemBuilder.clickHandler((panel, player, c, s) -> { itemBuilder.clickHandler((panel, player, c, s) -> {
if (!challenge.getChallengeType().equals(ChallengeType.ICON)) { new AdminGUI(addon, player, challenge, world, permPrefix, label);
new AdminGUI(addon, player, challenge, world, permPrefix, label);
}
return true; return true;
}); });
} else if (mode.equals(Mode.EDIT)) { } else if (mode.equals(Mode.EDIT)) {
// Admin edit click // Admin edit click
itemBuilder.clickHandler((panel, player, c, s) -> { itemBuilder.clickHandler((panel, player, c, s) -> {
if (!challenge.getChallengeType().equals(ChallengeType.ICON)) { new AdminEditGUI(addon, player, target, challenge, world, permPrefix, label);
new AdminEditGUI(addon, player, target, challenge, world, permPrefix, label);
}
return true; return true;
}); });
} else { } else {
// Player click // Player click
itemBuilder.clickHandler((panel, player, c, s) -> { itemBuilder.clickHandler((panel, player, c, s) -> {
if (!challenge.getChallengeType().equals(ChallengeType.ICON)) { new TryToComplete(addon, player, manager, challenge, world, permPrefix, label);
new TryToComplete(addon, player, manager, challenge, world, permPrefix, label);
}
return true; return true;
}); });
} }
// If the challenge has a specific slot allocated, use it // If the challenge has a specific slot allocated, use it
if (challenge.getSlot() >= 0) { if (challenge.getOrder() >= 0) {
panelBuilder.item(challenge.getSlot(),itemBuilder.build()); panelBuilder.item(challenge.getOrder(),itemBuilder.build());
} else { } else {
panelBuilder.item(itemBuilder.build()); panelBuilder.item(itemBuilder.build());
} }
@ -216,7 +209,6 @@ public class ChallengesPanels2 {
* Creates the challenge description for the "item" in the inventory * Creates the challenge description for the "item" in the inventory
* *
* @param challenge * @param challenge
* @param player
* @return List of strings splitting challenge string into 25 chars long * @return List of strings splitting challenge string into 25 chars long
*/ */
private List<String> challengeDescription(Challenge challenge) { private List<String> challengeDescription(Challenge challenge) {
@ -287,7 +279,7 @@ public class ChallengesPanels2 {
// First time // First time
moneyReward = challenge.getRewardMoney(); moneyReward = challenge.getRewardMoney();
rewardText = challenge.getRewardText(); rewardText = challenge.getRewardText();
expReward = challenge.getRewardExp(); expReward = challenge.getRewardExperience();
if (!rewardText.isEmpty()) { if (!rewardText.isEmpty()) {
result.addAll(splitTrans(requester, "challenges.first-time-rewards")); result.addAll(splitTrans(requester, "challenges.first-time-rewards"));
} }
@ -296,7 +288,7 @@ public class ChallengesPanels2 {
// Repeat challenge // Repeat challenge
moneyReward = challenge.getRepeatMoneyReward(); moneyReward = challenge.getRepeatMoneyReward();
rewardText = challenge.getRepeatRewardText(); rewardText = challenge.getRepeatRewardText();
expReward = challenge.getRepeatExpReward(); expReward = challenge.getRepeatExperienceReward();
if (!rewardText.isEmpty()) { if (!rewardText.isEmpty()) {
result.addAll(splitTrans(requester, "challenges.repeat-rewards")); result.addAll(splitTrans(requester, "challenges.repeat-rewards"));
} }

View File

@ -73,7 +73,7 @@ public class RequiredPanel implements ClickHandler, PanelListener {
.clickHandler(this) .clickHandler(this)
.build()).forEach(pb::item); .build()).forEach(pb::item);
return pb.user(user).build(); return pb.user(user).build();
case LEVEL: case OTHER:
break; break;
default: default:
@ -137,8 +137,6 @@ public class RequiredPanel implements ClickHandler, PanelListener {
} }
// Save changes // Save changes
switch (challenge.getChallengeType()) { switch (challenge.getChallengeType()) {
case ICON:
break;
case INVENTORY: case INVENTORY:
List<ItemStack> reqItems = new ArrayList<>(); List<ItemStack> reqItems = new ArrayList<>();
// Skip first item // Skip first item
@ -154,7 +152,7 @@ public class RequiredPanel implements ClickHandler, PanelListener {
break; break;
case ISLAND: case ISLAND:
break; break;
case LEVEL: case OTHER:
break; break;
default: default:
break; break;

View File

@ -97,7 +97,7 @@ public class TryToComplete {
vaultHook -> vaultHook.deposit(this.user, this.challenge.getRewardMoney())); vaultHook -> vaultHook.deposit(this.user, this.challenge.getRewardMoney()));
// Give exp // Give exp
user.getPlayer().giveExp(challenge.getRewardExp()); user.getPlayer().giveExp(challenge.getRewardExperience());
// Run commands // Run commands
runCommands(challenge.getRewardCommands()); runCommands(challenge.getRewardCommands());
user.sendMessage("challenges.you-completed", "[challenge]", challenge.getFriendlyName()); user.sendMessage("challenges.you-completed", "[challenge]", challenge.getFriendlyName());
@ -118,7 +118,7 @@ public class TryToComplete {
vaultHook -> vaultHook.deposit(this.user, this.challenge.getRepeatMoneyReward())); vaultHook -> vaultHook.deposit(this.user, this.challenge.getRepeatMoneyReward()));
// Give exp // Give exp
user.getPlayer().giveExp(challenge.getRepeatExpReward()); user.getPlayer().giveExp(challenge.getRepeatExperienceReward());
// Run commands // Run commands
runCommands(challenge.getRepeatRewardCommands()); runCommands(challenge.getRepeatRewardCommands());
user.sendMessage("challenges.you-repeated", "[challenge]", challenge.getFriendlyName()); user.sendMessage("challenges.you-repeated", "[challenge]", challenge.getFriendlyName());
@ -162,7 +162,7 @@ public class TryToComplete {
vaultHook -> vaultHook.deposit(this.user, this.challenge.getRewardMoney())); vaultHook -> vaultHook.deposit(this.user, this.challenge.getRewardMoney()));
// Give exp // Give exp
user.getPlayer().giveExp(challenge.getRewardExp()); user.getPlayer().giveExp(challenge.getRewardExperience());
// Run commands // Run commands
runCommands(challenge.getRewardCommands()); runCommands(challenge.getRewardCommands());
user.sendMessage("challenges.you-completed", "[challenge]", challenge.getFriendlyName()); user.sendMessage("challenges.you-completed", "[challenge]", challenge.getFriendlyName());
@ -183,7 +183,7 @@ public class TryToComplete {
vaultHook -> vaultHook.deposit(this.user, this.challenge.getRepeatMoneyReward())); vaultHook -> vaultHook.deposit(this.user, this.challenge.getRepeatMoneyReward()));
// Give exp // Give exp
user.getPlayer().giveExp(challenge.getRepeatExpReward()); user.getPlayer().giveExp(challenge.getRepeatExperienceReward());
// Run commands // Run commands
runCommands(challenge.getRepeatRewardCommands()); runCommands(challenge.getRepeatRewardCommands());
user.sendMessage("challenges.you-repeated", "[challenge]", challenge.getFriendlyName()); user.sendMessage("challenges.you-repeated", "[challenge]", challenge.getFriendlyName());
@ -199,7 +199,7 @@ public class TryToComplete {
*/ */
private ChallengeResult checkIfCanCompleteChallenge() { private ChallengeResult checkIfCanCompleteChallenge() {
// Check the world // Check the world
if (!Util.getWorld(user.getWorld()).getName().equalsIgnoreCase(challenge.getWorld())) { if (!challenge.getUniqueId().startsWith(Util.getWorld(world).getName())) {
user.sendMessage("general.errors.wrong-world"); user.sendMessage("general.errors.wrong-world");
return new ChallengeResult(); return new ChallengeResult();
} }
@ -215,7 +215,7 @@ public class TryToComplete {
} }
// Check repeatability // Check repeatability
if (manager.isChallengeComplete(user, challenge.getUniqueId(), world) if (manager.isChallengeComplete(user, challenge.getUniqueId(), world)
&& (!challenge.isRepeatable() || challenge.getChallengeType().equals(ChallengeType.LEVEL) && (!challenge.isRepeatable() || challenge.getChallengeType().equals(ChallengeType.OTHER)
|| challenge.getChallengeType().equals(ChallengeType.ISLAND))) { || challenge.getChallengeType().equals(ChallengeType.ISLAND))) {
user.sendMessage("challenges.not-repeatable"); user.sendMessage("challenges.not-repeatable");
return new ChallengeResult(); return new ChallengeResult();
@ -226,24 +226,24 @@ public class TryToComplete {
if (vaultHook.isPresent()) if (vaultHook.isPresent())
{ {
if (!vaultHook.get().has(this.user, this.challenge.getReqMoney())) if (!vaultHook.get().has(this.user, this.challenge.getRequiredMoney()))
{ {
this.user.sendMessage("challenges.not-enough-money", "[money]", Integer.toString(this.challenge.getReqMoney())); this.user.sendMessage("challenges.not-enough-money", "[money]", Integer.toString(this.challenge.getRequiredMoney()));
return new ChallengeResult(); return new ChallengeResult();
} }
} }
// Check exp // Check exp
if (this.user.getPlayer().getTotalExperience() < this.challenge.getReqExp()) if (this.user.getPlayer().getTotalExperience() < this.challenge.getRequiredExperience())
{ {
this.user.sendMessage("challenges.not-enough-exp", "[xp]", Integer.toString(this.challenge.getReqExp())); this.user.sendMessage("challenges.not-enough-exp", "[xp]", Integer.toString(this.challenge.getRequiredExperience()));
return new ChallengeResult(); return new ChallengeResult();
} }
switch (challenge.getChallengeType()) { switch (challenge.getChallengeType()) {
case INVENTORY: case INVENTORY:
return checkInventory(); return checkInventory();
case LEVEL: case OTHER:
return checkLevel(); return checkLevel();
case ISLAND: case ISLAND:
return checkSurrounding(); return checkSurrounding();
@ -303,9 +303,9 @@ public class TryToComplete {
if (vaultHook.isPresent() && if (vaultHook.isPresent() &&
this.challenge.isTakeMoney() && this.challenge.isTakeMoney() &&
this.challenge.getReqMoney() > 0) this.challenge.getRequiredMoney() > 0)
{ {
vaultHook.get().withdraw(this.user, this.challenge.getReqMoney()); vaultHook.get().withdraw(this.user, this.challenge.getRequiredMoney());
} }
} }
@ -346,12 +346,12 @@ public class TryToComplete {
// Check if the level addon is installed or not // Check if the level addon is installed or not
long level = addon.getAddonByName("Level") long level = addon.getAddonByName("Level")
.map(l -> ((Level)l).getIslandLevel(world, user.getUniqueId())).orElse(0L); .map(l -> ((Level)l).getIslandLevel(world, user.getUniqueId())).orElse(0L);
if (level >= challenge.getReqIslandlevel()) { if (level >= challenge.getRequiredIslandLevel()) {
// process money removal // process money removal
this.removeMoney(); this.removeMoney();
return new ChallengeResult().setMeetsRequirements(); return new ChallengeResult().setMeetsRequirements();
} else { } else {
user.sendMessage("challenges.error.island-level", TextVariables.NUMBER, String.valueOf(challenge.getReqIslandlevel())); user.sendMessage("challenges.error.island-level", TextVariables.NUMBER, String.valueOf(challenge.getRequiredIslandLevel()));
return new ChallengeResult(); return new ChallengeResult();
} }
} }
@ -428,7 +428,6 @@ public class TryToComplete {
private boolean meetsRequirements; private boolean meetsRequirements;
private boolean repeat; private boolean repeat;
/** /**
* @param meetsRequirements the meetsRequirements to set
*/ */
public ChallengeResult setMeetsRequirements() { public ChallengeResult setMeetsRequirements() {
this.meetsRequirements = true; this.meetsRequirements = true;

View File

@ -102,7 +102,7 @@ public class EditChallengeGUI extends CommonGUI
case ISLAND: case ISLAND:
this.buildIslandRequirementsPanel(panelBuilder); this.buildIslandRequirementsPanel(panelBuilder);
break; break;
case LEVEL: case OTHER:
this.buildOtherRequirementsPanel(panelBuilder); this.buildOtherRequirementsPanel(panelBuilder);
break; break;
} }
@ -320,7 +320,7 @@ public class EditChallengeGUI extends CommonGUI
{ {
icon = new ItemStack(Material.CHEST); icon = new ItemStack(Material.CHEST);
} }
else if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.LEVEL)) else if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.OTHER))
{ {
icon = new ItemStack(Material.EXPERIENCE_BOTTLE); icon = new ItemStack(Material.EXPERIENCE_BOTTLE);
} }
@ -427,13 +427,13 @@ public class EditChallengeGUI extends CommonGUI
description = Collections.singletonList( description = Collections.singletonList(
this.user.getTranslation("challenges.gui.admin.descriptions.order", this.user.getTranslation("challenges.gui.admin.descriptions.order",
"[value]", "[value]",
Integer.toString(this.challenge.getSlot()))); Integer.toString(this.challenge.getOrder())));
icon = new ItemStack(Material.DROPPER); icon = new ItemStack(Material.DROPPER);
clickHandler = (panel, user, clickType, slot) -> { clickHandler = (panel, user, clickType, slot) -> {
new NumberGUI(this.user, this.challenge.getSlot(), -1, 54, (status, value) -> { new NumberGUI(this.user, this.challenge.getOrder(), -1, 54, (status, value) -> {
if (status) if (status)
{ {
this.challenge.setSlot(value); this.challenge.setOrder(value);
} }
this.build(); this.build();
@ -640,13 +640,13 @@ public class EditChallengeGUI extends CommonGUI
case REQUIRED_PERMISSIONS: case REQUIRED_PERMISSIONS:
{ {
name = this.user.getTranslation("challenges.gui.admin.buttons.permissions"); name = this.user.getTranslation("challenges.gui.admin.buttons.permissions");
description = new ArrayList<>(this.challenge.getReqPerms()); description = new ArrayList<>(this.challenge.getRequiredPermissions());
icon = new ItemStack(Material.REDSTONE_LAMP); icon = new ItemStack(Material.REDSTONE_LAMP);
clickHandler = (panel, user, clickType, slot) -> { clickHandler = (panel, user, clickType, slot) -> {
new StringListGUI(this.user, this.challenge.getReqPerms(), (status, value) -> { new StringListGUI(this.user, this.challenge.getRequiredPermissions(), (status, value) -> {
if (status) if (status)
{ {
this.challenge.setReqPerms(new HashSet<>(value)); this.challenge.setRequiredPermissions(new HashSet<>(value));
} }
this.build(); this.build();
@ -713,13 +713,13 @@ public class EditChallengeGUI extends CommonGUI
description = Collections.singletonList( description = Collections.singletonList(
this.user.getTranslation("challenges.gui.admin.descriptions.required-exp", this.user.getTranslation("challenges.gui.admin.descriptions.required-exp",
"[value]", "[value]",
Integer.toString(this.challenge.getMaxTimes()))); Integer.toString(this.challenge.getRequiredExperience())));
icon = new ItemStack(Material.EXPERIENCE_BOTTLE); icon = new ItemStack(Material.EXPERIENCE_BOTTLE);
clickHandler = (panel, user, clickType, slot) -> { clickHandler = (panel, user, clickType, slot) -> {
new NumberGUI(this.user, this.challenge.getReqExp(), 0, (status, value) -> { new NumberGUI(this.user, this.challenge.getRequiredExperience(), 0, (status, value) -> {
if (status) if (status)
{ {
this.challenge.setReqExp(value); this.challenge.setRequiredExperience(value);
} }
this.build(); this.build();
@ -758,13 +758,13 @@ public class EditChallengeGUI extends CommonGUI
description = Collections.singletonList( description = Collections.singletonList(
this.user.getTranslation("challenges.gui.admin.descriptions.required-level", this.user.getTranslation("challenges.gui.admin.descriptions.required-level",
"[value]", "[value]",
Long.toString(this.challenge.getReqIslandlevel()))); Long.toString(this.challenge.getRequiredIslandLevel())));
icon = new ItemStack(Material.BEACON); icon = new ItemStack(Material.BEACON);
clickHandler = (panel, user, clickType, slot) -> { clickHandler = (panel, user, clickType, slot) -> {
new NumberGUI(this.user, (int) this.challenge.getReqIslandlevel(), (status, value) -> { new NumberGUI(this.user, (int) this.challenge.getRequiredIslandLevel(), (status, value) -> {
if (status) if (status)
{ {
this.challenge.setReqIslandlevel(value); this.challenge.setRequiredIslandLevel(value);
} }
this.build(); this.build();
@ -781,13 +781,13 @@ public class EditChallengeGUI extends CommonGUI
description = Collections.singletonList( description = Collections.singletonList(
this.user.getTranslation("challenges.gui.admin.descriptions.required-money", this.user.getTranslation("challenges.gui.admin.descriptions.required-money",
"[value]", "[value]",
Integer.toString(this.challenge.getReqMoney()))); Integer.toString(this.challenge.getRequiredMoney())));
icon = new ItemStack(Material.GOLD_INGOT); icon = new ItemStack(Material.GOLD_INGOT);
clickHandler = (panel, user, clickType, slot) -> { clickHandler = (panel, user, clickType, slot) -> {
new NumberGUI(this.user, this.challenge.getReqMoney(), 0, (status, value) -> { new NumberGUI(this.user, this.challenge.getRequiredMoney(), 0, (status, value) -> {
if (status) if (status)
{ {
this.challenge.setReqMoney(value); this.challenge.setRequiredMoney(value);
} }
this.build(); this.build();
@ -874,13 +874,13 @@ public class EditChallengeGUI extends CommonGUI
description = Collections.singletonList( description = Collections.singletonList(
this.user.getTranslation("challenges.gui.admin.descriptions.reward-exp", this.user.getTranslation("challenges.gui.admin.descriptions.reward-exp",
"[value]", "[value]",
Integer.toString(this.challenge.getRewardExp()))); Integer.toString(this.challenge.getRewardExperience())));
icon = new ItemStack(Material.EXPERIENCE_BOTTLE); icon = new ItemStack(Material.EXPERIENCE_BOTTLE);
clickHandler = (panel, user, clickType, slot) -> { clickHandler = (panel, user, clickType, slot) -> {
new NumberGUI(this.user, this.challenge.getReqExp(), 0, (status, value) -> { new NumberGUI(this.user, this.challenge.getRewardExperience(), 0, (status, value) -> {
if (status) if (status)
{ {
this.challenge.setRewardExp(value); this.challenge.setRewardExperience(value);
} }
this.build(); this.build();
@ -1035,13 +1035,13 @@ public class EditChallengeGUI extends CommonGUI
description = Collections.singletonList( description = Collections.singletonList(
this.user.getTranslation("challenges.gui.admin.descriptions.repeat-reward-exp", this.user.getTranslation("challenges.gui.admin.descriptions.repeat-reward-exp",
"[value]", "[value]",
Integer.toString(this.challenge.getRepeatExpReward()))); Integer.toString(this.challenge.getRepeatExperienceReward())));
icon = new ItemStack(Material.GLASS_BOTTLE); icon = new ItemStack(Material.GLASS_BOTTLE);
clickHandler = (panel, user, clickType, slot) -> { clickHandler = (panel, user, clickType, slot) -> {
new NumberGUI(this.user, this.challenge.getRepeatExpReward(), 0, (status, value) -> { new NumberGUI(this.user, this.challenge.getRepeatExperienceReward(), 0, (status, value) -> {
if (status) if (status)
{ {
this.challenge.setRepeatExpReward(value); this.challenge.setRepeatExperienceReward(value);
} }
this.build(); this.build();
@ -1234,4 +1234,4 @@ public class EditChallengeGUI extends CommonGUI
* Variable holds current active menu. * Variable holds current active menu.
*/ */
private MenuType currentMenuType; private MenuType currentMenuType;
} }

View File

@ -398,13 +398,13 @@ public class EditLevelGUI extends CommonGUI
description = Collections.singletonList( description = Collections.singletonList(
this.user.getTranslation("challenges.gui.admin.descriptions.waiver-amount", this.user.getTranslation("challenges.gui.admin.descriptions.waiver-amount",
"[value]", "[value]",
Integer.toString(this.challengeLevel.getWaiveramount()))); Integer.toString(this.challengeLevel.getWaiverAmount())));
icon = new ItemStack(Material.REDSTONE_TORCH); icon = new ItemStack(Material.REDSTONE_TORCH);
clickHandler = (panel, user, clickType, slot) -> { clickHandler = (panel, user, clickType, slot) -> {
new NumberGUI(this.user, this.challengeLevel.getWaiveramount(), 0, (status, value) -> { new NumberGUI(this.user, this.challengeLevel.getWaiverAmount(), 0, (status, value) -> {
if (status) if (status)
{ {
this.challengeLevel.setWaiveramount(value); this.challengeLevel.setWaiverAmount(value);
} }
this.build(); this.build();
@ -419,14 +419,14 @@ public class EditLevelGUI extends CommonGUI
case REWARD_DESCRIPTION: case REWARD_DESCRIPTION:
{ {
name = this.user.getTranslation("challenges.gui.admin.buttons.reward-text"); name = this.user.getTranslation("challenges.gui.admin.buttons.reward-text");
description = Collections.singletonList(this.challengeLevel.getRewardDescription()); description = Collections.singletonList(this.challengeLevel.getRewardText());
icon = new ItemStack(Material.WRITTEN_BOOK); icon = new ItemStack(Material.WRITTEN_BOOK);
clickHandler = (panel, user, clickType, slot) -> { clickHandler = (panel, user, clickType, slot) -> {
new AnvilGUI(this.addon.getPlugin(), new AnvilGUI(this.addon.getPlugin(),
this.user.getPlayer(), this.user.getPlayer(),
this.challengeLevel.getRewardDescription(), this.challengeLevel.getRewardText(),
(player, reply) -> { (player, reply) -> {
this.challengeLevel.setRewardDescription(reply); this.challengeLevel.setRewardText(reply);
this.build(); this.build();
return reply; return reply;
}); });
@ -468,13 +468,13 @@ public class EditLevelGUI extends CommonGUI
description = Collections.singletonList( description = Collections.singletonList(
this.user.getTranslation("challenges.gui.admin.descriptions.reward-exp", this.user.getTranslation("challenges.gui.admin.descriptions.reward-exp",
"[value]", "[value]",
Integer.toString(this.challengeLevel.getExpReward()))); Integer.toString(this.challengeLevel.getRewardExperience())));
icon = new ItemStack(Material.EXPERIENCE_BOTTLE); icon = new ItemStack(Material.EXPERIENCE_BOTTLE);
clickHandler = (panel, user, clickType, slot) -> { clickHandler = (panel, user, clickType, slot) -> {
new NumberGUI(this.user, this.challengeLevel.getExpReward(), 0, (status, value) -> { new NumberGUI(this.user, this.challengeLevel.getRewardExperience(), 0, (status, value) -> {
if (status) if (status)
{ {
this.challengeLevel.setExpReward(value); this.challengeLevel.setRewardExperience(value);
} }
this.build(); this.build();
@ -491,13 +491,13 @@ public class EditLevelGUI extends CommonGUI
description = Collections.singletonList( description = Collections.singletonList(
this.user.getTranslation("challenges.gui.admin.descriptions.reward-money", this.user.getTranslation("challenges.gui.admin.descriptions.reward-money",
"[value]", "[value]",
Integer.toString(this.challengeLevel.getMoneyReward()))); Integer.toString(this.challengeLevel.getRewardMoney())));
icon = new ItemStack(Material.GOLD_INGOT); icon = new ItemStack(Material.GOLD_INGOT);
clickHandler = (panel, user, clickType, slot) -> { clickHandler = (panel, user, clickType, slot) -> {
new NumberGUI(this.user, this.challengeLevel.getMoneyReward(), 0, (status, value) -> { new NumberGUI(this.user, this.challengeLevel.getRewardMoney(), 0, (status, value) -> {
if (status) if (status)
{ {
this.challengeLevel.setMoneyReward(value); this.challengeLevel.setRewardMoney(value);
} }
this.build(); this.build();
@ -544,7 +544,7 @@ public class EditLevelGUI extends CommonGUI
new SelectChallengeGUI(this.user, challengeList, (status, value) -> { new SelectChallengeGUI(this.user, challengeList, (status, value) -> {
if (status) if (status)
{ {
manager.linkChallenge(this.challengeLevel, value); manager.addChallengeToLevel(value, this.challengeLevel);
} }
this.build(); this.build();
@ -636,4 +636,4 @@ public class EditLevelGUI extends CommonGUI
* Variable holds current active menu. * Variable holds current active menu.
*/ */
private MenuType currentMenuType; private MenuType currentMenuType;
} }

View File

@ -443,13 +443,13 @@ public class ChallengesGUI extends CommonGUI
{ {
rewardText = challenge.getRewardText(); rewardText = challenge.getRewardText();
rewardMoney = challenge.getRewardMoney(); rewardMoney = challenge.getRewardMoney();
rewardExperience = challenge.getRewardExp(); rewardExperience = challenge.getRewardExperience();
} }
else else
{ {
rewardText = challenge.getRepeatRewardText(); rewardText = challenge.getRepeatRewardText();
rewardMoney = challenge.getRepeatMoneyReward(); rewardMoney = challenge.getRepeatMoneyReward();
rewardExperience = challenge.getRepeatExpReward(); rewardExperience = challenge.getRepeatExperienceReward();
} }
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();