mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-02-12 18:31:24 +01:00
Moved to use new utility package, attempts at #113
New Utility jar BukkitPluginDependency contains new classes that include methods & classes usually required for me to start creating a project, such as: - Version check - Abstract command classes (For subcommands & commands w/ subcommands) - UUIDFetcher - Log utility - Benchmarking It was tested with Plan to ensure it works. It will be used in the future to lower the threshold of starting a new project.
This commit is contained in:
parent
6d0819fc45
commit
7949113f6e
@ -39,19 +39,20 @@
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>org/**</exclude>
|
||||
<exclude>javassist/**</exclude>
|
||||
<exclude>mockito-extensions/**</exclude>
|
||||
<exclude>net/**</exclude>
|
||||
<exclude>junit/**</exclude>
|
||||
<exclude>com/thoughtworks/**</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
<artifactSet>
|
||||
<excludes>
|
||||
<exclude>org.powermock:*</exclude>
|
||||
<exclude>org.javassist:*</exclude>
|
||||
<exclude>com.thoughtworks.xstream:*</exclude>
|
||||
<exclude>xmlpull:*</exclude>
|
||||
<exclude>xpp3:*</exclude>
|
||||
<exclude>org.objenesis:*</exclude>
|
||||
<exclude>cglib:*</exclude>
|
||||
<exclude>org.*:*</exclude>
|
||||
<exclude>org.easymock:*</exclude>
|
||||
<exclude>junit:*</exclude>
|
||||
</excludes>
|
||||
</artifactSet>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
@ -111,6 +112,54 @@
|
||||
<type>pom</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito</artifactId>
|
||||
<version>1.6.6</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<version>1.6.6</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4-rule</artifactId>
|
||||
<version>1.6.6</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-classloading-xstream</artifactId>
|
||||
<version>1.6.6</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>1.10.19</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-easymock</artifactId>
|
||||
<version>1.6.6</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<version>3.4</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
|
33
Plan/pom.xml
33
Plan/pom.xml
@ -13,6 +13,12 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- SoftDepended Plugins-->
|
||||
<dependency>
|
||||
<groupId>com.djrapitops</groupId>
|
||||
<artifactId>BukkitPluginDependency</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.djrapitops</groupId>
|
||||
<artifactId>PlanPluginBridge</artifactId>
|
||||
@ -113,19 +119,20 @@
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>org/**</exclude>
|
||||
<exclude>javassist/**</exclude>
|
||||
<exclude>mockito-extensions/**</exclude>
|
||||
<exclude>net/**</exclude>
|
||||
<exclude>junit/**</exclude>
|
||||
<exclude>com/thoughtworks/**</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
<artifactSet>
|
||||
<excludes>
|
||||
<exclude>org.powermock:*</exclude>
|
||||
<exclude>org.javassist:*</exclude>
|
||||
<exclude>com.thoughtworks.xstream:*</exclude>
|
||||
<exclude>xmlpull:*</exclude>
|
||||
<exclude>xpp3:*</exclude>
|
||||
<exclude>org.objenesis:*</exclude>
|
||||
<exclude>cglib:*</exclude>
|
||||
<exclude>org.*:*</exclude>
|
||||
<exclude>org.easymock:*</exclude>
|
||||
<exclude>junit:*</exclude>
|
||||
</excludes>
|
||||
</artifactSet>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
@ -1,13 +1,6 @@
|
||||
package main.java.com.djrapitops.plan;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Collection;
|
||||
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
|
||||
/**
|
||||
* This class manages the messages going to the Bukkit's Logger.
|
||||
@ -17,27 +10,17 @@ import org.bukkit.command.ConsoleCommandSender;
|
||||
*/
|
||||
public class Log {
|
||||
|
||||
final private static String DEBUG = "DebugLog.txt";
|
||||
final private static String ERRORS = "Errors.txt";
|
||||
|
||||
/**
|
||||
* Logs the message to the console as INFO.
|
||||
*
|
||||
* @param message "Message" will show up as [INFO][Plan]: Message
|
||||
*/
|
||||
public static void info(String message) {
|
||||
Plan instance = Plan.getInstance();
|
||||
if (instance != null) {
|
||||
instance.getLogger().info(message);
|
||||
}
|
||||
if (!message.contains("[DEBUG]")) {
|
||||
debug(message);
|
||||
}
|
||||
Plan.getInstance().getPluginLogger().info(message);
|
||||
}
|
||||
|
||||
public static void infoColor(String message) {
|
||||
ConsoleCommandSender consoleSender = Plan.getInstance().getServer().getConsoleSender();
|
||||
consoleSender.sendMessage(Phrase.PREFIX + message);
|
||||
Plan.getInstance().getPluginLogger().infoColor(message);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -46,10 +29,7 @@ public class Log {
|
||||
* @param message "Message" will show up as [ERROR][Plan]: Message
|
||||
*/
|
||||
public static void error(String message) {
|
||||
Plan instance = Plan.getInstance();
|
||||
if (instance != null) {
|
||||
instance.getLogger().severe(message);
|
||||
}
|
||||
Plan.getInstance().getPluginLogger().error(message);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -58,16 +38,7 @@ public class Log {
|
||||
* @param message "Message" will show up as [INFO][Plan]: [DEBUG] Message
|
||||
*/
|
||||
public static void debug(String message) {
|
||||
String debugMode = Settings.DEBUG.toString().toLowerCase();
|
||||
boolean both = debugMode.equals("true") || debugMode.equals("both");
|
||||
boolean logConsole = Settings.DEBUG.isTrue() || both || debugMode.equals("console");
|
||||
boolean logFile = debugMode.equals("file") || both;
|
||||
if (logConsole) {
|
||||
info("[DEBUG] " + message);
|
||||
}
|
||||
if (logFile) {
|
||||
toLog(message, DEBUG);
|
||||
}
|
||||
Plan.getInstance().getPluginLogger().debug(message);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,12 +48,7 @@ public class Log {
|
||||
* @param e Throwable, eg NullPointerException
|
||||
*/
|
||||
public static void toLog(String source, Throwable e) {
|
||||
error(Phrase.ERROR_LOGGED.parse(e.toString()));
|
||||
toLog(source + " Caught " + e, ERRORS);
|
||||
for (StackTraceElement x : e.getStackTrace()) {
|
||||
toLog(" " + x, ERRORS);
|
||||
}
|
||||
toLog("", ERRORS);
|
||||
Plan.getInstance().getPluginLogger().toLog(source, e);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -92,9 +58,7 @@ public class Log {
|
||||
* @param e Collection of Throwables, eg NullPointerException
|
||||
*/
|
||||
public static void toLog(String source, Collection<Throwable> e) {
|
||||
for (Throwable ex : e) {
|
||||
toLog(source, ex);
|
||||
}
|
||||
Plan.getInstance().getPluginLogger().toLog(source, e);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,34 +68,10 @@ public class Log {
|
||||
* @param filename Name of the file to write to.
|
||||
*/
|
||||
public static void toLog(String message, String filename) {
|
||||
if (filename.equals(ERRORS)) {
|
||||
Log.debug(message);
|
||||
}
|
||||
Plan plan = Plan.getInstance();
|
||||
if (plan == null) {
|
||||
return;
|
||||
}
|
||||
File folder = plan.getDataFolder();
|
||||
if (!folder.exists()) {
|
||||
folder.mkdir();
|
||||
}
|
||||
File log = new File(folder, filename);
|
||||
try {
|
||||
if (!log.exists()) {
|
||||
log.createNewFile();
|
||||
}
|
||||
FileWriter fw = new FileWriter(log, true);
|
||||
try (PrintWriter pw = new PrintWriter(fw)) {
|
||||
String timestamp = FormatUtils.formatTimeStampSecond(MiscUtils.getTime());
|
||||
pw.println("[" + timestamp + "] " + message);
|
||||
pw.flush();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.error("Failed to create" + filename + "file");
|
||||
}
|
||||
Plan.getInstance().getPluginLogger().toLog(message, filename);
|
||||
}
|
||||
|
||||
public static String getErrorsFilename() {
|
||||
return ERRORS;
|
||||
return Plan.getInstance().getPluginLogger().getErrorsFilename();
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,8 @@
|
||||
*/
|
||||
package main.java.com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.javaplugin.ColorScheme;
|
||||
import com.djrapitops.javaplugin.RslPlugin;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
@ -42,7 +44,6 @@ import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
@ -53,7 +54,7 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
* @author Rsl1122
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class Plan extends JavaPlugin {
|
||||
public class Plan extends RslPlugin<Plan> {
|
||||
|
||||
private API api;
|
||||
private DataCacheHandler handler;
|
||||
@ -79,19 +80,25 @@ public class Plan extends JavaPlugin {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
setInstance(this);
|
||||
getDataFolder().mkdirs();
|
||||
super.setDebugMode(Settings.DEBUG.toString());
|
||||
super.setColorScheme(new ColorScheme(Phrase.COLOR_MAIN.color(), Phrase.COLOR_SEC.color(), Phrase.COLOR_TER.color()));
|
||||
super.setLogPrefix("[Plan]");
|
||||
super.setUpdateCheckUrl("https://raw.githubusercontent.com/Rsl1122/Plan-PlayerAnalytics/master/Plan/src/main/resources/plugin.yml");
|
||||
super.setUpdateUrl("https://www.spigotmc.org/resources/plan-player-analytics.32536/");
|
||||
super.onEnableDefaultTasks();
|
||||
|
||||
initLocale();
|
||||
|
||||
Server server = getServer();
|
||||
|
||||
Server server = getServer();
|
||||
variable = new ServerVariableHolder(server);
|
||||
|
||||
|
||||
Log.debug("-------------------------------------");
|
||||
Log.debug("Debug log, Server Start: Plan v."+getDescription().getVersion());
|
||||
Log.debug("Server: "+server.getBukkitVersion());
|
||||
Log.debug("Version: "+server.getVersion());
|
||||
Log.debug("Debug log: Plan v." + getDescription().getVersion());
|
||||
Log.debug("Implements RslPlugin v." + getRslVersion());
|
||||
Log.debug("Server: " + server.getBukkitVersion());
|
||||
Log.debug("Version: " + server.getVersion());
|
||||
Log.debug("-------------------------------------");
|
||||
|
||||
|
||||
databases = new HashSet<>();
|
||||
databases.add(new MySQLDB(this));
|
||||
databases.add(new SQLiteDB(this));
|
||||
@ -100,8 +107,6 @@ public class Plan extends JavaPlugin {
|
||||
getConfig().options().header(Phrase.CONFIG_HEADER + "");
|
||||
saveConfig();
|
||||
|
||||
Log.info(MiscUtils.checkVersion());
|
||||
|
||||
Log.info(Phrase.DB_INIT + "");
|
||||
if (initDatabase()) {
|
||||
Log.info(Phrase.DB_ESTABLISHED.parse(db.getConfigName()));
|
||||
@ -136,13 +141,13 @@ public class Plan extends JavaPlugin {
|
||||
|| (Settings.USE_ALTERNATIVE_UI.isTrue())) {
|
||||
Log.infoColor(Phrase.ERROR_NO_DATA_VIEW + "");
|
||||
}
|
||||
if (!Settings.SHOW_ALTERNATIVE_IP.isTrue() && server.getIp().isEmpty()) {
|
||||
if (!Settings.SHOW_ALTERNATIVE_IP.isTrue() && variable.getIp().isEmpty()) {
|
||||
Log.infoColor(Phrase.NOTIFY_EMPTY_IP + "");
|
||||
}
|
||||
|
||||
hookHandler = new HookHandler();
|
||||
|
||||
Log.debug("Verboose debug messages are enabled.");
|
||||
|
||||
Log.debug("Verboose debug messages are enabled.");
|
||||
Log.info(Phrase.ENABLED + "");
|
||||
}
|
||||
|
||||
@ -175,27 +180,27 @@ public class Plan extends JavaPlugin {
|
||||
pluginManager.registerEvents(new PlanPlayerListener(this), this);
|
||||
|
||||
if (Settings.GATHERCHAT.isTrue()) {
|
||||
pluginManager.registerEvents(new PlanChatListener(this), this);
|
||||
registerListener(new PlanChatListener(this));
|
||||
} else {
|
||||
Log.infoColor(Phrase.NOTIFY_DISABLED_CHATLISTENER + "");
|
||||
}
|
||||
if (Settings.GATHERGMTIMES.isTrue()) {
|
||||
pluginManager.registerEvents(new PlanGamemodeChangeListener(this), this);
|
||||
registerListener(new PlanGamemodeChangeListener(this));
|
||||
} else {
|
||||
Log.infoColor(Phrase.NOTIFY_DISABLED_GMLISTENER + "");
|
||||
}
|
||||
if (Settings.GATHERCOMMANDS.isTrue()) {
|
||||
pluginManager.registerEvents(new PlanCommandPreprocessListener(this), this);
|
||||
registerListener(new PlanCommandPreprocessListener(this));
|
||||
} else {
|
||||
Log.infoColor(Phrase.NOTIFY_DISABLED_COMMANDLISTENER + "");
|
||||
}
|
||||
if (Settings.GATHERKILLS.isTrue()) {
|
||||
pluginManager.registerEvents(new PlanDeathEventListener(this), this);
|
||||
registerListener(new PlanDeathEventListener(this));
|
||||
} else {
|
||||
Log.infoColor(Phrase.NOTIFY_DISABLED_DEATHLISTENER + "");
|
||||
}
|
||||
if (Settings.GATHERLOCATIONS.isTrue()) {
|
||||
pluginManager.registerEvents(new PlanPlayerMoveListener(this), this);
|
||||
registerListener(new PlanPlayerMoveListener(this));
|
||||
}
|
||||
}
|
||||
|
||||
@ -400,32 +405,6 @@ public class Plan extends JavaPlugin {
|
||||
public ServerVariableHolder getVariable() {
|
||||
return variable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the current instance of Plan.
|
||||
*
|
||||
* Instance is set on the first line of onEnable method.
|
||||
*
|
||||
* @return current instance of Plan, Singleton.
|
||||
* @throws IllegalStateException If onEnable method has not been called and
|
||||
* the instance is null.
|
||||
*/
|
||||
public static Plan getInstance() {
|
||||
Plan INSTANCE = PlanHolder.INSTANCE;
|
||||
if (INSTANCE == null) {
|
||||
throw new IllegalStateException("Plugin not enabled properly, Singleton instance is null.");
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to set the current instance of Plan.
|
||||
*
|
||||
* @param plan The newly enabled Plan instance.
|
||||
*/
|
||||
public static void setInstance(Plan plan) {
|
||||
PlanHolder.INSTANCE = plan;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the PlanAPI. @see API
|
||||
@ -435,15 +414,14 @@ public class Plan extends JavaPlugin {
|
||||
* Plan and the instance is null.
|
||||
*/
|
||||
public static API getPlanAPI() throws IllegalStateException {
|
||||
Plan INSTANCE = PlanHolder.INSTANCE;
|
||||
Plan INSTANCE = getInstance();
|
||||
if (INSTANCE == null) {
|
||||
throw new IllegalStateException("Plugin not enabled properly, Singleton instance is null.");
|
||||
}
|
||||
return INSTANCE.api;
|
||||
}
|
||||
|
||||
private static class PlanHolder {
|
||||
|
||||
private static Plan INSTANCE = null;
|
||||
|
||||
public static Plan getInstance() {
|
||||
return (Plan) getPluginInstance();
|
||||
}
|
||||
}
|
||||
|
@ -3,19 +3,27 @@ package main.java.com.djrapitops.plan;
|
||||
import org.bukkit.Server;
|
||||
|
||||
/**
|
||||
* Class responsible for holding server variable values that do not change
|
||||
* without a reload.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.4.1
|
||||
*/
|
||||
public class ServerVariableHolder {
|
||||
|
||||
private int maxPlayers;
|
||||
private String ip;
|
||||
|
||||
public ServerVariableHolder(Server server) {
|
||||
maxPlayers = server.getMaxPlayers();
|
||||
ip = server.getIp();
|
||||
}
|
||||
|
||||
public int getMaxPlayers() {
|
||||
return maxPlayers;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package main.java.com.djrapitops.plan.api;
|
||||
|
||||
import com.djrapitops.javaplugin.utilities.UUIDFetcher;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -14,7 +15,6 @@ import main.java.com.djrapitops.plan.data.handling.info.HandlingInfo;
|
||||
import main.java.com.djrapitops.plan.ui.DataRequestHandler;
|
||||
import main.java.com.djrapitops.plan.ui.webserver.WebSocketServer;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.uuid.UUIDFetcher;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
|
@ -1,16 +0,0 @@
|
||||
package main.java.com.djrapitops.plan.command;
|
||||
|
||||
/**
|
||||
* This enum contains different types of commands.
|
||||
*
|
||||
* CONSOLE can be used always, PLAYER can only be used as a player,
|
||||
* CONSOLE_WITH_ARGUMENTS can be used always, except with arguments on console.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public enum CommandType {
|
||||
CONSOLE,
|
||||
PLAYER,
|
||||
CONSOLE_WITH_ARGUMENTS
|
||||
}
|
@ -1,17 +1,15 @@
|
||||
package main.java.com.djrapitops.plan.command;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import com.djrapitops.javaplugin.command.TreeCommand;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.command.commands.*;
|
||||
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* CommandExecutor for the /plan command, and all subcommands.
|
||||
@ -19,9 +17,7 @@ import org.bukkit.entity.Player;
|
||||
* @author Rsl1122
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class PlanCommand implements CommandExecutor {
|
||||
|
||||
private final List<SubCommand> commands;
|
||||
public class PlanCommand extends TreeCommand<Plan> implements CommandExecutor {
|
||||
|
||||
/**
|
||||
* CommandExecutor class Constructor.
|
||||
@ -31,8 +27,19 @@ public class PlanCommand implements CommandExecutor {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public PlanCommand(Plan plugin) {
|
||||
commands = new ArrayList<>();
|
||||
commands.add(new HelpCommand(plugin, this));
|
||||
super(plugin, new SubCommand("plan", CommandType.CONSOLE, "") {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
return true;
|
||||
}
|
||||
}, "plan");
|
||||
super.setDefaultCommand("inspect");
|
||||
// commands.add(new HelpCommand(plugin, this));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCommands() {
|
||||
commands.add(new InspectCommand(plugin));
|
||||
commands.add(new QuickInspectCommand(plugin));
|
||||
commands.add(new AnalyzeCommand(plugin));
|
||||
@ -42,94 +49,4 @@ public class PlanCommand implements CommandExecutor {
|
||||
commands.add(new ReloadCommand(plugin));
|
||||
commands.add(new ManageCommand(plugin));
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the list of all subcommands.
|
||||
*
|
||||
* @return Initialized SubCommands
|
||||
*/
|
||||
public List<SubCommand> getCommands() {
|
||||
return this.commands;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks SubCommands for matching aliases.
|
||||
*
|
||||
* @param name SubCommand in text form that might match alias.
|
||||
* @return SubCommand, null if no match.
|
||||
*/
|
||||
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, FormatUtils.mergeArrays(new String[]{command}, args));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if Sender has rights to run the command and executes matching
|
||||
* subcommand.
|
||||
*
|
||||
* @param sender source of the command.
|
||||
* @param cmd command.
|
||||
* @param commandLabel label.
|
||||
* @param args arguments of the command
|
||||
* @return true
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
Log.debug("Registered command with arguments: "+Arrays.toString(args));
|
||||
if (args.length < 1) {
|
||||
sendDefaultCommand(sender, cmd, commandLabel, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
SubCommand command = getCommand(args[0]);
|
||||
|
||||
if (command == null) {
|
||||
sendDefaultCommand(sender, cmd, commandLabel, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean console = !(sender instanceof Player);
|
||||
|
||||
if (!command.getPermission().userHasThisPermission(sender)) {
|
||||
sender.sendMessage("" + Phrase.COMMAND_NO_PERMISSION);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (console && args.length < 2 && command.getCommandType() == CommandType.CONSOLE_WITH_ARGUMENTS) {
|
||||
sender.sendMessage("" + Phrase.COMMAND_REQUIRES_ARGUMENTS.parse(Phrase.USE_PLAN + ""));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (console && command.getCommandType() == CommandType.PLAYER) {
|
||||
sender.sendMessage("" + Phrase.COMMAND_SENDER_NOT_PLAYER);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
String[] realArgs = new String[args.length - 1];
|
||||
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
realArgs[i - 1] = args[i];
|
||||
}
|
||||
|
||||
command.onCommand(sender, cmd, commandLabel, realArgs);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,105 +0,0 @@
|
||||
package main.java.com.djrapitops.plan.command;
|
||||
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* Abstract subcommand class that stores all the required information of a
|
||||
* command.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public abstract class SubCommand {
|
||||
|
||||
private final String name;
|
||||
private final Permissions permission;
|
||||
private final String usage;
|
||||
private final CommandType commandType;
|
||||
private final String arguments;
|
||||
|
||||
/**
|
||||
* Class constructor, called with super(...) in subcommands.
|
||||
*
|
||||
* @param name Name(s) (aliases) of the command
|
||||
* @param permission Required permission
|
||||
* @param usage Usage information
|
||||
* @param commandType Type Enum
|
||||
* @param arguments Additional possible arguments the command requires
|
||||
*/
|
||||
public SubCommand(String name, Permissions permission, String usage, CommandType commandType, String arguments) {
|
||||
this.name = name;
|
||||
this.permission = permission;
|
||||
this.usage = usage;
|
||||
this.commandType = commandType;
|
||||
this.arguments = arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get a string format of required arguments.
|
||||
*
|
||||
* @return Additional possible arguments the command requires
|
||||
*/
|
||||
public String getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the first alias.
|
||||
*
|
||||
* @return First alias of the command
|
||||
*/
|
||||
public String getFirstName() {
|
||||
return name.split(",")[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get all aliases.
|
||||
*
|
||||
* @return All aliases separated with ','
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the permission required by the command.
|
||||
*
|
||||
* @return Required permission
|
||||
*/
|
||||
public Permissions getPermission() {
|
||||
return permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the info about usage of the command.
|
||||
*
|
||||
* @return Usage information
|
||||
*/
|
||||
public String getUsage() {
|
||||
return usage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the command type.
|
||||
*
|
||||
* @return CommandType Enum.
|
||||
*/
|
||||
public CommandType getCommandType() {
|
||||
return commandType;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Command Execution method.
|
||||
*
|
||||
* @param sender Parameter of onCommand in CommandExecutor.
|
||||
* @param cmd Parameter of onCommand in CommandExecutor.
|
||||
* @param commandLabel Parameter of onCommand in CommandExecutor.
|
||||
* @param args Parameter of onCommand in CommandExecutor.
|
||||
* @return Was the execution successful?
|
||||
* @see CommandExecutor
|
||||
*/
|
||||
public abstract boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args);
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
package main.java.com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.command.CommandType;
|
||||
import main.java.com.djrapitops.plan.command.CommandUtils;
|
||||
import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.data.cache.AnalysisCacheHandler;
|
||||
import main.java.com.djrapitops.plan.ui.TextUI;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
@ -27,8 +27,8 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
*/
|
||||
public class AnalyzeCommand extends SubCommand {
|
||||
|
||||
private Plan plugin;
|
||||
private AnalysisCacheHandler analysisCache;
|
||||
private final Plan plugin;
|
||||
private final AnalysisCacheHandler analysisCache;
|
||||
|
||||
/**
|
||||
* Subcommand Constructor.
|
||||
@ -36,7 +36,7 @@ public class AnalyzeCommand extends SubCommand {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public AnalyzeCommand(Plan plugin) {
|
||||
super("analyze, analyse, analysis", Permissions.ANALYZE, Phrase.CMD_USG_ANALYZE.parse(), CommandType.CONSOLE, "");
|
||||
super("analyze, analyse, analysis", CommandType.CONSOLE, Permissions.ANALYZE.getPermission(), Phrase.CMD_USG_ANALYZE.parse());
|
||||
this.plugin = plugin;
|
||||
analysisCache = plugin.getAnalysisCache();
|
||||
}
|
||||
|
@ -1,55 +0,0 @@
|
||||
package main.java.com.djrapitops.plan.command.commands;
|
||||
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.command.CommandType;
|
||||
import main.java.com.djrapitops.plan.command.PlanCommand;
|
||||
import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* This subcommand is used to view the subcommands.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class HelpCommand extends SubCommand {
|
||||
|
||||
private final Plan plugin;
|
||||
private final PlanCommand command;
|
||||
|
||||
/**
|
||||
* Subcommand Constructor.
|
||||
*
|
||||
* @param plugin Current instance of Plan
|
||||
* @param command Current instance of PlanCommand
|
||||
*/
|
||||
public HelpCommand(Plan plugin, PlanCommand command) {
|
||||
super("help,?", Permissions.HELP, Phrase.CMD_USG_HELP + "", CommandType.CONSOLE, "");
|
||||
|
||||
this.plugin = plugin;
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command comd, String commandLabel, String[] args) {
|
||||
boolean isConsole = !(sender instanceof Player);
|
||||
ChatColor oColor = Phrase.COLOR_MAIN.color();
|
||||
ChatColor tColor = Phrase.COLOR_SEC.color();
|
||||
|
||||
sender.sendMessage(Phrase.CMD_HELP_HEADER + "");
|
||||
|
||||
this.command.getCommands().stream()
|
||||
.filter(cmd -> !cmd.getName().equalsIgnoreCase(getName()))
|
||||
.filter(cmd -> cmd.getPermission().userHasThisPermission(sender))
|
||||
.filter(cmd -> !(isConsole && cmd.getCommandType() == CommandType.PLAYER))
|
||||
.map(cmd -> tColor + " " + Phrase.BALL.toString() + oColor + " /plan " + cmd.getFirstName() + " " + cmd.getArguments() + tColor + " - " + cmd.getUsage())
|
||||
.forEach(msg -> sender.sendMessage(msg));
|
||||
sender.sendMessage(Phrase.CMD_FOOTER + "");
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
package main.java.com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import com.djrapitops.javaplugin.utilities.VersionUtils;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.command.CommandType;
|
||||
import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -18,7 +18,7 @@ import org.bukkit.command.CommandSender;
|
||||
*/
|
||||
public class InfoCommand extends SubCommand {
|
||||
|
||||
private Plan plugin;
|
||||
private final Plan plugin;
|
||||
|
||||
/**
|
||||
* Subcommand Constructor.
|
||||
@ -26,7 +26,7 @@ public class InfoCommand extends SubCommand {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public InfoCommand(Plan plugin) {
|
||||
super("info", Permissions.INFO, Phrase.CMD_USG_INFO + "", CommandType.CONSOLE, "");
|
||||
super("info", CommandType.CONSOLE,Permissions.INFO.getPermission(), Phrase.CMD_USG_INFO + "");
|
||||
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@ -38,7 +38,7 @@ public class InfoCommand extends SubCommand {
|
||||
String[] messages = {
|
||||
Phrase.CMD_INFO_HEADER + "",
|
||||
Phrase.CMD_INFO_VERSION.parse(plugin.getDescription().getVersion()),
|
||||
Phrase.CMD_BALL.toString() + tColor + " " + MiscUtils.checkVersion(),
|
||||
Phrase.CMD_BALL.toString() + tColor + " " + VersionUtils.checkVersion(plugin),
|
||||
Phrase.CMD_MANAGE_STATUS_ACTIVE_DB.parse(plugin.getDB().getConfigName()),
|
||||
Phrase.CMD_FOOTER + ""
|
||||
};
|
||||
|
@ -1,5 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.command.CommandUtils;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
@ -7,9 +9,7 @@ import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.command.CommandType;
|
||||
import main.java.com.djrapitops.plan.command.Condition;
|
||||
import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.data.cache.InspectCacheHandler;
|
||||
import main.java.com.djrapitops.plan.ui.TextUI;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
@ -30,8 +30,8 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
*/
|
||||
public class InspectCommand extends SubCommand {
|
||||
|
||||
private Plan plugin;
|
||||
private InspectCacheHandler inspectCache;
|
||||
private final Plan plugin;
|
||||
private final InspectCacheHandler inspectCache;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
@ -39,7 +39,7 @@ public class InspectCommand extends SubCommand {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public InspectCommand(Plan plugin) {
|
||||
super("inspect", Permissions.INSPECT, Phrase.CMD_USG_INSPECT + "", CommandType.CONSOLE_WITH_ARGUMENTS, Phrase.ARG_PLAYER + "");
|
||||
super("inspect", CommandType.CONSOLE_WITH_ARGUMENTS, Permissions.INSPECT.getPermission(), Phrase.CMD_USG_INSPECT + "", Phrase.ARG_PLAYER + "");
|
||||
|
||||
this.plugin = plugin;
|
||||
inspectCache = plugin.getInspectCache();
|
||||
@ -75,7 +75,7 @@ public class InspectCommand extends SubCommand {
|
||||
private int timesrun = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
public void run() {
|
||||
timesrun++;
|
||||
if (inspectCache.isCached(uuid)) {
|
||||
sendInspectMsg(sender, playerName, uuid);
|
||||
@ -85,7 +85,7 @@ public class InspectCommand extends SubCommand {
|
||||
if (timesrun > 10) {
|
||||
Log.debug("Command Timeout Message, Inspect.");
|
||||
sender.sendMessage(Phrase.COMMAND_TIMEOUT.parse("Inspect"));
|
||||
this.cancel();
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,17 +1,14 @@
|
||||
package main.java.com.djrapitops.plan.command.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import com.djrapitops.javaplugin.command.TreeCommand;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.command.CommandType;
|
||||
import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.command.commands.manage.*;
|
||||
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* This command is used to manage the database of the plugin.
|
||||
@ -21,10 +18,7 @@ import org.bukkit.entity.Player;
|
||||
* @author Rsl1122
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public class ManageCommand extends SubCommand {
|
||||
|
||||
private final List<SubCommand> commands;
|
||||
private Plan plugin;
|
||||
public class ManageCommand extends TreeCommand<Plan> {
|
||||
|
||||
/**
|
||||
* Subcommand Constructor.
|
||||
@ -32,10 +26,16 @@ public class ManageCommand extends SubCommand {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public ManageCommand(Plan plugin) {
|
||||
super("manage, m", Permissions.MANAGE, Phrase.CMD_USG_MANAGE + "", CommandType.CONSOLE, "");
|
||||
this.plugin = plugin;
|
||||
commands = new ArrayList<>();
|
||||
commands.add(new ManageHelpCommand(plugin, this));
|
||||
super(plugin, new SubCommand("manage,m", CommandType.CONSOLE, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE + "") {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
return true;
|
||||
}
|
||||
}, "plan manage");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCommands() {
|
||||
commands.add(new ManageMoveCommand(plugin));
|
||||
commands.add(new ManageHotswapCommand(plugin));
|
||||
commands.add(new ManageBackupCommand(plugin));
|
||||
@ -45,81 +45,4 @@ public class ManageCommand extends SubCommand {
|
||||
commands.add(new ManageRemoveCommand(plugin));
|
||||
commands.add(new ManageClearCommand(plugin));
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the list of manage subcommands.
|
||||
*
|
||||
* @return Initialized SubCommands
|
||||
*/
|
||||
public List<SubCommand> getCommands() {
|
||||
return this.commands;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks SubCommands for matching aliases.
|
||||
*
|
||||
* @param name SubCommand in text form that might match alias.
|
||||
* @return SubCommand, null if no match.
|
||||
*/
|
||||
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 = "help";
|
||||
onCommand(sender, cmd, commandLabel, FormatUtils.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 (!command.getPermission().userHasThisPermission(sender)) {
|
||||
sender.sendMessage("" + Phrase.COMMAND_NO_PERMISSION);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (console && args.length < 2 && command.getCommandType() == CommandType.CONSOLE_WITH_ARGUMENTS) {
|
||||
sender.sendMessage("" + Phrase.COMMAND_REQUIRES_ARGUMENTS.parse(Phrase.USE_MANAGE + ""));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (console && command.getCommandType() == CommandType.PLAYER) {
|
||||
sender.sendMessage("" + Phrase.COMMAND_SENDER_NOT_PLAYER);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
String[] realArgs = new String[args.length - 1];
|
||||
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
realArgs[i - 1] = args[i];
|
||||
}
|
||||
|
||||
command.onCommand(sender, cmd, commandLabel, realArgs);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
package main.java.com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.command.CommandType;
|
||||
import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.data.cache.AnalysisCacheHandler;
|
||||
import main.java.com.djrapitops.plan.ui.TextUI;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
@ -23,8 +23,8 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
*/
|
||||
public class QuickAnalyzeCommand extends SubCommand {
|
||||
|
||||
private Plan plugin;
|
||||
private AnalysisCacheHandler analysisCache;
|
||||
private final Plan plugin;
|
||||
private final AnalysisCacheHandler analysisCache;
|
||||
|
||||
/**
|
||||
* Subcommand Constructor.
|
||||
@ -32,7 +32,7 @@ public class QuickAnalyzeCommand extends SubCommand {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public QuickAnalyzeCommand(Plan plugin) {
|
||||
super("qanalyze, qanalyse, qanalysis", Permissions.QUICK_ANALYZE, Phrase.CMD_USG_QANALYZE.parse(), CommandType.CONSOLE, "");
|
||||
super("qanalyze, qanalyse, qanalysis", CommandType.CONSOLE, Permissions.QUICK_ANALYZE.getPermission(), Phrase.CMD_USG_QANALYZE.parse());
|
||||
this.plugin = plugin;
|
||||
analysisCache = plugin.getAnalysisCache();
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
package main.java.com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.command.CommandType;
|
||||
import main.java.com.djrapitops.plan.command.CommandUtils;
|
||||
import main.java.com.djrapitops.plan.command.Condition;
|
||||
import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.data.cache.InspectCacheHandler;
|
||||
import main.java.com.djrapitops.plan.ui.TextUI;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
@ -26,8 +26,8 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
*/
|
||||
public class QuickInspectCommand extends SubCommand {
|
||||
|
||||
private Plan plugin;
|
||||
private InspectCacheHandler inspectCache;
|
||||
private final Plan plugin;
|
||||
private final InspectCacheHandler inspectCache;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
@ -35,7 +35,7 @@ public class QuickInspectCommand extends SubCommand {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public QuickInspectCommand(Plan plugin) {
|
||||
super("qinspect", Permissions.QUICK_INSPECT, Phrase.CMD_USG_QINSPECT + "", CommandType.CONSOLE_WITH_ARGUMENTS, Phrase.ARG_PLAYER + "");
|
||||
super("qinspect", CommandType.CONSOLE_WITH_ARGUMENTS, Permissions.QUICK_INSPECT.getPermission(), Phrase.CMD_USG_QINSPECT + "", Phrase.ARG_PLAYER + "");
|
||||
|
||||
this.plugin = plugin;
|
||||
inspectCache = plugin.getInspectCache();
|
||||
|
@ -1,10 +1,10 @@
|
||||
package main.java.com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.command.CommandType;
|
||||
import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@ -16,7 +16,7 @@ import org.bukkit.command.CommandSender;
|
||||
*/
|
||||
public class ReloadCommand extends SubCommand {
|
||||
|
||||
private Plan plugin;
|
||||
private final Plan plugin;
|
||||
|
||||
/**
|
||||
* Subcommand constructor.
|
||||
@ -24,7 +24,7 @@ public class ReloadCommand extends SubCommand {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public ReloadCommand(Plan plugin) {
|
||||
super("reload", Permissions.MANAGE, Phrase.CMD_USG_RELOAD + "", CommandType.CONSOLE, "");
|
||||
super("reload", CommandType.CONSOLE, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_RELOAD + "");
|
||||
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@ -7,10 +9,8 @@ import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.command.CommandType;
|
||||
import main.java.com.djrapitops.plan.command.CommandUtils;
|
||||
import main.java.com.djrapitops.plan.command.Condition;
|
||||
import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.data.cache.InspectCacheHandler;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
@ -39,7 +39,7 @@ public class SearchCommand extends SubCommand {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public SearchCommand(Plan plugin) {
|
||||
super("search", Permissions.SEARCH, Phrase.CMD_USG_SEARCH + "", CommandType.CONSOLE_WITH_ARGUMENTS, Phrase.ARG_SEARCH + "");
|
||||
super("search", CommandType.CONSOLE_WITH_ARGUMENTS, Permissions.SEARCH.getPermission(), Phrase.CMD_USG_SEARCH + "", Phrase.ARG_SEARCH + "");
|
||||
this.plugin = plugin;
|
||||
inspectCache = plugin.getInspectCache();
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
package main.java.com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.command.CommandType;
|
||||
import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.utilities.ManageUtils;
|
||||
import org.bukkit.command.Command;
|
||||
@ -28,7 +28,7 @@ public class ManageBackupCommand extends SubCommand {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public ManageBackupCommand(Plan plugin) {
|
||||
super("backup", Permissions.MANAGE, Phrase.CMD_USG_MANAGE_BACKUP + "", CommandType.CONSOLE, "<DB>");
|
||||
super("backup", CommandType.CONSOLE, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE_BACKUP + "", "<DB>");
|
||||
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package main.java.com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.command.CommandType;
|
||||
import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -29,7 +29,7 @@ public class ManageClearCommand extends SubCommand {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public ManageClearCommand(Plan plugin) {
|
||||
super("clear", Permissions.MANAGE, Phrase.CMD_USG_MANAGE_CLEAR + "", CommandType.CONSOLE_WITH_ARGUMENTS, "<DB> [-a]");
|
||||
super("clear", CommandType.CONSOLE_WITH_ARGUMENTS, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE_CLEAR + "", "<DB> [-a]");
|
||||
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
@ -1,69 +0,0 @@
|
||||
package main.java.com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.command.CommandType;
|
||||
import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.command.commands.ManageCommand;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* This manage subcommand is used to view all other manage subcommands.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public class ManageHelpCommand extends SubCommand {
|
||||
|
||||
private final Plan plugin;
|
||||
private final ManageCommand command;
|
||||
|
||||
/**
|
||||
* Subcommand Constructor.
|
||||
*
|
||||
* @param plugin Current instance of Plan
|
||||
* @param command Current instance of PlanCommand
|
||||
*/
|
||||
public ManageHelpCommand(Plan plugin, ManageCommand command) {
|
||||
super("help,?", Permissions.MANAGE, Phrase.CMD_USG_MANAGE_HELP + "", CommandType.CONSOLE, "");
|
||||
|
||||
this.plugin = plugin;
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command c, String commandLabel, String[] args) {
|
||||
|
||||
ChatColor oColor = Phrase.COLOR_MAIN.color();
|
||||
ChatColor tColor = Phrase.COLOR_SEC.color();
|
||||
ChatColor hColor = Phrase.COLOR_TER.color();
|
||||
|
||||
// Header
|
||||
sender.sendMessage(Phrase.CMD_MANAGE_HELP_HEADER + "");
|
||||
// Help results
|
||||
for (SubCommand cmd : this.command.getCommands()) {
|
||||
if (cmd.getName().equalsIgnoreCase(getName())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!cmd.getPermission().userHasThisPermission(sender)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player) && cmd.getCommandType() == CommandType.PLAYER) {
|
||||
continue;
|
||||
}
|
||||
|
||||
sender.sendMessage(tColor + " " + Phrase.BALL.toString() + oColor
|
||||
+ " /plan manage " + cmd.getFirstName() + " " + cmd.getArguments() + tColor + " - " + cmd.getUsage());
|
||||
}
|
||||
// Footer
|
||||
sender.sendMessage(hColor + Phrase.ARROWS_RIGHT.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
package main.java.com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import java.sql.SQLException;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.command.CommandType;
|
||||
import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -20,7 +20,7 @@ import org.bukkit.command.CommandSender;
|
||||
*/
|
||||
public class ManageHotswapCommand extends SubCommand {
|
||||
|
||||
private Plan plugin;
|
||||
private final Plan plugin;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
@ -28,7 +28,7 @@ public class ManageHotswapCommand extends SubCommand {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public ManageHotswapCommand(Plan plugin) {
|
||||
super("hotswap", Permissions.MANAGE, Phrase.CMD_USG_MANAGE_HOTSWAP + "", CommandType.CONSOLE_WITH_ARGUMENTS, "<DB>");
|
||||
super("hotswap", CommandType.CONSOLE_WITH_ARGUMENTS, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE_HOTSWAP + "", "<DB>");
|
||||
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -8,8 +10,6 @@ import java.util.stream.Collectors;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.command.CommandType;
|
||||
import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.data.handling.importing.ImportUtils;
|
||||
import main.java.com.djrapitops.plan.data.handling.importing.Importer;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayers;
|
||||
@ -36,7 +36,7 @@ public class ManageImportCommand extends SubCommand {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public ManageImportCommand(Plan plugin) {
|
||||
super("import", Permissions.MANAGE, Phrase.CMD_USG_MANAGE_IMPORT + "", CommandType.CONSOLE, Phrase.ARG_IMPORT + "");
|
||||
super("import", CommandType.CONSOLE, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE_IMPORT + "", Phrase.ARG_IMPORT + "");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
@ -7,8 +9,6 @@ import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.command.CommandType;
|
||||
import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.utilities.ManageUtils;
|
||||
import org.bukkit.command.Command;
|
||||
@ -17,9 +17,9 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
* This manage subcommand is used to move all data from one database to another.
|
||||
*
|
||||
*
|
||||
* Destination database will be cleared.
|
||||
*
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 2.3.0
|
||||
*/
|
||||
@ -33,11 +33,11 @@ public class ManageMoveCommand extends SubCommand {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public ManageMoveCommand(Plan plugin) {
|
||||
super("move", Permissions.MANAGE, Phrase.CMD_USG_MANAGE_MOVE + "", CommandType.CONSOLE_WITH_ARGUMENTS, Phrase.ARG_MOVE + "");
|
||||
super("move", CommandType.CONSOLE_WITH_ARGUMENTS, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE_MOVE + "", Phrase.ARG_MOVE + "");
|
||||
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
if (args.length < 2) {
|
||||
|
@ -1,5 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
@ -7,8 +9,6 @@ import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.command.CommandType;
|
||||
import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
import org.bukkit.command.Command;
|
||||
@ -31,7 +31,7 @@ public class ManageRemoveCommand extends SubCommand {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public ManageRemoveCommand(Plan plugin) {
|
||||
super("remove", Permissions.MANAGE, Phrase.CMD_USG_MANAGE_REMOVE + "", CommandType.CONSOLE_WITH_ARGUMENTS, Phrase.ARG_PLAYER + " [-a]");
|
||||
super("remove", CommandType.CONSOLE_WITH_ARGUMENTS, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE_REMOVE + "", Phrase.ARG_PLAYER + " [-a]");
|
||||
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@ -8,8 +10,6 @@ import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.command.CommandType;
|
||||
import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import main.java.com.djrapitops.plan.utilities.ManageUtils;
|
||||
@ -34,7 +34,7 @@ public class ManageRestoreCommand extends SubCommand {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public ManageRestoreCommand(Plan plugin) {
|
||||
super("restore", Permissions.MANAGE, Phrase.CMD_USG_MANAGE_RESTORE + "", CommandType.CONSOLE, Phrase.ARG_RESTORE + "");
|
||||
super("restore", CommandType.CONSOLE, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE_RESTORE + "", Phrase.ARG_RESTORE + "");
|
||||
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
package main.java.com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.command.CommandType;
|
||||
import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@ -23,7 +23,7 @@ public class ManageStatusCommand extends SubCommand {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public ManageStatusCommand(Plan plugin) {
|
||||
super("status", Permissions.MANAGE, Phrase.CMD_USG_MANAGE_STATUS + "", CommandType.CONSOLE, "");
|
||||
super("status", CommandType.CONSOLE, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE_STATUS + "");
|
||||
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.database;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.4.3
|
||||
* @param <T>
|
||||
*/
|
||||
public class Container<T> {
|
||||
private T object;
|
||||
private int id;
|
||||
|
||||
public Container(T object, int id) {
|
||||
this.object = object;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public T getObject() {
|
||||
return object;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
40
Plan/src/main/java/com/djrapitops/plan/database/DBUtils.java
Normal file
40
Plan/src/main/java/com/djrapitops/plan/database/DBUtils.java
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.database;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.4.3
|
||||
*/
|
||||
public class DBUtils {
|
||||
|
||||
public static <T> List<List<Container<T>>> splitIntoBatches(Map<Integer, List<T>> objects) {
|
||||
List<List<Container<T>>> wrappedBatches = new ArrayList<>();
|
||||
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
|
||||
for (Entry<Integer, List<T>> entry : objects.entrySet()) {
|
||||
for (T object : entry.getValue()) {
|
||||
if (wrappedBatches.size() - 1 <= j) {
|
||||
wrappedBatches.add(new ArrayList<>());
|
||||
}
|
||||
wrappedBatches.get(j).add(new Container<>(object, entry.getKey()));
|
||||
i++;
|
||||
if (i % 1024 == 0) {
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return wrappedBatches;
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@ -21,6 +22,8 @@ import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.tables.*;
|
||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.ManageUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
@ -151,6 +154,7 @@ public abstract class SQLDB extends Database {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
clean();
|
||||
Benchmark.start("Convert Bukkitdata to DB data");
|
||||
Set<UUID> uuids = usersTable.getSavedUUIDs();
|
||||
uuids.removeAll(usersTable.getContainsBukkitData(uuids));
|
||||
@ -465,8 +469,45 @@ public abstract class SQLDB extends Database {
|
||||
*/
|
||||
@Override
|
||||
public void clean() {
|
||||
Log.info("Cleaning the database.");
|
||||
try {
|
||||
checkConnection();
|
||||
Map<Integer, List<SessionData>> allSessions = sessionsTable.getSessionData(usersTable.getAllUserIds().values());
|
||||
Benchmark.start("Combine Sessions");
|
||||
int before = MathUtils.sumInt(allSessions.values().stream().map(l -> l.size()));
|
||||
Log.debug("Sessions before: " + before);
|
||||
Map<Integer, Integer> beforeM = new HashMap<>();
|
||||
Map<Integer, Integer> afterM = new HashMap<>();
|
||||
for (Integer id : allSessions.keySet()) {
|
||||
List<SessionData> sessions = allSessions.get(id);
|
||||
beforeM.put(id, sessions.size());
|
||||
if (sessions.isEmpty()) {
|
||||
afterM.put(id, 0);
|
||||
continue;
|
||||
}
|
||||
List<SessionData> combined = ManageUtils.combineSessions(sessions);
|
||||
afterM.put(id, combined.size());
|
||||
allSessions.put(id, combined);
|
||||
}
|
||||
int after = MathUtils.sumInt(allSessions.values().stream().map(l -> l.size()));
|
||||
Log.debug("Sessions after: " + after);
|
||||
if (before - after > 50) {
|
||||
Benchmark.start("Save combined sessions");
|
||||
Iterator<Integer> iterator = new HashSet<>(allSessions.keySet()).iterator();
|
||||
while (iterator.hasNext()) {
|
||||
int id = iterator.next();
|
||||
if (afterM.get(id) < beforeM.get(id)) {
|
||||
sessionsTable.removeUserSessions(id);
|
||||
} else {
|
||||
allSessions.remove(id);
|
||||
}
|
||||
}
|
||||
sessionsTable.saveSessionData(allSessions);
|
||||
Benchmark.stop("Save combined sessions");
|
||||
}
|
||||
Benchmark.stop("Combine Sessions");
|
||||
Log.info("Combined " + (before - after) + " sessions.");
|
||||
Log.info("Clean complete.");
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.data.SessionData;
|
||||
import main.java.com.djrapitops.plan.database.Container;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
|
||||
@ -200,6 +201,25 @@ public class SessionsTable extends Table {
|
||||
}
|
||||
Benchmark.start("Save Sessions multiple " + sessions.size());
|
||||
Map<Integer, List<SessionData>> saved = getSessionData(sessions.keySet());
|
||||
for (Integer id : sessions.keySet()) {
|
||||
List<SessionData> sessionList = sessions.get(id);
|
||||
List<SessionData> s = saved.get(id);
|
||||
if (s != null) {
|
||||
sessionList.removeAll(s);
|
||||
}
|
||||
if (sessionList.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
saved.put(id, sessionList);
|
||||
}
|
||||
List<List<Container<SessionData>>> batches = splitIntoBatches(sessions);
|
||||
for (List<Container<SessionData>> batch : batches) {
|
||||
saveSessionBatch(batch);
|
||||
}
|
||||
Benchmark.stop("Save Sessions multiple " + sessions.size());
|
||||
}
|
||||
|
||||
private void saveSessionBatch(List<Container<SessionData>> batch) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement("INSERT INTO " + tableName + " ("
|
||||
@ -210,34 +230,23 @@ public class SessionsTable extends Table {
|
||||
|
||||
boolean commitRequired = false;
|
||||
int i = 0;
|
||||
for (Integer id : sessions.keySet()) {
|
||||
List<SessionData> sessionList = sessions.get(id);
|
||||
List<SessionData> s = saved.get(id);
|
||||
if (s != null) {
|
||||
sessionList.removeAll(s);
|
||||
}
|
||||
if (sessionList.isEmpty()) {
|
||||
for (Container<SessionData> data : batch) {
|
||||
SessionData session = data.getObject();
|
||||
int id = data.getId();
|
||||
if (!session.isValid()) {
|
||||
continue;
|
||||
}
|
||||
for (SessionData session : sessionList) {
|
||||
long end = session.getSessionEnd();
|
||||
long start = session.getSessionStart();
|
||||
if (end < start) {
|
||||
continue;
|
||||
}
|
||||
statement.setInt(1, id);
|
||||
statement.setLong(2, start);
|
||||
statement.setLong(3, end);
|
||||
statement.addBatch();
|
||||
commitRequired = true;
|
||||
i++;
|
||||
}
|
||||
statement.setInt(1, id);
|
||||
statement.setLong(2, session.getSessionStart());
|
||||
statement.setLong(3, session.getSessionEnd());
|
||||
statement.addBatch();
|
||||
commitRequired = true;
|
||||
i++;
|
||||
}
|
||||
if (commitRequired) {
|
||||
Log.debug("Executing session batch: "+i);
|
||||
statement.executeBatch();
|
||||
Log.debug("Executing session batch: " + i);
|
||||
statement.executeBatch();
|
||||
}
|
||||
Benchmark.stop("Save Sessions multiple " + sessions.size());
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
|
@ -3,7 +3,11 @@ package main.java.com.djrapitops.plan.database.tables;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.database.Container;
|
||||
import main.java.com.djrapitops.plan.database.DBUtils;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
|
||||
/**
|
||||
@ -123,4 +127,8 @@ public abstract class Table {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected <T> List<List<Container<T>>> splitIntoBatches(Map<Integer, List<T>> objects) {
|
||||
return DBUtils.splitIntoBatches(objects);
|
||||
}
|
||||
}
|
||||
|
@ -874,4 +874,9 @@ public class UsersTable extends Table {
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<Integer, Long> getLoginTimes(Collection<UUID> uuids) {
|
||||
//TODO
|
||||
return new HashMap<>();
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,20 @@
|
||||
package main.java.com.djrapitops.plan.utilities;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import com.djrapitops.javaplugin.utilities.BenchmarkUtil;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class Benchmark {
|
||||
|
||||
private static Map<String, Long> starts = new HashMap<>();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param source
|
||||
*/
|
||||
public static void start(String source) {
|
||||
starts.put(source, System.nanoTime());
|
||||
BenchmarkUtil.start(source);
|
||||
Log.debug(source);
|
||||
}
|
||||
|
||||
@ -27,13 +24,10 @@ public class Benchmark {
|
||||
* @return
|
||||
*/
|
||||
public static long stop(String source) {
|
||||
Long s = starts.get(source);
|
||||
if (s != null) {
|
||||
long ms = (System.nanoTime() - s) / 1000000;
|
||||
long ms = BenchmarkUtil.stop(source);
|
||||
if (ms != -1) {
|
||||
Log.debug(source + " took " + ms+" ms");
|
||||
starts.remove(source);
|
||||
return ms;
|
||||
}
|
||||
return -1;
|
||||
return ms;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.utilities;
|
||||
|
||||
import com.djrapitops.javaplugin.utilities.FormattingUtils;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Date;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import org.bukkit.Location;
|
||||
|
||||
@ -36,30 +36,15 @@ public class FormatUtils {
|
||||
* @return
|
||||
*/
|
||||
public static String formatTimeStamp(long epochMs) {
|
||||
Date date = new Date(epochMs);
|
||||
String timeStamp = date.toString();
|
||||
// "EEE MMM dd HH:mm:ss zzz yyyy"
|
||||
// "0123456789012345678901234567"
|
||||
String day = timeStamp.substring(4, 10);
|
||||
String clock = timeStamp.substring(11, 16);
|
||||
return day + ", " + clock;
|
||||
return FormattingUtils.formatTimeStamp(epochMs);
|
||||
}
|
||||
|
||||
public static String formatTimeStampSecond(long epochMs) {
|
||||
Date date = new Date(epochMs);
|
||||
String timeStamp = date.toString();
|
||||
String day = timeStamp.substring(4, 10);
|
||||
String clock = timeStamp.substring(11, 19);
|
||||
return day + ", " + clock;
|
||||
return FormattingUtils.formatTimeStampSecond(epochMs);
|
||||
}
|
||||
|
||||
public static String formatTimeStampYear(long epochMs) {
|
||||
Date date = new Date(epochMs);
|
||||
String timeStamp = date.toString();
|
||||
String year = timeStamp.substring(24);
|
||||
String day = timeStamp.substring(4, 10);
|
||||
String clock = timeStamp.substring(11, 16);
|
||||
return day + " " + year + ", " + clock;
|
||||
return FormattingUtils.formatTimeStampYear(epochMs);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,7 +54,7 @@ public class FormatUtils {
|
||||
* @return
|
||||
*/
|
||||
public static String removeLetters(String dataPoint) {
|
||||
return dataPoint.replaceAll("[^\\d.]", "");
|
||||
return FormattingUtils.removeLetters(dataPoint);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,11 +63,7 @@ public class FormatUtils {
|
||||
* @return
|
||||
*/
|
||||
public static String removeNumbers(String dataPoint) {
|
||||
for (char c : removeLetters(dataPoint).toCharArray()) {
|
||||
dataPoint = dataPoint.replace(c + "", "");
|
||||
}
|
||||
dataPoint = dataPoint.replace(" ", "");
|
||||
return dataPoint;
|
||||
return FormattingUtils.removeNumbers(dataPoint);
|
||||
}
|
||||
|
||||
// Formats long in milliseconds into d:h:m:s string
|
||||
@ -114,21 +95,21 @@ public class FormatUtils {
|
||||
}
|
||||
if (hours != 0) {
|
||||
String h = Settings.FORMAT_HOURS.toString().replace("%hours%", "" + hours);
|
||||
if (h.contains("%zero%") && (hours+"").length() == 1) {
|
||||
if (h.contains("%zero%") && (hours + "").length() == 1) {
|
||||
builder.append('0');
|
||||
}
|
||||
builder.append(h);
|
||||
}
|
||||
if (minutes != 0) {
|
||||
String m = Settings.FORMAT_MINUTES.toString().replace("%minutes%", "" + minutes);
|
||||
if (m.contains("%zero%") && (minutes+"").length() == 1) {
|
||||
if (m.contains("%zero%") && (minutes + "").length() == 1) {
|
||||
builder.append('0');
|
||||
}
|
||||
builder.append(m);
|
||||
builder.append(m);
|
||||
}
|
||||
if (seconds != 0) {
|
||||
if (seconds != 0) {
|
||||
String s = Settings.FORMAT_SECONDS.toString().replace("%seconds%", "" + seconds);
|
||||
if (s.contains("%zero%") && (seconds+"").length() == 1) {
|
||||
if (s.contains("%zero%") && (seconds + "").length() == 1) {
|
||||
builder.append('0');
|
||||
}
|
||||
builder.append(s);
|
||||
@ -148,15 +129,7 @@ public class FormatUtils {
|
||||
* @throws NumberFormatException When wrong format
|
||||
*/
|
||||
public static int parseVersionNumber(String versionString) throws NumberFormatException {
|
||||
String[] versionArray = versionString.split("\\.");
|
||||
if (versionArray.length != 3) {
|
||||
throw new NumberFormatException("Wrong format used");
|
||||
}
|
||||
int main = Integer.parseInt(versionArray[0]) * 10000;
|
||||
int major = Integer.parseInt(versionArray[1]) * 100;
|
||||
int minor = Integer.parseInt(versionArray[2]);
|
||||
int versionNumber = main + major + minor;
|
||||
return versionNumber;
|
||||
return FormattingUtils.parseVersionNumber(versionString);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -166,18 +139,7 @@ public class FormatUtils {
|
||||
* @return One array with contents of the multiple
|
||||
*/
|
||||
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;
|
||||
return FormattingUtils.mergeArrays(arrays);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -187,7 +149,7 @@ public class FormatUtils {
|
||||
* @return Readable location format.
|
||||
*/
|
||||
public static String formatLocation(Location loc) {
|
||||
return "x " + loc.getBlockX() + " z " + loc.getBlockZ() + " in " + loc.getWorld();
|
||||
return FormattingUtils.formatLocation(loc);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,7 +50,7 @@ public class HtmlUtils {
|
||||
}
|
||||
|
||||
public static String getServerAnalysisUrlWithProtocol() {
|
||||
return Settings.LINK_PROTOCOL.toString()+getServerAnalysisUrl();
|
||||
return Settings.LINK_PROTOCOL.toString()+":"+getServerAnalysisUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,7 +59,7 @@ public class HtmlUtils {
|
||||
*/
|
||||
public static String getServerAnalysisUrl() {
|
||||
int port = Settings.WEBSERVER_PORT.getNumber();
|
||||
String ip = Plan.getInstance().getServer().getIp() + ":" + port;
|
||||
String ip = Plan.getInstance().getVariable().getIp() + ":" + port;
|
||||
String securityCode = Settings.SECURITY_CODE.toString();
|
||||
boolean useAlternativeIP = Settings.SHOW_ALTERNATIVE_IP.isTrue();
|
||||
if (useAlternativeIP) {
|
||||
@ -70,7 +70,7 @@ public class HtmlUtils {
|
||||
}
|
||||
|
||||
public static String getInspectUrlWithProtocol(String playerName) {
|
||||
return Settings.LINK_PROTOCOL.toString()+getInspectUrl(playerName);
|
||||
return Settings.LINK_PROTOCOL.toString()+":"+getInspectUrl(playerName);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,7 +80,7 @@ public class HtmlUtils {
|
||||
*/
|
||||
public static String getInspectUrl(String playerName) {
|
||||
int port = Settings.WEBSERVER_PORT.getNumber();
|
||||
String ip = Plan.getInstance().getServer().getIp() + ":" + port;
|
||||
String ip = Plan.getInstance().getVariable().getIp() + ":" + port;
|
||||
String securityCode = Settings.SECURITY_CODE.toString();
|
||||
boolean useAlternativeIP = Settings.SHOW_ALTERNATIVE_IP.isTrue();
|
||||
if (useAlternativeIP) {
|
||||
|
@ -1,17 +1,22 @@
|
||||
package main.java.com.djrapitops.plan.utilities;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.SessionData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -69,11 +74,45 @@ public class ManageUtils {
|
||||
clearAndCopyToDB.removeAllData();
|
||||
List<UserData> allUserData = copyFromDB.getUserDataForUUIDS(copyFromDB.getSavedUUIDs());
|
||||
clearAndCopyToDB.saveMultipleUserData(allUserData);
|
||||
clearAndCopyToDB.getCommandUseTable().saveCommandUse(copyFromDB.getCommandUseTable().getCommandUse());
|
||||
clearAndCopyToDB.getCommandUseTable().saveCommandUse(copyFromDB.getCommandUseTable().getCommandUse());
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
Log.toLog("ManageUtils.move", e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean containsCombinable(List<SessionData> sessions) {
|
||||
// Checks if there are starts & ends that are the same, or less than 5000 ms away from each other.
|
||||
return sessions.stream()
|
||||
.anyMatch(s -> sessions.stream()
|
||||
.filter(ses -> !ses.equals(s))
|
||||
.map(ses -> ses.getSessionStart())
|
||||
.anyMatch((Long start) -> (Math.abs(s.getSessionEnd() - start) < 5000)));
|
||||
}
|
||||
|
||||
public static List<SessionData> combineSessions(List<SessionData> sessions) {
|
||||
List<SessionData> newSessions = new ArrayList<>();
|
||||
List<SessionData> removed = new ArrayList<>();
|
||||
Iterator<SessionData> iterator = sessions.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
SessionData session = iterator.next();
|
||||
if (removed.contains(session)) {
|
||||
continue;
|
||||
}
|
||||
List<SessionData> close = sessions.stream().filter(ses -> Math.abs(session.getSessionEnd() - ses.getSessionStart()) < 5000).collect(Collectors.toList());
|
||||
if (!close.isEmpty()) {
|
||||
long big = MathUtils.getBiggestLong(close.stream().map((SessionData ses) -> ses.getSessionEnd()).collect(Collectors.toList()));
|
||||
session.endSession(big);
|
||||
removed.addAll(close);
|
||||
}
|
||||
newSessions.add(session);
|
||||
}
|
||||
boolean containsCombinable = containsCombinable(newSessions);
|
||||
if (containsCombinable) {
|
||||
return combineSessions(newSessions);
|
||||
} else {
|
||||
return newSessions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,54 +34,6 @@ public class MiscUtils {
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the version and returns response String.
|
||||
*
|
||||
* @return String informing about status of plugins version.
|
||||
*/
|
||||
public static String checkVersion() {
|
||||
try {
|
||||
Plan plugin = Plan.getInstance();
|
||||
String cVersion = plugin.getDescription().getVersion();
|
||||
String gitVersion = getGitVersion();
|
||||
if (checkVersion(cVersion, gitVersion)) {
|
||||
return Phrase.VERSION_NEW_AVAILABLE.parse(gitVersion);
|
||||
} else {
|
||||
return Phrase.VERSION_LATEST + "";
|
||||
}
|
||||
} catch (IOException | NumberFormatException e) {
|
||||
Log.error(Phrase.VERSION_CHECK_ERROR + "");
|
||||
}
|
||||
return Phrase.VERSION_FAIL + "";
|
||||
}
|
||||
|
||||
private static String getGitVersion() throws IOException {
|
||||
URL githubUrl = new URL("https://raw.githubusercontent.com/Rsl1122/Plan-PlayerAnalytics/master/Plan/src/main/resources/plugin.yml");
|
||||
String lineWithVersion = "";
|
||||
Scanner websiteScanner = new Scanner(githubUrl.openStream());
|
||||
while (websiteScanner.hasNextLine()) {
|
||||
String line = websiteScanner.nextLine();
|
||||
if (line.toLowerCase().contains("version")) {
|
||||
lineWithVersion = line;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return lineWithVersion.split(": ")[1];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param currentVersion
|
||||
* @param gitVersion
|
||||
* @return
|
||||
* @throws NumberFormatException
|
||||
*/
|
||||
public static boolean checkVersion(String currentVersion, String gitVersion) throws NumberFormatException {
|
||||
int newestVersionNumber = FormatUtils.parseVersionNumber(gitVersion);
|
||||
int currentVersionNumber = FormatUtils.parseVersionNumber(currentVersion);
|
||||
return newestVersionNumber > currentVersionNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
|
@ -1,149 +0,0 @@
|
||||
/*
|
||||
* 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 main.java.com.djrapitops.plan.utilities.uuid;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
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;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param names
|
||||
* @param rateLimiting
|
||||
*/
|
||||
public UUIDFetcher(List<String> names, boolean rateLimiting) {
|
||||
this.names = ImmutableList.copyOf(names);
|
||||
this.rateLimiting = rateLimiting;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param names
|
||||
*/
|
||||
public UUIDFetcher(List<String> names) {
|
||||
this(names, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, UUID> call() throws Exception {
|
||||
Map<String, UUID> uuidMap = new HashMap<>();
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uuid
|
||||
* @return
|
||||
*/
|
||||
public static byte[] toBytes(UUID uuid) {
|
||||
ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]);
|
||||
byteBuffer.putLong(uuid.getMostSignificantBits());
|
||||
byteBuffer.putLong(uuid.getLeastSignificantBits());
|
||||
return byteBuffer.array();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array
|
||||
* @return
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static UUID getUUIDOf(String name) throws Exception {
|
||||
return new UUIDFetcher(Arrays.asList(name)).call().get(name);
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.utilities.uuid;
|
||||
|
||||
import com.djrapitops.javaplugin.utilities.UUIDFetcher;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
|
@ -498,7 +498,7 @@ header p {
|
||||
</div>
|
||||
</div>
|
||||
<canvas id="playerChartMonth" width="1000" height="350" style="width: 95%;"></canvas>
|
||||
<p><i class="fa fa-user-circle" aria-hidden="true"></i> Unique Playes: %uniquejoinsmonth% | <i class="fa fa-user-circle-o" aria-hidden="true"></i> Unique/Day: %avguniquejoinsmonth%</p>
|
||||
<p><i class="fa fa-user-circle" aria-hidden="true"></i> Unique Players: %uniquejoinsmonth% | <i class="fa fa-user-circle-o" aria-hidden="true"></i> Unique/Day: %avguniquejoinsmonth%</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
|
@ -415,5 +415,5 @@ public class DatabaseTest {
|
||||
assertTrue("Doesn't contain /tp", commandUse.containsKey("/tp"));
|
||||
assertTrue("Doesn't contain /pla", commandUse.containsKey("/pla"));
|
||||
assertTrue("Doesn't contain /help", commandUse.containsKey("/help"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,142 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.utilities;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import main.java.com.djrapitops.plan.data.SessionData;
|
||||
import main.java.com.djrapitops.plan.utilities.ManageUtils;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({JavaPlugin.class})
|
||||
public class ManageUtilsTest {
|
||||
|
||||
private int threshold = 5000;
|
||||
|
||||
public ManageUtilsTest() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws IOException, Exception {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsCombinable() {
|
||||
List<SessionData> data = new ArrayList<>();
|
||||
data.add(new SessionData(0, 100));
|
||||
data.add(new SessionData(threshold - 100, threshold * 2));
|
||||
data.add(new SessionData(threshold * 2 + 100, threshold * 3));
|
||||
assertTrue(ManageUtils.containsCombinable(data));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsCombinableFalse() {
|
||||
List<SessionData> data = new ArrayList<>();
|
||||
data.add(new SessionData(0, threshold));
|
||||
data.add(new SessionData(threshold * 3, threshold * 4));
|
||||
assertTrue(!ManageUtils.containsCombinable(data));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsCombinableFalse2() {
|
||||
List<SessionData> data = new ArrayList<>();
|
||||
data.add(new SessionData(0, threshold * 2));
|
||||
data.add(new SessionData(threshold * 3, threshold * 4));
|
||||
assertTrue(!ManageUtils.containsCombinable(data));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsCombinableFalse3() {
|
||||
List<SessionData> data = new ArrayList<>();
|
||||
data.add(new SessionData(0, threshold * 2));
|
||||
data.add(new SessionData(threshold * 3 + 200, threshold * 4));
|
||||
assertTrue(!ManageUtils.containsCombinable(data));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombineSessions() {
|
||||
List<SessionData> data = new ArrayList<>();
|
||||
data.add(new SessionData(0, 100));
|
||||
data.add(new SessionData(threshold, threshold * 2));
|
||||
data.add(new SessionData(threshold * 2 + 100, threshold * 3));
|
||||
SessionData get = ManageUtils.combineSessions(data).get(0);
|
||||
SessionData exp = new SessionData(0, threshold * 3);
|
||||
assertEquals(exp, get);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombineSessions2() {
|
||||
List<SessionData> data = new ArrayList<>();
|
||||
data.add(new SessionData(0, 100));
|
||||
data.add(new SessionData(threshold, threshold * 2));
|
||||
data.add(new SessionData(threshold * 2 + 100, threshold * 3));
|
||||
data.add(new SessionData(threshold * 3 + 200, threshold * 4));
|
||||
SessionData get = ManageUtils.combineSessions(data).get(0);
|
||||
SessionData exp = new SessionData(0, threshold * 4);
|
||||
assertEquals(exp, get);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombineSessions3() {
|
||||
List<SessionData> data = new ArrayList<>();
|
||||
data.add(new SessionData(0, 100));
|
||||
data.add(new SessionData(threshold, threshold * 2));
|
||||
data.add(new SessionData(threshold * 3 + 200, threshold * 4));
|
||||
List<SessionData> result = ManageUtils.combineSessions(data);
|
||||
SessionData exp = new SessionData(0, threshold * 2);
|
||||
assertEquals(exp, result.get(0));
|
||||
SessionData exp2 = new SessionData(threshold * 3 + 200, threshold * 4);
|
||||
assertEquals(exp2, result.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombineSessions4() {
|
||||
List<SessionData> data = new ArrayList<>();
|
||||
data.add(new SessionData(0, 100));
|
||||
data.add(new SessionData(threshold, threshold * 2));
|
||||
data.add(new SessionData(threshold * 3 + 200, threshold * 4));
|
||||
data.add(new SessionData(threshold * 5 - 200, threshold * 5));
|
||||
List<SessionData> result = ManageUtils.combineSessions(data);
|
||||
SessionData exp = new SessionData(0, threshold * 2);
|
||||
assertEquals(exp, result.get(0));
|
||||
SessionData exp2 = new SessionData(threshold * 3 + 200, threshold * 5);
|
||||
assertEquals(exp2, result.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombineSessions5() {
|
||||
List<SessionData> data = new ArrayList<>();
|
||||
data.add(new SessionData(0, 100));
|
||||
data.add(new SessionData(threshold, threshold * 2));
|
||||
data.add(new SessionData(threshold * 5, threshold * 5 + 100));
|
||||
data.add(new SessionData(threshold * 8, threshold * 8 + 200));
|
||||
data.add(new SessionData(threshold * 9 - 200, threshold * 10));
|
||||
List<SessionData> result = ManageUtils.combineSessions(data);
|
||||
SessionData exp = new SessionData(0, threshold * 2);
|
||||
assertEquals(exp, result.get(0));
|
||||
SessionData exp2 = new SessionData(threshold * 5, threshold * 5 + 100);
|
||||
assertEquals(exp2, result.get(1));
|
||||
SessionData exp3 = new SessionData(threshold * 8, threshold * 10);
|
||||
assertEquals(exp3, result.get(2));
|
||||
}
|
||||
|
||||
}
|
@ -52,44 +52,6 @@ public class MiscUtilsTest {
|
||||
PowerMock.replay(Bukkit.class);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testCheckVersion() {
|
||||
String versionG = "2.10.9";
|
||||
assertTrue(MiscUtils.checkVersion("2.0.0", versionG));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testCheckVersion2() {
|
||||
assertTrue(!MiscUtils.checkVersion("3.0.0", "2.10.9"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckVersion5() {
|
||||
assertTrue(MiscUtils.checkVersion("2.10.9", "3.0.0"));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testCheckVersion3() {
|
||||
assertTrue(!MiscUtils.checkVersion("2.11.0", "2.10.9"));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testCheckVersion4() {
|
||||
assertTrue(!MiscUtils.checkVersion("2.11.0", "2.11.0"));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -5,11 +5,13 @@
|
||||
*/
|
||||
package test.java.utils;
|
||||
|
||||
import com.djrapitops.javaplugin.utilities.PluginLog;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.logging.Logger;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.ServerVariableHolder;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
@ -63,6 +65,10 @@ public class TestInit {
|
||||
// Mockito.doReturn("0.0.0.0").when(mockServer).getIp();
|
||||
when(planMock.getServer()).thenReturn(mockServer);
|
||||
when(planMock.getLogger()).thenReturn(Logger.getGlobal());
|
||||
ServerVariableHolder serverVariableHolder = new ServerVariableHolder(mockServer);
|
||||
when(planMock.getVariable()).thenReturn(serverVariableHolder);
|
||||
PluginLog<Plan> log = new PluginLog(planMock, "console", "");
|
||||
when(planMock.getPluginLogger()).thenReturn(log);
|
||||
Plan.setInstance(planMock);
|
||||
// Mockito.doReturn("0.0.0.0").when(planMock).getServer().getIp();
|
||||
Settings.DEBUG.setValue(true);
|
||||
|
Loading…
Reference in New Issue
Block a user