Merge pull request #57 from BONNe/rework

Fix some Bugs from PR.
This commit is contained in:
tastybento 2019-01-27 22:54:24 -08:00 committed by GitHub
commit 849bde6d27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 42 deletions

View File

@ -159,6 +159,8 @@ public class ListChallengesGUI extends CommonGUI
{ {
this.addon.getChallengesManager().deleteChallenge(challenge); this.addon.getChallengesManager().deleteChallenge(challenge);
} }
this.build();
}); });
return true; return true;
}); });

View File

@ -160,6 +160,8 @@ public class ListLevelsGUI extends CommonGUI
this.addon.getChallengesManager(). this.addon.getChallengesManager().
deleteChallengeLevel(challengeLevel); deleteChallengeLevel(challengeLevel);
} }
this.build();
}); });
return true; return true;
}); });

View File

@ -184,8 +184,10 @@ public class ListUsersGUI extends CommonGUI
{ {
manager.setChallengeComplete(User.getInstance(player), value); manager.setChallengeComplete(User.getInstance(player), value);
} }
else
this.build(); {
this.build();
}
}); });
break; break;
case RESET: case RESET:
@ -194,8 +196,10 @@ public class ListUsersGUI extends CommonGUI
{ {
manager.resetChallenge(User.getInstance(player), value); manager.resetChallenge(User.getInstance(player), value);
} }
else
this.build(); {
this.build();
}
}); });
break; break;
case RESET_ALL: case RESET_ALL:
@ -204,6 +208,8 @@ public class ListUsersGUI extends CommonGUI
{ {
manager.resetAllChallenges(this.user, this.world); manager.resetAllChallenges(this.user, this.world);
} }
this.build();
}); });
break; break;
} }

View File

