Skip to content

Commit 643c5e8

Browse files
committed
Add an option to hide undeployed challenges from challenge list (#175)
Added new config option "gui-settings.undeployed-view-mode" with 3 values - 'VISIBLE' - all challenges are visible - 'HIDDEN' - only deployed challenges are visible - 'TOGGLEABLE' - users will be able to choose option for themself (not implemented) Implement functionality in ChallengesGUI, where if option hidden is set, then all undeployed challenges are removed. Implement ability to edit this option via admin Settings panel.
1 parent e5ec5d5 commit 643c5e8

File tree

6 files changed

+158
-6
lines changed

6 files changed

+158
-6
lines changed

src/main/java/world/bentobox/challenges/config/Settings.java

+40-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import world.bentobox.challenges.config.SettingsUtils.GuiMode;
1919
import world.bentobox.challenges.config.SettingsUtils.ChallengeLore;
2020
import world.bentobox.challenges.config.SettingsUtils.LevelLore;
21+
import world.bentobox.challenges.config.SettingsUtils.VisibilityMode;
2122
import world.bentobox.challenges.database.object.adapters.ChallengeLoreAdapter;
2223
import world.bentobox.challenges.database.object.adapters.LevelLoreAdapter;
2324

@@ -82,6 +83,16 @@ public class Settings implements ConfigObject
8283
@ConfigEntry(path = "gui-settings.add-completed-glow")
8384
private boolean addCompletedGlow = true;
8485

86+
@ConfigComment("")
87+
@ConfigComment("This variable allows to choose which Challenges users can see in Challenges GUI.")
88+
@ConfigComment("Valid values are:")
89+
@ConfigComment(" 'VISIBLE' - there will be no hidden challenges. All challenges will be viewable in GUI.")
90+
@ConfigComment(" 'HIDDEN' - shows only deployed challenges.")
91+
@ConfigComment(" 'TOGGLEABLE' - there will be button in GUI that allows users to switch from ALL modes.")
92+
@ConfigComment("TOGGLEABLE - Currently not implemented.")
93+
@ConfigEntry(path = "gui-settings.undeployed-view-mode")
94+
private VisibilityMode visibilityMode = VisibilityMode.VISIBLE;
95+
8596
@ConfigComment("")
8697
@ConfigComment("This allows to change default locked level icon. This option may be")
8798
@ConfigComment("overwritten by each challenge level. If challenge level has specified")
@@ -191,9 +202,9 @@ public class Settings implements ConfigObject
191202
private String configVersion = "v3";
192203

193204

194-
// ---------------------------------------------------------------------
195-
// Section: Methods
196-
// ---------------------------------------------------------------------
205+
// ---------------------------------------------------------------------
206+
// Section: Getters
207+
// ---------------------------------------------------------------------
197208

198209

199210
/**
@@ -400,6 +411,21 @@ public long getAutoSaveTimer()
400411
}
401412

402413

414+
/**
415+
* This method returns the visibilityMode value.
416+
* @return the value of visibilityMode.
417+
*/
418+
public VisibilityMode getVisibilityMode()
419+
{
420+
return this.visibilityMode;
421+
}
422+
423+
424+
// ---------------------------------------------------------------------
425+
// Section: Setters
426+
// ---------------------------------------------------------------------
427+
428+
403429
/**
404430
* This method sets the autoSaveTimer object value.
405431
* @param autoSaveTimer the autoSaveTimer object new value.
@@ -607,4 +633,15 @@ public void setLifeSpan(int lifeSpan)
607633
{
608634
this.lifeSpan = lifeSpan;
609635
}
636+
637+
638+
/**
639+
* This method sets the visibilityMode value.
640+
* @param visibilityMode the visibilityMode new value.
641+
*
642+
*/
643+
public void setVisibilityMode(VisibilityMode visibilityMode)
644+
{
645+
this.visibilityMode = visibilityMode;
646+
}
610647
}

src/main/java/world/bentobox/challenges/config/SettingsUtils.java

+21
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,27 @@ public enum GuiMode
2828
}
2929

3030

31+
/**
32+
* This enum holds all possible values for displaying challenges. It allows to
33+
* enable/disable displaying un-deployed challenges.
34+
*/
35+
public enum VisibilityMode
36+
{
37+
/**
38+
* Show all challenges regardless of their deployment status.
39+
*/
40+
VISIBLE,
41+
/**
42+
* Hide all undeployed challenges in User GUI.
43+
*/
44+
HIDDEN,
45+
/**
46+
* Allows users to switch them on/off in GUI.
47+
*/
48+
TOGGLEABLE
49+
}
50+
51+
3152
/**
3253
* This enum holds all possible values for Challenge Lore Message.
3354
*/

