mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-23 09:37:54 +01:00
parent
59c38305b8
commit
f8d8054d13
@ -7,6 +7,7 @@ import java.io.PrintWriter;
|
||||
import java.util.Collection;
|
||||
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
|
||||
/**
|
||||
* This class manages the messages going to the Bukkit's Logger.
|
||||
@ -16,6 +17,9 @@ import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
*/
|
||||
public class Log {
|
||||
|
||||
final protected static String DEBUG = "DebugLog.txt";
|
||||
final protected static String ERRORS = "Errors.txt";
|
||||
|
||||
/**
|
||||
* Logs the message to the console as INFO.
|
||||
*
|
||||
@ -28,6 +32,11 @@ public class Log {
|
||||
}
|
||||
}
|
||||
|
||||
public static void infoColor(String message) {
|
||||
ConsoleCommandSender consoleSender = Plan.getInstance().getServer().getConsoleSender();
|
||||
consoleSender.sendMessage(Phrase.PREFIX + message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs an error message to the console as ERROR.
|
||||
*
|
||||
@ -46,9 +55,16 @@ public class Log {
|
||||
* @param message "Message" will show up as [INFO][Plan]: [DEBUG] Message
|
||||
*/
|
||||
public static void debug(String message) {
|
||||
if (Settings.DEBUG.isTrue()) {
|
||||
String debugMode = Settings.DEBUG.toString().toLowerCase();
|
||||
boolean both = debugMode.equals("true") || debugMode.equals("both");
|
||||
boolean logConsole = Settings.DEBUG.isTrue() || both;
|
||||
boolean logFile = debugMode.equals("file") || both;
|
||||
if (logConsole) {
|
||||
info("[DEBUG] " + message);
|
||||
}
|
||||
if (logFile) {
|
||||
toLog(message, DEBUG);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,11 +75,11 @@ public class Log {
|
||||
*/
|
||||
public static void toLog(String source, Throwable e) {
|
||||
error(Phrase.ERROR_LOGGED.parse(e.toString()));
|
||||
toLog(source + " Caught " + e);
|
||||
toLog(source + " Caught " + e, ERRORS);
|
||||
for (StackTraceElement x : e.getStackTrace()) {
|
||||
toLog(" " + x);
|
||||
toLog(" " + x, ERRORS);
|
||||
}
|
||||
toLog("");
|
||||
toLog("", ERRORS);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,8 +99,21 @@ public class Log {
|
||||
*
|
||||
* @param message Message to log to Errors.txt [timestamp] Message
|
||||
*/
|
||||
@Deprecated
|
||||
public static void toLog(String message) {
|
||||
Log.debug(message);
|
||||
toLog(message, ERRORS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a message to the a given file with a timestamp.
|
||||
*
|
||||
* @param message Message to log to Errors.txt [timestamp] Message
|
||||
* @param filename Name of the file to write to.
|
||||
*/
|
||||
public static void toLog(String message, String filename) {
|
||||
if (filename.equals(ERRORS)) {
|
||||
Log.debug(message);
|
||||
}
|
||||
Plan plan = Plan.getInstance();
|
||||
if (plan == null) {
|
||||
return;
|
||||
@ -93,19 +122,19 @@ public class Log {
|
||||
if (!folder.exists()) {
|
||||
folder.mkdir();
|
||||
}
|
||||
File log = new File(folder, "Errors.txt");
|
||||
File log = new File(folder, filename);
|
||||
try {
|
||||
if (!log.exists()) {
|
||||
log.createNewFile();
|
||||
}
|
||||
FileWriter fw = new FileWriter(log, true);
|
||||
try (PrintWriter pw = new PrintWriter(fw)) {
|
||||
String timestamp = FormatUtils.formatTimeStamp(MiscUtils.getTime());
|
||||
String timestamp = FormatUtils.formatTimeStampSecond(MiscUtils.getTime());
|
||||
pw.println("[" + timestamp + "] " + message);
|
||||
pw.flush();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
plan.getLogger().severe("Failed to create Errors.txt file");
|
||||
Log.error("Failed to create" + filename + "file");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,11 @@ public enum Phrase {
|
||||
DB_TYPE_DOES_NOT_EXIST("That database type doesn't exist."),
|
||||
DB_FAILURE_DISABLE("Database initialization has failed, disabling Plan."),
|
||||
NOTIFY_EMPTY_IP(ChatColor.YELLOW + "" + PREFIX + "IP in server.properties is empty & AlternativeServerIP is not used, incorrect links will be given!"),
|
||||
//
|
||||
NOTIFY_DISABLED_CHATLISTENER(ChatColor.YELLOW + "Chat listener disabled, nickname info inaccurate."),
|
||||
NOTIFY_DISABLED_GMLISTENER(ChatColor.YELLOW + "Gamemode change listener disabled, Gm times info inaccurate."),
|
||||
NOTIFY_DISABLED_COMMANDLISTENER(ChatColor.YELLOW + "Command usage listener disabled."),
|
||||
NOTIFY_DISABLED_DEATHLISTENER(ChatColor.YELLOW + "Death listener disabled, player & mob kills not recorded."),
|
||||
//
|
||||
CACHE_SAVETASK_DISABLED("Attempted to schedule data for save after task was shut down."),
|
||||
CACHE_GETTASK_DISABLED("Attempted to schedule data grab after task was shut down."),
|
||||
CACHE_CLEARTASK_DISABLED("Attempted to schedule data for clear after task was shut down."),
|
||||
|
@ -40,7 +40,6 @@ import main.java.com.djrapitops.plan.ui.Html;
|
||||
import main.java.com.djrapitops.plan.ui.webserver.WebSocketServer;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
@ -110,7 +109,6 @@ public class Plan extends JavaPlugin {
|
||||
|
||||
this.api = new API(this);
|
||||
handler.handleReload();
|
||||
ConsoleCommandSender consoleSender = getServer().getConsoleSender();
|
||||
|
||||
bootAnalysisTaskID = -1;
|
||||
if (Settings.WEBSERVER_ENABLED.isTrue()) {
|
||||
@ -125,10 +123,10 @@ public class Plan extends JavaPlugin {
|
||||
}
|
||||
} else if (!(Settings.SHOW_ALTERNATIVE_IP.isTrue())
|
||||
|| (Settings.USE_ALTERNATIVE_UI.isTrue())) {
|
||||
consoleSender.sendMessage(Phrase.PREFIX + "" + Phrase.ERROR_NO_DATA_VIEW);
|
||||
Log.infoColor(Phrase.ERROR_NO_DATA_VIEW + "");
|
||||
}
|
||||
if (!Settings.SHOW_ALTERNATIVE_IP.isTrue() && getServer().getIp().isEmpty()) {
|
||||
consoleSender.sendMessage(Phrase.NOTIFY_EMPTY_IP + "");
|
||||
Log.infoColor(Phrase.NOTIFY_EMPTY_IP + "");
|
||||
}
|
||||
|
||||
hookHandler = new HookHandler();
|
||||
@ -161,11 +159,29 @@ public class Plan extends JavaPlugin {
|
||||
|
||||
private void registerListeners() {
|
||||
final PluginManager pluginManager = getServer().getPluginManager();
|
||||
pluginManager.registerEvents(new PlanChatListener(this), this);
|
||||
|
||||
pluginManager.registerEvents(new PlanPlayerListener(this), this);
|
||||
pluginManager.registerEvents(new PlanGamemodeChangeListener(this), this);
|
||||
pluginManager.registerEvents(new PlanCommandPreprocessListener(this), this);
|
||||
pluginManager.registerEvents(new PlanDeathEventListener(this), this);
|
||||
|
||||
if (Settings.GATHERCHAT.isTrue()) {
|
||||
pluginManager.registerEvents(new PlanChatListener(this), this);
|
||||
} else {
|
||||
Log.infoColor(Phrase.NOTIFY_DISABLED_CHATLISTENER + "");
|
||||
}
|
||||
if (Settings.GATHERGMTIMES.isTrue()) {
|
||||
pluginManager.registerEvents(new PlanGamemodeChangeListener(this), this);
|
||||
} else {
|
||||
Log.infoColor(Phrase.NOTIFY_DISABLED_GMLISTENER + "");
|
||||
}
|
||||
if (Settings.GATHERCOMMANDS.isTrue()) {
|
||||
pluginManager.registerEvents(new PlanCommandPreprocessListener(this), this);
|
||||
} else {
|
||||
Log.infoColor(Phrase.NOTIFY_DISABLED_COMMANDLISTENER + "");
|
||||
}
|
||||
if (Settings.GATHERKILLS.isTrue()) {
|
||||
pluginManager.registerEvents(new PlanDeathEventListener(this), this);
|
||||
} else {
|
||||
Log.infoColor(Phrase.NOTIFY_DISABLED_DEATHLISTENER + "");
|
||||
}
|
||||
if (Settings.GATHERLOCATIONS.isTrue()) {
|
||||
pluginManager.registerEvents(new PlanPlayerMoveListener(this), this);
|
||||
}
|
||||
|
@ -10,8 +10,7 @@ import java.util.List;
|
||||
* @since 2.3.2
|
||||
*/
|
||||
public enum Settings {
|
||||
// Boolean
|
||||
DEBUG("Settings.Debug"),
|
||||
// Boolean
|
||||
WEBSERVER_ENABLED("Settings.WebServer.Enabled"),
|
||||
ANALYSIS_REFRESH_ON_ENABLE("Settings.Cache.AnalysisCache.RefreshAnalysisCacheOnEnable"),
|
||||
ANALYSIS_LOG_TO_CONSOLE("Settings.Analysis.LogProgressOnConsole"),
|
||||
@ -21,6 +20,10 @@ public enum Settings {
|
||||
SHOW_ALTERNATIVE_IP("Settings.WebServer.ShowAlternativeServerIP"),
|
||||
USE_ALTERNATIVE_UI("Settings.UseTextUI"),
|
||||
GATHERLOCATIONS("Settings.Data.GatherLocations"),
|
||||
GATHERCHAT("Settings.Data.ChatListener"),
|
||||
GATHERKILLS("Settings.Data.GatherKillData"),
|
||||
GATHERGMTIMES("Settings.Data.GamemodeChangeListener"),
|
||||
GATHERCOMMANDS("Settings.Data.GatherCommandUsage"),
|
||||
SECURITY_IP_UUID("Settings.WebServer.Security.DisplayIPsAndUUIDs"),
|
||||
ENABLED_AA("Customization.Plugins.Enabled.AdvancedAchievements"),
|
||||
ENABLED_ESS("Customization.Plugins.Enabled.Essentials"),
|
||||
@ -41,6 +44,7 @@ public enum Settings {
|
||||
PROCESS_SAVE_LIMIT("Settings.Cache.Processing.SaveLimit"),
|
||||
PROCESS_CLEAR_LIMIT("Settings.Cache.Processing.ClearLimit"),
|
||||
// String
|
||||
DEBUG("Settings.Debug"),
|
||||
ALTERNATIVE_IP("Settings.WebServer.AlternativeIP"),
|
||||
DB_TYPE("database.type"),
|
||||
DEM_TRIGGERS("Customization.DemographicsTriggers.Trigger"),
|
||||
@ -54,6 +58,8 @@ public enum Settings {
|
||||
//
|
||||
SERVER_NAME("Customization.ServerName"),
|
||||
//
|
||||
FORMAT_YEAR("Customization.Formats.TimeAmount.Year"),
|
||||
FORMAT_YEARS("Customization.Formats.TimeAmount.Years"),
|
||||
FORMAT_DAYS("Customization.Formats.TimeAmount.Days"),
|
||||
FORMAT_HOURS("Customization.Formats.TimeAmount.Hours"),
|
||||
FORMAT_MINUTES("Customization.Formats.TimeAmount.Minutes"),
|
||||
|
@ -11,7 +11,7 @@ import main.java.com.djrapitops.plan.data.handling.info.HandlingInfo;
|
||||
import main.java.com.djrapitops.plan.ui.DataRequestHandler;
|
||||
import main.java.com.djrapitops.plan.ui.webserver.WebSocketServer;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.UUIDFetcher;
|
||||
import main.java.com.djrapitops.plan.utilities.uuid.UUIDFetcher;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
package main.java.com.djrapitops.plan.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.command.commands.*;
|
||||
@ -89,6 +91,7 @@ public class PlanCommand implements CommandExecutor {
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
Log.debug("Registered command with arguments: "+Arrays.toString(args));
|
||||
if (args.length < 1) {
|
||||
sendDefaultCommand(sender, cmd, commandLabel, args);
|
||||
return true;
|
||||
|
@ -11,7 +11,7 @@ import main.java.com.djrapitops.plan.data.cache.InspectCacheHandler;
|
||||
import main.java.com.djrapitops.plan.ui.TextUI;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.UUIDFetcher;
|
||||
import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
@ -60,7 +60,7 @@ public class InspectCommand extends SubCommand {
|
||||
public void run() {
|
||||
UUID uuid;
|
||||
try {
|
||||
uuid = UUIDFetcher.getUUIDOf(playerName);
|
||||
uuid = UUIDUtility.getUUIDOf(playerName);
|
||||
if (uuid == null) {
|
||||
throw new Exception("Username doesn't exist.");
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.data.cache.InspectCacheHandler;
|
||||
import main.java.com.djrapitops.plan.ui.TextUI;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.UUIDFetcher;
|
||||
import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
@ -50,7 +50,7 @@ public class QuickInspectCommand extends SubCommand {
|
||||
public void run() {
|
||||
UUID uuid;
|
||||
try {
|
||||
uuid = UUIDFetcher.getUUIDOf(playerName);
|
||||
uuid = UUIDUtility.getUUIDOf(playerName);
|
||||
if (uuid == null) {
|
||||
throw new Exception("Username doesn't exist.");
|
||||
}
|
||||
|
@ -10,12 +10,10 @@ import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.command.CommandType;
|
||||
import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.UUIDFetcher;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
|
||||
/**
|
||||
* This manage subcommand is used to remove a single player's data from the
|
||||
@ -47,33 +45,31 @@ public class ManageRemoveCommand extends SubCommand {
|
||||
|
||||
String playerName = MiscUtils.getPlayerName(args, sender, Permissions.MANAGE);
|
||||
|
||||
UUID uuid;
|
||||
try {
|
||||
uuid = UUIDFetcher.getUUIDOf(playerName);
|
||||
if (uuid == null) {
|
||||
throw new Exception("Username doesn't exist.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(Phrase.USERNAME_NOT_VALID.toString());
|
||||
return true;
|
||||
}
|
||||
OfflinePlayer p = getOfflinePlayer(uuid);
|
||||
if (!p.hasPlayedBefore()) {
|
||||
sender.sendMessage(Phrase.USERNAME_NOT_SEEN.toString());
|
||||
return true;
|
||||
}
|
||||
if (!plugin.getDB().wasSeenBefore(uuid)) {
|
||||
sender.sendMessage(Phrase.USERNAME_NOT_KNOWN.toString());
|
||||
return true;
|
||||
}
|
||||
if (!Arrays.asList(args).contains("-a")) {
|
||||
sender.sendMessage(Phrase.COMMAND_ADD_CONFIRMATION_ARGUMENT.parse(Phrase.WARN_REMOVE.parse(plugin.getDB().getConfigName())));
|
||||
return true;
|
||||
}
|
||||
|
||||
(new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
UUID uuid;
|
||||
try {
|
||||
uuid = UUIDUtility.getUUIDOf(playerName);
|
||||
if (uuid == null) {
|
||||
throw new Exception("Username doesn't exist.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(Phrase.USERNAME_NOT_VALID.toString());
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
if (!plugin.getDB().wasSeenBefore(uuid)) {
|
||||
sender.sendMessage(Phrase.USERNAME_NOT_KNOWN.toString());
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
if (!Arrays.asList(args).contains("-a")) {
|
||||
sender.sendMessage(Phrase.COMMAND_ADD_CONFIRMATION_ARGUMENT.parse(Phrase.WARN_REMOVE.parse(plugin.getDB().getConfigName())));
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse());
|
||||
try {
|
||||
plugin.getHandler().getDataCache().remove(uuid);
|
||||
|
@ -3,13 +3,10 @@ package main.java.com.djrapitops.plan.data.additional.advancedachievements;
|
||||
import com.hm.achievement.api.AdvancedAchievementsAPI;
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.additional.AnalysisType;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
import main.java.com.djrapitops.plan.ui.Html;
|
||||
|
@ -3,7 +3,6 @@ package main.java.com.djrapitops.plan.data.additional.jobs;
|
||||
import main.java.com.djrapitops.plan.data.additional.Hook;
|
||||
import main.java.com.djrapitops.plan.api.API;
|
||||
import main.java.com.djrapitops.plan.data.additional.HookHandler;
|
||||
import main.java.com.djrapitops.plan.data.additional.mcmmo.McmmoAnalysisSkillTable;
|
||||
|
||||
/**
|
||||
* A Class responsible for hooking to Jobs and registering data sources.
|
||||
|
@ -31,7 +31,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
|
||||
/**
|
||||
* This Class contains the Cache.
|
||||
@ -195,7 +194,7 @@ public class DataCacheHandler extends LocationCache {
|
||||
public void cache(UserData data) {
|
||||
data.setOnline(true);
|
||||
dataCache.put(data.getUuid(), data);
|
||||
Log.info(Phrase.CACHE_ADD.parse(data.getUuid().toString()));
|
||||
Log.debug(Phrase.CACHE_ADD.parse(data.getUuid().toString()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -381,7 +380,7 @@ public class DataCacheHandler extends LocationCache {
|
||||
}
|
||||
} else {
|
||||
dataCache.remove(uuid);
|
||||
Log.info(Phrase.CACHE_REMOVE.parse(uuid.toString()));
|
||||
Log.debug(Phrase.CACHE_REMOVE.parse(uuid.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ import main.java.com.djrapitops.plan.data.DemographicsData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
import main.java.com.djrapitops.plan.utilities.UUIDFetcher;
|
||||
import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
import org.bukkit.GameMode;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
|
||||
@ -669,7 +669,7 @@ public class UsersTable extends Table {
|
||||
UUID uuid = uData.getUuid();
|
||||
if (uuid == null) {
|
||||
try {
|
||||
uData.setUuid(UUIDFetcher.getUUIDOf(uData.getName()));
|
||||
uData.setUuid(UUIDUtility.getUUIDOf(uData.getName(), db));
|
||||
} catch (Exception ex) {
|
||||
continue;
|
||||
}
|
||||
@ -755,8 +755,7 @@ public class UsersTable extends Table {
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* @throws SQLException
|
||||
* @return @throws SQLException
|
||||
*/
|
||||
public Map<UUID, Integer> getAllUserIds() throws SQLException {
|
||||
Benchmark.start("Get User IDS ALL");
|
||||
@ -786,4 +785,23 @@ public class UsersTable extends Table {
|
||||
public String getColumnID() {
|
||||
return columnID;
|
||||
}
|
||||
|
||||
public UUID getUuidOf(String playername) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try {
|
||||
statement = prepareStatement("SELECT " + columnUUID + " FROM " + tableName + " WHERE (UPPER(" + columnName + ")=UPPER(?))");
|
||||
statement.setString(1, playername);
|
||||
set = statement.executeQuery();
|
||||
while (set.next()) {
|
||||
String uuidS = set.getString(columnUUID);
|
||||
UUID uuid = UUID.fromString(uuidS);
|
||||
return uuid;
|
||||
}
|
||||
return null;
|
||||
} finally {
|
||||
close(set);
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public class TextUI {
|
||||
String ball = sec + " " + Phrase.BALL + main;
|
||||
return new String[]{
|
||||
sec + " " + Phrase.BALL + (banned ? ChatColor.DARK_RED + " Banned" : ter + (active ? " Active" : " Inactive")) + (online ? ChatColor.GREEN + " Online" : ChatColor.RED + " Offline"),
|
||||
ball + " Registered: " + sec + FormatUtils.formatTimeStamp(d.getRegistered()),
|
||||
ball + " Registered: " + sec + FormatUtils.formatTimeStampYear(d.getRegistered()),
|
||||
ball + " Last seen: " + sec + FormatUtils.formatTimeStamp(d.getLastPlayed()),
|
||||
ball + " Playtime: " + sec + FormatUtils.formatTimeAmount(d.getPlayTime()),
|
||||
ball + " Login times: " + sec + d.getLoginTimes(),
|
||||
|
@ -5,7 +5,6 @@
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.ui.graphs;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@ -68,9 +67,6 @@ public class PunchCardGraphCreator {
|
||||
int h = dAndH[1];
|
||||
dataArray[d][h] = dataArray[d][h] + 1;
|
||||
}
|
||||
for (int i = 0; i < 7; i++) {
|
||||
Log.debug(" " + Arrays.toString(dataArray[i]));
|
||||
}
|
||||
if (Settings.ANALYSIS_REMOVE_OUTLIERS.isTrue()) {
|
||||
int avg = findAverage(dataArray);
|
||||
double standardDiviation = getStandardDiviation(dataArray, avg);
|
||||
@ -84,9 +80,6 @@ public class PunchCardGraphCreator {
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 7; i++) {
|
||||
Log.debug(" " + Arrays.toString(dataArray[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
return dataArray;
|
||||
@ -168,9 +161,6 @@ public class PunchCardGraphCreator {
|
||||
}
|
||||
}
|
||||
Log.debug("Biggest value: " + big);
|
||||
for (int i = 0; i < 7; i++) {
|
||||
Log.debug(" " + Arrays.toString(scaled[i]));
|
||||
}
|
||||
return scaled;
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class SortablePlayersTableCreator {
|
||||
banOunknownOactiveOinactive,
|
||||
uData.getPlayTime() + "", FormatUtils.formatTimeAmount(uData.getPlayTime()),
|
||||
uData.getLoginTimes() + "",
|
||||
uData.getRegistered() + "", FormatUtils.formatTimeStamp(uData.getRegistered()),
|
||||
uData.getRegistered() + "", FormatUtils.formatTimeStampYear(uData.getRegistered()),
|
||||
uData.getLastPlayed() + "", FormatUtils.formatTimeStamp(uData.getLastPlayed()),
|
||||
uData.getDemData().getGeoLocation()
|
||||
);
|
||||
|
@ -6,7 +6,7 @@ import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.ui.DataRequestHandler;
|
||||
import main.java.com.djrapitops.plan.utilities.UUIDFetcher;
|
||||
import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -67,7 +67,7 @@ public class Response {
|
||||
if (command.equals("player")) {
|
||||
if (requestArgs.length > 3) {
|
||||
String playerName = requestArgs[3].trim();
|
||||
UUID uuid = UUIDFetcher.getUUIDOf(playerName);
|
||||
UUID uuid = UUIDUtility.getUUIDOf(playerName);
|
||||
if (uuid == null) {
|
||||
String errorMessage = "HTTP/1.1 500 UUID not Found\r\n"
|
||||
+ "Content-Type: text/html;\r\n"
|
||||
|
@ -36,8 +36,30 @@ public class FormatUtils {
|
||||
* @return
|
||||
*/
|
||||
public static String formatTimeStamp(long epochMs) {
|
||||
Date sfd = new Date(epochMs);
|
||||
return ("" + sfd).substring(4, 19);
|
||||
Date date = new Date(epochMs);
|
||||
String timeStamp = date.toString();
|
||||
// "EEE MMM dd HH:mm:ss zzz yyyy"
|
||||
// "0123456789012345678901234567"
|
||||
String day = timeStamp.substring(4, 10);
|
||||
String clock = timeStamp.substring(11, 16);
|
||||
return day + ", " + clock;
|
||||
}
|
||||
|
||||
public static String formatTimeStampSecond(long epochMs) {
|
||||
Date date = new Date(epochMs);
|
||||
String timeStamp = date.toString();
|
||||
String day = timeStamp.substring(4, 10);
|
||||
String clock = timeStamp.substring(11, 19);
|
||||
return day + ", " + clock;
|
||||
}
|
||||
|
||||
public static String formatTimeStampYear(long epochMs) {
|
||||
Date date = new Date(epochMs);
|
||||
String timeStamp = date.toString();
|
||||
String year = timeStamp.substring(24);
|
||||
String day = timeStamp.substring(4, 10);
|
||||
String clock = timeStamp.substring(11, 16);
|
||||
return day + " " + year + ", " + clock;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,18 +95,27 @@ public class FormatUtils {
|
||||
x /= 60;
|
||||
long hours = x % 24;
|
||||
x /= 24;
|
||||
long days = x;
|
||||
long days = x % 365;
|
||||
x /= 365;
|
||||
long years = x;
|
||||
if (years != 0) {
|
||||
if (years == 1) {
|
||||
builder.append(Settings.FORMAT_YEAR.toString());
|
||||
} else {
|
||||
builder.append(Settings.FORMAT_YEARS.toString().replace("%years%", "" + years));
|
||||
}
|
||||
}
|
||||
if (days != 0) {
|
||||
builder.append(Settings.FORMAT_DAYS.toString().replace("%days%", ""+days));
|
||||
builder.append(Settings.FORMAT_DAYS.toString().replace("%days%", "" + days));
|
||||
}
|
||||
if (hours != 0) {
|
||||
builder.append(Settings.FORMAT_HOURS.toString().replace("%hours%", ""+hours));
|
||||
builder.append(Settings.FORMAT_HOURS.toString().replace("%hours%", "" + hours));
|
||||
}
|
||||
if (minutes != 0) {
|
||||
builder.append(Settings.FORMAT_MINUTES.toString().replace("%minutes%", ""+minutes));
|
||||
builder.append(Settings.FORMAT_MINUTES.toString().replace("%minutes%", "" + minutes));
|
||||
}
|
||||
if (seconds != 0) {
|
||||
builder.append(Settings.FORMAT_SECONDS.toString().replace("%seconds%", ""+seconds));
|
||||
builder.append(Settings.FORMAT_SECONDS.toString().replace("%seconds%", "" + seconds));
|
||||
}
|
||||
String formattedTime = builder.toString();
|
||||
if (formattedTime.isEmpty()) {
|
||||
|
@ -5,7 +5,6 @@ import java.io.FileNotFoundException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.ui.Html;
|
||||
|
@ -150,7 +150,7 @@ public class PlaceholderUtils {
|
||||
boolean showIPandUUID = Settings.SECURITY_IP_UUID.isTrue();
|
||||
UUID uuid = data.getUuid();
|
||||
replaceMap.put("%uuid%", (showIPandUUID ? "" + uuid : Html.HIDDEN.parse()));
|
||||
replaceMap.put("%lastseen%", FormatUtils.formatTimeStamp(data.getLastPlayed()));
|
||||
replaceMap.put("%lastseen%", FormatUtils.formatTimeStampYear(data.getLastPlayed()));
|
||||
replaceMap.put("%logintimes%", "" + data.getLoginTimes());
|
||||
replaceMap.put("%geoloc%", data.getDemData().getGeoLocation());
|
||||
long now = MiscUtils.getTime();
|
||||
@ -189,7 +189,7 @@ public class PlaceholderUtils {
|
||||
replaceMap.put("%ips%", (showIPandUUID ? data.getIps().toString() : Html.HIDDEN.parse()));
|
||||
replaceMap.put("%nicknames%", HtmlUtils.removeXSS(HtmlUtils.swapColorsToSpan(data.getNicknames().toString())));
|
||||
replaceMap.put("%name%", data.getName());
|
||||
replaceMap.put("%registered%", FormatUtils.formatTimeStamp(data.getRegistered()));
|
||||
replaceMap.put("%registered%", FormatUtils.formatTimeStampYear(data.getRegistered()));
|
||||
replaceMap.put("%timeskicked%", "" + data.getTimesKicked());
|
||||
replaceMap.put("%playtime%", FormatUtils.formatTimeAmount(data.getPlayTime()));
|
||||
replaceMap.put("%banned%", data.isBanned() ? Html.BANNED.parse() : "");
|
||||
|
@ -10,7 +10,6 @@ import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.api.Gender;
|
||||
import main.java.com.djrapitops.plan.data.AnalysisData;
|
||||
import main.java.com.djrapitops.plan.data.DemographicsData;
|
||||
import main.java.com.djrapitops.plan.data.KillData;
|
||||
|
@ -11,15 +11,11 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.data.AnalysisData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.ui.DataRequestHandler;
|
||||
import main.java.com.djrapitops.plan.ui.webserver.WebSocketServer;
|
||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.PlaceholderUtils;
|
||||
|
@ -19,7 +19,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.utilities;
|
||||
package main.java.com.djrapitops.plan.utilities.uuid;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.io.InputStreamReader;
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.utilities.uuid;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
*/
|
||||
public class UUIDUtility {
|
||||
|
||||
public static UUID getUUIDOf(String playername) throws Exception {
|
||||
return getUUIDOf(playername, Plan.getInstance().getDB());
|
||||
}
|
||||
|
||||
public static UUID getUUIDOf(String playername, Database db) throws Exception {
|
||||
UUID uuid = null;
|
||||
try {
|
||||
uuid = db.getUsersTable().getUuidOf(playername);
|
||||
} catch (SQLException e) {
|
||||
Log.toLog("UUIDUtility", e);
|
||||
}
|
||||
if (uuid == null) {
|
||||
uuid = UUIDFetcher.getUUIDOf(playername);
|
||||
}
|
||||
return uuid;
|
||||
}
|
||||
}
|
@ -4,6 +4,10 @@ Settings:
|
||||
UseTextUI: false
|
||||
Data:
|
||||
GatherLocations: true
|
||||
ChatListener: true
|
||||
GatherKillData: true
|
||||
GamemodeChangeListener: true
|
||||
GatherCommandUsage: true
|
||||
Analysis:
|
||||
LogProgressOnConsole: false
|
||||
NotifyWhenFinished: true
|
||||
@ -39,6 +43,8 @@ Customization:
|
||||
ServerName: 'Plan'
|
||||
Formats:
|
||||
TimeAmount:
|
||||
Year: '1 year, '
|
||||
Years: '%years% years, '
|
||||
Days: '%days%d '
|
||||
Hours: '%hours%h '
|
||||
Minutes: '%minutes%m '
|
||||
|
@ -6,8 +6,6 @@
|
||||
package test.java.main.java.com.djrapitops.plan;
|
||||
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import test.java.utils.MockUtils;
|
||||
|
@ -22,8 +22,6 @@ import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -11,7 +11,6 @@ import main.java.com.djrapitops.plan.data.SessionData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.cache.SessionCache;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -6,7 +6,6 @@
|
||||
package test.java.main.java.com.djrapitops.plan.data.cache.queue;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
|
@ -29,9 +29,6 @@ import test.java.utils.TestInit;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -26,7 +26,6 @@ import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.MockUtils;
|
||||
import test.java.utils.TestInit;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -37,8 +37,6 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.*;
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.After;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -70,10 +70,18 @@ public class FormatUtilsTest {
|
||||
@Test
|
||||
public void testFormatTimeStamp() {
|
||||
long epochZero = 0L;
|
||||
String expResult = "Jan 01 02:00:00";
|
||||
String expResult = "Jan 01, 02:00";
|
||||
String result = FormatUtils.formatTimeStamp(epochZero);
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatTimeStampYear() {
|
||||
long epochZero = 0L;
|
||||
String expResult = "Jan 01 1970, 02:00";
|
||||
String result = FormatUtils.formatTimeStampYear(epochZero);
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -14,7 +14,6 @@ import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.junit.After;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -11,7 +11,6 @@ import java.nio.file.Files;
|
||||
import java.util.logging.Logger;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
|
Loading…
Reference in New Issue
Block a user