2016-12-08 18:31:10 +01:00
|
|
|
package com.djrapitops.plan.command.commands;
|
|
|
|
|
|
|
|
import com.djrapitops.plan.Plan;
|
|
|
|
import com.djrapitops.plan.command.CommandType;
|
|
|
|
import com.djrapitops.plan.command.SubCommand;
|
|
|
|
import com.djrapitops.plan.command.utils.DataFormatUtils;
|
|
|
|
import com.djrapitops.plan.command.utils.DataUtils;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Comparator;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
2016-12-11 19:09:40 +01:00
|
|
|
import com.djrapitops.plan.UUIDFetcher;
|
2016-12-08 18:31:10 +01:00
|
|
|
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
public class InspectCommand extends SubCommand {
|
|
|
|
|
|
|
|
private Plan plugin;
|
|
|
|
|
|
|
|
public InspectCommand(Plan plugin) {
|
|
|
|
super("inspect", "plan.inspect", "Inspect data /plan <player> [-a, -r].", CommandType.CONSOLE_WITH_ARGUMENTS);
|
|
|
|
|
|
|
|
this.plugin = plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
2016-12-12 20:45:05 +01:00
|
|
|
String playerName = DataUtils.getPlayerDisplayname(args, sender);
|
2016-12-08 18:31:10 +01:00
|
|
|
if (this.plugin.getHooks().isEmpty()) {
|
|
|
|
this.plugin.logError("noHookedPluginsError on InspectCommand");
|
|
|
|
|
|
|
|
this.plugin.logToFile("INSPECT\nnoHookedPluginsError on InspectCommand");
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean allData = false;
|
|
|
|
boolean format = true;
|
|
|
|
for (String arg : args) {
|
|
|
|
if (arg.toLowerCase().equals("-a")) {
|
|
|
|
allData = true;
|
|
|
|
}
|
|
|
|
if (arg.toLowerCase().equals("-r")) {
|
|
|
|
format = false;
|
|
|
|
}
|
|
|
|
}
|
2016-12-12 20:45:05 +01:00
|
|
|
Date refreshDate = new Date();
|
2016-12-09 18:42:09 +01:00
|
|
|
HashMap<String, String> data = DataUtils.getData(allData, playerName);
|
2016-12-08 18:31:10 +01:00
|
|
|
if (format && !data.isEmpty()) {
|
2016-12-09 18:42:09 +01:00
|
|
|
data = DataFormatUtils.removeExtraDataPoints(data);
|
2016-12-08 18:31:10 +01:00
|
|
|
}
|
|
|
|
if (data.isEmpty()) {
|
|
|
|
data.put("ERR-NO RESULTS", "No results were found.");
|
|
|
|
|
|
|
|
plugin.logToFile("INSPECT-Results\nNo results were found for: " + playerName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-12-09 18:42:09 +01:00
|
|
|
List<String[]> dataList = DataFormatUtils.turnDataHashMapToSortedListOfArrays(data);
|
2016-12-08 18:31:10 +01:00
|
|
|
|
|
|
|
ChatColor operatorColor = ChatColor.DARK_GREEN;
|
|
|
|
ChatColor textColor = ChatColor.GRAY;
|
|
|
|
|
2016-12-09 18:42:09 +01:00
|
|
|
//header
|
2016-12-12 20:45:05 +01:00
|
|
|
sender.sendMessage(textColor + "-- [" + operatorColor + "PLAN - Inspect results: " + playerName +" - took "+DataFormatUtils.formatTimeAmountSinceDate(refreshDate, new Date())+ textColor + "] --");
|
2016-12-08 18:31:10 +01:00
|
|
|
|
|
|
|
for (String[] dataString : dataList) {
|
|
|
|
sender.sendMessage("" + operatorColor + dataString[0].charAt(4) + dataString[0].toLowerCase().substring(5) + ": " + textColor + dataString[1]);
|
|
|
|
}
|
|
|
|
sender.sendMessage(textColor + "-- o --");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-12-12 20:45:05 +01:00
|
|
|
// Use DataUtils.getData instead
|
2016-12-09 18:42:09 +01:00
|
|
|
@Deprecated
|
2016-12-08 18:31:10 +01:00
|
|
|
public HashMap<String, String> getData(boolean allData, String playerName) {
|
|
|
|
return DataUtils.getData(allData, playerName);
|
|
|
|
}
|
|
|
|
|
2016-12-12 20:45:05 +01:00
|
|
|
// Use DataFormatUtils.removeExtraDataPoints instead
|
2016-12-09 18:42:09 +01:00
|
|
|
@Deprecated
|
2016-12-08 18:31:10 +01:00
|
|
|
public HashMap<String, String> format(HashMap<String, String> data) throws NumberFormatException {
|
|
|
|
return DataFormatUtils.removeExtraDataPoints(data);
|
|
|
|
}
|
|
|
|
|
2016-12-12 20:45:05 +01:00
|
|
|
// Use DataUtils.getPlayerDisplayname instead
|
|
|
|
@Deprecated
|
2016-12-08 18:31:10 +01:00
|
|
|
private String getPlayerDisplayname(String[] args, CommandSender sender) {
|
2016-12-12 20:45:05 +01:00
|
|
|
return DataUtils.getPlayerDisplayname(args, sender);
|
2016-12-08 18:31:10 +01:00
|
|
|
}
|
|
|
|
}
|