Skip to content

Commit

Permalink
Add GUI for editing Challenge and Challenge Level lore messages.
Browse files Browse the repository at this point in the history
Rework Lore message construction.
  • Loading branch information
BONNe authored and BuildTools committed Sep 3, 2019
1 parent 747c12f commit c7fe138
Show file tree
Hide file tree
Showing 9 changed files with 1,277 additions and 312 deletions.
67 changes: 40 additions & 27 deletions src/main/java/world/bentobox/challenges/config/Settings.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,7 +14,12 @@
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")
Expand Down Expand Up @@ -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).")
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -271,7 +284,7 @@ public int getLoreLineLength()
* This method returns the levelLoreMessage object.
* @return the levelLoreMessage object.
*/
public String getLevelLoreMessage()
public List<LevelLore> getLevelLoreMessage()
{
return levelLoreMessage;
}
Expand Down Expand Up @@ -455,7 +468,7 @@ public void setConfigVersion(String configVersion)
* 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;
}
Expand All @@ -465,7 +478,7 @@ public void setChallengeLoreMessage(String challengeLoreMessage)
* 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;
}
Expand Down
128 changes: 128 additions & 0 deletions src/main/java/world/bentobox/challenges/config/SettingsUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,132 @@ public enum GuiMode
*/
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,
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit c7fe138

Please sign in to comment.