src/main/java/world/bentobox/challenges/panel/admin/EditSettingsGUI.java

+66-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
import world.bentobox.challenges.ChallengesAddon;
1616
import world.bentobox.challenges.config.Settings;
1717
import world.bentobox.challenges.config.SettingsUtils.GuiMode;
18+
import world.bentobox.challenges.config.SettingsUtils.VisibilityMode;
1819
import world.bentobox.challenges.panel.CommonGUI;
1920
import world.bentobox.challenges.panel.util.NumberGUI;
2021
import world.bentobox.challenges.panel.util.SelectBlocksGUI;
2122
import world.bentobox.challenges.utils.GuiUtils;
23+
import world.bentobox.challenges.utils.Utils;
2224

2325

2426
/**
@@ -90,8 +92,9 @@ public void build()
9092

9193
panelBuilder.item(28, this.getSettingsButton(Button.BROADCAST));
9294

93-
panelBuilder.item(20, this.getSettingsButton(Button.GLOW_COMPLETED));
94-
panelBuilder.item(29, this.getSettingsButton(Button.REMOVE_COMPLETED));
95+
panelBuilder.item(11, this.getSettingsButton(Button.GLOW_COMPLETED));
96+
panelBuilder.item(20, this.getSettingsButton(Button.REMOVE_COMPLETED));
97+
panelBuilder.item(29, this.getSettingsButton(Button.VISIBILITY_MODE));
9598

9699
panelBuilder.item(21, this.getSettingsButton(Button.LOCKED_LEVEL_ICON));
97100
panelBuilder.item(30, this.getSettingsButton(Button.FREE_AT_TOP));
@@ -490,6 +493,61 @@ private PanelItem getSettingsButton(Button button)
490493
glow = false;
491494
break;
492495
}
496+
case VISIBILITY_MODE:
497+
{
498+
name = this.user.getTranslation("challenges.gui.buttons.admin.visibility-mode");
499+
500+
List<String> values = new ArrayList<>(5);
501+
values.add(this.user.getTranslation("challenges.gui.descriptions.admin.visibility-mode"));
502+
503+
values.add((this.settings.getVisibilityMode().equals(VisibilityMode.VISIBLE) ? "&2" : "&c") +
504+
this.user.getTranslation("challenges.gui.descriptions.visibility.visible"));
505+
values.add((this.settings.getVisibilityMode().equals(VisibilityMode.HIDDEN) ? "&2" : "&c") +
506+
this.user.getTranslation("challenges.gui.descriptions.visibility.hidden"));
507+
values.add((this.settings.getVisibilityMode().equals(VisibilityMode.TOGGLEABLE) ? "&2" : "&c") +
508+
this.user.getTranslation("challenges.gui.descriptions.visibility.toggleable"));
509+
510+
values.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
511+
"[value]",this.settings.getVisibilityMode().name()));
512+
513+
description = values;
514+
515+
if (this.settings.getVisibilityMode().equals(VisibilityMode.VISIBLE))
516+
{
517+
icon = new ItemStack(Material.OAK_PLANKS);
518+
}
519+
else if (this.settings.getVisibilityMode().equals(VisibilityMode.HIDDEN))
520+
{
521+
icon = new ItemStack(Material.OAK_SLAB);
522+
}
523+
else
524+
{
525+
icon = new ItemStack(Material.OAK_BUTTON);
526+
}
527+
528+
clickHandler = (panel, user, clickType, slot) -> {
529+
if (clickType.isRightClick())
530+
{
531+
this.settings.setVisibilityMode(
532+
Utils.getPreviousValue(VisibilityMode.values(),
533+
this.settings.getVisibilityMode()));
534+
}
535+
else
536+
{
537+
this.settings.setVisibilityMode(
538+
Utils.getNextValue(VisibilityMode.values(),
539+
this.settings.getVisibilityMode()));
540+
}
541+
542+
// Rebuild just this icon
543+
panel.getInventory().setItem(slot,
544+
this.getSettingsButton(button).getItem());
545+
546+
return true;
547+
};
548+
glow = false;
549+
break;
550+
}
493551
default:
494552
return new PanelItemBuilder().build();
495553
}
@@ -529,7 +587,12 @@ private enum Button
529587
GLOW_COMPLETED,
530588
LOCKED_LEVEL_ICON,
531589
ENABLE_TITLE,
532-
TITLE_SHOWTIME
590+
TITLE_SHOWTIME,
591+
592+
/**
593+
* This allows to switch between different challenges visibility modes.
594+
*/
595+
VISIBILITY_MODE
533596
}
534597

