Skip to content

Commit f41aee3

Browse files
committed
Remove most direct usages of Theme in Java code
1 parent f46801e commit f41aee3

10 files changed

Lines changed: 51 additions & 164 deletions

File tree

Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/JSONFactory.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import com.djrapitops.plan.settings.locale.Locale;
4242
import com.djrapitops.plan.settings.locale.lang.GenericLang;
4343
import com.djrapitops.plan.settings.locale.lang.HtmlLang;
44-
import com.djrapitops.plan.settings.theme.Theme;
4544
import com.djrapitops.plan.settings.theme.ThemeVal;
4645
import com.djrapitops.plan.storage.database.DBSystem;
4746
import com.djrapitops.plan.storage.database.Database;
@@ -74,7 +73,6 @@ public class JSONFactory {
7473
private final DBSystem dbSystem;
7574
private final ServerInfo serverInfo;
7675
private final ServerUptimeCalculator serverUptimeCalculator;
77-
private final Theme theme;
7876
private final Graphs graphs;
7977
private final Formatters formatters;
8078

@@ -85,7 +83,6 @@ public JSONFactory(
8583
DBSystem dbSystem,
8684
ServerInfo serverInfo,
8785
ServerUptimeCalculator serverUptimeCalculator,
88-
Theme theme,
8986
Graphs graphs,
9087
Formatters formatters
9188
) {
@@ -94,7 +91,6 @@ public JSONFactory(
9491
this.dbSystem = dbSystem;
9592
this.serverInfo = serverInfo;
9693
this.serverUptimeCalculator = serverUptimeCalculator;
97-
this.theme = theme;
9894
this.graphs = graphs;
9995
this.formatters = formatters;
10096
}
@@ -307,7 +303,7 @@ public Map<String, Object> serversAsJSONMaps() {
307303
Map<String, Object> server = new HashMap<>();
308304
server.put("name", entry.getValue().getIdentifiableName());
309305
server.put("serverUUID", entry.getValue().getUuid().toString());
310-
server.put("playersOnlineColor", theme.getValue(ThemeVal.GRAPH_PLAYERS_ONLINE));
306+
server.put("playersOnlineColor", ThemeVal.GRAPH_PLAYERS_ONLINE.getDefaultValue());
311307

312308
Optional<DateObj<Integer>> recentPeak = db.query(TPSQueries.fetchPeakPlayerCount(serverUUID, now - TimeUnit.DAYS.toMillis(2L)));
313309
Optional<DateObj<Integer>> allTimePeak = db.query(TPSQueries.fetchAllTimePeakPlayerCount(serverUUID));

Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/PlayerJSONCreator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ private Map<String, Object> createPingGraphJson(PlayerContainer player) {
156156
.put("avg_ping_series", pingGraph.getAvgGraph().getPointArrays())
157157
.put("max_ping_series", pingGraph.getMaxGraph().getPointArrays())
158158
.put("colors", Maps.builder(String.class, String.class)
159-
.put("min", theme.getValue(ThemeVal.GRAPH_MIN_PING))
160-
.put("avg", theme.getValue(ThemeVal.GRAPH_AVG_PING))
161-
.put("max", theme.getValue(ThemeVal.GRAPH_MAX_PING))
159+
.put("min", ThemeVal.GRAPH_MIN_PING.getDefaultValue())
160+
.put("avg", ThemeVal.GRAPH_AVG_PING.getDefaultValue())
161+
.put("max", ThemeVal.GRAPH_MAX_PING.getDefaultValue())
162162
.build())
163163
.build();
164164
}

Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/graphs/GraphJSONCreator.java

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import com.djrapitops.plan.settings.config.paths.DataGatheringSettings;
4545
import com.djrapitops.plan.settings.config.paths.DisplaySettings;
4646
import com.djrapitops.plan.settings.config.paths.TimeSettings;
47-
import com.djrapitops.plan.settings.locale.Locale;
4847
import com.djrapitops.plan.settings.locale.lang.GenericLang;
4948
import com.djrapitops.plan.settings.theme.Theme;
5049
import com.djrapitops.plan.settings.theme.ThemeVal;
@@ -76,21 +75,18 @@
7675
public class GraphJSONCreator {
7776

7877
private final PlanConfig config;
79-
private final Locale locale;
8078
private final Theme theme;
8179
private final DBSystem dbSystem;
8280
private final Graphs graphs;
8381

8482
@Inject
8583
public GraphJSONCreator(
8684
PlanConfig config,
87-
Locale locale,
8885
Theme theme,
8986
DBSystem dbSystem,
9087
Graphs graphs
9188
) {
9289
this.config = config;
93-
this.locale = locale;
9490
this.theme = theme;
9591
this.dbSystem = dbSystem;
9692
this.graphs = graphs;
@@ -111,14 +107,14 @@ public String performanceGraphJSON(ServerUUID serverUUID) {
111107
",\"chunks\":" + lineGraphs.chunkGraph(tpsMutator).toHighChartsSeries() +
112108
",\"disk\":" + lineGraphs.diskGraph(tpsMutator).toHighChartsSeries() +
113109
",\"colors\":{" +
114-
"\"playersOnline\":\"" + theme.getValue(ThemeVal.GRAPH_PLAYERS_ONLINE) + "\"," +
115-
"\"cpu\":\"" + theme.getValue(ThemeVal.GRAPH_CPU) + "\"," +
116-
"\"ram\":\"" + theme.getValue(ThemeVal.GRAPH_RAM) + "\"," +
117-
"\"entities\":\"" + theme.getValue(ThemeVal.GRAPH_ENTITIES) + "\"," +
118-
"\"chunks\":\"" + theme.getValue(ThemeVal.GRAPH_CHUNKS) + "\"," +
119-
"\"low\":\"" + theme.getValue(ThemeVal.GRAPH_TPS_LOW) + "\"," +
120-
"\"med\":\"" + theme.getValue(ThemeVal.GRAPH_TPS_MED) + "\"," +
121-
"\"high\":\"" + theme.getValue(ThemeVal.GRAPH_TPS_HIGH) + "\"}" +
110+
"\"playersOnline\":\"" + ThemeVal.GRAPH_PLAYERS_ONLINE.getDefaultValue() + "\"," +
111+
"\"cpu\":\"" + ThemeVal.GRAPH_CPU.getDefaultValue() + "\"," +
112+
"\"ram\":\"" + ThemeVal.GRAPH_RAM.getDefaultValue() + "\"," +
113+
"\"entities\":\"" + ThemeVal.GRAPH_ENTITIES.getDefaultValue() + "\"," +
114+
"\"chunks\":\"" + ThemeVal.GRAPH_CHUNKS.getDefaultValue() + "\"," +
115+
"\"low\":\"" + ThemeVal.GRAPH_TPS_LOW.getDefaultValue() + "\"," +
116+
"\"med\":\"" + ThemeVal.GRAPH_TPS_MED.getDefaultValue() + "\"," +
117+
"\"high\":\"" + ThemeVal.GRAPH_TPS_HIGH.getDefaultValue() + "\"}" +
122118
",\"zones\":{" +
123119
"\"tpsThresholdMed\":" + config.get(DisplaySettings.GRAPH_TPS_THRESHOLD_MED) + ',' +
124120
"\"tpsThresholdHigh\":" + config.get(DisplaySettings.GRAPH_TPS_THRESHOLD_HIGH) + ',' +
@@ -169,14 +165,14 @@ public Map<String, Object> optimizedPerformanceGraphJSON(ServerUUID serverUUID)
169165
.put("keys", new String[]{"date", "playersOnline", "tps", "cpu", "ram", "entities", "chunks", "disk"})
170166
.put("values", values)
171167
.put("colors", Maps.builder(String.class, Object.class)
172-
.put("playersOnline", theme.getValue(ThemeVal.GRAPH_PLAYERS_ONLINE))
173-
.put("cpu", theme.getValue(ThemeVal.GRAPH_CPU))
174-
.put("ram", theme.getValue(ThemeVal.GRAPH_RAM))
175-
.put("entities", theme.getValue(ThemeVal.GRAPH_ENTITIES))
176-
.put("chunks", theme.getValue(ThemeVal.GRAPH_CHUNKS))
177-
.put("low", theme.getValue(ThemeVal.GRAPH_TPS_LOW))
178-
.put("med", theme.getValue(ThemeVal.GRAPH_TPS_MED))
179-
.put("high", theme.getValue(ThemeVal.GRAPH_TPS_HIGH))
168+
.put("playersOnline", ThemeVal.GRAPH_PLAYERS_ONLINE.getDefaultValue())
169+
.put("cpu", ThemeVal.GRAPH_CPU.getDefaultValue())
170+
.put("ram", ThemeVal.GRAPH_RAM.getDefaultValue())
171+
.put("entities", ThemeVal.GRAPH_ENTITIES.getDefaultValue())
172+
.put("chunks", ThemeVal.GRAPH_CHUNKS.getDefaultValue())
173+
.put("low", ThemeVal.GRAPH_TPS_LOW.getDefaultValue())
174+
.put("med", ThemeVal.GRAPH_TPS_MED.getDefaultValue())
175+
.put("high", ThemeVal.GRAPH_TPS_HIGH.getDefaultValue())
180176
.build())
181177
.put("zones", Maps.builder(String.class, Object.class)
182178
.put("tpsThresholdMed", config.get(DisplaySettings.GRAPH_TPS_THRESHOLD_MED))
@@ -199,7 +195,7 @@ public String playersOnlineGraph(ServerUUID serverUUID) {
199195
Point::fromDateObj
200196
);
201197
return "{\"playersOnline\":" + graphs.line().lineGraph(points).toHighChartsSeries() +
202-
",\"color\":\"" + theme.getValue(ThemeVal.GRAPH_PLAYERS_ONLINE) + "\"}";
198+
",\"color\":\"" + ThemeVal.GRAPH_PLAYERS_ONLINE.getDefaultValue() + "\"}";
203199
}
204200

205201
public String uniqueAndNewGraphJSON(ServerUUID serverUUID) {
@@ -245,8 +241,8 @@ public String createUniqueAndNewJSON(LineGraphFactory lineGraphs, NavigableMap<L
245241
MutatorFunctions.addMissing(newPerDay, gapFillPeriod, 0)
246242
), gapStrategy).toHighChartsSeries() +
247243
",\"colors\":{" +
248-
"\"playersOnline\":\"" + theme.getValue(ThemeVal.GRAPH_PLAYERS_ONLINE) + "\"," +
249-
"\"newPlayers\":\"" + theme.getValue(ThemeVal.LIGHT_GREEN) + "\"" +
244+
"\"playersOnline\":\"" + ThemeVal.GRAPH_PLAYERS_ONLINE.getDefaultValue() + "\"," +
245+
"\"newPlayers\":\"" + ThemeVal.LIGHT_GREEN.getDefaultValue() + "\"" +
250246
"}}";
251247
}
252248

@@ -401,9 +397,9 @@ public Map<String, Object> createGeolocationJSON(Map<String, Integer> geolocatio
401397
.put("geolocation_series", worldMap.getEntries())
402398
.put("geolocation_bar_series", geolocationBarGraph.getBars())
403399
.put("colors", Maps.builder(String.class, String.class)
404-
.put("low", theme.getValue(ThemeVal.WORLD_MAP_LOW))
405-
.put("high", theme.getValue(ThemeVal.WORLD_MAP_HIGH))
406-
.put("bars", theme.getValue(ThemeVal.GREEN))
400+
.put("low", ThemeVal.WORLD_MAP_LOW.getDefaultValue())
401+
.put("high", ThemeVal.WORLD_MAP_HIGH.getDefaultValue())
402+
.put("bars", ThemeVal.GREEN.getDefaultValue())
407403
.build())
408404
.build();
409405
}
@@ -426,9 +422,9 @@ public String pingGraphsJSON(ServerUUID serverUUID) {
426422
",\"avg_ping_series\":" + pingGraph.getAvgGraph().toHighChartsSeries() +
427423
",\"max_ping_series\":" + pingGraph.getMaxGraph().toHighChartsSeries() +
428424
",\"colors\":{" +
429-
"\"min\":\"" + theme.getValue(ThemeVal.GRAPH_MIN_PING) + "\"," +
430-
"\"avg\":\"" + theme.getValue(ThemeVal.GRAPH_AVG_PING) + "\"," +
431-
"\"max\":\"" + theme.getValue(ThemeVal.GRAPH_MAX_PING) + "\"" +
425+
"\"min\":\"" + ThemeVal.GRAPH_MIN_PING.getDefaultValue() + "\"," +
426+
"\"avg\":\"" + ThemeVal.GRAPH_AVG_PING.getDefaultValue() + "\"," +
427+
"\"max\":\"" + ThemeVal.GRAPH_MAX_PING.getDefaultValue() + "\"" +
432428
"}}";
433429
}
434430

@@ -440,7 +436,7 @@ public Map<String, Object> punchCardJSONAsMap(ServerUUID serverUUID) {
440436
);
441437
return Maps.builder(String.class, Object.class)
442438
.put("punchCard", graphs.special().punchCard(sessions).getDots())
443-
.put("color", theme.getValue(ThemeVal.GRAPH_PUNCHCARD))
439+
.put("color", ThemeVal.GRAPH_PUNCHCARD.getDefaultValue())
444440
.build();
445441
}
446442

@@ -547,6 +543,6 @@ public GraphCollection<ServerSpecificLineGraph> proxyPlayersOnlineGraphs() {
547543
proxyGraphs.add(new ServerSpecificLineGraph(points, ServerDto.fromServer(proxy)));
548544
}
549545

550-
return new GraphCollection<>(proxyGraphs, theme.getValue(ThemeVal.GRAPH_PLAYERS_ONLINE));
546+
return new GraphCollection<>(proxyGraphs, ThemeVal.GRAPH_PLAYERS_ONLINE.getDefaultValue());
551547
}
552548
}

Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/graphs/calendar/CalendarFactory.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import com.djrapitops.plan.delivery.domain.container.PlayerContainer;
2020
import com.djrapitops.plan.delivery.formatting.Formatters;
2121
import com.djrapitops.plan.settings.config.PlanConfig;
22-
import com.djrapitops.plan.settings.locale.Locale;
23-
import com.djrapitops.plan.settings.theme.Theme;
2422

2523
import javax.inject.Inject;
2624
import javax.inject.Singleton;
@@ -34,28 +32,22 @@
3432
*/
3533
@Singleton
3634
public class CalendarFactory {
37-
private final Theme theme;
3835
private final PlanConfig config;
39-
private final Locale locale;
4036
private final Formatters formatters;
4137

4238
@Inject
4339
public CalendarFactory(
4440
PlanConfig config,
45-
Locale locale,
46-
Formatters formatters,
47-
Theme theme
41+
Formatters formatters
4842
) {
4943
this.config = config;
50-
this.locale = locale;
5144
this.formatters = formatters;
52-
this.theme = theme;
5345
}
5446

5547
public PlayerCalendar playerCalendar(PlayerContainer player) {
5648
return new PlayerCalendar(
5749
player,
58-
formatters.timeAmount(), formatters.yearLong(), formatters.iso8601NoClockLong(), theme, locale,
50+
formatters.iso8601NoClockLong(),
5951
config.getTimeZone()
6052
);
6153
}
@@ -68,7 +60,7 @@ public ServerCalendar serverCalendar(
6860
) {
6961
return new ServerCalendar(
7062
uniquePerDay, newPerDay, playtimePerDay, sessionsPerDay,
71-
formatters.iso8601NoClockTZIndependentLong(), theme
63+
formatters.iso8601NoClockTZIndependentLong()
7264
);
7365
}
7466
}

Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/graphs/calendar/PlayerCalendar.java

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
import com.djrapitops.plan.gathering.domain.FinishedSession;
2323
import com.djrapitops.plan.gathering.domain.PlayerKill;
2424
import com.djrapitops.plan.gathering.domain.PlayerKills;
25-
import com.djrapitops.plan.settings.locale.Locale;
2625
import com.djrapitops.plan.settings.locale.lang.HtmlLang;
27-
import com.djrapitops.plan.settings.theme.Theme;
2826
import com.djrapitops.plan.settings.theme.ThemeVal;
2927
import com.djrapitops.plan.utilities.java.Lists;
3028

@@ -38,33 +36,21 @@
3836
*/
3937
public class PlayerCalendar {
4038

41-
private final Formatter<Long> timeAmount;
42-
private final Formatter<Long> year;
4339
private final Formatter<Long> iso8601Formatter;
44-
private final Theme theme;
45-
private final Locale locale;
4640
private final TimeZone timeZone;
4741

4842
private final List<FinishedSession> allSessions;
4943
private final long registered;
5044

5145
PlayerCalendar(
5246
PlayerContainer container,
53-
Formatter<Long> timeAmount,
54-
Formatter<Long> year,
5547
Formatter<Long> iso8601Formatter,
56-
Theme theme,
57-
Locale locale,
5848
TimeZone timeZone
5949
) {
6050
this.allSessions = container.getValue(PlayerKeys.SESSIONS).orElse(new ArrayList<>());
6151
this.registered = container.getValue(PlayerKeys.REGISTERED).orElse(0L);
6252

63-
this.timeAmount = timeAmount;
64-
this.year = year;
6553
this.iso8601Formatter = iso8601Formatter;
66-
this.theme = theme;
67-
this.locale = locale;
6854
this.timeZone = timeZone;
6955
}
7056

@@ -73,7 +59,7 @@ public List<CalendarEntry> getEntries() {
7359

7460
entries.add(CalendarEntry
7561
.of(HtmlLang.LABEL_REGISTERED.getKey(), registered, registered + timeZone.getOffset(registered))
76-
.withColor(theme.getValue(ThemeVal.LIGHT_GREEN))
62+
.withColor(ThemeVal.LIGHT_GREEN.getDefaultValue())
7763
);
7864

7965
Map<String, List<FinishedSession>> sessionsByDay = getSessionsByDay();
@@ -87,10 +73,10 @@ public List<CalendarEntry> getEntries() {
8773

8874
entries.add(CalendarEntry
8975
.of(HtmlLang.LABEL_PLAYTIME.getKey(), playtime, day)
90-
.withColor(theme.getValue(ThemeVal.GREEN))
76+
.withColor(ThemeVal.GREEN.getDefaultValue())
9177
);
9278
entries.add(CalendarEntry.of(HtmlLang.SIDE_SESSIONS.getKey(), sessionCount, day)
93-
.withColor(theme.getValue(ThemeVal.TEAL)));
79+
.withColor(ThemeVal.TEAL.getDefaultValue()));
9480
}
9581

9682
long fiveMinutes = TimeUnit.MINUTES.toMillis(5L);
@@ -102,7 +88,7 @@ public List<CalendarEntry> getEntries() {
10288
entries.add(CalendarEntry
10389
.of(HtmlLang.SESSION.getKey(), session.getLength(), start + timeZone.getOffset(start))
10490
.withEnd(end + timeZone.getOffset(end))
105-
.withColor(theme.getValue(ThemeVal.TEAL))
91+
.withColor(ThemeVal.TEAL.getDefaultValue())
10692
);
10793

10894
for (PlayerKill kill : session.getExtraData(PlayerKills.class).map(PlayerKills::asList).orElseGet(ArrayList::new)) {
@@ -111,7 +97,7 @@ public List<CalendarEntry> getEntries() {
11197
entries.add(CalendarEntry
11298
.of(HtmlLang.KILLED.getKey(), victim, time)
11399
.withEnd(time + fiveMinutes)
114-
.withColor(theme.getValue(ThemeVal.RED))
100+
.withColor(ThemeVal.RED.getDefaultValue())
115101
);
116102
}
117103
}

Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/graphs/calendar/ServerCalendar.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import com.djrapitops.plan.delivery.formatting.Formatter;
2020
import com.djrapitops.plan.settings.locale.lang.HtmlLang;
21-
import com.djrapitops.plan.settings.theme.Theme;
2221
import com.djrapitops.plan.settings.theme.ThemeVal;
2322

2423
import java.util.*;
@@ -36,22 +35,19 @@ public class ServerCalendar {
3635
private final SortedMap<Long, Long> playtimePerDay;
3736

3837
private final Formatter<Long> iso8601TZIndependent;
39-
private final Theme theme;
4038

4139
ServerCalendar(
4240
SortedMap<Long, Integer> uniquePerDay,
4341
SortedMap<Long, Integer> newPerDay,
4442
SortedMap<Long, Long> playtimePerDay,
4543
NavigableMap<Long, Integer> sessionsPerDay,
46-
Formatter<Long> iso8601TZIndependent,
47-
Theme theme
44+
Formatter<Long> iso8601TZIndependent
4845
) {
4946
this.uniquePerDay = uniquePerDay;
5047
this.newPerDay = newPerDay;
5148
this.iso8601TZIndependent = iso8601TZIndependent;
5249
this.sessionsPerDay = sessionsPerDay;
5350
this.playtimePerDay = playtimePerDay;
54-
this.theme = theme;
5551
}
5652

5753
public List<CalendarEntry> getEntries() {
@@ -74,7 +70,7 @@ private void appendNewPlayers(List<CalendarEntry> entries) {
7470
String day = iso8601TZIndependent.apply(key);
7571

7672
entries.add(CalendarEntry.of(HtmlLang.NEW_CALENDAR.getKey(), newPlayers, day)
77-
.withColor(theme.getValue(ThemeVal.LIGHT_GREEN)));
73+
.withColor(ThemeVal.LIGHT_GREEN.getDefaultValue()));
7874
}
7975
}
8076

@@ -102,7 +98,7 @@ private void appendPlaytime(List<CalendarEntry> entries) {
10298
String day = iso8601TZIndependent.apply(key);
10399

104100
entries.add(CalendarEntry.of(HtmlLang.LABEL_PLAYTIME.getKey(), playtime, day)
105-
.withColor(theme.getValue(ThemeVal.GREEN)));
101+
.withColor(ThemeVal.GREEN.getDefaultValue()));
106102
}
107103
}
108104

@@ -116,7 +112,7 @@ private void appendSessionCounts(List<CalendarEntry> entries) {
116112
String day = iso8601TZIndependent.apply(key);
117113

118114
entries.add(CalendarEntry.of(HtmlLang.SIDE_SESSIONS.getKey(), sessionCount, day)
119-
.withColor(theme.getValue(ThemeVal.TEAL)));
115+
.withColor(ThemeVal.TEAL.getDefaultValue()));
120116
}
121117
}
122118
}

0 commit comments

Comments
 (0)