First Release Candidate [2.0.0]

Fixed bugs:
- Demographics data properly detected.
- MapComparator now compares values as integers.
- ServerData is now saved properly, and playersOnline is updated
properly.

Other:
- Graph is untested
- MySQL untested
This commit is contained in:
Rsl1122 2017-01-16 17:47:27 +02:00
parent 5108213df6
commit e8acdc678a
13 changed files with 176 additions and 139 deletions

View File

@ -3,7 +3,6 @@ package com.djrapitops.plan;
import com.djrapitops.plan.command.PlanCommand;
import com.djrapitops.plan.api.API;
import com.djrapitops.plan.data.cache.AnalysisCacheHandler;
import com.djrapitops.planlite.api.Hook;
import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plan.database.Database;
import com.djrapitops.plan.database.databases.MySQLDB;
@ -14,8 +13,6 @@ import com.djrapitops.plan.data.listeners.*;
import main.java.com.djrapitops.plan.ui.webserver.WebSocketServer;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.ArrayList;
import java.util.List;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
@ -219,4 +216,8 @@ public class Plan extends JavaPlugin {
public Database getDB() {
return db;
}
public WebSocketServer getUiServer() {
return uiServer;
}
}

View File

@ -2,8 +2,12 @@ package com.djrapitops.plan.api;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLiteHook;
import com.djrapitops.plan.data.AnalysisData;
import com.djrapitops.plan.data.UserData;
import com.djrapitops.plan.utilities.FormatUtils;
import com.djrapitops.planlite.UUIDFetcher;
import java.util.Date;
import java.util.UUID;
/**
*
@ -65,4 +69,81 @@ public class API {
public static String formatTimeStamp(String timeInMs) {
return FormatUtils.formatTimeStamp(timeInMs);
}
/**
* Uses UUIDFetcher to turn PlayerName to UUID
*
* @param playerName Player's name
* @return UUID of the Player
* @throws Exception if player's name is not registered at Mojang
*/
public UUID playerNameToUUID(String playerName) throws Exception {
return UUIDFetcher.getUUIDOf(playerName);
}
/**
* Caches the UserData to the InspectCache for time specified in the Plan
* config, so it can be called by webserver.
*
* Does not cache anything if the player has not joined the server or has no
* data in the database.
*
* @param uuid UUID of the Player
*/
public void cacheUserDataToInspectCache(UUID uuid) {
plugin.getInspectCache().cache(uuid);
}
/**
* Returns the ip:port/player/playername html as a string so it can be
* integrated into other webserver plugins.
*
* If UserData of the specified player is not in the Cache returns <h1>404
* Data was not found in cache</h1>
*
* @param uuid UUID of the Player
* @return html as a string or a single error line html.
*/
public String getPlayerHtmlAsString(UUID uuid) {
return plugin.getUiServer().getDataReqHandler().getDataHtml(uuid);
}
/**
* Updates the AnalysisCache so the cached data can be called by the
* webserver.
*/
public void updateAnalysisCache() {
plugin.getAnalysisCache().updateCache();
}
/**
* Returns the ip:port/server html as a string so it can be integrated into
* other webserver plugins.
*
* If AnalysisData is not in the AnalysisCache: returns <h1>404 Data was not
* found in cache</h1>
*
* @return html as a string or a single error line html.
*/
public String getAnalysisHtmlAsString() {
return plugin.getUiServer().getDataReqHandler().getAnalysisHtml();
}
/**
* Returns UserData from the InspectCache
*
* @param uuid UUID of the Player
* @return UserData of the Player in the InspectCache or null if not found
*/
public UserData getUserDataFromInspectCache(UUID uuid) {
return plugin.getInspectCache().getFromCache(uuid);
}
/**
* Returns AnalysisData from the AnalysisCache
* @return AnalysisData in the AnalysisCache or null if not found
*/
public AnalysisData getAnalysisDataFromCache() {
return plugin.getAnalysisCache().getData();
}
}

View File

@ -1,55 +0,0 @@
package com.djrapitops.plan.api;
/**
* Old API part.
*
* @author Rsl1122
* @deprecated Moved to PlanLite plugin
*/
@Deprecated
public class DataPoint {
private String data;
private final DataType type;
/**
*
* @param data
* @param type
* @deprecated Moved to PlanLite plugin
*/
@Deprecated
public DataPoint(String data, DataType type) {
this.data = data;
this.type = type;
}
/**
*
* @return @deprecated Moved to PlanLite plugin
*/
@Deprecated
public String data() {
return data;
}
/**
*
* @param data
* @deprecated Moved to PlanLite plugin
*/
@Deprecated
public void setData(String data) {
this.data = data;
}
/**
*
* @return @deprecated Moved to PlanLite plugin
*/
@Deprecated
public DataType type() {
return type;
}
}

