diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java index ad76912..8e0bd0d 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java @@ -159,6 +159,8 @@ public class ListChallengesGUI extends CommonGUI { this.addon.getChallengesManager().deleteChallenge(challenge); } + + this.build(); }); return true; }); diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java index 5267d10..b340dc5 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java @@ -160,6 +160,8 @@ public class ListLevelsGUI extends CommonGUI this.addon.getChallengesManager(). deleteChallengeLevel(challengeLevel); } + + this.build(); }); return true; }); diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java index c7c5461..153958f 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java @@ -184,8 +184,10 @@ public class ListUsersGUI extends CommonGUI { manager.setChallengeComplete(User.getInstance(player), value); } - - this.build(); + else + { + this.build(); + } }); break; case RESET: @@ -194,8 +196,10 @@ public class ListUsersGUI extends CommonGUI { manager.resetChallenge(User.getInstance(player), value); } - - this.build(); + else + { + this.build(); + } }); break; case RESET_ALL: @@ -204,6 +208,8 @@ public class ListUsersGUI extends CommonGUI { manager.resetAllChallenges(this.user, this.world); } + + this.build(); }); break; } diff --git a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java index a1913f5..ca88b0f 100644 --- a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java @@ -78,39 +78,39 @@ public class ChallengesGUI extends CommonGUI // TODO: get last completed level. + int nextItemIndex = 0; + if (this.addon.getChallengesSettings().isFreeChallengesFirst()) { - this.addFreeChallenges(panelBuilder); + this.addFreeChallenges(panelBuilder, nextItemIndex); // Start new row for challenges. - while (panelBuilder.nextSlot() % 9 != 0) + if (panelBuilder.nextSlot() % 9 != 0) { - panelBuilder.item( - new PanelItemBuilder().icon(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(" ").build()); + nextItemIndex = panelBuilder.nextSlot() - panelBuilder.nextSlot() % 9 + 9; } } - this.addChallenges(panelBuilder); + this.addChallenges(panelBuilder, nextItemIndex); // Start new row for levels. - while (panelBuilder.nextSlot() % 9 != 0) + // Start new row for challenges. + if (panelBuilder.nextSlot() % 9 != 0) { - panelBuilder.item( - new PanelItemBuilder().icon(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(" ").build()); + nextItemIndex = panelBuilder.nextSlot() - panelBuilder.nextSlot() % 9 + 9; } - this.addChallengeLevels(panelBuilder); + this.addChallengeLevels(panelBuilder, nextItemIndex); if (!this.addon.getChallengesSettings().isFreeChallengesFirst()) { // Start new row for free challenges. - while (panelBuilder.nextSlot() % 9 != 0) + if (panelBuilder.nextSlot() % 9 != 0) { - panelBuilder.item( - new PanelItemBuilder().icon(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(" ").build()); + nextItemIndex = panelBuilder.nextSlot() - panelBuilder.nextSlot() % 9 + 9; } - this.addFreeChallenges(panelBuilder); + this.addFreeChallenges(panelBuilder, nextItemIndex); } panelBuilder.build(); @@ -120,19 +120,20 @@ public class ChallengesGUI extends CommonGUI /** * This method adds free challenges to panelBuilder. * @param panelBuilder where free challenges must be added. + * @param firstItemIndex index of first element. */ - private void addFreeChallenges(PanelBuilder panelBuilder) + private void addFreeChallenges(PanelBuilder panelBuilder, int firstItemIndex) { List freeChallenges = this.challengesManager.getFreeChallenges(this.world); final int freeChallengesCount = freeChallenges.size(); if (freeChallengesCount > 18) { - int firstIndex = panelBuilder.nextSlot(); + int index = firstItemIndex; if (this.freeChallengeIndex > 0) { - panelBuilder.item(new PanelItemBuilder(). + panelBuilder.item(index++, new PanelItemBuilder(). icon(Material.SIGN). name(this.user.getTranslation("challenges.gui.buttons.previous")). clickHandler((panel, user1, clickType, slot) -> { @@ -144,19 +145,19 @@ public class ChallengesGUI extends CommonGUI int currentIndex = this.freeChallengeIndex; - while (panelBuilder.nextSlot() != firstIndex + 18 && currentIndex < freeChallengesCount) + while (panelBuilder.nextSlot() != firstItemIndex + 18 && currentIndex < freeChallengesCount) { - panelBuilder.item(this.getChallengeButton(freeChallenges.get(currentIndex++))); + panelBuilder.item(index++, this.getChallengeButton(freeChallenges.get(currentIndex++))); } // Check if one challenge is left if (currentIndex + 1 == freeChallengesCount) { - panelBuilder.item(this.getChallengeButton(freeChallenges.get(currentIndex))); + panelBuilder.item(index, this.getChallengeButton(freeChallenges.get(currentIndex))); } else if (currentIndex < freeChallengesCount) { - panelBuilder.item(new PanelItemBuilder(). + panelBuilder.item(index, new PanelItemBuilder(). icon(Material.SIGN). name(this.user.getTranslation("challenges.gui.buttons.next")). clickHandler((panel, user1, clickType, slot) -> { @@ -171,7 +172,7 @@ public class ChallengesGUI extends CommonGUI for (Challenge challenge : freeChallenges) { // there are no limitations. Just bunch insert. - panelBuilder.item(this.getChallengeButton(challenge)); + panelBuilder.item(firstItemIndex++, this.getChallengeButton(challenge)); } } } @@ -180,8 +181,9 @@ public class ChallengesGUI extends CommonGUI /** * This method adds last selected level challenges to panelBuilder. * @param panelBuilder where last selected level challenges must be added. + * @param firstItemIndex index of first element. */ - private void addChallenges(PanelBuilder panelBuilder) + private void addChallenges(PanelBuilder panelBuilder, int firstItemIndex) { if (this.lastSelectedLevel != null) { @@ -190,11 +192,11 @@ public class ChallengesGUI extends CommonGUI if (challengesCount > 18) { - int firstIndex = panelBuilder.nextSlot(); + int index = firstItemIndex; if (this.pageIndex > 0) { - panelBuilder.item(new PanelItemBuilder(). + panelBuilder.item(index++, new PanelItemBuilder(). icon(Material.SIGN). name(this.user.getTranslation("challenges.gui.buttons.previous")). clickHandler((panel, user1, clickType, slot) -> { @@ -206,19 +208,19 @@ public class ChallengesGUI extends CommonGUI int currentIndex = this.pageIndex; - while (panelBuilder.nextSlot() != firstIndex + 18 && currentIndex < challengesCount) + while (panelBuilder.nextSlot() != firstItemIndex + 18 && currentIndex < challengesCount) { - panelBuilder.item(this.getChallengeButton(challenges.get(currentIndex++))); + panelBuilder.item(index++, this.getChallengeButton(challenges.get(currentIndex++))); } // Check if one challenge is left if (currentIndex + 1 == challengesCount) { - panelBuilder.item(this.getChallengeButton(challenges.get(currentIndex))); + panelBuilder.item(index, this.getChallengeButton(challenges.get(currentIndex))); } else if (currentIndex < challengesCount) { - panelBuilder.item(new PanelItemBuilder(). + panelBuilder.item(index, new PanelItemBuilder(). icon(Material.SIGN). name(this.user.getTranslation("challenges.gui.buttons.next")). clickHandler((panel, user1, clickType, slot) -> { @@ -233,7 +235,7 @@ public class ChallengesGUI extends CommonGUI for (Challenge challenge : challenges) { // there are no limitations. Just bunch insert. - panelBuilder.item(this.getChallengeButton(challenge)); + panelBuilder.item(firstItemIndex++, this.getChallengeButton(challenge)); } } } @@ -243,8 +245,9 @@ public class ChallengesGUI extends CommonGUI /** * This method adds challenge levels to panelBuilder. * @param panelBuilder where challenge levels must be added. + * @param firstItemIndex index of first element. */ - private void addChallengeLevels(PanelBuilder panelBuilder) + private void addChallengeLevels(PanelBuilder panelBuilder, int firstItemIndex) { // Clone to avoid creating new level on each build. List leftLevels = new ArrayList<>(this.levelStatusList); @@ -256,11 +259,11 @@ public class ChallengesGUI extends CommonGUI if (levelCounts > 9) { - int firstIndex = panelBuilder.nextSlot(); + int index = firstItemIndex; if (this.levelIndex > 0) { - panelBuilder.item(new PanelItemBuilder(). + panelBuilder.item(index++, new PanelItemBuilder(). icon(Material.SIGN). name(this.user.getTranslation("challenges.gui.buttons.previous")). clickHandler((panel, user1, clickType, slot) -> { @@ -272,19 +275,19 @@ public class ChallengesGUI extends CommonGUI int currentIndex = this.levelIndex; - while (panelBuilder.nextSlot() != firstIndex + 9 && currentIndex < levelCounts) + while (panelBuilder.nextSlot() != firstItemIndex + 9 && currentIndex < levelCounts) { - panelBuilder.item(this.getLevelButton(leftLevels.get(currentIndex++))); + panelBuilder.item(index++, this.getLevelButton(leftLevels.get(currentIndex++))); } // Check if one challenge is left if (currentIndex + 1 == levelCounts) { - panelBuilder.item(this.getLevelButton(leftLevels.get(currentIndex))); + panelBuilder.item(index, this.getLevelButton(leftLevels.get(currentIndex))); } else if (currentIndex < levelCounts) { - panelBuilder.item(new PanelItemBuilder(). + panelBuilder.item(index, new PanelItemBuilder(). icon(Material.SIGN). name(this.user.getTranslation("challenges.gui.buttons.next")). clickHandler((panel, user1, clickType, slot) -> { @@ -299,7 +302,7 @@ public class ChallengesGUI extends CommonGUI for (LevelStatus level : leftLevels) { // there are no limitations. Just bunch insert. - panelBuilder.item(this.getLevelButton(level)); + panelBuilder.item(firstItemIndex++, this.getLevelButton(level)); } } } diff --git a/src/main/java/world/bentobox/challenges/utils/GuiUtils.java b/src/main/java/world/bentobox/challenges/utils/GuiUtils.java index 737f735..89ad053 100644 --- a/src/main/java/world/bentobox/challenges/utils/GuiUtils.java +++ b/src/main/java/world/bentobox/challenges/utils/GuiUtils.java @@ -381,7 +381,7 @@ public class GuiUtils List result = new ArrayList<>(); Arrays.stream(string.split("\\|")). - map(line -> Arrays.asList(WordUtils.wrap(line, 25).split("\\r\\n"))). + map(line -> Arrays.asList(WordUtils.wrap(line, 25).split(System.getProperty("line.separator")))). forEach(result::addAll); return result;