mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-15 20:51:21 +01:00
Rearranged code
This commit is contained in:
parent
9bbe4b27b2
commit
47f061edcb
@ -52,6 +52,14 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
private boolean setupAllowed = false;
|
private boolean setupAllowed = false;
|
||||||
|
|
||||||
|
public static PlanBungee getInstance() {
|
||||||
|
return (PlanBungee) StaticHolder.getInstance(PlanBungee.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UUID getServerUUID() {
|
||||||
|
return getInstance().getServerUuid();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
super.onEnable();
|
super.onEnable();
|
||||||
@ -99,10 +107,6 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
|
|||||||
registerCommand("planbungee", new PlanBungeeCommand(this));
|
registerCommand("planbungee", new PlanBungeeCommand(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlanBungee getInstance() {
|
|
||||||
return (PlanBungee) StaticHolder.getInstance(PlanBungee.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
system.disable();
|
system.disable();
|
||||||
@ -163,10 +167,6 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
|
|||||||
return variableHolder;
|
return variableHolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UUID getServerUUID() {
|
|
||||||
return getInstance().getServerUuid();
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getServerUuid() {
|
public UUID getServerUuid() {
|
||||||
return serverInfoManager.getServerUUID();
|
return serverInfoManager.getServerUUID();
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,19 @@ import java.util.UUID;
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public interface PlanPlugin extends IPlugin {
|
public interface PlanPlugin extends IPlugin {
|
||||||
|
static PlanPlugin getInstance() {
|
||||||
|
boolean bukkitAvailable = Check.isBukkitAvailable();
|
||||||
|
boolean bungeeAvailable = Check.isBungeeAvailable();
|
||||||
|
if (bukkitAvailable && bungeeAvailable) {
|
||||||
|
// TODO Test Plugin
|
||||||
|
} else if (bungeeAvailable) {
|
||||||
|
return Plan.getInstance();
|
||||||
|
} else if (bukkitAvailable) {
|
||||||
|
return PlanBungee.getInstance();
|
||||||
|
}
|
||||||
|
throw new IllegalAccessError("Plugin instance not available");
|
||||||
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
Database getDB();
|
Database getDB();
|
||||||
|
|
||||||
@ -55,17 +68,4 @@ public interface PlanPlugin extends IPlugin {
|
|||||||
ColorScheme getColorScheme();
|
ColorScheme getColorScheme();
|
||||||
|
|
||||||
boolean isReloading();
|
boolean isReloading();
|
||||||
|
|
||||||
static PlanPlugin getInstance() {
|
|
||||||
boolean bukkitAvailable = Check.isBukkitAvailable();
|
|
||||||
boolean bungeeAvailable = Check.isBungeeAvailable();
|
|
||||||
if (bukkitAvailable && bungeeAvailable) {
|
|
||||||
// TODO Test Plugin
|
|
||||||
} else if (bungeeAvailable) {
|
|
||||||
return Plan.getInstance();
|
|
||||||
} else if (bukkitAvailable) {
|
|
||||||
return PlanBungee.getInstance();
|
|
||||||
}
|
|
||||||
throw new IllegalAccessError("Plugin instance not available");
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -79,6 +79,57 @@ public class PlayerProfile implements OfflinePlayer {
|
|||||||
activityIndexCache = new HashMap<>();
|
activityIndexCache = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static long getPlaytime(Stream<Session> s) {
|
||||||
|
return s.map(Session::getLength)
|
||||||
|
.mapToLong(i -> i)
|
||||||
|
.sum();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long getLongestSession(Stream<Session> s) {
|
||||||
|
OptionalLong longestSession = s.map(Session::getLength)
|
||||||
|
.mapToLong(i -> i)
|
||||||
|
.max();
|
||||||
|
if (longestSession.isPresent()) {
|
||||||
|
return longestSession.getAsLong();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long getSessionMedian(Stream<Session> s) {
|
||||||
|
List<Long> sessionLenghts = s.map(Session::getLength)
|
||||||
|
.sorted()
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (sessionLenghts.isEmpty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return sessionLenghts.get(sessionLenghts.size() / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long getSessionAverage(Stream<Session> s) {
|
||||||
|
OptionalDouble average = s.map(Session::getLength)
|
||||||
|
.mapToLong(i -> i)
|
||||||
|
.average();
|
||||||
|
if (average.isPresent()) {
|
||||||
|
return (long) average.getAsDouble();
|
||||||
|
}
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Stream<PlayerKill> getPlayerKills(Stream<Session> s) {
|
||||||
|
return s.map(Session::getPlayerKills)
|
||||||
|
.flatMap(Collection::stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long getDeathCount(Stream<Session> s) {
|
||||||
|
return s.mapToLong(Session::getDeaths)
|
||||||
|
.sum();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long getMobKillCount(Stream<Session> s) {
|
||||||
|
return s.mapToLong(Session::getMobKills)
|
||||||
|
.sum();
|
||||||
|
}
|
||||||
|
|
||||||
// Calculating Getters
|
// Calculating Getters
|
||||||
public ActivityIndex getActivityIndex(long date) {
|
public ActivityIndex getActivityIndex(long date) {
|
||||||
ActivityIndex index = activityIndexCache.get(date);
|
ActivityIndex index = activityIndexCache.get(date);
|
||||||
@ -98,6 +149,10 @@ public class PlayerProfile implements OfflinePlayer {
|
|||||||
return worldTimesMap.getOrDefault(null, new WorldTimes(new HashMap<>()));
|
return worldTimesMap.getOrDefault(null, new WorldTimes(new HashMap<>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setWorldTimes(Map<UUID, WorldTimes> worldTimes) {
|
||||||
|
worldTimesMap.putAll(worldTimes);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get world times per server for this player.
|
* Get world times per server for this player.
|
||||||
*
|
*
|
||||||
@ -151,12 +206,6 @@ public class PlayerProfile implements OfflinePlayer {
|
|||||||
return getPlaytime(getSessions(serverUUID).stream());
|
return getPlaytime(getSessions(serverUUID).stream());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getPlaytime(Stream<Session> s) {
|
|
||||||
return s.map(Session::getLength)
|
|
||||||
.mapToLong(i -> i)
|
|
||||||
.sum();
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getLongestSession() {
|
public long getLongestSession() {
|
||||||
return getLongestSession(-1, MiscUtils.getTime() + 1L);
|
return getLongestSession(-1, MiscUtils.getTime() + 1L);
|
||||||
}
|
}
|
||||||
@ -169,16 +218,6 @@ public class PlayerProfile implements OfflinePlayer {
|
|||||||
return getLongestSession(getSessions(serverUUID).stream());
|
return getLongestSession(getSessions(serverUUID).stream());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getLongestSession(Stream<Session> s) {
|
|
||||||
OptionalLong longestSession = s.map(Session::getLength)
|
|
||||||
.mapToLong(i -> i)
|
|
||||||
.max();
|
|
||||||
if (longestSession.isPresent()) {
|
|
||||||
return longestSession.getAsLong();
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getSessionMedian() {
|
public long getSessionMedian() {
|
||||||
return getSessionMedian(-1, MiscUtils.getTime() + 1L);
|
return getSessionMedian(-1, MiscUtils.getTime() + 1L);
|
||||||
}
|
}
|
||||||
@ -191,15 +230,7 @@ public class PlayerProfile implements OfflinePlayer {
|
|||||||
return getSessionMedian(getSessions(serverUUID).stream());
|
return getSessionMedian(getSessions(serverUUID).stream());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getSessionMedian(Stream<Session> s) {
|
// Special Getters
|
||||||
List<Long> sessionLenghts = s.map(Session::getLength)
|
|
||||||
.sorted()
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
if (sessionLenghts.isEmpty()) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return sessionLenghts.get(sessionLenghts.size() / 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getSessionAverage() {
|
public long getSessionAverage() {
|
||||||
return getSessionAverage(-1, MiscUtils.getTime() + 1L);
|
return getSessionAverage(-1, MiscUtils.getTime() + 1L);
|
||||||
@ -213,22 +244,10 @@ public class PlayerProfile implements OfflinePlayer {
|
|||||||
return getSessionAverage(getSessions(serverUUID).stream());
|
return getSessionAverage(getSessions(serverUUID).stream());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getSessionAverage(Stream<Session> s) {
|
|
||||||
OptionalDouble average = s.map(Session::getLength)
|
|
||||||
.mapToLong(i -> i)
|
|
||||||
.average();
|
|
||||||
if (average.isPresent()) {
|
|
||||||
return (long) average.getAsDouble();
|
|
||||||
}
|
|
||||||
return 0L;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean playedBetween(long after, long before) {
|
public boolean playedBetween(long after, long before) {
|
||||||
return getSessions(after, before).findFirst().isPresent();
|
return getSessions(after, before).findFirst().isPresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special Getters
|
|
||||||
|
|
||||||
public Stream<Session> getAllSessions() {
|
public Stream<Session> getAllSessions() {
|
||||||
return sessions.values().stream().flatMap(Collection::stream);
|
return sessions.values().stream().flatMap(Collection::stream);
|
||||||
}
|
}
|
||||||
@ -261,11 +280,6 @@ public class PlayerProfile implements OfflinePlayer {
|
|||||||
return getPlayerKills(getSessions(serverUUID).stream());
|
return getPlayerKills(getSessions(serverUUID).stream());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Stream<PlayerKill> getPlayerKills(Stream<Session> s) {
|
|
||||||
return s.map(Session::getPlayerKills)
|
|
||||||
.flatMap(Collection::stream);
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getPlayerKillCount() {
|
public long getPlayerKillCount() {
|
||||||
return getPlayerKills().count();
|
return getPlayerKills().count();
|
||||||
}
|
}
|
||||||
@ -282,11 +296,6 @@ public class PlayerProfile implements OfflinePlayer {
|
|||||||
return getDeathCount(getSessions(serverUUID).stream());
|
return getDeathCount(getSessions(serverUUID).stream());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getDeathCount(Stream<Session> s) {
|
|
||||||
return s.mapToLong(Session::getDeaths)
|
|
||||||
.sum();
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getMobKillCount() {
|
public long getMobKillCount() {
|
||||||
return getMobKillCount(getAllSessions());
|
return getMobKillCount(getAllSessions());
|
||||||
}
|
}
|
||||||
@ -295,11 +304,6 @@ public class PlayerProfile implements OfflinePlayer {
|
|||||||
return getMobKillCount(getSessions(serverUUID).stream());
|
return getMobKillCount(getSessions(serverUUID).stream());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getMobKillCount(Stream<Session> s) {
|
|
||||||
return s.mapToLong(Session::getMobKills)
|
|
||||||
.sum();
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getSessionCount() {
|
public long getSessionCount() {
|
||||||
return getAllSessions().count();
|
return getAllSessions().count();
|
||||||
}
|
}
|
||||||
@ -308,12 +312,12 @@ public class PlayerProfile implements OfflinePlayer {
|
|||||||
return getSessions(serverUUID).size();
|
return getSessions(serverUUID).size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setters & Adders
|
||||||
|
|
||||||
public long getRegistered(UUID serverUUID) {
|
public long getRegistered(UUID serverUUID) {
|
||||||
return registeredMap.getOrDefault(serverUUID, -1L);
|
return registeredMap.getOrDefault(serverUUID, -1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setters & Adders
|
|
||||||
|
|
||||||
public void bannedOnServer(UUID serverUUID) {
|
public void bannedOnServer(UUID serverUUID) {
|
||||||
bannedOnServers.add(serverUUID);
|
bannedOnServers.add(serverUUID);
|
||||||
}
|
}
|
||||||
@ -334,10 +338,6 @@ public class PlayerProfile implements OfflinePlayer {
|
|||||||
this.sessions.put(serverUUID, sessions);
|
this.sessions.put(serverUUID, sessions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSessions(Map<UUID, List<Session>> sessions) {
|
|
||||||
this.sessions.putAll(sessions);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addActiveSession(Session activeSession) {
|
public void addActiveSession(Session activeSession) {
|
||||||
UUID serverUUID = PlanPlugin.getInstance().getServerUuid();
|
UUID serverUUID = PlanPlugin.getInstance().getServerUuid();
|
||||||
List<Session> sessions = getSessions(serverUUID);
|
List<Session> sessions = getSessions(serverUUID);
|
||||||
@ -357,10 +357,6 @@ public class PlayerProfile implements OfflinePlayer {
|
|||||||
worldTimesMap.put(serverUUID, worldTimes);
|
worldTimesMap.put(serverUUID, worldTimes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWorldTimes(Map<UUID, WorldTimes> worldTimes) {
|
|
||||||
worldTimesMap.putAll(worldTimes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTotalWorldTimes(WorldTimes worldTimes) {
|
public void setTotalWorldTimes(WorldTimes worldTimes) {
|
||||||
worldTimesMap.put(null, worldTimes);
|
worldTimesMap.put(null, worldTimes);
|
||||||
}
|
}
|
||||||
@ -369,38 +365,34 @@ public class PlayerProfile implements OfflinePlayer {
|
|||||||
registeredMap.put(serverUUID, registered);
|
registeredMap.put(serverUUID, registered);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getTimesKicked() {
|
||||||
|
return timesKicked;
|
||||||
|
}
|
||||||
|
|
||||||
// Default Setters
|
// Default Setters
|
||||||
|
|
||||||
public void setActions(List<Action> actions) {
|
|
||||||
this.actions = actions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNicknames(Map<UUID, List<String>> nicknames) {
|
|
||||||
this.nicknames = nicknames;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGeoInformation(List<GeoInfo> geoInformation) {
|
|
||||||
this.geoInformation = geoInformation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTimesKicked(int timesKicked) {
|
public void setTimesKicked(int timesKicked) {
|
||||||
this.timesKicked = timesKicked;
|
this.timesKicked = timesKicked;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default Getters
|
|
||||||
|
|
||||||
public int getTimesKicked() {
|
|
||||||
return timesKicked;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<UUID, List<String>> getNicknames() {
|
public Map<UUID, List<String>> getNicknames() {
|
||||||
return nicknames;
|
return nicknames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setNicknames(Map<UUID, List<String>> nicknames) {
|
||||||
|
this.nicknames = nicknames;
|
||||||
|
}
|
||||||
|
|
||||||
public List<GeoInfo> getGeoInformation() {
|
public List<GeoInfo> getGeoInformation() {
|
||||||
return geoInformation;
|
return geoInformation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Default Getters
|
||||||
|
|
||||||
|
public void setGeoInformation(List<GeoInfo> geoInformation) {
|
||||||
|
this.geoInformation = geoInformation;
|
||||||
|
}
|
||||||
|
|
||||||
public UUID getUuid() {
|
public UUID getUuid() {
|
||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
@ -425,10 +417,18 @@ public class PlayerProfile implements OfflinePlayer {
|
|||||||
return sessions;
|
return sessions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSessions(Map<UUID, List<Session>> sessions) {
|
||||||
|
this.sessions.putAll(sessions);
|
||||||
|
}
|
||||||
|
|
||||||
public List<Action> getActions() {
|
public List<Action> getActions() {
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setActions(List<Action> actions) {
|
||||||
|
this.actions = actions;
|
||||||
|
}
|
||||||
|
|
||||||
public Map<String, String> getPluginReplaceMap() {
|
public Map<String, String> getPluginReplaceMap() {
|
||||||
return pluginReplaceMap;
|
return pluginReplaceMap;
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,125 @@ public class ServerProfile {
|
|||||||
lastPeakPlayers = -1;
|
lastPeakPlayers = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static long getLowSpikeCount(List<TPS> tpsData) {
|
||||||
|
int mediumThreshold = Settings.THEME_GRAPH_TPS_THRESHOLD_MED.getNumber();
|
||||||
|
|
||||||
|
boolean wasLow = false;
|
||||||
|
long spikeCount = 0L;
|
||||||
|
|
||||||
|
for (TPS tpsObj : tpsData) {
|
||||||
|
double tps = tpsObj.getTicksPerSecond();
|
||||||
|
if (tps < mediumThreshold) {
|
||||||
|
if (!wasLow) {
|
||||||
|
spikeCount++;
|
||||||
|
wasLow = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
wasLow = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return spikeCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<PlayerKill> getPlayerKills(List<Session> s) {
|
||||||
|
List<PlayerKill> kills = new ArrayList<>();
|
||||||
|
for (Session session : s) {
|
||||||
|
kills.addAll(session.getPlayerKills());
|
||||||
|
}
|
||||||
|
return kills;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long getMobKillCount(List<Session> s) {
|
||||||
|
long total = 0;
|
||||||
|
for (Session session : s) {
|
||||||
|
total += session.getMobKills();
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long getDeathCount(List<Session> s) {
|
||||||
|
long total = 0;
|
||||||
|
for (Session session : s) {
|
||||||
|
total += session.getDeaths();
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getPlayersOnline() {
|
||||||
|
if (Check.isBungeeAvailable()) {
|
||||||
|
return PlanBungee.getInstance().getProxy().getOnlineCount();
|
||||||
|
} else {
|
||||||
|
return Plan.getInstance().getServer().getOnlinePlayers().size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getPlayersMax() {
|
||||||
|
return PlanPlugin.getInstance().getVariable().getMaxPlayers();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long serverDownTime(List<TPS> tpsData) {
|
||||||
|
long lastDate = -1;
|
||||||
|
long downTime = 0;
|
||||||
|
for (TPS tps : tpsData) {
|
||||||
|
long date = tps.getDate();
|
||||||
|
if (lastDate == -1) {
|
||||||
|
lastDate = date;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
long diff = date - lastDate;
|
||||||
|
if (diff > TimeAmount.MINUTE.ms() * 3L) {
|
||||||
|
downTime += diff;
|
||||||
|
}
|
||||||
|
lastDate = date;
|
||||||
|
}
|
||||||
|
|
||||||
|
return downTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long serverIdleTime(List<TPS> tpsData) {
|
||||||
|
long lastDate = -1;
|
||||||
|
int lastPlayers = 0;
|
||||||
|
long idleTime = 0;
|
||||||
|
for (TPS tps : tpsData) {
|
||||||
|
long date = tps.getDate();
|
||||||
|
int players = tps.getPlayers();
|
||||||
|
if (lastDate == -1) {
|
||||||
|
lastDate = date;
|
||||||
|
lastPlayers = players;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
long diff = date - lastDate;
|
||||||
|
if (lastPlayers == 0 && players == 0) {
|
||||||
|
idleTime += diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastDate = date;
|
||||||
|
lastPlayers = players;
|
||||||
|
}
|
||||||
|
|
||||||
|
return idleTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double aboveLowThreshold(List<TPS> tpsData) {
|
||||||
|
if (tpsData.isEmpty()) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int threshold = Settings.THEME_GRAPH_TPS_THRESHOLD_MED.getNumber();
|
||||||
|
|
||||||
|
long count = 0;
|
||||||
|
for (TPS tps : tpsData) {
|
||||||
|
if (tps.getTicksPerSecond() >= threshold) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count * 1.0 / tpsData.size();
|
||||||
|
}
|
||||||
|
|
||||||
public List<PlayerProfile> getPlayers() {
|
public List<PlayerProfile> getPlayers() {
|
||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
@ -88,27 +207,6 @@ public class ServerProfile {
|
|||||||
this.commandUsage = commandUsage;
|
this.commandUsage = commandUsage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getLowSpikeCount(List<TPS> tpsData) {
|
|
||||||
int mediumThreshold = Settings.THEME_GRAPH_TPS_THRESHOLD_MED.getNumber();
|
|
||||||
|
|
||||||
boolean wasLow = false;
|
|
||||||
long spikeCount = 0L;
|
|
||||||
|
|
||||||
for (TPS tpsObj : tpsData) {
|
|
||||||
double tps = tpsObj.getTicksPerSecond();
|
|
||||||
if (tps < mediumThreshold) {
|
|
||||||
if (!wasLow) {
|
|
||||||
spikeCount++;
|
|
||||||
wasLow = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
wasLow = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return spikeCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getAverageTPS(long after, long before) {
|
public double getAverageTPS(long after, long before) {
|
||||||
OptionalDouble average = getTPSData(after, before)
|
OptionalDouble average = getTPSData(after, before)
|
||||||
.mapToDouble(TPS::getTicksPerSecond)
|
.mapToDouble(TPS::getTicksPerSecond)
|
||||||
@ -200,6 +298,8 @@ public class ServerProfile {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Default setters & getters
|
||||||
|
|
||||||
public long getTotalPlaytime() {
|
public long getTotalPlaytime() {
|
||||||
return serverWorldtimes.getTotal();
|
return serverWorldtimes.getTotal();
|
||||||
}
|
}
|
||||||
@ -220,32 +320,6 @@ public class ServerProfile {
|
|||||||
return players.stream().map(p -> p.getSessions(serverUUID)).flatMap(Collection::stream).collect(Collectors.toList());
|
return players.stream().map(p -> p.getSessions(serverUUID)).flatMap(Collection::stream).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<PlayerKill> getPlayerKills(List<Session> s) {
|
|
||||||
List<PlayerKill> kills = new ArrayList<>();
|
|
||||||
for (Session session : s) {
|
|
||||||
kills.addAll(session.getPlayerKills());
|
|
||||||
}
|
|
||||||
return kills;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long getMobKillCount(List<Session> s) {
|
|
||||||
long total = 0;
|
|
||||||
for (Session session : s) {
|
|
||||||
total += session.getMobKills();
|
|
||||||
}
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long getDeathCount(List<Session> s) {
|
|
||||||
long total = 0;
|
|
||||||
for (Session session : s) {
|
|
||||||
total += session.getDeaths();
|
|
||||||
}
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default setters & getters
|
|
||||||
|
|
||||||
public WorldTimes getServerWorldtimes() {
|
public WorldTimes getServerWorldtimes() {
|
||||||
return serverWorldtimes;
|
return serverWorldtimes;
|
||||||
}
|
}
|
||||||
@ -286,18 +360,6 @@ public class ServerProfile {
|
|||||||
this.allTimePeakPlayers = allTimePeakPlayers;
|
this.allTimePeakPlayers = allTimePeakPlayers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getPlayersOnline() {
|
|
||||||
if (Check.isBungeeAvailable()) {
|
|
||||||
return PlanBungee.getInstance().getProxy().getOnlineCount();
|
|
||||||
} else {
|
|
||||||
return Plan.getInstance().getServer().getOnlinePlayers().size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getPlayersMax() {
|
|
||||||
return PlanPlugin.getInstance().getVariable().getMaxPlayers();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Stream<PlayerProfile> getOps() {
|
public Stream<PlayerProfile> getOps() {
|
||||||
return players.stream().filter(PlayerProfile::isOp);
|
return players.stream().filter(PlayerProfile::isOp);
|
||||||
}
|
}
|
||||||
@ -316,74 +378,12 @@ public class ServerProfile {
|
|||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long serverDownTime(List<TPS> tpsData) {
|
|
||||||
long lastDate = -1;
|
|
||||||
long downTime = 0;
|
|
||||||
for (TPS tps : tpsData) {
|
|
||||||
long date = tps.getDate();
|
|
||||||
if (lastDate == -1) {
|
|
||||||
lastDate = date;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
long diff = date - lastDate;
|
|
||||||
if (diff > TimeAmount.MINUTE.ms() * 3L) {
|
|
||||||
downTime += diff;
|
|
||||||
}
|
|
||||||
lastDate = date;
|
|
||||||
}
|
|
||||||
|
|
||||||
return downTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long serverIdleTime(long after, long before) {
|
public long serverIdleTime(long after, long before) {
|
||||||
return serverIdleTime(getTPSData(after, before)
|
return serverIdleTime(getTPSData(after, before)
|
||||||
.sorted(new TPSComparator())
|
.sorted(new TPSComparator())
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long serverIdleTime(List<TPS> tpsData) {
|
|
||||||
long lastDate = -1;
|
|
||||||
int lastPlayers = 0;
|
|
||||||
long idleTime = 0;
|
|
||||||
for (TPS tps : tpsData) {
|
|
||||||
long date = tps.getDate();
|
|
||||||
int players = tps.getPlayers();
|
|
||||||
if (lastDate == -1) {
|
|
||||||
lastDate = date;
|
|
||||||
lastPlayers = players;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
long diff = date - lastDate;
|
|
||||||
if (lastPlayers == 0 && players == 0) {
|
|
||||||
idleTime += diff;
|
|
||||||
}
|
|
||||||
|
|
||||||
lastDate = date;
|
|
||||||
lastPlayers = players;
|
|
||||||
}
|
|
||||||
|
|
||||||
return idleTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double aboveLowThreshold(List<TPS> tpsData) {
|
|
||||||
if (tpsData.isEmpty()) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int threshold = Settings.THEME_GRAPH_TPS_THRESHOLD_MED.getNumber();
|
|
||||||
|
|
||||||
long count = 0;
|
|
||||||
for (TPS tps : tpsData) {
|
|
||||||
if (tps.getTicksPerSecond() >= threshold) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return count * 1.0 / tpsData.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlayerProfile getPlayer(UUID uuid) {
|
public PlayerProfile getPlayer(UUID uuid) {
|
||||||
if (playerMap == null) {
|
if (playerMap == null) {
|
||||||
playerMap = players.stream().collect(Collectors.toMap(PlayerProfile::getUuid, Function.identity()));
|
playerMap = players.stream().collect(Collectors.toMap(PlayerProfile::getUuid, Function.identity()));
|
||||||
|
@ -11,16 +11,16 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public class ActivityIndex {
|
public class ActivityIndex {
|
||||||
|
|
||||||
private static long loadSetting(long value) {
|
|
||||||
return value < 0 ? 1 : value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final double value;
|
private final double value;
|
||||||
|
|
||||||
public ActivityIndex(PlayerProfile player, long date) {
|
public ActivityIndex(PlayerProfile player, long date) {
|
||||||
value = calculate(player, date);
|
value = calculate(player, date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static long loadSetting(long value) {
|
||||||
|
return value < 0 ? 1 : value;
|
||||||
|
}
|
||||||
|
|
||||||
private double calculate(PlayerProfile player, long date) {
|
private double calculate(PlayerProfile player, long date) {
|
||||||
long week = TimeAmount.WEEK.ms();
|
long week = TimeAmount.WEEK.ms();
|
||||||
long weekAgo = date - week;
|
long weekAgo = date - week;
|
||||||
|
@ -26,13 +26,12 @@ import java.util.stream.Collectors;
|
|||||||
public class HealthNotes {
|
public class HealthNotes {
|
||||||
|
|
||||||
private final List<String> healthNotes;
|
private final List<String> healthNotes;
|
||||||
private double serverHealth;
|
|
||||||
|
|
||||||
private final AnalysisData analysisData;
|
private final AnalysisData analysisData;
|
||||||
private final TreeMap<Long, Map<String, Set<UUID>>> activityData;
|
private final TreeMap<Long, Map<String, Set<UUID>>> activityData;
|
||||||
private final List<TPS> tpsDataMonth;
|
private final List<TPS> tpsDataMonth;
|
||||||
private final long now;
|
private final long now;
|
||||||
private final long fourWeeksAgo;
|
private final long fourWeeksAgo;
|
||||||
|
private double serverHealth;
|
||||||
|
|
||||||
public HealthNotes(AnalysisData analysisData, TreeMap<Long, Map<String, Set<UUID>>> activityData, List<TPS> tpsDataMonth, long now) {
|
public HealthNotes(AnalysisData analysisData, TreeMap<Long, Map<String, Set<UUID>>> activityData, List<TPS> tpsDataMonth, long now) {
|
||||||
this.healthNotes = new ArrayList<>();
|
this.healthNotes = new ArrayList<>();
|
||||||
|
@ -25,21 +25,6 @@ import java.util.UUID;
|
|||||||
*/
|
*/
|
||||||
public class ServerSpecificSettings {
|
public class ServerSpecificSettings {
|
||||||
|
|
||||||
public void addOriginalBukkitSettings(PlanBungee plugin, UUID serverUUID, Map<String, Object> settings) {
|
|
||||||
try {
|
|
||||||
Config config = plugin.getMainConfig();
|
|
||||||
if (!Verify.isEmpty(config.getString("Servers." + serverUUID + ".ServerName"))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (Map.Entry<String, Object> entry : settings.entrySet()) {
|
|
||||||
config.set("Servers." + serverUUID + "." + entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
config.save();
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.toLog(this.getClass().getName(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void updateSettings(Plan plugin, Map<String, String> settings) {
|
public static void updateSettings(Plan plugin, Map<String, String> settings) {
|
||||||
Log.debug("Checking new settings..");
|
Log.debug("Checking new settings..");
|
||||||
Config config = plugin.getMainConfig();
|
Config config = plugin.getMainConfig();
|
||||||
@ -92,6 +77,21 @@ public class ServerSpecificSettings {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addOriginalBukkitSettings(PlanBungee plugin, UUID serverUUID, Map<String, Object> settings) {
|
||||||
|
try {
|
||||||
|
Config config = plugin.getMainConfig();
|
||||||
|
if (!Verify.isEmpty(config.getString("Servers." + serverUUID + ".ServerName"))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (Map.Entry<String, Object> entry : settings.entrySet()) {
|
||||||
|
config.set("Servers." + serverUUID + "." + entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
config.save();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.toLog(this.getClass().getName(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String getPath(UUID serverUUID, Settings setting) {
|
private String getPath(UUID serverUUID, Settings setting) {
|
||||||
String path = "Servers." + serverUUID;
|
String path = "Servers." + serverUUID;
|
||||||
switch (setting) {
|
switch (setting) {
|
||||||
|
@ -44,10 +44,6 @@ public class Locale {
|
|||||||
messages = new EnumMap<>(Msg.class);
|
messages = new EnumMap<>(Msg.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unload() {
|
|
||||||
messages.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Locale getInstance() {
|
public static Locale getInstance() {
|
||||||
Locale locale = ConfigSystem.getInstance().getLocale();
|
Locale locale = ConfigSystem.getInstance().getLocale();
|
||||||
NullCheck.check(locale, new IllegalStateException("Locale has not been initialized."));
|
NullCheck.check(locale, new IllegalStateException("Locale has not been initialized."));
|
||||||
@ -58,6 +54,10 @@ public class Locale {
|
|||||||
return getInstance().getMessage(msg);
|
return getInstance().getMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void unload() {
|
||||||
|
messages.clear();
|
||||||
|
}
|
||||||
|
|
||||||
public void loadLocale() {
|
public void loadLocale() {
|
||||||
String locale = Settings.LOCALE.toString().toUpperCase();
|
String locale = Settings.LOCALE.toString().toUpperCase();
|
||||||
Benchmark.start("Initializing locale");
|
Benchmark.start("Initializing locale");
|
||||||
|
@ -33,6 +33,14 @@ public class Theme implements SubSystem {
|
|||||||
return themeSystem;
|
return themeSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getValue(ThemeVal variable) {
|
||||||
|
return getInstance().getThemeValue(variable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String replaceColors(String resourceString) {
|
||||||
|
return getInstance().replaceThemeColors(resourceString);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enable() throws EnableException {
|
public void enable() throws EnableException {
|
||||||
String themeName = Settings.THEME_BASE.toString();
|
String themeName = Settings.THEME_BASE.toString();
|
||||||
@ -95,12 +103,4 @@ public class Theme implements SubSystem {
|
|||||||
public String getThemeValue(ThemeVal color) {
|
public String getThemeValue(ThemeVal color) {
|
||||||
return config.getString(color.getThemePath());
|
return config.getString(color.getThemePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getValue(ThemeVal variable) {
|
|
||||||
return getInstance().getThemeValue(variable);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String replaceColors(String resourceString) {
|
|
||||||
return getInstance().replaceThemeColors(resourceString);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -44,6 +44,19 @@ public abstract class PlanSystem implements SubSystem {
|
|||||||
webServerSystem = new WebServerSystem();
|
webServerSystem = new WebServerSystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static PlanSystem getInstance() {
|
||||||
|
boolean bukkitAvailable = Check.isBukkitAvailable();
|
||||||
|
boolean bungeeAvailable = Check.isBungeeAvailable();
|
||||||
|
if (bukkitAvailable && bungeeAvailable) {
|
||||||
|
// TODO test system.
|
||||||
|
} else if (bungeeAvailable) {
|
||||||
|
return BungeeSystem.getInstance();
|
||||||
|
} else {
|
||||||
|
return BukkitSystem.getInstance();
|
||||||
|
}
|
||||||
|
throw new IllegalAccessError("PlanSystem is not available on this platform.");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enable() throws EnableException {
|
public void enable() throws EnableException {
|
||||||
checkSubSystemInitialization();
|
checkSubSystemInitialization();
|
||||||
@ -93,19 +106,6 @@ public abstract class PlanSystem implements SubSystem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlanSystem getInstance() {
|
|
||||||
boolean bukkitAvailable = Check.isBukkitAvailable();
|
|
||||||
boolean bungeeAvailable = Check.isBungeeAvailable();
|
|
||||||
if (bukkitAvailable && bungeeAvailable) {
|
|
||||||
// TODO test system.
|
|
||||||
} else if (bungeeAvailable) {
|
|
||||||
return BungeeSystem.getInstance();
|
|
||||||
} else {
|
|
||||||
return BukkitSystem.getInstance();
|
|
||||||
}
|
|
||||||
throw new IllegalAccessError("PlanSystem is not available on this platform.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Accessor methods.
|
// Accessor methods.
|
||||||
|
|
||||||
public ProcessingQueue getProcessingQueue() {
|
public ProcessingQueue getProcessingQueue() {
|
||||||
|
@ -4,8 +4,8 @@ import com.djrapitops.plan.Plan;
|
|||||||
import com.djrapitops.plan.data.container.Session;
|
import com.djrapitops.plan.data.container.Session;
|
||||||
import com.djrapitops.plan.system.processing.processors.info.NetworkPageUpdateProcessor;
|
import com.djrapitops.plan.system.processing.processors.info.NetworkPageUpdateProcessor;
|
||||||
import com.djrapitops.plan.system.processing.processors.player.*;
|
import com.djrapitops.plan.system.processing.processors.player.*;
|
||||||
import com.djrapitops.plan.systems.cache.DataCache;
|
|
||||||
import com.djrapitops.plan.system.tasks.TaskSystem;
|
import com.djrapitops.plan.system.tasks.TaskSystem;
|
||||||
|
import com.djrapitops.plan.systems.cache.DataCache;
|
||||||
import com.djrapitops.plan.utilities.MiscUtils;
|
import com.djrapitops.plan.utilities.MiscUtils;
|
||||||
import com.djrapitops.plugin.api.systems.NotificationCenter;
|
import com.djrapitops.plugin.api.systems.NotificationCenter;
|
||||||
import com.djrapitops.plugin.api.utility.log.Log;
|
import com.djrapitops.plugin.api.utility.log.Log;
|
||||||
@ -43,6 +43,10 @@ public class PlayerOnlineListener implements Listener {
|
|||||||
cache = plugin.getDataCache();
|
cache = plugin.getDataCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setCountKicks(boolean value) {
|
||||||
|
countKicks = value;
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
public void onPlayerLogin(PlayerLoginEvent event) {
|
||||||
try {
|
try {
|
||||||
@ -147,8 +151,4 @@ public class PlayerOnlineListener implements Listener {
|
|||||||
Log.toLog(this.getClass(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setCountKicks(boolean value) {
|
|
||||||
countKicks = value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,13 @@ public abstract class Processor<T> {
|
|||||||
this.object = object;
|
this.object = object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void queue(Processor... processors) {
|
||||||
|
ProcessingQueue processingQueue = ProcessingQueue.getInstance();
|
||||||
|
for (Processor processor : processors) {
|
||||||
|
processingQueue.queue(processor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void process();
|
public abstract void process();
|
||||||
|
|
||||||
public T getObject() {
|
public T getObject() {
|
||||||
@ -27,11 +34,4 @@ public abstract class Processor<T> {
|
|||||||
public void queue() {
|
public void queue() {
|
||||||
queue(this);
|
queue(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void queue(Processor... processors) {
|
|
||||||
ProcessingQueue processingQueue = ProcessingQueue.getInstance();
|
|
||||||
for (Processor processor : processors) {
|
|
||||||
processingQueue.queue(processor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -101,6 +101,14 @@ public enum Settings {
|
|||||||
this.configPath = path;
|
this.configPath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ServerSpecificSettings serverSpecific() {
|
||||||
|
if (!Check.isBungeeAvailable()) {
|
||||||
|
throw new IllegalStateException("Not supposed to call this method on Bukkit");
|
||||||
|
}
|
||||||
|
|
||||||
|
return serverSpecificSettings;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the settings is a boolean, this method should be used.
|
* If the settings is a boolean, this method should be used.
|
||||||
*
|
*
|
||||||
@ -157,12 +165,4 @@ public enum Settings {
|
|||||||
private Config getConfig() {
|
private Config getConfig() {
|
||||||
return ConfigSystem.getInstance().getConfig();
|
return ConfigSystem.getInstance().getConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ServerSpecificSettings serverSpecific() {
|
|
||||||
if (!Check.isBungeeAvailable()) {
|
|
||||||
throw new IllegalStateException("Not supposed to call this method on Bukkit");
|
|
||||||
}
|
|
||||||
|
|
||||||
return serverSpecificSettings;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,8 @@ import com.djrapitops.plugin.task.ITask;
|
|||||||
*/
|
*/
|
||||||
public class BukkitTaskSystem extends TaskSystem {
|
public class BukkitTaskSystem extends TaskSystem {
|
||||||
|
|
||||||
|
private ITask bootAnalysisTask;
|
||||||
|
|
||||||
public BukkitTaskSystem(Plan plugin) {
|
public BukkitTaskSystem(Plan plugin) {
|
||||||
tpsCountTimer = Check.isPaperAvailable()
|
tpsCountTimer = Check.isPaperAvailable()
|
||||||
? new PaperTPSCountTimer(plugin)
|
? new PaperTPSCountTimer(plugin)
|
||||||
@ -29,8 +31,6 @@ public class BukkitTaskSystem extends TaskSystem {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ITask bootAnalysisTask;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enable() {
|
public void enable() {
|
||||||
registerTasks();
|
registerTasks();
|
||||||
|
@ -34,6 +34,10 @@ public class VersionCheckSystem implements SubSystem {
|
|||||||
return versionCheckSystem;
|
return versionCheckSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isNewVersionAvailable() {
|
||||||
|
return getInstance().newVersionAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enable() {
|
public void enable() {
|
||||||
checkForNewVersion();
|
checkForNewVersion();
|
||||||
@ -63,8 +67,4 @@ public class VersionCheckSystem implements SubSystem {
|
|||||||
public void disable() {
|
public void disable() {
|
||||||
/* Does not need to be closed */
|
/* Does not need to be closed */
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isNewVersionAvailable() {
|
|
||||||
return getInstance().newVersionAvailable;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -18,11 +18,10 @@ import java.util.Optional;
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class Request {
|
public class Request {
|
||||||
private Authentication auth;
|
|
||||||
private final String requestMethod;
|
private final String requestMethod;
|
||||||
private final String target;
|
private final String target;
|
||||||
|
|
||||||
private final HttpExchange exchange;
|
private final HttpExchange exchange;
|
||||||
|
private Authentication auth;
|
||||||
|
|
||||||
public Request(HttpExchange exchange) {
|
public Request(HttpExchange exchange) {
|
||||||
this.requestMethod = exchange.getRequestMethod();
|
this.requestMethod = exchange.getRequestMethod();
|
||||||
|
@ -27,6 +27,11 @@ public class WebServerSystem implements SubSystem {
|
|||||||
return PlanSystem.getInstance().getWebServerSystem();
|
return PlanSystem.getInstance().getWebServerSystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isWebServerEnabled() {
|
||||||
|
WebServer webServer = getInstance().webServer;
|
||||||
|
return webServer != null && webServer.isEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enable() throws EnableException {
|
public void enable() throws EnableException {
|
||||||
webServer.initServer();
|
webServer.initServer();
|
||||||
@ -44,11 +49,6 @@ public class WebServerSystem implements SubSystem {
|
|||||||
webServer.stop();
|
webServer.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isWebServerEnabled() {
|
|
||||||
WebServer webServer = getInstance().webServer;
|
|
||||||
return webServer != null && webServer.isEnabled();
|
|
||||||
}
|
|
||||||
|
|
||||||
public WebServer getWebServer() {
|
public WebServer getWebServer() {
|
||||||
return webServer;
|
return webServer;
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,10 @@ public abstract class Response {
|
|||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setHeader(String header) {
|
||||||
|
this.header = header;
|
||||||
|
}
|
||||||
|
|
||||||
public String getResponse() {
|
public String getResponse() {
|
||||||
return header + "\r\n"
|
return header + "\r\n"
|
||||||
+ "Content-Type: " + type + ";\r\n"
|
+ "Content-Type: " + type + ";\r\n"
|
||||||
@ -51,10 +55,6 @@ public abstract class Response {
|
|||||||
this.content = content;
|
this.content = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHeader(String header) {
|
|
||||||
this.header = header;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCode() {
|
public int getCode() {
|
||||||
return header == null ? 500 : Integer.parseInt(header.split(" ")[1]);
|
return header == null ? 500 : Integer.parseInt(header.split(" ")[1]);
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,10 @@ public class InspectPageResponse extends Response {
|
|||||||
super.setContent(response.getContent());
|
super.setContent(response.getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static InspectPageResponse copyOf(InspectPageResponse response) {
|
||||||
|
return new InspectPageResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
public void setInspectPagePluginsTab(String[] inspectPagePluginsTab) {
|
public void setInspectPagePluginsTab(String[] inspectPagePluginsTab) {
|
||||||
Map<String, String> replaceMap = new HashMap<>();
|
Map<String, String> replaceMap = new HashMap<>();
|
||||||
replaceMap.put("navPluginsTabs", inspectPagePluginsTab[0]);
|
replaceMap.put("navPluginsTabs", inspectPagePluginsTab[0]);
|
||||||
@ -45,8 +49,4 @@ public class InspectPageResponse extends Response {
|
|||||||
|
|
||||||
setContent(StrSubstitutor.replace(getContent(), replaceMap));
|
setContent(StrSubstitutor.replace(getContent(), replaceMap));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static InspectPageResponse copyOf(InspectPageResponse response) {
|
|
||||||
return new InspectPageResponse(response);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -35,12 +35,36 @@ import java.util.stream.Collectors;
|
|||||||
*/
|
*/
|
||||||
public abstract class WebAPI {
|
public abstract class WebAPI {
|
||||||
|
|
||||||
|
private static TrustManager[] trustAllCerts = new TrustManager[]{
|
||||||
|
new X509TrustManager() {
|
||||||
|
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
|
||||||
|
//No need to implement.
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
|
||||||
|
//No need to implement.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
private Map<String, String> variables;
|
private Map<String, String> variables;
|
||||||
|
|
||||||
|
|
||||||
public WebAPI() {
|
public WebAPI() {
|
||||||
this.variables = new HashMap<>();
|
this.variables = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> readVariables(String requestBody) {
|
||||||
|
String[] variables = requestBody.split(";&variable;");
|
||||||
|
|
||||||
|
return Arrays.stream(variables)
|
||||||
|
.map(variable -> variable.split("=", 2))
|
||||||
|
.filter(splitVariables -> splitVariables.length == 2)
|
||||||
|
.collect(Collectors.toMap(splitVariables -> splitVariables[0], splitVariables -> splitVariables[1], (a, b) -> b));
|
||||||
|
}
|
||||||
|
|
||||||
public Response processRequest(PlanPlugin plugin, Map<String, String> variables) {
|
public Response processRequest(PlanPlugin plugin, Map<String, String> variables) {
|
||||||
String sender = variables.get("sender");
|
String sender = variables.get("sender");
|
||||||
@ -149,22 +173,6 @@ public abstract class WebAPI {
|
|||||||
return sc.getSocketFactory();
|
return sc.getSocketFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TrustManager[] trustAllCerts = new TrustManager[]{
|
|
||||||
new X509TrustManager() {
|
|
||||||
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
|
|
||||||
//No need to implement.
|
|
||||||
}
|
|
||||||
|
|
||||||
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
|
|
||||||
//No need to implement.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
protected Response success() {
|
protected Response success() {
|
||||||
return ResponseCache.loadResponse(PageId.TRUE.id(), SuccessResponse::new);
|
return ResponseCache.loadResponse(PageId.TRUE.id(), SuccessResponse::new);
|
||||||
}
|
}
|
||||||
@ -190,13 +198,4 @@ public abstract class WebAPI {
|
|||||||
}
|
}
|
||||||
return parameters.toString();
|
return parameters.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, String> readVariables(String requestBody) {
|
|
||||||
String[] variables = requestBody.split(";&variable;");
|
|
||||||
|
|
||||||
return Arrays.stream(variables)
|
|
||||||
.map(variable -> variable.split("=", 2))
|
|
||||||
.filter(splitVariables -> splitVariables.length == 2)
|
|
||||||
.collect(Collectors.toMap(splitVariables -> splitVariables[0], splitVariables -> splitVariables[1], (a, b) -> b));
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -15,8 +15,8 @@ import java.util.*;
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public class WebAPIManager extends TreePageHandler {
|
public class WebAPIManager extends TreePageHandler {
|
||||||
|
|
||||||
private final Map<String, WebAPI> registry;
|
|
||||||
private static final Set<String> accessKeys = new HashSet<>();
|
private static final Set<String> accessKeys = new HashSet<>();
|
||||||
|
private final Map<String, WebAPI> registry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor used to hide the public constructor
|
* Constructor used to hide the public constructor
|
||||||
|
@ -30,9 +30,8 @@ import java.util.zip.GZIPInputStream;
|
|||||||
*/
|
*/
|
||||||
public class GeolocationCache {
|
public class GeolocationCache {
|
||||||
|
|
||||||
private static File geolocationDB = new File(PlanPlugin.getInstance().getDataFolder(), "GeoIP.dat");
|
|
||||||
|
|
||||||
private static final Map<String, String> geolocationCache = new HashMap<>();
|
private static final Map<String, String> geolocationCache = new HashMap<>();
|
||||||
|
private static File geolocationDB = new File(PlanPlugin.getInstance().getDataFolder(), "GeoIP.dat");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor used to hide the public constructor
|
* Constructor used to hide the public constructor
|
||||||
|
@ -31,6 +31,21 @@ public class SessionCache {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to get the Map of active sessions.
|
||||||
|
* <p>
|
||||||
|
* Used for testing.
|
||||||
|
*
|
||||||
|
* @return key:value UUID:Session
|
||||||
|
*/
|
||||||
|
public static Map<UUID, Session> getActiveSessions() {
|
||||||
|
return activeSessions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clear() {
|
||||||
|
activeSessions.clear();
|
||||||
|
}
|
||||||
|
|
||||||
public void cacheSession(UUID uuid, Session session) {
|
public void cacheSession(UUID uuid, Session session) {
|
||||||
activeSessions.put(uuid, session);
|
activeSessions.put(uuid, session);
|
||||||
plugin.addToProcessQueue(new Processor<Plan>(plugin) {
|
plugin.addToProcessQueue(new Processor<Plan>(plugin) {
|
||||||
@ -76,19 +91,4 @@ public class SessionCache {
|
|||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to get the Map of active sessions.
|
|
||||||
* <p>
|
|
||||||
* Used for testing.
|
|
||||||
*
|
|
||||||
* @return key:value UUID:Session
|
|
||||||
*/
|
|
||||||
public static Map<UUID, Session> getActiveSessions() {
|
|
||||||
return activeSessions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void clear() {
|
|
||||||
activeSessions.clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -62,13 +62,11 @@ public class BukkitInformationManager extends InformationManager {
|
|||||||
private final Plan plugin;
|
private final Plan plugin;
|
||||||
private final DataCache dataCache;
|
private final DataCache dataCache;
|
||||||
private final Analysis analysis;
|
private final Analysis analysis;
|
||||||
|
private final Map<UUID, String[]> pluginsTabContents;
|
||||||
private AnalysisData analysisData;
|
private AnalysisData analysisData;
|
||||||
private String analysisPluginsTab;
|
private String analysisPluginsTab;
|
||||||
private Long refreshDate;
|
private Long refreshDate;
|
||||||
|
|
||||||
private final Map<UUID, String[]> pluginsTabContents;
|
|
||||||
|
|
||||||
public BukkitInformationManager(Plan plugin) {
|
public BukkitInformationManager(Plan plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
dataCache = new DataCache(plugin);
|
dataCache = new DataCache(plugin);
|
||||||
|
@ -48,11 +48,10 @@ import java.util.stream.Collectors;
|
|||||||
public class BungeeInformationManager extends InformationManager {
|
public class BungeeInformationManager extends InformationManager {
|
||||||
|
|
||||||
private final PlanBungee plugin;
|
private final PlanBungee plugin;
|
||||||
private Map<UUID, ServerInfo> bukkitServers;
|
|
||||||
|
|
||||||
private final Map<UUID, String> networkPageContent;
|
private final Map<UUID, String> networkPageContent;
|
||||||
private final Map<UUID, Map<UUID, String[]>> pluginsTabContent;
|
private final Map<UUID, Map<UUID, String[]>> pluginsTabContent;
|
||||||
private final BungeeServerInfoManager serverInfoManager;
|
private final BungeeServerInfoManager serverInfoManager;
|
||||||
|
private Map<UUID, ServerInfo> bukkitServers;
|
||||||
|
|
||||||
public BungeeInformationManager(PlanBungee plugin) {
|
public BungeeInformationManager(PlanBungee plugin) {
|
||||||
usingAnotherWebServer = false;
|
usingAnotherWebServer = false;
|
||||||
|
@ -29,9 +29,9 @@ import java.util.UUID;
|
|||||||
public class BukkitServerInfoManager {
|
public class BukkitServerInfoManager {
|
||||||
|
|
||||||
private final Plan plugin;
|
private final Plan plugin;
|
||||||
|
private final ServerTable serverTable;
|
||||||
private ServerInfo serverInfo;
|
private ServerInfo serverInfo;
|
||||||
private ServerInfoFile serverInfoFile;
|
private ServerInfoFile serverInfoFile;
|
||||||
private final ServerTable serverTable;
|
|
||||||
|
|
||||||
public BukkitServerInfoManager(Plan plugin) throws EnableException {
|
public BukkitServerInfoManager(Plan plugin) throws EnableException {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
@ -30,11 +30,10 @@ import java.util.stream.Collectors;
|
|||||||
public class BungeeServerInfoManager {
|
public class BungeeServerInfoManager {
|
||||||
|
|
||||||
private final PlanBungee plugin;
|
private final PlanBungee plugin;
|
||||||
private ServerInfo serverInfo;
|
|
||||||
private final Database db;
|
private final Database db;
|
||||||
|
|
||||||
private final Map<UUID, ServerInfo> bukkitServers;
|
private final Map<UUID, ServerInfo> bukkitServers;
|
||||||
private final Set<UUID> onlineServers;
|
private final Set<UUID> onlineServers;
|
||||||
|
private ServerInfo serverInfo;
|
||||||
private ServerTable serverTable;
|
private ServerTable serverTable;
|
||||||
|
|
||||||
public BungeeServerInfoManager(PlanBungee plugin) {
|
public BungeeServerInfoManager(PlanBungee plugin) {
|
||||||
|
@ -33,9 +33,9 @@ import java.util.stream.Collectors;
|
|||||||
*/
|
*/
|
||||||
public class Analysis {
|
public class Analysis {
|
||||||
|
|
||||||
|
private static ServerProfile serverProfile;
|
||||||
private final Plan plugin;
|
private final Plan plugin;
|
||||||
private int taskId = -1;
|
private int taskId = -1;
|
||||||
private static ServerProfile serverProfile;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Constructor.
|
* Class Constructor.
|
||||||
@ -46,6 +46,15 @@ public class Analysis {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only available during Analysis.
|
||||||
|
*
|
||||||
|
* @return ServerProfile being analyzed or null if analysis is not being run.
|
||||||
|
*/
|
||||||
|
public static ServerProfile getServerProfile() {
|
||||||
|
return serverProfile;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Analyzes the data of all offline players on the server.
|
* Analyzes the data of all offline players on the server.
|
||||||
*
|
*
|
||||||
@ -221,13 +230,4 @@ public class Analysis {
|
|||||||
public boolean isAnalysisBeingRun() {
|
public boolean isAnalysisBeingRun() {
|
||||||
return taskId != -1;
|
return taskId != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Only available during Analysis.
|
|
||||||
*
|
|
||||||
* @return ServerProfile being analyzed or null if analysis is not being run.
|
|
||||||
*/
|
|
||||||
public static ServerProfile getServerProfile() {
|
|
||||||
return serverProfile;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user