View File

@ -1,26 +0,0 @@
package com.djrapitops.plan.api;
/**
* Old API Part.
*
* @author Rsl1122
* @deprecated Moved to PlanLite plugin
*/
@Deprecated
public enum DataType {
STRING, // Any preformatted data & words
TIME, // Long in milliseconds
TIME_TIMESTAMP, // Long in milliseconds since Epoch Date 1970, will be subtracted from current time.
DATE, // Long in milliseconds since Epoch Date 1970
LOCATION, // X:# Y:# Z:#
AMOUNT, // Number
AMOUNT_WITH_MAX, // Example: 41 / 44
AMOUNT_WITH_LETTERS, // Example $50
BOOLEAN, // true/false
PERCENT, // Example 50%
OTHER, // Any data not listed here - will not be analyzed
MAP, // An image presentation of array in string format, no format yet
LINK, // Link to a webpage
HEATMAP, // An image presentation of array in string format, no format yet
DEPRECATED // Old data that has been rendered useless
}

View File

@ -1,33 +0,0 @@
package com.djrapitops.plan.api;
import java.util.HashMap;
/**
* Old API Part
*
* @author Rsl1122
* @deprecated
*/
@Deprecated
public interface Hook {
/**
*
* @param player
* @return
* @throws Exception
* @deprecated
*/
@Deprecated
public HashMap<String, DataPoint> getData(String player) throws Exception;
/**
*
* @param player
* @return
* @throws Exception
* @deprecated
*/
@Deprecated
public HashMap<String, DataPoint> getAllData(String player) throws Exception;
}

View File

@ -15,7 +15,7 @@ public class DemographicsData {
}
public DemographicsData() {
this(-1, Gender.UNKNOWN, "Not_known");
this(-1, Gender.UNKNOWN, "Not Known");
}
// Getters

View File

@ -1,20 +1,59 @@
package com.djrapitops.plan.data;
import com.djrapitops.plan.Plan;
import java.util.HashMap;
import org.bukkit.Bukkit;
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
import org.bukkit.scheduler.BukkitRunnable;
/**
*
* @author Rsl1122
*/
public class ServerData {
private final HashMap<String, Integer> commandUsage;
private int playersOnline;
private int newPlayers;
/**
* Class Constructor.
*
* Creates a new DataPoint of ServerData with the currently known player
* count.
*
* @param commandUsage HashMap of Commands used and times they have been
* used.
* @param newPlayers Amount of new players that have joined that day.
*/
public ServerData(HashMap<String, Integer> commandUsage, int newPlayers) {
this.commandUsage = commandUsage;
this.playersOnline = Bukkit.getServer().getOnlinePlayers().size();
this.newPlayers = newPlayers;
}
/**
* Class Constructor with playersOnline.
*
* Creates a new DataPoint of ServerData with defined player count.
*
* @param commandUsage HashMap of Commands used and times they have been
* used.
* @param newPlayers Amount of new players that have joined that day.
* @param playersOnline Amount of players at the time of save.
*/
public ServerData(HashMap<String, Integer> commandUsage, int newPlayers, int playersOnline) {
this.commandUsage = commandUsage;
this.playersOnline = playersOnline;
this.newPlayers = newPlayers;
}
/**
* Updates PlayerCount if the player is new.
*
* @param newPlayer If data for player is not found in the database this is
* true.
*/
public void playerJoined(boolean newPlayer) {
updatePlayerCount();
if (newPlayer) {
@ -22,14 +61,30 @@ public class ServerData {
}
}
/**
* Updates playersOnline to current playercount.
*/
public void updatePlayerCount() {
playersOnline = Bukkit.getServer().getOnlinePlayers().size();
}
/**
* Updates playersOnline after 5 seconds to wait for Player to leave.
*/
public void playerLeft() {
updatePlayerCount();
(new BukkitRunnable() {
@Override
public void run() {
updatePlayerCount();
this.cancel();
}
}).runTaskLater(getPlugin(Plan.class), 5 * 20);
}
/**
* Adds command to the commandUse Map and adds 1 to the amount it has been used.
* @param command Used command (eg. /plan)
*/
public void commandRegistered(String command) {
if (!commandUsage.containsKey(command)) {
commandUsage.put(command, 0);
@ -37,14 +92,23 @@ public class ServerData {
commandUsage.put(command, commandUsage.get(command) + 1);
}
/**
* @return HashMap of used Commands and how many times they've been used.
*/
public HashMap<String, Integer> getCommandUsage() {
return commandUsage;
}
/**
* @return How many players were online at the time of save.
*/
public int getPlayersOnline() {
return playersOnline;
}
/**
* @return How many players were new at the time of save.
*/
public int getNewPlayers() {
return newPlayers;
}

View File

@ -138,6 +138,7 @@ public class DataCacheHandler {
dataCache.keySet().stream().forEach((uuid) -> {
saveCachedData(uuid);
});
serverData.updatePlayerCount();
saveServerData();
timesSaved++;
}

View File

@ -3,15 +3,16 @@ package com.djrapitops.plan.data.handlers;
import com.djrapitops.plan.data.cache.DataCacheHandler;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.api.Gender;
import com.djrapitops.plan.data.DemographicsData;
import com.djrapitops.plan.data.UserData;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.util.ArrayList;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
/**
*
@ -107,21 +108,24 @@ public class DemographicsHandler {
*/
public void handleLogin(PlayerJoinEvent event, UserData data) {
InetAddress address = event.getPlayer().getAddress().getAddress();
Plan plugin = getPlugin(Plan.class);
DemographicsData demData = data.getDemData();
try {
Scanner locationScanner = new Scanner("http://freegeoip.net/csv/" + address.getHostAddress());
String result = "";
while (locationScanner.hasNextLine()) {
result = locationScanner.nextLine();
URL url = new URL("http://freegeoip.net/csv/" + address.getHostAddress());
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String resultline;
while ((resultline = in.readLine()) != null) {
result += resultline + ",";
}
in.close();
String[] results = result.split(",");
if (!result.isEmpty()) {
data.getDemData().setGeoLocation(results[2]);
} else {
data.getDemData().setGeoLocation("Not Known");
if (!results[2].isEmpty()) {
demData.setGeoLocation(results[2]);
}
} catch (Exception e) {
demData.setGeoLocation("Not Known");
}
}
}

View File

@ -422,7 +422,8 @@ public abstract class SQLDB extends Database {
ResultSet set = statement.executeQuery();
while (set.next()) {
int newPlayers = set.getInt(serverdataColumnNewPlayers);
rawServerData.put(set.getLong(serverdataColumnDate), new ServerData(commandUse, newPlayers));
int playersOnline = set.getInt(serverdataColumnPlayersOnline);
rawServerData.put(set.getLong(serverdataColumnDate), new ServerData(commandUse, newPlayers, playersOnline));
}
set.close();
statement.close();
@ -752,6 +753,7 @@ public abstract class SQLDB extends Database {
}
}
@Override
public void clean() {
checkConnection();
plugin.log("DATABASE-SQLDB\nCleaning DB not implemented");

View File

@ -12,7 +12,6 @@ import com.googlecode.charts4j.LineChart;
import com.googlecode.charts4j.Plots;
import com.googlecode.charts4j.XYLine;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

View File

@ -1,8 +1,6 @@
package main.java.com.djrapitops.plan.ui.webserver;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.data.cache.AnalysisCacheHandler;
import com.djrapitops.plan.data.cache.InspectCacheHandler;
import com.djrapitops.plan.ui.DataRequestHandler;
import com.djrapitops.plan.ui.webserver.Request;
import com.djrapitops.plan.ui.webserver.Response;
@ -25,8 +23,6 @@ public class WebSocketServer {
private ServerSocket server;
private Plan plugin;
private InspectCacheHandler inspectHandler;
private AnalysisCacheHandler analysisHandler;
private DataRequestHandler dataReqHandler;
private boolean shutdown;
@ -40,7 +36,6 @@ public class WebSocketServer {
*/
public WebSocketServer(Plan plugin) {
this.plugin = plugin;
this.inspectHandler = plugin.getInspectCache();
this.PORT = plugin.getConfig().getInt("Settings.WebServer.Port");
shutdown = false;
dataReqHandler = new DataRequestHandler(plugin);
@ -107,4 +102,8 @@ public class WebSocketServer {
e.printStackTrace();
}
}
public DataRequestHandler getDataReqHandler() {
return dataReqHandler;
}
}

View File

@ -12,7 +12,7 @@ public class MapComparator {
hashMap.keySet().stream().forEach((key) -> {
sortedList.add(new String[]{"" + hashMap.get(key), key});
});
Collections.sort(sortedList, (String[] strings, String[] otherStrings) -> strings[0].compareTo(otherStrings[0]));
Collections.sort(sortedList, (String[] strings, String[] otherStrings) -> Integer.parseInt(strings[0])-(Integer.parseInt(otherStrings[0])));
return sortedList;
}