535598

src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java

+13
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import world.bentobox.bentobox.api.user.User;
1313
import world.bentobox.challenges.ChallengesAddon;
1414
import world.bentobox.challenges.ChallengesManager;
15+
import world.bentobox.challenges.config.SettingsUtils.VisibilityMode;
1516
import world.bentobox.challenges.database.object.Challenge;
1617
import world.bentobox.challenges.panel.CommonGUI;
1718
import world.bentobox.challenges.tasks.TryToComplete;
@@ -151,6 +152,12 @@ private void addFreeChallenges(PanelBuilder panelBuilder, int firstItemIndex)
151152
this.challengesManager.isChallengeComplete(this.user, this.world, challenge));
152153
}
153154

155+
// Remove all undeployed challenges if VisibilityMode is set to Hidden.
156+
if (this.addon.getChallengesSettings().getVisibilityMode().equals(VisibilityMode.HIDDEN))
157+
{
158+
freeChallenges.removeIf(challenge -> !challenge.isDeployed());
159+
}
160+
154161
final int freeChallengesCount = freeChallenges.size();
155162

156163
if (freeChallengesCount > 18)
@@ -221,6 +228,12 @@ private void addChallenges(PanelBuilder panelBuilder, int firstItemIndex)
221228
this.challengesManager.isChallengeComplete(this.user, this.world, challenge));
222229
}
223230

231+
// Remove all undeployed challenges if VisibilityMode is set to Hidden.
232+
if (this.addon.getChallengesSettings().getVisibilityMode().equals(VisibilityMode.HIDDEN))
233+
{
234+
challenges.removeIf(challenge -> !challenge.isDeployed());
235+
}
236+
224237
final int challengesCount = challenges.size();
225238

226239
if (challengesCount > 18)

src/main/resources/config.yml

+8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ gui-settings:
4343
# Add enchanted glow to completed challenges
4444
add-completed-glow: true
4545
#
46+
# This variable allows to choose which Challenges users can see in Challenges GUI.
47+
# Valid values are:
48+
# 'VISIBLE' - there will be no hidden challenges. All challenges will be viewable in GUI.
49+
# 'HIDDEN' - shows only deployed challenges.
50+
# 'TOGGLEABLE' - there will be button in GUI that allows users to switch from ALL modes.
51+
# TOGGLEABLE - Currently not implemented.
52+
undeployed-view-mode: VISIBLE
53+
#
4654
# This allows to change default locked level icon. This option may be
4755
# overwritten by each challenge level. If challenge level has specified
4856
# their locked level icon, then it will be used, instead of this one.

src/main/resources/locales/en-US.yml

+10
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ challenges:
136136
glow: 'Glow when completed'
137137
free-at-top: 'Free challenges first'
138138
line-length: 'Lore line length'
139+
visibility-mode: 'Challenge Visibility Mode'
139140
toggle-user-list: 'User List'
140141
remove-selected: 'Remove Selected'
141142
add: 'Add'
@@ -263,6 +264,9 @@ challenges:
263264
island-store: 'Allows to enable/disable challenges data storing per island. This means that challenges will be the same on whole team, if this is enabled.|Will NOT convert data on click. PROGRESS WILL BE LOST.'
264265
default-locked-icon: 'Allows to change default locked level icon.|This option can be overwritten by each level.'
265266
gui-mode: 'Allows to enable/disable single challenges GUI.|&2Requires server restart.'
267+
268+
visibility-mode: 'Allows to switch if undeployed challenges should be displayed or not.'
269+
266270
click-to-edit: '&4Click here to edit input.'
267271
edit-text-line: '&6 Edit text message!'
268272
add-text-line: '&6 Add new text message!'
@@ -330,6 +334,12 @@ challenges:
330334

331335
increase-by: "&aIncrease completion count by [value]"
332336
reduce-by: "&cReduce completion count by [value]"
337+
338+
visibility:
339+
visible: "All challenges are visible for everyone"
340+
hidden: "Only Deployed challenges are visible."
341+
toggleable: "Allows to toggle if undeployed challenges should be displayed"
342+
333343
challenge-description:
334344
level: '&FLevel: [level]'
335345
completed: '&BCompleted'

0 commit comments

Comments
 (0)