mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-12-01 06:53:37 +01:00
Add GUI for editing Challenge and Challenge Level lore messages.
Rework Lore message construction.
This commit is contained in:
parent
747c12f1a6
commit
c7fe138d78
@ -1,7 +1,9 @@
|
||||
package world.bentobox.challenges.config;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Material;
|
||||
@ -12,7 +14,12 @@ import world.bentobox.bentobox.api.configuration.ConfigEntry;
|
||||
import world.bentobox.bentobox.api.configuration.ConfigObject;
|
||||
import world.bentobox.bentobox.api.configuration.StoreAt;
|
||||
|
||||
import world.bentobox.bentobox.database.objects.adapters.Adapter;
|
||||
import world.bentobox.challenges.config.SettingsUtils.GuiMode;
|
||||
import world.bentobox.challenges.config.SettingsUtils.ChallengeLore;
|
||||
import world.bentobox.challenges.config.SettingsUtils.LevelLore;
|
||||
import world.bentobox.challenges.database.object.adapters.ChallengeLoreAdapter;
|
||||
import world.bentobox.challenges.database.object.adapters.LevelLoreAdapter;
|
||||
|
||||
|
||||
@StoreAt(filename="config.yml", path="addons/Challenges")
|
||||
@ -98,35 +105,41 @@ public class Settings implements ConfigObject
|
||||
@ConfigComment("one object from challenge description. If letter is not used, then its represented part")
|
||||
@ConfigComment("will not be in description. If use any letter that is not recognized, then it will be")
|
||||
@ConfigComment("ignored. Some strings can be customized via lang file under 'challenges.gui.challenge-description'.")
|
||||
@ConfigComment("List of letters and their meaning: ")
|
||||
@ConfigComment(" - L - Level String: '*.level'")
|
||||
@ConfigComment(" - S - Status String: '*.completed'")
|
||||
@ConfigComment(" - T - Times String: '*.completed-times', '*.completed-times-of' or '*.maxed-reached'")
|
||||
@ConfigComment(" - D - Description String: defined in challenge object - challenge.description")
|
||||
@ConfigComment(" - W - Warning String: '*.warning-items-take', '*.objects-close-by', '*.warning-entities-kill', '*.warning-blocks-remove'")
|
||||
@ConfigComment(" - E - Environment String: defined in challenge object - challenge.environment")
|
||||
@ConfigComment(" - Q - Requirement String: '*.required-level', '*.required-money', '*.required-experience'")
|
||||
@ConfigComment(" - R - Reward String: '*.experience-reward', '*.money-reward', '*.not-repeatable'")
|
||||
@ConfigComment("By adding 'i' after Q or R (requirements and rewards) will display list of items, blocks")
|
||||
@ConfigComment("and entities that are defined in challenge and can be customized under 'challenges.gui.description.*'")
|
||||
@ConfigEntry(path = "gui-settings.challenge-lore-message")
|
||||
private String challengeLoreMessage = "LSTDEQiWRi";
|
||||
@ConfigComment("List of values and their meaning: ")
|
||||
@ConfigComment(" - LEVEL - Level String: '*.level'")
|
||||
@ConfigComment(" - STATUS - Status String: '*.completed'")
|
||||
@ConfigComment(" - COUNT - Times String: '*.completed-times', '*.completed-times-of' or '*.maxed-reached'")
|
||||
@ConfigComment(" - DESCRIPTION - Description String: defined in challenge object - challenge.description")
|
||||
@ConfigComment(" - WARNINGS - Warning String: '*.warning-items-take', '*.objects-close-by', '*.warning-entities-kill', '*.warning-blocks-remove'")
|
||||
@ConfigComment(" - ENVIRONMENT - Environment String: defined in challenge object - challenge.environment")
|
||||
@ConfigComment(" - REQUIREMENTS - Requirement String: '*.required-level', '*.required-money', '*.required-experience' and items, blocks or entities")
|
||||
@ConfigComment(" - REWARD_TEXT - Reward String: message that is defined in challenge.rewardTest and challenge.repeatRewardText")
|
||||
@ConfigComment(" - REWARD_OTHER - Reward extra String: '*.experience-reward', '*.money-reward', '*.not-repeatable'")
|
||||
@ConfigComment(" - REWARD_ITEMS - Reward Items: List of items that will be rewarded.")
|
||||
@ConfigComment(" - REWARD_COMMANDS - Reward Commands: List of commands that will be rewarded.")
|
||||
@ConfigComment("Requirement and reward items, blocks and entities that are defined in challenge and can be customized under 'challenges.gui.item-description.*'")
|
||||
@ConfigEntry(path = "gui-settings.challenge-lore")
|
||||
@Adapter(ChallengeLoreAdapter.class)
|
||||
private List<ChallengeLore> challengeLoreMessage = new ArrayList<>();
|
||||
|
||||
@ConfigComment("")
|
||||
@ConfigComment("This string allows to change element order in Level description. Each letter represents")
|
||||
@ConfigComment("one object from level description. If letter is not used, then its represented part")
|
||||
@ConfigComment("will not be in description. If use any letter that is not recognized, then it will be")
|
||||
@ConfigComment("ignored. Some strings can be customized via lang file under 'challenges.gui.level-description'.")
|
||||
@ConfigComment("List of letters and their meaning: ")
|
||||
@ConfigComment(" - S - Status String: '*.completed'")
|
||||
@ConfigComment(" - T - Count of completed challenges String: '*.completed-challenges-of'")
|
||||
@ConfigComment(" - D - Description String: defined in level object - challengeLevel.unlockMessage")
|
||||
@ConfigComment(" - A - WaiverAmount String: '*.waver-amount'")
|
||||
@ConfigComment(" - R - Reward String: '*.experience-reward', '*.money-reward', '*.not-repeatable'")
|
||||
@ConfigComment("By adding 'i' after R (rewards) will display list of items that are defined in challenge")
|
||||
@ConfigComment("and can be customized under 'challenges.gui.description.*'")
|
||||
@ConfigEntry(path = "gui-settings.level-lore-message")
|
||||
private String levelLoreMessage = "STDARi";
|
||||
@ConfigComment("List of values and their meaning: ")
|
||||
@ConfigComment(" - LEVEL_STATUS - Status String: '*.completed'")
|
||||
@ConfigComment(" - CHALLENGE_COUNT - Count of completed challenges String: '*.completed-challenges-of'")
|
||||
@ConfigComment(" - UNLOCK_MESSAGE - Description String: defined in level object - challengeLevel.unlockMessage")
|
||||
@ConfigComment(" - WAIVER_AMOUNT - WaiverAmount String: '*.waver-amount'")
|
||||
@ConfigComment(" - LEVEL_REWARD_TEXT - Reward String: message that is defined in challengeLevel.rewardText.")
|
||||
@ConfigComment(" - LEVEL_REWARD_OTHER - Reward extra String: '*.experience-reward', '*.money-reward'")
|
||||
@ConfigComment(" - LEVEL_REWARD_ITEMS - Reward Items: List of items that will be rewarded.")
|
||||
@ConfigComment(" - LEVEL_REWARD_COMMANDS - Reward Commands: List of commands that will be rewarded.")
|
||||
@ConfigComment("Reward items that are defined in challenge level and can be customized under 'challenges.gui.item-description.*'")
|
||||
@ConfigEntry(path = "gui-settings.level-lore")
|
||||
@Adapter(LevelLoreAdapter.class)
|
||||
private List<LevelLore> levelLoreMessage = new ArrayList<>();
|
||||
|
||||
@ConfigComment("")
|
||||
@ConfigComment("This indicate if challenges data will be stored per island (true) or per player (false).")
|
||||
@ -187,7 +200,7 @@ public class Settings implements ConfigObject
|
||||
* This method returns the challengeLoreMessage object.
|
||||
* @return the challengeLoreMessage object.
|
||||
*/
|
||||
public String getChallengeLoreMessage()
|
||||
public List<ChallengeLore> getChallengeLoreMessage()
|
||||
{
|
||||
return challengeLoreMessage;
|
||||
}
|
||||
@ -271,7 +284,7 @@ public class Settings implements ConfigObject
|
||||
* This method returns the levelLoreMessage object.
|
||||
* @return the levelLoreMessage object.
|
||||
*/
|
||||
public String getLevelLoreMessage()
|
||||
public List<LevelLore> getLevelLoreMessage()
|
||||
{
|
||||
return levelLoreMessage;
|
||||
}
|
||||
@ -455,7 +468,7 @@ public class Settings implements ConfigObject
|
||||
* This method sets the challengeLoreMessage object value.
|
||||
* @param challengeLoreMessage the challengeLoreMessage object new value.
|
||||
*/
|
||||
public void setChallengeLoreMessage(String challengeLoreMessage)
|
||||
public void setChallengeLoreMessage(List<ChallengeLore> challengeLoreMessage)
|
||||
{
|
||||
this.challengeLoreMessage = challengeLoreMessage;
|
||||
}
|
||||
@ -465,7 +478,7 @@ public class Settings implements ConfigObject
|
||||
* This method sets the levelLoreMessage object value.
|
||||
* @param levelLoreMessage the levelLoreMessage object new value.
|
||||
*/
|
||||
public void setLevelLoreMessage(String levelLoreMessage)
|
||||
public void setLevelLoreMessage(List<LevelLore> levelLoreMessage)
|
||||
{
|
||||
this.levelLoreMessage = levelLoreMessage;
|
||||
}
|
||||
|
@ -26,4 +26,132 @@ public class SettingsUtils
|
||||
*/
|
||||
CURRENT_WORLD
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This enum holds all possible values for Challenge Lore Message.
|
||||
*/
|
||||
public enum ChallengeLore
|
||||
{
|
||||
/**
|
||||
* Level String: 'challenges.gui.challenge-description.level'
|
||||
*/
|
||||
LEVEL,
|
||||
|
||||
/**
|
||||
* Status String: 'challenges.gui.challenge-description.completed'
|
||||
*/
|
||||
STATUS,
|
||||
|
||||
/**
|
||||
* Completion Times String:
|
||||
* 'challenges.gui.challenge-description.completed-times',
|
||||
* 'challenges.gui.challenge-description.completed-times-of'
|
||||
* 'challenges.gui.challenge-description.maxed-reached'
|
||||
*/
|
||||
COUNT,
|
||||
|
||||
/**
|
||||
* Description String: defined in challenge object - challenge.description
|
||||
*/
|
||||
DESCRIPTION,
|
||||
|
||||
/**
|
||||
* Warning String:
|
||||
* 'challenges.gui.challenge-description.warning-items-take'
|
||||
* 'challenges.gui.challenge-description.objects-close-by'
|
||||
* 'challenges.gui.challenge-description.warning-entities-kill'
|
||||
* 'challenges.gui.challenge-description.warning-blocks-remove'
|
||||
*/
|
||||
WARNINGS,
|
||||
|
||||
/**
|
||||
* Environment String: defined in challenge object - challenge.environment
|
||||
*/
|
||||
ENVIRONMENT,
|
||||
|
||||
/**
|
||||
* Requirement String:
|
||||
* 'challenges.gui.challenge-description.required-level'
|
||||
* 'challenges.gui.challenge-description.required-money'
|
||||
* 'challenges.gui.challenge-description.required-experience'
|
||||
* and challenge.requiredItems, challenge.requiredBlocks or challenge.requiredEntities
|
||||
*/
|
||||
REQUIREMENTS,
|
||||
|
||||
/**
|
||||
* Reward String: message that is defined in challenge.rewardTest and challenge.repeatRewardText
|
||||
*/
|
||||
REWARD_TEXT,
|
||||
|
||||
/**
|
||||
* Reward other String:
|
||||
* 'challenges.gui.challenge-description.experience-reward'
|
||||
* 'challenges.gui.challenge-description.money-reward'
|
||||
* 'challenges.gui.challenge-description.not-repeatable'
|
||||
*/
|
||||
REWARD_OTHER,
|
||||
|
||||
/**
|
||||
* Reward Items: List of items that will be rewarded defined in challenge.rewardItems and
|
||||
* challenge.repeatRewardItems.
|
||||
*/
|
||||
REWARD_ITEMS,
|
||||
|
||||
/**
|
||||
* Reward commands: List of commands that will be rewarded defined in challenge.rewardCommands
|
||||
* and challenge.repeatRewardCommands.
|
||||
*/
|
||||
REWARD_COMMANDS,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This enum holds all possible values for Level Lore Message.
|
||||
*/
|
||||
public enum LevelLore
|
||||
{
|
||||
/**
|
||||
* Status String: 'challenges.gui.level-description.completed'
|
||||
*/
|
||||
LEVEL_STATUS,
|
||||
|
||||
/**
|
||||
* Completed Challenge count String: 'challenges.gui.level-description.completed-challenges-of'
|
||||
*/
|
||||
CHALLENGE_COUNT,
|
||||
|
||||
/**
|
||||
* Unlock message String: defined in challenge level object - challengeLevel.unlockMessage
|
||||
*/
|
||||
UNLOCK_MESSAGE,
|
||||
|
||||
/**
|
||||
* Count of challenges which can be skipped to unlock next level string:
|
||||
* 'challenges.gui.level-description.waver-amount'
|
||||
*/
|
||||
WAIVER_AMOUNT,
|
||||
|
||||
/**
|
||||
* Reward String: message that is defined in challengeLevel.rewardTest
|
||||
*/
|
||||
LEVEL_REWARD_TEXT,
|
||||
|
||||
/**
|
||||
* Reward other String:
|
||||
* 'challenges.gui.level-description.experience-reward'
|
||||
* 'challenges.gui.level-description.money-reward'
|
||||
*/
|
||||
LEVEL_REWARD_OTHER,
|
||||
|
||||
/**
|
||||
* Reward Items: List of items that will be rewarded defined in challengeLevel.rewardItems.
|
||||
*/
|
||||
LEVEL_REWARD_ITEMS,
|
||||
|
||||
/**
|
||||
* Reward commands: List of commands that will be rewarded defined in challengeLevel.rewardCommands.
|
||||
*/
|
||||
LEVEL_REWARD_COMMANDS,
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
//
|
||||
// Created by BONNe
|
||||
// Copyright - 2019
|
||||
//
|
||||
|
||||
|
||||
package world.bentobox.challenges.database.object.adapters;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import world.bentobox.bentobox.database.objects.adapters.AdapterInterface;
|
||||
import world.bentobox.challenges.config.SettingsUtils.ChallengeLore;
|
||||
|
||||
|
||||
/**
|
||||
* This adapter allows to serialize and deserialize ChallengeLore object.
|
||||
*/
|
||||
public class ChallengeLoreAdapter implements AdapterInterface<List<ChallengeLore>, List<String>>
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<ChallengeLore> deserialize(Object from)
|
||||
{
|
||||
List<ChallengeLore> result;
|
||||
|
||||
if (from instanceof List)
|
||||
{
|
||||
result = ((List<String>) from).stream().
|
||||
map(ChallengeLore::valueOf).
|
||||
collect(Collectors.toCollection(ArrayList::new));
|
||||
}
|
||||
else
|
||||
{
|
||||
result = new ArrayList<>(0);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<String> serialize(Object to)
|
||||
{
|
||||
List<String> result;
|
||||
|
||||
if (to instanceof List)
|
||||
{
|
||||
result = ((List<ChallengeLore>) to).stream().
|
||||
map(ChallengeLore::name).
|
||||
collect(Collectors.toCollection(ArrayList::new));
|
||||
}
|
||||
else
|
||||
{
|
||||
result = new ArrayList<>(0);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
//
|
||||
// Created by BONNe
|
||||
// Copyright - 2019
|
||||
//
|
||||
|
||||
|
||||
package world.bentobox.challenges.database.object.adapters;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import world.bentobox.bentobox.database.objects.adapters.AdapterInterface;
|
||||
import world.bentobox.challenges.config.SettingsUtils.LevelLore;
|
||||
|
||||
|
||||
/**
|
||||
* This adapter allows to serialize and deserialize LevelLore object.
|
||||
*/
|
||||
public class LevelLoreAdapter implements AdapterInterface<List<LevelLore>, List<String>>
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<LevelLore> deserialize(Object from)
|
||||
{
|
||||
List<LevelLore> result;
|
||||
|
||||
if (from instanceof List)
|
||||
{
|
||||
result = ((List<String>) from).stream().
|
||||
map(LevelLore::valueOf).
|
||||
collect(Collectors.toCollection(ArrayList::new));
|
||||
}
|
||||
else
|
||||
{
|
||||
result = new ArrayList<>(0);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<String> serialize(Object to)
|
||||
{
|
||||
List<String> result;
|
||||
|
||||
if (to instanceof List)
|
||||
{
|
||||
result = ((List<LevelLore>) to).stream().
|
||||
map(LevelLore::name).
|
||||
collect(Collectors.toCollection(ArrayList::new));
|
||||
}
|
||||
else
|
||||
{
|
||||
result = new ArrayList<>(0);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@ -336,21 +336,19 @@ public abstract class CommonGUI
|
||||
// Some values to avoid overchecking.
|
||||
ChallengesManager manager = this.addon.getChallengesManager();
|
||||
|
||||
final boolean isCompletedOnce = manager.isChallengeComplete(user.getUniqueId(), world, challenge);
|
||||
final boolean isCompletedOnce =
|
||||
manager.isChallengeComplete(user.getUniqueId(), world, challenge);
|
||||
final long doneTimes = challenge.isRepeatable() ?
|
||||
manager.getChallengeTimes(this.user, this.world, challenge) :
|
||||
isCompletedOnce ? 0 : 1;
|
||||
manager.getChallengeTimes(this.user, this.world, challenge) : isCompletedOnce ? 0 : 1;
|
||||
|
||||
boolean isCompletedAll = isCompletedOnce && challenge.isRepeatable() &&
|
||||
challenge.getMaxTimes() > 0 && doneTimes >= challenge.getMaxTimes();
|
||||
challenge.getMaxTimes() > 0 &&
|
||||
doneTimes >= challenge.getMaxTimes();
|
||||
|
||||
// Used to know if blocks, entities, items should be added after requirements and rewards.
|
||||
char prevChar = ' ';
|
||||
|
||||
for (char c : this.addon.getChallengesSettings().getChallengeLoreMessage().toLowerCase().toCharArray())
|
||||
this.addon.getChallengesSettings().getChallengeLoreMessage().forEach(messagePart -> {
|
||||
switch (messagePart)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'l':
|
||||
case LEVEL:
|
||||
{
|
||||
ChallengeLevel level = manager.getLevel(challenge);
|
||||
|
||||
@ -361,21 +359,22 @@ public abstract class CommonGUI
|
||||
}
|
||||
else
|
||||
{
|
||||
result.add(this.user.getTranslation("challenges.gui.challenge-description.level",
|
||||
result.add(this.user
|
||||
.getTranslation("challenges.gui.challenge-description.level",
|
||||
"[level]", level.getFriendlyName()));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 's':
|
||||
case STATUS:
|
||||
{
|
||||
if (isCompletedOnce)
|
||||
{
|
||||
result.add(this.user.getTranslation("challenges.gui.challenge-description.completed"));
|
||||
result.add(this.user
|
||||
.getTranslation("challenges.gui.challenge-description.completed"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 't':
|
||||
case COUNT:
|
||||
{
|
||||
if (challenge.isRepeatable())
|
||||
{
|
||||
@ -383,35 +382,39 @@ public abstract class CommonGUI
|
||||
{
|
||||
if (isCompletedAll)
|
||||
{
|
||||
result.add(this.user.getTranslation("challenges.gui.challenge-description.maxed-reached",
|
||||
"[donetimes]", String.valueOf(doneTimes),
|
||||
"[maxtimes]", String.valueOf(challenge.getMaxTimes())));
|
||||
result.add(this.user.getTranslation(
|
||||
"challenges.gui.challenge-description.maxed-reached",
|
||||
"[donetimes]",
|
||||
String.valueOf(doneTimes),
|
||||
"[maxtimes]",
|
||||
String.valueOf(challenge.getMaxTimes())));
|
||||
}
|
||||
else
|
||||
{
|
||||
result.add(this.user.getTranslation(
|
||||
"challenges.gui.challenge-description.completed-times-of",
|
||||
"[donetimes]", String.valueOf(doneTimes),
|
||||
"[maxtimes]", String.valueOf(challenge.getMaxTimes())));
|
||||
"[donetimes]",
|
||||
String.valueOf(doneTimes),
|
||||
"[maxtimes]",
|
||||
String.valueOf(challenge.getMaxTimes())));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result.add(this.user.getTranslation("challenges.gui.challenge-description.completed-times",
|
||||
"[donetimes]", String.valueOf(doneTimes)));
|
||||
result.add(this.user.getTranslation(
|
||||
"challenges.gui.challenge-description.completed-times",
|
||||
"[donetimes]",
|
||||
String.valueOf(doneTimes)));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'd':
|
||||
{
|
||||
if (!isCompletedAll)
|
||||
case DESCRIPTION:
|
||||
{
|
||||
result.addAll(challenge.getDescription());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'w':
|
||||
case WARNINGS:
|
||||
{
|
||||
if (!isCompletedAll)
|
||||
{
|
||||
@ -425,15 +428,18 @@ public abstract class CommonGUI
|
||||
}
|
||||
else if (challenge.getChallengeType().equals(Challenge.ChallengeType.ISLAND))
|
||||
{
|
||||
result.add(this.user.getTranslation("challenges.gui.challenge-description.objects-close-by"));
|
||||
result.add(this.user.getTranslation(
|
||||
"challenges.gui.challenge-description.objects-close-by"));
|
||||
|
||||
if (challenge.isRemoveEntities() && !challenge.getRequiredEntities().isEmpty())
|
||||
if (challenge.isRemoveEntities() &&
|
||||
!challenge.getRequiredEntities().isEmpty())
|
||||
{
|
||||
result.add(this.user.getTranslation(
|
||||
"challenges.gui.challenge-description.warning-entities-kill"));
|
||||
}
|
||||
|
||||
if (challenge.isRemoveBlocks() && !challenge.getRequiredBlocks().isEmpty())
|
||||
if (challenge.isRemoveBlocks() &&
|
||||
!challenge.getRequiredBlocks().isEmpty())
|
||||
{
|
||||
result.add(this.user.getTranslation(
|
||||
"challenges.gui.challenge-description.warning-blocks-remove"));
|
||||
@ -442,7 +448,7 @@ public abstract class CommonGUI
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'e':
|
||||
case ENVIRONMENT:
|
||||
{
|
||||
// Display only if there are limited environments
|
||||
|
||||
@ -469,15 +475,23 @@ public abstract class CommonGUI
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'q':
|
||||
case REQUIREMENTS:
|
||||
{
|
||||
if (!isCompletedAll && challenge.getChallengeType() == Challenge.ChallengeType.OTHER)
|
||||
if (!isCompletedAll)
|
||||
{
|
||||
if (challenge.getChallengeType() == Challenge.ChallengeType.OTHER)
|
||||
{
|
||||
result.addAll(this.getChallengeRequirements(challenge));
|
||||
}
|
||||
else
|
||||
{
|
||||
result.addAll(this.getChallengeRequiredItems(challenge));
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 'r':
|
||||
case REWARD_TEXT:
|
||||
{
|
||||
if (isCompletedAll)
|
||||
{
|
||||
@ -485,33 +499,43 @@ public abstract class CommonGUI
|
||||
}
|
||||
else
|
||||
{
|
||||
result.addAll(this.getChallengeRewards(challenge, isCompletedOnce));
|
||||
if (isCompletedOnce)
|
||||
{
|
||||
result.add(challenge.getRepeatRewardText());
|
||||
}
|
||||
else
|
||||
{
|
||||
result.add(challenge.getRewardText());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'i':
|
||||
case REWARD_OTHER:
|
||||
{
|
||||
if (!isCompletedAll)
|
||||
{
|
||||
if (prevChar == 'q' && challenge.getChallengeType() != Challenge.ChallengeType.OTHER)
|
||||
{
|
||||
result.addAll(this.getChallengeRequiredItems(challenge));
|
||||
}
|
||||
else if (prevChar == 'r')
|
||||
{
|
||||
result.addAll(this.getChallengeRewardItems(challenge, isCompletedOnce, user));
|
||||
}
|
||||
result.addAll(this.getChallengeRewardOthers(challenge, isCompletedOnce));
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
case REWARD_ITEMS:
|
||||
{
|
||||
if (!isCompletedAll)
|
||||
{
|
||||
result.addAll(this.getChallengeRewardItems(challenge, isCompletedOnce));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case REWARD_COMMANDS:
|
||||
{
|
||||
if (!isCompletedAll)
|
||||
{
|
||||
result.addAll(this.getChallengeRewardCommands(challenge, isCompletedOnce, user));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
prevChar = c;
|
||||
}
|
||||
});
|
||||
|
||||
result.replaceAll(x -> x.replace("[label]", this.topLabel));
|
||||
|
||||
@ -525,31 +549,25 @@ public abstract class CommonGUI
|
||||
* @param isCompletedOnce indicate if must use repeat rewards
|
||||
* @return list of strings that contains rewards message.
|
||||
*/
|
||||
private List<String> getChallengeRewards(Challenge challenge, boolean isCompletedOnce)
|
||||
private List<String> getChallengeRewardOthers(Challenge challenge, boolean isCompletedOnce)
|
||||
{
|
||||
String rewardText;
|
||||
double rewardMoney;
|
||||
int rewardExperience;
|
||||
|
||||
|
||||
if (!isCompletedOnce)
|
||||
{
|
||||
rewardText = challenge.getRewardText();
|
||||
rewardMoney = challenge.getRewardMoney();
|
||||
rewardExperience = challenge.getRewardExperience();
|
||||
}
|
||||
else
|
||||
{
|
||||
rewardText = challenge.getRepeatRewardText();
|
||||
rewardMoney = challenge.getRepeatMoneyReward();
|
||||
rewardExperience = challenge.getRepeatExperienceReward();
|
||||
}
|
||||
|
||||
List<String> result = new ArrayList<>();
|
||||
|
||||
// Add reward text
|
||||
result.add(rewardText);
|
||||
|
||||
// Add message about reward XP
|
||||
if (rewardExperience > 0)
|
||||
{
|
||||
@ -569,28 +587,24 @@ public abstract class CommonGUI
|
||||
|
||||
|
||||
/**
|
||||
* This method returns list of strings that contains reward items and commands from given challenge.
|
||||
* This method returns list of strings that contains reward items from given challenge.
|
||||
* @param challenge Challenge which reward items and commands must be returned.
|
||||
* @param isCompletedOnce Boolean that indicate if must use repeat rewards.
|
||||
* @param user Target user for command string.
|
||||
* @return List of strings that contains message from challenges.
|
||||
*/
|
||||
private List<String> getChallengeRewardItems(Challenge challenge, boolean isCompletedOnce, Player user)
|
||||
private List<String> getChallengeRewardItems(Challenge challenge, boolean isCompletedOnce)
|
||||
{
|
||||
List<String> result = new ArrayList<>();
|
||||
|
||||
List<ItemStack> rewardItems;
|
||||
List<String> rewardCommands;
|
||||
|
||||
if (!isCompletedOnce)
|
||||
if (isCompletedOnce)
|
||||
{
|
||||
rewardItems = challenge.getRewardItems();
|
||||
rewardCommands = challenge.getRewardCommands();
|
||||
rewardItems = challenge.getRepeatItemReward();
|
||||
}
|
||||
else
|
||||
{
|
||||
rewardItems = challenge.getRepeatItemReward();
|
||||
rewardCommands = challenge.getRepeatRewardCommands();
|
||||
rewardItems = challenge.getRewardItems();
|
||||
}
|
||||
|
||||
// Add message about reward items
|
||||
@ -602,6 +616,32 @@ public abstract class CommonGUI
|
||||
result.addAll(this.generateItemStackDescription(itemStack)));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method returns list of strings that contains reward commands from given challenge.
|
||||
* @param challenge Challenge which reward items and commands must be returned.
|
||||
* @param isCompletedOnce Boolean that indicate if must use repeat rewards.
|
||||
* @param user Target user for command string.
|
||||
* @return List of strings that contains message from challenges.
|
||||
*/
|
||||
private List<String> getChallengeRewardCommands(Challenge challenge, boolean isCompletedOnce, Player user)
|
||||
{
|
||||
List<String> result = new ArrayList<>();
|
||||
|
||||
List<String> rewardCommands;
|
||||
|
||||
if (isCompletedOnce)
|
||||
{
|
||||
rewardCommands = challenge.getRepeatRewardCommands();
|
||||
}
|
||||
else
|
||||
{
|
||||
rewardCommands = challenge.getRewardCommands();
|
||||
}
|
||||
|
||||
// Add message about reward commands
|
||||
if (!rewardCommands.isEmpty())
|
||||
{
|
||||
@ -723,14 +763,15 @@ public abstract class CommonGUI
|
||||
ChallengesManager manager = this.addon.getChallengesManager();
|
||||
LevelStatus status = manager.getChallengeLevelStatus(user.getUniqueId(), this.world, level);
|
||||
|
||||
// Used to know if blocks, entities, items should be added after requirements and rewards.
|
||||
char prevChar = ' ';
|
||||
// Check if unlock message should appear.
|
||||
boolean hasCompletedOne = status.isComplete() || status.isUnlocked() &&
|
||||
level.getChallenges().stream().anyMatch(challenge ->
|
||||
this.addon.getChallengesManager().isChallengeComplete(user.getUniqueId(), world, challenge));
|
||||
|
||||
for (char c : this.addon.getChallengesSettings().getLevelLoreMessage().toLowerCase().toCharArray())
|
||||
this.addon.getChallengesSettings().getLevelLoreMessage().forEach(messagePart -> {
|
||||
switch (messagePart)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 's':
|
||||
case LEVEL_STATUS:
|
||||
{
|
||||
if (status.isComplete())
|
||||
{
|
||||
@ -738,9 +779,9 @@ public abstract class CommonGUI
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 't':
|
||||
case CHALLENGE_COUNT:
|
||||
{
|
||||
if (!status.isComplete())
|
||||
if (!status.isComplete() && status.isUnlocked())
|
||||
{
|
||||
int doneChallengeCount = (int) level.getChallenges().stream().
|
||||
filter(challenge -> this.addon.getChallengesManager().isChallengeComplete(user.getUniqueId(), world, challenge)).
|
||||
@ -750,33 +791,43 @@ public abstract class CommonGUI
|
||||
"[number]", Integer.toString(doneChallengeCount),
|
||||
"[max]", Integer.toString(level.getChallenges().size())));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 'd':
|
||||
case UNLOCK_MESSAGE:
|
||||
{
|
||||
if (!status.isUnlocked())
|
||||
if (!hasCompletedOne)
|
||||
{
|
||||
result.add(level.getUnlockMessage());
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 'a':
|
||||
case WAIVER_AMOUNT:
|
||||
{
|
||||
if (!status.isUnlocked() && !status.isComplete())
|
||||
if (status.isUnlocked() && !status.isComplete())
|
||||
{
|
||||
result.add(this.user.getTranslation("challenges.gui.level-description.waver-amount",
|
||||
"[value]", Integer.toString(level.getWaiverAmount())));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 'r':
|
||||
case LEVEL_REWARD_TEXT:
|
||||
{
|
||||
if (status.isUnlocked() && !status.isComplete())
|
||||
{
|
||||
result.add(level.getRewardText());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case LEVEL_REWARD_OTHER:
|
||||
{
|
||||
if (status.isUnlocked() && !status.isComplete())
|
||||
{
|
||||
if (level.getRewardExperience() > 0)
|
||||
{
|
||||
result.add(this.user
|
||||
.getTranslation("challenges.gui.level-description.experience-reward",
|
||||
result.add(this.user.getTranslation("challenges.gui.level-description.experience-reward",
|
||||
"[value]", Integer.toString(level.getRewardExperience())));
|
||||
}
|
||||
|
||||
@ -788,21 +839,20 @@ public abstract class CommonGUI
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'i':
|
||||
case LEVEL_REWARD_ITEMS:
|
||||
{
|
||||
if (status.isUnlocked() && !status.isComplete() && prevChar == 'r')
|
||||
{
|
||||
// Add message about reward items
|
||||
if (!level.getRewardItems().isEmpty())
|
||||
if (status.isUnlocked() && !status.isComplete() && !level.getRewardItems().isEmpty())
|
||||
{
|
||||
result.add(this.user.getTranslation("challenges.gui.level-description.reward-items"));
|
||||
|
||||
Utils.groupEqualItems(level.getRewardItems()).forEach(itemStack ->
|
||||
result.addAll(this.generateItemStackDescription(itemStack)));
|
||||
}
|
||||
|
||||
// Add message about reward commands
|
||||
if (!level.getRewardCommands().isEmpty())
|
||||
break;
|
||||
}
|
||||
case LEVEL_REWARD_COMMANDS:
|
||||
{
|
||||
if (status.isUnlocked() && !status.isComplete() && !level.getRewardCommands().isEmpty())
|
||||
{
|
||||
result.add(this.user.getTranslation("challenges.gui.level-description.reward-commands"));
|
||||
|
||||
@ -812,17 +862,10 @@ public abstract class CommonGUI
|
||||
"[command]", command.replace("[player]", user.getName()).replace("[SELF]", "")));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
prevChar = c;
|
||||
}
|
||||
});
|
||||
|
||||
result.replaceAll(x -> x.replace("[label]", this.topLabel));
|
||||
|
||||
@ -836,7 +879,7 @@ public abstract class CommonGUI
|
||||
|
||||
|
||||
/**
|
||||
* This method generates decsription for given item stack object.
|
||||
* This method generates description for given item stack object.
|
||||
* @param itemStack Object which lore must be generated
|
||||
* @return List with generated description
|
||||
*/
|
||||
|
@ -0,0 +1,630 @@
|
||||
package world.bentobox.challenges.panel.admin;
|
||||
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import java.util.*;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||
import world.bentobox.bentobox.api.panels.PanelListener;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.challenges.config.SettingsUtils.ChallengeLore;
|
||||
import world.bentobox.challenges.config.SettingsUtils.LevelLore;
|
||||
import world.bentobox.challenges.panel.CommonGUI;
|
||||
import world.bentobox.challenges.utils.GuiUtils;
|
||||
|
||||
|
||||
/**
|
||||
* This class allows to change Input ItemStacks to different ItemStacks.
|
||||
*/
|
||||
public class EditLoreGUI extends CommonGUI
|
||||
{
|
||||
public EditLoreGUI(CommonGUI parent, LoreType loreType)
|
||||
{
|
||||
super(parent);
|
||||
|
||||
this.lore = loreType;
|
||||
this.activeValues = new ArrayList<>();
|
||||
|
||||
switch (this.lore)
|
||||
{
|
||||
case CHALLENGES:
|
||||
|
||||
for (ChallengeLore lore : this.addon.getChallengesSettings().getChallengeLoreMessage())
|
||||
{
|
||||
this.activeValues.add(lore.name());
|
||||
}
|
||||
|
||||
break;
|
||||
case LEVELS:
|
||||
|
||||
for (LevelLore lore : this.addon.getChallengesSettings().getLevelLoreMessage())
|
||||
{
|
||||
this.activeValues.add(lore.name());
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This is static call method for easier GUI opening.
|
||||
* @param parent Parent GUI.
|
||||
* @param loreType loreType that will be edited.
|
||||
*/
|
||||
public static void open(CommonGUI parent, LoreType loreType)
|
||||
{
|
||||
new EditLoreGUI(parent, loreType).build();
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Methods
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* This method builds panel that allows to change given number value.
|
||||
*/
|
||||
@Override
|
||||
public void build()
|
||||
{
|
||||
PanelBuilder panelBuilder = new PanelBuilder().
|
||||
name(this.user.getTranslation("challenges.gui.title.admin.lore-edit")).
|
||||
user(this.user).
|
||||
listener(new CustomPanelListener());
|
||||
|
||||
GuiUtils.fillBorder(panelBuilder, 5, Material.MAGENTA_STAINED_GLASS_PANE);
|
||||
|
||||
// Define all active buttons
|
||||
panelBuilder.item(1, this.getButton(Button.SAVE));
|
||||
|
||||
panelBuilder.item(3, this.getButton(Button.ADD));
|
||||
panelBuilder.item(4, this.getButton(Button.REMOVE));
|
||||
|
||||
// TODO: Need 2 View Buttons
|
||||
// One for closes / One for opened.
|
||||
// panelBuilder.item(6, this.getButton(Button.VIEW));
|
||||
|
||||
panelBuilder.item(44, this.returnButton);
|
||||
|
||||
// necessary as I have a border around this GUI
|
||||
int currentIndex = 10;
|
||||
|
||||
// Only 21 elements will be displayed. On porpoise!
|
||||
for (int i = 0; i < this.activeValues.size() || i > 21; i++)
|
||||
{
|
||||
panelBuilder.item(currentIndex++, this.getLoreButton(this.activeValues.get(i)));
|
||||
|
||||
// Border element
|
||||
if (currentIndex % 9 == 8)
|
||||
{
|
||||
currentIndex += 2;
|
||||
}
|
||||
|
||||
// Just in case. Should never occur.
|
||||
if (currentIndex % 9 == 0)
|
||||
{
|
||||
currentIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
panelBuilder.build();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method create button that does some functionality in current gui.
|
||||
* @param button Button functionality.
|
||||
* @return PanelItem.
|
||||
*/
|
||||
private PanelItem getButton(Button button)
|
||||
{
|
||||
ItemStack icon;
|
||||
String name;
|
||||
List<String> description;
|
||||
PanelItem.ClickHandler clickHandler;
|
||||
|
||||
switch (button)
|
||||
{
|
||||
case SAVE:
|
||||
{
|
||||
name = this.user.getTranslation("challenges.gui.buttons.admin.save");
|
||||
description = Collections.emptyList();
|
||||
icon = new ItemStack(Material.COMMAND_BLOCK);
|
||||
clickHandler = (panel, user, clickType, slot) -> {
|
||||
|
||||
switch (this.lore)
|
||||
{
|
||||
case CHALLENGES:
|
||||
{
|
||||
List<ChallengeLore> lore = this.activeValues.stream().
|
||||
map(ChallengeLore::valueOf).
|
||||
collect(Collectors.toCollection(() -> new ArrayList<>(this.activeValues.size())));
|
||||
|
||||
this.addon.getChallengesSettings().setChallengeLoreMessage(lore);
|
||||
|
||||
break;
|
||||
}
|
||||
case LEVELS:
|
||||
{
|
||||
List<LevelLore> lore = this.activeValues.stream().
|
||||
map(LevelLore::valueOf).
|
||||
collect(Collectors.toCollection(() -> new ArrayList<>(this.activeValues.size())));
|
||||
|
||||
this.addon.getChallengesSettings().setLevelLoreMessage(lore);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Save and return to parent gui.
|
||||
this.parentGUI.build();
|
||||
|
||||
return true;
|
||||
};
|
||||
break;
|
||||
}
|
||||
case ADD:
|
||||
{
|
||||
name = this.user.getTranslation("challenges.gui.buttons.admin.add");
|
||||
description = Collections.emptyList();
|
||||
icon = new ItemStack(Material.GREEN_STAINED_GLASS_PANE);
|
||||
clickHandler = (panel, user, clickType, slot) -> {
|
||||
new AddLoreElementGUI(element -> {
|
||||
this.activeValues.add(element);
|
||||
this.build();
|
||||
});
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
break;
|
||||
}
|
||||
case REMOVE:
|
||||
{
|
||||
name = this.user.getTranslation("challenges.gui.buttons.admin.remove-selected");
|
||||
description = Collections.emptyList();
|
||||
icon = new ItemStack(Material.RED_STAINED_GLASS_PANE);
|
||||
clickHandler = (panel, user, clickType, slot) -> {
|
||||
new RemoveLoreElementGUI((element, index) -> {
|
||||
if (this.activeValues.get(index).equals(element))
|
||||
{
|
||||
this.activeValues.remove(element);
|
||||
}
|
||||
|
||||
this.build();
|
||||
});
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
break;
|
||||
}
|
||||
case VIEW:
|
||||
{
|
||||
name = this.user.getTranslation("challenges.gui.buttons.admin.view");
|
||||
description = Collections.emptyList();
|
||||
icon = new ItemStack(Material.YELLOW_STAINED_GLASS_PANE);
|
||||
clickHandler = (panel, user, clickType, slot) -> {
|
||||
return true;
|
||||
};
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
return new PanelItemBuilder().
|
||||
icon(icon).
|
||||
name(name).
|
||||
description(GuiUtils.stringSplit(description, this.addon.getChallengesSettings().getLoreLineLength())).
|
||||
glow(false).
|
||||
clickHandler(clickHandler).
|
||||
build();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method creates button for lore element.
|
||||
* @param loreElement String that represents current lore element.
|
||||
* @return PanelItem.
|
||||
*/
|
||||
private PanelItem getLoreButton(String loreElement)
|
||||
{
|
||||
switch (this.lore)
|
||||
{
|
||||
case CHALLENGES:
|
||||
return this.getChallengeLoreButton(loreElement);
|
||||
case LEVELS:
|
||||
return this.getLevelLoreButton(loreElement);
|
||||
default:
|
||||
// this should never happen!
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method creates button for challenge lore element.
|
||||
* @param loreElement String that represents current challenge lore element.
|
||||
* @return PanelItem.
|
||||
*/
|
||||
private PanelItem getChallengeLoreButton(String loreElement)
|
||||
{
|
||||
Material icon;
|
||||
String name = loreElement;
|
||||
List<String> description = new ArrayList<>();
|
||||
description.add(this.user.getTranslation(REFERENCE_DESCRIPTION + "lore." + loreElement.toLowerCase()));
|
||||
|
||||
PanelItem.ClickHandler clickHandler = (panel, user1, clickType, slot) -> true;
|
||||
|
||||
switch (ChallengeLore.valueOf(loreElement))
|
||||
{
|
||||
case LEVEL:
|
||||
{
|
||||
icon = Material.DIRT;
|
||||
break;
|
||||
}
|
||||
case STATUS:
|
||||
{
|
||||
icon = Material.LEVER;
|
||||
break;
|
||||
}
|
||||
case COUNT:
|
||||
{
|
||||
icon = Material.REPEATER;
|
||||
break;
|
||||
}
|
||||
case DESCRIPTION:
|
||||
{
|
||||
icon = Material.WRITTEN_BOOK;
|
||||
break;
|
||||
}
|
||||
case WARNINGS:
|
||||
{
|
||||
icon = Material.LAVA_BUCKET;
|
||||
break;
|
||||
}
|
||||
case ENVIRONMENT:
|
||||
{
|
||||
icon = Material.GLASS;
|
||||
break;
|
||||
}
|
||||
case REQUIREMENTS:
|
||||
{
|
||||
icon = Material.HOPPER;
|
||||
break;
|
||||
}
|
||||
case REWARD_TEXT:
|
||||
{
|
||||
icon = Material.PAPER;
|
||||
break;
|
||||
}
|
||||
case REWARD_OTHER:
|
||||
{
|
||||
icon = Material.CHEST;
|
||||
break;
|
||||
}
|
||||
case REWARD_ITEMS:
|
||||
{
|
||||
icon = Material.TRAPPED_CHEST;
|
||||
break;
|
||||
}
|
||||
case REWARD_COMMANDS:
|
||||
{
|
||||
icon = Material.COMMAND_BLOCK;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
icon = Material.BARRIER;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new PanelItemBuilder().
|
||||
name(name).
|
||||
icon(icon).
|
||||
description(description).
|
||||
clickHandler(clickHandler).
|
||||
glow(false).
|
||||
build();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method creates button for challenge level lore element.
|
||||
* @param loreElement String that represents current challenge level lore element.
|
||||
* @return PanelItem.
|
||||
*/
|
||||
private PanelItem getLevelLoreButton(String loreElement)
|
||||
{
|
||||
Material icon;
|
||||
String name = loreElement;
|
||||
List<String> description = new ArrayList<>();
|
||||
description.add(this.user.getTranslation(REFERENCE_DESCRIPTION + "lore." + loreElement.toLowerCase()));
|
||||
|
||||
PanelItem.ClickHandler clickHandler = (panel, user1, clickType, slot) -> true;
|
||||
|
||||
switch (LevelLore.valueOf(loreElement))
|
||||
{
|
||||
case LEVEL_STATUS:
|
||||
{
|
||||
icon = Material.DIRT;
|
||||
break;
|
||||
}
|
||||
case CHALLENGE_COUNT:
|
||||
{
|
||||
icon = Material.REPEATER;
|
||||
break;
|
||||
}
|
||||
case UNLOCK_MESSAGE:
|
||||
{
|
||||
icon = Material.WRITTEN_BOOK;
|
||||
break;
|
||||
}
|
||||
case WAIVER_AMOUNT:
|
||||
{
|
||||
icon = Material.COMPARATOR;
|
||||
break;
|
||||
}
|
||||
case LEVEL_REWARD_TEXT:
|
||||
{
|
||||
icon = Material.PAPER;
|
||||
break;
|
||||
}
|
||||
case LEVEL_REWARD_OTHER:
|
||||
{
|
||||
icon = Material.CHEST;
|
||||
break;
|
||||
}
|
||||
case LEVEL_REWARD_ITEMS:
|
||||
{
|
||||
icon = Material.TRAPPED_CHEST;
|
||||
break;
|
||||
}
|
||||
case LEVEL_REWARD_COMMANDS:
|
||||
{
|
||||
icon = Material.COMMAND_BLOCK;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
icon = Material.BARRIER;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new PanelItemBuilder().
|
||||
name(name).
|
||||
icon(icon).
|
||||
description(description).
|
||||
clickHandler(clickHandler).
|
||||
glow(false).
|
||||
build();
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Select GUI
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* This class opens new GUI that add an element from all available lore values.
|
||||
*/
|
||||
private class AddLoreElementGUI
|
||||
{
|
||||
private AddLoreElementGUI(Consumer<String> selectedElement)
|
||||
{
|
||||
PanelBuilder panelBuilder = new PanelBuilder().
|
||||
name(EditLoreGUI.this.user.getTranslation("challenges.gui.title.admin.lore-add")).
|
||||
user(EditLoreGUI.this.user);
|
||||
|
||||
GuiUtils.fillBorder(panelBuilder, 5, Material.MAGENTA_STAINED_GLASS_PANE);
|
||||
|
||||
int currentIndex = 10;
|
||||
|
||||
List<String> values = new ArrayList<>();
|
||||
|
||||
// Populate list with all elements.
|
||||
switch (EditLoreGUI.this.lore)
|
||||
{
|
||||
case CHALLENGES:
|
||||
for (ChallengeLore value : ChallengeLore.values())
|
||||
{
|
||||
values.add(value.name());
|
||||
}
|
||||
break;
|
||||
case LEVELS:
|
||||
for (LevelLore value : LevelLore.values())
|
||||
{
|
||||
values.add(value.name());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
for (String value : values)
|
||||
{
|
||||
PanelItem item = EditLoreGUI.this.getLoreButton(value);
|
||||
|
||||
item.setClickHandler((panel, user1, clickType, slot) -> {
|
||||
selectedElement.accept(value);
|
||||
return true;
|
||||
});
|
||||
|
||||
panelBuilder.item(currentIndex++, item);
|
||||
|
||||
// Border element
|
||||
if (currentIndex % 9 == 8)
|
||||
{
|
||||
currentIndex += 2;
|
||||
}
|
||||
|
||||
// Just in case. Should never occur.
|
||||
if (currentIndex % 9 == 0)
|
||||
{
|
||||
currentIndex++;
|
||||
}
|
||||
|
||||
// Just in case. Should never occur.
|
||||
if (currentIndex > 35)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
panelBuilder.build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This class opens new GUI that remove an element from all available lore values.
|
||||
*/
|
||||
private class RemoveLoreElementGUI
|
||||
{
|
||||
private RemoveLoreElementGUI(BiConsumer<String, Integer> selectedElement)
|
||||
{
|
||||
PanelBuilder panelBuilder = new PanelBuilder().
|
||||
name(EditLoreGUI.this.user.getTranslation("challenges.gui.title.admin.lore-remove")).
|
||||
user(EditLoreGUI.this.user);
|
||||
|
||||
GuiUtils.fillBorder(panelBuilder, 5, Material.MAGENTA_STAINED_GLASS_PANE);
|
||||
|
||||
int currentIndex = 10;
|
||||
|
||||
List<String> values = EditLoreGUI.this.activeValues;
|
||||
|
||||
for (int i = 0; i < values.size(); i++)
|
||||
{
|
||||
final int counter = i;
|
||||
|
||||
String value = values.get(counter);
|
||||
PanelItem item = EditLoreGUI.this.getLoreButton(value);
|
||||
|
||||
item.setClickHandler((panel, user1, clickType, slot) -> {
|
||||
selectedElement.accept(value, counter);
|
||||
return true;
|
||||
});
|
||||
|
||||
panelBuilder.item(currentIndex++, item);
|
||||
|
||||
// Border element
|
||||
if (currentIndex % 9 == 8)
|
||||
{
|
||||
currentIndex += 2;
|
||||
}
|
||||
|
||||
// Just in case. Should never occur.
|
||||
if (currentIndex % 9 == 0)
|
||||
{
|
||||
currentIndex++;
|
||||
}
|
||||
|
||||
// Just in case. Should never occur.
|
||||
if (currentIndex > 35)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
panelBuilder.build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Private classes
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* This CustomPanelListener allows to move items in current panel.
|
||||
*/
|
||||
private class CustomPanelListener implements PanelListener
|
||||
{
|
||||
@Override
|
||||
public void setup()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onInventoryClose(InventoryCloseEvent inventoryCloseEvent)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onInventoryClick(User user, InventoryClickEvent event)
|
||||
{
|
||||
// First row of elements should be ignored, as it contains buttons and blocked slots.
|
||||
event.setCancelled(event.getRawSlot() < 9 ||
|
||||
event.getRawSlot() < 35 ||
|
||||
event.getRawSlot() % 9 == 0 ||
|
||||
event.getRawSlot() % 9 == 8);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Enums
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* This enum holds all button values in current gui.
|
||||
*/
|
||||
private enum Button
|
||||
{
|
||||
SAVE,
|
||||
ADD,
|
||||
REMOVE,
|
||||
VIEW,
|
||||
RETURN
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This enum holds which Lore is edited with current GUI.
|
||||
*/
|
||||
public enum LoreType
|
||||
{
|
||||
CHALLENGES,
|
||||
LEVELS,
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Variables
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Lore that will be edited with current GUI.
|
||||
*/
|
||||
private final LoreType lore;
|
||||
|
||||
/**
|
||||
* List of lore elements that are currently enabled.
|
||||
*/
|
||||
private List<String> activeValues;
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Constants
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
|
||||
private final static String REFERENCE_DESCRIPTION = "challenges.gui.descriptions.admin.";
|
||||
}
|
@ -236,21 +236,11 @@ public class EditSettingsGUI extends CommonGUI
|
||||
{
|
||||
description = new ArrayList<>(2);
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.level-lore"));
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
||||
"[value]", this.settings.getLevelLoreMessage()));
|
||||
name = this.user.getTranslation("challenges.gui.buttons.admin.level-lore");
|
||||
icon = new ItemStack(Material.MAP);
|
||||
clickHandler = (panel, user1, clickType, i) -> {
|
||||
|
||||
// TODO: AnvilGUI is out. Need to implement better GUI for editing this.
|
||||
// new AnvilGUI(this.addon.getPlugin(),
|
||||
// this.user.getPlayer(),
|
||||
// this.settings.getLevelLoreMessage(),
|
||||
// (player, reply) -> {
|
||||
// this.settings.setLevelLoreMessage(reply);
|
||||
// panel.getInventory().setItem(i, this.getSettingsButton(button).getItem());
|
||||
// return reply;
|
||||
// });
|
||||
EditLoreGUI.open(this, EditLoreGUI.LoreType.LEVELS);
|
||||
|
||||
return true;
|
||||
};
|
||||
@ -261,21 +251,11 @@ public class EditSettingsGUI extends CommonGUI
|
||||
{
|
||||
description = new ArrayList<>(2);
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.challenge-lore"));
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
||||
"[value]", this.settings.getChallengeLoreMessage()));
|
||||
name = this.user.getTranslation("challenges.gui.buttons.admin.challenge-lore");
|
||||
icon = new ItemStack(Material.PAPER);
|
||||
clickHandler = (panel, user1, clickType, i) -> {
|
||||
// TODO: AnvilGUI is out. Need to implement better GUI for editing this.
|
||||
|
||||
// new AnvilGUI(this.addon.getPlugin(),
|
||||
// this.user.getPlayer(),
|
||||
// this.settings.getChallengeLoreMessage(),
|
||||
// (player, reply) -> {
|
||||
// this.settings.setChallengeLoreMessage(reply);
|
||||
// panel.getInventory().setItem(i, this.getSettingsButton(button).getItem());
|
||||
// return reply;
|
||||
// });
|
||||
EditLoreGUI.open(this, EditLoreGUI.LoreType.CHALLENGES);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
@ -62,32 +62,55 @@ gui-settings:
|
||||
# one object from challenge description. If letter is not used, then its represented part
|
||||
# will not be in description. If use any letter that is not recognized, then it will be
|
||||
# ignored. Some strings can be customized via lang file under 'challenges.gui.challenge-description'.
|
||||
# List of letters and their meaning:
|
||||
# - L - Level String: '*.level'
|
||||
# - S - Status String: '*.completed'
|
||||
# - T - Times String: '*.completed-times', '*.completed-times-of' or '*.maxed-reached'
|
||||
# - D - Description String: defined in challenge object - challenge.description
|
||||
# - W - Warning String: '*.warning-items-take', '*.objects-close-by', '*.warning-entities-kill', '*.warning-blocks-remove'
|
||||
# - E - Environment String: defined in challenge object - challenge.environment
|
||||
# - Q - Requirement String: '*.required-level', '*.required-money', '*.required-experience'
|
||||
# - R - Reward String: '*.experience-reward', '*.money-reward', '*.not-repeatable'
|
||||
# By adding 'i' after Q or R (requirements and rewards) will display list of items, blocks
|
||||
# and entities that are defined in challenge and can be customized under 'challenges.gui.description.*'
|
||||
challenge-lore-message: LSTDEQiWRi
|
||||
# List of values and their meaning:
|
||||
# - LEVEL - Level String: '*.level'
|
||||
# - STATUS - Status String: '*.completed'
|
||||
# - COUNT - Times String: '*.completed-times', '*.completed-times-of' or '*.maxed-reached'
|
||||
# - DESCRIPTION - Description String: defined in challenge object - challenge.description
|
||||
# - WARNINGS - Warning String: '*.warning-items-take', '*.objects-close-by', '*.warning-entities-kill', '*.warning-blocks-remove'
|
||||
# - ENVIRONMENT - Environment String: defined in challenge object - challenge.environment
|
||||
# - REQUIREMENTS - Requirement String: '*.required-level', '*.required-money', '*.required-experience' and items, blocks or entities
|
||||
# - REWARD_TEXT - Reward String: message that is defined in challenge.rewardTest and challenge.repeatRewardText
|
||||
# - REWARD_OTHER - Reward extra String: '*.experience-reward', '*.money-reward', '*.not-repeatable'
|
||||
# - REWARD_ITEMS - Reward Items: List of items that will be rewarded.
|
||||
# - REWARD_COMMANDS - Reward Commands: List of commands that will be rewarded.
|
||||
# Requirement and reward items, blocks and entities that are defined in challenge and can be customized under 'challenges.gui.item-description.*'
|
||||
challenge-lore:
|
||||
- LEVEL
|
||||
- STATUS
|
||||
- COUNT
|
||||
- DESCRIPTION
|
||||
- WARNINGS
|
||||
- ENVIRONMENT
|
||||
- REQUIREMENTS
|
||||
- REWARD_TEXT
|
||||
- REWARD_OTHER
|
||||
- REWARD_ITEMS
|
||||
- REWARD_COMMANDS
|
||||
#
|
||||
# This string allows to change element order in Level description. Each letter represents
|
||||
# one object from level description. If letter is not used, then its represented part
|
||||
# will not be in description. If use any letter that is not recognized, then it will be
|
||||
# ignored. Some strings can be customized via lang file under 'challenges.gui.level-description'.
|
||||
# List of letters and their meaning:
|
||||
# - S - Status String: '*.completed'
|
||||
# - T - Count of completed challenges String: '*.completed-challenges-of'
|
||||
# - D - Description String: defined in level object - challengeLevel.unlockMessage
|
||||
# - A - WaiverAmount String: '*.waver-amount'
|
||||
# - R - Reward String: '*.experience-reward', '*.money-reward', '*.not-repeatable'
|
||||
# By adding 'i' after R (rewards) will display list of items that are defined in challenge
|
||||
# and can be customized under 'challenges.gui.description.*'
|
||||
level-lore-message: STDARi
|
||||
# List of values and their meaning:
|
||||
# - LEVEL_STATUS - Status String: '*.completed'
|
||||
# - CHALLENGE_COUNT - Count of completed challenges String: '*.completed-challenges-of'
|
||||
# - UNLOCK_MESSAGE - Description String: defined in level object - challengeLevel.unlockMessage
|
||||
# - WAIVER_AMOUNT - WaiverAmount String: '*.waver-amount'
|
||||
# - LEVEL_REWARD_TEXT - Reward String: message that is defined in challengeLevel.rewardText.
|
||||
# - LEVEL_REWARD_OTHER - Reward extra String: '*.experience-reward', '*.money-reward'
|
||||
# - LEVEL_REWARD_ITEMS - Reward Items: List of items that will be rewarded.
|
||||
# - LEVEL_REWARD_COMMANDS - Reward Commands: List of commands that will be rewarded.
|
||||
# Reward items that are defined in challenge level and can be customized under 'challenges.gui.item-description.*'
|
||||
level-lore:
|
||||
- LEVEL_STATUS
|
||||
- CHALLENGE_COUNT
|
||||
- UNLOCK_MESSAGE
|
||||
- WAIVER_AMOUNT
|
||||
- LEVEL_REWARD_TEXT
|
||||
- LEVEL_REWARD_OTHER
|
||||
- LEVEL_REWARD_ITEMS
|
||||
- LEVEL_REWARD_COMMANDS
|
||||
#
|
||||
# This indicate if challenges data will be stored per island (true) or per player (false).
|
||||
store-island-data: false
|
||||
|
@ -273,6 +273,28 @@ challenges:
|
||||
library-lang: '&aLanguage: [lang]'
|
||||
library-gamemode: '&aPrimary for [gamemode]'
|
||||
|
||||
lore:
|
||||
level: "Level string. | Represents translation 'challenges.gui.challenge-description.level'."
|
||||
status: "Status string. | Represents translation 'challenges.gui.challenge-description.completed'."
|
||||
count: "Completion count string. | Represents translation for 'challenges.gui.challenge-description.completed-times', 'challenges.gui.challenge-description.completed-times-of' and 'challenges.gui.challenge-description.maxed-reached'."
|
||||
description: "Description string. | Defined in challenges object - challenge.description."
|
||||
warnings: "Warning string. | Represents translation for: | 'challenges.gui.challenge-description.warning-items-take' | 'challenges.gui.challenge-description.objects-close-by' | 'challenges.gui.challenge-description.warning-entities-kill' | 'challenges.gui.challenge-description.warning-blocks-remove'."
|
||||
environment: "Environment string. | Defined in challenges object - challenge.environment."
|
||||
requirements: "Requirement string. | Represents translation for: | 'challenges.gui.challenge-description.required-level' | 'challenges.gui.challenge-description.required-money' | 'challenges.gui.challenge-description.required-experience' | and challenge.requiredItems, challenge.requiredBlocks or challenge.requiredEntities."
|
||||
reward_text: "Reward string. | Defined in challenge.rewardText and challenge.repeatRewardText"
|
||||
reward_other: "Reward other String. | Represents translation for: | 'challenges.gui.challenge-description.experience-reward' | 'challenges.gui.challenge-description.money-reward' | 'challenges.gui.challenge-description.not-repeatable'."
|
||||
reward_items: "Reward Items. | List of items that will be rewarded defined in challenge.rewardItems and challenge.repeatRewardItems."
|
||||
reward_commands: "Reward Commands. | List of commands that will be rewarded defined in challenge.rewardCommands and challenge.repeatRewardCommands."
|
||||
|
||||
level_status: "Status string. | Represents translation 'challenges.gui.level-description.completed'."
|
||||
challenge_count: "Completed challenge count string. | Represents translation for 'challenges.gui.level-description.completed-challenges-of'"
|
||||
unlock_message: "Unlock message string. | Defined in challenges Level object - challengeLevel.unlockMessage."
|
||||
waiver_amount: "Shippable challenge count to unlock next level string. | Represents translation for 'challenges.gui.level-description.waver-amount'"
|
||||
level_reward_text: "Reward string. | Defined in challengeLevel.rewardText"
|
||||
level_reward_other: "Reward other String. | Represents translation for: | 'challenges.gui.level-description.experience-reward' | 'challenges.gui.level-description.money-reward'."
|
||||
level_reward_items: "Reward Items. | List of items that will be rewarded defined in challengeLevel.rewardItems."
|
||||
level_reward_commands: "Reward Commands. | List of commands that will be rewarded defined in challengeLevel.rewardCommands."
|
||||
|
||||
current-value: '|&6Current value: [value].'
|
||||
enabled: 'Active'
|
||||
disabled: 'Disabled'
|
||||
|
Loading…
Reference in New Issue
Block a user