mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-23 09:37:54 +01:00
Serialize Sessions into json without Gson during shutdown
Affects issues: - Fixed #1970
This commit is contained in:
parent
b3200d1734
commit
8d445aaccc
@ -57,4 +57,8 @@ public class Counter {
|
||||
"count=" + count +
|
||||
'}';
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return "{\"count\": " + count + "}";
|
||||
}
|
||||
}
|
||||
|
@ -191,16 +191,14 @@ public class FinishedSession implements DateHolder {
|
||||
* @return Serialized format
|
||||
*/
|
||||
public String serializeCSV() {
|
||||
Gson gson = new Gson();
|
||||
|
||||
return String.valueOf(playerUUID) + ';' +
|
||||
serverUUID + ';' +
|
||||
start + ';' +
|
||||
end + ';' +
|
||||
afkTime + ';' +
|
||||
gson.toJson(getExtraData(WorldTimes.class).orElseGet(WorldTimes::new)) + ';' +
|
||||
gson.toJson(getExtraData(PlayerKills.class).orElseGet(PlayerKills::new)) + ';' +
|
||||
gson.toJson(getExtraData(MobKillCounter.class).orElseGet(MobKillCounter::new)) + ';' +
|
||||
gson.toJson(getExtraData(DeathCounter.class).orElseGet(DeathCounter::new));
|
||||
getExtraData(WorldTimes.class).orElseGet(WorldTimes::new).toJson() + ';' +
|
||||
getExtraData(PlayerKills.class).orElseGet(PlayerKills::new).toJson() + ';' +
|
||||
getExtraData(MobKillCounter.class).orElseGet(MobKillCounter::new).toJson() + ';' +
|
||||
getExtraData(DeathCounter.class).orElseGet(DeathCounter::new).toJson();
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,8 @@
|
||||
*/
|
||||
package com.djrapitops.plan.gathering.domain;
|
||||
|
||||
import org.apache.commons.text.TextStringBuilder;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@ -57,11 +59,16 @@ public class GMTimes extends TimeKeeper {
|
||||
|
||||
public static String magicNumberToGMName(int magicNumber) {
|
||||
switch (magicNumber) {
|
||||
case 0: return SURVIVAL;
|
||||
case 1: return CREATIVE;
|
||||
case 2: return ADVENTURE;
|
||||
case 3: return SPECTATOR;
|
||||
default: return "UNKOWN";
|
||||
case 0:
|
||||
return SURVIVAL;
|
||||
case 1:
|
||||
return CREATIVE;
|
||||
case 2:
|
||||
return ADVENTURE;
|
||||
case 3:
|
||||
return SPECTATOR;
|
||||
default:
|
||||
return "UNKOWN";
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,4 +130,15 @@ public class GMTimes extends TimeKeeper {
|
||||
", lastStateChange=" + lastStateChange +
|
||||
'}';
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return "{\"times\": {" +
|
||||
new TextStringBuilder().appendWithSeparators(times.entrySet().stream()
|
||||
.map(entry -> "\"" + entry.getKey() + "\": " + entry.getValue())
|
||||
.iterator(), ",").build() +
|
||||
" }," +
|
||||
" \"state\": \"" + state + "\"," +
|
||||
" \"lastStateChange\": " + lastStateChange +
|
||||
"}";
|
||||
}
|
||||
}
|
@ -124,4 +124,14 @@ public class PlayerKill implements DateHolder {
|
||||
public boolean isNotSelfKill() {
|
||||
return !isSelfKill();
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return "{\"killer\": \"" + killer + "\"," +
|
||||
" \"victim\": \"" + victim + "\"," +
|
||||
" \"weapon\": \"" + weapon + "\"," +
|
||||
" \"date\": " + date + "," +
|
||||
" \"victimName\": \"" + victimName + "\"," +
|
||||
" \"killerName\": \"" + killerName + "\"" +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
package com.djrapitops.plan.gathering.domain;
|
||||
|
||||
import com.djrapitops.plan.utilities.comparators.DateHolderRecentComparator;
|
||||
import org.apache.commons.text.TextStringBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -73,4 +74,13 @@ public class PlayerKills {
|
||||
"kills=" + kills +
|
||||
'}';
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return "{" +
|
||||
" \"kills\": [" +
|
||||
new TextStringBuilder().appendWithSeparators(kills
|
||||
.stream().map(PlayerKill::toJson).iterator(), ",").build() +
|
||||
" ]" +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,8 @@
|
||||
*/
|
||||
package com.djrapitops.plan.gathering.domain;
|
||||
|
||||
import org.apache.commons.text.TextStringBuilder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@ -197,4 +199,15 @@ public class WorldTimes {
|
||||
setGMTimesForWorld(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return "{\"times\": {" +
|
||||
new TextStringBuilder().appendWithSeparators(times.entrySet().stream()
|
||||
.map(entry -> "\"" + entry.getKey() + "\": " + entry.getValue().toJson())
|
||||
.iterator(), ",").build() +
|
||||
" }," +
|
||||
" \"currentWorld\": \"" + currentWorld + "\"," +
|
||||
" \"currentGamemode\": \"" + currentGamemode + "\"" +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user