|
|
|
@ -40,6 +40,8 @@ public class TraceManager implements Listener {
|
|
|
|
|
|
|
|
|
|
private final Map<Region, Map<Player, PlayerTraceShowData>> showDataPerRegionPerPlayer = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
private final Map<Player, Set<Player>> followerMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Utility variable to keep track of the next open trace id;
|
|
|
|
|
*/
|
|
|
|
@ -54,6 +56,9 @@ public class TraceManager implements Listener {
|
|
|
|
|
protected int add(Trace trace) {
|
|
|
|
|
showDataPerRegionPerPlayer.getOrDefault(trace.getRegion(), Collections.emptyMap()).forEach((player, playerTraceShowData) -> {
|
|
|
|
|
trace.render(player, playerTraceShowData);
|
|
|
|
|
followerMap.getOrDefault(player, Collections.emptySet()).forEach(follower -> {
|
|
|
|
|
trace.render(follower, playerTraceShowData);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
traces.put(nextOpenId, trace);
|
|
|
|
|
tracesByRegion.computeIfAbsent(trace.getRegion(), region -> new HashMap<>()).put(nextOpenId, trace);
|
|
|
|
@ -63,7 +68,16 @@ public class TraceManager implements Listener {
|
|
|
|
|
|
|
|
|
|
protected void addAll(Trace trace, List<TNTPoint> TNTPoints) {
|
|
|
|
|
trace.addAll(TNTPoints, player -> {
|
|
|
|
|
return showDataPerRegionPerPlayer.getOrDefault(trace.getRegion(), Collections.emptyMap()).get(player);
|
|
|
|
|
Map.Entry<Player, Set<Player>> entry = followerMap.entrySet()
|
|
|
|
|
.stream()
|
|
|
|
|
.filter(playerSetEntry -> playerSetEntry.getValue().contains(player))
|
|
|
|
|
.findFirst()
|
|
|
|
|
.orElse(null);
|
|
|
|
|
if (entry == null) {
|
|
|
|
|
return showDataPerRegionPerPlayer.getOrDefault(trace.getRegion(), Collections.emptyMap()).get(player);
|
|
|
|
|
} else {
|
|
|
|
|
return showDataPerRegionPerPlayer.getOrDefault(trace.getRegion(), Collections.emptyMap()).get(entry.getKey());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -78,6 +92,7 @@ public class TraceManager implements Listener {
|
|
|
|
|
Trace trace = traces.remove(id);
|
|
|
|
|
showDataPerRegionPerPlayer.get(trace.getRegion()).forEach((player, playerTraceShowData) -> {
|
|
|
|
|
trace.hide(player);
|
|
|
|
|
followerMap.getOrDefault(player, Collections.emptySet()).forEach(trace::hide);
|
|
|
|
|
});
|
|
|
|
|
tracesByRegion.get(trace.getRegion()).remove(id);
|
|
|
|
|
return true;
|
|
|
|
@ -92,8 +107,10 @@ public class TraceManager implements Listener {
|
|
|
|
|
.flatMap(map -> map.entrySet().stream())
|
|
|
|
|
.map(Map.Entry::getKey)
|
|
|
|
|
.forEach(player -> {
|
|
|
|
|
Set<Player> players = followerMap.getOrDefault(player, Collections.emptySet());
|
|
|
|
|
traces.values().forEach(trace -> {
|
|
|
|
|
trace.hide(player);
|
|
|
|
|
players.forEach(trace::hide);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
traces.clear();
|
|
|
|
@ -144,10 +161,15 @@ public class TraceManager implements Listener {
|
|
|
|
|
* @param playerTraceShowData
|
|
|
|
|
*/
|
|
|
|
|
public void show(Player player, PlayerTraceShowData playerTraceShowData) {
|
|
|
|
|
unfollow(player);
|
|
|
|
|
|
|
|
|
|
Region region = Region.getRegion(player.getLocation());
|
|
|
|
|
showDataPerRegionPerPlayer.computeIfAbsent(region, ignored -> new HashMap<>()).put(player, playerTraceShowData);
|
|
|
|
|
tracesByRegion.getOrDefault(region, Collections.emptyMap()).forEach((integer, trace) -> {
|
|
|
|
|
trace.render(player, playerTraceShowData);
|
|
|
|
|
followerMap.getOrDefault(player, Collections.emptySet()).forEach(follower -> {
|
|
|
|
|
trace.render(follower, playerTraceShowData);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -157,11 +179,56 @@ public class TraceManager implements Listener {
|
|
|
|
|
* @param player
|
|
|
|
|
*/
|
|
|
|
|
public void hide(Player player) {
|
|
|
|
|
unfollow(player);
|
|
|
|
|
|
|
|
|
|
Region region = Region.getRegion(player.getLocation());
|
|
|
|
|
PlayerTraceShowData previous = showDataPerRegionPerPlayer.getOrDefault(region, Collections.emptyMap()).remove(player);
|
|
|
|
|
if (previous == null) return;
|
|
|
|
|
tracesByRegion.getOrDefault(player, Collections.emptyMap()).forEach((integer, trace) -> {
|
|
|
|
|
tracesByRegion.getOrDefault(region, Collections.emptyMap()).forEach((integer, trace) -> {
|
|
|
|
|
trace.hide(player);
|
|
|
|
|
followerMap.getOrDefault(player, Collections.emptySet()).forEach(trace::hide);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean hasFollower(Player player) {
|
|
|
|
|
return followerMap.containsKey(player);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean follow(Player follower, Player following) {
|
|
|
|
|
if (followerMap.containsKey(follower)) return false;
|
|
|
|
|
followerMap.computeIfAbsent(following, ignored -> new HashSet<>()).add(follower);
|
|
|
|
|
|
|
|
|
|
showDataPerRegionPerPlayer.forEach((region, playerPlayerTraceShowDataMap) -> {
|
|
|
|
|
if (playerPlayerTraceShowDataMap.containsKey(follower)) {
|
|
|
|
|
tracesByRegion.getOrDefault(region, Collections.emptyMap()).forEach((integer, trace) -> {
|
|
|
|
|
trace.hide(follower);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlayerTraceShowData playerTraceShowData = playerPlayerTraceShowDataMap.get(following);
|
|
|
|
|
if (playerTraceShowData == null) return;
|
|
|
|
|
tracesByRegion.getOrDefault(region, Collections.emptyMap()).forEach((integer, trace) -> {
|
|
|
|
|
trace.render(follower, playerTraceShowData);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void unfollow(Player follower) {
|
|
|
|
|
if (followerMap.containsKey(follower)) return;
|
|
|
|
|
List<Player> toRemove = new ArrayList<>();
|
|
|
|
|
followerMap.forEach((player, players) -> {
|
|
|
|
|
players.remove(player);
|
|
|
|
|
if (players.isEmpty()) toRemove.add(player);
|
|
|
|
|
});
|
|
|
|
|
toRemove.forEach(followerMap::remove);
|
|
|
|
|
|
|
|
|
|
showDataPerRegionPerPlayer.forEach((region, playerPlayerTraceShowDataMap) -> {
|
|
|
|
|
PlayerTraceShowData playerTraceShowData = playerPlayerTraceShowDataMap.get(follower);
|
|
|
|
|
if (playerTraceShowData == null) return;
|
|
|
|
|
tracesByRegion.getOrDefault(region, Collections.emptyMap()).forEach((integer, trace) -> {
|
|
|
|
|
trace.render(follower, playerTraceShowData);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -173,6 +240,8 @@ public class TraceManager implements Listener {
|
|
|
|
|
* @param to end of time interval
|
|
|
|
|
*/
|
|
|
|
|
public void renderAt(Player player, int from, int to) {
|
|
|
|
|
unfollow(player);
|
|
|
|
|
|
|
|
|
|
Region region = Region.getRegion(player.getLocation());
|
|
|
|
|
PlayerTraceShowData playerTraceShowData = showDataPerRegionPerPlayer.computeIfAbsent(region, ignored -> new HashMap<>()).computeIfAbsent(player, ignored -> new PlayerTraceShowData(BundleFilter.STRICT));
|
|
|
|
|
|
|
|
|
@ -186,6 +255,9 @@ public class TraceManager implements Listener {
|
|
|
|
|
|
|
|
|
|
tracesByRegion.getOrDefault(region, Collections.emptyMap()).forEach((integer, trace) -> {
|
|
|
|
|
trace.render(player, playerTraceShowData);
|
|
|
|
|
followerMap.getOrDefault(player, Collections.emptySet()).forEach(follower -> {
|
|
|
|
|
trace.render(follower, playerTraceShowData);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -196,6 +268,8 @@ public class TraceManager implements Listener {
|
|
|
|
|
* @param records the record for which isolation is toggled
|
|
|
|
|
*/
|
|
|
|
|
public void isolate(Player player, TNTPoint... records) {
|
|
|
|
|
unfollow(player);
|
|
|
|
|
|
|
|
|
|
Region region = Region.getRegion(player.getLocation());
|
|
|
|
|
PlayerTraceShowData playerTraceShowData = showDataPerRegionPerPlayer.computeIfAbsent(region, ignored -> new HashMap<>()).computeIfAbsent(player, ignored -> new PlayerTraceShowData(BundleFilter.STRICT));
|
|
|
|
|
|
|
|
|
@ -219,6 +293,9 @@ public class TraceManager implements Listener {
|
|
|
|
|
PlayerTraceShowData finalPlayerTraceShowData = playerTraceShowData;
|
|
|
|
|
tracesByRegion.getOrDefault(region, Collections.emptyMap()).forEach((integer, trace) -> {
|
|
|
|
|
trace.render(player, finalPlayerTraceShowData);
|
|
|
|
|
followerMap.getOrDefault(player, Collections.emptySet()).forEach(follower -> {
|
|
|
|
|
trace.render(follower, finalPlayerTraceShowData);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|