@@ -172,7 +172,14 @@ public boolean isReadOnly() {
172172 @ Nullable
173173 private final Island island ;
174174 private final List <TabType > tabs ;
175- private final Flag .Mode defaultMode ;
175+ /** The display mode the viewer chose; shared by every tab. */
176+ private Flag .Mode selectedMode ;
177+ /** Whether a mode change is saved as the viewer's preference for next time. */
178+ private boolean remembersMode ;
179+ /**
180+ * Per-tab overrides of {@link #selectedMode}, set when a tab has nothing to show in the
181+ * chosen mode and skips ahead.
182+ */
176183 private final Map <TabType , Flag .Mode > modes = new EnumMap <>(TabType .class );
177184 private final Map <TabType , ItemTemplateRecord > tabTemplates = new EnumMap <>(TabType .class );
178185 /**
@@ -198,7 +205,7 @@ public boolean isReadOnly() {
198205 * @param world the world the settings are for
199206 * @param island the island, or null if the viewer is not on one
200207 * @param tabs the tabs to show, in order; the first the viewer may see is shown initially
201- * @param defaultMode the display mode each tab starts in
208+ * @param defaultMode the display mode the panel starts in
202209 */
203210 protected SettingsPanel (@ NonNull CompositeCommand command , @ NonNull User user , @ NonNull String templateName ,
204211 @ NonNull World world , @ Nullable Island island , @ NonNull List <TabType > tabs , Flag .Mode defaultMode ) {
@@ -210,13 +217,14 @@ protected SettingsPanel(@NonNull CompositeCommand command, @NonNull User user, @
210217 this .tabs = tabs .stream ()
211218 .filter (t -> t .getPermission (prefix ).isEmpty () || user .hasPermission (t .getPermission (prefix )))
212219 .toList ();
213- this .defaultMode = defaultMode ;
220+ this .selectedMode = defaultMode ;
214221 this .activeTab = this .tabs .isEmpty () ? tabs .get (0 ) : this .tabs .get (0 );
215222 }
216223
217224 /**
218225 * Opens the settings panel for a player. With an island the protection and settings tabs are
219- * shown; without one, only the read-only view of the world's protection flags.
226+ * shown; without one, only the read-only view of the world's protection flags. It opens in the
227+ * display mode the player last chose.
220228 * @param command the island settings command
221229 * @param user the viewer
222230 * @param island the island, or null if the viewer is not on one
@@ -226,7 +234,10 @@ public static boolean openPanel(@NonNull CompositeCommand command, @NonNull User
226234 List <TabType > tabs = island == null ? List .of (TabType .WORLD_PROTECTION )
227235 : List .of (TabType .PROTECTION , TabType .SETTING );
228236 World world = island == null ? command .getWorld () : island .getWorld ();
229- return new SettingsPanel (command , user , SETTINGS_PANEL , world , island , tabs , Mode .BASIC ).open ();
237+ SettingsPanel settingsPanel = new SettingsPanel (command , user , SETTINGS_PANEL , world , island , tabs ,
238+ command .getPlugin ().getPlayers ().getFlagsDisplayMode (user .getUniqueId ()));
239+ settingsPanel .remembersMode = true ;
240+ return settingsPanel .open ();
230241 }
231242
232243 /**
@@ -441,7 +452,7 @@ private List<Flag> getFlags(Flag.Mode mode) {
441452 }
442453
443454 private Flag .Mode currentMode () {
444- return modes .getOrDefault (activeTab , defaultMode );
455+ return modes .getOrDefault (activeTab , selectedMode );
445456 }
446457
447458 private boolean isVisibleToUser (Flag flag ) {
@@ -623,7 +634,12 @@ private PanelItem createModeButton(@NonNull ItemTemplateRecord template, Templat
623634 user .getTranslation (PROTECTION_PANEL + "mode." + nextKey + ".name" )))
624635 .clickHandler ((p , u , clickType , s ) -> {
625636 if (clickAllowed (template , clickType )) {
626- modes .put (activeTab , currentMode ().getNext ());
637+ // One mode for every tab, remembered for the next time the player opens it
638+ selectedMode = currentMode ().getNext ();
639+ modes .clear ();
640+ if (remembersMode ) {
641+ plugin .getPlayers ().setFlagsDisplayMode (u .getUniqueId (), selectedMode );
642+ }
627643 pageIndex = 0 ;
628644 u .getPlayer ().playSound (u .getLocation (), Sound .BLOCK_STONE_BUTTON_CLICK_OFF , 1F , 1F );
629645 }
0 commit comments