Finished first version of 2.0.0 Data Structure (SQL, Handlers, Listeners) + other

- Renamed old Plan to PlanLite with refractor
- Deprecated PlanLite API classes in Plan (Hook, DataPoint, DataType)
- API not yet changed
- extra hook calls passed onto PlanLite
- Created the new data structure that saves all the information needed
by analysis. (Not Bugtested)
- Refractored PlanDemographics code into DemographicsHandler
- Added Gender Enum
- Added Phrase Enum (plugin messages)

TODO:
- Bugtest SQL
- Bugtest UserData
- Bugtest ServerData
- Inspect command
- Analysis
- Search command (No clue yet)
- Bugtest Listeners
- Bugtest Handlers
- Command listener
- ServerData newPlayers / day reset
- Config
- html webserver for results
This commit is contained in:
Rsl1122 2016-12-31 00:39:11 +02:00
parent df8e9dcd77
commit e903a5ac25
76 changed files with 2337 additions and 989 deletions

View File

@ -29,31 +29,13 @@ dist.jar=${dist.dir}/Plan.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
file.reference.AdvancedAchievements-4.0.2.jar=C:\\Users\\Risto\\Documents\\NetBeansProjects\\AdvancedAchievements\\target\\AdvancedAchievements-4.0.2.jar
file.reference.craftbukkit-1.11.2.jar=D:\\Minecraft Servers\\Buildtools\\craftbukkit-1.11.2.jar
file.reference.Factions.jar=D:\\Minecraft Servers\\TestServer\\plugins\\Uusi kansio\\Factions.jar
file.reference.MassiveCore.jar=D:\\Minecraft Servers\\TestServer\\plugins\\Uusi kansio\\MassiveCore.jar
file.reference.mcMMO.jar=D:\\Minecraft Servers\\TestServer\\plugins\\Uusi kansio\\mcMMO.jar
file.reference.PlaceholderAPI.jar=D:\\Minecraft Servers\\TestServer\\plugins\\Uusi kansio\\PlaceholderAPI.jar
file.reference.PlayerLogger_v1.0_.jar=D:\\Minecraft Servers\\TestServer\\plugins\\Uusi kansio\\PlayerLogger[v1.0].jar
file.reference.SuperbVote-0.3.2.jar=D:\\Minecraft Servers\\TestServer\\plugins\\Uusi kansio\\SuperbVote-0.3.2.jar
file.reference.Towny.jar=D:\\Downloads\\Towny.jar
file.reference.Vault.jar=D:\\Minecraft Servers\\TestServer\\plugins\\Vault.jar
file.reference.PlanLite.jar=..\\Plan Lite\\dist\\PlanLite.jar
includes=**
jar.compress=true
javac.classpath=\
${file.reference.OnTime.jar}:\
${file.reference.EssentialsX-2.0.1.jar}:\
${file.reference.Towny.jar}:\
${file.reference.Vault.jar}:\
${file.reference.Factions.jar}:\
${file.reference.MassiveCore.jar}:\
${file.reference.mcMMO.jar}:\
${file.reference.SuperbVote-0.3.2.jar}:\
${file.reference.PlaceholderAPI.jar}:\
${file.reference.AdvancedAchievements-4.0.2.jar}:\
${file.reference.PlayerLogger_v1.0_.jar}:\
${file.reference.craftbukkit-1.11.2.jar}
${file.reference.craftbukkit-1.11.2.jar}:\
${file.reference.PlanLite.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false

View File

@ -0,0 +1,39 @@
package com.djrapitops.plan;
import org.bukkit.ChatColor;
public enum Phrase {
DATABASE_TYPE_DOES_NOT_EXIST("That database type doesn't exist."),
DATABASE_FAILURE_DISABLE("Database initialization has failed, disabling Plan."),
PLANLITE_REG_HOOK("Registered additional hook, passed on to PlanLite: "),
USERNAME_NOT_VALID("This Player doesn't exist."),
USERNAME_NOT_SEEN("This Player has not played on this server."),
USERNAME_NOT_KNOWN("Player not found from the database."),
COLOR_MAIN(ChatColor.DARK_GREEN),
COLOR_SEC(ChatColor.GRAY),
COLOR_TER(ChatColor.DARK_GRAY),
ERROR_PLANLITE("PlanLite not found, if you're have plugins using PlanAPI v1.6.0 download PlanLite."),
ERROR_NO_USERNAME("INSPECT-GETNAME\nNo username given, returned empty username.\n");
private final String text;
private final ChatColor color;
private Phrase(final String text) {
this.text = text;
this.color = null;
}
private Phrase(final ChatColor color) {
this.color = color;
this.text = "";
}
@Override
public String toString() {
return text;
}
public ChatColor color() {
return color;
}
}

View File

@ -1,53 +1,58 @@
package com.djrapitops.plan;
import com.djrapitops.plan.api.API;
import com.djrapitops.plan.command.hooks.EssentialsHook;
import com.djrapitops.plan.command.hooks.FactionsHook;
import com.djrapitops.plan.command.hooks.OnTimeHook;
import com.djrapitops.plan.api.Hook;
import com.djrapitops.plan.command.hooks.PlaceholderAPIHook;
import com.djrapitops.plan.command.hooks.SuperbVoteHook;
//import com.djrapitops.plan.command.hooks.McMMOHook;
import com.djrapitops.plan.command.hooks.TownyHook;
import com.djrapitops.plan.command.hooks.VaultHook;
import com.djrapitops.plan.command.hooks.AdvancedAchievementsHook;
import com.djrapitops.plan.command.hooks.BukkitDataHook;
import com.djrapitops.plan.command.hooks.PlayerLoggerHook;
import com.djrapitops.plan.command.utils.DataUtils;
import com.djrapitops.plan.command.utils.MiscUtils;
import com.djrapitops.plan.database.Database;
import com.djrapitops.plan.database.databases.MySQLDB;
import com.djrapitops.plan.database.databases.SQLiteDB;
import com.djrapitops.plan.datahandlers.DataHandler;
import com.djrapitops.plan.datahandlers.listeners.PlanChatListener;
import com.djrapitops.plan.datahandlers.listeners.PlanGamemodeChangeListener;
import com.djrapitops.plan.datahandlers.listeners.PlanPlayerListener;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import java.util.HashSet;
import org.bukkit.configuration.ConfigurationSection;
public class Plan extends JavaPlugin {
private final Map<String, Hook> hooks;
private API api;
private final Map<String, Hook> extraHooks;
public Plan() {
this.hooks = new HashMap<>();
this.extraHooks = new HashMap<>();
}
public Map<String, Hook> getHooks() {
return this.hooks;
}
private PlanLiteHook planLiteHook;
private DataHandler handler;
private Database db;
private HashSet<Database> databases;
@Override
public void onEnable() {
getDataFolder().mkdirs();
databases = new HashSet<>();
databases.add(new MySQLDB(this));
databases.add(new SQLiteDB(this));
for (Database database : databases) {
String name = database.getConfigName();
ConfigurationSection section = getConfig().getConfigurationSection(name);
if (section == null) {
section = getConfig().createSection(name);
}
database.getConfigDefaults(section);
if (section.getKeys(false).isEmpty()) {
getConfig().set(name, null);
}
}
getConfig().options().copyDefaults(true);
getConfig().options().header("Plan Config\n"
@ -57,81 +62,39 @@ public class Plan extends JavaPlugin {
saveConfig();
try {
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
PlaceholderAPIHook phAHook = new PlaceholderAPIHook(this);
phAHook.hook();
}
} catch (Exception e) {
logError("Failed to create placeholders.yml");
logToFile("Failed to create placeholders.yml\n" + e);
}
List<String> hookFail = hookInit();
if (this.hooks.isEmpty()) {
logError("Found no plugins to get data (or config set to false). Disabling plugin..");
logToFile("MAIN\nNo Hooks found. Plugin Disabled.");
getServer().getPluginManager().disablePlugin(this);
return;
}
initDatabase();
this.api = new API(this);
hookPlanLite();
this.handler = new DataHandler(this);
registerListeners();
log(MiscUtils.checkVersion());
String loadedMsg = "Hooked into: ";
for (String key : this.hooks.keySet()) {
loadedMsg += ChatColor.GREEN + key + " ";
}
String failedMsg = "Not Hooked: ";
for (String string : hookFail) {
failedMsg += ChatColor.RED + string + " ";
}
Bukkit.getServer().getConsoleSender().sendMessage("[Plan] " + loadedMsg);
if (!hookFail.isEmpty()) {
Bukkit.getServer().getConsoleSender().sendMessage("[Plan] " + failedMsg);
}
getCommand("plan").setExecutor(new PlanCommand(this));
log("Player Analytics Enabled.");
}
public List<String> hookInit() {
this.hooks.clear();
List<String> hookFail = new ArrayList<>();
String[] pluginsArray = {"OnTime", "Essentials", "Towny", "Vault", "Factions", "SuperbVote",
"AdvancedAchievements", "BukkitData", "PlayerLogger"};
List<String> plugins = new ArrayList<>();
plugins.addAll(Arrays.asList(pluginsArray));
StringBuilder errors = new StringBuilder();
errors.append("MAIN-HOOKINIT\n");
plugins.parallelStream().forEach((pluginName) -> {
if (getConfig().getBoolean("visible." + pluginName.toLowerCase())) {
public void hookPlanLite() {
try {
String className = "com.djrapitops.plan.command.hooks." + pluginName + "Hook";
Class<Hook> clazz = (Class<Hook>) Hook.class.forName(className);
this.hooks.put(pluginName, clazz.getConstructor(Plan.class).newInstance(this));
} catch (Exception | NoClassDefFoundError e) {
hookFail.add(pluginName);
errors.append("Failed to hook ").append(pluginName).append("\n").append(e);
errors.append("\n").append(e.getCause());
if (getConfig().getBoolean("enabledData.planLite.pluginEnabled")) {
planLiteHook = new PlanLiteHook(this);
}
} else {
hookFail.add(ChatColor.YELLOW + pluginName);
} catch (NoClassDefFoundError | Exception e) {
}
});
if (!errors.toString().equals("MAIN-HOOKINIT\n")) {
logToFile(errors.toString());
}
for (String extraHook : this.extraHooks.keySet()) {
this.hooks.put(extraHook, this.extraHooks.get(extraHook));
}
return hookFail;
@Deprecated
public List<String> hookInit() {
return new ArrayList<>();
}
@Override
public void onDisable() {
log("Saving cached data..");
handler.saveCachedData();
log("Player Analytics Disabled.");
}
@ -149,7 +112,7 @@ public class Plan extends JavaPlugin {
if (!folder.exists()) {
folder.mkdir();
}
File log = new File(getDataFolder(), "errorlog.txt");
File log = new File(getDataFolder(), "Errors.txt");
try {
if (!log.exists()) {
log.createNewFile();
@ -160,7 +123,7 @@ public class Plan extends JavaPlugin {
pw.flush();
}
} catch (IOException e) {
logError("Failed to create log.txt file");
logError("Failed to create Errors.txt file");
}
}
}
@ -170,12 +133,55 @@ public class Plan extends JavaPlugin {
}
public void addExtraHook(String name, Hook hook) {
try {
this.extraHooks.put(name, hook);
this.hooks.put(name, hook);
log("Registered additional hook: " + name);
} catch (Exception | NoClassDefFoundError e) {
logToFile("Failed to hook " + name + "\n" + e);
if (planLiteHook != null) {
planLiteHook.addExtraHook(name, hook);
} else {
logError(Phrase.ERROR_PLANLITE.toString());
}
}
private void registerListeners() {
getServer().getPluginManager().registerEvents(new PlanChatListener(this), this);
getServer().getPluginManager().registerEvents(new PlanPlayerListener(this), this);
getServer().getPluginManager().registerEvents(new PlanGamemodeChangeListener(this), this);
}
public DataHandler getHandler() {
return handler;
}
public PlanLiteHook getPlanLiteHook() {
return planLiteHook;
}
public Database getDB() {
return db;
}
private boolean initDatabase() {
String type = getConfig().getString("database.type");
db = null;
for (Database database : databases) {
if (type.equalsIgnoreCase(database.getConfigName())) {
this.db = database;
break;
}
}
if (db == null) {
log(Phrase.DATABASE_TYPE_DOES_NOT_EXIST.toString());
return false;
}
if (!db.init()) {
log(Phrase.DATABASE_FAILURE_DISABLE.toString());
setEnabled(false);
return false;
}
return true;
}
}

View File

@ -0,0 +1,33 @@
package com.djrapitops.plan;
import com.djrapitops.plan.api.Hook;
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
public class PlanLiteHook {
private PlanLite planLite;
private Plan plugin;
public PlanLiteHook(Plan plugin) {
try {
this.planLite = getPlugin(PlanLite.class);
if (planLite == null) {
throw new Exception(Phrase.ERROR_PLANLITE.toString());
}
} catch (Exception e) {
plugin.logError(e.toString());
}
}
void addExtraHook(String name, Hook hook) {
try {
if (planLite == null) {
throw new Exception(Phrase.ERROR_PLANLITE.toString());
}
planLite.addExtraHook(name, hook);
plugin.log(Phrase.PLANLITE_REG_HOOK.toString() + name);
} catch (Exception | NoClassDefFoundError e) {
plugin.logError("Failed to hook " + name + "\n " + e);
}
}
}

View File

@ -1,26 +1,30 @@
package com.djrapitops.plan.api;
@Deprecated
public class DataPoint {
private String data;
private final DataType type;
@Deprecated
public DataPoint(String data, DataType type) {
this.data = data;
this.type = type;
}
@Deprecated
public String data() {
return data;
}
@Deprecated
public void setData(String data) {
this.data = data;
}
@Deprecated
public DataType type() {
return type;
}
}

View File

@ -1,6 +1,7 @@
package com.djrapitops.plan.api;
@Deprecated
public enum DataType {
STRING, // Any preformatted data & words
TIME, // Long in milliseconds

View File

@ -0,0 +1,20 @@
package com.djrapitops.plan.api;
public enum Gender {
MALE, FEMALE, OTHER, UNKNOWN;
public static Gender parse(String string) {
switch (string) {
case "female":
return Gender.FEMALE;
case "male":
return Gender.MALE;
case "other":
return Gender.OTHER;
default:
break;
}
return Gender.UNKNOWN;
}
}

View File

@ -1,16 +1,13 @@
package com.djrapitops.plan.api;
import com.djrapitops.plan.Plan;
import java.util.HashMap;
@Deprecated
public interface Hook {
@Deprecated
public HashMap<String, DataPoint> getData(String player) throws Exception;
@Deprecated
public HashMap<String, DataPoint> getAllData(String player) throws Exception;
public default void setPlan(Plan plan) throws Exception {
}
}

View File

@ -26,7 +26,6 @@ public class InfoCommand extends SubCommand {
sender.sendMessage(textColor +"--["+operatorColor+"PLAN - Info"+textColor+"]--");
sender.sendMessage(operatorColor+"Version: "+textColor+plugin.getDescription().getVersion());
sender.sendMessage(textColor+MiscUtils.checkVersion());
sender.sendMessage(operatorColor+"Enabled Hooks: "+textColor+plugin.getHooks().keySet());
return true;
}

View File

@ -1,18 +1,20 @@
package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.Phrase;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.UUIDFetcher;
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.Date;
import java.util.HashMap;
import java.util.List;
import com.djrapitops.plan.api.DataPoint;
import com.djrapitops.plan.api.DataType;
import com.djrapitops.plan.database.UserData;
import java.util.UUID;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@ -29,47 +31,39 @@ public class InspectCommand extends SubCommand {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
String playerName = DataUtils.getPlayerDisplayname(args, sender);
if (this.plugin.getHooks().isEmpty()) {
this.plugin.logError("noHookedPluginsError on InspectCommand");
this.plugin.logToFile("INSPECT\nnoHookedPluginsError on InspectCommand");
return false;
UUID uuid;
try {
uuid = UUIDFetcher.getUUIDOf(playerName);
} catch (Exception e) {
sender.sendMessage(Phrase.USERNAME_NOT_VALID.toString());
return true;
}
boolean allData = false;
boolean format = true;
for (String arg : args) {
if (arg.toLowerCase().equals("-a")) {
allData = true;
}
if (arg.toLowerCase().equals("-r")) {
format = false;
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;
}
Date refreshDate = new Date();
HashMap<String, DataPoint> data = DataUtils.getData(allData, playerName);
if (format && !data.isEmpty()) {
data = DataFormatUtils.removeExtraDataPoints(data);
}
if (data.isEmpty()) {
data.put("ERR-NO RESULTS", new DataPoint("No results were found.", DataType.OTHER));
UserData data = plugin.getHandler().getCurrentData(uuid);
plugin.logToFile("INSPECT-Results\nNo results were found for: " + playerName);
}
List<String[]> dataList = DataFormatUtils.turnDataHashMapToSortedListOfArrays(data);
ChatColor operatorColor = ChatColor.DARK_GREEN;
ChatColor textColor = ChatColor.GRAY;
ChatColor operatorColor = Phrase.COLOR_MAIN.color();
ChatColor textColor = Phrase.COLOR_SEC.color();
//header
sender.sendMessage(textColor + "-- [" + operatorColor + "PLAN - Inspect results: " + playerName +" - took "+DataFormatUtils.formatTimeAmountSinceDate(refreshDate, new Date())+ textColor + "] --");
for (String[] dataString : dataList) {
sender.sendMessage("" + operatorColor + dataString[0].charAt(4) + dataString[0].toLowerCase().substring(5) + ": " + textColor + dataString[1]);
}
sender.sendMessage(data.getUuid().toString());
sender.sendMessage(data.getIps().toString());
sender.sendMessage(""+data.isBanned());
sender.sendMessage(textColor + "-- o --");
return true;
}

View File

@ -1,5 +1,6 @@
package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.Phrase;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.command.CommandType;
import com.djrapitops.plan.command.SubCommand;
@ -24,22 +25,11 @@ public class ReloadCommand extends SubCommand {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
plugin.reloadConfig();
List<String> hookFail = plugin.hookInit();
ChatColor operatorColor = ChatColor.DARK_GREEN;
ChatColor textColor = ChatColor.GRAY;
sender.sendMessage(textColor + "[" + operatorColor + "PLAN" + textColor + "] Config & Hooks reloaded.");
String loadedMsg = " Hooked into: ";
for (String key : plugin.getHooks().keySet()) {
loadedMsg += ChatColor.GREEN + key + " ";
}
String failedMsg = " Not Hooked: ";
for (String string : hookFail) {
failedMsg += ChatColor.RED + string + " ";
}
sender.sendMessage(textColor + loadedMsg);
if (!hookFail.isEmpty()) {
sender.sendMessage(textColor + failedMsg);
}
plugin.hookPlanLite();
ChatColor operatorColor = Phrase.COLOR_MAIN.color();
ChatColor textColor = Phrase.COLOR_SEC.color();
sender.sendMessage(textColor + "[" + operatorColor + "PLAN" + textColor + "] Reload complete.");
return true;
}

View File

@ -46,12 +46,6 @@ public class SearchCommand extends SubCommand {
}
args = DataFormatUtils.parseSearchArgs(args);
HashMap<UUID, HashMap<String, DataPoint>> data = DataUtils.getTotalData(matchingPlayers);
if (this.plugin.getHooks().isEmpty()) {
this.plugin.logError("noHookedPluginsError on SearchCommand");
this.plugin.logToFile("SEARCH\nnoHookedPluginsError on SearchCommand");
return false;
}
Date refreshDate = new Date();
HashMap<String, List<String[]>> dataLists = new HashMap<>();

View File

@ -1,106 +0,0 @@
package com.djrapitops.plan.command.hooks;
import com.djrapitops.plan.api.Hook;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.UUIDFetcher;
import com.djrapitops.plan.api.DataPoint;
import com.djrapitops.plan.api.DataType;
import com.hm.achievement.AdvancedAchievements;
import com.hm.achievement.category.MultipleAchievements;
import com.hm.achievement.category.NormalAchievements;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Optional;
import java.util.UUID;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.OfflinePlayer;
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
public class AdvancedAchievementsHook implements Hook {
private Plan plugin;
private AdvancedAchievements aAPlugin;
private int totalAchievements;
private boolean usingUUID;
public AdvancedAchievementsHook(Plan plugin) throws Exception, NoClassDefFoundError {
this.plugin = plugin;
this.aAPlugin = getPlugin(AdvancedAchievements.class);
// Version was important because 4.0.3 added required method for Offline players
String[] aAVersion = aAPlugin.getDescription().getVersion().split("\\.");
try {
double versionNumber = Double.parseDouble(aAVersion[0] + "." + aAVersion[1] + aAVersion[2]);
if (versionNumber >= 4.03) {
this.usingUUID = true;
} else {
this.usingUUID = false;
plugin.logError("Advanced Achievements 4.0.3 or above required for Offline players");
}
} catch (Exception e) {
// Some versions were formatted with two numbers
try {
double versionNumber = Double.parseDouble(aAVersion[0] + "." + aAVersion[1]);
if (versionNumber >= 4.03) {
this.usingUUID = true;
} else {
this.usingUUID = false;
plugin.logError("Advanced Achievements 4.0.3 or above required for Offline players");
}
} catch (Exception e2) {
plugin.logToFile("AAHOOK\nError getting version number.\n" + e2 + "\n" + e + "\n"
+ aAPlugin.getDescription().getVersion() + "\n" + Arrays.toString(aAVersion));
}
}
// Get total number of Achievements
for (NormalAchievements category : NormalAchievements.values()) {
String categoryName = category.toString();
if (aAPlugin.getDisabledCategorySet().contains(categoryName)) {
continue;
}
totalAchievements += aAPlugin.getPluginConfig().getConfigurationSection(categoryName).getKeys(false).size();
}
for (MultipleAchievements category : MultipleAchievements.values()) {
String categoryName = category.toString();
if (aAPlugin.getDisabledCategorySet().contains(categoryName)) {
continue;
}
for (String item : aAPlugin.getPluginConfig().getConfigurationSection(categoryName).getKeys(false)) {
totalAchievements += aAPlugin.getPluginConfig().getConfigurationSection(categoryName + '.' + item)
.getKeys(false).size();
}
}
if (!aAPlugin.getDisabledCategorySet().contains("Commands")) {
totalAchievements += aAPlugin.getPluginConfig().getConfigurationSection("Commands").getKeys(false).size();
}
}
@Override
public HashMap<String, DataPoint> getData(String player) throws Exception {
HashMap<String, DataPoint> data = new HashMap<>();
try {
UUID uuid = UUIDFetcher.getUUIDOf(player);
OfflinePlayer p = getOfflinePlayer(uuid);
if (p.hasPlayedBefore()) {
if (totalAchievements > 0) {
if (this.usingUUID) {
data.put("AAC-ACHIEVEMENTS", new DataPoint(aAPlugin.getDb().getPlayerAchievementsAmount(uuid.toString()) + " / " + totalAchievements, DataType.AMOUNT_WITH_MAX));
} else {
plugin.log("You're using outdated version of AdvancedAchievements!");
}
}
}
} catch (IllegalArgumentException e) {
}
return data;
}
@Override
public HashMap<String, DataPoint> getAllData(String player) throws Exception {
return getData(player);
}
public boolean isUsingUUID() {
return usingUUID;
}
}

View File

@ -1,59 +0,0 @@
package com.djrapitops.plan.command.hooks;
import com.djrapitops.plan.api.Hook;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.UUIDFetcher;
import com.djrapitops.plan.api.DataPoint;
import com.djrapitops.plan.api.DataType;
import com.google.common.base.Optional;
import java.util.HashMap;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
public class BukkitDataHook implements Hook {
private final Plan plugin;
public BukkitDataHook(Plan p) throws Exception {
plugin = p;
}
@Override
public HashMap<String, DataPoint> getData(String player) throws Exception {
HashMap<String, DataPoint> data = new HashMap<>();
try {
OfflinePlayer p = getOfflinePlayer(UUIDFetcher.getUUIDOf(player));
if (p.hasPlayedBefore()) {
data.put("BUK-REGISTERED", new DataPoint("" + p.getFirstPlayed(), DataType.DATE));
data.put("BUK-LAST LOGIN", new DataPoint("" + p.getLastPlayed(), DataType.DATE));
if (p.isBanned()) {
data.put("BUK-BANNED", new DataPoint("" + p.isBanned(), DataType.BOOLEAN));
}
data.put("BUK-ONLINE", new DataPoint("" + p.isOnline(), DataType.BOOLEAN));
}
} catch (IllegalArgumentException | NullPointerException e) {
}
return data;
}
@Override
public HashMap<String, DataPoint> getAllData(String player) throws Exception {
HashMap<String, DataPoint> data = new HashMap<>();
data.putAll(getData(player));
try {
OfflinePlayer p = getOfflinePlayer(UUIDFetcher.getUUIDOf(player));
if (p.hasPlayedBefore()) {
Location loc = p.getBedSpawnLocation();
if (Optional.of(loc).isPresent()) {
data.put("BUK-BED LOCATION WORLD", new DataPoint(loc.getWorld().getName(), DataType.STRING));
data.put("BUK-BED LOCATION", new DataPoint(" X:" + loc.getBlockX() + " Y:" + loc.getBlockY() + " Z:" + loc.getBlockZ(), DataType.LOCATION));
}
data.put("BUK-UUID", new DataPoint("" + p.getUniqueId(), DataType.OTHER));
}
} catch (IllegalArgumentException | NullPointerException e) {
}
return data;
}
}

View File

@ -1,102 +0,0 @@
package com.djrapitops.plan.command.hooks;
import com.djrapitops.plan.api.Hook;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.UUIDFetcher;
import com.djrapitops.plan.api.DataPoint;
import com.djrapitops.plan.api.DataType;
import java.util.HashMap;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.User;
import net.ess3.api.IEssentials;
import com.earth2me.essentials.craftbukkit.BanLookup;
import java.util.Optional;
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
import org.bukkit.BanList;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
public class EssentialsHook implements Hook {
private IEssentials ess;
private final Plan plugin;
public EssentialsHook(Plan p) throws Exception {
this.ess = getPlugin(Essentials.class);
this.plugin = p;
}
// Gets data with Essentials own User methods
@Override
public HashMap<String, DataPoint> getData(String player) throws Exception {
HashMap<String, DataPoint> data = new HashMap<>();
try {
User user = this.ess.getOfflineUser(player);
OfflinePlayer p = getOfflinePlayer(UUIDFetcher.getUUIDOf(player));
if (p.hasPlayedBefore()) {
if (Optional.of(user).isPresent()) {
if (this.ess.getServer().getBanList(BanList.Type.IP).isBanned(player)
|| BanLookup.isBanned(this.ess, player)) {
data.put("ESS-BANNED", new DataPoint("" + true, DataType.BOOLEAN));
data.put("ESS-BAN REASON", new DataPoint("" + BanLookup.getBanEntry(this.ess, player).getReason(), DataType.STRING));
}
if (user.isJailed()) {
data.put("ESS-JAILED", new DataPoint("" + true, DataType.BOOLEAN));
data.put("ESS-JAIL TIME", new DataPoint("" + user.getJailTimeout(), DataType.TIME_TIMESTAMP));
}
if (user.isMuted()) {
data.put("ESS-MUTED", new DataPoint("" + true, DataType.BOOLEAN));
data.put("ESS-MUTE TIME", new DataPoint("" + user.getMuteTimeout(), DataType.TIME_TIMESTAMP));
}
try {
if (user.isReachable()) {
Location loc = user.getLocation();
data.put("ESS-LOCATION WORLD", new DataPoint(loc.getWorld().getName(), DataType.STRING));
data.put("ESS-LOCATION", new DataPoint(" X:" + loc.getBlockX() + " Y:" + loc.getBlockY() + " Z:" + loc.getBlockZ(), DataType.LOCATION));
} else {
Location loc = user.getLogoutLocation();
data.put("ESS-LOCATION WORLD", new DataPoint(loc.getWorld().getName(), DataType.STRING));
data.put("ESS-LOCATION", new DataPoint("X:" + loc.getBlockX() + " Y:" + loc.getBlockY() + " Z:" + loc.getBlockZ(), DataType.LOCATION));
}
} catch (Exception e) {
this.plugin.logToFile("ESSENTIALSHOOK\n" + e + "\n" + e.getMessage());
}
data.put("ESS-NICKNAME", new DataPoint("" + user.getDisplayName(), DataType.STRING));
if (user.isReachable()) {
data.put("ESS-ONLINE SINCE", new DataPoint("" + user.getLastLogin(), DataType.TIME_TIMESTAMP));
} else {
data.put("ESS-OFFLINE SINCE", new DataPoint("" + user.getLastLogout(), DataType.TIME_TIMESTAMP));
}
}
}
} catch (IllegalArgumentException e) {
}
return data;
}
@Override
public HashMap<String, DataPoint> getAllData(String player) throws Exception {
HashMap<String, DataPoint> data = new HashMap<>();
data.putAll(getData(player));
try {
OfflinePlayer p = getOfflinePlayer(UUIDFetcher.getUUIDOf(player));
if (p.hasPlayedBefore()) {
User user = this.ess.getOfflineUser(player);
if (Optional.of(user).isPresent()) {
data.put("ESS-UUID", new DataPoint("" + user.getBase().getUniqueId().toString(), DataType.OTHER));
data.put("ESS-HEALTH", new DataPoint("" + user.getBase().getHealth(), DataType.AMOUNT));
data.put("ESS-HUNGER", new DataPoint("" + user.getBase().getFoodLevel(), DataType.AMOUNT));
data.put("ESS-XP LEVEL", new DataPoint("" + user.getBase().getLevel(), DataType.AMOUNT));
data.put("ESS-OPPED", new DataPoint("" + user.getBase().isOp(), DataType.BOOLEAN));
data.put("ESS-FLYING", new DataPoint("" + user.getBase().isFlying(), DataType.BOOLEAN));
}
}
} catch (IllegalArgumentException e) {
}
return data;
}
}

View File

@ -1,55 +0,0 @@
package com.djrapitops.plan.command.hooks;
import com.djrapitops.plan.api.Hook;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.UUIDFetcher;
import com.djrapitops.plan.api.DataPoint;
import com.djrapitops.plan.api.DataType;
import com.massivecraft.factions.Factions;
import java.util.HashMap;
import com.massivecraft.factions.entity.MPlayer;
import java.util.UUID;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.OfflinePlayer;
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
public class FactionsHook implements Hook {
private Plan plugin;
private Factions factions;
public FactionsHook(Plan plugin) throws Exception {
this.plugin = plugin;
this.factions = getPlugin(Factions.class);
}
@Override
public HashMap<String, DataPoint> getData(String player) throws Exception {
HashMap<String, DataPoint> data = new HashMap<>();
try {
MPlayer mplayer;
UUID uuid = UUIDFetcher.getUUIDOf(player);
OfflinePlayer p = getOfflinePlayer(uuid);
if (p.hasPlayedBefore()) {
mplayer = MPlayer.get(uuid);
if (mplayer.hasFaction()) {
data.put("FAC-FACTION", new DataPoint(mplayer.getFactionName(), DataType.STRING));
if (mplayer.hasTitle()) {
data.put("FAC-TITLE", new DataPoint(mplayer.getTitle(), DataType.STRING));
}
}
data.put("FAC-POWER", new DataPoint(mplayer.getPowerRounded() + " / " + mplayer.getPowerMax(), DataType.AMOUNT_WITH_MAX));
data.put("FAC-POWER PER HOUR", new DataPoint("" + mplayer.getPowerPerHour(), DataType.AMOUNT));
data.put("FAC-POWER PER DEATH", new DataPoint("" + mplayer.getPowerPerDeath(), DataType.AMOUNT));
}
} catch (IllegalArgumentException e) {
}
return data;
}
@Override
public HashMap<String, DataPoint> getAllData(String player) throws Exception {
return getData(player);
}
}

View File

@ -1,52 +0,0 @@
package com.djrapitops.plan.command.hooks;
import com.djrapitops.plan.api.Hook;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.UUIDFetcher;
import com.djrapitops.plan.api.DataPoint;
import com.djrapitops.plan.api.DataType;
import java.util.HashMap;
import me.edge209.OnTime.OnTimeAPI;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.OfflinePlayer;
public class OnTimeHook implements Hook {
private Plan plugin;
public OnTimeHook(Plan plugin) throws Exception {
this.plugin = plugin;
if (OnTimeAPI.data.LASTLOGIN == null) {
throw new Exception("Ontime not installed.");
}
}
@Override
public HashMap<String, DataPoint> getData(String player) throws Exception {
HashMap<String, DataPoint> data = new HashMap<>();
try {
OfflinePlayer p = getOfflinePlayer(UUIDFetcher.getUUIDOf(player));
if (p.hasPlayedBefore()) {
try {
data.put("ONT-LAST LOGIN", new DataPoint("" + OnTimeAPI.getPlayerTimeData(player, OnTimeAPI.data.LASTLOGIN), DataType.DEPRECATED));
data.put("ONT-TOTAL PLAY", new DataPoint("" + OnTimeAPI.getPlayerTimeData(player, OnTimeAPI.data.TOTALPLAY), DataType.TIME));
data.put("ONT-TOTAL VOTES", new DataPoint("" + OnTimeAPI.getPlayerTimeData(player, OnTimeAPI.data.TOTALVOTE), DataType.AMOUNT));
data.put("ONT-TOTAL REFERRED", new DataPoint("" + OnTimeAPI.getPlayerTimeData(player, OnTimeAPI.data.TOTALREFER), DataType.AMOUNT));
} catch (NoClassDefFoundError e) {
plugin.logToFile("ONTIME HOOK ERROR"
+ "\nOntimeHook enabled but failing, could not get data."
+ "\n" + e
+ "\n" + e.getMessage());
}
}
} catch (IllegalArgumentException e) {
}
return data;
}
@Override
public HashMap<String, DataPoint> getAllData(String player) throws Exception {
return getData(player);
}
}

View File

@ -1,38 +0,0 @@
package com.djrapitops.plan.command.hooks;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.api.DataPoint;
import com.djrapitops.plan.command.utils.DataFormatUtils;
import com.djrapitops.plan.command.utils.DataUtils;
import com.google.common.base.Optional;
import java.util.HashMap;
import me.clip.placeholderapi.external.EZPlaceholderHook;
import org.bukkit.entity.Player;
public class PlaceholderAPIHook extends EZPlaceholderHook {
private final Plan plan;
public PlaceholderAPIHook(Plan plan) {
super(plan, "plan");
this.plan = plan;
}
@Override
public String onPlaceholderRequest(Player player, String identifier) {
HashMap<String, DataPoint> data = DataFormatUtils.removeExtraDataPoints(DataUtils.getData(true, player.getDisplayName()));
String key = identifier.toUpperCase();
if (Optional.of(data.get(key)).isPresent()) {
return data.get(key).data();
} else {
plan.logToFile("PlaceholderAPIHOOK\nFailed to get data\n" + player.getDisplayName() + "\n" + key);
}
return null;
}
@Override
public boolean hook() {
return super.hook();
}
}

View File

@ -1,63 +0,0 @@
package com.djrapitops.plan.command.hooks;
import com.djrapitops.plan.api.Hook;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.UUIDFetcher;
import com.djrapitops.plan.api.DataPoint;
import com.djrapitops.plan.api.DataType;
import java.util.HashMap;
import java.util.UUID;
import me.BadBones69.Logger.SettingsManager;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.file.FileConfiguration;
public class PlayerLoggerHook implements Hook {
private Plan plugin;
public PlayerLoggerHook(Plan plugin) throws Exception, NoClassDefFoundError {
this.plugin = plugin;
SettingsManager.getInstance();
}
@Override
public HashMap<String, DataPoint> getData(String player) throws Exception {
HashMap<String, DataPoint> data = new HashMap<>();
FileConfiguration file = SettingsManager.getInstance().getData();
try {
UUID uuid = UUIDFetcher.getUUIDOf(player);
OfflinePlayer p = getOfflinePlayer(uuid);
if (p.hasPlayedBefore()) {
data.put("PLG-REGISTERED", new DataPoint(file.getString("Players." + uuid + ".DateJoined"), DataType.DEPRECATED));
data.put("PLG-LAST LOGIN", new DataPoint(file.getString("Players." + uuid + ".LastSeen"), DataType.DEPRECATED));
data.put("PLG-TIMES JOINED", new DataPoint(file.getString("Players." + uuid + ".TimePlayed"), DataType.AMOUNT));
data.put("PLG-KILLS", new DataPoint(file.getString("Players." + uuid + ".Kills"), DataType.AMOUNT));
data.put("PLG-DEATHS", new DataPoint(file.getString("Players." + uuid + ".Deaths"), DataType.AMOUNT));
data.put("PLG-TIMES KICKED", new DataPoint(file.getString("Players." + uuid + ".Kicks"), DataType.AMOUNT));
}
} catch (IllegalArgumentException e) {
}
return data;
}
@Override
public HashMap<String, DataPoint> getAllData(String player) throws Exception {
HashMap<String, DataPoint> data = new HashMap<>();
data.putAll(getData(player));
try {
UUID uuid = UUIDFetcher.getUUIDOf(player);
OfflinePlayer p = getOfflinePlayer(uuid);
FileConfiguration file = SettingsManager.getInstance().getData();
if (p.hasPlayedBefore()) {
data.put("PLG-STICKS MADE", new DataPoint(file.getString("Players." + uuid + ".Sticks"), DataType.AMOUNT));
data.put("PLG-STEPS", new DataPoint(file.getString("Players." + uuid + ".Steps"), DataType.AMOUNT));
data.put("PLG-CROUCHES", new DataPoint(file.getString("Players." + uuid + ".Twerks"), DataType.AMOUNT));
}
} catch (IllegalArgumentException e) {
}
return data;
}
}

View File

@ -1,43 +0,0 @@
package com.djrapitops.plan.command.hooks;
import com.djrapitops.plan.api.Hook;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.UUIDFetcher;
import com.djrapitops.plan.api.DataPoint;
import com.djrapitops.plan.api.DataType;
import io.minimum.minecraft.superbvote.SuperbVote;
import java.util.HashMap;
import java.util.UUID;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.OfflinePlayer;
public class SuperbVoteHook implements Hook {
private Plan plugin;
private SuperbVote hookP;
public SuperbVoteHook(Plan plugin) throws Exception {
this.plugin = plugin;
this.hookP = SuperbVote.getPlugin();
}
@Override
public HashMap<String, DataPoint> getData(String player) throws Exception {
HashMap<String, DataPoint> data = new HashMap<>();
try {
UUID uuid = UUIDFetcher.getUUIDOf(player);
OfflinePlayer p = getOfflinePlayer(uuid);
if (p.hasPlayedBefore()) {
data.put("SVO-VOTES", new DataPoint("" + hookP.getVoteStorage().getVotes(uuid), DataType.AMOUNT));
}
} catch (IllegalArgumentException e) {
}
return data;
}
@Override
public HashMap<String, DataPoint> getAllData(String player) throws Exception {
return getData(player);
}
}

View File

@ -1,94 +0,0 @@
package com.djrapitops.plan.command.hooks;
import com.djrapitops.plan.api.Hook;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.UUIDFetcher;
import com.djrapitops.plan.api.DataPoint;
import com.djrapitops.plan.api.DataType;
import com.palmergames.bukkit.towny.Towny;
import static com.palmergames.bukkit.towny.TownyFormatter.getFormattedName;
import static com.palmergames.bukkit.towny.TownyFormatter.lastOnlineFormat;
import static com.palmergames.bukkit.towny.TownyFormatter.registeredFormat;
import com.palmergames.bukkit.towny.exceptions.TownyException;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.TownyUniverse;
import com.palmergames.bukkit.util.BukkitTools;
import java.util.HashMap;
import java.util.List;
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
import static com.palmergames.bukkit.towny.TownyFormatter.getFormattedResidents;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.OfflinePlayer;
public class TownyHook implements Hook {
private final Towny towny;
private final Plan plugin;
public TownyHook(Plan p) throws Exception {
this.towny = getPlugin(Towny.class);
this.plugin = p;
}
@Override
public HashMap<String, DataPoint> getData(String player) throws Exception {
HashMap<String, DataPoint> data = new HashMap<>();
try {
OfflinePlayer p = getOfflinePlayer(UUIDFetcher.getUUIDOf(player));
if (p.hasPlayedBefore()) {
try {
Resident resident = TownyUniverse.getDataSource().getResident(player);
if (resident != null) {
data.put("TOW-ONLINE", new DataPoint("" + BukkitTools.isOnline(player), DataType.BOOLEAN));
data.put("TOW-REGISTERED", new DataPoint(registeredFormat.format(resident.getRegistered()), DataType.DEPRECATED));
data.put("TOW-LAST LOGIN", new DataPoint(lastOnlineFormat.format(resident.getLastOnline()), DataType.DEPRECATED));
data.put("TOW-OWNER OF", new DataPoint(resident.getTownBlocks().size() + " plots", DataType.STRING));
try {
if (resident.hasTown()) {
data.put("TOW-TOWN", new DataPoint(getFormattedName(resident.getTown()), DataType.STRING));
}
if (resident.hasNation()) {
if (!resident.getNationRanks().isEmpty()) {
data.put("TOW-NATION", new DataPoint(resident.getTown().getNation().getName(), DataType.STRING));
}
}
} catch (TownyException e) {
plugin.logToFile("TOWNYHOOK\n" + e + "\n" + e.getMessage());
}
}
} catch (TownyException e) {
plugin.logToFile("TOWNYHOOK\n" + e + "\nError resident: " + player);
}
}
} catch (IllegalArgumentException e) {
}
return data;
}
@Override
public HashMap<String, DataPoint> getAllData(String player) throws Exception {
HashMap<String, DataPoint> data = new HashMap<>();
data.putAll(getData(player));
try {
OfflinePlayer p = getOfflinePlayer(UUIDFetcher.getUUIDOf(player));
if (p.hasPlayedBefore()) {
try {
Resident resident = TownyUniverse.getDataSource().getResident(player);
data.put("TOW-PLOT PERMS", new DataPoint(resident.getPermissions().getColourString(), DataType.STRING));
data.put("TOW-PLOT OPTIONS", new DataPoint("PVP: " + ((resident.getPermissions().pvp) ? "ON" : "OFF") + " Explosions: " + ((resident.getPermissions().explosion) ? "ON" : "OFF") + " Firespread: " + ((resident.getPermissions().fire) ? "ON" : "OFF") + " Mob Spawns: " + ((resident.getPermissions().mobs) ? "ON" : "OFF"), DataType.STRING));
List<Resident> friends = resident.getFriends();
data.put("TOW-FRIENDS", new DataPoint(getFormattedResidents("Friends", friends).toString(), DataType.STRING));
} catch (TownyException e) {
plugin.logToFile("TOWNYHOOK-All\n" + e + "\nError resident: " + player);
}
}
} catch (IllegalArgumentException e) {
}
return data;
}
}

View File

@ -1,44 +0,0 @@
package com.djrapitops.plan.command.hooks;
import com.djrapitops.plan.api.Hook;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.UUIDFetcher;
import com.djrapitops.plan.api.DataPoint;
import com.djrapitops.plan.api.DataType;
import java.util.HashMap;
import java.util.UUID;
import org.bukkit.OfflinePlayer;
import net.milkbowl.vault.economy.Economy;
import static org.bukkit.Bukkit.getOfflinePlayer;
import static org.bukkit.Bukkit.getServer;
public class VaultHook implements Hook {
private Plan plugin;
private Economy econ;
public VaultHook(Plan plugin) throws Exception {
this.plugin = plugin;
this.econ = getServer().getServicesManager().getRegistration(Economy.class).getProvider();
}
@Override
public HashMap<String, DataPoint> getData(String player) throws Exception {
HashMap<String, DataPoint> data = new HashMap<>();
try {
UUID uuid = UUIDFetcher.getUUIDOf(player);
OfflinePlayer p = getOfflinePlayer(uuid);
if (p.hasPlayedBefore()) {
data.put("ECO-BALANCE", new DataPoint(this.econ.format(this.econ.getBalance(p)), DataType.AMOUNT_WITH_LETTERS));
}
} catch (IllegalArgumentException e) {
}
return data;
}
@Override
public HashMap<String, DataPoint> getAllData(String player) throws Exception {
return getData(player);
}
}

View File

@ -1,13 +1,11 @@
package com.djrapitops.plan.command.utils;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.command.hooks.AdvancedAchievementsHook;
import com.djrapitops.plan.api.DataPoint;
import com.djrapitops.plan.api.DataType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
@ -24,14 +22,6 @@ public class Analysis {
String[] ignore = {"ESS-HEALTH", "ESS-HUNGER", "ESS-XP LEVEL", "ESS-OPPED"};
List<String> ignoreKeys = new ArrayList<>();
List<DataType> ignoreTypes = new ArrayList<>();
try {
AdvancedAchievementsHook aaHook = (AdvancedAchievementsHook) plugin.getHooks().get("AdvancedAchievements");
if (!aaHook.isUsingUUID()) {
ignoreKeys.add("AAC-ACHIEVEMENTS");
}
} catch (Exception e) {
ignoreKeys.add("AAC-ACHIEVEMENTS");
}
ignoreKeys.addAll(Arrays.asList(ignore));
ignoreTypes.addAll(Arrays.asList(ignoreType));

View File

@ -1,5 +1,6 @@
package com.djrapitops.plan.command.utils;
import com.djrapitops.plan.Phrase;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.UUIDFetcher;
import com.djrapitops.plan.api.DataPoint;
@ -24,39 +25,12 @@ public class DataUtils {
// returns data given by each Hook
public static HashMap<String, DataPoint> getData(boolean allData, String playerName) {
HashMap<String, DataPoint> data = new HashMap<>();
Plan plugin = getPlugin(Plan.class);
plugin.getHooks().keySet().parallelStream().forEach((hook) -> {
try {
if (allData) {
data.putAll(plugin.getHooks().get(hook).getAllData(playerName));
} else {
data.putAll(plugin.getHooks().get(hook).getData(playerName));
}
} catch (Exception e) {
String toLog = "UTILS-GetData"
+ "\nFailed to getData from " + hook
+ "\n" + e
+ "\ncausing argument: " + playerName;
for (StackTraceElement element : e.getStackTrace()) {
toLog += "\n " + element;
}
plugin.logToFile(toLog);
}
});
return data;
}
// Returns data HashMaps for all pplayers in a HashMap.
public static HashMap<UUID, HashMap<String, DataPoint>> getTotalData(Set<OfflinePlayer> ofPlayers) {
HashMap<UUID, HashMap<String, DataPoint>> playerData = new HashMap<>();
List<OfflinePlayer> players = new ArrayList<>();
players.addAll(ofPlayers);
players.parallelStream()
.filter((player) -> (playerData.get(player.getUniqueId()) == null))
.forEach((player) -> {
playerData.put(player.getUniqueId(), getData(true, player.getName()));
});
return playerData;
}
@ -73,7 +47,7 @@ public class DataUtils {
playerName = "ArgumentGivenError";
plugin.log("No username given, returned empty username.");
plugin.logToFile("INSPECT-GETNAME\nNo username given, returned empty username.\n" + args[0]);
plugin.logToFile(Phrase.ERROR_NO_USERNAME + args[0]);
} else if (sender.hasPermission("plan.inspect.other") || !(sender instanceof Player)) {
playerName = args[0];

View File

@ -0,0 +1,52 @@
package com.djrapitops.plan.database;
import com.djrapitops.plan.Plan;
import org.bukkit.configuration.ConfigurationSection;
import java.util.*;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
public abstract class Database {
private final Plan plugin;
protected boolean cacheAccounts;
public Database(Plan plugin) {
this.plugin = plugin;
}
public boolean init() {
return false;
}
public abstract UserData getUserData(UUID uuid);
public abstract void saveUserData(UUID uuid, UserData data);
public abstract boolean wasSeenBefore(UUID uuid);
public abstract void getConfigDefaults(ConfigurationSection section);
public abstract void clean();
public abstract String getName();
public String getConfigName() {
return getName().toLowerCase().replace(" ", "");
}
public ConfigurationSection getConfigSection() {
return plugin.getConfig().getConfigurationSection(getConfigName());
}
public abstract int getVersion();
public abstract void setVersion(int version);
public abstract void saveServerData(ServerData serverData);
public abstract ServerData getServerData();
}

View File

@ -0,0 +1,50 @@
package com.djrapitops.plan.database;
import com.djrapitops.plan.api.Gender;
public class DemographicsData {
private int age;
private Gender gender;
private String geoLocation;
public DemographicsData(int age, Gender gender, String geoLocation) {
this.age = age;
this.gender = gender;
this.geoLocation = geoLocation;
}
public DemographicsData() {
this(-1, Gender.UNKNOWN, "UNKNOWN");
}
// Getters
public int getAge() {
return age;
}
public Gender getGender() {
return gender;
}
public String getGeoLocation() {
return geoLocation;
}
// Setters
public void setAge(int age) {
this.age = age;
}
public void setGender(Gender gender) {
this.gender = gender;
}
public void setGeoLocation(String geoLocation) {
this.geoLocation = geoLocation;
}
}

View File

@ -0,0 +1,51 @@
package com.djrapitops.plan.database;
import java.util.HashMap;
import org.bukkit.Bukkit;
public class ServerData {
private final HashMap<String, Integer> commandUsage;
private int playersOnline;
private int newPlayers;
public ServerData(HashMap<String, Integer> commandUsage, int newPlayers) {
this.commandUsage = commandUsage;
this.playersOnline = Bukkit.getServer().getOnlinePlayers().size();
this.newPlayers = newPlayers;
}
public void playerJoined(boolean newPlayer) {
updatePlayerCount();
if (newPlayer) {
newPlayers++;
}
}
public void updatePlayerCount() {
playersOnline = Bukkit.getServer().getOnlinePlayers().size();
}
public void playerLeft() {
updatePlayerCount();
}
public void commandRegistered(String command) {
if (!commandUsage.containsKey(command)) {
commandUsage.put(command, 0);
}
commandUsage.put(command, commandUsage.get(command)+1);
}
public HashMap<String, Integer> getCommandUsage() {
return commandUsage;
}
public int getPlayersOnline() {
return playersOnline;
}
public int getNewPlayers() {
return newPlayers;
}
}

View File

@ -0,0 +1,264 @@
package com.djrapitops.plan.database;
import com.djrapitops.plan.database.DemographicsData;
import com.djrapitops.plan.database.Database;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
public class UserData {
private boolean isAccessed;
private UUID uuid;
private Location location;
private List<Location> locations;
private Location bedLocation;
private List<InetAddress> ips;
private List<String> nicknames;
private long registered;
private long lastPlayed;
private long playTime;
private int loginTimes;
private int timesKicked;
private long lastGmSwapTime;
private GameMode lastGamemode;
private HashMap<GameMode, Long> gmTimes;
private boolean isOp;
private boolean isBanned;
private DemographicsData demData;
public UserData(Player player, DemographicsData demData, Database db) {
uuid = player.getUniqueId();
bedLocation = player.getBedSpawnLocation();
registered = player.getFirstPlayed();
location = player.getLocation();
isOp = player.isOp();
locations = new ArrayList<>();
nicknames = new ArrayList<>();
ips = new ArrayList<>();
gmTimes = new HashMap<>();
this.demData = demData;
isBanned = player.isBanned();
}
public UserData(OfflinePlayer player, DemographicsData demData, Database db) {
uuid = player.getUniqueId();
bedLocation = player.getBedSpawnLocation();
registered = player.getFirstPlayed();
isOp = player.isOp();
locations = new ArrayList<>();
nicknames = new ArrayList<>();
ips = new ArrayList<>();
gmTimes = new HashMap<>();
this.demData = demData;
isBanned = player.isBanned();
}
public UserData(OfflinePlayer player, DemographicsData demData) {
uuid = player.getUniqueId();
bedLocation = player.getBedSpawnLocation();
registered = player.getFirstPlayed();
isOp = player.isOp();
locations = new ArrayList<>();
nicknames = new ArrayList<>();
ips = new ArrayList<>();
gmTimes = new HashMap<>();
this.demData = demData;
isBanned = player.isBanned();
}
public void addIpAddress(InetAddress ip) {
if (!ips.contains(ip)) {
ips.add(ip);
}
}
public void addIpAddresses(Collection<InetAddress> addIps) {
ips.addAll(addIps);
}
public void addLocation(Location loc) {
locations.add(loc);
location = locations.get(locations.size()-1);
}
public void addLocations(Collection<Location> addLocs) {
locations.addAll(addLocs);
location = locations.get(locations.size()-1);
}
public void addNickname(String nick) {
if (!nicknames.contains(nick)) {
nicknames.add(nick);
}
}
public void addNicknames(Collection<String> addNicks) {
nicknames.addAll(addNicks);
}
public void setGMTime(GameMode gm, long time) {
gmTimes.put(gm, time);
}
public void setAllGMTimes(long survivalTime, long creativeTime, long adventureTime, long spectatorTime) {
gmTimes.clear();
gmTimes.put(GameMode.SURVIVAL, survivalTime);
gmTimes.put(GameMode.CREATIVE, creativeTime);
gmTimes.put(GameMode.ADVENTURE, adventureTime);
gmTimes.put(GameMode.SPECTATOR, spectatorTime);
}
public void updateBanned(Player p) {
isBanned = p.isBanned();
}
public boolean isAccessed() {
return isAccessed;
}
public void setAccessing(boolean value) {
isAccessed = value;
}
// Getters -------------------------------------------------------------
public UUID getUuid() {
return uuid;
}
public Location getLocation() {
return location;
}
public List<Location> getLocations() {
return locations;
}
public Location getBedLocation() {
return bedLocation;
}
public List<InetAddress> getIps() {
return ips;
}
public List<String> getNicknames() {
return nicknames;
}
public long getRegistered() {
return registered;
}
public long getLastPlayed() {
return lastPlayed;
}
public long getPlayTime() {
return playTime;
}
public int getLoginTimes() {
return loginTimes;
}
public int getTimesKicked() {
return timesKicked;
}
public HashMap<GameMode, Long> getGmTimes() {
return gmTimes;
}
public long getLastGmSwapTime() {
return lastGmSwapTime;
}
public GameMode getLastGamemode() {
return lastGamemode;
}
public boolean isOp() {
return isOp;
}
public boolean isBanned() {
return isBanned;
}
public DemographicsData getDemData() {
return demData;
}
// Setters -------------------------------------------------------------
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
public void setLocation(Location location) {
this.location = location;
}
public void setLocations(List<Location> locations) {
this.locations = locations;
}
public void setBedLocation(Location bedLocation) {
this.bedLocation = bedLocation;
}
public void setIps(List<InetAddress> ips) {
this.ips = ips;
}
public void setNicknames(List<String> nicknames) {
this.nicknames = nicknames;
}
public void setRegistered(long registered) {
this.registered = registered;
}
public void setLastPlayed(long lastPlayed) {
this.lastPlayed = lastPlayed;
}
public void setPlayTime(long playTime) {
this.playTime = playTime;
}
public void setLoginTimes(int loginTimes) {
this.loginTimes = loginTimes;
}
public void setTimesKicked(int timesKicked) {
this.timesKicked = timesKicked;
}
public void setGmTimes(HashMap<GameMode, Long> gmTimes) {
this.gmTimes = gmTimes;
}
public void setLastGmSwapTime(long lastGmSwapTime) {
this.lastGmSwapTime = lastGmSwapTime;
}
public void setLastGamemode(GameMode lastGamemode) {
this.lastGamemode = lastGamemode;
}
public void setIsOp(boolean isOp) {
this.isOp = isOp;
}
public void setDemData(DemographicsData demData) {
this.demData = demData;
}
}

View File

@ -0,0 +1,72 @@
package com.djrapitops.plan.database.databases;
import com.djrapitops.plan.Plan;
import org.bukkit.configuration.ConfigurationSection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class MySQLDB extends SQLDB {
public MySQLDB(Plan plugin) {
super(plugin, true);
}
@Override
protected Connection getNewConnection() {
ConfigurationSection config = getConfigSection();
setUserName(config.getString("tables.users"));
setLocationName(config.getString("tables.locations"));
setNicknamesName(config.getString("tables.nicknames"));
setGamemodetimesName(config.getString("tables.gamemodes"));
setIpsName(config.getString("tables.ips"));
setCommanduseName(config.getString("tables.commandusages"));
setServerdataName(config.getString("tables.serverdata"));
try {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://" + config.getString("host") + ":" + config.getString("port") + "/" + config.getString("database");
return DriverManager.getConnection(url, config.getString("user"), config.getString("password"));
} catch (ClassNotFoundException | SQLException e) {
return null;
}
}
private ConfigurationSection getSection(ConfigurationSection parent, String childName) {
ConfigurationSection child = parent.getConfigurationSection(childName);
if (child == null) {
child = parent.createSection(childName);
}
return child;
}
@Override
public void getConfigDefaults(ConfigurationSection section) {
section.addDefault("host", "localhost");
section.addDefault("port", 3306);
section.addDefault("user", "root");
section.addDefault("password", "minecraft");
section.addDefault("database", "Plan");
ConfigurationSection tables = getSection(section, "tables");
tables.addDefault("users", "plan_users");
tables.addDefault("locations", "plan_locations");
tables.addDefault("nicknames", "plan_nicknames");
tables.addDefault("gamemodetimes", "plan_gamemodetimes");
tables.addDefault("ips", "plan_ips");
tables.addDefault("commandusages", "plan_commandusages");
tables.addDefault("serverdata", "plan_serverdata");
}
@Override
public String getName() {
return "MySQL";
}
}

View File

@ -0,0 +1,763 @@
package com.djrapitops.plan.database.databases;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.api.Gender;
import com.djrapitops.plan.database.Database;
import com.djrapitops.plan.database.DemographicsData;
import com.djrapitops.plan.database.ServerData;
import com.djrapitops.plan.database.UserData;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.GameMode;
import org.bukkit.Location;
public abstract class SQLDB extends Database {
private final Plan plugin;
private final boolean supportsModification;
private Connection connection;
private String userName;
private String locationName;
private String serverdataName;
private String commanduseName;
private String gamemodetimesName;
private String nicknamesName;
private String ipsName;
private String userColumnUUID;
private final String userColumnID;
private String userColumnPlayTime;
private String userColumnDemGeoLocation;
private String userColumnDemAge;
private String userColumnDemGender;
private String userColumnLastGM;
private String userColumnLastGMSwapTime;
private final String locationColumnUserID;
private String locationColumnID;
private String locationColumnCoordinatesX;
private String locationColumnCoordinatesZ;
private String locationColumnWorld;
private String serverdataColumnDate;
private String serverdataColumnPlayersOnline;
private String serverdataColumnNewPlayers;
private String commanduseColumnCommand;
private String commanduseColumnTimesUsed;
private final String gamemodetimesColumnUserID;
private String gamemodetimesColumnGamemode;
private String gamemodetimesColumnTime;
private String nicknamesColumnUserID;
private String nicknamesColumnNick;
private final String ipsColumnUserID;
private String ipsColumnIP;
private String versionName;
public SQLDB(Plan plugin, boolean supportsModification) {
super(plugin);
this.plugin = plugin;
this.supportsModification = supportsModification;
userName = "plan_users";
locationName = "plan_locations";
nicknamesName = "plan_nicknames";
commanduseName = "plan_commandusages";
gamemodetimesName = "plan_gamemodetimes";
serverdataName = "plan_serverdata";
ipsName = "plan_ips";
userColumnID = "id";
locationColumnID = "id";
userColumnUUID = "uuid";
locationColumnUserID = "user_id";
nicknamesColumnUserID = "user_id";
gamemodetimesColumnUserID = "user_id";
ipsColumnUserID = "user_id";
userColumnDemAge = "age";
userColumnDemGender = "gender";
userColumnDemGeoLocation = "geolocation";
userColumnLastGM = "last_gamemode";
userColumnLastGMSwapTime = "last_gamemode_swap";
userColumnPlayTime = "play_time";
locationColumnCoordinatesX = "x";
locationColumnCoordinatesZ = "z";
locationColumnWorld = "world_name";
nicknamesColumnNick = "nickname";
gamemodetimesColumnGamemode = "gamemode";
gamemodetimesColumnTime = "time";
ipsColumnIP = "ip";
commanduseColumnCommand = "command";
commanduseColumnTimesUsed = "times_used";
serverdataColumnDate = "date";
serverdataColumnNewPlayers = "new_players";
serverdataColumnPlayersOnline = "players_online";
versionName = "plan_version";
plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
@Override
public void run() {
try {
if (connection != null && !connection.isClosed()) {
connection.createStatement().execute("/* ping */ SELECT 1");
}
} catch (SQLException e) {
connection = getNewConnection();
}
}
}, 60 * 20, 60 * 20);
}
@Override
public boolean init() {
super.init();
return checkConnection();
}
public boolean checkConnection() {
try {
if (connection == null || connection.isClosed()) {
connection = getNewConnection();
if (connection == null || connection.isClosed()) {
return false;
}
ResultSet set = connection.prepareStatement(supportsModification ? ("SHOW TABLES LIKE '" + userName + "'") : "SELECT name FROM sqlite_master WHERE type='table' AND name='" + userName + "'").executeQuery();
// boolean newDatabase = set.next();
set.close();
query("CREATE TABLE IF NOT EXISTS " + userName + " ("
+ userColumnID + " int NOT NULL PRIMARY KEY, "
+ userColumnUUID + " varchar(36) NOT NULL, "
+ userColumnDemAge + " int NOT NULL, "
+ userColumnDemGender + " varchar(8) NOT NULL, "
+ userColumnDemGeoLocation + " varchar(50) NOT NULL, "
+ userColumnLastGM + " varchar(15) NOT NULL, "
+ userColumnLastGMSwapTime + " bigint NOT NULL, "
+ userColumnPlayTime + " bigint NOT NULL"
+ ")"
);
query("CREATE TABLE IF NOT EXISTS " + locationName + " ("
+ locationColumnID + " int NOT NULL, "
+ locationColumnUserID + " int NOT NULL, "
+ locationColumnCoordinatesX + " int NOT NULL, "
+ locationColumnCoordinatesZ + " int NOT NULL, "
+ locationColumnWorld + " varchar(64) NOT NULL, "
+ "FOREIGN KEY(" + locationColumnUserID + ") REFERENCES " + userName + "(" + userColumnID + ")"
+ ")"
);
query("CREATE TABLE IF NOT EXISTS " + gamemodetimesName + " ("
+ gamemodetimesColumnUserID + " int NOT NULL, "
+ gamemodetimesColumnGamemode + " varchar(15) NOT NULL, "
+ gamemodetimesColumnTime + " bigint NOT NULL, "
+ "FOREIGN KEY(" + gamemodetimesColumnUserID + ") REFERENCES " + userName + "(" + userColumnID + ")"
+ ")"
);
query("CREATE TABLE IF NOT EXISTS " + ipsName + " ("
+ ipsColumnUserID + " int NOT NULL, "
+ ipsColumnIP + " varchar(20) NOT NULL, "
+ "FOREIGN KEY(" + ipsColumnUserID + ") REFERENCES " + userName + "(" + userColumnID + ")"
+ ")"
);
query("CREATE TABLE IF NOT EXISTS " + nicknamesName + " ("
+ nicknamesColumnUserID + " int NOT NULL, "
+ nicknamesColumnNick + " varchar(30) NOT NULL, "
+ "FOREIGN KEY(" + nicknamesColumnUserID + ") REFERENCES " + userName + "(" + userColumnID + ")"
+ ")"
);
query("CREATE TABLE IF NOT EXISTS " + commanduseName + " ("
+ commanduseColumnCommand + " varchar(20) NOT NULL, "
+ commanduseColumnTimesUsed + " int NOT NULL"
+ ")"
);
query("CREATE TABLE IF NOT EXISTS " + serverdataName + " ("
+ serverdataColumnDate + " bigint NOT NULL, "
+ serverdataColumnNewPlayers + " int NOT NULL, "
+ serverdataColumnPlayersOnline + " int NOT NULL"
+ ")"
);
query("CREATE TABLE IF NOT EXISTS " + versionName + " ("
+ "version int NOT NULL"
+ ")"
);
}
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return true;
}
protected abstract Connection getNewConnection();
public boolean query(String sql) throws SQLException {
return connection.createStatement().execute(sql);
}
public void close() {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
@Override
public int getVersion() {
checkConnection();
int version = 0;
try {
ResultSet set = connection.prepareStatement("SELECT * from " + versionName).executeQuery();
if (set.next()) {
version = set.getInt("version");
}
set.close();
return version;
} catch (Exception e) {
e.printStackTrace();
return version;
}
}
@Override
public void setVersion(int version) {
checkConnection();
try {
connection.prepareStatement("DELETE FROM " + versionName).executeUpdate();
connection.prepareStatement("INSERT INTO " + versionName + " (version) VALUES (" + version + ")").executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
@Override
public boolean wasSeenBefore(UUID uuid) {
return getUserId(uuid.toString()) != -1;
}
private int getUserId(String uuid) {
int userId = -1;
try {
PreparedStatement statement = connection.prepareStatement("SELECT "+userColumnID+" FROM " + userName + " WHERE UPPER(" + userColumnUUID + ") LIKE UPPER(?)");
statement.setString(1, uuid);
ResultSet set = statement.executeQuery();
while (set.next()) {
userId = set.getInt(userColumnID);
}
set.close();
} catch (SQLException | NullPointerException e) {
e.printStackTrace();
}
return userId;
}
@Override
public UserData getUserData(UUID uuid) {
checkConnection();
try {
PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + userName + " WHERE UPPER(" + userColumnUUID + ") LIKE UPPER(?)");
statement.setString(1, uuid.toString());
ResultSet set = statement.executeQuery();
UserData data = new UserData(getOfflinePlayer(uuid), new DemographicsData());
String id = null;
while (set.next()) {
id = set.getString(userColumnID);
if (id == null) {
return null;
}
data.getDemData().setAge(set.getInt(userColumnDemAge));
data.getDemData().setGender(Gender.parse(set.getString(userColumnDemGender)));
data.getDemData().setGeoLocation(set.getString(userColumnDemGeoLocation));
data.setLastGamemode(GameMode.valueOf(userColumnLastGM));
data.setLastGmSwapTime(set.getLong(userColumnLastGMSwapTime));
data.setPlayTime(set.getLong(userColumnPlayTime));
}
set.close();
statement = connection.prepareStatement("SELECT * FROM " + locationName + " WHERE UPPER(" + locationColumnUserID + ") LIKE UPPER(?)");
statement.setString(1, id);
set = statement.executeQuery();
List<Location> locations = new ArrayList<>();
while (set.next()) {
locations.add(new Location(Bukkit.getWorld(set.getString(locationColumnWorld)), set.getInt(locationColumnCoordinatesX), 0, set.getInt(locationColumnCoordinatesZ)));
}
set.close();
data.addLocations(locations);
if (locations.isEmpty()) {
plugin.logToFile("DATABASE-SQLDB\nLocations list is empty");
} else {
data.setLocation(locations.get(locations.size() - 1));
}
statement = connection.prepareStatement("SELECT * FROM " + nicknamesName + " WHERE UPPER(" + nicknamesColumnUserID + ") LIKE UPPER(?)");
statement.setString(1, id);
set = statement.executeQuery();
List<String> nicknames = new ArrayList<>();
while (set.next()) {
nicknames.add(set.getString(nicknamesColumnNick));
}
set.close();
data.addNicknames(nicknames);
statement = connection.prepareStatement("SELECT * FROM " + ipsName + " WHERE UPPER(" + ipsColumnUserID + ") LIKE UPPER(?)");
statement.setString(1, id);
set = statement.executeQuery();
List<InetAddress> ips = new ArrayList<>();
while (set.next()) {
try {
ips.add(InetAddress.getByName(set.getString(ipsColumnIP)));
} catch (SQLException | UnknownHostException e) {
}
}
set.close();
data.addIpAddresses(ips);
statement = connection.prepareStatement("SELECT * FROM " + gamemodetimesName + " WHERE UPPER(" + gamemodetimesColumnUserID + ") LIKE UPPER(?)");
statement.setString(1, id);
set = statement.executeQuery();
HashMap<GameMode, Long> times = new HashMap<>();
while (set.next()) {
times.put(GameMode.valueOf(set.getString(gamemodetimesColumnGamemode)), set.getLong(gamemodetimesColumnTime));
}
set.close();
data.setGmTimes(times);
return data;
} catch (SQLException e) {
plugin.logToFile("DATABASE-SQLDB\n" + e + "\n" + e.getCause());
return null;
}
}
@Override
public ServerData getServerData() {
HashMap<String, Integer> commandUse = getCommandUse();
int newPlayers = 0;
try{
PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + serverdataName
+"ORDER BY "+serverdataColumnDate+" ASC LIMIT 1");
ResultSet set = statement.executeQuery();
while (set.next()) {
newPlayers = set.getInt(serverdataColumnNewPlayers);
}
set.close();
} catch (SQLException e) {
plugin.logToFile("DATABASE-SQLDB-GetServerData\n" + e + "\n" + e.getCause());
return null;
}
return new ServerData(commandUse, newPlayers);
}
@Override
public void saveServerData(ServerData data) {
saveCommandUse(data.getCommandUsage());
}
private void saveCommandUse(HashMap<String, Integer> data) {
try {
PreparedStatement statement = connection.prepareStatement(
"DELETE FROM " + commanduseName);
statement.execute();
for (String key : data.keySet()) {
statement = connection.prepareStatement("INSERT INTO " + commanduseName + " ("
+ commanduseColumnCommand + ", "
+ commanduseColumnTimesUsed
+ ") VALUES (?, ?)");
statement.setString(1, key);
statement.setInt(2, data.get(key));
statement.execute();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
private HashMap<String, Integer> getCommandUse() {
HashMap<String, Integer> commandUse = new HashMap<>();
try{
PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + commanduseName);
ResultSet set = statement.executeQuery();
while (set.next()) {
commandUse.put(set.getString(commanduseColumnCommand), set.getInt(commanduseColumnTimesUsed));
}
set.close();
} catch (SQLException e) {
plugin.logToFile("DATABASE-SQLDB\n" + e + "\n" + e.getCause());
}
return commandUse;
}
public void removeAccount(String uuid) {
checkConnection();
int userId = getUserId(uuid);
if (userId == -1) {
return;
}
PreparedStatement statement;
try {
statement = connection.prepareStatement("DELETE FROM " + userName + " WHERE UPPER(" + userColumnUUID + ") LIKE UPPER(?)");
statement.setString(1, uuid);
statement.execute();
statement = connection.prepareStatement("DELETE FROM " + locationName + " WHERE UPPER(" + locationColumnUserID + ") LIKE UPPER(?)");
statement.setString(1, "" + userId);
statement.execute();
statement = connection.prepareStatement("DELETE FROM " + nicknamesName + " WHERE UPPER(" + nicknamesColumnUserID + ") LIKE UPPER(?)");
statement.setString(1, "" + userId);
statement.execute();
statement = connection.prepareStatement("DELETE FROM " + gamemodetimesName + " WHERE UPPER(" + gamemodetimesColumnUserID + ") LIKE UPPER(?)");
statement.setString(1, "" + userId);
statement.execute();
statement = connection.prepareStatement("DELETE FROM " + ipsName + " WHERE UPPER(" + ipsColumnIP + ") LIKE UPPER(?)");
statement.setString(1, "" + userId);
statement.execute();
} catch (SQLException e) {
plugin.logToFile("DATABASE_SQLDB\n" + e + "\n" + e.getCause());
}
}
@Override
public void saveUserData(UUID uuid, UserData data) {
checkConnection();
int userId = getUserId(uuid.toString());
try {
String sql = "UPDATE " + userName + " SET "
+ userColumnDemAge + "=?, "
+ userColumnDemGender + "=? "
+ userColumnDemGeoLocation + "=? "
+ userColumnLastGM + "=? "
+ userColumnLastGMSwapTime + "=? "
+ userColumnPlayTime + "=? "
+ "WHERE UPPER(" + userColumnUUID + ") LIKE UPPER(?)";
PreparedStatement statement = connection.prepareStatement(sql);
statement.setInt(1, data.getDemData().getAge());
statement.setString(2, data.getDemData().getGender().toString());
statement.setString(3, data.getDemData().getGeoLocation());
statement.setString(4, data.getLastGamemode().name());
statement.setLong(5, data.getLastGmSwapTime());
statement.setLong(6, data.getPlayTime());
if (statement.executeUpdate() == 0) {
statement = connection.prepareStatement("INSERT INTO " + userName + " ("
+ userColumnID + ", "
+ userColumnUUID + ", "
+ userColumnDemAge + ", "
+ userColumnDemGender + ", "
+ userColumnDemGeoLocation + ", "
+ userColumnLastGM + ", "
+ userColumnLastGMSwapTime + ", "
+ userColumnPlayTime
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
statement.setInt(1, userId);
statement.setString(2, uuid.toString());
statement.setInt(3, data.getDemData().getAge());
statement.setString(4, data.getDemData().getGender().toString());
statement.setString(5, data.getDemData().getGeoLocation());
statement.setString(6, data.getLastGamemode().name());
statement.setLong(7, data.getLastGmSwapTime());
statement.setLong(8, data.getPlayTime());
statement.execute();
}
saveLocationList(userId, data.getLocations());
saveNickList(userId, data.getNicknames());
saveIPList(userId, data.getIps());
saveGMTimes(userId, data.getGmTimes());
} catch (SQLException e) {
e.printStackTrace();
}
}
public void saveLocationList(int userId, List<Location> locations) {
try {
PreparedStatement statement = connection.prepareStatement(
"DELETE FROM " + locationName + " WHERE UPPER(" + locationColumnUserID + ") LIKE UPPER(?)");
statement.setString(1, "" + userId);
statement.execute();
for (int i = 0; i < locations.size(); i++) {
Location location = locations.get(i);
statement = connection.prepareStatement("INSERT INTO " + locationName + " ("
+ locationColumnID + ", "
+ locationColumnUserID + ", "
+ locationColumnCoordinatesX + ", "
+ locationColumnCoordinatesZ + ", "
+ locationColumnWorld
+ ") VALUES (?, ?, ?, ?, ?)");
statement.setInt(1, i);
statement.setInt(2, userId);
statement.setInt(3, location.getBlockX());
statement.setInt(4, location.getBlockZ());
statement.setString(5, location.getWorld().getName());
statement.execute();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public void saveNickList(int userId, List<String> names) {
try {
PreparedStatement statement = connection.prepareStatement(
"DELETE FROM " + nicknamesName + " WHERE UPPER(" + nicknamesColumnUserID + ") LIKE UPPER(?)");
statement.setString(1, "" + userId);
statement.execute();
for (String name : names) {
statement = connection.prepareStatement("INSERT INTO " + nicknamesName + " ("
+ nicknamesColumnUserID + ", "
+ nicknamesColumnNick
+ ") VALUES (?, ?)");
statement.setInt(1, userId);
statement.setString(2, name);
statement.execute();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public void saveIPList(int userId, List<InetAddress> ips) {
try {
PreparedStatement statement = connection.prepareStatement(
"DELETE FROM " + ipsName + " WHERE UPPER(" + ipsColumnUserID + ") LIKE UPPER(?)");
statement.setString(1, "" + userId);
statement.execute();
for (InetAddress ip : ips) {
statement = connection.prepareStatement("INSERT INTO " + ipsName + " ("
+ ipsColumnUserID + ", "
+ ipsColumnIP
+ ") VALUES (?, ?)");
statement.setInt(1, userId);
statement.setString(2, ip.getHostAddress());
statement.execute();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public void saveGMTimes(int userId, HashMap<GameMode, Long> gamemodeTimes) {
try {
PreparedStatement statement = connection.prepareStatement(
"DELETE FROM " + gamemodetimesName + " WHERE UPPER(" + gamemodetimesColumnUserID + ") LIKE UPPER(?)");
statement.setString(1, "" + userId);
statement.execute();
for (GameMode gm : gamemodeTimes.keySet()) {
statement = connection.prepareStatement("INSERT INTO " + gamemodetimesName + " ("
+ gamemodetimesColumnUserID + ", "
+ gamemodetimesColumnGamemode + ", "
+ gamemodetimesColumnTime
+ ") VALUES (?, ?, ?)");
statement.setInt(1, userId);
statement.setString(2, gm.name());
statement.setLong(3, gamemodeTimes.get(gm));
statement.execute();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public void clean() {
checkConnection();
plugin.log("DATABASE-SQLDB\nCleaning DB not implemented");
}
public void removeAllData() {
checkConnection();
try {
connection.prepareStatement("DELETE FROM " + userName).executeUpdate();
connection.prepareStatement("DELETE FROM " + locationName).executeUpdate();
connection.prepareStatement("DELETE FROM " + nicknamesName).executeUpdate();
connection.prepareStatement("DELETE FROM " + ipsName).executeUpdate();
connection.prepareStatement("DELETE FROM " + gamemodetimesName).executeUpdate();
connection.prepareStatement("DELETE FROM " + serverdataName).executeUpdate();
connection.prepareStatement("DELETE FROM " + commanduseName).executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
// Setters ---
public void setUserName(String userName) {
this.userName = userName;
}
public void setLocationName(String locationName) {
this.locationName = locationName;
}
public void setServerdataName(String serverdataName) {
this.serverdataName = serverdataName;
}
public void setCommanduseName(String commanduseName) {
this.commanduseName = commanduseName;
}
public void setGamemodetimesName(String gamemodetimesName) {
this.gamemodetimesName = gamemodetimesName;
}
public void setNicknamesName(String nicknamesName) {
this.nicknamesName = nicknamesName;
}
public void setIpsName(String ipsName) {
this.ipsName = ipsName;
}
public void setUserColumnUUID(String userColumnUUID) {
this.userColumnUUID = userColumnUUID;
}
public void setUserColumnPlayTime(String userColumnPlayTime) {
this.userColumnPlayTime = userColumnPlayTime;
}
public void setUserColumnDemGeoLocation(String userColumnDemGeoLocation) {
this.userColumnDemGeoLocation = userColumnDemGeoLocation;
}
public void setUserColumnDemAge(String userColumnDemAge) {
this.userColumnDemAge = userColumnDemAge;
}
public void setUserColumnDemGender(String userColumnDemGender) {
this.userColumnDemGender = userColumnDemGender;
}
public void setUserColumnLastGM(String userColumnLastGM) {
this.userColumnLastGM = userColumnLastGM;
}
public void setUserColumnLastGMSwapTime(String userColumnLastGMSwapTime) {
this.userColumnLastGMSwapTime = userColumnLastGMSwapTime;
}
public void setLocationColumnCoordinatesZ(String locationColumnCoordinates) {
this.locationColumnCoordinatesZ = locationColumnCoordinates;
}
public void setLocationColumnCoordinatesX(String locationColumnCoordinates) {
this.locationColumnCoordinatesX = locationColumnCoordinates;
}
public void setLocationColumnWorld(String locationColumnWorld) {
this.locationColumnWorld = locationColumnWorld;
}
public void setServerdataColumnDate(String serverdataColumnDate) {
this.serverdataColumnDate = serverdataColumnDate;
}
public void setServerdataColumnPlayersOnline(String serverdataColumnPlayersOnline) {
this.serverdataColumnPlayersOnline = serverdataColumnPlayersOnline;
}
public void setServerdataColumnNewPlayers(String serverdataColumnNewPlayers) {
this.serverdataColumnNewPlayers = serverdataColumnNewPlayers;
}
public void setCommanduseColumnCommand(String commanduseColumnCommand) {
this.commanduseColumnCommand = commanduseColumnCommand;
}
public void setCommanduseColumnTimesUsed(String commanduseColumnTimesUsed) {
this.commanduseColumnTimesUsed = commanduseColumnTimesUsed;
}
public void setGamemodetimesColumnGamemode(String gamemodetimesColumnGamemode) {
this.gamemodetimesColumnGamemode = gamemodetimesColumnGamemode;
}
public void setGamemodetimesColumnTime(String gamemodetimesColumnTime) {
this.gamemodetimesColumnTime = gamemodetimesColumnTime;
}
public void setNicknamesColumnUserID(String nicknamesColumnUserID) {
this.nicknamesColumnUserID = nicknamesColumnUserID;
}
public void setNicknamesColumnNick(String nicknamesColumnNick) {
this.nicknamesColumnNick = nicknamesColumnNick;
}
public void setIpsColumnIP(String ipsColumnIP) {
this.ipsColumnIP = ipsColumnIP;
}
}

View File

@ -0,0 +1,41 @@
package com.djrapitops.plan.database.databases;
import com.djrapitops.plan.Plan;
import org.bukkit.configuration.ConfigurationSection;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class SQLiteDB extends SQLDB {
private final Plan plugin;
public SQLiteDB(Plan plugin) {
super(plugin, false);
this.plugin = plugin;
}
@Override
public Connection getNewConnection() {
try {
Class.forName("org.sqlite.JDBC");
return DriverManager.getConnection("jdbc:sqlite:" + new File(plugin.getDataFolder(), "database.db").getAbsolutePath());
} catch (ClassNotFoundException | SQLException e) {
return null;
}
}
@Override
public void getConfigDefaults(ConfigurationSection section) {
}
@Override
public String getName() {
return "SQLite";
}
}

View File

@ -0,0 +1,41 @@
package com.djrapitops.plan.datahandlers;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.database.UserData;
import java.util.Date;
import java.util.UUID;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class ActivityHandler {
private final Plan plugin;
private final DataHandler handler;
public ActivityHandler(Plan plugin, DataHandler h) {
this.plugin = plugin;
this.handler = h;
}
public boolean isFirstTimeJoin(UUID uuid) {
return !handler.getDB().wasSeenBefore(uuid);
}
public void saveToCache(Player player, UserData data) {
long timeNow = new Date().getTime();
data.setPlayTime(data.getPlayTime()+(data.getLastPlayed()-timeNow));
data.setLastPlayed(timeNow);
}
public void handleLogIn(PlayerLoginEvent event, UserData data) {
data.setLastPlayed(new Date().getTime());
data.updateBanned(event.getPlayer());
}
public void handleLogOut(PlayerQuitEvent event, UserData data) {
Player player = event.getPlayer();
data.setPlayTime(data.getPlayTime()+(data.getLastPlayed()-new Date().getTime()));
data.setLastPlayed(player.getLastPlayed());
}
}

View File

@ -0,0 +1,34 @@
package com.djrapitops.plan.datahandlers;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.database.UserData;
import java.util.Date;
import java.util.UUID;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class BasicInfoHandler {
private DataHandler handler;
public BasicInfoHandler(Plan plugin, DataHandler h) {
this.handler = h;
}
public void save(Player player) {
}
public void handleLogIn(PlayerLoginEvent event) {
Player player = event.getPlayer();
UserData data = handler.getCurrentData(player.getUniqueId());
data.addNickname(player.getDisplayName());
data.addIpAddress(event.getAddress());
}
public void handleLogOut(PlayerQuitEvent event) {
Player player = event.getPlayer();
UserData data = handler.getCurrentData(player.getUniqueId());
}
}

View File

@ -0,0 +1,150 @@
package com.djrapitops.plan.datahandlers;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.database.Database;
import com.djrapitops.plan.database.DemographicsData;
import com.djrapitops.plan.database.UserData;
import com.djrapitops.plan.database.ServerData;
import java.util.HashMap;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class DataHandler {
private final HashMap<UUID, UserData> dataCache;
private final Plan plugin;
private final ActivityHandler activityHandler;
private final GamemodeTimesHandler gamemodeTimesHandler;
private final LocationHandler locationHandler;
private final DemographicsHandler demographicsHandler;
private final BasicInfoHandler basicInfoHandler;
private final RuleBreakingHandler ruleBreakingHandler;
private final ServerData serverData;
private final ServerDataHandler serverDataHandler;
private final PlanLiteHandler planLiteHandler;
private final Database db;
public DataHandler(Plan plugin) {
this.plugin = plugin;
db = plugin.getDB();
dataCache = new HashMap<>();
activityHandler = new ActivityHandler(plugin, this);
gamemodeTimesHandler = new GamemodeTimesHandler(plugin, this);
locationHandler = new LocationHandler(plugin, this);
demographicsHandler = new DemographicsHandler(plugin, this);
basicInfoHandler = new BasicInfoHandler(plugin, this);
ruleBreakingHandler = new RuleBreakingHandler(plugin, this);
serverData = db.getServerData();
serverDataHandler = new ServerDataHandler(serverData);
planLiteHandler = new PlanLiteHandler(plugin);
int minutes = plugin.getConfig().getInt("saveEveryXMinutes");
plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
@Override
public void run() {
saveHandlerDataToCache();
saveCachedData();
}
}, 60 * 20 * minutes, 60 * 20 * minutes);
}
@Deprecated
public boolean isFirstTimeJoin(UUID uuid) {
return activityHandler.isFirstTimeJoin(uuid);
}
public UserData getCurrentData(UUID uuid, boolean cache) {
if (!db.wasSeenBefore(uuid)) {
return null;
}
if (cache) {
if (dataCache.get(uuid) == null) {
dataCache.put(uuid, db.getUserData(uuid));
}
return dataCache.get(uuid);
} else {
return db.getUserData(uuid);
}
}
public UserData getCurrentData(UUID uuid) {
return getCurrentData(uuid, true);
}
public void saveCachedData() {
dataCache.keySet().parallelStream().forEach((uuid) -> {
saveCachedData(uuid);
});
saveServerData();
}
public void saveCachedData(UUID uuid) {
if (dataCache.get(uuid) != null) {
db.saveUserData(uuid, dataCache.get(uuid));
}
}
public void saveServerData() {
db.saveServerData(serverData);
}
private void saveHandlerDataToCache() {
Bukkit.getServer().getOnlinePlayers().parallelStream().forEach((p) -> {
UserData data = getCurrentData(p.getUniqueId());
activityHandler.saveToCache(p, data);
gamemodeTimesHandler.saveToCache(p, data);
});
}
public void clearCache() {
dataCache.clear();
}
public void clearFromCache(UUID uuid) {
if (dataCache.get(uuid) != null) {
dataCache.remove(uuid);
}
}
public void newPlayer(Player player) {
dataCache.put(player.getUniqueId(), new UserData(player, new DemographicsData(), db));
}
public ActivityHandler getActivityHandler() {
return activityHandler;
}
public LocationHandler getLocationHandler() {
return locationHandler;
}
public DemographicsHandler getDemographicsHandler() {
return demographicsHandler;
}
public BasicInfoHandler getBasicInfoHandler() {
return basicInfoHandler;
}
public RuleBreakingHandler getRuleBreakingHandler() {
return ruleBreakingHandler;
}
public GamemodeTimesHandler getGamemodeTimesHandler() {
return gamemodeTimesHandler;
}
public Database getDB() {
return db;
}
public ServerData getServerData() {
return serverData;
}
public ServerDataHandler getServerDataHandler() {
return serverDataHandler;
}
}

View File

@ -0,0 +1,125 @@
package com.djrapitops.plan.datahandlers;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.api.Gender;
import com.djrapitops.plan.database.UserData;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import org.bukkit.entity.Player;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
public class DemographicsHandler {
private final DataHandler handler;
public DemographicsHandler(Plan plugin, DataHandler h) {
this.handler = h;
}
public void handleChatEvent(AsyncPlayerChatEvent event, UserData data) {
Player player = event.getPlayer();
// Create lists
String[] triggersA = {"i\\'m", "am", "im"};
String[] femaleA = {"female", "girl", "gurl", "woman", "gal", "mrs", "she", "miss"};
String[] maleA = {"male", "boy", "man", "boe", "sir", "mr", "guy", "he"};
String[] ageA = {"years", "year-old", "old"};
String[] ignoreA = {"sure", "think", "with", "are"};
Set<String> triggers = new HashSet<>();
Set<String> female = new HashSet<>();
Set<String> male = new HashSet<>();
Set<String> ages = new HashSet<>();
Set<String> ignore = new HashSet<>();
triggers.addAll(Arrays.asList(triggersA));
female.addAll(Arrays.asList(femaleA));
male.addAll(Arrays.asList(maleA));
ages.addAll(Arrays.asList(ageA));
ignore.addAll(Arrays.asList(ignoreA));
// get message
String message = event.getMessage();
String[] messageA = message.split("\\s+");
boolean trigger = false;
boolean age = false;
boolean gender = false;
// Does message contain important data?
for (String string : messageA) {
if (ignore.contains(string)) {
trigger = false;
break;
}
if (triggers.contains(string)) {
trigger = true;
}
if (ages.contains(string)) {
age = true;
}
if (female.contains(string) || male.contains(string)) {
gender = true;
}
}
// if not end
if (!trigger) {
return;
}
// Manage important data
if (age) {
int ageNum = -1;
for (String string : messageA) {
try {
ageNum = Integer.parseInt(string);
if (ageNum != -1) {
break;
}
} catch (Exception e) {
}
}
if (ageNum != -1 && ageNum < 100) {
data.getDemData().setAge(ageNum);
}
}
if (gender) {
for (String string : messageA) {
if (female.contains(string)) {
data.getDemData().setGender(Gender.FEMALE);
} else if (male.contains(string)) {
data.getDemData().setGender(Gender.MALE);
}
}
}
}
public void handleLogIn(PlayerLoginEvent event, UserData data) {
InetAddress address = event.getAddress();
try {
Scanner locationScanner = new Scanner("http://ip-api.com/line/" + address.getHostAddress());
List<String> results = new ArrayList<>();
while (locationScanner.hasNextLine()) {
results.add(locationScanner.nextLine());
}
if (results.size() >= 2) {
data.getDemData().setGeoLocation(results.get(1));
} else {
data.getDemData().setGeoLocation("UNKOWN");
}
} catch (Exception e) {
Plan plugin = getPlugin(Plan.class);
plugin.logToFile("http://ip-api.com/line/" + address.getHostAddress());
plugin.logToFile("" + e);
plugin.logToFile(address.toString());
}
}
}

View File

@ -0,0 +1,43 @@
package com.djrapitops.plan.datahandlers;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.database.UserData;
import java.util.HashMap;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
public class GamemodeTimesHandler {
private final Plan plugin;
private final DataHandler handler;
public GamemodeTimesHandler(Plan plugin, DataHandler h) {
this.plugin = plugin;
handler = h;
}
public void handleChangeEvent(PlayerGameModeChangeEvent event, UserData data) {
HashMap<GameMode, Long> times = data.getGmTimes();
long lastSwap = data.getLastGmSwapTime();
handler.getActivityHandler().saveToCache(event.getPlayer(), data);
long now = data.getPlayTime();
GameMode oldGM = data.getLastGamemode();
data.setGMTime(oldGM, times.get(oldGM)+(lastSwap-now));
GameMode newGM = event.getNewGameMode();
data.setLastGamemode(newGM);
data.setLastGmSwapTime(now);
}
void saveToCache(Player p, UserData data) {
HashMap<GameMode, Long> times = data.getGmTimes();
long lastSwap = data.getLastGmSwapTime();
handler.getActivityHandler().saveToCache(p, data);
long now = data.getPlayTime();
GameMode currentGM = p.getGameMode();
data.setGMTime(currentGM, times.get(currentGM)+(lastSwap-now));
data.setLastGmSwapTime(now);
}
}

View File

@ -0,0 +1,31 @@
package com.djrapitops.plan.datahandlers;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.database.UserData;
import java.util.Collection;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerQuitEvent;
public class LocationHandler {
private final DataHandler handler;
public LocationHandler(Plan plugin, DataHandler h) {
this.handler = h;
}
public void addLocation(UUID uuid, Location loc) {
handler.getCurrentData(uuid).addLocation(loc);
}
public void addLocations(UUID uuid, Collection<Location> locs) {
handler.getCurrentData(uuid).addLocations(locs);
}
public void handleLogOut(PlayerQuitEvent event, UserData data) {
Player p = event.getPlayer();
handler.getCurrentData(p.getUniqueId()).setBedLocation(p.getBedSpawnLocation());
}
}

View File

@ -0,0 +1,15 @@
package com.djrapitops.plan.datahandlers;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLiteHook;
public class PlanLiteHandler {
private Plan plugin;
private PlanLiteHook hook;
public PlanLiteHandler(Plan plugin) {
this.plugin = plugin;
hook = plugin.getPlanLiteHook();
}
}

View File

@ -0,0 +1,29 @@
package com.djrapitops.plan.datahandlers;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.database.UserData;
import java.util.Date;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class RuleBreakingHandler {
private final DataHandler handler;
public RuleBreakingHandler(Plan plugin, DataHandler h) {
this.handler = h;
}
public void handleLogout(PlayerQuitEvent event, UserData data) {
Player player = event.getPlayer();
data.updateBanned(player);
}
public void handleKick(PlayerKickEvent event, UserData data) {
Player player = event.getPlayer();
data.setTimesKicked(data.getTimesKicked()+1);
data.setPlayTime(data.getPlayTime()+(data.getLastPlayed()-new Date().getTime()));
data.setLastPlayed(player.getLastPlayed());
}
}

View File

@ -0,0 +1,28 @@
package com.djrapitops.plan.datahandlers;
import com.djrapitops.plan.database.ServerData;
public class ServerDataHandler {
private ServerData serverData;
public ServerDataHandler(ServerData serverData) {
this.serverData = serverData;
}
public void handleLogin(boolean newPlayer) {
serverData.playerJoined(newPlayer);
}
public void handleLogout() {
serverData.playerLeft();
}
public void handleKick() {
handleLogout();
}
public void handleCommand(String command) {
serverData.commandRegistered(command);
}
}

View File

@ -0,0 +1,36 @@
package com.djrapitops.plan.datahandlers.listeners;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.datahandlers.DataHandler;
import com.djrapitops.plan.datahandlers.DemographicsHandler;
import com.djrapitops.plan.database.UserData;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
public class PlanChatListener implements Listener {
private final Plan plugin;
private final DataHandler handler;
private final DemographicsHandler demographicsHandler;
public PlanChatListener(Plan plugin) {
this.plugin = plugin;
handler = plugin.getHandler();
demographicsHandler = handler.getDemographicsHandler();
}
@EventHandler(priority = EventPriority.MONITOR)
public void onChat(AsyncPlayerChatEvent event) {
if (event.isCancelled()) {
return;
}
Player p = event.getPlayer();
UserData data = handler.getCurrentData(p.getUniqueId());
data.addNickname(p.getDisplayName());
demographicsHandler.handleChatEvent(event, data);
}
}

View File

@ -0,0 +1,35 @@
package com.djrapitops.plan.datahandlers.listeners;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.datahandlers.DataHandler;
import com.djrapitops.plan.datahandlers.GamemodeTimesHandler;
import com.djrapitops.plan.database.UserData;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
public class PlanGamemodeChangeListener implements Listener {
private final Plan plugin;
private final DataHandler handler;
private final GamemodeTimesHandler gmTimesH;
public PlanGamemodeChangeListener(Plan plugin) {
this.plugin = plugin;
handler = plugin.getHandler();
gmTimesH = handler.getGamemodeTimesHandler();
}
@EventHandler(priority = EventPriority.MONITOR)
public void onGamemodeChange(PlayerGameModeChangeEvent event) {
if (event.isCancelled()) {
return;
}
Player p = event.getPlayer();
UserData data = handler.getCurrentData(p.getUniqueId());
gmTimesH.handleChangeEvent(event, data);
}
}

View File

@ -0,0 +1,80 @@
package com.djrapitops.plan.datahandlers.listeners;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.datahandlers.ActivityHandler;
import com.djrapitops.plan.datahandlers.DataHandler;
import com.djrapitops.plan.datahandlers.DemographicsHandler;
import com.djrapitops.plan.datahandlers.LocationHandler;
import com.djrapitops.plan.datahandlers.RuleBreakingHandler;
import com.djrapitops.plan.datahandlers.ServerDataHandler;
import com.djrapitops.plan.database.UserData;
import java.util.UUID;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent.Result;
import org.bukkit.event.player.PlayerQuitEvent;
public class PlanPlayerListener implements Listener {
private final DataHandler handler;
private final ActivityHandler activityH;
private final LocationHandler locationH;
private final DemographicsHandler demographicH;
private final RuleBreakingHandler rulebreakH;
private final ServerDataHandler serverHandler;
public PlanPlayerListener(Plan plugin) {
handler = plugin.getHandler();
activityH = handler.getActivityHandler();
demographicH = handler.getDemographicsHandler();
locationH = handler.getLocationHandler();
rulebreakH = handler.getRuleBreakingHandler();
serverHandler = handler.getServerDataHandler();
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerLogin(PlayerLoginEvent event) {
if (!event.getResult().equals(Result.ALLOWED)) {
return;
}
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
boolean newPlayer = activityH.isFirstTimeJoin(uuid);
if (newPlayer) {
handler.newPlayer(player);
}
serverHandler.handleLogin(newPlayer);
UserData data = handler.getCurrentData(uuid);
activityH.handleLogIn(event, data);
demographicH.handleLogIn(event, data);
handler.saveCachedData(uuid);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event) {
UUID uuid = event.getPlayer().getUniqueId();
UserData data = handler.getCurrentData(uuid);
activityH.handleLogOut(event, data);
locationH.handleLogOut(event, data);
serverHandler.handleLogout();
handler.saveCachedData(uuid);
handler.clearFromCache(uuid);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerKick(PlayerKickEvent event) {
if (event.isCancelled()) {
return;
}
UUID uuid = event.getPlayer().getUniqueId();
UserData data = handler.getCurrentData(uuid);
rulebreakH.handleKick(event, data);
serverHandler.handleKick();
handler.saveCachedData(uuid);
handler.clearFromCache(uuid);
}
}

View File

@ -1,13 +1,50 @@
debug: true
visible:
bukkitdata: true
ontime: true
essentials: true
factions: true
saveEveryXMinutes: 5
database:
type: sqlite
enabledData:
planLite:
pluginEnabled: true
towny: true
vault: true
superbvote: true
placeholderapi: true
advancedachievements: true
playerlogger: true
factions: true
achievements: true
votes: true
economy: true
essentials:
ruleBreaking: true
server:
commandUsage: true
playersOnline: true
amountOfNewPlayers: true
player:
basic info:
uuid: true
ipAddresses: true
usedNicknames: true
opped: true
activity:
dateRegistered: true
lastLogin: true
playTime: true
loginTimes: true
gamemodePercentages: true
location:
showLocation: true
locationHeatmap: true
bedLocation: true
ruleBreaking:
banLogging: true
timesKicked: true
demographics:
geoLocation: true
age: true
gender: true

View File

@ -1,6 +1,6 @@
name: Plan
main: com.djrapitops.plan.Plan
version: 1.6.2
version: 2.0.0
commands:
plan:
@ -23,15 +23,7 @@ commands:
description: run commands to debug the plugin.
softdepend:
- OnTime
- EssentialsX
- Towny
- Vault
- Factions
- SuperbVote
- PlaceholderAPI
- AdvancedAchievements
- PlayerLogger
- PlanLite
permissions:
plan.?:
@ -61,6 +53,7 @@ permissions:
plan.debug:
description: Allows debug command
default: op
plan.basic:
children:
plan.?: true

View File

@ -7,8 +7,8 @@
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="Plan_Lite" default="default" basedir=".">
<description>Builds, tests, and runs the project Plan Lite.</description>
<project name="PlanLite" default="default" basedir=".">
<description>Builds, tests, and runs the project PlanLite.</description>
<import file="nbproject/build-impl.xml"/>
<!--
@ -58,7 +58,7 @@
An example of overriding the target for project execution could look like this:
<target name="run" depends="Plan_Lite-impl.jar">
<target name="run" depends="PlanLite-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>

View File

@ -19,7 +19,7 @@ is divided into following sections:
- cleanup
-->
<project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="Plan_Lite-impl">
<project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="PlanLite-impl">
<fail message="Please build using Ant 1.8.0 or higher.">
<condition>
<not>
@ -449,7 +449,7 @@ is divided into following sections:
</fileset>
</union>
<taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/>
<testng classfilesetref="test.set" failureProperty="tests.failed" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="Plan_Lite" testname="TestNG tests" workingDir="${work.dir}">
<testng classfilesetref="test.set" failureProperty="tests.failed" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="PlanLite" testname="TestNG tests" workingDir="${work.dir}">
<xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
<propertyset>
<propertyref prefix="test-sys-prop."/>
@ -600,7 +600,7 @@ is divided into following sections:
<condition else="-testclass @{testClass}" property="test.class.or.method" value="-methods @{testClass}.@{testMethod}">
<isset property="test.method"/>
</condition>
<condition else="-suitename Plan_Lite -testname @{testClass} ${test.class.or.method}" property="testng.cmd.args" value="@{testClass}">
<condition else="-suitename PlanLite -testname @{testClass} ${test.class.or.method}" property="testng.cmd.args" value="@{testClass}">
<matches pattern=".*\.xml" string="@{testClass}"/>
</condition>
<delete dir="${build.test.results.dir}" quiet="true"/>
@ -892,7 +892,7 @@ is divided into following sections:
<delete file="${built-jar.properties}" quiet="true"/>
</target>
<target if="already.built.jar.${basedir}" name="-warn-already-built-jar">
<echo level="warn" message="Cycle detected: Plan Lite was already built"/>
<echo level="warn" message="Cycle detected: PlanLite was already built"/>
</target>
<target depends="init,-deps-jar-init" name="deps-jar" unless="no.deps">
<mkdir dir="${build.dir}"/>
@ -1377,7 +1377,7 @@ is divided into following sections:
<delete file="${built-clean.properties}" quiet="true"/>
</target>
<target if="already.built.clean.${basedir}" name="-warn-already-built-clean">
<echo level="warn" message="Cycle detected: Plan Lite was already built"/>
<echo level="warn" message="Cycle detected: PlanLite was already built"/>
</target>
<target depends="init,-deps-clean-init" name="deps-clean" unless="no.deps">
<mkdir dir="${build.dir}"/>

View File

@ -1,8 +1,8 @@
build.xml.data.CRC32=4ad1677b
build.xml.script.CRC32=db0f56d1
build.xml.data.CRC32=f0bf6c4b
build.xml.script.CRC32=42f31611
build.xml.stylesheet.CRC32=8064a381@1.79.1.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=4ad1677b
nbproject/build-impl.xml.script.CRC32=22df94d2
nbproject/build-impl.xml.data.CRC32=f0bf6c4b
nbproject/build-impl.xml.script.CRC32=b8db7136
nbproject/build-impl.xml.stylesheet.CRC32=05530350@1.79.1.48

View File

@ -3,7 +3,7 @@ annotation.processing.enabled.in.editor=false
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=Plan Lite
application.title=PlanLite
application.vendor=Risto
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
@ -25,7 +25,7 @@ debug.test.classpath=\
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/Plan_Lite.jar
dist.jar=${dist.dir}/PlanLite.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=

View File

@ -3,7 +3,7 @@
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>Plan Lite</name>
<name>PlanLite</name>
<source-roots>
<root id="src.dir"/>
</source-roots>

View File

@ -24,7 +24,7 @@ public class PlanCommand implements CommandExecutor {
private final List<SubCommand> commands;
public PlanCommand(Plan plugin) {
public PlanCommand(PlanLite plugin) {
commands = new ArrayList<>();
commands.add(new HelpCommand(plugin, this));

View File

@ -29,13 +29,13 @@ import java.util.Arrays;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
public class Plan extends JavaPlugin {
public class PlanLite extends JavaPlugin {
private final Map<String, Hook> hooks;
private API api;
private final Map<String, Hook> extraHooks;
public Plan() {
public PlanLite() {
this.hooks = new HashMap<>();
this.extraHooks = new HashMap<>();
}
@ -111,7 +111,7 @@ public class Plan extends JavaPlugin {
try {
String className = "com.djrapitops.plan.command.hooks." + pluginName + "Hook";
Class<Hook> clazz = (Class<Hook>) Hook.class.forName(className);
this.hooks.put(pluginName, clazz.getConstructor(Plan.class).newInstance(this));
this.hooks.put(pluginName, clazz.getConstructor(PlanLite.class).newInstance(this));
} catch (Exception | NoClassDefFoundError e) {
hookFail.add(pluginName);
errors.append("Failed to hook ").append(pluginName).append("\n").append(e);

View File

@ -1,6 +1,6 @@
package com.djrapitops.plan.api;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLite;
import com.djrapitops.plan.command.utils.DataFormatUtils;
import com.djrapitops.plan.command.utils.DataUtils;
import java.util.Date;
@ -8,9 +8,9 @@ import java.util.HashMap;
public class API {
private Plan plugin;
private PlanLite plugin;
public API(Plan plugin) {
public API(PlanLite plugin) {
this.plugin = plugin;
}

View File

@ -1,7 +1,7 @@
package com.djrapitops.plan.api;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLite;
import java.util.HashMap;
public interface Hook {
@ -9,7 +9,7 @@ public interface Hook {
public HashMap<String, DataPoint> getData(String player) throws Exception;
public HashMap<String, DataPoint> getAllData(String player) throws Exception;
public default void setPlan(Plan plan) throws Exception {
public default void setPlan(PlanLite plan) throws Exception {
}

View File

@ -1,6 +1,6 @@
package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLite;
import com.djrapitops.plan.command.CommandType;
import com.djrapitops.plan.command.SubCommand;
import com.djrapitops.plan.api.DataPoint;
@ -18,12 +18,12 @@ import org.bukkit.entity.Player;
public class AnalyzeCommand extends SubCommand {
private Plan plugin;
private PlanLite plugin;
private HashMap<UUID, HashMap<String, DataPoint>> playerData;
private HashMap<String, DataPoint> analyzedPlayerdata;
private Date refreshDate;
public AnalyzeCommand(Plan plugin) {
public AnalyzeCommand(PlanLite plugin) {
super("analyze", "plan.analyze", "Analyze data of all players /plan analyze [-refresh]", CommandType.CONSOLE);
this.plugin = plugin;
}

View File

@ -1,6 +1,6 @@
package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLite;
import com.djrapitops.plan.command.CommandType;
import com.djrapitops.plan.command.SubCommand;
import com.djrapitops.plan.command.utils.DataUtils;
@ -11,9 +11,9 @@ import org.bukkit.command.CommandSender;
public class DebugCommand extends SubCommand {
private Plan plugin;
private PlanLite plugin;
public DebugCommand(Plan plugin) {
public DebugCommand(PlanLite plugin) {
super("debug", "plan.debug", "Test plugin for possible errors (debug feature)", CommandType.PLAYER);
this.plugin = plugin;
}

View File

@ -1,7 +1,7 @@
package com.djrapitops.plan.command.commands;
//import com.djrapitops.plan.Phrase;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLite;
import com.djrapitops.plan.PlanCommand;
import com.djrapitops.plan.command.CommandType;
import com.djrapitops.plan.command.SubCommand;
@ -12,10 +12,10 @@ import org.bukkit.entity.Player;
public class HelpCommand extends SubCommand {
private final Plan plugin;
private final PlanLite plugin;
private final PlanCommand command;
public HelpCommand(Plan plugin, PlanCommand command) {
public HelpCommand(PlanLite plugin, PlanCommand command) {
super("help,?", "plan.?", "Show command list.", CommandType.CONSOLE);
this.plugin = plugin;

View File

@ -1,6 +1,6 @@
package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLite;
import com.djrapitops.plan.command.CommandType;
import com.djrapitops.plan.command.SubCommand;
import com.djrapitops.plan.command.utils.MiscUtils;
@ -10,9 +10,9 @@ import org.bukkit.command.CommandSender;
public class InfoCommand extends SubCommand {
private Plan plugin;
private PlanLite plugin;
public InfoCommand(Plan plugin) {
public InfoCommand(PlanLite plugin) {
super("info", "plan.info", "View version and enabled hooks", CommandType.CONSOLE);
this.plugin = plugin;

View File

@ -1,6 +1,6 @@
package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLite;
import com.djrapitops.plan.command.CommandType;
import com.djrapitops.plan.command.SubCommand;
import com.djrapitops.plan.command.utils.DataFormatUtils;
@ -18,9 +18,9 @@ import org.bukkit.command.CommandSender;
public class InspectCommand extends SubCommand {
private Plan plugin;
private PlanLite plugin;
public InspectCommand(Plan plugin) {
public InspectCommand(PlanLite plugin) {
super("inspect", "plan.inspect", "Inspect data /plan <player> [-a, -r].", CommandType.CONSOLE_WITH_ARGUMENTS);
this.plugin = plugin;

View File

@ -1,6 +1,6 @@
package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLite;
import com.djrapitops.plan.command.CommandType;
import com.djrapitops.plan.command.SubCommand;
import com.djrapitops.plan.command.hooks.PlaceholderAPIHook;
@ -13,9 +13,9 @@ import org.bukkit.command.CommandSender;
public class ReloadCommand extends SubCommand {
private Plan plugin;
private PlanLite plugin;
public ReloadCommand(Plan plugin) {
public ReloadCommand(PlanLite plugin) {
super("reload", "plan.reload", "Reload plugin config & Hooks", CommandType.CONSOLE);
this.plugin = plugin;

View File

@ -1,6 +1,6 @@
package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLite;
import com.djrapitops.plan.command.CommandType;
import com.djrapitops.plan.command.SubCommand;
import com.djrapitops.plan.api.DataPoint;
@ -18,12 +18,13 @@ import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import static org.bukkit.Bukkit.getOfflinePlayer;
public class SearchCommand extends SubCommand {
private final Plan plugin;
private final PlanLite plugin;
public SearchCommand(Plan plugin) {
public SearchCommand(PlanLite plugin) {
super("search", "plan.search", "Inspect specific data /plan <search terms> [-p]", CommandType.CONSOLE_WITH_ARGUMENTS);
this.plugin = plugin;
}

View File

@ -1,7 +1,7 @@
package com.djrapitops.plan.command.hooks;
import com.djrapitops.plan.api.Hook;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLite;
import com.djrapitops.plan.UUIDFetcher;
import com.djrapitops.plan.api.DataPoint;
import com.djrapitops.plan.api.DataType;
@ -15,15 +15,16 @@ import java.util.UUID;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.OfflinePlayer;
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
import static org.bukkit.Bukkit.getOfflinePlayer;
public class AdvancedAchievementsHook implements Hook {
private Plan plugin;
private PlanLite plugin;
private AdvancedAchievements aAPlugin;
private int totalAchievements;
private boolean usingUUID;
public AdvancedAchievementsHook(Plan plugin) throws Exception, NoClassDefFoundError {
public AdvancedAchievementsHook(PlanLite plugin) throws Exception, NoClassDefFoundError {
this.plugin = plugin;
this.aAPlugin = getPlugin(AdvancedAchievements.class);
// Version was important because 4.0.3 added required method for Offline players

View File

@ -1,7 +1,7 @@
package com.djrapitops.plan.command.hooks;
import com.djrapitops.plan.api.Hook;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLite;
import com.djrapitops.plan.UUIDFetcher;
import com.djrapitops.plan.api.DataPoint;
import com.djrapitops.plan.api.DataType;
@ -10,12 +10,13 @@ import java.util.HashMap;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import static org.bukkit.Bukkit.getOfflinePlayer;
public class BukkitDataHook implements Hook {
private final Plan plugin;
private final PlanLite plugin;
public BukkitDataHook(Plan p) throws Exception {
public BukkitDataHook(PlanLite p) throws Exception {
plugin = p;
}

View File

@ -1,7 +1,7 @@
package com.djrapitops.plan.command.hooks;
import com.djrapitops.plan.api.Hook;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLite;
import com.djrapitops.plan.UUIDFetcher;
import com.djrapitops.plan.api.DataPoint;
import com.djrapitops.plan.api.DataType;
@ -17,13 +17,14 @@ import org.bukkit.BanList;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import static org.bukkit.Bukkit.getOfflinePlayer;
public class EssentialsHook implements Hook {
private IEssentials ess;
private final Plan plugin;
private final PlanLite plugin;
public EssentialsHook(Plan p) throws Exception {
public EssentialsHook(PlanLite p) throws Exception {
this.ess = getPlugin(Essentials.class);
this.plugin = p;
}

View File

@ -1,7 +1,7 @@
package com.djrapitops.plan.command.hooks;
import com.djrapitops.plan.api.Hook;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLite;
import com.djrapitops.plan.UUIDFetcher;
import com.djrapitops.plan.api.DataPoint;
import com.djrapitops.plan.api.DataType;
@ -13,13 +13,14 @@ import java.util.UUID;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.OfflinePlayer;
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
import static org.bukkit.Bukkit.getOfflinePlayer;
public class FactionsHook implements Hook {
private Plan plugin;
private PlanLite plugin;
private Factions factions;
public FactionsHook(Plan plugin) throws Exception {
public FactionsHook(PlanLite plugin) throws Exception {
this.plugin = plugin;
this.factions = getPlugin(Factions.class);
}

View File

@ -1,7 +1,7 @@
package com.djrapitops.plan.command.hooks;
import com.djrapitops.plan.api.Hook;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLite;
import com.djrapitops.plan.UUIDFetcher;
import com.djrapitops.plan.api.DataPoint;
import com.djrapitops.plan.api.DataType;
@ -9,12 +9,13 @@ import java.util.HashMap;
import me.edge209.OnTime.OnTimeAPI;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.OfflinePlayer;
import static org.bukkit.Bukkit.getOfflinePlayer;
public class OnTimeHook implements Hook {
private Plan plugin;
private PlanLite plugin;
public OnTimeHook(Plan plugin) throws Exception {
public OnTimeHook(PlanLite plugin) throws Exception {
this.plugin = plugin;
if (OnTimeAPI.data.LASTLOGIN == null) {
throw new Exception("Ontime not installed.");

View File

@ -1,6 +1,6 @@
package com.djrapitops.plan.command.hooks;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLite;
import com.djrapitops.plan.api.DataPoint;
import com.djrapitops.plan.command.utils.DataFormatUtils;
import com.djrapitops.plan.command.utils.DataUtils;
@ -11,9 +11,9 @@ import org.bukkit.entity.Player;
public class PlaceholderAPIHook extends EZPlaceholderHook {
private final Plan plan;
private final PlanLite plan;
public PlaceholderAPIHook(Plan plan) {
public PlaceholderAPIHook(PlanLite plan) {
super(plan, "plan");
this.plan = plan;
}

View File

@ -1,7 +1,7 @@
package com.djrapitops.plan.command.hooks;
import com.djrapitops.plan.api.Hook;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLite;
import com.djrapitops.plan.UUIDFetcher;
import com.djrapitops.plan.api.DataPoint;
import com.djrapitops.plan.api.DataType;
@ -12,12 +12,13 @@ import me.BadBones69.Logger.SettingsManager;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.file.FileConfiguration;
import static org.bukkit.Bukkit.getOfflinePlayer;
public class PlayerLoggerHook implements Hook {
private Plan plugin;
private PlanLite plugin;
public PlayerLoggerHook(Plan plugin) throws Exception, NoClassDefFoundError {
public PlayerLoggerHook(PlanLite plugin) throws Exception, NoClassDefFoundError {
this.plugin = plugin;
SettingsManager.getInstance();
}

View File

@ -1,7 +1,7 @@
package com.djrapitops.plan.command.hooks;
import com.djrapitops.plan.api.Hook;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLite;
import com.djrapitops.plan.UUIDFetcher;
import com.djrapitops.plan.api.DataPoint;
import com.djrapitops.plan.api.DataType;
@ -10,13 +10,14 @@ import java.util.HashMap;
import java.util.UUID;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.OfflinePlayer;
import static org.bukkit.Bukkit.getOfflinePlayer;
public class SuperbVoteHook implements Hook {
private Plan plugin;
private PlanLite plugin;
private SuperbVote hookP;
public SuperbVoteHook(Plan plugin) throws Exception {
public SuperbVoteHook(PlanLite plugin) throws Exception {
this.plugin = plugin;
this.hookP = SuperbVote.getPlugin();
}

View File

@ -1,7 +1,7 @@
package com.djrapitops.plan.command.hooks;
import com.djrapitops.plan.api.Hook;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLite;
import com.djrapitops.plan.UUIDFetcher;
import com.djrapitops.plan.api.DataPoint;
import com.djrapitops.plan.api.DataType;
@ -19,13 +19,15 @@ import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
import static com.palmergames.bukkit.towny.TownyFormatter.getFormattedResidents;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.OfflinePlayer;
import static com.palmergames.bukkit.towny.TownyFormatter.getFormattedResidents;
import static org.bukkit.Bukkit.getOfflinePlayer;
public class TownyHook implements Hook {
private final Towny towny;
private final Plan plugin;
private final PlanLite plugin;
public TownyHook(Plan p) throws Exception {
public TownyHook(PlanLite p) throws Exception {
this.towny = getPlugin(Towny.class);
this.plugin = p;
}

View File

@ -1,7 +1,7 @@
package com.djrapitops.plan.command.hooks;
import com.djrapitops.plan.api.Hook;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLite;
import com.djrapitops.plan.UUIDFetcher;
import com.djrapitops.plan.api.DataPoint;
import com.djrapitops.plan.api.DataType;
@ -11,13 +11,14 @@ import org.bukkit.OfflinePlayer;
import net.milkbowl.vault.economy.Economy;
import static org.bukkit.Bukkit.getOfflinePlayer;
import static org.bukkit.Bukkit.getServer;
import static org.bukkit.Bukkit.getOfflinePlayer;
public class VaultHook implements Hook {
private Plan plugin;
private PlanLite plugin;
private Economy econ;
public VaultHook(Plan plugin) throws Exception {
public VaultHook(PlanLite plugin) throws Exception {
this.plugin = plugin;
this.econ = getServer().getServicesManager().getRegistration(Economy.class).getProvider();
}

View File

@ -1,6 +1,6 @@
package com.djrapitops.plan.command.utils;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLite;
import com.djrapitops.plan.command.hooks.AdvancedAchievementsHook;
import com.djrapitops.plan.api.DataPoint;
import com.djrapitops.plan.api.DataType;
@ -15,7 +15,7 @@ import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
public class Analysis {
public static HashMap<String, DataPoint> analyze(HashMap<UUID, HashMap<String, DataPoint>> playerData) {
Plan plugin = getPlugin(Plan.class);
PlanLite plugin = getPlugin(PlanLite.class);
HashMap<String, List<String>> playerDataLists = new HashMap<>();
HashMap<String, DataType> dataTypes = new HashMap<>();
// Ignore following keys (Strings, unprocessable or irrelevant data)

View File

@ -1,6 +1,6 @@
package com.djrapitops.plan.command.utils;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLite;
import com.djrapitops.plan.api.DataPoint;
import com.djrapitops.plan.api.DataType;
import java.util.ArrayList;
@ -16,7 +16,7 @@ public class DataFormatUtils {
public static HashMap<String, DataPoint> removeExtraDataPoints(HashMap<String, DataPoint> data) throws NumberFormatException {
Date dateNow = new Date();
List<String> remove = new ArrayList<>();
Plan plugin = getPlugin(Plan.class);
PlanLite plugin = getPlugin(PlanLite.class);
data.keySet().parallelStream().forEach((key) -> {
try {
// Process OnTime empty data (returns -1 if empty)
@ -148,7 +148,7 @@ public class DataFormatUtils {
}
}
if (!errors.equals("FORMAT-SEARCH\n")) {
Plan plugin = getPlugin(Plan.class);
PlanLite plugin = getPlugin(PlanLite.class);
plugin.logToFile(errors);
}
return removeExtraDataPoints(returnMap);

View File

@ -1,6 +1,6 @@
package com.djrapitops.plan.command.utils;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLite;
import com.djrapitops.plan.UUIDFetcher;
import com.djrapitops.plan.api.DataPoint;
import java.io.File;
@ -24,7 +24,7 @@ public class DataUtils {
// returns data given by each Hook
public static HashMap<String, DataPoint> getData(boolean allData, String playerName) {
HashMap<String, DataPoint> data = new HashMap<>();
Plan plugin = getPlugin(Plan.class);
PlanLite plugin = getPlugin(PlanLite.class);
plugin.getHooks().keySet().parallelStream().forEach((hook) -> {
try {
if (allData) {
@ -67,7 +67,7 @@ public class DataUtils {
public static String getPlayerDisplayname(String[] args, CommandSender sender) {
String playerName = "";
Plan plugin = getPlugin(Plan.class);
PlanLite plugin = getPlugin(PlanLite.class);
if (args.length > 0) {
if ((args[0].equals("-a")) || (args[0].equals("-r"))) {
playerName = "ArgumentGivenError";

View File

@ -1,6 +1,6 @@
package com.djrapitops.plan.command.utils;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLite;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
@ -13,7 +13,7 @@ public class MiscUtils {
// <h1>Plan - Player Analytics <span class="muted">
public static String checkVersion() {
Plan plugin = getPlugin(Plan.class);
PlanLite plugin = getPlugin(PlanLite.class);
String[] nVersion;
String[] cVersion;
String lineWithVersion;

View File

@ -1,6 +1,6 @@
name: Plan
main: com.djrapitops.plan.Plan
version: 1.6.2
name: PlanLite
main: com.djrapitops.plan.PlanLite
version: 1.6.3
commands:
plan: