Rearranged code

This commit is contained in:
Rsl1122 2018-01-15 20:17:39 +02:00
parent 9bbe4b27b2
commit 47f061edcb
32 changed files with 366 additions and 374 deletions

View File

@ -52,6 +52,14 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
@Deprecated
private boolean setupAllowed = false;
public static PlanBungee getInstance() {
return (PlanBungee) StaticHolder.getInstance(PlanBungee.class);
}
public static UUID getServerUUID() {
return getInstance().getServerUuid();
}
@Override
public void onEnable() {
super.onEnable();
@ -99,10 +107,6 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
registerCommand("planbungee", new PlanBungeeCommand(this));
}
public static PlanBungee getInstance() {
return (PlanBungee) StaticHolder.getInstance(PlanBungee.class);
}
@Override
public void onDisable() {
system.disable();
@ -163,10 +167,6 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
return variableHolder;
}
public static UUID getServerUUID() {
return getInstance().getServerUuid();
}
public UUID getServerUuid() {
return serverInfoManager.getServerUUID();
}

View File

@ -24,6 +24,19 @@ import java.util.UUID;
* @author Rsl1122
*/
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
Database getDB();
@ -55,17 +68,4 @@ public interface PlanPlugin extends IPlugin {
ColorScheme getColorScheme();
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");
}
}

View File

