mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-11-13 06:05:46 +01:00
Implement MetaData ignoring for rewards.
While required items had a metadata grouping, reward items did not have it. This will fix that. Fixes #289
This commit is contained in:
parent
71e0029d46
commit
88215b6f0c
@ -177,6 +177,11 @@ public class Challenge implements DataObject
|
||||
@Expose
|
||||
private List<String> rewardCommands = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Set of item stacks that should ignore metadata.
|
||||
*/
|
||||
@Expose
|
||||
private Set<Material> ignoreRewardMetaData = new HashSet<>();
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Repeat Rewards
|
||||
@ -457,6 +462,17 @@ public class Challenge implements DataObject
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets ignore reward meta data.
|
||||
*
|
||||
* @return the ignore reward meta data
|
||||
*/
|
||||
public Set<Material> getIgnoreRewardMetaData()
|
||||
{
|
||||
return ignoreRewardMetaData;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Setters
|
||||
// ---------------------------------------------------------------------
|
||||
@ -724,6 +740,17 @@ public class Challenge implements DataObject
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets ignore reward meta data.
|
||||
*
|
||||
* @param ignoreRewardMetaData the ignore reward meta data
|
||||
*/
|
||||
public void setIgnoreRewardMetaData(Set<Material> ignoreRewardMetaData)
|
||||
{
|
||||
this.ignoreRewardMetaData = ignoreRewardMetaData;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Other methods
|
||||
// ---------------------------------------------------------------------
|
||||
@ -856,6 +883,7 @@ public class Challenge implements DataObject
|
||||
clone.setRepeatMoneyReward(this.repeatMoneyReward);
|
||||
clone.setRepeatRewardCommands(new ArrayList<>(this.repeatRewardCommands));
|
||||
clone.setTimeout(this.timeout);
|
||||
clone.setIgnoreRewardMetaData(new HashSet<>(this.ignoreRewardMetaData));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -115,6 +115,10 @@ public class ChallengeLevel implements DataObject, Comparable<ChallengeLevel>
|
||||
@Expose
|
||||
private Set<String> challenges = new HashSet<>();
|
||||
|
||||
@ConfigComment("")
|
||||
@ConfigComment("Set of materials which metadata can be ignored.")
|
||||
@Expose
|
||||
private Set<Material> ignoreRewardMetaData = new HashSet<>();
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Getters
|
||||
@ -263,6 +267,17 @@ public class ChallengeLevel implements DataObject, Comparable<ChallengeLevel>
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets ignore reward meta data.
|
||||
*
|
||||
* @return the ignore reward meta data
|
||||
*/
|
||||
public Set<Material> getIgnoreRewardMetaData()
|
||||
{
|
||||
return ignoreRewardMetaData;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Setters
|
||||
// ---------------------------------------------------------------------
|
||||
@ -424,6 +439,17 @@ public class ChallengeLevel implements DataObject, Comparable<ChallengeLevel>
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets ignore reward meta data.
|
||||
*
|
||||
* @param ignoreRewardMetaData the ignore reward meta data
|
||||
*/
|
||||
public void setIgnoreRewardMetaData(Set<Material> ignoreRewardMetaData)
|
||||
{
|
||||
this.ignoreRewardMetaData = ignoreRewardMetaData;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Other methods
|
||||
// ---------------------------------------------------------------------
|
||||
@ -564,6 +590,7 @@ public class ChallengeLevel implements DataObject, Comparable<ChallengeLevel>
|
||||
clone.setRewardMoney(this.rewardMoney);
|
||||
clone.setRewardCommands(new ArrayList<>(this.rewardCommands));
|
||||
clone.setChallenges(new HashSet<>(this.challenges));
|
||||
clone.setIgnoreRewardMetaData(new HashSet<>(this.ignoreRewardMetaData));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -655,7 +655,7 @@ public abstract class CommonPanel
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(this.user.getTranslationOrNothing(reference + "item-title"));
|
||||
Utils.groupEqualItems(challenge.getRepeatItemReward(), Collections.emptySet()).stream().
|
||||
Utils.groupEqualItems(challenge.getRepeatItemReward(), challenge.getIgnoreRewardMetaData()).stream().
|
||||
sorted(Comparator.comparing(ItemStack::getType)).
|
||||
forEach(itemStack ->
|
||||
{
|
||||
@ -756,7 +756,7 @@ public abstract class CommonPanel
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(this.user.getTranslationOrNothing(reference + "item-title"));
|
||||
Utils.groupEqualItems(challenge.getRewardItems(), Collections.emptySet()).stream().
|
||||
Utils.groupEqualItems(challenge.getRewardItems(), challenge.getIgnoreRewardMetaData()).stream().
|
||||
sorted(Comparator.comparing(ItemStack::getType)).
|
||||
forEach(itemStack ->
|
||||
{
|
||||
@ -970,7 +970,7 @@ public abstract class CommonPanel
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(this.user.getTranslationOrNothing(reference + "item-title"));
|
||||
Utils.groupEqualItems(level.getRewardItems(), Collections.emptySet()).stream().
|
||||
Utils.groupEqualItems(level.getRewardItems(), level.getIgnoreRewardMetaData()).stream().
|
||||
sorted(Comparator.comparing(ItemStack::getType)).
|
||||
forEach(itemStack ->
|
||||
{
|
||||
|
@ -282,11 +282,20 @@ public class EditChallengePanel extends CommonPanel
|
||||
|
||||
panelBuilder.item(22, this.createRewardButton(RewardButton.REPEATABLE));
|
||||
|
||||
if (!this.challenge.getRewardItems().isEmpty() || !this.challenge.getRepeatItemReward().isEmpty())
|
||||
{
|
||||
panelBuilder.item(31, this.createRewardButton(RewardButton.ADD_IGNORED_META));
|
||||
}
|
||||
|
||||
if (!this.challenge.getIgnoreRewardMetaData().isEmpty())
|
||||
{
|
||||
panelBuilder.item(32, this.createRewardButton(RewardButton.REMOVE_IGNORED_META));
|
||||
}
|
||||
|
||||
if (this.challenge.isRepeatable())
|
||||
{
|
||||
panelBuilder.item(13, this.createRewardButton(RewardButton.COOL_DOWN));
|
||||
|
||||
panelBuilder.item(31, this.createRewardButton(RewardButton.REPEAT_COUNT));
|
||||
panelBuilder.item(23, this.createRewardButton(RewardButton.REPEAT_COUNT));
|
||||
|
||||
panelBuilder.item(15, this.createRewardButton(RewardButton.REPEAT_REWARD_TEXT));
|
||||
panelBuilder.item(24, this.createRewardButton(RewardButton.REPEAT_REWARD_COMMANDS));
|
||||
@ -967,6 +976,12 @@ public class EditChallengePanel extends CommonPanel
|
||||
forEach(collection::remove);
|
||||
collection.addAll(requirements.getIgnoreMetaData());
|
||||
|
||||
if (Material.values().length == collection.size())
|
||||
{
|
||||
// If there are no items anymore, then do not allow opening gui.
|
||||
return true;
|
||||
}
|
||||
|
||||
MultiBlockSelector.open(this.user,
|
||||
MultiBlockSelector.Mode.ANY,
|
||||
collection,
|
||||
@ -974,6 +989,7 @@ public class EditChallengePanel extends CommonPanel
|
||||
{
|
||||
if (status)
|
||||
{
|
||||
materials.addAll(requirements.getIgnoreMetaData());
|
||||
requirements.setIgnoreMetaData(new HashSet<>(materials));
|
||||
}
|
||||
|
||||
@ -1442,7 +1458,7 @@ public class EditChallengePanel extends CommonPanel
|
||||
{
|
||||
description.add(this.user.getTranslation(reference + "title"));
|
||||
|
||||
Utils.groupEqualItems(this.challenge.getRewardItems(), Collections.emptySet()).
|
||||
Utils.groupEqualItems(this.challenge.getRewardItems(), this.challenge.getIgnoreRewardMetaData()).
|
||||
stream().
|
||||
sorted(Comparator.comparing(ItemStack::getType)).
|
||||
forEach(itemStack ->
|
||||
@ -1694,7 +1710,7 @@ public class EditChallengePanel extends CommonPanel
|
||||
{
|
||||
description.add(this.user.getTranslation(reference + "title"));
|
||||
|
||||
Utils.groupEqualItems(this.challenge.getRepeatItemReward(), Collections.emptySet()).
|
||||
Utils.groupEqualItems(this.challenge.getRepeatItemReward(), this.challenge.getIgnoreRewardMetaData()).
|
||||
stream().
|
||||
sorted(Comparator.comparing(ItemStack::getType)).
|
||||
forEach(itemStack ->
|
||||
@ -1821,6 +1837,101 @@ public class EditChallengePanel extends CommonPanel
|
||||
description.add(this.user.getTranslation(Constants.TIPS + "shift-click-to-reset"));
|
||||
}
|
||||
}
|
||||
case ADD_IGNORED_META -> {
|
||||
if (this.challenge.getIgnoreRewardMetaData().isEmpty())
|
||||
{
|
||||
description.add(this.user.getTranslation(reference + "none"));
|
||||
}
|
||||
else
|
||||
{
|
||||
description.add(this.user.getTranslation(reference + "title"));
|
||||
|
||||
this.challenge.getIgnoreRewardMetaData().stream().
|
||||
sorted(Comparator.comparing(Material::name)).
|
||||
forEach(itemStack ->
|
||||
description.add(this.user.getTranslationOrNothing(reference + "list",
|
||||
"[item]", Utils.prettifyObject(itemStack, this.user))));
|
||||
}
|
||||
|
||||
icon = new ItemStack(Material.GREEN_SHULKER_BOX);
|
||||
|
||||
clickHandler = (panel, user, clickType, slot) -> {
|
||||
if (this.challenge.getRewardItems().isEmpty() &&
|
||||
this.challenge.getRepeatItemReward().isEmpty())
|
||||
{
|
||||
// Do nothing if no requirements are set.
|
||||
return true;
|
||||
}
|
||||
|
||||
// Allow choosing only from inventory items.
|
||||
Set<Material> collection = Arrays.stream(Material.values()).collect(Collectors.toSet());
|
||||
this.challenge.getRewardItems().stream().
|
||||
map(ItemStack::getType).
|
||||
forEach(collection::remove);
|
||||
this.challenge.getRepeatItemReward().stream().
|
||||
map(ItemStack::getType).
|
||||
forEach(collection::remove);
|
||||
collection.addAll(this.challenge.getIgnoreRewardMetaData());
|
||||
|
||||
if (Material.values().length == collection.size())
|
||||
{
|
||||
// If there are no items anymore, then do not allow opening gui.
|
||||
return true;
|
||||
}
|
||||
|
||||
MultiBlockSelector.open(this.user,
|
||||
MultiBlockSelector.Mode.ANY,
|
||||
collection,
|
||||
(status, materials) ->
|
||||
{
|
||||
if (status)
|
||||
{
|
||||
materials.addAll(this.challenge.getIgnoreRewardMetaData());
|
||||
this.challenge.setIgnoreRewardMetaData(new HashSet<>(materials));
|
||||
}
|
||||
|
||||
this.build();
|
||||
});
|
||||
return true;
|
||||
};
|
||||
glow = false;
|
||||
|
||||
description.add("");
|
||||
description.add(this.user.getTranslation(Constants.TIPS + "click-to-add"));
|
||||
}
|
||||
case REMOVE_IGNORED_META -> {
|
||||
icon = new ItemStack(Material.RED_SHULKER_BOX);
|
||||
|
||||
clickHandler = (panel, user, clickType, slot) -> {
|
||||
if (this.challenge.getIgnoreRewardMetaData().isEmpty())
|
||||
{
|
||||
// Do nothing if no requirements are set.
|
||||
return true;
|
||||
}
|
||||
|
||||
// Allow choosing only from inventory items.
|
||||
Set<Material> collection = Arrays.stream(Material.values()).collect(Collectors.toSet());
|
||||
collection.removeAll(this.challenge.getIgnoreRewardMetaData());
|
||||
|
||||
MultiBlockSelector.open(this.user,
|
||||
MultiBlockSelector.Mode.ANY,
|
||||
collection,
|
||||
(status, materials) ->
|
||||
{
|
||||
if (status)
|
||||
{
|
||||
this.challenge.getIgnoreRewardMetaData().removeAll(materials);
|
||||
}
|
||||
|
||||
this.build();
|
||||
});
|
||||
return true;
|
||||
};
|
||||
glow = false;
|
||||
|
||||
description.add("");
|
||||
description.add(this.user.getTranslation(Constants.TIPS + "click-to-remove"));
|
||||
}
|
||||
default -> {
|
||||
icon = new ItemStack(Material.PAPER);
|
||||
clickHandler = null;
|
||||
@ -1951,6 +2062,9 @@ public class EditChallengePanel extends CommonPanel
|
||||
REPEAT_REWARD_EXPERIENCE,
|
||||
REPEAT_REWARD_MONEY,
|
||||
REPEAT_REWARD_COMMANDS,
|
||||
|
||||
ADD_IGNORED_META,
|
||||
REMOVE_IGNORED_META,
|
||||
}
|
||||
|
||||
|
||||
|
@ -27,6 +27,7 @@ import world.bentobox.challenges.panel.CommonPanel;
|
||||
import world.bentobox.challenges.panel.ConversationUtils;
|
||||
import world.bentobox.challenges.panel.util.ItemSelector;
|
||||
import world.bentobox.challenges.panel.util.ChallengeSelector;
|
||||
import world.bentobox.challenges.panel.util.MultiBlockSelector;
|
||||
import world.bentobox.challenges.utils.Constants;
|
||||
import world.bentobox.challenges.utils.Utils;
|
||||
|
||||
@ -191,6 +192,16 @@ public class EditLevelPanel extends CommonPagedPanel<Challenge>
|
||||
panelBuilder.item(13, this.createButton(Button.REWARD_ITEMS));
|
||||
panelBuilder.item(22, this.createButton(Button.REWARD_EXPERIENCE));
|
||||
panelBuilder.item(31, this.createButton(Button.REWARD_MONEY));
|
||||
|
||||
if (!this.challengeLevel.getRewardItems().isEmpty())
|
||||
{
|
||||
panelBuilder.item(33, this.createButton(Button.ADD_IGNORED_META));
|
||||
}
|
||||
|
||||
if (!this.challengeLevel.getIgnoreRewardMetaData().isEmpty())
|
||||
{
|
||||
panelBuilder.item(34, this.createButton(Button.REMOVE_IGNORED_META));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -387,7 +398,7 @@ public class EditLevelPanel extends CommonPagedPanel<Challenge>
|
||||
{
|
||||
description.add(this.user.getTranslation(reference + "title"));
|
||||
|
||||
Utils.groupEqualItems(this.challengeLevel.getRewardItems(), Collections.emptySet()).
|
||||
Utils.groupEqualItems(this.challengeLevel.getRewardItems(), this.challengeLevel.getIgnoreRewardMetaData()).
|
||||
stream().
|
||||
sorted(Comparator.comparing(ItemStack::getType)).
|
||||
forEach(itemStack ->
|
||||
@ -514,6 +525,97 @@ public class EditLevelPanel extends CommonPagedPanel<Challenge>
|
||||
description.add(this.user.getTranslation(Constants.TIPS + "shift-click-to-reset"));
|
||||
}
|
||||
}
|
||||
case ADD_IGNORED_META -> {
|
||||
if (this.challengeLevel.getIgnoreRewardMetaData().isEmpty())
|
||||
{
|
||||
description.add(this.user.getTranslation(reference + "none"));
|
||||
}
|
||||
else
|
||||
{
|
||||
description.add(this.user.getTranslation(reference + "title"));
|
||||
|
||||
this.challengeLevel.getIgnoreRewardMetaData().stream().
|
||||
sorted(Comparator.comparing(Material::name)).
|
||||
forEach(itemStack ->
|
||||
description.add(this.user.getTranslationOrNothing(reference + "list",
|
||||
"[item]", Utils.prettifyObject(itemStack, this.user))));
|
||||
}
|
||||
|
||||
icon = new ItemStack(Material.GREEN_SHULKER_BOX);
|
||||
|
||||
clickHandler = (panel, user, clickType, slot) -> {
|
||||
if (this.challengeLevel.getRewardItems().isEmpty())
|
||||
{
|
||||
// Do nothing if no requirements are set.
|
||||
return true;
|
||||
}
|
||||
|
||||
// Allow choosing only from inventory items.
|
||||
Set<Material> collection = Arrays.stream(Material.values()).collect(Collectors.toSet());
|
||||
this.challengeLevel.getRewardItems().stream().
|
||||
map(ItemStack::getType).
|
||||
forEach(collection::remove);
|
||||
collection.addAll(this.challengeLevel.getIgnoreRewardMetaData());
|
||||
|
||||
if (Material.values().length == collection.size())
|
||||
{
|
||||
// If all materials are blocked, then do not allow to open gui.
|
||||
return true;
|
||||
}
|
||||
|
||||
MultiBlockSelector.open(this.user,
|
||||
MultiBlockSelector.Mode.ANY,
|
||||
collection,
|
||||
(status, materials) ->
|
||||
{
|
||||
if (status)
|
||||
{
|
||||
materials.addAll(this.challengeLevel.getIgnoreRewardMetaData());
|
||||
this.challengeLevel.setIgnoreRewardMetaData(new HashSet<>(materials));
|
||||
}
|
||||
|
||||
this.build();
|
||||
});
|
||||
return true;
|
||||
};
|
||||
glow = false;
|
||||
|
||||
description.add("");
|
||||
description.add(this.user.getTranslation(Constants.TIPS + "click-to-add"));
|
||||
}
|
||||
case REMOVE_IGNORED_META -> {
|
||||
icon = new ItemStack(Material.RED_SHULKER_BOX);
|
||||
|
||||
clickHandler = (panel, user, clickType, slot) -> {
|
||||
if (this.challengeLevel.getIgnoreRewardMetaData().isEmpty())
|
||||
{
|
||||
// Do nothing if no requirements are set.
|
||||
return true;
|
||||
}
|
||||
|
||||
// Allow choosing only from inventory items.
|
||||
Set<Material> collection = Arrays.stream(Material.values()).collect(Collectors.toSet());
|
||||
collection.removeAll(this.challengeLevel.getIgnoreRewardMetaData());
|
||||
|
||||
MultiBlockSelector.open(this.user,
|
||||
MultiBlockSelector.Mode.ANY,
|
||||
collection,
|
||||
(status, materials) ->
|
||||
{
|
||||
if (status)
|
||||
{
|
||||
this.challengeLevel.getIgnoreRewardMetaData().removeAll(materials);
|
||||
}
|
||||
|
||||
this.build();
|
||||
});
|
||||
return true;
|
||||
};
|
||||
glow = false;
|
||||
|
||||
description.add("");
|
||||
description.add(this.user.getTranslation(Constants.TIPS + "click-to-remove"));
|
||||
}
|
||||
case NAME -> {
|
||||
description.add(this.user.getTranslation(reference + "value",
|
||||
Constants.PARAMETER_NAME, this.challengeLevel.getFriendlyName()));
|
||||
@ -858,6 +960,9 @@ public class EditLevelPanel extends CommonPagedPanel<Challenge>
|
||||
REWARD_MONEY,
|
||||
REWARD_COMMANDS,
|
||||
|
||||
ADD_IGNORED_META,
|
||||
REMOVE_IGNORED_META,
|
||||
|
||||
ADD_CHALLENGES,
|
||||
REMOVE_CHALLENGES
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user