2017-01-09 23:05:37 +01:00
|
|
|
package com.djrapitops.planlite.command.commands;
|
2016-12-08 18:31:10 +01:00
|
|
|
|
2017-01-15 17:54:14 +01:00
|
|
|
import com.djrapitops.planlite.Phrase;
|
2017-01-09 23:05:37 +01:00
|
|
|
import com.djrapitops.planlite.PlanLite;
|
2017-01-15 17:54:14 +01:00
|
|
|
import com.djrapitops.planlite.UUIDFetcher;
|
2017-01-09 23:05:37 +01:00
|
|
|
import com.djrapitops.planlite.command.CommandType;
|
|
|
|
import com.djrapitops.planlite.command.SubCommand;
|
|
|
|
import com.djrapitops.planlite.command.utils.DataFormatUtils;
|
|
|
|
import com.djrapitops.planlite.command.utils.DataUtils;
|
2016-12-08 18:31:10 +01:00
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
2017-01-09 23:05:37 +01:00
|
|
|
import com.djrapitops.planlite.api.DataPoint;
|
|
|
|
import com.djrapitops.planlite.api.DataType;
|
2017-01-15 17:54:14 +01:00
|
|
|
import java.util.UUID;
|
|
|
|
import static org.bukkit.Bukkit.getOfflinePlayer;
|
2016-12-08 18:31:10 +01:00
|
|
|
|
|
|
|
import org.bukkit.ChatColor;
|
2017-01-15 17:54:14 +01:00
|
|
|
import org.bukkit.OfflinePlayer;
|
2016-12-08 18:31:10 +01:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
|
|
|
|
public class InspectCommand extends SubCommand {
|
|
|
|
|
2016-12-30 23:39:11 +01:00
|
|
|
private PlanLite plugin;
|
2016-12-08 18:31:10 +01:00
|
|
|
|
2016-12-30 23:39:11 +01:00
|
|
|
public InspectCommand(PlanLite plugin) {
|
2017-01-15 17:54:14 +01:00
|
|
|
super("inspect", "planlite.inspect", "Inspect data /planlite <player> [-a, -r].", CommandType.CONSOLE_WITH_ARGUMENTS);
|
2016-12-08 18:31:10 +01:00
|
|
|
|
|
|
|
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);
|
2017-01-15 17:54:14 +01:00
|
|
|
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;
|
|
|
|
}
|
2016-12-08 18:31:10 +01:00
|
|
|
if (this.plugin.getHooks().isEmpty()) {
|
2017-01-15 17:54:14 +01:00
|
|
|
sender.sendMessage(Phrase.ERROR_NO_HOOKS.toString());
|
|
|
|
return true;
|
2016-12-08 18:31:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
1.6.0 - New Data Structure, API changes, data handling changes, Player Logger Hook, Info Command
- Changed data format to include the Type the data is for easier
analysis (Of Future data and API Using plugins)
- API Changes:
- Hook moved to com.djrapitops.plan.api
- Hook now returns HashMap<Strring, DataPoint>
- added DataPoint to ..plan.api
- added DataType Enum to ..plan.api
- New format uses: data.put("XXX-Key", new Datapoint(String data,
Enum(DataType) datatype));
- Depricated getData(String playername) that returns old format of data,
still returns correct format
- Depricated getAllData(String playername)
- Move to get(All)Data(String name, boolean [anything]) to get the new
format of data.
- Added Player Logger Hook
- Added Info Command that gives version, hooks and checks for new
version.
- Check for new version upon startup
2016-12-19 16:30:08 +01:00
|
|
|
HashMap<String, DataPoint> 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()) {
|
1.6.0 - New Data Structure, API changes, data handling changes, Player Logger Hook, Info Command
- Changed data format to include the Type the data is for easier
analysis (Of Future data and API Using plugins)
- API Changes:
- Hook moved to com.djrapitops.plan.api
- Hook now returns HashMap<Strring, DataPoint>
- added DataPoint to ..plan.api
- added DataType Enum to ..plan.api
- New format uses: data.put("XXX-Key", new Datapoint(String data,
Enum(DataType) datatype));
- Depricated getData(String playername) that returns old format of data,
still returns correct format
- Depricated getAllData(String playername)
- Move to get(All)Data(String name, boolean [anything]) to get the new
format of data.
- Added Player Logger Hook
- Added Info Command that gives version, hooks and checks for new
version.
- Check for new version upon startup
2016-12-19 16:30:08 +01:00
|
|
|
data.put("ERR-NO RESULTS", new DataPoint("No results were found.", DataType.OTHER));
|
2016-12-08 18:31:10 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
2017-01-15 17:54:14 +01:00
|
|
|
ChatColor oColor = Phrase.COLOR_MAIN.color();
|
|
|
|
ChatColor tColor = Phrase.COLOR_SEC.color();
|
|
|
|
ChatColor hColor = Phrase.COLOR_TER.color();
|
|
|
|
|
|
|
|
sender.sendMessage(hColor + Phrase.ARROWS_RIGHT.toString() + oColor + " Player Analytics Lite | Inspect results: " + playerName);
|
2016-12-08 18:31:10 +01:00
|
|
|
|
|
|
|
for (String[] dataString : dataList) {
|
2017-01-15 17:54:14 +01:00
|
|
|
sender.sendMessage(" " + tColor + Phrase.BALL + oColor+" "+ dataString[0].charAt(4) + dataString[0].toLowerCase().substring(5) + ": " + tColor + dataString[1]);
|
2016-12-08 18:31:10 +01:00
|
|
|
}
|
2017-01-15 17:54:14 +01:00
|
|
|
sender.sendMessage(hColor + Phrase.ARROWS_RIGHT.toString());
|
2016-12-08 18:31:10 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|