@ -77,7 +77,7 @@ public class InspectCommand extends SubCommand {
}
if (CommandUtils.isPlayer(sender) && plugin.getWebServer().isAuthRequired()) {
boolean senderHasWebUser = activeDB.check().doesWebUserExists(sender.getName());
if (!senderHasWebUser) {
sender.sendMessage(ChatColor.YELLOW + "[Plan] You might not have a web user, use /plan register <password>");
}

View File

@ -79,6 +79,57 @@ public class PlayerProfile implements OfflinePlayer {
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
public ActivityIndex getActivityIndex(long date) {
ActivityIndex index = activityIndexCache.get(date);
@ -98,6 +149,10 @@ public class PlayerProfile implements OfflinePlayer {
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.
*
@ -151,12 +206,6 @@ public class PlayerProfile implements OfflinePlayer {
return getPlaytime(getSessions(serverUUID).stream());
}
public static long getPlaytime(Stream<Session> s) {
return s.map(Session::getLength)
.mapToLong(i -> i)
.sum();
}
public long getLongestSession() {
return getLongestSession(-1, MiscUtils.getTime() + 1L);
}
@ -169,16 +218,6 @@ public class PlayerProfile implements OfflinePlayer {
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() {
return getSessionMedian(-1, MiscUtils.getTime() + 1L);
}
@ -191,15 +230,7 @@ public class PlayerProfile implements OfflinePlayer {
return getSessionMedian(getSessions(serverUUID).stream());
}
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);
}
// Special Getters
public long getSessionAverage() {
return getSessionAverage(-1, MiscUtils.getTime() + 1L);
@ -213,22 +244,10 @@ public class PlayerProfile implements OfflinePlayer {
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) {
return getSessions(after, before).findFirst().isPresent();
}
// Special Getters
public Stream<Session> getAllSessions() {
return sessions.values().stream().flatMap(Collection::stream);
}
@ -261,11 +280,6 @@ public class PlayerProfile implements OfflinePlayer {
return getPlayerKills(getSessions(serverUUID).stream());
}
public static Stream<PlayerKill> getPlayerKills(Stream<Session> s) {
return s.map(Session::getPlayerKills)
.flatMap(Collection::stream);
}
public long getPlayerKillCount() {
return getPlayerKills().count();
}
@ -282,11 +296,6 @@ public class PlayerProfile implements OfflinePlayer {
return getDeathCount(getSessions(serverUUID).stream());
}
public static long getDeathCount(Stream<Session> s) {
return s.mapToLong(Session::getDeaths)
.sum();
}
public long getMobKillCount() {
return getMobKillCount(getAllSessions());
}
@ -295,11 +304,6 @@ public class PlayerProfile implements OfflinePlayer {
return getMobKillCount(getSessions(serverUUID).stream());
}
public static long getMobKillCount(Stream<Session> s) {
return s.mapToLong(Session::getMobKills)
.sum();
}
public long getSessionCount() {
return getAllSessions().count();
}
@ -308,12 +312,12 @@ public class PlayerProfile implements OfflinePlayer {
return getSessions(serverUUID).size();
}
// Setters & Adders
public long getRegistered(UUID serverUUID) {
return registeredMap.getOrDefault(serverUUID, -1L);
}
// Setters & Adders
public void bannedOnServer(UUID serverUUID) {
bannedOnServers.add(serverUUID);
}
@ -334,10 +338,6 @@ public class PlayerProfile implements OfflinePlayer {
this.sessions.put(serverUUID, sessions);
}
public void setSessions(Map<UUID, List<Session>> sessions) {
this.sessions.putAll(sessions);
}
public void addActiveSession(Session activeSession) {
UUID serverUUID = PlanPlugin.getInstance().getServerUuid();
List<Session> sessions = getSessions(serverUUID);
@ -357,10 +357,6 @@ public class PlayerProfile implements OfflinePlayer {
worldTimesMap.put(serverUUID, worldTimes);
}
public void setWorldTimes(Map<UUID, WorldTimes> worldTimes) {
worldTimesMap.putAll(worldTimes);
}
public void setTotalWorldTimes(WorldTimes worldTimes) {
worldTimesMap.put(null, worldTimes);
}
@ -369,38 +365,34 @@ public class PlayerProfile implements OfflinePlayer {
registeredMap.put(serverUUID, registered);
}
public int getTimesKicked() {
return timesKicked;
}
// 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) {
this.timesKicked = timesKicked;
}
// Default Getters
public int getTimesKicked() {
return timesKicked;
}
public Map<UUID, List<String>> getNicknames() {
return nicknames;
}
public void setNicknames(Map<UUID, List<String>> nicknames) {
this.nicknames = nicknames;
}
public List<GeoInfo> getGeoInformation() {
return geoInformation;
}
// Default Getters
public void setGeoInformation(List<GeoInfo> geoInformation) {
this.geoInformation = geoInformation;
}
public UUID getUuid() {
return uuid;
}
@ -425,10 +417,18 @@ public class PlayerProfile implements OfflinePlayer {
return sessions;
}
public void setSessions(Map<UUID, List<Session>> sessions) {
this.sessions.putAll(sessions);
}
public List<Action> getActions() {
return actions;
}
public void setActions(List<Action> actions) {
this.actions = actions;
}
public Map<String, String> getPluginReplaceMap() {
return pluginReplaceMap;
}

View File

@ -64,6 +64,125 @@ public class ServerProfile {
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() {
return players;
}
@ -88,27 +207,6 @@ public class ServerProfile {
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) {
OptionalDouble average = getTPSData(after, before)
.mapToDouble(TPS::getTicksPerSecond)
@ -200,6 +298,8 @@ public class ServerProfile {
.collect(Collectors.toList());
}
// Default setters & getters
public long getTotalPlaytime() {
return serverWorldtimes.getTotal();
}
@ -220,32 +320,6 @@ public class ServerProfile {
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() {
return serverWorldtimes;
}
@ -286,18 +360,6 @@ public class ServerProfile {
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() {
return players.stream().filter(PlayerProfile::isOp);
}
@ -316,74 +378,12 @@ public class ServerProfile {
.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) {
return serverIdleTime(getTPSData(after, before)
.sorted(new TPSComparator())
.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) {
if (playerMap == null) {
playerMap = players.stream().collect(Collectors.toMap(PlayerProfile::getUuid, Function.identity()));

View File

@ -11,16 +11,16 @@ import java.util.stream.Collectors;
public class ActivityIndex {
private static long loadSetting(long value) {
return value < 0 ? 1 : value;
}
private final double value;
public ActivityIndex(PlayerProfile player, long date) {
value = calculate(player, date);
}
private static long loadSetting(long value) {
return value < 0 ? 1 : value;
}
private double calculate(PlayerProfile player, long date) {
long week = TimeAmount.WEEK.ms();
long weekAgo = date - week;

View File

@ -26,13 +26,12 @@ import java.util.stream.Collectors;
public class HealthNotes {
private final List<String> healthNotes;
private double serverHealth;
private final AnalysisData analysisData;
private final TreeMap<Long, Map<String, Set<UUID>>> activityData;
private final List<TPS> tpsDataMonth;
private final long now;
private final long fourWeeksAgo;
private double serverHealth;
public HealthNotes(AnalysisData analysisData, TreeMap<Long, Map<String, Set<UUID>>> activityData, List<TPS> tpsDataMonth, long now) {
this.healthNotes = new ArrayList<>();

View File

@ -25,21 +25,6 @@ import java.util.UUID;
*/
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) {
Log.debug("Checking new settings..");
Config config = plugin.getMainConfig();
@ -92,6 +77,21 @@ public class ServerSpecificSettings {
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) {
String path = "Servers." + serverUUID;
switch (setting) {

View File

@ -44,10 +44,6 @@ public class Locale {
messages = new EnumMap<>(Msg.class);
}
public void unload() {
messages.clear();
}
public static Locale getInstance() {
Locale locale = ConfigSystem.getInstance().getLocale();
NullCheck.check(locale, new IllegalStateException("Locale has not been initialized."));
@ -58,6 +54,10 @@ public class Locale {
return getInstance().getMessage(msg);
}
public void unload() {
messages.clear();
}
public void loadLocale() {
String locale = Settings.LOCALE.toString().toUpperCase();
Benchmark.start("Initializing locale");

View File

@ -33,6 +33,14 @@ public class Theme implements SubSystem {
return themeSystem;
}
public static String getValue(ThemeVal variable) {
return getInstance().getThemeValue(variable);
}
public static String replaceColors(String resourceString) {
return getInstance().replaceThemeColors(resourceString);
}
@Override
public void enable() throws EnableException {
String themeName = Settings.THEME_BASE.toString();
@ -95,12 +103,4 @@ public class Theme implements SubSystem {
public String getThemeValue(ThemeVal color) {
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);
}
}

View File

@ -44,6 +44,19 @@ public abstract class PlanSystem implements SubSystem {
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
public void enable() throws EnableException {
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.
public ProcessingQueue getProcessingQueue() {

View File

@ -13,7 +13,7 @@ import com.djrapitops.plan.system.database.databases.sql.MySQLDB;
* @author Rsl1122
*/
public class BungeeDBSystem extends DBSystem {
@Override
protected void initDatabase() throws DBInitException {
db = new MySQLDB();

View File

@ -12,7 +12,7 @@ public abstract class ListenerSystem implements SubSystem {
NullCheck.check(listenerSystem, new IllegalStateException("Listener system was not initialized."));
return listenerSystem;
}
@Override
public void enable() {
Benchmark.start("Register Listeners");

View File

@ -4,8 +4,8 @@ import com.djrapitops.plan.Plan;
import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.system.processing.processors.info.NetworkPageUpdateProcessor;
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.systems.cache.DataCache;
import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plugin.api.systems.NotificationCenter;
import com.djrapitops.plugin.api.utility.log.Log;
@ -43,6 +43,10 @@ public class PlayerOnlineListener implements Listener {
cache = plugin.getDataCache();
}
public static void setCountKicks(boolean value) {
countKicks = value;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerLogin(PlayerLoginEvent event) {
try {
@ -147,8 +151,4 @@ public class PlayerOnlineListener implements Listener {
Log.toLog(this.getClass(), e);
}
}
public static void setCountKicks(boolean value) {
countKicks = value;
}
}

View File

@ -18,6 +18,13 @@ public abstract class Processor<T> {
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 T getObject() {
@ -27,11 +34,4 @@ public abstract class Processor<T> {
public void queue() {
queue(this);
}
public static void queue(Processor... processors) {
ProcessingQueue processingQueue = ProcessingQueue.getInstance();
for (Processor processor : processors) {
processingQueue.queue(processor);
}
}
}

View File

@ -101,6 +101,14 @@ public enum Settings {
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.
*
@ -157,12 +165,4 @@ public enum Settings {
private Config 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;
}
}

View File

@ -22,6 +22,8 @@ import com.djrapitops.plugin.task.ITask;
*/
public class BukkitTaskSystem extends TaskSystem {
private ITask bootAnalysisTask;
public BukkitTaskSystem(Plan plugin) {
tpsCountTimer = Check.isPaperAvailable()
? new PaperTPSCountTimer(plugin)
@ -29,8 +31,6 @@ public class BukkitTaskSystem extends TaskSystem {
}
private ITask bootAnalysisTask;
@Override
public void enable() {
registerTasks();

View File

@ -34,7 +34,7 @@ public abstract class TPSCountTimer<T extends PlanPlugin> extends AbsRunnable {
long now = MiscUtils.getTime();
addNewTPSEntry(nanoTime, now);
if (history.size() >= 60) {
plugin.addToProcessQueue(new TPSInsertProcessor(new ArrayList<>(history)));
history.clear();

View File

@ -34,6 +34,10 @@ public class VersionCheckSystem implements SubSystem {
return versionCheckSystem;
}
public static boolean isNewVersionAvailable() {
return getInstance().newVersionAvailable;
}
@Override
public void enable() {
checkForNewVersion();
@ -63,8 +67,4 @@ public class VersionCheckSystem implements SubSystem {
public void disable() {
/* Does not need to be closed */
}
public static boolean isNewVersionAvailable() {
return getInstance().newVersionAvailable;
}
}

View File

@ -18,11 +18,10 @@ import java.util.Optional;
* @author Rsl1122
*/
public class Request {
private Authentication auth;
private final String requestMethod;
private final String target;
private final HttpExchange exchange;
private Authentication auth;
public Request(HttpExchange exchange) {
this.requestMethod = exchange.getRequestMethod();

View File

@ -27,6 +27,11 @@ public class WebServerSystem implements SubSystem {
return PlanSystem.getInstance().getWebServerSystem();
}
public static boolean isWebServerEnabled() {
WebServer webServer = getInstance().webServer;
return webServer != null && webServer.isEnabled();
}
@Override
public void enable() throws EnableException {
webServer.initServer();
@ -44,11 +49,6 @@ public class WebServerSystem implements SubSystem {
webServer.stop();
}
public static boolean isWebServerEnabled() {
WebServer webServer = getInstance().webServer;
return webServer != null && webServer.isEnabled();
}
public WebServer getWebServer() {
return webServer;
}

View File

@ -35,6 +35,10 @@ public abstract class Response {
return header;
}
public void setHeader(String header) {
this.header = header;
}
public String getResponse() {
return header + "\r\n"
+ "Content-Type: " + type + ";\r\n"
@ -51,10 +55,6 @@ public abstract class Response {
this.content = content;
}
public void setHeader(String header) {
this.header = header;
}
public int getCode() {
return header == null ? 500 : Integer.parseInt(header.split(" ")[1]);
}

View File

@ -38,6 +38,10 @@ public class InspectPageResponse extends Response {
super.setContent(response.getContent());
}
public static InspectPageResponse copyOf(InspectPageResponse response) {
return new InspectPageResponse(response);
}
public void setInspectPagePluginsTab(String[] inspectPagePluginsTab) {
Map<String, String> replaceMap = new HashMap<>();
replaceMap.put("navPluginsTabs", inspectPagePluginsTab[0]);
@ -45,8 +49,4 @@ public class InspectPageResponse extends Response {
setContent(StrSubstitutor.replace(getContent(), replaceMap));
}
public static InspectPageResponse copyOf(InspectPageResponse response) {
return new InspectPageResponse(response);
}
}

View File

@ -35,12 +35,36 @@ import java.util.stream.Collectors;
*/
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;
public WebAPI() {
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) {
String sender = variables.get("sender");
@ -149,22 +173,6 @@ public abstract class WebAPI {
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() {
return ResponseCache.loadResponse(PageId.TRUE.id(), SuccessResponse::new);
}
@ -190,13 +198,4 @@ public abstract class WebAPI {
}
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));
}
}

View File

@ -15,8 +15,8 @@ import java.util.*;
@Deprecated
public class WebAPIManager extends TreePageHandler {
private final Map<String, WebAPI> registry;
private static final Set<String> accessKeys = new HashSet<>();
private final Map<String, WebAPI> registry;
/**
* Constructor used to hide the public constructor

View File

@ -30,9 +30,8 @@ import java.util.zip.GZIPInputStream;
*/
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 File geolocationDB = new File(PlanPlugin.getInstance().getDataFolder(), "GeoIP.dat");
/**
* Constructor used to hide the public constructor

View File

@ -31,6 +31,21 @@ public class SessionCache {
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) {
activeSessions.put(uuid, session);
plugin.addToProcessQueue(new Processor<Plan>(plugin) {
@ -76,19 +91,4 @@ public class SessionCache {
}
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();
}
}

View File

@ -62,13 +62,11 @@ public class BukkitInformationManager extends InformationManager {
private final Plan plugin;
private final DataCache dataCache;
private final Analysis analysis;
private final Map<UUID, String[]> pluginsTabContents;
private AnalysisData analysisData;
private String analysisPluginsTab;
private Long refreshDate;
private final Map<UUID, String[]> pluginsTabContents;
public BukkitInformationManager(Plan plugin) {
this.plugin = plugin;
dataCache = new DataCache(plugin);

View File

@ -48,11 +48,10 @@ import java.util.stream.Collectors;
public class BungeeInformationManager extends InformationManager {
private final PlanBungee plugin;
private Map<UUID, ServerInfo> bukkitServers;
private final Map<UUID, String> networkPageContent;
private final Map<UUID, Map<UUID, String[]>> pluginsTabContent;
private final BungeeServerInfoManager serverInfoManager;
private Map<UUID, ServerInfo> bukkitServers;
public BungeeInformationManager(PlanBungee plugin) {
usingAnotherWebServer = false;

View File

@ -29,9 +29,9 @@ import java.util.UUID;
public class BukkitServerInfoManager {
private final Plan plugin;
private final ServerTable serverTable;
private ServerInfo serverInfo;
private ServerInfoFile serverInfoFile;
private final ServerTable serverTable;
public BukkitServerInfoManager(Plan plugin) throws EnableException {
this.plugin = plugin;

View File

@ -30,11 +30,10 @@ import java.util.stream.Collectors;
public class BungeeServerInfoManager {
private final PlanBungee plugin;
private ServerInfo serverInfo;
private final Database db;
private final Map<UUID, ServerInfo> bukkitServers;
private final Set<UUID> onlineServers;
private ServerInfo serverInfo;
private ServerTable serverTable;
public BungeeServerInfoManager(PlanBungee plugin) {

View File

@ -33,9 +33,9 @@ import java.util.stream.Collectors;
*/
public class Analysis {
private static ServerProfile serverProfile;
private final Plan plugin;
private int taskId = -1;
private static ServerProfile serverProfile;
/**
* Class Constructor.
@ -46,6 +46,15 @@ public class Analysis {
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.
*
@ -221,13 +230,4 @@ public class Analysis {
public boolean isAnalysisBeingRun() {
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;
}
}