@ -78,39 +78,39 @@ public class ChallengesGUI extends CommonGUI
// TODO: get last completed level. // TODO: get last completed level.
int nextItemIndex = 0;
if (this.addon.getChallengesSettings().isFreeChallengesFirst()) if (this.addon.getChallengesSettings().isFreeChallengesFirst())
{ {
this.addFreeChallenges(panelBuilder); this.addFreeChallenges(panelBuilder, nextItemIndex);
// Start new row for challenges. // Start new row for challenges.
while (panelBuilder.nextSlot() % 9 != 0) if (panelBuilder.nextSlot() % 9 != 0)
{ {
panelBuilder.item( nextItemIndex = panelBuilder.nextSlot() - panelBuilder.nextSlot() % 9 + 9;
new PanelItemBuilder().icon(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(" ").build());
} }
} }
this.addChallenges(panelBuilder); this.addChallenges(panelBuilder, nextItemIndex);
// Start new row for levels. // Start new row for levels.
while (panelBuilder.nextSlot() % 9 != 0) // Start new row for challenges.
if (panelBuilder.nextSlot() % 9 != 0)
{ {
panelBuilder.item( nextItemIndex = panelBuilder.nextSlot() - panelBuilder.nextSlot() % 9 + 9;
new PanelItemBuilder().icon(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(" ").build());
} }
this.addChallengeLevels(panelBuilder); this.addChallengeLevels(panelBuilder, nextItemIndex);
if (!this.addon.getChallengesSettings().isFreeChallengesFirst()) if (!this.addon.getChallengesSettings().isFreeChallengesFirst())
{ {
// Start new row for free challenges. // Start new row for free challenges.
while (panelBuilder.nextSlot() % 9 != 0) if (panelBuilder.nextSlot() % 9 != 0)
{ {
panelBuilder.item( nextItemIndex = panelBuilder.nextSlot() - panelBuilder.nextSlot() % 9 + 9;
new PanelItemBuilder().icon(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(" ").build());
} }
this.addFreeChallenges(panelBuilder); this.addFreeChallenges(panelBuilder, nextItemIndex);
} }
panelBuilder.build(); panelBuilder.build();
@ -120,19 +120,20 @@ public class ChallengesGUI extends CommonGUI
/** /**
* This method adds free challenges to panelBuilder. * This method adds free challenges to panelBuilder.
* @param panelBuilder where free challenges must be added. * @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<Challenge> freeChallenges = this.challengesManager.getFreeChallenges(this.world); List<Challenge> freeChallenges = this.challengesManager.getFreeChallenges(this.world);
final int freeChallengesCount = freeChallenges.size(); final int freeChallengesCount = freeChallenges.size();
if (freeChallengesCount > 18) if (freeChallengesCount > 18)
{ {
int firstIndex = panelBuilder.nextSlot(); int index = firstItemIndex;
if (this.freeChallengeIndex > 0) if (this.freeChallengeIndex > 0)
{ {
panelBuilder.item(new PanelItemBuilder(). panelBuilder.item(index++, new PanelItemBuilder().
icon(Material.SIGN). icon(Material.SIGN).
name(this.user.getTranslation("challenges.gui.buttons.previous")). name(this.user.getTranslation("challenges.gui.buttons.previous")).
clickHandler((panel, user1, clickType, slot) -> { clickHandler((panel, user1, clickType, slot) -> {
@ -144,19 +145,19 @@ public class ChallengesGUI extends CommonGUI
int currentIndex = this.freeChallengeIndex; 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 // Check if one challenge is left
if (currentIndex + 1 == freeChallengesCount) if (currentIndex + 1 == freeChallengesCount)
{ {
panelBuilder.item(this.getChallengeButton(freeChallenges.get(currentIndex))); panelBuilder.item(index, this.getChallengeButton(freeChallenges.get(currentIndex)));
} }
else if (currentIndex < freeChallengesCount) else if (currentIndex < freeChallengesCount)
{ {
panelBuilder.item(new PanelItemBuilder(). panelBuilder.item(index, new PanelItemBuilder().
icon(Material.SIGN). icon(Material.SIGN).
name(this.user.getTranslation("challenges.gui.buttons.next")). name(this.user.getTranslation("challenges.gui.buttons.next")).
clickHandler((panel, user1, clickType, slot) -> { clickHandler((panel, user1, clickType, slot) -> {
@ -171,7 +172,7 @@ public class ChallengesGUI extends CommonGUI
for (Challenge challenge : freeChallenges) for (Challenge challenge : freeChallenges)
{ {
// there are no limitations. Just bunch insert. // 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. * This method adds last selected level challenges to panelBuilder.
* @param panelBuilder where last selected level challenges must be added. * @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) if (this.lastSelectedLevel != null)
{ {
@ -190,11 +192,11 @@ public class ChallengesGUI extends CommonGUI
if (challengesCount > 18) if (challengesCount > 18)
{ {
int firstIndex = panelBuilder.nextSlot(); int index = firstItemIndex;
if (this.pageIndex > 0) if (this.pageIndex > 0)
{ {
panelBuilder.item(new PanelItemBuilder(). panelBuilder.item(index++, new PanelItemBuilder().
icon(Material.SIGN). icon(Material.SIGN).
name(this.user.getTranslation("challenges.gui.buttons.previous")). name(this.user.getTranslation("challenges.gui.buttons.previous")).
clickHandler((panel, user1, clickType, slot) -> { clickHandler((panel, user1, clickType, slot) -> {
@ -206,19 +208,19 @@ public class ChallengesGUI extends CommonGUI
int currentIndex = this.pageIndex; 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 // Check if one challenge is left
if (currentIndex + 1 == challengesCount) if (currentIndex + 1 == challengesCount)
{ {
panelBuilder.item(this.getChallengeButton(challenges.get(currentIndex))); panelBuilder.item(index, this.getChallengeButton(challenges.get(currentIndex)));
} }
else if (currentIndex < challengesCount) else if (currentIndex < challengesCount)
{ {
panelBuilder.item(new PanelItemBuilder(). panelBuilder.item(index, new PanelItemBuilder().
icon(Material.SIGN). icon(Material.SIGN).
name(this.user.getTranslation("challenges.gui.buttons.next")). name(this.user.getTranslation("challenges.gui.buttons.next")).
clickHandler((panel, user1, clickType, slot) -> { clickHandler((panel, user1, clickType, slot) -> {
@ -233,7 +235,7 @@ public class ChallengesGUI extends CommonGUI
for (Challenge challenge : challenges) for (Challenge challenge : challenges)
{ {
// there are no limitations. Just bunch insert. // 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. * This method adds challenge levels to panelBuilder.
* @param panelBuilder where challenge levels must be added. * @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. // Clone to avoid creating new level on each build.
List<LevelStatus> leftLevels = new ArrayList<>(this.levelStatusList); List<LevelStatus> leftLevels = new ArrayList<>(this.levelStatusList);
@ -256,11 +259,11 @@ public class ChallengesGUI extends CommonGUI
if (levelCounts > 9) if (levelCounts > 9)
{ {
int firstIndex = panelBuilder.nextSlot(); int index = firstItemIndex;
if (this.levelIndex > 0) if (this.levelIndex > 0)
{ {
panelBuilder.item(new PanelItemBuilder(). panelBuilder.item(index++, new PanelItemBuilder().
icon(Material.SIGN). icon(Material.SIGN).
name(this.user.getTranslation("challenges.gui.buttons.previous")). name(this.user.getTranslation("challenges.gui.buttons.previous")).
clickHandler((panel, user1, clickType, slot) -> { clickHandler((panel, user1, clickType, slot) -> {
@ -272,19 +275,19 @@ public class ChallengesGUI extends CommonGUI
int currentIndex = this.levelIndex; 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 // Check if one challenge is left
if (currentIndex + 1 == levelCounts) if (currentIndex + 1 == levelCounts)
{ {
panelBuilder.item(this.getLevelButton(leftLevels.get(currentIndex))); panelBuilder.item(index, this.getLevelButton(leftLevels.get(currentIndex)));
} }
else if (currentIndex < levelCounts) else if (currentIndex < levelCounts)
{ {
panelBuilder.item(new PanelItemBuilder(). panelBuilder.item(index, new PanelItemBuilder().
icon(Material.SIGN). icon(Material.SIGN).
name(this.user.getTranslation("challenges.gui.buttons.next")). name(this.user.getTranslation("challenges.gui.buttons.next")).
clickHandler((panel, user1, clickType, slot) -> { clickHandler((panel, user1, clickType, slot) -> {
@ -299,7 +302,7 @@ public class ChallengesGUI extends CommonGUI
for (LevelStatus level : leftLevels) for (LevelStatus level : leftLevels)
{ {
// there are no limitations. Just bunch insert. // there are no limitations. Just bunch insert.
panelBuilder.item(this.getLevelButton(level)); panelBuilder.item(firstItemIndex++, this.getLevelButton(level));
} }
} }
} }

View File

@ -381,7 +381,7 @@ public class GuiUtils
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
Arrays.stream(string.split("\\|")). 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); forEach(result::addAll);
return result; return result;