mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-04-06 18:10:29 +08:00
Preparations for complete rewrite of the plugin
Created two copies of the project, and left plugin yml with version so version checking on current versions will not break. Plan Lite: - Current version - Uses plugins to get the data Plan Advanced: - Will be almost complete rewrite of the plugin. - Will be released as Plan 2.0.0 when ready - Current Plan will be released as Plan Lite 1.6.3 when rewrite is complete. - Will gather data and save it - Better consistency and Time axis to analysis. - Better analysis, possibly web page creation for results - Support for Plan Lite - More options
This commit is contained in:
parent
c1603198ba
commit
df8e9dcd77
8
.gitignore
vendored
8
.gitignore
vendored
@ -1,3 +1,9 @@
|
||||
/dist/
|
||||
/build/
|
||||
/nbproject/
|
||||
/nbproject/
|
||||
/Plan Lite/build/
|
||||
/Plan Lite/dist/
|
||||
/Plan Lite/nbproject/private/
|
||||
/Plan Advanced/build/
|
||||
/Plan Advanced/dist/
|
||||
/Plan Advanced/nbproject/private/
|
@ -30,6 +30,7 @@ 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
|
||||
@ -41,7 +42,6 @@ file.reference.Vault.jar=D:\\Minecraft Servers\\TestServer\\plugins\\Vault.jar
|
||||
includes=**
|
||||
jar.compress=true
|
||||
javac.classpath=\
|
||||
${file.reference.craftbukkit-1.10.2.jar}:\
|
||||
${file.reference.OnTime.jar}:\
|
||||
${file.reference.EssentialsX-2.0.1.jar}:\
|
||||
${file.reference.Towny.jar}:\
|
||||
@ -52,7 +52,8 @@ javac.classpath=\
|
||||
${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.PlayerLogger_v1.0_.jar}:\
|
||||
${file.reference.craftbukkit-1.11.2.jar}
|
||||
# Space-separated list of extra javac options
|
||||
javac.compilerargs=
|
||||
javac.deprecation=false
|
83
Plan Advanced/src/plugin.yml
Normal file
83
Plan Advanced/src/plugin.yml
Normal file
@ -0,0 +1,83 @@
|
||||
name: Plan
|
||||
main: com.djrapitops.plan.Plan
|
||||
version: 1.6.2
|
||||
|
||||
commands:
|
||||
plan:
|
||||
usage: /<command> <name>
|
||||
description: base command
|
||||
inspect:
|
||||
usage: /plan inspect <name>
|
||||
description: inspect player data
|
||||
analyze:
|
||||
usage: /plan analyze
|
||||
description: analyze all players' data, add -refresh to refresh analysis.
|
||||
reload:
|
||||
usage: /plan reload
|
||||
description: reload plugin config
|
||||
search:
|
||||
usage: /plan <search terms> -p add -p to make not search playername
|
||||
description: search data of multiple players with search terms
|
||||
debug:
|
||||
usage: /plan debug
|
||||
description: run commands to debug the plugin.
|
||||
|
||||
softdepend:
|
||||
- OnTime
|
||||
- EssentialsX
|
||||
- Towny
|
||||
- Vault
|
||||
- Factions
|
||||
- SuperbVote
|
||||
- PlaceholderAPI
|
||||
- AdvancedAchievements
|
||||
- PlayerLogger
|
||||
|
||||
permissions:
|
||||
plan.?:
|
||||
description: Help command
|
||||
default: true
|
||||
plan.inspect:
|
||||
description: Allows you to check your player data.
|
||||
default: true
|
||||
plan.inspect.other:
|
||||
description: Allows you to check other players' player data.
|
||||
default: true
|
||||
plan.analyze:
|
||||
description: Allows you to check analysed data about all players.
|
||||
default: true
|
||||
plan.analyze.refresh:
|
||||
description: Allows you to refresh the analyse result with -r argument
|
||||
default: op
|
||||
plan.reload:
|
||||
description: Allows to reload plugin config
|
||||
default: true
|
||||
plan.search:
|
||||
description: Allows search
|
||||
default: true
|
||||
plan.info:
|
||||
description: Allows to view info
|
||||
default: true
|
||||
plan.debug:
|
||||
description: Allows debug command
|
||||
default: op
|
||||
plan.basic:
|
||||
children:
|
||||
plan.?: true
|
||||
plan.inspect: true
|
||||
plan.info: true
|
||||
plan.search: true
|
||||
plan.advanced:
|
||||
childer:
|
||||
plan.basic: true
|
||||
plan.analyze: true
|
||||
plan.staff:
|
||||
children:
|
||||
plan.debug: true
|
||||
plan.advanced: true
|
||||
plan.inspect.other: true
|
||||
plan.analyze.refresh: true
|
||||
plan.reload: true
|
||||
plan.*:
|
||||
children:
|
||||
plan.staff: true
|
73
Plan Lite/build.xml
Normal file
73
Plan Lite/build.xml
Normal file
@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- You may freely edit this file. See commented blocks below for -->
|
||||
<!-- some examples of how to customize the build. -->
|
||||
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
||||
<!-- By default, only the Clean and Build commands use this build script. -->
|
||||
<!-- Commands such as Run, Debug, and Test only use this build script if -->
|
||||
<!-- 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>
|
||||
<import file="nbproject/build-impl.xml"/>
|
||||
<!--
|
||||
|
||||
There exist several targets which are by default empty and which can be
|
||||
used for execution of your tasks. These targets are usually executed
|
||||
before and after some main targets. They are:
|
||||
|
||||
-pre-init: called before initialization of project properties
|
||||
-post-init: called after initialization of project properties
|
||||
-pre-compile: called before javac compilation
|
||||
-post-compile: called after javac compilation
|
||||
-pre-compile-single: called before javac compilation of single file
|
||||
-post-compile-single: called after javac compilation of single file
|
||||
-pre-compile-test: called before javac compilation of JUnit tests
|
||||
-post-compile-test: called after javac compilation of JUnit tests
|
||||
-pre-compile-test-single: called before javac compilation of single JUnit test
|
||||
-post-compile-test-single: called after javac compilation of single JUunit test
|
||||
-pre-jar: called before JAR building
|
||||
-post-jar: called after JAR building
|
||||
-post-clean: called after cleaning build products
|
||||
|
||||
(Targets beginning with '-' are not intended to be called on their own.)
|
||||
|
||||
Example of inserting an obfuscator after compilation could look like this:
|
||||
|
||||
<target name="-post-compile">
|
||||
<obfuscate>
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
</obfuscate>
|
||||
</target>
|
||||
|
||||
For list of available properties check the imported
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
|
||||
Another way to customize the build is by overriding existing main targets.
|
||||
The targets of interest are:
|
||||
|
||||
-init-macrodef-javac: defines macro for javac compilation
|
||||
-init-macrodef-junit: defines macro for junit execution
|
||||
-init-macrodef-debug: defines macro for class debugging
|
||||
-init-macrodef-java: defines macro for class execution
|
||||
-do-jar: JAR building
|
||||
run: execution of project
|
||||
-javadoc-build: Javadoc generation
|
||||
test-report: JUnit report generation
|
||||
|
||||
An example of overriding the target for project execution could look like this:
|
||||
|
||||
<target name="run" depends="Plan_Lite-impl.jar">
|
||||
<exec dir="bin" executable="launcher.exe">
|
||||
<arg file="${dist.jar}"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
Notice that the overridden target depends on the jar target and not only on
|
||||
the compile target as the regular run target does. Again, for a list of available
|
||||
properties which you can use, check the target you are overriding in the
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
-->
|
||||
</project>
|
2
Plan Lite/manifest.mf
Normal file
2
Plan Lite/manifest.mf
Normal file
@ -0,0 +1,2 @@
|
||||
Manifest-Version: 1.0
|
||||
X-COMMENT: Main-Class will be added automatically by build
|
1419
Plan Lite/nbproject/build-impl.xml
Normal file
1419
Plan Lite/nbproject/build-impl.xml
Normal file
File diff suppressed because it is too large
Load Diff
8
Plan Lite/nbproject/genfiles.properties
Normal file
8
Plan Lite/nbproject/genfiles.properties
Normal file
@ -0,0 +1,8 @@
|
||||
build.xml.data.CRC32=4ad1677b
|
||||
build.xml.script.CRC32=db0f56d1
|
||||
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.stylesheet.CRC32=05530350@1.79.1.48
|
98
Plan Lite/nbproject/project.properties
Normal file
98
Plan Lite/nbproject/project.properties
Normal file
@ -0,0 +1,98 @@
|
||||
annotation.processing.enabled=true
|
||||
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.vendor=Risto
|
||||
build.classes.dir=${build.dir}/classes
|
||||
build.classes.excludes=**/*.java,**/*.form
|
||||
# This directory is removed when the project is cleaned:
|
||||
build.dir=build
|
||||
build.generated.dir=${build.dir}/generated
|
||||
build.generated.sources.dir=${build.dir}/generated-sources
|
||||
# Only compile against the classpath explicitly listed here:
|
||||
build.sysclasspath=ignore
|
||||
build.test.classes.dir=${build.dir}/test/classes
|
||||
build.test.results.dir=${build.dir}/test/results
|
||||
# Uncomment to specify the preferred debugger connection transport:
|
||||
#debug.transport=dt_socket
|
||||
debug.classpath=\
|
||||
${run.classpath}
|
||||
debug.test.classpath=\
|
||||
${run.test.classpath}
|
||||
# Files in build.classes.dir which should be excluded from distribution jar
|
||||
dist.archive.excludes=
|
||||
# This directory is removed when the project is cleaned:
|
||||
dist.dir=dist
|
||||
dist.jar=${dist.dir}/Plan_Lite.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
|
||||
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}
|
||||
# Space-separated list of extra javac options
|
||||
javac.compilerargs=
|
||||
javac.deprecation=false
|
||||
javac.external.vm=true
|
||||
javac.processorpath=\
|
||||
${javac.classpath}
|
||||
javac.source=1.8
|
||||
javac.target=1.8
|
||||
javac.test.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
javac.test.processorpath=\
|
||||
${javac.test.classpath}
|
||||
javadoc.additionalparam=
|
||||
javadoc.author=false
|
||||
javadoc.encoding=${source.encoding}
|
||||
javadoc.noindex=false
|
||||
javadoc.nonavbar=false
|
||||
javadoc.notree=false
|
||||
javadoc.private=false
|
||||
javadoc.splitindex=true
|
||||
javadoc.use=true
|
||||
javadoc.version=false
|
||||
javadoc.windowtitle=
|
||||
main.class=player.analytics.main.Main
|
||||
manifest.file=manifest.mf
|
||||
meta.inf.dir=${src.dir}/META-INF
|
||||
mkdist.disabled=false
|
||||
platform.active=default_platform
|
||||
run.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
# Space-separated list of JVM arguments used when running the project.
|
||||
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
|
||||
# To set system properties for unit tests define test-sys-prop.name=value:
|
||||
run.jvmargs=
|
||||
run.test.classpath=\
|
||||
${javac.test.classpath}:\
|
||||
${build.test.classes.dir}
|
||||
source.encoding=UTF-8
|
||||
src.dir=src
|
||||
test.src.dir=test
|
15
Plan Lite/nbproject/project.xml
Normal file
15
Plan Lite/nbproject/project.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.java.j2seproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<name>Plan Lite</name>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
</source-roots>
|
||||
<test-roots>
|
||||
<root id="test.src.dir"/>
|
||||
</test-roots>
|
||||
</data>
|
||||
</configuration>
|
||||
</project>
|
181
Plan Lite/src/com/djrapitops/plan/Plan.java
Normal file
181
Plan Lite/src/com/djrapitops/plan/Plan.java
Normal file
@ -0,0 +1,181 @@
|
||||
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 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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getDataFolder().mkdirs();
|
||||
|
||||
getConfig().options().copyDefaults(true);
|
||||
|
||||
getConfig().options().header("Plan Config\n"
|
||||
+ "debug - Errors are saved in errorlog.txt when they occur\n"
|
||||
+ "visible - Plugin's data is accessable with /plan inspect command"
|
||||
);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
this.api = new API(this);
|
||||
|
||||
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())) {
|
||||
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());
|
||||
}
|
||||
} else {
|
||||
hookFail.add(ChatColor.YELLOW + pluginName);
|
||||
}
|
||||
});
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
log("Player Analytics Disabled.");
|
||||
}
|
||||
|
||||
public void log(String message) {
|
||||
getLogger().info(message);
|
||||
}
|
||||
|
||||
public void logError(String message) {
|
||||
getLogger().severe(message);
|
||||
}
|
||||
|
||||
public void logToFile(String message) {
|
||||
if (getConfig().getBoolean("debug")) {
|
||||
File folder = getDataFolder();
|
||||
if (!folder.exists()) {
|
||||
folder.mkdir();
|
||||
}
|
||||
File log = new File(getDataFolder(), "errorlog.txt");
|
||||
try {
|
||||
if (!log.exists()) {
|
||||
log.createNewFile();
|
||||
}
|
||||
FileWriter fw = new FileWriter(log, true);
|
||||
try (PrintWriter pw = new PrintWriter(fw)) {
|
||||
pw.println(message + "\n");
|
||||
pw.flush();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logError("Failed to create log.txt file");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public API getAPI() {
|
||||
return api;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
112
Plan Lite/src/com/djrapitops/plan/PlanCommand.java
Normal file
112
Plan Lite/src/com/djrapitops/plan/PlanCommand.java
Normal file
@ -0,0 +1,112 @@
|
||||
package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plan.command.CommandType;
|
||||
import com.djrapitops.plan.command.SubCommand;
|
||||
import com.djrapitops.plan.command.commands.AnalyzeCommand;
|
||||
import com.djrapitops.plan.command.commands.DebugCommand;
|
||||
import com.djrapitops.plan.command.commands.HelpCommand;
|
||||
import com.djrapitops.plan.command.commands.InfoCommand;
|
||||
import com.djrapitops.plan.command.commands.InspectCommand;
|
||||
import com.djrapitops.plan.command.commands.ReloadCommand;
|
||||
import com.djrapitops.plan.command.commands.SearchCommand;
|
||||
import com.djrapitops.plan.command.utils.MiscUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlanCommand implements CommandExecutor {
|
||||
|
||||
private final List<SubCommand> commands;
|
||||
|
||||
public PlanCommand(Plan plugin) {
|
||||
commands = new ArrayList<>();
|
||||
|
||||
commands.add(new HelpCommand(plugin, this));
|
||||
commands.add(new InspectCommand(plugin));
|
||||
commands.add(new AnalyzeCommand(plugin));
|
||||
commands.add(new SearchCommand(plugin));
|
||||
commands.add(new InfoCommand(plugin));
|
||||
commands.add(new ReloadCommand(plugin));
|
||||
commands.add(new DebugCommand(plugin));
|
||||
}
|
||||
|
||||
public List<SubCommand> getCommands() {
|
||||
return this.commands;
|
||||
}
|
||||
|
||||
public SubCommand getCommand(String name) {
|
||||
for (SubCommand command : commands) {
|
||||
String[] aliases = command.getName().split(",");
|
||||
|
||||
for (String alias : aliases) {
|
||||
if (alias.equalsIgnoreCase(name)) {
|
||||
return command;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void sendDefaultCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
String command = "inspect";
|
||||
if (args.length < 1) {
|
||||
command = "help";
|
||||
}
|
||||
onCommand(sender, cmd, commandLabel, MiscUtils.mergeArrays(new String[]{command}, args));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
if (args.length < 1) {
|
||||
sendDefaultCommand(sender, cmd, commandLabel, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
SubCommand command = getCommand(args[0]);
|
||||
|
||||
if (command == null) {
|
||||
sendDefaultCommand(sender, cmd, commandLabel, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean console = !(sender instanceof Player);
|
||||
|
||||
if (!sender.hasPermission(command.getPermission())) {
|
||||
// Phrase.NO_PERMISSION_FOR_COMMAND.sendWithPrefix( sender );
|
||||
sender.sendMessage(ChatColor.RED + "[PLAN] You do not have the required permmission.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (console && args.length < 2 && command.getCommandType() == CommandType.CONSOLE_WITH_ARGUMENTS) {
|
||||
// Phrase.COMMAND_NEEDS_ARGUMENTS.sendWithPrefix( sender );
|
||||
sender.sendMessage(ChatColor.RED + "[PLAN] Command requires arguments.");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (console && command.getCommandType() == CommandType.PLAYER) {
|
||||
// Phrase.COMMAND_NOT_CONSOLE.sendWithPrefix( sender, commandLabel );
|
||||
sender.sendMessage(ChatColor.RED + "[PLAN] This command can be only used as a player.");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
String[] realArgs = new String[args.length - 1];
|
||||
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
realArgs[i - 1] = args[i];
|
||||
}
|
||||
|
||||
if (!command.onCommand(sender, cmd, commandLabel, realArgs)) {
|
||||
// Phrase.TRY_COMMAND.sendWithPrefix( sender, parse( commandLabel, command ) );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
133
Plan Lite/src/com/djrapitops/plan/UUIDFetcher.java
Normal file
133
Plan Lite/src/com/djrapitops/plan/UUIDFetcher.java
Normal file
@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Copyright (c) 2015 Nate Mortensen
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.djrapitops.plan;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class UUIDFetcher implements Callable<Map<String, UUID>>
|
||||
{
|
||||
private static final double PROFILES_PER_REQUEST = 100;
|
||||
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
|
||||
private final JSONParser jsonParser = new JSONParser();
|
||||
private final List<String> names;
|
||||
private final boolean rateLimiting;
|
||||
|
||||
public UUIDFetcher( List<String> names, boolean rateLimiting )
|
||||
{
|
||||
this.names = ImmutableList.copyOf( names );
|
||||
this.rateLimiting = rateLimiting;
|
||||
}
|
||||
|
||||
public UUIDFetcher( List<String> names )
|
||||
{
|
||||
this( names, true );
|
||||
}
|
||||
|
||||
public Map<String, UUID> call() throws Exception
|
||||
{
|
||||
Map<String, UUID> uuidMap = new HashMap<String, UUID>();
|
||||
|
||||
int requests = ( int ) Math.ceil( names.size() / PROFILES_PER_REQUEST );
|
||||
|
||||
for( int i = 0; i < requests; i++ )
|
||||
{
|
||||
HttpURLConnection connection = createConnection();
|
||||
String body = JSONArray.toJSONString( names.subList( i * 100, Math.min( ( i + 1 ) * 100, names.size() ) ) );
|
||||
writeBody( connection, body );
|
||||
JSONArray array = ( JSONArray ) jsonParser.parse( new InputStreamReader( connection.getInputStream() ) );
|
||||
for( Object profile : array )
|
||||
{
|
||||
JSONObject jsonProfile = ( JSONObject ) profile;
|
||||
String id = ( String ) jsonProfile.get( "id" );
|
||||
String name = ( String ) jsonProfile.get( "name" );
|
||||
UUID uuid = UUIDFetcher.getUUID( id );
|
||||
uuidMap.put( name, uuid );
|
||||
}
|
||||
if( rateLimiting && i != requests - 1 )
|
||||
{
|
||||
Thread.sleep( 100L );
|
||||
}
|
||||
}
|
||||
return uuidMap;
|
||||
}
|
||||
|
||||
private static void writeBody( HttpURLConnection connection, String body ) throws Exception
|
||||
{
|
||||
OutputStream stream = connection.getOutputStream();
|
||||
stream.write( body.getBytes() );
|
||||
stream.flush();
|
||||
stream.close();
|
||||
}
|
||||
|
||||
private static HttpURLConnection createConnection() throws Exception
|
||||
{
|
||||
URL url = new URL( PROFILE_URL );
|
||||
HttpURLConnection connection = ( HttpURLConnection ) url.openConnection();
|
||||
connection.setRequestMethod( "POST" );
|
||||
connection.setRequestProperty( "Content-Type", "application/json" );
|
||||
connection.setUseCaches( false );
|
||||
connection.setDoInput( true );
|
||||
connection.setDoOutput( true );
|
||||
return connection;
|
||||
}
|
||||
|
||||
private static UUID getUUID( String id )
|
||||
{
|
||||
return UUID.fromString( id.substring( 0, 8 ) + "-" + id.substring( 8, 12 ) + "-" + id.substring( 12, 16 ) + "-" + id.substring( 16, 20 ) + "-" + id.substring( 20, 32 ) );
|
||||
}
|
||||
|
||||
public static byte[] toBytes( UUID uuid )
|
||||
{
|
||||
ByteBuffer byteBuffer = ByteBuffer.wrap( new byte[16] );
|
||||
byteBuffer.putLong( uuid.getMostSignificantBits() );
|
||||
byteBuffer.putLong( uuid.getLeastSignificantBits() );
|
||||
return byteBuffer.array();
|
||||
}
|
||||
|
||||
public static UUID fromBytes( byte[] array )
|
||||
{
|
||||
if( array.length != 16 )
|
||||
{
|
||||
throw new IllegalArgumentException( "Illegal byte array length: " + array.length );
|
||||
}
|
||||
ByteBuffer byteBuffer = ByteBuffer.wrap( array );
|
||||
long mostSignificant = byteBuffer.getLong();
|
||||
long leastSignificant = byteBuffer.getLong();
|
||||
return new UUID( mostSignificant, leastSignificant );
|
||||
}
|
||||
|
||||
public static UUID getUUIDOf( String name ) throws Exception
|
||||
{
|
||||
return new UUIDFetcher( Arrays.asList( name ) ).call().get( name );
|
||||
}
|
||||
}
|
112
Plan Lite/src/com/djrapitops/plan/api/API.java
Normal file
112
Plan Lite/src/com/djrapitops/plan/api/API.java
Normal file
@ -0,0 +1,112 @@
|
||||
package com.djrapitops.plan.api;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.command.utils.DataFormatUtils;
|
||||
import com.djrapitops.plan.command.utils.DataUtils;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class API {
|
||||
|
||||
private Plan plugin;
|
||||
|
||||
public API(Plan plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public boolean getDebug() {
|
||||
return plugin.getConfig().getBoolean("debug");
|
||||
}
|
||||
|
||||
public boolean getVisibleEssentials() {
|
||||
return plugin.getConfig().getBoolean("visible.essentials");
|
||||
}
|
||||
|
||||
public boolean getVisibleOnTime() {
|
||||
return plugin.getConfig().getBoolean("visible.ontime");
|
||||
}
|
||||
|
||||
public boolean getVisibleFactions() {
|
||||
return plugin.getConfig().getBoolean("visible.factions");
|
||||
}
|
||||
|
||||
public boolean getVisibleSuperbVote() {
|
||||
return plugin.getConfig().getBoolean("visible.superbvote");
|
||||
}
|
||||
|
||||
public boolean getVisibleTowny() {
|
||||
return plugin.getConfig().getBoolean("visible.towny");
|
||||
}
|
||||
|
||||
public boolean getVisibleVault() {
|
||||
return plugin.getConfig().getBoolean("visible.vault");
|
||||
}
|
||||
|
||||
public boolean getVisibleAdvancedAchievements() {
|
||||
return plugin.getConfig().getBoolean("visible.advancedachievements");
|
||||
}
|
||||
|
||||
public boolean getVisiblePlaceholderAPI() {
|
||||
return plugin.getConfig().getBoolean("visible.placeholderapi");
|
||||
}
|
||||
|
||||
public HashMap<String, DataPoint> getData(String playerName, boolean dataPoint) {
|
||||
return DataFormatUtils.removeExtraDataPoints(DataUtils.getData(false, playerName));
|
||||
}
|
||||
|
||||
// Please move to DataPoint system as soon as possible
|
||||
@Deprecated
|
||||
public HashMap<String, String> getData(String playerName) {
|
||||
HashMap<String, String> data = new HashMap<>();
|
||||
HashMap<String, DataPoint> dataWPoints = getData(playerName, true);
|
||||
dataWPoints.keySet().parallelStream().forEach((key) -> {
|
||||
data.put(key, dataWPoints.get(key).data());
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
public HashMap<String, DataPoint> getAllData(String playerName, boolean dataPoint) {
|
||||
return DataFormatUtils.removeExtraDataPoints(DataUtils.getData(true, playerName));
|
||||
}
|
||||
|
||||
// Please move to DataPoint system as soon as possible
|
||||
@Deprecated
|
||||
public HashMap<String, String> getAllData(String playerName) {
|
||||
HashMap<String, String> data = new HashMap<>();
|
||||
HashMap<String, DataPoint> dataWPoints = getAllData(playerName, true);
|
||||
dataWPoints.keySet().parallelStream().forEach((key) -> {
|
||||
data.put(key, dataWPoints.get(key).data());
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
public HashMap<String, DataPoint> transformOldDataFormat(HashMap<String, String> oldData) {
|
||||
HashMap<String, DataPoint> data = new HashMap<>();
|
||||
for (String key : oldData.keySet()) {
|
||||
data.put(key, new DataPoint(oldData.get(key), DataType.OTHER));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
// use (new Date) on after parameter for time since moment to now
|
||||
public static String formatTimeSinceDate(Date before, Date after) {
|
||||
return DataFormatUtils.formatTimeAmountSinceDate(before, after);
|
||||
}
|
||||
|
||||
// use (new Date) on after parameter for time since moment to now
|
||||
public static String formatTimeSinceString(String before, Date after) {
|
||||
return DataFormatUtils.formatTimeAmountSinceString(before, after);
|
||||
}
|
||||
|
||||
public static String formatTimeAmount(String timeInMs) {
|
||||
return DataFormatUtils.formatTimeAmount(timeInMs);
|
||||
}
|
||||
|
||||
public static String formatTimeStamp(String timeInMs) {
|
||||
return DataFormatUtils.formatTimeStamp(timeInMs);
|
||||
}
|
||||
|
||||
public void addExtraHook(String name, Hook hook) {
|
||||
plugin.addExtraHook(name, hook);
|
||||
}
|
||||
}
|
26
Plan Lite/src/com/djrapitops/plan/api/DataPoint.java
Normal file
26
Plan Lite/src/com/djrapitops/plan/api/DataPoint.java
Normal file
@ -0,0 +1,26 @@
|
||||
|
||||
package com.djrapitops.plan.api;
|
||||
|
||||
public class DataPoint {
|
||||
private String data;
|
||||
private final DataType type;
|
||||
|
||||
public DataPoint(String data, DataType type) {
|
||||
this.data = data;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String data() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public DataType type() {
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
}
|
20
Plan Lite/src/com/djrapitops/plan/api/DataType.java
Normal file
20
Plan Lite/src/com/djrapitops/plan/api/DataType.java
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
package com.djrapitops.plan.api;
|
||||
|
||||
public enum DataType {
|
||||
STRING, // Any preformatted data & words
|
||||
TIME, // Long in milliseconds
|
||||
TIME_TIMESTAMP, // Long in milliseconds since Epoch Date 1970, will be subtracted from current time.
|
||||
DATE, // Long in milliseconds since Epoch Date 1970
|
||||
LOCATION, // X:# Y:# Z:#
|
||||
AMOUNT, // Number
|
||||
AMOUNT_WITH_MAX, // Example: 41 / 44
|
||||
AMOUNT_WITH_LETTERS, // Example $50
|
||||
BOOLEAN, // true/false
|
||||
PERCENT, // Example 50%
|
||||
OTHER, // Any data not listed here - will not be analyzed
|
||||
MAP, // An image presentation of array in string format, no format yet
|
||||
LINK, // Link to a webpage
|
||||
HEATMAP, // An image presentation of array in string format, no format yet
|
||||
DEPRECATED // Old data that has been rendered useless
|
||||
}
|
16
Plan Lite/src/com/djrapitops/plan/api/Hook.java
Normal file
16
Plan Lite/src/com/djrapitops/plan/api/Hook.java
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
package com.djrapitops.plan.api;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import java.util.HashMap;
|
||||
|
||||
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 {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.djrapitops.plan.command;
|
||||
|
||||
public enum CommandType
|
||||
{
|
||||
CONSOLE,
|
||||
PLAYER,
|
||||
CONSOLE_WITH_ARGUMENTS
|
||||
}
|
63
Plan Lite/src/com/djrapitops/plan/command/SubCommand.java
Normal file
63
Plan Lite/src/com/djrapitops/plan/command/SubCommand.java
Normal file
@ -0,0 +1,63 @@
|
||||
package com.djrapitops.plan.command;
|
||||
|
||||
//import com.djrapitops.plan.Phrase;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public abstract class SubCommand
|
||||
{
|
||||
private final String name;
|
||||
|
||||
private final String permission;
|
||||
|
||||
private final String usage;
|
||||
|
||||
// private final Phrase description;
|
||||
|
||||
private final CommandType commandType;
|
||||
|
||||
public SubCommand( String name, String permission, String usage, CommandType commandType )
|
||||
{
|
||||
this.name = name;
|
||||
|
||||
this.permission = permission;
|
||||
|
||||
this.usage = usage;
|
||||
|
||||
// this.description = description;
|
||||
|
||||
this.commandType = commandType;
|
||||
}
|
||||
|
||||
public String getFirstName()
|
||||
{
|
||||
return name.split( "," )[0];
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getPermission()
|
||||
{
|
||||
return permission;
|
||||
}
|
||||
|
||||
public String getUsage()
|
||||
{
|
||||
return usage;
|
||||
}
|
||||
|
||||
// public Phrase getDescription()
|
||||
// {
|
||||
// return description;
|
||||
// }
|
||||
|
||||
public CommandType getCommandType()
|
||||
{
|
||||
return commandType;
|
||||
}
|
||||
|
||||
public abstract boolean onCommand( CommandSender sender, Command cmd, String commandLabel, String[] args );
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.command.CommandType;
|
||||
import com.djrapitops.plan.command.SubCommand;
|
||||
import com.djrapitops.plan.api.DataPoint;
|
||||
import com.djrapitops.plan.command.utils.DataFormatUtils;
|
||||
import com.djrapitops.plan.command.utils.DataUtils;
|
||||
import com.djrapitops.plan.command.utils.Analysis;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class AnalyzeCommand extends SubCommand {
|
||||
|
||||
private Plan plugin;
|
||||
private HashMap<UUID, HashMap<String, DataPoint>> playerData;
|
||||
private HashMap<String, DataPoint> analyzedPlayerdata;
|
||||
private Date refreshDate;
|
||||
|
||||
public AnalyzeCommand(Plan plugin) {
|
||||
super("analyze", "plan.analyze", "Analyze data of all players /plan analyze [-refresh]", CommandType.CONSOLE);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
ChatColor operatorColor = ChatColor.DARK_GREEN;
|
||||
ChatColor textColor = ChatColor.GRAY;
|
||||
for (String arg : args) {
|
||||
if (arg.toLowerCase().equals("-refresh")) {
|
||||
if (sender.hasPermission("plan.analyze.refresh") || !(sender instanceof Player)) {
|
||||
refreshAnalysisData(sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.playerData == null || this.refreshDate == null || this.analyzedPlayerdata == null || DataFormatUtils.formatTimeAmountSinceDate(refreshDate, new Date()).contains("m")) {
|
||||
refreshAnalysisData(sender);
|
||||
}
|
||||
|
||||
//header
|
||||
sender.sendMessage(textColor + "-- [" + operatorColor + "PLAN - Analysis results, refreshed "
|
||||
+ DataFormatUtils.formatTimeAmountSinceDate(refreshDate, new Date()) + " ago:" + textColor + "] --");
|
||||
|
||||
List<String[]> dataList = DataFormatUtils.turnDataHashMapToSortedListOfArrays(analyzedPlayerdata);
|
||||
|
||||
sender.sendMessage("" + textColor + "Averages for " + this.playerData.size() + " player(s)");
|
||||
for (String[] dataString : dataList) {
|
||||
sender.sendMessage("" + operatorColor + dataString[0].charAt(4) + dataString[0].toLowerCase().substring(5) + ": " + textColor + dataString[1]);
|
||||
}
|
||||
sender.sendMessage(textColor + "-- o --");
|
||||
return true;
|
||||
}
|
||||
|
||||
private void refreshAnalysisData(CommandSender sender) {
|
||||
ChatColor operatorColor = ChatColor.DARK_GREEN;
|
||||
ChatColor textColor = ChatColor.GRAY;
|
||||
sender.sendMessage(textColor + "[" + operatorColor + "Plan" + textColor + "] "
|
||||
+ "Refreshing playerData, this might take a while..");
|
||||
this.playerData = DataUtils.getTotalData(DataUtils.getMatchingDisplaynames(true));
|
||||
this.refreshDate = new Date();
|
||||
this.analyzedPlayerdata = Analysis.analyze(this.playerData);
|
||||
sender.sendMessage(textColor + "[" + operatorColor + "Plan" + textColor + "] "
|
||||
+ "Refreshed, took "+DataFormatUtils.formatTimeAmountSinceDate(refreshDate, new Date()));
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.command.CommandType;
|
||||
import com.djrapitops.plan.command.SubCommand;
|
||||
import com.djrapitops.plan.command.utils.DataUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class DebugCommand extends SubCommand {
|
||||
|
||||
private Plan plugin;
|
||||
|
||||
public DebugCommand(Plan plugin) {
|
||||
super("debug", "plan.debug", "Test plugin for possible errors (debug feature)", CommandType.PLAYER);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
if (!plugin.getConfig().getBoolean("debug")) {
|
||||
sender.sendMessage(ChatColor.RED+"[Plan] Debug disabled in config");
|
||||
return true;
|
||||
}
|
||||
String[] commands = {"plan", "plan info", "plan reload", "plan inspect",
|
||||
"plan inspect "+sender.getName()+"-a", "plan inspect reinogiern",
|
||||
"plan analyze", "plan search", "plan search "+sender.getName()+" -p"};
|
||||
for (String command : commands) {
|
||||
Bukkit.dispatchCommand(sender, command);
|
||||
}
|
||||
sender.sendMessage(ChatColor.GREEN+"[Plan] Debug successful, possible errors written in file.");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
//import com.djrapitops.plan.Phrase;
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.PlanCommand;
|
||||
import com.djrapitops.plan.command.CommandType;
|
||||
import com.djrapitops.plan.command.SubCommand;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class HelpCommand extends SubCommand {
|
||||
|
||||
private final Plan plugin;
|
||||
private final PlanCommand command;
|
||||
|
||||
public HelpCommand(Plan plugin, PlanCommand command) {
|
||||
super("help,?", "plan.?", "Show command list.", CommandType.CONSOLE);
|
||||
|
||||
this.plugin = plugin;
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
|
||||
ChatColor operatorColor = ChatColor.DARK_GREEN;
|
||||
|
||||
ChatColor textColor = ChatColor.GRAY;
|
||||
|
||||
sender.sendMessage(textColor + "-- [" + operatorColor + "PLAN - Player Analytics" + textColor + "] --");
|
||||
|
||||
for (SubCommand command : this.command.getCommands()) {
|
||||
if (command.getName().equalsIgnoreCase(getName())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!sender.hasPermission(command.getPermission())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player) && command.getCommandType() == CommandType.PLAYER) {
|
||||
continue;
|
||||
}
|
||||
|
||||
sender.sendMessage(operatorColor + "/plan " + command.getFirstName() + textColor + " - " + command.getUsage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.command.CommandType;
|
||||
import com.djrapitops.plan.command.SubCommand;
|
||||
import com.djrapitops.plan.command.utils.MiscUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class InfoCommand extends SubCommand {
|
||||
|
||||
private Plan plugin;
|
||||
|
||||
public InfoCommand(Plan plugin) {
|
||||
super("info", "plan.info", "View version and enabled hooks", CommandType.CONSOLE);
|
||||
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
plugin.reloadConfig();
|
||||
ChatColor operatorColor = ChatColor.DARK_GREEN;
|
||||
ChatColor textColor = ChatColor.GRAY;
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.command.CommandType;
|
||||
import com.djrapitops.plan.command.SubCommand;
|
||||
import com.djrapitops.plan.command.utils.DataFormatUtils;
|
||||
import com.djrapitops.plan.command.utils.DataUtils;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import com.djrapitops.plan.api.DataPoint;
|
||||
import com.djrapitops.plan.api.DataType;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class InspectCommand extends SubCommand {
|
||||
|
||||
private Plan plugin;
|
||||
|
||||
public InspectCommand(Plan plugin) {
|
||||
super("inspect", "plan.inspect", "Inspect data /plan <player> [-a, -r].", CommandType.CONSOLE_WITH_ARGUMENTS);
|
||||
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
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;
|
||||
}
|
||||
|
||||
boolean allData = false;
|
||||
boolean format = true;
|
||||
for (String arg : args) {
|
||||
if (arg.toLowerCase().equals("-a")) {
|
||||
allData = true;
|
||||
}
|
||||
if (arg.toLowerCase().equals("-r")) {
|
||||
format = false;
|
||||
}
|
||||
}
|
||||
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));
|
||||
|
||||
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;
|
||||
|
||||
//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(textColor + "-- o --");
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.command.CommandType;
|
||||
import com.djrapitops.plan.command.SubCommand;
|
||||
import com.djrapitops.plan.command.hooks.PlaceholderAPIHook;
|
||||
import com.djrapitops.plan.command.utils.DataUtils;
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class ReloadCommand extends SubCommand {
|
||||
|
||||
private Plan plugin;
|
||||
|
||||
public ReloadCommand(Plan plugin) {
|
||||
super("reload", "plan.reload", "Reload plugin config & Hooks", CommandType.CONSOLE);
|
||||
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.command.CommandType;
|
||||
import com.djrapitops.plan.command.SubCommand;
|
||||
import com.djrapitops.plan.api.DataPoint;
|
||||
import com.djrapitops.plan.api.DataType;
|
||||
import com.djrapitops.plan.command.utils.DataFormatUtils;
|
||||
import com.djrapitops.plan.command.utils.DataUtils;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
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;
|
||||
|
||||
public class SearchCommand extends SubCommand {
|
||||
|
||||
private final Plan plugin;
|
||||
|
||||
public SearchCommand(Plan plugin) {
|
||||
super("search", "plan.search", "Inspect specific data /plan <search terms> [-p]", CommandType.CONSOLE_WITH_ARGUMENTS);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
boolean playerFirst = false;
|
||||
for (String arg : args) {
|
||||
if (arg.equals("-p")) {
|
||||
playerFirst = true;
|
||||
}
|
||||
}
|
||||
Set<OfflinePlayer> matchingPlayers;
|
||||
if (playerFirst) {
|
||||
String[] playername = new String[1];
|
||||
playername[0] = args[0];
|
||||
matchingPlayers = DataUtils.getMatchingDisplaynames(playername, sender, false);
|
||||
} else {
|
||||
matchingPlayers = DataUtils.getMatchingDisplaynames(args, sender, false);
|
||||
}
|
||||
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<>();
|
||||
for (UUID key : data.keySet()) {
|
||||
OfflinePlayer p = getOfflinePlayer(key);
|
||||
HashMap<String, DataPoint> dataMap = data.get(key);
|
||||
if (!dataMap.isEmpty()) {
|
||||
dataMap = DataFormatUtils.removeExtraDataPointsSearch(dataMap, args);
|
||||
}
|
||||
if (dataMap.isEmpty()) {
|
||||
dataMap.put("ERR-NO RESULTS", new DataPoint("No results were found.", DataType.OTHER));
|
||||
plugin.logToFile("SEARCH-Results\nNo results were found for: " + p.getName() + Arrays.toString(args));
|
||||
}
|
||||
dataLists.put(p.getName(), DataFormatUtils.turnDataHashMapToSortedListOfArrays(dataMap));
|
||||
}
|
||||
|
||||
ChatColor operatorColor = ChatColor.DARK_GREEN;
|
||||
ChatColor textColor = ChatColor.GRAY;
|
||||
|
||||
//header
|
||||
sender.sendMessage(textColor + "-- [" + operatorColor + "PLAN - Search results: took " + DataFormatUtils.formatTimeAmountSinceDate(refreshDate, new Date()) + textColor + "] --");
|
||||
sender.sendMessage(operatorColor + "Results for: " + Arrays.toString(args));
|
||||
for (String playerName : dataLists.keySet()) {
|
||||
sender.sendMessage(textColor + "Matching player: " + playerName);
|
||||
for (String[] dataString : dataLists.get(playerName)) {
|
||||
sender.sendMessage("" + operatorColor + dataString[0].charAt(4) + dataString[0].toLowerCase().substring(5) + ": " + textColor + dataString[1]);
|
||||
}
|
||||
}
|
||||
if (dataLists.isEmpty()) {
|
||||
sender.sendMessage(operatorColor + "No results for " + textColor + Arrays.toString(args) + operatorColor + ".");
|
||||
}
|
||||
sender.sendMessage(textColor + "-- o --");
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
105
Plan Lite/src/com/djrapitops/plan/command/utils/Analysis.java
Normal file
105
Plan Lite/src/com/djrapitops/plan/command/utils/Analysis.java
Normal file
@ -0,0 +1,105 @@
|
||||
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;
|
||||
|
||||
public class Analysis {
|
||||
|
||||
public static HashMap<String, DataPoint> analyze(HashMap<UUID, HashMap<String, DataPoint>> playerData) {
|
||||
Plan plugin = getPlugin(Plan.class);
|
||||
HashMap<String, List<String>> playerDataLists = new HashMap<>();
|
||||
HashMap<String, DataType> dataTypes = new HashMap<>();
|
||||
// Ignore following keys (Strings, unprocessable or irrelevant data)
|
||||
DataType[] ignoreType = {DataType.DEPRECATED, DataType.STRING, DataType.LOCATION, DataType.LINK, DataType.HEATMAP,
|
||||
DataType.MAP, DataType.OTHER, DataType.DATE, DataType.TIME_TIMESTAMP};
|
||||
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));
|
||||
|
||||
// Turn playerData into Hashmap of Lists sorted by keys.
|
||||
playerData.keySet().parallelStream().forEach((key) -> {
|
||||
playerData.get(key).keySet().parallelStream()
|
||||
.filter((dataKey) -> !(ignoreKeys.contains(dataKey)))
|
||||
.map((dataKey) -> {
|
||||
if (dataTypes.get(dataKey) == null) {
|
||||
dataTypes.put(dataKey, playerData.get(key).get(dataKey).type());
|
||||
}
|
||||
return dataKey;
|
||||
})
|
||||
.filter((dataKey) -> !(ignoreTypes.contains(dataTypes.get(dataKey))))
|
||||
.map((dataKey) -> {
|
||||
if (playerDataLists.get(dataKey) == null) {
|
||||
playerDataLists.put(dataKey, new ArrayList<>());
|
||||
}
|
||||
return dataKey;
|
||||
})
|
||||
.forEach((dataKey) -> {
|
||||
playerDataLists.get(dataKey).add(playerData.get(key).get(dataKey).data());
|
||||
});
|
||||
});
|
||||
|
||||
HashMap<String, DataPoint> analyzedData = new HashMap<>();
|
||||
|
||||
// Analyze
|
||||
playerDataLists.keySet().parallelStream().forEach((dataKey) -> {
|
||||
DataType type = dataTypes.get(dataKey);
|
||||
if (type == DataType.AMOUNT
|
||||
|| type == DataType.AMOUNT_WITH_LETTERS
|
||||
|| type == DataType.AMOUNT_WITH_MAX
|
||||
|| type == DataType.PERCENT) {
|
||||
// Get a clean list of dataPoints with only numbers
|
||||
List<String> dataPoints = playerDataLists.get(dataKey);
|
||||
if (null != type) {
|
||||
switch (type) {
|
||||
case AMOUNT_WITH_LETTERS:
|
||||
dataPoints = AnalysisUtils.parseWLetters(playerDataLists.get(dataKey));
|
||||
break;
|
||||
case PERCENT:
|
||||
dataPoints = AnalysisUtils.parseWLetters(playerDataLists.get(dataKey));
|
||||
break;
|
||||
case AMOUNT_WITH_MAX:
|
||||
dataPoints = AnalysisUtils.parseWMax(playerDataLists.get(dataKey));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (type == DataType.PERCENT) {
|
||||
String averageAmount = AnalysisUtils.AmountAverage(dataPoints);
|
||||
analyzedData.put(dataKey, new DataPoint(averageAmount + "%", DataType.PERCENT));
|
||||
} else {
|
||||
String averageAmount = AnalysisUtils.AmountAverage(dataPoints);
|
||||
analyzedData.put(dataKey, new DataPoint(averageAmount, DataType.AMOUNT));
|
||||
// String highestAmount = AnalysisUtils.AmountHighest(dataPoints);
|
||||
// analyzedData.put(dataKey + " (HIGHEST)", new DataPoint(highestAmount, DataType.AMOUNT));
|
||||
}
|
||||
} else if (type == DataType.TIME) {
|
||||
String averageTime = AnalysisUtils.TimeAverage(playerDataLists.get(dataKey));
|
||||
analyzedData.put(dataKey, new DataPoint(averageTime, DataType.TIME));
|
||||
} else if (type == DataType.BOOLEAN) {
|
||||
String percent = AnalysisUtils.BooleanPercent(playerDataLists.get(dataKey));
|
||||
analyzedData.put(dataKey, new DataPoint(percent, DataType.PERCENT));
|
||||
}
|
||||
});
|
||||
return DataFormatUtils.formatAnalyzed(analyzedData);
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package com.djrapitops.plan.command.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class AnalysisUtils {
|
||||
|
||||
static String AmountAverage(List<String> dataPoints) {
|
||||
double sum = 0;
|
||||
|
||||
for (String dataPoint : dataPoints) {
|
||||
try {
|
||||
sum += Double.parseDouble(dataPoint);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
return "" + (sum * 1.0 / dataPoints.size());
|
||||
}
|
||||
|
||||
static List<String> parseWLetters(List<String> dataPoints) {
|
||||
List<String> parsed = new ArrayList<>();
|
||||
dataPoints.parallelStream().forEach((dataPoint) -> {
|
||||
parsed.add(DataFormatUtils.removeLetters(dataPoint));
|
||||
});
|
||||
return parsed;
|
||||
}
|
||||
|
||||
static List<String> parseWMax(List<String> dataPoints) {
|
||||
List<String> parsed = new ArrayList<>();
|
||||
dataPoints.parallelStream().forEach((dataPoint) -> {
|
||||
parsed.add(dataPoint.split(" ")[0]);
|
||||
});
|
||||
return parsed;
|
||||
}
|
||||
|
||||
static String TimeAverage(List<String> dataPoints) {
|
||||
Long time = Long.parseLong("0");
|
||||
for (String dataPoint : dataPoints) {
|
||||
try {
|
||||
time += Long.parseLong(dataPoint);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
return "" + (time / dataPoints.size());
|
||||
}
|
||||
|
||||
static String BooleanPercent(List<String> dataPoints) {
|
||||
int amount = 0;
|
||||
for (String dataPoint : dataPoints) {
|
||||
try {
|
||||
if (Boolean.parseBoolean(dataPoint)) {
|
||||
amount++;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
return "" + ((amount * 1.0 / dataPoints.size())*100)+"%";
|
||||
}
|
||||
|
||||
static String AmountHighest(List<String> dataPoints) {
|
||||
int highest = 0;
|
||||
for (String dataPoint : dataPoints) {
|
||||
try {
|
||||
int value = Integer.parseInt(dataPoint);
|
||||
if (value > highest) {
|
||||
highest = value;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
return ""+highest;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,298 @@
|
||||
package com.djrapitops.plan.command.utils;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.api.DataPoint;
|
||||
import com.djrapitops.plan.api.DataType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
|
||||
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);
|
||||
data.keySet().parallelStream().forEach((key) -> {
|
||||
try {
|
||||
// Process OnTime empty data (returns -1 if empty)
|
||||
if (key.subSequence(0, 3).equals("ONT")) {
|
||||
if ((data.get(key)).data().equals("-1") || (data.get(key)).data().equals("-1.0")) {
|
||||
remove.add(key);
|
||||
}
|
||||
}
|
||||
// Process failed PlaceholderAPI requests (%string%)
|
||||
if (key.subSequence(0, 3).equals("PHA")) {
|
||||
if ((data.get(key)).data().contains("%")) {
|
||||
remove.add(key);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
plugin.logToFile("FORMAT-Remove\n" + e + "\n" + key);
|
||||
}
|
||||
});
|
||||
// Remove faulty data to prevent TOW-LAST LOGIN from being removed with empty data
|
||||
remove.parallelStream().forEach((removedKey) -> {
|
||||
data.remove(removedKey);
|
||||
});
|
||||
remove.clear();
|
||||
// Process Towny data (Empty returns date with 1970 for REGISTERED)
|
||||
if (data.get("TOW-REGISTERED") != null) {
|
||||
if (data.get("TOW-REGISTERED").data().contains("1970")) {
|
||||
remove.add("TOW-REGISTERED");
|
||||
remove.add("TOW-ONLINE");
|
||||
remove.add("TOW-LAST LOGIN");
|
||||
remove.add("TOW-OWNER OF");
|
||||
if (data.get("TOW-FRIENDS") != null) {
|
||||
remove.add("TOW-FRIENDS");
|
||||
remove.add("TOW-PLOT PERMS");
|
||||
remove.add("TOW-PLOT OPTIONS");
|
||||
}
|
||||
}
|
||||
}
|
||||
// If both OnTime and Towny data found, OnTime priority.
|
||||
if (data.get("ONT-LAST LOGIN") != null) {
|
||||
remove.add("TOW-LAST LOGIN");
|
||||
remove.add("PLG-LAST LOGIN");
|
||||
}
|
||||
// Remove faulty Towny data
|
||||
remove.parallelStream().forEach((removeKey) -> {
|
||||
data.remove(removeKey);
|
||||
});
|
||||
// Remove faulty Essentials SINCE data, reload turns data to 0
|
||||
String[] keysRemoveIfZero = {"ESS-ONLINE SINCE", "ESS-OFFLINE SINCE"};
|
||||
for (String key : keysRemoveIfZero) {
|
||||
if (data.get(key) != null) {
|
||||
if (data.get(key).data().equals("0")) {
|
||||
data.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Remove OnTime Total Votes if SuperbVote is present
|
||||
if (data.get("SVO-VOTES") != null) {
|
||||
if (data.get("ONT-TOTAL VOTES") != null) {
|
||||
data.remove("ONT-TOTAL VOTES");
|
||||
}
|
||||
}
|
||||
// Remove Bukkit uuid points if essentials present
|
||||
if (data.get("ESS-UUID") != null) {
|
||||
data.remove("BUK-UUID");
|
||||
}
|
||||
// Remove colliding Player Logger Data
|
||||
if (data.get("TOW-LAST LOGIN") != null) {
|
||||
data.remove("PLG-LAST LOGIN");
|
||||
}
|
||||
|
||||
data.keySet().parallelStream()
|
||||
.filter((key) -> (data.get(key).type() == DataType.DEPRECATED))
|
||||
.forEach((key) -> {
|
||||
remove.add(key);
|
||||
});
|
||||
remove.parallelStream().forEach((key) -> {
|
||||
data.remove(key);
|
||||
});
|
||||
// Format TimeStamps and Time Amounts
|
||||
for (String key : data.keySet()) {
|
||||
DataPoint dataPoint = data.get(key);
|
||||
if (null != dataPoint.type()) switch (dataPoint.type()) {
|
||||
case DATE:{
|
||||
String formatted = formatTimeStamp(dataPoint.data());
|
||||
dataPoint.setData(formatted);
|
||||
break;
|
||||
}
|
||||
case TIME:{
|
||||
String formatted = formatTimeAmount(dataPoint.data());
|
||||
dataPoint.setData(formatted);
|
||||
break;
|
||||
}
|
||||
case TIME_TIMESTAMP:{
|
||||
String formatted = formatTimeAmountSinceString(dataPoint.data(), dateNow);
|
||||
dataPoint.setData(formatted);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
// Analysis data Formatting, will be updated after more analysis is added
|
||||
public static HashMap<String, DataPoint> formatAnalyzed(HashMap<String, DataPoint> analyzedData) {
|
||||
return removeExtraDataPoints(analyzedData);
|
||||
}
|
||||
|
||||
// Format Search Results
|
||||
public static HashMap<String, DataPoint> removeExtraDataPointsSearch(HashMap<String, DataPoint> dataMap, String[] args) {
|
||||
if (args.length <= 1) {
|
||||
return removeExtraDataPoints(dataMap);
|
||||
}
|
||||
HashMap<String, DataPoint> returnMap = new HashMap<>();
|
||||
String errors = "FORMAT-SEARCH\n";
|
||||
for (String key : dataMap.keySet()) {
|
||||
for (String arg : args) {
|
||||
try {
|
||||
if (key.toLowerCase().contains(arg.toLowerCase())) {
|
||||
returnMap.put(key, dataMap.get(key));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!errors.contains(Arrays.toString(args))) {
|
||||
errors += Arrays.toString(args) + "\n";
|
||||
}
|
||||
errors += (e + "\n" + key + " " + arg + "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!errors.equals("FORMAT-SEARCH\n")) {
|
||||
Plan plugin = getPlugin(Plan.class);
|
||||
plugin.logToFile(errors);
|
||||
}
|
||||
return removeExtraDataPoints(returnMap);
|
||||
}
|
||||
|
||||
// Replace certain items of search terms with plugin tags and remove playername if -p
|
||||
public static String[] parseSearchArgs(String[] args) {
|
||||
String[] aacTerms = {"aac", "advanced", "achiev"};
|
||||
String[] svoTerms = {"svo", "superb", "vote"};
|
||||
String[] ontTerms = {"ont", "onoime", "time"};
|
||||
String[] ecoTerms = {"eco", "money", "bal"};
|
||||
String[] towTerms = {"tow", "town", "nation", "res", "plot", "perm"};
|
||||
|
||||
List<String> aac = new ArrayList<>();
|
||||
List<String> svo = new ArrayList<>();
|
||||
List<String> ont = new ArrayList<>();
|
||||
List<String> eco = new ArrayList<>();
|
||||
List<String> tow = new ArrayList<>();
|
||||
|
||||
aac.addAll(Arrays.asList(aacTerms));
|
||||
svo.addAll(Arrays.asList(svoTerms));
|
||||
ont.addAll(Arrays.asList(ontTerms));
|
||||
eco.addAll(Arrays.asList(ecoTerms));
|
||||
tow.addAll(Arrays.asList(towTerms));
|
||||
String[] returnArray = new String[args.length];
|
||||
argloop:
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
for (String s : aac) {
|
||||
if (args[i].toLowerCase().contains(s)) {
|
||||
returnArray[i] = "AAC";
|
||||
continue argloop;
|
||||
}
|
||||
}
|
||||
for (String s : svo) {
|
||||
if (args[i].toLowerCase().contains(s)) {
|
||||
returnArray[i] = "SVO";
|
||||
continue argloop;
|
||||
}
|
||||
}
|
||||
for (String s : ont) {
|
||||
if (args[i].toLowerCase().contains(s)) {
|
||||
returnArray[i] = "ONT";
|
||||
continue argloop;
|
||||
}
|
||||
}
|
||||
for (String s : eco) {
|
||||
if (args[i].toLowerCase().contains(s)) {
|
||||
returnArray[i] = "ECO";
|
||||
continue argloop;
|
||||
}
|
||||
}
|
||||
for (String s : tow) {
|
||||
if (args[i].toLowerCase().contains(s)) {
|
||||
returnArray[i] = "TOW";
|
||||
continue argloop;
|
||||
}
|
||||
}
|
||||
returnArray[i] = args[i];
|
||||
if (args[i].equals("-p")) {
|
||||
returnArray[0] = args[0] + "_(Playername)";
|
||||
returnArray[i] = "---";
|
||||
}
|
||||
}
|
||||
return returnArray;
|
||||
}
|
||||
|
||||
// Creates a new Date with Epoch second and returns Date and Time String
|
||||
public static String formatTimeStamp(String string) throws NumberFormatException {
|
||||
long ms = Long.parseLong(string);
|
||||
Date sfd = new Date(ms);
|
||||
return ("" + sfd).substring(4, 19);
|
||||
}
|
||||
|
||||
// Formats Time Since (0 -> string)
|
||||
public static String formatTimeAmount(String string) throws NumberFormatException {
|
||||
long ms = Long.parseLong(string);
|
||||
return turnMsLongToString(ms);
|
||||
}
|
||||
|
||||
// Formats Time Difference String before -> Date now
|
||||
public static String formatTimeAmountSinceString(String string, Date now) throws NumberFormatException {
|
||||
long ms = Math.abs((now.toInstant().getEpochSecond() * 1000) - Long.parseLong(string));
|
||||
return turnMsLongToString(ms);
|
||||
}
|
||||
|
||||
// Formats Time Difference Date before -> Date now
|
||||
public static String formatTimeAmountSinceDate(Date before, Date now) throws NumberFormatException {
|
||||
long ms = Math.abs((now.toInstant().getEpochSecond() * 1000) - (before.toInstant().getEpochSecond() * 1000));
|
||||
return turnMsLongToString(ms);
|
||||
}
|
||||
|
||||
// Formats long in milliseconds into d:h:m:s string
|
||||
private static String turnMsLongToString(long ms) {
|
||||
String returnValue = "";
|
||||
long x = ms / 1000;
|
||||
long seconds = x % 60;
|
||||
x /= 60;
|
||||
long minutes = x % 60;
|
||||
x /= 60;
|
||||
long hours = x % 24;
|
||||
x /= 24;
|
||||
long days = x;
|
||||
if (days != 0) {
|
||||
returnValue += days + "d ";
|
||||
}
|
||||
if (hours != 0) {
|
||||
returnValue += hours + "h ";
|
||||
}
|
||||
if (minutes != 0) {
|
||||
returnValue += minutes + "m ";
|
||||
}
|
||||
if (seconds != 0) {
|
||||
returnValue += seconds + "s";
|
||||
}
|
||||
if (returnValue.isEmpty()) {
|
||||
returnValue += "< 1s";
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
// Removes letters from a string leaving only numbers and dots.
|
||||
public static String removeLetters(String dataPoint) {
|
||||
String numbers = "0123456789.";
|
||||
List<Character> numList = new ArrayList<>();
|
||||
char[] numberArray = numbers.toCharArray();
|
||||
for (char c : numberArray) {
|
||||
numList.add(c);
|
||||
}
|
||||
String returnString = "";
|
||||
for (int i = 0; i < dataPoint.length(); i++) {
|
||||
if (numList.contains(dataPoint.charAt(i))) {
|
||||
returnString += dataPoint.charAt(i);
|
||||
}
|
||||
}
|
||||
return returnString;
|
||||
}
|
||||
|
||||
// Sorts HashMap into Sorted List of Arrays
|
||||
public static List<String[]> turnDataHashMapToSortedListOfArrays(HashMap<String, DataPoint> data) {
|
||||
List<String[]> dataList = new ArrayList<>();
|
||||
data.keySet().stream().forEach((key) -> {
|
||||
dataList.add(new String[]{key, data.get(key).data()});
|
||||
});
|
||||
Collections.sort(dataList, (String[] strings, String[] otherStrings) -> strings[0].compareTo(otherStrings[0]));
|
||||
return dataList;
|
||||
}
|
||||
}
|
114
Plan Lite/src/com/djrapitops/plan/command/utils/DataUtils.java
Normal file
114
Plan Lite/src/com/djrapitops/plan/command/utils/DataUtils.java
Normal file
@ -0,0 +1,114 @@
|
||||
package com.djrapitops.plan.command.utils;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.UUIDFetcher;
|
||||
import com.djrapitops.plan.api.DataPoint;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
|
||||
public class DataUtils {
|
||||
|
||||
// allData defined by -a argument in InspectCommand
|
||||
// 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;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static HashMap<String, DataPoint> analyze(HashMap<UUID, HashMap<String, DataPoint>> playerData) {
|
||||
return Analysis.analyze(playerData);
|
||||
}
|
||||
|
||||
public static String getPlayerDisplayname(String[] args, CommandSender sender) {
|
||||
String playerName = "";
|
||||
Plan plugin = getPlugin(Plan.class);
|
||||
if (args.length > 0) {
|
||||
if ((args[0].equals("-a")) || (args[0].equals("-r"))) {
|
||||
playerName = "ArgumentGivenError";
|
||||
plugin.log("No username given, returned empty username.");
|
||||
|
||||
plugin.logToFile("INSPECT-GETNAME\nNo username given, returned empty username.\n" + args[0]);
|
||||
|
||||
} else if (sender.hasPermission("plan.inspect.other") || !(sender instanceof Player)) {
|
||||
playerName = args[0];
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Player player = plugin.getServer().getPlayer(UUIDFetcher.getUUIDOf(sender.getName()));
|
||||
playerName = player.getName();
|
||||
} catch (Exception e) {
|
||||
playerName = "ConsoleNotPlayerErr";
|
||||
}
|
||||
}
|
||||
return playerName;
|
||||
}
|
||||
|
||||
public static Set<OfflinePlayer> getMatchingDisplaynames(String[] args, CommandSender sender, boolean all) {
|
||||
List<OfflinePlayer> players = new ArrayList<>();
|
||||
players.addAll(Arrays.asList(Bukkit.getOfflinePlayers()));
|
||||
Set<OfflinePlayer> matches = new HashSet<>();
|
||||
if (all) {
|
||||
matches.addAll(players);
|
||||
} else {
|
||||
List<String> searchTerms = new ArrayList<>();
|
||||
searchTerms.addAll(Arrays.asList(args));
|
||||
|
||||
players.parallelStream().forEach((p) -> {
|
||||
searchTerms.stream().filter((searchTerm) -> (p.getName().toLowerCase().contains(searchTerm.toLowerCase()))).forEach((_item) -> {
|
||||
matches.add(p);
|
||||
});
|
||||
});
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
|
||||
public static Set<OfflinePlayer> getMatchingDisplaynames(boolean b) {
|
||||
return getMatchingDisplaynames(new String[0], null, true);
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package com.djrapitops.plan.command.utils;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
|
||||
public class MiscUtils {
|
||||
// <h1>Plan - Player Analytics <span class="muted">
|
||||
|
||||
public static String checkVersion() {
|
||||
Plan plugin = getPlugin(Plan.class);
|
||||
String[] nVersion;
|
||||
String[] cVersion;
|
||||
String lineWithVersion;
|
||||
try {
|
||||
URL githubUrl = new URL("https://raw.githubusercontent.com/Rsl1122/Plan-PlayerAnalytics/master/src/plugin.yml");
|
||||
lineWithVersion = "";
|
||||
Scanner websiteScanner = new Scanner(githubUrl.openStream());
|
||||
while (websiteScanner.hasNextLine()) {
|
||||
String line = websiteScanner.nextLine();
|
||||
if (line.toLowerCase().contains("version")) {
|
||||
lineWithVersion = line;
|
||||
break;
|
||||
}
|
||||
}
|
||||
String versionString = lineWithVersion.split(": ")[1];
|
||||
nVersion = versionString.split("\\.");
|
||||
double newestVersionNumber = Double.parseDouble(nVersion[0] + "." + nVersion[1] + nVersion[2]);
|
||||
cVersion = plugin.getDescription().getVersion().split("\\.");
|
||||
double currentVersionNumber = Double.parseDouble(cVersion[0] + "." + cVersion[1] + cVersion[2]);
|
||||
if (newestVersionNumber > currentVersionNumber) {
|
||||
return "New Version (" + versionString + ") is availible at https://www.spigotmc.org/resources/plan-player-analytics.32536/";
|
||||
} else {
|
||||
return "You're running the latest version";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
plugin.logToFile("Failed to compare versions.\n"+e);
|
||||
}
|
||||
return "Failed to get newest version number.";
|
||||
}
|
||||
|
||||
public static String[] mergeArrays(String[]... arrays) {
|
||||
int arraySize = 0;
|
||||
for (String[] array : arrays) {
|
||||
arraySize += array.length;
|
||||
}
|
||||
String[] result = new String[arraySize];
|
||||
int j = 0;
|
||||
for (String[] array : arrays) {
|
||||
for (String string : array) {
|
||||
result[j++] = string;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
13
Plan Lite/src/config.yml
Normal file
13
Plan Lite/src/config.yml
Normal file
@ -0,0 +1,13 @@
|
||||
debug: true
|
||||
|
||||
visible:
|
||||
bukkitdata: true
|
||||
ontime: true
|
||||
essentials: true
|
||||
factions: true
|
||||
towny: true
|
||||
vault: true
|
||||
superbvote: true
|
||||
placeholderapi: true
|
||||
advancedachievements: true
|
||||
playerlogger: true
|
83
Plan Lite/src/plugin.yml
Normal file
83
Plan Lite/src/plugin.yml
Normal file
@ -0,0 +1,83 @@
|
||||
name: Plan
|
||||
main: com.djrapitops.plan.Plan
|
||||
version: 1.6.2
|
||||
|
||||
commands:
|
||||
plan:
|
||||
usage: /<command> <name>
|
||||
description: base command
|
||||
inspect:
|
||||
usage: /plan inspect <name>
|
||||
description: inspect player data
|
||||
analyze:
|
||||
usage: /plan analyze
|
||||
description: analyze all players' data, add -refresh to refresh analysis.
|
||||
reload:
|
||||
usage: /plan reload
|
||||
description: reload plugin config
|
||||
search:
|
||||
usage: /plan <search terms> -p add -p to make not search playername
|
||||
description: search data of multiple players with search terms
|
||||
debug:
|
||||
usage: /plan debug
|
||||
description: run commands to debug the plugin.
|
||||
|
||||
softdepend:
|
||||
- OnTime
|
||||
- EssentialsX
|
||||
- Towny
|
||||
- Vault
|
||||
- Factions
|
||||
- SuperbVote
|
||||
- PlaceholderAPI
|
||||
- AdvancedAchievements
|
||||
- PlayerLogger
|
||||
|
||||
permissions:
|
||||
plan.?:
|
||||
description: Help command
|
||||
default: true
|
||||
plan.inspect:
|
||||
description: Allows you to check your player data.
|
||||
default: true
|
||||
plan.inspect.other:
|
||||
description: Allows you to check other players' player data.
|
||||
default: true
|
||||
plan.analyze:
|
||||
description: Allows you to check analysed data about all players.
|
||||
default: true
|
||||
plan.analyze.refresh:
|
||||
description: Allows you to refresh the analyse result with -r argument
|
||||
default: op
|
||||
plan.reload:
|
||||
description: Allows to reload plugin config
|
||||
default: true
|
||||
plan.search:
|
||||
description: Allows search
|
||||
default: true
|
||||
plan.info:
|
||||
description: Allows to view info
|
||||
default: true
|
||||
plan.debug:
|
||||
description: Allows debug command
|
||||
default: op
|
||||
plan.basic:
|
||||
children:
|
||||
plan.?: true
|
||||
plan.inspect: true
|
||||
plan.info: true
|
||||
plan.search: true
|
||||
plan.advanced:
|
||||
childer:
|
||||
plan.basic: true
|
||||
plan.analyze: true
|
||||
plan.staff:
|
||||
children:
|
||||
plan.debug: true
|
||||
plan.advanced: true
|
||||
plan.inspect.other: true
|
||||
plan.analyze.refresh: true
|
||||
plan.reload: true
|
||||
plan.*:
|
||||
children:
|
||||
plan.staff: true
|
@ -1,12 +0,0 @@
|
||||
compile.on.save=true
|
||||
do.depend=false
|
||||
do.jar=true
|
||||
file.reference.AdvancedAchievements-4.0.2.jar=D:\\Minecraft Servers\\TestServer\\plugins\\Uusi kansio\\AdvancedAchievements.jar
|
||||
file.reference.craftbukkit-1.10.2.jar=D:\\Minecraft Servers\\Buildtools\\craftbukkit-1.10.2.jar
|
||||
file.reference.EssentialsX-2.0.1.jar=D:\\Minecraft Servers\\TestServer\\plugins\\Uusi kansio\\EssentialsX-2.0.1.jar
|
||||
file.reference.OnTime.jar=D:\\Minecraft Servers\\TestServer\\plugins\\Uusi kansio\\OnTime.jar
|
||||
file.reference.Towny.jar=D:\\Minecraft Servers\\TestServer\\plugins\\Uusi kansio\\Towny.jar
|
||||
file.reference.Vault.jar=D:\\Minecraft Servers\\TestServer\\plugins\\Uusi kansio\\Vault.jar
|
||||
javac.debug=true
|
||||
javadoc.preview=true
|
||||
user.properties.file=C:\\Users\\Risto\\AppData\\Roaming\\.tmcbeans\\8.1.0\\build.properties
|
@ -1,20 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
|
||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
||||
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
|
||||
<group>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/command/hooks/PlayerLoggerHook.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/command/hooks/EssentialsHook.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/command/hooks/PlaceholderAPIHook.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/command/hooks/AdvancedAchievementsHook.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/command/hooks/FactionsHook.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/command/hooks/BukkitDataHook.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/Plan.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/command/hooks/VaultHook.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/command/hooks/SuperbVoteHook.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/command/hooks/TownyHook.java</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/plugin.yml</file>
|
||||
<file>file:/C:/Users/Risto/Documents/NetBeansProjects/Plan/src/com/djrapitops/plan/command/hooks/OnTimeHook.java</file>
|
||||
</group>
|
||||
</open-files>
|
||||
</project-private>
|
@ -1,83 +1 @@
|
||||
name: Plan
|
||||
main: com.djrapitops.plan.Plan
|
||||
version: 1.6.2
|
||||
|
||||
commands:
|
||||
plan:
|
||||
usage: /<command> <name>
|
||||
description: base command
|
||||
inspect:
|
||||
usage: /plan inspect <name>
|
||||
description: inspect player data
|
||||
analyze:
|
||||
usage: /plan analyze
|
||||
description: analyze all players' data, add -refresh to refresh analysis.
|
||||
reload:
|
||||
usage: /plan reload
|
||||
description: reload plugin config
|
||||
search:
|
||||
usage: /plan <search terms> -p add -p to make not search playername
|
||||
description: search data of multiple players with search terms
|
||||
debug:
|
||||
usage: /plan debug
|
||||
description: run commands to debug the plugin.
|
||||
|
||||
softdepend:
|
||||
- OnTime
|
||||
- EssentialsX
|
||||
- Towny
|
||||
- Vault
|
||||
- Factions
|
||||
- SuperbVote
|
||||
- PlaceholderAPI
|
||||
- AdvancedAchievements
|
||||
- PlayerLogger
|
||||
|
||||
permissions:
|
||||
plan.?:
|
||||
description: Help command
|
||||
default: true
|
||||
plan.inspect:
|
||||
description: Allows you to check your player data.
|
||||
default: true
|
||||
plan.inspect.other:
|
||||
description: Allows you to check other players' player data.
|
||||
default: true
|
||||
plan.analyze:
|
||||
description: Allows you to check analysed data about all players.
|
||||
default: true
|
||||
plan.analyze.refresh:
|
||||
description: Allows you to refresh the analyse result with -r argument
|
||||
default: op
|
||||
plan.reload:
|
||||
description: Allows to reload plugin config
|
||||
default: true
|
||||
plan.search:
|
||||
description: Allows search
|
||||
default: true
|
||||
plan.info:
|
||||
description: Allows to view info
|
||||
default: true
|
||||
plan.debug:
|
||||
description: Allows debug command
|
||||
default: op
|
||||
plan.basic:
|
||||
children:
|
||||
plan.?: true
|
||||
plan.inspect: true
|
||||
plan.info: true
|
||||
plan.search: true
|
||||
plan.advanced:
|
||||
childer:
|
||||
plan.basic: true
|
||||
plan.analyze: true
|
||||
plan.staff:
|
||||
children:
|
||||
plan.debug: true
|
||||
plan.advanced: true
|
||||
plan.inspect.other: true
|
||||
plan.analyze.refresh: true
|
||||
plan.reload: true
|
||||
plan.*:
|
||||
children:
|
||||
plan.staff: true
|
Loading…
x
Reference in New Issue
Block a user