Rework ChallengesManager.

Implement all methods that were only placeholders.
Remove all unnecessary old methods.
Implement new methods in all classes.

User and Admin command now opens new GUI.
This commit is contained in:
BONNe1704 2019-01-23 17:30:30 +02:00
parent 1bc6bb2b76
commit 590b3f114c
21 changed files with 981 additions and 680 deletions

View File

@ -97,7 +97,7 @@ public class ChallengesImportManager
challengeLevel.setRewardExperience(unlock.getInt("expReward"));
challengeLevel.setRewardCommands(unlock.getStringList("commands"));
}
addon.getChallengesManager().storeLevel(challengeLevel);
addon.getChallengesManager().loadLevel(challengeLevel, overwrite, user, false);
}
} else {
user.sendMessage("challenges.admin.import.no-levels");
@ -118,7 +118,7 @@ public class ChallengesImportManager
newChallenge.setDeployed(true);
ConfigurationSection details = chals.getConfigurationSection(challenge);
newChallenge.setFriendlyName(details.getString("friendlyname", challenge));
newChallenge.setDescription(addon.getChallengesManager().stringSplit(details.getString("description", "")));
newChallenge.setDescription(GuiUtils.stringSplit(details.getString("description", "")));
newChallenge.setIcon(ItemParser.parse(details.getString("icon") + ":1"));
newChallenge.setChallengeType(Challenge.ChallengeType.valueOf(details.getString("type","INVENTORY").toUpperCase()));
newChallenge.setTakeItems(details.getBoolean("takeItems",true));
@ -149,7 +149,7 @@ public class ChallengesImportManager
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().loadChallenge(newChallenge, overwrite, user, false)) {
size++;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -3,10 +3,10 @@ package world.bentobox.challenges.commands;
import java.util.List;
import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.panel.ChallengesPanels2;
import world.bentobox.challenges.panel.ChallengesPanels2.Mode;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.challenges.panel.user.ChallengesGUI;
public class ChallengesCommand extends CompositeCommand {
public static final String CHALLENGE_COMMAND = "challenges";
@ -19,7 +19,11 @@ public class ChallengesCommand extends CompositeCommand {
public boolean execute(User user, String label, List<String> args) {
// Open up the challenges GUI
if (user.isPlayer()) {
new ChallengesPanels2((ChallengesAddon) getAddon(), user, user, args.isEmpty() ? "" : args.get(0), getWorld(), getPermissionPrefix(), getTopLabel(), Mode.PLAYER);
new ChallengesGUI((ChallengesAddon) this.getAddon(),
this.getWorld(),
user,
this.getTopLabel(),
this.getPermissionPrefix()).build();
return true;
}
// Show help

View File

@ -3,10 +3,10 @@ package world.bentobox.challenges.commands.admin;
import java.util.List;
import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.panel.ChallengesPanels2;
import world.bentobox.challenges.panel.ChallengesPanels2.Mode;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.challenges.panel.admin.AdminGUI;
public class Challenges extends CompositeCommand {
@ -25,7 +25,7 @@ public class Challenges extends CompositeCommand {
this.setDescription("challenges.admin.description");
// Register sub commands
new ImportCommand(getAddon(), this);
new CompleteChallenge(getAddon(), this);
// new CompleteChallenge(getAddon(), this);
new ReloadChallenges(getAddon(), this);
new ResetChallenge(getAddon(), this);
//new ShowChallenges(getAddon(), this);
@ -37,7 +37,12 @@ public class Challenges extends CompositeCommand {
public boolean execute(User user, String label, List<String> args) {
// Open up the admin challenges GUI
if (user.isPlayer()) {
new ChallengesPanels2((ChallengesAddon) getAddon(), user, user, args.isEmpty() ? "" : args.get(0), getWorld(), getPermissionPrefix(), getTopLabel(), Mode.ADMIN);
new AdminGUI((ChallengesAddon) this.getAddon(),
this.getWorld(),
user,
this.getTopLabel(),
this.getPermissionPrefix()).build();
return true;
}
return false;

View File

@ -51,13 +51,13 @@ public class CompleteChallenge extends CompositeCommand {
return false;
}
// Check for valid challenge name
if (!manager.isChallenge(getWorld(), args.get(1))) {
if (!manager.containsChallenge(args.get(1))) {
user.sendMessage("challenges.admin.complete.unknown-challenge");
return false;
}
// Complete challenge
User target = User.getInstance(targetUUID);
manager.setChallengeComplete(target, args.get(1), getWorld());
manager.setChallengeComplete(target, this.manager.getChallenge(args.get(1)));
user.sendMessage("general.success");
return true;
}
@ -70,7 +70,7 @@ public class CompleteChallenge extends CompositeCommand {
return Optional.of(Util.tabLimit(new ArrayList<>(Util.getOnlinePlayerList(user)), lastArg));
} else if (args.size() == 4) {
// Challenges in this world
return Optional.of(Util.tabLimit(manager.getAllChallengesList(getWorld()), lastArg));
return Optional.of(Util.tabLimit(manager.getAllChallengesNames(getWorld()), lastArg));
}
return Optional.empty();
}

View File

@ -56,13 +56,13 @@ public class ResetChallenge extends CompositeCommand {
return false;
}
// Check for valid challenge name
if (!manager.isChallenge(getWorld(), args.get(1))) {
if (!manager.containsChallenge(args.get(1))) {
user.sendMessage("challenges.admin.complete.unknown-challenge");
return false;
}
// Complete challenge
User target = User.getInstance(targetUUID);
manager.setResetChallenge(target, args.get(1), getWorld());
manager.resetChallenge(target, manager.getChallenge(args.get(1)));
user.sendMessage("general.success");
return true;
}
@ -75,7 +75,7 @@ public class ResetChallenge extends CompositeCommand {
return Optional.of(Util.tabLimit(new ArrayList<>(Util.getOnlinePlayerList(user)), lastArg));
} else if (args.size() == 4) {
// Challenges in this world
return Optional.of(Util.tabLimit(manager.getAllChallengesList(getWorld()), lastArg));
return Optional.of(Util.tabLimit(manager.getAllChallengesNames(getWorld()), lastArg));
}
return Optional.empty();
}

View File

@ -28,7 +28,7 @@ public class ShowChallenges extends CompositeCommand {
@Override
public boolean execute(User user, String label, List<String> args) {
((ChallengesAddon)getAddon()).getChallengesManager().getAllChallengesList().forEach(user::sendRawMessage);
((ChallengesAddon)getAddon()).getChallengesManager().getAllChallengesNames(this.getWorld()).forEach(user::sendRawMessage);
return true;
}

View File

@ -77,7 +77,7 @@ public class SurroundChallengeBuilder {
}
public boolean build() {
return addon.getChallengesManager().createSurroundingChallenge(this);
return false; //addon.getChallengesManager().createSurroundingChallenge(this);
}

View File

@ -7,6 +7,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.bentobox.api.events.island.IslandEvent;
import world.bentobox.bentobox.api.events.island.IslandEvent.Reason;
@ -27,7 +28,7 @@ public class ResetListener implements Listener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onIslandReset(IslandEvent e) {
if (e.getReason().equals(Reason.CREATED) || (addon.getChallengesSettings().isResetChallenges() && e.getReason().equals(Reason.RESETTED))) {
addon.getChallengesManager().resetAllChallenges(e.getOwner(), e.getLocation().getWorld());
addon.getChallengesManager().resetAllChallenges(User.getInstance(e.getOwner()), e.getLocation().getWorld());
}
}
}

View File

@ -23,7 +23,7 @@ public class SaveListener implements Listener
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onWorldSave(WorldSaveEvent e)
{
if (!this.addon.getChallengesManager().getAllChallengesList(e.getWorld()).isEmpty())
if (!this.addon.getChallengesManager().getAllChallenges(e.getWorld()).isEmpty())
{
this.addon.getChallengesManager().save();
}

View File

@ -11,6 +11,8 @@ import org.bukkit.inventory.ItemStack;
import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.ChallengesManager;
import world.bentobox.challenges.database.object.ChallengeLevel;
import world.bentobox.challenges.utils.GuiUtils;
import world.bentobox.challenges.utils.LevelStatus;
import world.bentobox.challenges.commands.ChallengesCommand;
import world.bentobox.challenges.database.object.Challenge;
@ -30,7 +32,7 @@ public class ChallengesPanels {
private ChallengesAddon addon;
private ChallengesManager manager;
private User user;
private String level;
private ChallengeLevel level;
private World world;
private String permPrefix;
private String label;
@ -43,17 +45,17 @@ public class ChallengesPanels {
this.permPrefix = permPrefix;
this.label = label;
if (manager.getChallengeList().isEmpty()) {
if (manager.getAllChallenges(world).isEmpty()) {
addon.getLogger().severe("There are no challenges set up!");
user.sendMessage("general.errors.general");
return;
}
if (level.isEmpty()) {
level = manager.getChallengeList().keySet().iterator().next().getUniqueId();
level = manager.getLevels(world).iterator().next().getUniqueId();
}
this.level = level;
this.level = this.manager.getLevel(level);
// Check if level is valid
if (!manager.isLevelUnlocked(user, level, world)) {
if (!manager.isLevelUnlocked(user, world, this.level)) {
return;
}
PanelBuilder panelBuilder = new PanelBuilder()
@ -69,7 +71,7 @@ public class ChallengesPanels {
}
private void addChallengeItems(PanelBuilder panelBuilder) {
Set<Challenge> levelChallenges = manager.getChallenges(level, world);
List<Challenge> levelChallenges = manager.getLevelChallenges(level);
// Only show a control panel for the level requested.
for (Challenge challenge : levelChallenges) {
createItem(panelBuilder, challenge);
@ -77,7 +79,7 @@ public class ChallengesPanels {
}
private void addFreeChallanges(PanelBuilder panelBuilder) {
manager.getChallenges(ChallengesManager.FREE, world).forEach(challenge -> createItem(panelBuilder, challenge));
manager.getFreeChallenges(world).forEach(challenge -> createItem(panelBuilder, challenge));
}
@ -88,7 +90,7 @@ public class ChallengesPanels {
*/
private void createItem(PanelBuilder panelBuilder, Challenge challenge) {
// Check completion
boolean completed = manager.isChallengeComplete(user, challenge.getUniqueId(), world);
boolean completed = manager.isChallengeComplete(user, challenge);
// If challenge is removed after completion, remove it
if (completed && challenge.isRemoveWhenCompleted()) {
return;
@ -130,7 +132,7 @@ public class ChallengesPanels {
PanelItem item = new PanelItemBuilder()
.icon(new ItemStack(Material.ENCHANTED_BOOK))
.name(name)
.description(manager.stringSplit(user.getTranslation("challenges.navigation","[level]",name)))
.description(GuiUtils.stringSplit(user.getTranslation("challenges.navigation","[level]",name)))
.clickHandler((p, u, c, s) -> {
u.closeInventory();
u.performCommand(label + " " + ChallengesCommand.CHALLENGE_COMMAND + " " + status.getLevel().getUniqueId());
@ -144,7 +146,7 @@ public class ChallengesPanels {
PanelItem item = new PanelItemBuilder()
.icon(new ItemStack(Material.BOOK))
.name(name)
.description(manager.stringSplit(user.getTranslation("challenges.to-complete", "[challengesToDo]",String.valueOf(previousStatus != null ? previousStatus.getNumberOfChallengesStillToDo() : ""), "[thisLevel]", previousLevelName)))
.description(GuiUtils.stringSplit(user.getTranslation("challenges.to-complete", "[challengesToDo]",String.valueOf(previousStatus != null ? previousStatus.getNumberOfChallengesStillToDo() : ""), "[thisLevel]", previousLevelName)))
.build();
panelBuilder.item(item);
}
@ -167,9 +169,9 @@ public class ChallengesPanels {
}
// Check if completed or not
boolean complete = addon.getChallengesManager().isChallengeComplete(user, challenge.getUniqueId(), world);
boolean complete = addon.getChallengesManager().isChallengeComplete(user, challenge);
int maxTimes = challenge.getMaxTimes();
long doneTimes = addon.getChallengesManager().checkChallengeTimes(user, challenge, world);
long doneTimes = addon.getChallengesManager().getChallengeTimes(user, challenge);
if (complete) {
result.add(user.getTranslation("challenges.complete"));
}
@ -234,6 +236,6 @@ public class ChallengesPanels {
}
private Collection<? extends String> splitTrans(User user, String string, String...strings) {
return addon.getChallengesManager().stringSplit(user.getTranslation(string, strings));
return GuiUtils.stringSplit(user.getTranslation(string, strings));
}
}

View File

@ -10,6 +10,8 @@ import org.bukkit.inventory.ItemStack;
import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.ChallengesManager;
import world.bentobox.challenges.database.object.ChallengeLevel;
import world.bentobox.challenges.utils.GuiUtils;
import world.bentobox.challenges.utils.LevelStatus;
import world.bentobox.challenges.commands.ChallengesCommand;
import world.bentobox.challenges.database.object.Challenge;
@ -35,7 +37,7 @@ public class ChallengesPanels2 {
private ChallengesAddon addon;
private ChallengesManager manager;
private User requester;
private String level;
private ChallengeLevel level;
private World world;
private String permPrefix;
private String label;
@ -52,18 +54,18 @@ public class ChallengesPanels2 {
this.label = label;
this.mode = mode;
if (manager.getChallengeList().isEmpty()) {
if (manager.getAllChallenges(world).isEmpty()) {
addon.getLogger().severe("There are no challenges set up!");
requester.sendMessage("general.errors.general");
return;
}
if (level.isEmpty()) {
// TODO: open the farthest challenge panel
level = manager.getChallengeList().keySet().iterator().next().getUniqueId();
level = manager.getLevels(world).iterator().next().getUniqueId();
}
this.level = level;
this.level = manager.getLevel(level);
// Check if level is valid
if (mode.equals(Mode.PLAYER) && !manager.isLevelUnlocked(requester, level, world)) {
if (mode.equals(Mode.PLAYER) && !manager.isLevelUnlocked(requester, world, this.level)) {
return;
}
PanelBuilder panelBuilder = new PanelBuilder();
@ -93,13 +95,13 @@ public class ChallengesPanels2 {
private void addChallengeItems(PanelBuilder panelBuilder) {
// Only show a control panel for the level requested.
for (Challenge challenge : manager.getChallenges(level, world)) {
for (Challenge challenge : manager.getLevelChallenges(level)) {
createItem(panelBuilder, challenge);
}
}
private void addFreeChallanges(PanelBuilder panelBuilder) {
manager.getChallenges(ChallengesManager.FREE, world).forEach(challenge -> createItem(panelBuilder, challenge));
manager.getFreeChallenges(world).forEach(challenge -> createItem(panelBuilder, challenge));
}
@ -116,10 +118,10 @@ public class ChallengesPanels2 {
glow = challenge.isDeployed();
break;
case EDIT:
glow = manager.isChallengeComplete(requester, challenge.getUniqueId(), world);
glow = manager.isChallengeComplete(requester, challenge);
break;
case PLAYER:
glow = manager.isChallengeComplete(requester, challenge.getUniqueId(), world);
glow = manager.isChallengeComplete(requester, challenge);
break;
default:
break;
@ -169,7 +171,7 @@ public class ChallengesPanels2 {
// Add navigation to other levels
for (LevelStatus status: manager.getChallengeLevelStatus(requester, world)) {
if (status.getLevel().getUniqueId().equalsIgnoreCase(level)) {
if (status.getLevel().getUniqueId().equalsIgnoreCase(level.getUniqueId())) {
// Skip if this is the current level
previousStatus = status;
continue;
@ -182,7 +184,7 @@ public class ChallengesPanels2 {
PanelItem item = new PanelItemBuilder()
.icon(new ItemStack(Material.ENCHANTED_BOOK))
.name(name)
.description(manager.stringSplit(requester.getTranslation("challenges.navigation","[level]",name)))
.description(GuiUtils.stringSplit(requester.getTranslation("challenges.navigation","[level]",name)))
.clickHandler((p, u, c, s) -> {
u.closeInventory();
u.performCommand(label + " " + ChallengesCommand.CHALLENGE_COMMAND + " " + status.getLevel().getUniqueId());
@ -196,7 +198,7 @@ public class ChallengesPanels2 {
PanelItem item = new PanelItemBuilder()
.icon(new ItemStack(Material.BOOK))
.name(name)
.description(manager.stringSplit(requester.getTranslation("challenges.to-complete", "[challengesToDo]",String.valueOf(previousStatus != null ? previousStatus.getNumberOfChallengesStillToDo() : ""), "[thisLevel]", previousLevelName)))
.description(GuiUtils.stringSplit(requester.getTranslation("challenges.to-complete", "[challengesToDo]",String.valueOf(previousStatus != null ? previousStatus.getNumberOfChallengesStillToDo() : ""), "[thisLevel]", previousLevelName)))
.build();
panelBuilder.item(item);
}
@ -230,9 +232,9 @@ public class ChallengesPanels2 {
result.addAll(addRewards(challenge, true, true));
} else {
// Check if completed or not
boolean complete = addon.getChallengesManager().isChallengeComplete(requester, challenge.getUniqueId(), world);
boolean complete = addon.getChallengesManager().isChallengeComplete(requester, challenge);
int maxTimes = challenge.getMaxTimes();
long doneTimes = addon.getChallengesManager().checkChallengeTimes(requester, challenge, world);
long doneTimes = addon.getChallengesManager().getChallengeTimes(requester, challenge);
if (complete) {
result.add(requester.getTranslation("challenges.complete"));
}
@ -307,6 +309,6 @@ public class ChallengesPanels2 {
}
private Collection<? extends String> splitTrans(User user, String string, String...strings) {
return addon.getChallengesManager().stringSplit(user.getTranslation(string, strings));
return GuiUtils.stringSplit(user.getTranslation(string, strings));
}
}

View File

@ -29,7 +29,7 @@ public class CreateChallengeListener implements PanelListener {
@Override
public void onInventoryClose(InventoryCloseEvent event) {
addon.getChallengesManager().createInvChallenge(user, event.getInventory());
addon.getChallengesManager().createChallenge("uniqueID");
}
@Override

View File

@ -124,7 +124,7 @@ public class TryToComplete {
user.sendMessage("challenges.you-repeated", "[challenge]", challenge.getFriendlyName());
}
// Mark as complete
manager.setChallengeComplete(user, challenge.getUniqueId(), world);
manager.setChallengeComplete(user, challenge);
user.closeInventory();
user.getPlayer().performCommand(label + " " + ChallengesCommand.CHALLENGE_COMMAND + " " + challenge.getLevel());
return result;
@ -189,7 +189,7 @@ public class TryToComplete {
user.sendMessage("challenges.you-repeated", "[challenge]", challenge.getFriendlyName());
}
// Mark as complete
manager.setChallengeComplete(user, challenge.getUniqueId(), world);
manager.setChallengeComplete(user, challenge);
user.closeInventory();
user.getPlayer().performCommand(label + " " + ChallengesCommand.CHALLENGE_COMMAND + " " + challenge.getLevel());
}
@ -204,17 +204,17 @@ public class TryToComplete {
return new ChallengeResult();
}
// Check if user has the
if (!challenge.getLevel().equals(ChallengesManager.FREE) && !manager.isLevelUnlocked(user, challenge.getLevel(), world)) {
if (!challenge.getLevel().equals(ChallengesManager.FREE) && !manager.isLevelUnlocked(user, world, manager.getLevel(challenge.getLevel()))) {
user.sendMessage("challenges.errors.challenge-level-not-available");
return new ChallengeResult();
}
// Check max times
if (challenge.isRepeatable() && challenge.getMaxTimes() > 0 && manager.checkChallengeTimes(user, challenge, world) >= challenge.getMaxTimes()) {
if (challenge.isRepeatable() && challenge.getMaxTimes() > 0 && manager.getChallengeTimes(user, challenge) >= challenge.getMaxTimes()) {
user.sendMessage("challenges.not-repeatable");
return new ChallengeResult();
}
// Check repeatability
if (manager.isChallengeComplete(user, challenge.getUniqueId(), world)
if (manager.isChallengeComplete(user, challenge)
&& (!challenge.isRepeatable() || challenge.getChallengeType().equals(ChallengeType.OTHER)
|| challenge.getChallengeType().equals(ChallengeType.ISLAND))) {
user.sendMessage("challenges.not-repeatable");
@ -288,7 +288,7 @@ public class TryToComplete {
this.removeMoney();
// Return the result
return new ChallengeResult().setMeetsRequirements().setRepeat(manager.isChallengeComplete(user, challenge.getUniqueId(), world));
return new ChallengeResult().setMeetsRequirements().setRepeat(manager.isChallengeComplete(user, challenge));
}

View File

@ -11,6 +11,7 @@ import net.wesjd.anvilgui.AnvilGUI;
import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.util.Util;
import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.panel.CommonGUI;
import world.bentobox.challenges.utils.GuiUtils;
@ -198,25 +199,25 @@ public class AdminGUI extends CommonGUI
this.user.getPlayer(),
"unique_id",
(player, reply) -> {
String newName = Util.getWorld(this.world).getName() + "_" + reply;
if (this.addon.getChallengesManager().validateChallengeUniqueID(this.world, reply))
{
new EditChallengeGUI(this.addon,
this.world,
this.user,
this.addon.getChallengesManager().createChallenge(reply),
this.topLabel,
this.permissionPrefix,
this).build();
}
else
{
this.user.sendMessage("challenges.errors.unique-id", "[id]", reply);
this.build();
}
if (this.addon.getChallengesManager().containsChallenge(newName))
{
new EditChallengeGUI(this.addon,
this.world,
this.user,
this.addon.getChallengesManager().createChallenge(reply),
this.topLabel,
this.permissionPrefix,
this).build();
}
else
{
this.user.sendMessage("challenges.errors.unique-id", "[id]", reply);
}
return reply;
});
return reply;
});
return true;
};
@ -234,8 +235,9 @@ public class AdminGUI extends CommonGUI
this.user.getPlayer(),
"unique_id",
(player, reply) -> {
String newName = Util.getWorld(this.world).getName() + "_" + reply;
if (this.addon.getChallengesManager().validateLevelUniqueID(this.world, reply))
if (this.addon.getChallengesManager().containsLevel(newName))
{
new EditLevelGUI(this.addon,
this.world,
@ -248,7 +250,6 @@ public class AdminGUI extends CommonGUI
else
{
this.user.sendMessage("challenges.errors.unique-id", "[id]", reply);
this.build();
}
return reply;
@ -410,4 +411,4 @@ public class AdminGUI extends CommonGUI
return new PanelItem(icon, name, description, glow, clickHandler, false);
}
}
}

View File

@ -145,7 +145,7 @@ public class EditLevelGUI extends CommonGUI
*/
private void buildChallengesPanel(PanelBuilder panelBuilder)
{
List<Challenge> challengeList = this.addon.getChallengesManager().getChallenges(this.challengeLevel);
List<Challenge> challengeList = this.addon.getChallengesManager().getLevelChallenges(this.challengeLevel);
final int MAX_ELEMENTS = 21;
@ -538,8 +538,8 @@ public class EditLevelGUI extends CommonGUI
ChallengesManager manager = this.addon.getChallengesManager();
// Get all challenge that is not in current challenge.
List<Challenge> challengeList = manager.getChallengesList();
challengeList.removeAll(manager.getChallenges(this.challengeLevel));
List<Challenge> challengeList = manager.getAllChallenges(this.world);
challengeList.removeAll(manager.getLevelChallenges(this.challengeLevel));
new SelectChallengeGUI(this.user, challengeList, (status, value) -> {
if (status)
@ -563,10 +563,10 @@ public class EditLevelGUI extends CommonGUI
clickHandler = (panel, user, clickType, slot) -> {
ChallengesManager manager = this.addon.getChallengesManager();
new SelectChallengeGUI(this.user, manager.getChallenges(this.challengeLevel), (status, value) -> {
new SelectChallengeGUI(this.user, manager.getLevelChallenges(this.challengeLevel), (status, value) -> {
if (status)
{
manager.unlinkChallenge(this.challengeLevel, value);
manager.removeChallengeFromLevel(value, this.challengeLevel);
}
this.build();

View File

@ -82,7 +82,7 @@ public class ListChallengesGUI extends CommonGUI
GuiUtils.fillBorder(panelBuilder);
}
List<Challenge> challengeList = this.addon.getChallengesManager().getChallengesList();
List<Challenge> challengeList = this.addon.getChallengesManager().getAllChallenges(this.world);
final int MAX_ELEMENTS = 21;

View File

@ -82,7 +82,7 @@ public class ListLevelsGUI extends CommonGUI
GuiUtils.fillBorder(panelBuilder);
}
List<ChallengeLevel> levelList = this.addon.getChallengesManager().getChallengeLevelList();
List<ChallengeLevel> levelList = this.addon.getChallengesManager().getLevels(this.world);
final int MAX_ELEMENTS = 21;

View File

@ -178,20 +178,20 @@ public class ListUsersGUI extends CommonGUI
switch (this.operationMode)
{
case COMPLETE:
new SelectChallengeGUI(this.user, manager.getChallengesList(), (status, value) -> {
new SelectChallengeGUI(this.user, manager.getAllChallenges(this.world), (status, value) -> {
if (status)
{
manager.completeChallenge(player.getUniqueId(), value);
manager.setChallengeComplete(User.getInstance(player), value);
}
this.build();
});
break;
case RESET:
new SelectChallengeGUI(this.user, manager.getChallengesList(), (status, value) -> {
new SelectChallengeGUI(this.user, manager.getAllChallenges(this.world), (status, value) -> {
if (status)
{
manager.resetChallenge(player.getUniqueId(), value);
manager.resetChallenge(User.getInstance(player), value);
}
this.build();
@ -292,4 +292,4 @@ public class ListUsersGUI extends CommonGUI
return true;
}).build();
}
}
}

View File

@ -123,7 +123,7 @@ public class ChallengesGUI extends CommonGUI
*/
private void addFreeChallenges(PanelBuilder panelBuilder)
{
List<Challenge> freeChallenges = this.challengesManager.getFreeChallenges(this.user, this.world);
List<Challenge> freeChallenges = this.challengesManager.getFreeChallenges(this.world);
final int freeChallengesCount = freeChallenges.size();
if (freeChallengesCount > 18)
@ -185,7 +185,7 @@ public class ChallengesGUI extends CommonGUI
{
if (this.lastSelectedLevel != null)
{
List<Challenge> challenges = this.challengesManager.getChallenges(this.lastSelectedLevel.getLevel());
List<Challenge> challenges = this.challengesManager.getLevelChallenges(this.lastSelectedLevel.getLevel());
final int challengesCount = challenges.size();
if (challengesCount > 18)
@ -346,7 +346,7 @@ public class ChallengesGUI extends CommonGUI
List<String> result = new ArrayList<>();
result.add(this.user.getTranslation("challenges.level",
"[level]", this.challengesManager.getChallengesLevel(challenge)));
"[level]", this.challengesManager.getLevel(challenge).getFriendlyName()));
boolean completed = this.challengesManager.isChallengeComplete(this.user, challenge);
@ -358,7 +358,7 @@ public class ChallengesGUI extends CommonGUI
if (challenge.isRepeatable())
{
int maxTimes = challenge.getMaxTimes();
long doneTimes = this.challengesManager.checkChallengeTimes(this.user, challenge);
long doneTimes = this.challengesManager.getChallengeTimes(this.user, challenge);
if (maxTimes > 0)
{

View File

@ -1,11 +1,16 @@
package world.bentobox.challenges.utils;
import org.apache.commons.lang.WordUtils;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
@ -360,4 +365,24 @@ public class GuiUtils
return new BorderBlock(itemStack);
}
}
}
/**
* Simple splitter
*
* @param string - string to be split
* @return list of split strings
*/
public static List<String> stringSplit(String string)
{
string = ChatColor.translateAlternateColorCodes('&', string);
// Check length of lines
List<String> result = new ArrayList<>();
Arrays.asList(string.split("\\|")).
forEach(line -> result.addAll(
Arrays.asList(WordUtils.wrap(line, 25).split("\\n"))));
return result;
}
}