mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-21 05:50:18 +08:00
parent
7d0554688a
commit
913766214c
@ -99,6 +99,8 @@ public enum Settings {
|
||||
// StringList
|
||||
HIDE_FACTIONS("Plugins.Factions.HideFactions"),
|
||||
HIDE_TOWNS("Plugins.Towny.HideTowns"),
|
||||
// Config section
|
||||
WORLD_ALIASES("Customization.WorldAliases"),
|
||||
//
|
||||
// Bungee
|
||||
BUNGEE_IP("Server.IP"),
|
||||
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package main.java.com.djrapitops.plan;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Class responsible for managing Bukkit side config settings for World Aliases.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class WorldAliasSettings {
|
||||
|
||||
private final Plan plugin;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param plugin Current instance of Plan.
|
||||
*/
|
||||
public WorldAliasSettings(Plan plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get all World aliases in the config
|
||||
*
|
||||
* @return Map: Original name, Alias
|
||||
*/
|
||||
public Map<String, String> getAliases() {
|
||||
ConfigurationSection aliasSect = getAliasSection();
|
||||
|
||||
Map<String, String> aliasMap = new HashMap<>();
|
||||
for (String world : aliasSect.getKeys(false)) {
|
||||
aliasMap.put(world, aliasSect.getString(world));
|
||||
}
|
||||
return aliasMap;
|
||||
}
|
||||
|
||||
private ConfigurationSection getAliasSection() {
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
return config.getConfigurationSection(Settings.WORLD_ALIASES.getPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new World to the config section.
|
||||
* <p>
|
||||
* If exists does not override old value.
|
||||
*
|
||||
* @param world World name
|
||||
*/
|
||||
public void addWorld(String world) {
|
||||
ConfigurationSection aliasSect = getAliasSection();
|
||||
|
||||
Object previousValue = aliasSect.get(world);
|
||||
if (previousValue == null) {
|
||||
aliasSect.set(world, world);
|
||||
}
|
||||
plugin.saveConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get alias of a single world.
|
||||
*
|
||||
* @param world World name.
|
||||
* @return Alias.
|
||||
*/
|
||||
public String getAlias(String world) {
|
||||
return getAliasSection().getString(world);
|
||||
}
|
||||
}
|
@ -103,8 +103,11 @@ public abstract class TimeKeeper {
|
||||
}
|
||||
|
||||
public long getTime(String state) {
|
||||
Long time = times.get(state);
|
||||
return time != null ? time : 0L;
|
||||
return times.getOrDefault(state, 0L);
|
||||
}
|
||||
|
||||
public void addTime(String state, long time) {
|
||||
times.put(state, times.getOrDefault(state, 0L) + time);
|
||||
}
|
||||
|
||||
public long getTotal() {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.systems.listeners;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.WorldAliasSettings;
|
||||
import main.java.com.djrapitops.plan.data.Session;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -46,6 +47,8 @@ public class PlanGamemodeChangeListener implements Listener {
|
||||
String gameMode = event.getNewGameMode().name();
|
||||
String worldName = p.getWorld().getName();
|
||||
|
||||
new WorldAliasSettings(plugin).addWorld(worldName);
|
||||
|
||||
Optional<Session> cachedSession = plugin.getDataCache().getCachedSession(uuid);
|
||||
cachedSession.ifPresent(session -> session.changeState(worldName, gameMode, time));
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.systems.listeners;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.WorldAliasSettings;
|
||||
import main.java.com.djrapitops.plan.data.Session;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -28,6 +29,8 @@ public class PlanWorldChangeListener implements Listener {
|
||||
String gameMode = p.getGameMode().name();
|
||||
long time = MiscUtils.getTime();
|
||||
|
||||
new WorldAliasSettings(plugin).addWorld(worldName);
|
||||
|
||||
Optional<Session> cachedSession = plugin.getDataCache().getCachedSession(uuid);
|
||||
cachedSession.ifPresent(session -> session.changeState(worldName, gameMode, time));
|
||||
}
|
||||
|
@ -1,12 +1,11 @@
|
||||
package main.java.com.djrapitops.plan.utilities.html.graphs;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.WorldAliasSettings;
|
||||
import main.java.com.djrapitops.plan.data.time.GMTimes;
|
||||
import main.java.com.djrapitops.plan.data.time.WorldTimes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class WorldPieCreator {
|
||||
@ -28,14 +27,16 @@ public class WorldPieCreator {
|
||||
Map<String, Long> playtimePerWorld = worldTimes.getWorldTimes().entrySet().stream()
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().getTotal()));
|
||||
|
||||
List<String> worlds = new ArrayList<>(playtimePerWorld.keySet());
|
||||
Map<String, Long> playtimePerAlias = transformToAliases(playtimePerWorld);
|
||||
|
||||
List<String> worlds = new ArrayList<>(playtimePerAlias.keySet());
|
||||
Collections.sort(worlds);
|
||||
|
||||
int size = playtimePerWorld.size();
|
||||
for (String worldName : worlds) {
|
||||
seriesBuilder.append("{name:'").append(worldName)
|
||||
.append("',y:").append(playtimePerWorld.getOrDefault(worldName, 0L))
|
||||
.append(",drilldown: '").append(worldName).append("'");
|
||||
int size = playtimePerAlias.size();
|
||||
for (String alias : worlds) {
|
||||
seriesBuilder.append("{name:'").append(alias)
|
||||
.append("',y:").append(playtimePerAlias.getOrDefault(alias, 0L))
|
||||
.append(",drilldown: '").append(alias).append("'");
|
||||
|
||||
seriesBuilder.append("}");
|
||||
if (i < size - 1) {
|
||||
@ -52,6 +53,27 @@ public class WorldPieCreator {
|
||||
return new String[]{seriesData, drilldownData};
|
||||
}
|
||||
|
||||
private static Map<String, Long> transformToAliases(Map<String, Long> playtimePerWorld) {
|
||||
WorldAliasSettings aliasSettings = new WorldAliasSettings(Plan.getInstance());
|
||||
Map<String, String> aliases = aliasSettings.getAliases();
|
||||
|
||||
Map<String, Long> playtimePerAlias = new HashMap<>();
|
||||
for (Map.Entry<String, Long> entry : playtimePerWorld.entrySet()) {
|
||||
String worldName = entry.getKey();
|
||||
long playtime = entry.getValue();
|
||||
|
||||
if (!aliases.containsKey(worldName)) {
|
||||
aliases.put(worldName, worldName);
|
||||
aliasSettings.addWorld(worldName);
|
||||
}
|
||||
|
||||
String alias = aliases.get(worldName);
|
||||
|
||||
playtimePerAlias.put(alias, playtimePerAlias.getOrDefault(alias, 0L) + playtime);
|
||||
}
|
||||
return playtimePerAlias;
|
||||
}
|
||||
|
||||
private static String createDrilldownData(WorldTimes worldTimes) {
|
||||
StringBuilder drilldownBuilder = new StringBuilder();
|
||||
int i = 0;
|
||||
@ -60,15 +82,17 @@ public class WorldPieCreator {
|
||||
if (gmTimesMap.isEmpty()) {
|
||||
return "[]";
|
||||
}
|
||||
Map<String, GMTimes> gmTimesAliasMap = transformToGMAliases(gmTimesMap);
|
||||
|
||||
int size = gmTimesMap.size();
|
||||
drilldownBuilder.append("[");
|
||||
for (Map.Entry<String, GMTimes> world : gmTimesMap.entrySet()) {
|
||||
drilldownBuilder.append("{name:'").append(world.getKey())
|
||||
.append("', id:'").append(world.getKey())
|
||||
for (Map.Entry<String, GMTimes> worldAlias : gmTimesAliasMap.entrySet()) {
|
||||
drilldownBuilder.append("{name:'").append(worldAlias.getKey())
|
||||
.append("', id:'").append(worldAlias.getKey())
|
||||
.append("',colors: gmPieColors,");
|
||||
drilldownBuilder.append("data: [");
|
||||
|
||||
appendGMTimesForWorld(drilldownBuilder, world);
|
||||
appendGMTimesForWorld(drilldownBuilder, worldAlias);
|
||||
|
||||
if (i < size - 1) {
|
||||
drilldownBuilder.append(",");
|
||||
@ -79,6 +103,34 @@ public class WorldPieCreator {
|
||||
return drilldownBuilder.toString();
|
||||
}
|
||||
|
||||
private static Map<String, GMTimes> transformToGMAliases(Map<String, GMTimes> gmTimesMap) {
|
||||
WorldAliasSettings aliasSettings = new WorldAliasSettings(Plan.getInstance());
|
||||
Map<String, String> aliases = aliasSettings.getAliases();
|
||||
|
||||
Map<String, GMTimes> gmTimesPerAlias = new HashMap<>();
|
||||
|
||||
String[] gms = GMTimes.getGMKeyArray();
|
||||
|
||||
for (Map.Entry<String, GMTimes> entry : gmTimesMap.entrySet()) {
|
||||
String worldName = entry.getKey();
|
||||
GMTimes gmTimes = entry.getValue();
|
||||
|
||||
if (!aliases.containsKey(worldName)) {
|
||||
aliases.put(worldName, worldName);
|
||||
aliasSettings.addWorld(worldName);
|
||||
}
|
||||
|
||||
String alias = aliases.get(worldName);
|
||||
|
||||
GMTimes aliasGMtimes = gmTimesPerAlias.getOrDefault(alias, new GMTimes());
|
||||
for (String gm : gms) {
|
||||
aliasGMtimes.addTime(gm, gmTimes.getTime(gm));
|
||||
}
|
||||
gmTimesPerAlias.put(alias, aliasGMtimes);
|
||||
}
|
||||
return gmTimesPerAlias;
|
||||
}
|
||||
|
||||
private static void appendGMTimesForWorld(StringBuilder drilldownBuilder, Map.Entry<String, GMTimes> world) {
|
||||
Map<String, Long> gmTimes = world.getValue().getTimes();
|
||||
int smallSize = gmTimes.size();
|
||||
|
@ -67,6 +67,8 @@ Customization:
|
||||
Minutes: '%minutes%m '
|
||||
Seconds: '%seconds%s'
|
||||
Zero: '0s'
|
||||
WorldAliases:
|
||||
world: world
|
||||
|
||||
Theme:
|
||||
Base: Default
|
||||
|
Loading…
Reference in New Issue
Block a user