mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-03 06:57:36 +01:00
parent
c8d0cc91b6
commit
8356a0d52e
@ -38,6 +38,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static com.djrapitops.plan.utilities.MiscUtils.*;
|
||||
|
||||
@ -220,14 +221,14 @@ public class ServerPlaceHolders implements Placeholders {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (TopCategoryQuery<Long> query : queries) {
|
||||
final int nth = i;
|
||||
placeholders.registerStatic(String.format("top_%s_%s_%s", query.getCategory(), query.getTimeSpan(), nth),
|
||||
placeholders.registerStatic(String.format("top_%s_%s_%s", query.getCategory(), query.getTimeSpan(), nth + 1),
|
||||
parameters -> database.query(query.getQuery(nth, parameters))
|
||||
.map(TopListQueries.TopListEntry::getPlayerName)
|
||||
.orElse("-"));
|
||||
placeholders.registerStatic(String.format("top_%s_%s_%s_value", query.getCategory(), query.getTimeSpan(), nth),
|
||||
placeholders.registerStatic(String.format("top_%s_%s_%s_value", query.getCategory(), query.getTimeSpan(), nth + 1),
|
||||
parameters -> database.query(query.getQuery(nth, parameters))
|
||||
.map(TopListQueries.TopListEntry::getValue)
|
||||
.map(formatters.timeAmount())
|
||||
.map(query.getCategory().equals("player_kills") ? Function.identity() : formatters.timeAmount())
|
||||
.orElse("-"));
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,8 @@
|
||||
package com.djrapitops.plan.placeholder;
|
||||
|
||||
import com.djrapitops.plan.PlanSystem;
|
||||
import com.djrapitops.plan.delivery.domain.ServerIdentifier;
|
||||
import com.djrapitops.plan.gathering.domain.*;
|
||||
import com.djrapitops.plan.identification.ServerUUID;
|
||||
import com.djrapitops.plan.storage.database.Database;
|
||||
import com.djrapitops.plan.storage.database.transactions.events.StoreServerPlayerTransaction;
|
||||
@ -31,11 +33,10 @@ import utilities.mocks.PluginMockComponent;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@ -194,4 +195,44 @@ class PlanPlaceholdersTest {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@TestFactory
|
||||
@DisplayName("Top Player Kills Total placeholders work")
|
||||
Collection<DynamicTest> topKillsPlaceholdersWork() {
|
||||
return IntStream.range(1, 11)
|
||||
.mapToObj(integer -> "top_player_kills_total_" + integer + "_value")
|
||||
.map(placeholder -> DynamicTest.dynamicTest("'" + placeholder + "' returns something", () -> {
|
||||
storeKillers();
|
||||
String result = underTest.onPlaceholderRequest(null, placeholder, List.of(playerUUID.toString()));
|
||||
System.out.println("Placeholder '" + placeholder + "' was replaced with: '" + result + "'");
|
||||
assertNotNull(result);
|
||||
assertNotEquals(placeholder, result);
|
||||
}))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private void storeKillers() throws ExecutionException, InterruptedException {
|
||||
Database database = component.system().getDatabaseSystem().getDatabase();
|
||||
List<UUID> randomUUIDs = IntStream.of(11).mapToObj(i -> UUID.randomUUID()).toList();
|
||||
for (UUID playerUUID : randomUUIDs) {
|
||||
database.executeTransaction(new StoreServerPlayerTransaction(playerUUID, System::currentTimeMillis, playerUUID.toString(), serverUUID, () -> ""))
|
||||
.get();
|
||||
DataMap dataMap = new DataMap();
|
||||
List<PlayerKill> playerKills = new ArrayList<>();
|
||||
for (int i = 0; i < RandomData.randomInt(3, 20); i++) {
|
||||
UUID victim = randomUUIDs.get(RandomData.randomInt(0, randomUUIDs.size()));
|
||||
playerKills.add(new PlayerKill(
|
||||
new PlayerKill.Killer(playerUUID, playerUUID.toString()),
|
||||
new PlayerKill.Victim(victim, victim.toString()),
|
||||
new ServerIdentifier(serverUUID, TestConstants.SERVER_NAME),
|
||||
"Sword",
|
||||
System.currentTimeMillis()
|
||||
));
|
||||
}
|
||||
dataMap.put(PlayerKills.class, new PlayerKills(playerKills));
|
||||
dataMap.put(WorldTimes.class, new WorldTimes());
|
||||
|
||||
database.executeTransaction(new StoreSessionTransaction(new FinishedSession(playerUUID, serverUUID, System.currentTimeMillis(), System.currentTimeMillis(), 0, dataMap)))
|
||||
.get();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user