Merge branch '4.0.0-BungeeCord-Support' of https://github.com/Rsl1122/Plan-PlayerAnalytics

This commit is contained in:
Fuzzlemann 2017-08-21 18:01:10 +02:00
commit 5c28fc8d6f
2 changed files with 69 additions and 64 deletions

View File

@ -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)) {
currentGMTimes.changeState(gameMode, changeTime);
} else {
GMTimes newGMTimes = worldTimes.get(worldName); GMTimes newGMTimes = worldTimes.get(worldName);
if (newGMTimes == null) { if (newGMTimes == null) {
addWorld(worldName, gameMode, currentGMTimes.getLastStateChange()); addWorld(worldName, gameMode, currentGMTimes.getLastStateChange());
} }
currentGMTimes.changeState(gameMode, changeTime); currentGMTimes.changeState(currentGamemode, 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;
} }

View File

@ -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;
StringBuilder b = new StringBuilder(""+i); GMTimes gmTimes = test.getGMTimes(worldOne).get();
while (b.length() < 3) { test.updateState(worldOne, "CREATIVE", changeTime);
b.append(" "); assertEquals(1000L, gmTimes.getTime("SURVIVAL"));
} assertEquals(0L, gmTimes.getTime("CREATIVE"));
b.append(world).append(":").append(gm).append(": "); test.updateState(worldOne, "ADVENTURE", changeTime2);
while (b.length() < 18) { assertEquals(1000L, gmTimes.getTime("SURVIVAL"));
b.append(" "); assertEquals(1000L, gmTimes.getTime("CREATIVE"));
} assertEquals(0L, gmTimes.getTime("ADVENTURE"));
b.append(sizeW1);
while (b.length() < 21) {
b.append(" ");
} }
for (final String lookFor : gms) { @Test
long count = testedW.get(worldOne).stream().filter(gmNum -> gmNum.equals(lookFor)).count(); public void testGMTrackingTwoWorlds() {
b.append(" ").append(count); long changeTime = time + 1000L;
} long changeTime2 = time + 2000L;
while (b.length() < 29) { GMTimes worldOneGMTimes = test.getGMTimes(worldOne).get();
b.append(" "); test.updateState(worldOne, "CREATIVE", changeTime);
} test.updateState(worldOne, "ADVENTURE", changeTime2);
b.append(" |"); assertEquals(1000L, worldOneGMTimes.getTime("SURVIVAL"));
for (final String lookFor : gms) { assertEquals(1000L, worldOneGMTimes.getTime("CREATIVE"));
long count = testedW.get(worldTwo).stream().filter(gmNum -> gmNum.equals(lookFor)).count(); assertEquals(0L, worldOneGMTimes.getTime("ADVENTURE"));
b.append(" ").append(count);
} test.updateState(worldTwo, "SURVIVAL", time + 3000L);
while (b.length() < 40) { GMTimes worldTwoGMTimes = test.getGMTimes(worldTwo).get();
b.append(" "); assertEquals(1000L, worldOneGMTimes.getTime("SURVIVAL"));
} assertEquals(1000L, worldOneGMTimes.getTime("CREATIVE"));
b.append(" ") assertEquals(1000L, worldOneGMTimes.getTime("ADVENTURE"));
.append(sizeW2)
.append(" = ") assertEquals(0L, worldTwoGMTimes.getTime("SURVIVAL"));
.append(sizeW1 + sizeW2); assertEquals(0L, worldTwoGMTimes.getTime("CREATIVE"));
System.out.println(b.toString()); assertEquals(0L, worldTwoGMTimes.getTime("ADVENTURE"));
test.updateState(worldTwo, "CREATIVE", time + 4000L);
assertEquals(1000L, worldOneGMTimes.getTime("SURVIVAL"));
assertEquals(1000L, worldOneGMTimes.getTime("CREATIVE"));
assertEquals(1000L, worldOneGMTimes.getTime("ADVENTURE"));
assertEquals(1000L, worldTwoGMTimes.getTime("SURVIVAL"));
assertEquals(0L, worldTwoGMTimes.getTime("CREATIVE"));
test.updateState(worldTwo, "CREATIVE", time + 5000L);
assertEquals(1000L, worldTwoGMTimes.getTime("SURVIVAL"));
assertEquals(1000L, worldTwoGMTimes.getTime("CREATIVE"));
// No change should occur.
test.updateState(worldOne, "ADVENTURE", time + 5000L);
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.