mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-10-17 15:55:02 +02:00
Merge branch '4.0.0-BungeeCord-Support' of https://github.com/Rsl1122/Plan-PlayerAnalytics
This commit is contained in:
commit
5c28fc8d6f
@ -43,16 +43,18 @@ public class WorldTimes {
|
|||||||
|
|
||||||
public void updateState(String worldName, String gameMode, long changeTime) {
|
public void updateState(String worldName, String gameMode, long changeTime) {
|
||||||
GMTimes currentGMTimes = worldTimes.get(currentWorld);
|
GMTimes currentGMTimes = worldTimes.get(currentWorld);
|
||||||
|
if (worldName.equals(currentWorld)) {
|
||||||
GMTimes newGMTimes = worldTimes.get(worldName);
|
currentGMTimes.changeState(gameMode, changeTime);
|
||||||
if (newGMTimes == null) {
|
} else {
|
||||||
addWorld(worldName, gameMode, currentGMTimes.getLastStateChange());
|
GMTimes newGMTimes = worldTimes.get(worldName);
|
||||||
|
if (newGMTimes == null) {
|
||||||
|
addWorld(worldName, gameMode, currentGMTimes.getLastStateChange());
|
||||||
|
}
|
||||||
|
currentGMTimes.changeState(currentGamemode, changeTime);
|
||||||
}
|
}
|
||||||
currentGMTimes.changeState(gameMode, changeTime);
|
|
||||||
for (GMTimes gmTimes : worldTimes.values()) {
|
for (GMTimes gmTimes : worldTimes.values()) {
|
||||||
gmTimes.setLastStateChange(changeTime);
|
gmTimes.setLastStateChange(changeTime);
|
||||||
}
|
}
|
||||||
worldTimes.put(currentWorld, currentGMTimes);
|
|
||||||
currentWorld = worldName;
|
currentWorld = worldName;
|
||||||
currentGamemode = gameMode;
|
currentGamemode = gameMode;
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import test.java.utils.RandomData;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
@ -67,7 +66,7 @@ public class WorldTimesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLotOfChanges() {
|
public void testLotOfChangesWorldTime() {
|
||||||
long amount = 1000L;
|
long amount = 1000L;
|
||||||
String[] worlds = new String[]{worldOne, worldTwo};
|
String[] worlds = new String[]{worldOne, worldTwo};
|
||||||
|
|
||||||
@ -89,7 +88,6 @@ public class WorldTimesTest {
|
|||||||
|
|
||||||
long time = i * amount + this.time;
|
long time = i * amount + this.time;
|
||||||
|
|
||||||
printCurrentState(testedW, i, gm, world);
|
|
||||||
test.updateState(world, gm, time);
|
test.updateState(world, gm, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,66 +112,71 @@ public class WorldTimesTest {
|
|||||||
assertEquals(amount * 50, time1 + time2);
|
assertEquals(amount * 50, time1 + time2);
|
||||||
assertEquals(worldTimeOne, time1);
|
assertEquals(worldTimeOne, time1);
|
||||||
assertEquals(worldTimeTwo, time2);
|
assertEquals(worldTimeTwo, time2);
|
||||||
|
|
||||||
// Tests GM Time calculation
|
|
||||||
for (Map.Entry<String, List<String>> entry : testedW.entrySet()) {
|
|
||||||
String world = entry.getKey();
|
|
||||||
List<String> gmList = entry.getValue();
|
|
||||||
for (int i = 0; i < gms.length; i++) {
|
|
||||||
final String lookFor = gms[i];
|
|
||||||
long gmCount = gmList.stream().filter(gmNum -> gmNum.equals(lookFor)).count();
|
|
||||||
|
|
||||||
Optional<GMTimes> gmTimes = test.getGMTimes(world);
|
|
||||||
|
|
||||||
if (gmTimes.isPresent()) {
|
|
||||||
long expected = gmCount * amount;
|
|
||||||
long actual = gmTimes.get().getTime(lookFor);
|
|
||||||
assertEquals(world + ": " + lookFor + ": " + expected + " Actual: " + actual, expected, actual);
|
|
||||||
} else {
|
|
||||||
fail("GM Times can't not be present.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printCurrentState(Map<String, List<String>> testedW, int i, String gm, String world) {
|
@Test
|
||||||
int sizeW1 = testedW.get(worldOne).size();
|
public void testGMTrackingSingleWorld() {
|
||||||
int sizeW2 = testedW.get(worldTwo).size();
|
long changeTime = time + 1000L;
|
||||||
|
long changeTime2 = changeTime + 1000L;
|
||||||
|
GMTimes gmTimes = test.getGMTimes(worldOne).get();
|
||||||
|
test.updateState(worldOne, "CREATIVE", changeTime);
|
||||||
|
assertEquals(1000L, gmTimes.getTime("SURVIVAL"));
|
||||||
|
assertEquals(0L, gmTimes.getTime("CREATIVE"));
|
||||||
|
test.updateState(worldOne, "ADVENTURE", changeTime2);
|
||||||
|
assertEquals(1000L, gmTimes.getTime("SURVIVAL"));
|
||||||
|
assertEquals(1000L, gmTimes.getTime("CREATIVE"));
|
||||||
|
assertEquals(0L, gmTimes.getTime("ADVENTURE"));
|
||||||
|
}
|
||||||
|
|
||||||
StringBuilder b = new StringBuilder(""+i);
|
@Test
|
||||||
while (b.length() < 3) {
|
public void testGMTrackingTwoWorlds() {
|
||||||
b.append(" ");
|
long changeTime = time + 1000L;
|
||||||
}
|
long changeTime2 = time + 2000L;
|
||||||
b.append(world).append(":").append(gm).append(": ");
|
GMTimes worldOneGMTimes = test.getGMTimes(worldOne).get();
|
||||||
while (b.length() < 18) {
|
test.updateState(worldOne, "CREATIVE", changeTime);
|
||||||
b.append(" ");
|
test.updateState(worldOne, "ADVENTURE", changeTime2);
|
||||||
}
|
assertEquals(1000L, worldOneGMTimes.getTime("SURVIVAL"));
|
||||||
b.append(sizeW1);
|
assertEquals(1000L, worldOneGMTimes.getTime("CREATIVE"));
|
||||||
|
assertEquals(0L, worldOneGMTimes.getTime("ADVENTURE"));
|
||||||
|
|
||||||
while (b.length() < 21) {
|
test.updateState(worldTwo, "SURVIVAL", time + 3000L);
|
||||||
b.append(" ");
|
GMTimes worldTwoGMTimes = test.getGMTimes(worldTwo).get();
|
||||||
}
|
assertEquals(1000L, worldOneGMTimes.getTime("SURVIVAL"));
|
||||||
|
assertEquals(1000L, worldOneGMTimes.getTime("CREATIVE"));
|
||||||
|
assertEquals(1000L, worldOneGMTimes.getTime("ADVENTURE"));
|
||||||
|
|
||||||
for (final String lookFor : gms) {
|
assertEquals(0L, worldTwoGMTimes.getTime("SURVIVAL"));
|
||||||
long count = testedW.get(worldOne).stream().filter(gmNum -> gmNum.equals(lookFor)).count();
|
assertEquals(0L, worldTwoGMTimes.getTime("CREATIVE"));
|
||||||
b.append(" ").append(count);
|
assertEquals(0L, worldTwoGMTimes.getTime("ADVENTURE"));
|
||||||
}
|
|
||||||
while (b.length() < 29) {
|
test.updateState(worldTwo, "CREATIVE", time + 4000L);
|
||||||
b.append(" ");
|
|
||||||
}
|
assertEquals(1000L, worldOneGMTimes.getTime("SURVIVAL"));
|
||||||
b.append(" |");
|
assertEquals(1000L, worldOneGMTimes.getTime("CREATIVE"));
|
||||||
for (final String lookFor : gms) {
|
assertEquals(1000L, worldOneGMTimes.getTime("ADVENTURE"));
|
||||||
long count = testedW.get(worldTwo).stream().filter(gmNum -> gmNum.equals(lookFor)).count();
|
|
||||||
b.append(" ").append(count);
|
assertEquals(1000L, worldTwoGMTimes.getTime("SURVIVAL"));
|
||||||
}
|
assertEquals(0L, worldTwoGMTimes.getTime("CREATIVE"));
|
||||||
while (b.length() < 40) {
|
|
||||||
b.append(" ");
|
test.updateState(worldTwo, "CREATIVE", time + 5000L);
|
||||||
}
|
assertEquals(1000L, worldTwoGMTimes.getTime("SURVIVAL"));
|
||||||
b.append(" ")
|
assertEquals(1000L, worldTwoGMTimes.getTime("CREATIVE"));
|
||||||
.append(sizeW2)
|
|
||||||
.append(" = ")
|
// No change should occur.
|
||||||
.append(sizeW1 + sizeW2);
|
test.updateState(worldOne, "ADVENTURE", time + 5000L);
|
||||||
System.out.println(b.toString());
|
System.out.println(test);
|
||||||
|
assertEquals(1000L, worldOneGMTimes.getTime("ADVENTURE"));
|
||||||
|
assertEquals(1000L, worldTwoGMTimes.getTime("CREATIVE"));
|
||||||
|
test.updateState(worldTwo, "CREATIVE", time + 5000L);
|
||||||
|
System.out.println(test);
|
||||||
|
test.updateState(worldOne, "ADVENTURE", time + 6000L);
|
||||||
|
System.out.println(test);
|
||||||
|
assertEquals(1000L, worldOneGMTimes.getTime("ADVENTURE"));
|
||||||
|
assertEquals(2000L, worldTwoGMTimes.getTime("CREATIVE"));
|
||||||
|
|
||||||
|
test.updateState(worldTwo, "ADVENTURE", time + 7000L);
|
||||||
|
assertEquals(2000L, worldTwoGMTimes.getTime("CREATIVE"));
|
||||||
|
assertEquals(2000L, worldOneGMTimes.getTime("ADVENTURE"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Test where SessionData is ended, check if worldTimes & session length add up.
|
// TODO Test where SessionData is ended, check if worldTimes & session length add up.
|
||||||
|
Loading…
Reference in New Issue
Block a user