Skip to content

Commit 8675a18

Browse files
committed
Refactor message key within enums in api
1 parent c11e429 commit 8675a18

File tree

13 files changed

+87
-75
lines changed

13 files changed

+87
-75
lines changed

buildsystem-api/src/main/java/de/eintosti/buildsystem/api/navigator/settings/WorldFilter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import de.eintosti.buildsystem.api.world.BuildWorld;
2121
import java.util.function.Predicate;
22+
import org.jetbrains.annotations.ApiStatus.Internal;
2223

2324
public interface WorldFilter {
2425

@@ -34,6 +35,7 @@ enum Mode {
3435
this.loreKey = loreKey;
3536
}
3637

38+
@Internal
3739
public String getLoreKey() {
3840
return loreKey;
3941
}

buildsystem-api/src/main/java/de/eintosti/buildsystem/api/navigator/settings/WorldSort.java

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ public enum WorldSort {
6161
*/
6262
OLDEST_FIRST("world_sort_date_oldest");
6363

64-
private final String key;
64+
private final String messageKey;
6565

66-
WorldSort(String key) {
67-
this.key = key;
66+
WorldSort(String messageKey) {
67+
this.messageKey = messageKey;
6868
}
6969

7070
@Internal
71-
public String getKey() {
72-
return key;
71+
public String getMessageKey() {
72+
return messageKey;
7373
}
7474

7575
public static WorldSort matchWorldSort(String type) {
@@ -85,46 +85,4 @@ public static WorldSort matchWorldSort(String type) {
8585

8686
return NAME_A_TO_Z;
8787
}
88-
89-
public WorldSort getNext() {
90-
switch (this) {
91-
default: // NAME_A_TO_Z
92-
return NAME_Z_TO_A;
93-
case NAME_Z_TO_A:
94-
return PROJECT_A_TO_Z;
95-
case PROJECT_A_TO_Z:
96-
return PROJECT_Z_TO_A;
97-
case PROJECT_Z_TO_A:
98-
return STATUS_NOT_STARTED;
99-
case STATUS_NOT_STARTED:
100-
return STATUS_FINISHED;
101-
case STATUS_FINISHED:
102-
return NEWEST_FIRST;
103-
case NEWEST_FIRST:
104-
return OLDEST_FIRST;
105-
case OLDEST_FIRST:
106-
return NAME_A_TO_Z;
107-
}
108-
}
109-
110-
public WorldSort getPrevious() {
111-
switch (this) {
112-
default: // NAME_A_TO_Z
113-
return OLDEST_FIRST;
114-
case NAME_Z_TO_A:
115-
return NAME_A_TO_Z;
116-
case PROJECT_A_TO_Z:
117-
return NAME_Z_TO_A;
118-
case PROJECT_Z_TO_A:
119-
return PROJECT_A_TO_Z;
120-
case STATUS_NOT_STARTED:
121-
return PROJECT_Z_TO_A;
122-
case STATUS_FINISHED:
123-
return STATUS_NOT_STARTED;
124-
case NEWEST_FIRST:
125-
return STATUS_FINISHED;
126-
case OLDEST_FIRST:
127-
return NEWEST_FIRST;
128-
}
129-
}
13088
}

buildsystem-api/src/main/java/de/eintosti/buildsystem/api/player/settings/DesignColor.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
*/
1818
package de.eintosti.buildsystem.api.player.settings;
1919

20+
/**
21+
* A {@link DesignColor} is the color which glass panes are tinted to in different menus.
22+
*/
2023
public enum DesignColor {
2124
RED,
2225
ORANGE,
@@ -35,6 +38,12 @@ public enum DesignColor {
3538
LIGHT_GRAY,
3639
BLACK;
3740

41+
/**
42+
* Gets the {@link DesignColor} from a string.
43+
*
44+
* @param colorName The name of the color
45+
* @return The {@link DesignColor} or {@link DesignColor#BLACK} if the color does not exist
46+
*/
3847
public static DesignColor matchColor(String colorName) {
3948
try {
4049
return valueOf(colorName);

buildsystem-api/src/main/java/de/eintosti/buildsystem/api/world/data/BuildWorldStatus.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package de.eintosti.buildsystem.api.world.data;
1919

2020
import de.eintosti.buildsystem.api.world.BuildWorld;
21-
2221
import java.util.Locale;
2322
import org.jetbrains.annotations.ApiStatus.Internal;
2423

@@ -52,15 +51,15 @@ public enum BuildWorldStatus {
5251
ARCHIVE("status_archive", 5),
5352

5453
/**
55-
* Represents a world that is not shown in the navigator.
54+
* Represents a world not shown in the navigator.
5655
*/
5756
HIDDEN("status_hidden", 6);
5857

59-
private final String key;
58+
private final String messageKey;
6059
private final int stage;
6160

62-
BuildWorldStatus(String key, int stage) {
63-
this.key = key;
61+
BuildWorldStatus(String messageKey, int stage) {
62+
this.messageKey = messageKey;
6463
this.stage = stage;
6564
}
6665

@@ -70,8 +69,8 @@ public enum BuildWorldStatus {
7069
* @return The type's display name
7170
*/
7271
@Internal
73-
public String getKey() {
74-
return key;
72+
public String getMessageKey() {
73+
return messageKey;
7574
}
7675

7776
/**

buildsystem-api/src/main/java/de/eintosti/buildsystem/api/world/data/BuildWorldType.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.bukkit.World.Environment;
2121
import org.jetbrains.annotations.ApiStatus.Internal;
22+
import org.jetbrains.annotations.Nullable;
2223

2324
public enum BuildWorldType {
2425

@@ -72,19 +73,20 @@ public enum BuildWorldType {
7273
*/
7374
UNKNOWN(null);
7475

75-
private final String key;
76+
private final String messageKey;
7677

77-
BuildWorldType(String key) {
78-
this.key = key;
78+
BuildWorldType(String messageKey) {
79+
this.messageKey = messageKey;
7980
}
8081

8182
/**
82-
* Get the display name of the {@link BuildWorldType}.
83+
* Get the message key for the {@link BuildWorldType}'s display name.
8384
*
84-
* @return The type's display name
85+
* @return The type's display name message key, or {@code null} for {@link #IMPORTED} and {@link #UNKNOWN}
8586
*/
8687
@Internal
87-
public String getKey() {
88-
return key;
88+
@Nullable
89+
public String getMessageKey() {
90+
return messageKey;
8991
}
9092
}

buildsystem-core/src/main/java/de/eintosti/buildsystem/command/subcommand/worlds/InfoSubCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ public void execute(Player player, String[] args) {
6565
new AbstractMap.SimpleEntry<>("%world%", buildWorld.getName()),
6666
new AbstractMap.SimpleEntry<>("%creator%", getCreator(builders)),
6767
new AbstractMap.SimpleEntry<>("%item%", worldData.material().get().name()),
68-
new AbstractMap.SimpleEntry<>("%type%", Messages.getString(buildWorld.getType().getKey(), player)),
68+
new AbstractMap.SimpleEntry<>("%type%", Messages.getString(buildWorld.getType().getMessageKey(), player)),
6969
new AbstractMap.SimpleEntry<>("%private%", worldData.privateWorld().get()),
7070
new AbstractMap.SimpleEntry<>("%builders_enabled%", worldData.buildersEnabled().get()),
7171
new AbstractMap.SimpleEntry<>("%builders%", builders.asPlaceholder(player)),
7272
new AbstractMap.SimpleEntry<>("%block_breaking%", worldData.blockBreaking().get()),
7373
new AbstractMap.SimpleEntry<>("%block_placement%", worldData.blockPlacement().get()),
74-
new AbstractMap.SimpleEntry<>("%status%", Messages.getString(worldData.status().get().getKey(), player)),
74+
new AbstractMap.SimpleEntry<>("%status%", Messages.getString(worldData.status().get().getMessageKey(), player)),
7575
new AbstractMap.SimpleEntry<>("%project%", worldData.project().get()),
7676
new AbstractMap.SimpleEntry<>("%permission%", worldData.permission().get()),
7777
new AbstractMap.SimpleEntry<>("%time%", buildWorld.getWorldTime()),

buildsystem-core/src/main/java/de/eintosti/buildsystem/expansion/placeholderapi/PlaceholderApiExpansion.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,11 @@ private String parseBuildWorldPlaceholder(Player player, String identifier) {
233233
case "spawn":
234234
return worldData.customSpawn().get();
235235
case "status":
236-
return Messages.getString(worldData.status().get().getKey(), player);
236+
return Messages.getString(worldData.status().get().getMessageKey(), player);
237237
case "time":
238238
return buildWorld.getWorldTime();
239239
case "type":
240-
return Messages.getString(buildWorld.getType().getKey(), player);
240+
return Messages.getString(buildWorld.getType().getMessageKey(), player);
241241
case "world":
242242
return buildWorld.getName();
243243
default:

buildsystem-core/src/main/java/de/eintosti/buildsystem/navigator/inventory/FilteredWorldsInventory.java

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.util.ArrayList;
4646
import java.util.List;
4747
import java.util.Set;
48+
import java.util.function.Function;
4849
import org.bukkit.Bukkit;
4950
import org.bukkit.entity.Player;
5051
import org.bukkit.event.EventHandler;
@@ -160,7 +161,7 @@ private void addWorlds(Player player) {
160161
private void addWorldSortItem(Inventory inventory, Player player) {
161162
Settings settings = settingsManager.getSettings(player);
162163
WorldSort worldSort = settings.getWorldDisplay().getWorldSort();
163-
inventory.setItem(45, InventoryUtils.createItem(XMaterial.BOOK, Messages.getString("world_sort_title", player), Messages.getString(worldSort.getKey(), player)));
164+
inventory.setItem(45, InventoryUtils.createItem(XMaterial.BOOK, Messages.getString("world_sort_title", player), Messages.getString(worldSort.getMessageKey(), player)));
164165
}
165166

166167
private void addWorldFilterItem(Inventory inventory, Player player) {
@@ -223,9 +224,8 @@ public void onInventoryClick(InventoryClickEvent event) {
223224

224225
switch (event.getSlot()) {
225226
case 45:
226-
WorldSort newSort = event.isLeftClick()
227-
? worldDisplay.getWorldSort().getNext()
228-
: worldDisplay.getWorldSort().getPrevious();
227+
Function<WorldSort, WorldSort> newSortFunction = event.isLeftClick() ? this::getNextSort : this::getPreviousSort;
228+
WorldSort newSort = newSortFunction.apply(worldDisplay.getWorldSort());
229229
worldDisplay.setWorldSort(newSort);
230230
openInventory(player);
231231
return;
@@ -271,6 +271,48 @@ public void onInventoryClick(InventoryClickEvent event) {
271271
manageInventoryClick(event, player, itemStack);
272272
}
273273

274+
private WorldSort getNextSort(WorldSort sort) {
275+
switch (sort) {
276+
case NEWEST_FIRST:
277+
return WorldSort.OLDEST_FIRST;
278+
case OLDEST_FIRST:
279+
return WorldSort.NAME_A_TO_Z;
280+
case PROJECT_A_TO_Z:
281+
return WorldSort.PROJECT_Z_TO_A;
282+
case PROJECT_Z_TO_A:
283+
return WorldSort.STATUS_NOT_STARTED;
284+
case STATUS_NOT_STARTED:
285+
return WorldSort.STATUS_FINISHED;
286+
case STATUS_FINISHED:
287+
return WorldSort.NEWEST_FIRST;
288+
case NAME_Z_TO_A:
289+
return WorldSort.PROJECT_A_TO_Z;
290+
default: // NAME_A_TO_Z
291+
return WorldSort.NAME_Z_TO_A;
292+
}
293+
}
294+
295+
public WorldSort getPreviousSort(WorldSort sort) {
296+
switch (sort) {
297+
case NEWEST_FIRST:
298+
return WorldSort.STATUS_FINISHED;
299+
case OLDEST_FIRST:
300+
return WorldSort.NEWEST_FIRST;
301+
case PROJECT_A_TO_Z:
302+
return WorldSort.NAME_Z_TO_A;
303+
case PROJECT_Z_TO_A:
304+
return WorldSort.PROJECT_A_TO_Z;
305+
case STATUS_NOT_STARTED:
306+
return WorldSort.PROJECT_Z_TO_A;
307+
case STATUS_FINISHED:
308+
return WorldSort.STATUS_NOT_STARTED;
309+
case NAME_Z_TO_A:
310+
return WorldSort.NAME_A_TO_Z;
311+
default: // NAME_A_TO_Z
312+
return WorldSort.OLDEST_FIRST;
313+
}
314+
}
315+
274316
/**
275317
* Manage clicking in a {@link FilteredWorldsInventory}.
276318
* <p>

buildsystem-core/src/main/java/de/eintosti/buildsystem/player/settings/SettingsManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ private String parseWorldInformation(Player player, BuildWorld buildWorld, Strin
163163
WorldData worldData = buildWorld.getData();
164164
switch (input) {
165165
case "%status%":
166-
return Messages.getString(worldData.status().get().getKey(), player);
166+
return Messages.getString(worldData.status().get().getMessageKey(), player);
167167
case "%permission%":
168168
return worldData.permission().get();
169169
case "%project%":

buildsystem-core/src/main/java/de/eintosti/buildsystem/world/BuildWorldImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public String getDisplayName(Player player) {
169169
public List<String> getLore(Player player) {
170170
@SuppressWarnings("unchecked")
171171
Map.Entry<String, Object>[] placeholders = new Map.Entry[]{
172-
new AbstractMap.SimpleEntry<>("%status%", Messages.getString(worldData.status().get().getKey(), player)),
172+
new AbstractMap.SimpleEntry<>("%status%", Messages.getString(worldData.status().get().getMessageKey(), player)),
173173
new AbstractMap.SimpleEntry<>("%project%", worldData.project().get()),
174174
new AbstractMap.SimpleEntry<>("%permission%", worldData.permission().get()),
175175
new AbstractMap.SimpleEntry<>("%creator%", builders.hasCreator() ? builders.getCreator().getName() : "-"),

0 commit comments

Comments
 (0)