Merge pull request #417 from Rsl1122/4.0.5

Pull request for 4.0.6
This commit is contained in:
Rsl1122 2017-11-12 20:41:41 +02:00 committed by GitHub
commit 948f5e95d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
155 changed files with 1579 additions and 1336 deletions

View File

@ -4,20 +4,36 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.djrapitops</groupId>
<artifactId>Plan</artifactId>
<version>4.0.5</version>
<version>4.0.6</version>
<packaging>jar</packaging>
<repositories>
<repository>
<id>bungeecord-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>paper-repo</id>
<url>https://repo.destroystokyo.com/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<!-- PaperSpigot 1.12 -->
<!-- PaperSpigot -->
<dependency>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper</artifactId>
<version>1.12-R0.1-20170725.202533-1</version>
<artifactId>paper-api</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<!-- Spigot -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12-R0.1-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<!-- BungeeCord -->
@ -28,6 +44,7 @@
<type>jar</type>
<scope>provided</scope>
</dependency>
<!-- StringUtils lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
@ -44,7 +61,7 @@
<dependency>
<groupId>com.djrapitops</groupId>
<artifactId>abstract-plugin-framework</artifactId>
<version>2.0.5</version>
<version>3.0.0</version>
<scope>compile</scope>
</dependency>
<!-- Connection Pool -->
@ -70,7 +87,7 @@
<dependency>
<groupId>com.djrapitops</groupId>
<artifactId>PlanPluginBridge</artifactId>
<version>4.0.3</version>
<version>4.0.5</version>
<scope>compile</scope>
</dependency>
<!-- Testing -->

View File

@ -1,164 +0,0 @@
package main.java.com.djrapitops.plan;
import com.djrapitops.plugin.utilities.log.DebugInfo;
import com.djrapitops.plugin.utilities.log.PluginLog;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import java.util.Collection;
/**
* This class manages the messages going to the Console Logger.
* <p>
* Methods of Abstract Plugin Framework log utility are used.
*
* @author Rsl1122
* @since 3.0.0
*/
public class Log {
/**
* Constructor used to hide the public constructor
*/
private Log() {
throw new IllegalStateException("Utility Class");
}
/**
* Logs the message to the console as INFO.
*
* @param message "Message" will show up as [INFO][Plan]: Message
*/
public static void info(String message) {
getPluginLogger().info(message);
}
/**
* Sends a message to the console with the ChatColors.
*
* @param message Message to send.
*/
public static void infoColor(String message) {
getPluginLogger().infoColor(message);
}
/**
* Logs an error message to the console as ERROR.
*
* @param message "Message" will show up as [ERROR][Plan]: Message
*/
public static void error(String message) {
getPluginLogger().error(message);
}
/**
* Logs a debug message to the console as INFO if Settings.Debug is true.
*
* @param message "Message" will show up as [INFO][Plan]: [DEBUG] Message
*/
public static void debug(String message) {
getPluginLogger().debug(message);
}
/**
* Used for logging larger debug complexes.
*
* @param task complex this debug message is a part of.
* @param message Single message to add to the debug log.
* @return full debug complex so far.
*/
public static DebugInfo debug(String task, String message) {
return getDebug(task).addLine(message, MiscUtils.getTime());
}
/**
* Used for logging larger debug complexes.
*
* @param task complex this debug message is a part of.
* @param messages All messages to add to the debug log.
* @return full debug complex so far.
*/
public static DebugInfo debug(String task, String... messages) {
DebugInfo debug = getDebug(task);
long time = MiscUtils.getTime();
for (String message : messages) {
debug.addLine(message, time);
}
return debug;
}
/**
* Used for logging larger debug complexes.
*
* @param task complex to get
* @return full debug complex so far.
*/
public static DebugInfo getDebug(String task) {
return getPluginLogger().getDebug(task);
}
/**
* Logs the full debug complex to the debug log.
*
* @param task complex to log.
*/
public static void logDebug(String task) {
getDebug(task).toLog();
}
/**
* Logs the full debug complex to the debug log with an execution time.
*
* @param task complex to log.
* @param time execution time.
*/
public static void logDebug(String task, long time) {
getDebug(task).toLog(time);
}
/**
* Logs trace of caught Exception to Errors.txt and notifies on console.
*
* @param source Class name the exception was caught in.
* @param e {@code Throwable}, eg NullPointerException
*/
public static void toLog(String source, Throwable e) {
getPluginLogger().toLog(source, e);
}
/**
* Logs multiple caught Errors to Errors.txt.
*
* @param source Class name the exception was caught in.
* @param e Collection of {@code Throwable}, eg NullPointerException
*/
public static void toLog(String source, Collection<Throwable> e) {
Plan.getInstance().getPluginLogger().toLog(source, e);
}
private static PluginLog getPluginLogger() {
return MiscUtils.getIPlan().getPluginLogger();
}
public static void logStackTrace(Throwable e) {
error(e.toString());
for (StackTraceElement stackTraceElement : e.getStackTrace()) {
error(" " + stackTraceElement);
}
Throwable cause = e.getCause();
if (cause != null) {
logCause(cause);
}
}
private static void logCause(Throwable e) {
error("caused by: " + e.toString());
for (StackTraceElement stackTraceElement : e.getStackTrace()) {
error(" " + stackTraceElement);
}
Throwable cause = e.getCause();
if (cause != null) {
logCause(cause);
}
}
}

View File

@ -20,7 +20,14 @@
package main.java.com.djrapitops.plan;
import com.djrapitops.plugin.BukkitPlugin;
import com.djrapitops.plugin.StaticHolder;
import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.api.systems.TaskCenter;
import com.djrapitops.plugin.api.utility.Version;
import com.djrapitops.plugin.api.utility.log.DebugLog;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.settings.ColorScheme;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.ITask;
@ -29,6 +36,7 @@ import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.api.API;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.api.exceptions.DatabaseInitException;
import main.java.com.djrapitops.plan.api.exceptions.PlanEnableException;
import main.java.com.djrapitops.plan.command.PlanCommand;
import main.java.com.djrapitops.plan.data.additional.HookHandler;
import main.java.com.djrapitops.plan.database.Database;
@ -41,7 +49,6 @@ import main.java.com.djrapitops.plan.systems.cache.GeolocationCache;
import main.java.com.djrapitops.plan.systems.info.BukkitInformationManager;
import main.java.com.djrapitops.plan.systems.info.ImporterManager;
import main.java.com.djrapitops.plan.systems.info.InformationManager;
import main.java.com.djrapitops.plan.systems.info.pluginchannel.BukkitPluginChannelListener;
import main.java.com.djrapitops.plan.systems.info.server.BukkitServerInfoManager;
import main.java.com.djrapitops.plan.systems.listeners.*;
import main.java.com.djrapitops.plan.systems.processing.Processor;
@ -50,11 +57,14 @@ import main.java.com.djrapitops.plan.systems.queue.ProcessingQueue;
import main.java.com.djrapitops.plan.systems.tasks.TPSCountTimer;
import main.java.com.djrapitops.plan.systems.webserver.PageCache;
import main.java.com.djrapitops.plan.systems.webserver.WebServer;
import main.java.com.djrapitops.plan.utilities.Benchmark;
import main.java.com.djrapitops.plan.utilities.file.FileUtil;
import main.java.com.djrapitops.plan.utilities.metrics.BStats;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import java.io.File;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@ -69,11 +79,12 @@ import java.util.UUID;
* @author Rsl1122
* @since 1.0.0
*/
public class Plan extends BukkitPlugin<Plan> implements IPlan {
public class Plan extends BukkitPlugin implements IPlan {
private boolean reloading = false;
private API api;
private Config config;
private ProcessingQueue processingQueue;
private HookHandler hookHandler; // Manages 3rd party data sources
@ -102,7 +113,7 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
if (instance == null) {
throw new IllegalStateException("Plugin not enabled properly, Singleton instance is null.");
}
return instance.api;
return instance.getApi();
}
/**
@ -111,7 +122,7 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
* @return this object.
*/
public static Plan getInstance() {
return (Plan) getPluginInstance(Plan.class);
return (Plan) StaticHolder.getInstance(Plan.class);
}
public static UUID getServerUUID() {
@ -129,21 +140,39 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
*/
@Override
public void onEnable() {
super.onEnable();
try {
// Sets the Required variables for BukkitPlugin instance to function correctly
setInstance(this);
super.setDebugMode(Settings.DEBUG.toString());
initColorScheme();
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/");
File configFile = new File(getDataFolder(), "config.yml");
config = new Config(configFile);
config.copyDefaults(FileUtil.lines(this, "config.yml"));
config.save();
// Initializes BukkitPlugin variables, Checks version & Logs the debug header
super.onEnableDefaultTasks();
Log.setDebugMode(Settings.DEBUG.toString());
String currentVersion = getVersion();
String githubVersionUrl = "https://raw.githubusercontent.com/Rsl1122/Plan-PlayerAnalytics/master/Plan/src/main/resources/plugin.yml";
String spigotUrl = "https://www.spigotmc.org/resources/plan-player-analytics.32536/";
try {
if (Version.checkVersion(currentVersion, githubVersionUrl) || Version.checkVersion(currentVersion, spigotUrl)) {
Log.infoColor("§a----------------------------------------");
Log.infoColor("§aNew version is available at https://www.spigotmc.org/resources/plan-player-analytics.32536/");
Log.infoColor("§a----------------------------------------");
} else {
Log.info("You're using the latest version.");
}
} catch (IOException e) {
Log.error("Failed to check newest version number");
}
Benchmark.start("Enable");
GeolocationCache.checkDB();
try {
GeolocationCache.checkDB();
} catch (UnknownHostException e) {
Log.error("Plan Requires internet access on first run to download GeoLite2 Geolocation database.");
} catch (IOException e) {
throw new PlanEnableException("Something went wrong saving the downloaded GeoLite2 Geolocation database", e);
}
new Locale(this).loadLocale();
@ -151,13 +180,6 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
serverVariableHolder = new ServerVariableHolder(getServer());
Benchmark.stop("Enable", "Reading server variables");
Benchmark.start("Copy default config");
getConfig().options().copyDefaults(true);
getConfig().options().header("Plan Config | More info at https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/documentation/Configuration.md");
saveConfig();
Benchmark.stop("Enable", "Copy default config");
Benchmark.start("Init Database");
Log.info(Locale.get(Msg.ENABLE_DB_INIT).toString());
initDatabase();
@ -197,7 +219,7 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
Log.info("Make sure that the alternative IP points to the Bukkit Server: " + Settings.ALTERNATIVE_IP.toString());
}
registerCommand(new PlanCommand(this));
registerCommand("plan", new PlanCommand(this));
Benchmark.start("Hook to 3rd party plugins");
hookHandler = new HookHandler(this);
@ -205,37 +227,29 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
ImporterManager.registerImporter(new OfflinePlayerImporter());
// if (Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.isFalse()) {
// registerPluginChannelListener();
// }
BStats bStats = new BStats(this);
bStats.registerMetrics();
Log.debug("Verbose debug messages are enabled.");
Log.logDebug("Enable", Benchmark.stop("Enable", "Enable"));
Benchmark.stop("Enable", "Enable");
Log.logDebug("Enable");
Log.info(Locale.get(Msg.ENABLED).toString());
StaticHolder.saveInstance(ShutdownHook.class, this.getClass());
new ShutdownHook(this);
} catch (Exception e) {
Log.error("Plugin Failed to Initialize Correctly.");
Log.logStackTrace(e);
disablePlugin();
Log.toLog(this.getClass().getName(), e);
onDisable();
}
}
private void registerPluginChannelListener() {
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
Bukkit.getMessenger().registerIncomingPluginChannel(this, "Plan", new BukkitPluginChannelListener(this));
}
private void registerTasks() {
RunnableFactory runnableFactory = getRunnableFactory();
String bootAnalysisMsg = Locale.get(Msg.ENABLE_BOOT_ANALYSIS_INFO).toString();
String bootAnalysisRunMsg = Locale.get(Msg.ENABLE_BOOT_ANALYSIS_RUN_INFO).toString();
Benchmark.start("Task Registration");
tpsCountTimer = new TPSCountTimer(this);
runnableFactory.createNew(tpsCountTimer).runTaskTimer(1000, TimeAmount.SECOND.ticks());
RunnableFactory.createNew(tpsCountTimer).runTaskTimer(1000, TimeAmount.SECOND.ticks());
// Analysis refresh settings
int analysisRefreshMinutes = Settings.ANALYSIS_AUTO_REFRESH.getNumber();
@ -244,7 +258,7 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
Log.info(bootAnalysisMsg);
ITask bootAnalysisTask = runnableFactory.createNew("BootAnalysisTask", new AbsRunnable() {
ITask bootAnalysisTask = RunnableFactory.createNew("BootAnalysisTask", new AbsRunnable() {
@Override
public void run() {
Log.info(bootAnalysisRunMsg);
@ -256,7 +270,7 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
bootAnalysisTaskID = bootAnalysisTask.getTaskId();
if (analysisRefreshTaskIsEnabled) {
runnableFactory.createNew("PeriodicalAnalysisTask", new AbsRunnable() {
RunnableFactory.createNew("PeriodicalAnalysisTask", new AbsRunnable() {
@Override
public void run() {
infoManager.refreshAnalysis(getServerUUID());
@ -264,7 +278,7 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
}).runTaskTimerAsynchronously(analysisPeriod, analysisPeriod);
}
runnableFactory.createNew("PeriodicNetworkBoxRefreshTask", new AbsRunnable() {
RunnableFactory.createNew("PeriodicNetworkBoxRefreshTask", new AbsRunnable() {
@Override
public void run() {
infoManager.updateNetworkPageContent();
@ -274,15 +288,16 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
Benchmark.stop("Enable", "Task Registration");
}
private void initColorScheme() {
@Override
public ColorScheme getColorScheme() {
try {
ChatColor mainColor = ChatColor.getByChar(Settings.COLOR_MAIN.toString().charAt(1));
ChatColor secColor = ChatColor.getByChar(Settings.COLOR_SEC.toString().charAt(1));
ChatColor terColor = ChatColor.getByChar(Settings.COLOR_TER.toString().charAt(1));
super.setColorScheme(new ColorScheme(mainColor, secColor, terColor));
return new ColorScheme(mainColor, secColor, terColor);
} catch (Exception e) {
Log.infoColor(ChatColor.RED + "Customization, Chat colors set-up wrong, using defaults.");
super.setColorScheme(new ColorScheme(ChatColor.DARK_GREEN, ChatColor.GRAY, ChatColor.WHITE));
return new ColorScheme(ChatColor.DARK_GREEN, ChatColor.GRAY, ChatColor.WHITE);
}
}
@ -308,7 +323,7 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
processor.process();
}
} else {
getRunnableFactory().createNew("Re-Add processors", new AbsRunnable() {
RunnableFactory.createNew("Re-Add processors", new AbsRunnable() {
@Override
public void run() {
addToProcessQueue(processors.toArray(new Processor[processors.size()]));
@ -317,15 +332,24 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
}).runTaskLaterAsynchronously(TimeAmount.SECOND.ticks() * 5L);
}
}
getServer().getScheduler().cancelTasks(this);
if (Verify.notNull(infoManager, db)) {
taskStatus().cancelAllKnownTasks();
}
getPluginLogger().endAllDebugs();
Log.info(Locale.get(Msg.DISABLED).toString());
Benchmark.pluginDisabled(Plan.class);
DebugLog.pluginDisabled(Plan.class);
TaskCenter.cancelAllKnownTasks(Plan.class);
}
@Override
public String getVersion() {
return getDescription().getVersion();
}
@Override
public void onReload() {
try {
config.read();
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
}
}
private void registerListeners() {
@ -364,6 +388,7 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
}
db.init();
Log.info(Locale.get(Msg.ENABLE_DB_INFO).parse(db.getConfigName()));
}
/**
@ -460,7 +485,7 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
processingQueue.addToQueue(processor);
}
} else {
getRunnableFactory().createNew("Re-Add processors", new AbsRunnable() {
RunnableFactory.createNew("Re-Add processors", new AbsRunnable() {
@Override
public void run() {
addToProcessQueue(processors);
@ -470,19 +495,66 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
}
}
public InformationManager getInfoManager() {
return infoManager;
@Override
public Config getMainConfig() {
return config;
}
public void restart() {
reloading = true;
onDisable();
reloadConfig();
onEnable();
reloading = false;
public InformationManager getInfoManager() {
return infoManager;
}
public boolean isReloading() {
return reloading;
}
/**
* @deprecated Deprecated due to use of APF Config
*/
@Override
@Deprecated
public void reloadConfig() {
throw new IllegalStateException("This method should be used on this plugin. Use onReload() instead");
}
/**
* @deprecated Deprecated due to use of APF Config
*/
@Override
@Deprecated
public FileConfiguration getConfig() {
throw new IllegalStateException("This method should be used on this plugin. Use getMainConfig() instead");
}
/**
* @deprecated Deprecated due to use of APF Config
*/
@Override
@Deprecated
public void saveConfig() {
throw new IllegalStateException("This method should be used on this plugin. Use getMainConfig().save() instead");
}
/**
* @deprecated Deprecated due to use of APF Config
*/
@Override
@Deprecated
public void saveDefaultConfig() {
throw new IllegalStateException("This method should be used on this plugin.");
}
/**
* Method for getting the API.
* <p>
* Created due to necessity for testing, but can be used.
* For direct API getter use {@code Plan.getPlanAPI()}.
* <p>
* If Plan is reloaded a new API instance is created.
*
* @return Plan API instance.
*/
public API getApi() {
return api;
}
}

View File

@ -5,9 +5,15 @@
package main.java.com.djrapitops.plan;
import com.djrapitops.plugin.BungeePlugin;
import com.djrapitops.plugin.StaticHolder;
import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.api.utility.Version;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.settings.ColorScheme;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.api.exceptions.DatabaseInitException;
import main.java.com.djrapitops.plan.command.PlanBungeeCommand;
@ -23,9 +29,11 @@ import main.java.com.djrapitops.plan.systems.processing.Processor;
import main.java.com.djrapitops.plan.systems.queue.ProcessingQueue;
import main.java.com.djrapitops.plan.systems.tasks.TPSCountTimer;
import main.java.com.djrapitops.plan.systems.webserver.WebServer;
import main.java.com.djrapitops.plan.utilities.Benchmark;
import main.java.com.djrapitops.plan.utilities.file.FileUtil;
import net.md_5.bungee.api.ChatColor;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.UUID;
@ -35,7 +43,9 @@ import java.util.UUID;
*
* @author Rsl1122
*/
public class PlanBungee extends BungeePlugin<PlanBungee> implements IPlan {
public class PlanBungee extends BungeePlugin implements IPlan {
private Config config;
private WebServer webServer;
private Database db;
@ -47,18 +57,29 @@ public class PlanBungee extends BungeePlugin<PlanBungee> implements IPlan {
@Override
public void onEnable() {
super.onEnable();
try {
super.setInstance(this);
super.copyDefaultConfig("Plan Config | More info at https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/documentation/Configuration.md");
super.setDebugMode(Settings.DEBUG.toString());
super.getPluginLogger().setFolder(getDataFolder());
super.setColorScheme(new ColorScheme(ChatColor.GREEN, ChatColor.GRAY, ChatColor.WHITE));
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/");
File configFile = new File(getDataFolder(), "config.yml");
config = new Config(configFile);
config.copyDefaults(FileUtil.lines(this, "bungeeconfig.yml"));
config.save();
super.onEnableDefaultTasks();
Log.setDebugMode(Settings.DEBUG.toString());
String currentVersion = getVersion();
String githubVersionUrl = "https://raw.githubusercontent.com/Rsl1122/Plan-PlayerAnalytics/master/Plan/src/main/resources/plugin.yml";
String spigotUrl = "https://www.spigotmc.org/resources/plan-player-analytics.32536/";
try {
if (Version.checkVersion(currentVersion, githubVersionUrl) || Version.checkVersion(currentVersion, spigotUrl)) {
Log.infoColor("§a----------------------------------------");
Log.infoColor("§aNew version is available at https://www.spigotmc.org/resources/plan-player-analytics.32536/");
Log.infoColor("§a----------------------------------------");
} else {
Log.info("You're using the latest version.");
}
} catch (IOException e) {
Log.error("Failed to check newest version number");
}
variableHolder = new ServerVariableHolder(getProxy());
new Locale(this).loadLocale();
@ -66,7 +87,7 @@ public class PlanBungee extends BungeePlugin<PlanBungee> implements IPlan {
Log.info(Locale.get(Msg.ENABLE_DB_INIT).toString());
initDatabase();
registerCommand(new PlanBungeeCommand(this));
registerCommand("planbungee", new PlanBungeeCommand(this));
String ip = variableHolder.getIp();
if ("0.0.0.0".equals(ip)) {
@ -86,44 +107,41 @@ public class PlanBungee extends BungeePlugin<PlanBungee> implements IPlan {
if (!webServer.isEnabled()) {
Log.error("WebServer was not successfully initialized.");
disablePlugin();
onDisable();
return;
}
getRunnableFactory().createNew("Enable Bukkit Connection Task", new AbsRunnable() {
RunnableFactory.createNew("Enable Bukkit Connection Task", new AbsRunnable() {
@Override
public void run() {
infoManager.attemptConnection();
infoManager.sendConfigSettings();
}
}).runTaskAsynchronously();
getRunnableFactory().createNew("Player Count task", new TPSCountTimer(this))
RunnableFactory.createNew("Player Count task", new TPSCountTimer(this))
.runTaskTimerAsynchronously(1000, TimeAmount.SECOND.ticks());
getRunnableFactory().createNew("NetworkPageContentUpdateTask", new AbsRunnable("NetworkPageContentUpdateTask") {
RunnableFactory.createNew("NetworkPageContentUpdateTask", new AbsRunnable("NetworkPageContentUpdateTask") {
@Override
public void run() {
infoManager.updateNetworkPageContent();
}
}).runTaskTimerAsynchronously(1500, TimeAmount.MINUTE.ticks());
// getProxy().registerChannel("Plan");
// registerListener(new BungeePluginChannelListener(this));
processingQueue = new ProcessingQueue();
registerListener(new BungeePlayerListener(this));
Benchmark.stop("Enable", "WebServer Initialization");
Log.logDebug("Enable", "WebServer Initialization");
Log.info(Locale.get(Msg.ENABLED).toString());
} catch (Exception e) {
Log.error("Plugin Failed to Initialize Correctly.");
Log.logStackTrace(e);
disablePlugin();
Log.toLog(this.getClass().getName(), e);
onDisable();
}
}
public static PlanBungee getInstance() {
return getInstance(PlanBungee.class);
return (PlanBungee) StaticHolder.getInstance(PlanBungee.class);
}
@Override
@ -146,6 +164,21 @@ public class PlanBungee extends BungeePlugin<PlanBungee> implements IPlan {
}
}
Log.info(Locale.get(Msg.DISABLED).toString());
super.onDisable();
}
@Override
public String getVersion() {
return super.getDescription().getVersion();
}
@Override
public void onReload() {
try {
config.read();
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
}
}
private void initDatabase() throws DatabaseInitException {
@ -190,6 +223,24 @@ public class PlanBungee extends BungeePlugin<PlanBungee> implements IPlan {
return getResourceAsStream(resource);
}
@Override
public Config getMainConfig() {
return config;
}
@Override
public ColorScheme getColorScheme() {
try {
ChatColor mainColor = ChatColor.getByChar(Settings.COLOR_MAIN.toString().charAt(1));
ChatColor secColor = ChatColor.getByChar(Settings.COLOR_SEC.toString().charAt(1));
ChatColor terColor = ChatColor.getByChar(Settings.COLOR_TER.toString().charAt(1));
return new ColorScheme(mainColor, secColor, terColor);
} catch (Exception e) {
Log.infoColor(ChatColor.RED + "Customization, Chat colors set-up wrong, using defaults.");
return new ColorScheme(ChatColor.DARK_GREEN, ChatColor.GRAY, ChatColor.WHITE);
}
}
@Override
public ServerVariableHolder getVariable() {
return variableHolder;
@ -203,9 +254,4 @@ public class PlanBungee extends BungeePlugin<PlanBungee> implements IPlan {
return serverInfoManager.getServerUUID();
}
@Override
public void restart() {
onDisable();
onEnable();
}
}

View File

@ -4,10 +4,9 @@
*/
package main.java.com.djrapitops.plan;
import com.djrapitops.plugin.config.IConfig;
import com.djrapitops.plugin.config.fileconfig.IFileConfig;
import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.utilities.Verify;
import org.bukkit.configuration.file.FileConfiguration;
import java.io.IOException;
import java.util.Map;
@ -25,15 +24,14 @@ public class ServerSpecificSettings {
public void addOriginalBukkitSettings(PlanBungee plugin, UUID serverUUID, Map<String, Object> settings) {
try {
IConfig iConfig = plugin.getIConfig();
IFileConfig config = iConfig.getConfig();
Config config = plugin.getMainConfig();
if (!Verify.isEmpty(config.getString("Servers." + serverUUID + ".ServerName"))) {
return;
}
for (Map.Entry<String, Object> entry : settings.entrySet()) {
config.set("Servers." + serverUUID + "." + entry.getKey(), entry.getValue());
}
iConfig.save();
config.save();
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
}
@ -41,7 +39,7 @@ public class ServerSpecificSettings {
public static void updateSettings(Plan plugin, Map<String, String> settings) {
Log.debug("Checking new settings..");
FileConfiguration config = plugin.getConfig();
Config config = plugin.getMainConfig();
boolean changedSomething = false;
for (Map.Entry<String, String> setting : settings.entrySet()) {
@ -52,7 +50,7 @@ public class ServerSpecificSettings {
}
String stringValue = setting.getValue();
Object value = getValue(stringValue);
String currentValue = config.get(path).toString();
String currentValue = config.getString(path);
if (stringValue.equals(currentValue)) {
continue;
}
@ -64,11 +62,15 @@ public class ServerSpecificSettings {
}
if (changedSomething) {
plugin.saveConfig();
try {
config.save();
} catch (IOException e) {
Log.toLog("ServerSpecificSettings / ConfigSave", e);
}
Log.info("----------------------------------");
Log.info("The Received Bungee Settings changed the config values, restarting Plan..");
Log.info("----------------------------------");
plugin.restart();
plugin.reloadPlugin(true);
} else {
Log.debug("Settings up to date");
}
@ -105,63 +107,28 @@ public class ServerSpecificSettings {
return path;
}
public Object get(UUID serverUUID, Settings setting) {
try {
IFileConfig config = PlanBungee.getInstance().getIConfig().getConfig();
String path = getPath(serverUUID, setting);
String value = config.getString(path);
try {
return Boolean.parseBoolean(value);
} catch (Exception e) {
if (Verify.isEmpty(value)) {
return config.getInt(value);
}
return value;
}
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
}
return null;
}
public boolean getBoolean(UUID serverUUID, Settings setting) {
try {
IFileConfig config = PlanBungee.getInstance().getIConfig().getConfig();
String path = getPath(serverUUID, setting);
return config.getBoolean(path);
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
}
return false;
Config config = PlanBungee.getInstance().getMainConfig();
String path = getPath(serverUUID, setting);
return config.getBoolean(path);
}
public String getString(UUID serverUUID, Settings setting) {
try {
IFileConfig config = PlanBungee.getInstance().getIConfig().getConfig();
String path = getPath(serverUUID, setting);
return config.getString(path);
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
}
return null;
Config config = PlanBungee.getInstance().getMainConfig();
String path = getPath(serverUUID, setting);
return config.getString(path);
}
public Integer getInt(UUID serverUUID, Settings setting) {
try {
IFileConfig config = PlanBungee.getInstance().getIConfig().getConfig();
String path = getPath(serverUUID, setting);
return config.getInt(path);
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
}
return null;
Config config = PlanBungee.getInstance().getMainConfig();
String path = getPath(serverUUID, setting);
return config.getInt(path);
}
public void set(UUID serverUUID, Settings setting, Object value) throws IOException {
IConfig iConfig = PlanBungee.getInstance().getIConfig();
IFileConfig config = iConfig.getConfig();
Config config = PlanBungee.getInstance().getMainConfig();
String path = getPath(serverUUID, setting);
config.set(path, value);
iConfig.save();
config.save();
}
}

View File

@ -1,10 +1,9 @@
package main.java.com.djrapitops.plan;
import com.djrapitops.plugin.config.fileconfig.BukkitFileConfig;
import com.djrapitops.plugin.config.fileconfig.IFileConfig;
import com.djrapitops.plugin.utilities.Compatibility;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.config.Config;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import java.io.IOException;
import java.util.List;
/**
@ -168,20 +167,12 @@ public enum Settings {
return configPath;
}
private IFileConfig getConfig() {
try {
if (Compatibility.isBukkitAvailable()) {
return new BukkitFileConfig(Plan.getInstance().getConfig());
} else {
return PlanBungee.getInstance().getIConfig().getConfig();
}
} catch (IOException e) {
throw new IllegalStateException("Config could not be loaded.", e);
}
private Config getConfig() {
return MiscUtils.getIPlan().getMainConfig();
}
public static ServerSpecificSettings serverSpecific() {
if (!Compatibility.isBungeeAvailable()) {
if (!Check.isBungeeAvailable()) {
throw new IllegalStateException("Not supposed to call this method on Bukkit");
}

View File

@ -4,6 +4,8 @@
*/
package main.java.com.djrapitops.plan;
import com.djrapitops.plugin.StaticHolder;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.api.exceptions.DatabaseInitException;
import main.java.com.djrapitops.plan.data.Action;
import main.java.com.djrapitops.plan.data.Session;
@ -68,6 +70,7 @@ public class ShutdownHook extends Thread {
}
db = null;
dataCache = null;
StaticHolder.unRegister(Plan.class);
}
}

View File

@ -4,9 +4,12 @@
*/
package main.java.com.djrapitops.plan;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.api.config.ConfigNode;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.utilities.Verify;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@ -34,18 +37,18 @@ public class WorldAliasSettings {
* @return Map: Original name, Alias
*/
public Map<String, String> getAliases() {
ConfigurationSection aliasSect = getAliasSection();
ConfigNode aliasSect = getAliasSection();
Map<String, String> aliasMap = new HashMap<>();
for (String world : aliasSect.getKeys(false)) {
aliasMap.put(world, aliasSect.getString(world));
for (Map.Entry<String, ConfigNode> world : aliasSect.getChildren().entrySet()) {
aliasMap.put(world.getKey(), world.getValue().getString());
}
return aliasMap;
}
private ConfigurationSection getAliasSection() {
FileConfiguration config = plugin.getConfig();
return config.getConfigurationSection(Settings.WORLD_ALIASES.getPath());
private ConfigNode getAliasSection() {
Config config = plugin.getMainConfig();
return config.getConfigNode(Settings.WORLD_ALIASES.getPath());
}
/**
@ -56,13 +59,17 @@ public class WorldAliasSettings {
* @param world World name
*/
public void addWorld(String world) {
ConfigurationSection aliasSect = getAliasSection();
ConfigNode aliasSect = getAliasSection();
Object previousValue = aliasSect.get(world);
if (previousValue == null) {
String previousValue = aliasSect.getConfigNode(world).getValue();
if (Verify.isEmpty(previousValue)) {
aliasSect.set(world, world);
}
plugin.saveConfig();
try {
aliasSect.save();
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
}
}
/**

View File

@ -1,19 +1,20 @@
package main.java.com.djrapitops.plan.api;
import com.djrapitops.plugin.utilities.Verify;
import com.djrapitops.plugin.utilities.player.Fetch;
import com.djrapitops.plugin.utilities.player.IOfflinePlayer;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.AnalysisData;
import main.java.com.djrapitops.plan.data.additional.AnalysisType;
import main.java.com.djrapitops.plan.data.additional.PluginData;
import main.java.com.djrapitops.plan.systems.info.BukkitInformationManager;
import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility;
import org.bukkit.OfflinePlayer;
import java.sql.SQLException;
import java.util.Collection;
import java.util.UUID;
import static org.bukkit.Bukkit.getOfflinePlayer;
/**
* This class contains the API methods for Bukkit version of the plugin.
* <p>
@ -43,7 +44,7 @@ public class API {
}
/**
* Check whether or not the plugin enabled successfully.
* Condition whether or not the plugin enabled successfully.
*
* @return true if plugin is enabled correctly.
*/
@ -86,7 +87,7 @@ public class API {
}
/**
* Check if Players's Inspect page is cached to PageCache.
* Condition if Players's Inspect page is cached to PageCache.
*
* @param uuid UUID of the player.
* @return true/false
@ -98,7 +99,7 @@ public class API {
}
/**
* Check if Players's Inspect page is cached to PageCache of the providing WebServer.
* Condition if Players's Inspect page is cached to PageCache of the providing WebServer.
* <p>
* Using BungeeCord: Will send a {@code IsCachedWebAPI} request to check if the page is in Bungee's PageCache.
* Only Bukkit: Checks PageCache for page.
@ -147,7 +148,7 @@ public class API {
}
/**
* Check if the Analysis has been run and is cached to the AnalysisCache.
* Condition if the Analysis has been run and is cached to the AnalysisCache.
*
* @return true/false
*/
@ -165,7 +166,7 @@ public class API {
/**
* Used to get the full HTML of the Analysis page as a string.
* <p>
* Check if the data is cached to AnalysisCache before calling this.
* Condition if the data is cached to AnalysisCache before calling this.
*
* @return server.html with all placeholders replaced.
* @throws NullPointerException if AnalysisData has not been cached.
@ -177,7 +178,7 @@ public class API {
/**
* Used to get the AnalysisData object.
* <p>
* Check if the data is cached to AnalysisCache before calling this.
* Condition if the data is cached to AnalysisCache before calling this.
*
* @return AnalysisData object.
* @see AnalysisData
@ -201,7 +202,7 @@ public class API {
if (playerName != null) {
return playerName;
}
IOfflinePlayer offlinePlayer = Fetch.getIOfflinePlayer(uuid);
OfflinePlayer offlinePlayer = getOfflinePlayer(uuid);
if (offlinePlayer != null) {
return offlinePlayer.getName();
}

View File

@ -5,7 +5,8 @@
package main.java.com.djrapitops.plan.api;
import com.djrapitops.plugin.IPlugin;
import com.djrapitops.plugin.config.IConfig;
import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.settings.ColorScheme;
import main.java.com.djrapitops.plan.ServerVariableHolder;
import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.systems.info.InformationManager;
@ -14,7 +15,6 @@ import main.java.com.djrapitops.plan.systems.queue.ProcessingQueue;
import main.java.com.djrapitops.plan.systems.webserver.WebServer;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.UUID;
@ -42,7 +42,7 @@ public interface IPlan extends IPlugin {
InputStream getResource(String resource);
IConfig getIConfig() throws IOException;
Config getMainConfig();
void restart();
ColorScheme getColorScheme();
}

View File

@ -0,0 +1,28 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package main.java.com.djrapitops.plan.api.exceptions;
/**
* Group of WebAPIExceptions that can be considered a failed connection state on some occasions.
*
* @author Rsl1122
*/
public class WebAPIFailException extends WebAPIException {
public WebAPIFailException() {
}
public WebAPIFailException(String message) {
super(message);
}
public WebAPIFailException(String message, Throwable cause) {
super(message, cause);
}
public WebAPIFailException(Throwable cause) {
super(cause);
}
}

View File

@ -9,7 +9,7 @@ package main.java.com.djrapitops.plan.api.exceptions;
*
* @author Rsl1122
*/
public class WebAPIForbiddenException extends WebAPIException {
public class WebAPIForbiddenException extends WebAPIFailException {
public WebAPIForbiddenException(String url) {
super("Forbidden: " + url);
}

View File

@ -0,0 +1,16 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package main.java.com.djrapitops.plan.api.exceptions;
/**
* Thrown when WebAPI returns 404, usually when response is supposed to be false.
*
* @author Rsl1122
*/
public class WebAPIInternalErrorException extends WebAPIFailException {
public WebAPIInternalErrorException() {
super("Internal Error occurred on receiving server");
}
}

View File

@ -9,7 +9,7 @@ package main.java.com.djrapitops.plan.api.exceptions;
*
* @author Rsl1122
*/
public class WebAPINotFoundException extends WebAPIException {
public class WebAPINotFoundException extends WebAPIFailException {
public WebAPINotFoundException() {
super("Not Found");
}

View File

@ -21,12 +21,12 @@ public class ConditionUtils {
}
/**
* Check if the player has played.
* Condition if the player has played.
*
* @param uuid UUID of player
* @return has the player played before, false if uuid is null.
*/
public static boolean playerHasPlayed(UUID uuid) {
return Verify.notNull(uuid) && Plan.getInstance().fetch().hasPlayedBefore(uuid);
return Verify.notNull(uuid) && Plan.getInstance().getServer().getOfflinePlayer(uuid).hasPlayedBefore();
}
}

View File

@ -29,6 +29,7 @@ public class PlanBungeeCommand extends TreeCommand<PlanBungee> {
public PlanBungeeCommand(PlanBungee plugin) {
super(plugin, "planbungee", CommandType.CONSOLE, "", "", "planbungee");
super.setDefaultCommand("help");
super.setColorScheme(plugin.getColorScheme());
}
@Override
@ -38,13 +39,17 @@ public class PlanBungeeCommand extends TreeCommand<PlanBungee> {
@Override
public void addCommands() {
commands.add(new ReloadCommand(plugin));
commands.add(new StatusCommand<>(plugin, Permissions.MANAGE.getPermission()));
commands.add(new ListCommand());
add(
new ReloadCommand(plugin),
new StatusCommand<>(plugin, Permissions.MANAGE.getPermission(), plugin.getColorScheme()),
new ListCommand()
);
RegisterCommand registerCommand = new RegisterCommand(plugin);
commands.add(registerCommand);
commands.add(new WebUserCommand(plugin, registerCommand));
commands.add(new NetworkCommand(plugin));
commands.add(new ListServersCommand(plugin));
add(
registerCommand,
new WebUserCommand(plugin, registerCommand),
new NetworkCommand(plugin),
new ListServersCommand(plugin)
);
}
}

View File

@ -30,6 +30,7 @@ public class PlanCommand extends TreeCommand<Plan> {
public PlanCommand(Plan plugin) {
super(plugin, "plan", CommandType.CONSOLE, "", "", "plan");
super.setDefaultCommand("inspect");
super.setColorScheme(plugin.getColorScheme());
}
@Override
@ -39,22 +40,25 @@ public class PlanCommand extends TreeCommand<Plan> {
@Override
public void addCommands() {
commands.add(new InspectCommand(plugin));
commands.add(new AnalyzeCommand(plugin));
commands.add(new SearchCommand(plugin));
commands.add(new InfoCommand(plugin));
commands.add(new ReloadCommand(plugin));
commands.add(new ManageCommand(plugin));
commands.add(new StatusCommand<>(plugin, Permissions.MANAGE.getPermission()));
commands.add(new ListCommand());
add(
new InspectCommand(plugin),
new AnalyzeCommand(plugin),
new SearchCommand(plugin),
new InfoCommand(plugin),
new ReloadCommand(plugin),
new ManageCommand(plugin),
new StatusCommand<>(plugin, Permissions.MANAGE.getPermission(), plugin.getColorScheme()),
new ListCommand()
);
RegisterCommand registerCommand = new RegisterCommand(plugin);
commands.add(registerCommand);
commands.add(new WebUserCommand(plugin, registerCommand));
commands.add(new NetworkCommand(plugin));
commands.add(new ListServersCommand(plugin));
add(
registerCommand,
new WebUserCommand(plugin, registerCommand),
new NetworkCommand(plugin),
new ListServersCommand(plugin));
if (Settings.DEV_MODE.isTrue()) {
commands.add(new DevCommand(plugin));
add(new DevCommand(plugin));
}
}
}

View File

@ -1,12 +1,13 @@
package main.java.com.djrapitops.plan.command.commands;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.CommandUtils;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.locale.Locale;
@ -110,7 +111,7 @@ public class AnalyzeCommand extends SubCommand {
sender.sendMessage(Locale.get(Msg.CMD_INFO_FETCH_DATA).toString());
if (plugin.getInfoManager().isAuthRequired() && CommandUtils.isPlayer(sender)) {
plugin.getRunnableFactory().createNew(new AbsRunnable("WebUser exist check task") {
RunnableFactory.createNew(new AbsRunnable("WebUser exist check task") {
@Override
public void run() {
try {

View File

@ -13,7 +13,7 @@ import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg;
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPI;
import main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit.InspectWebAPI;
import main.java.com.djrapitops.plan.utilities.Check;
import main.java.com.djrapitops.plan.utilities.Condition;
import java.util.Optional;
import java.util.UUID;
@ -28,19 +28,19 @@ public class DevCommand extends SubCommand {
private final Plan plugin;
public DevCommand(Plan plugin) {
super("dev", CommandType.CONSOLE_WITH_ARGUMENTS, "plan.*", "Test Plugin functions not testable with unit tests.", "<feature to test>");
super("dev", CommandType.PLAYER_OR_ARGS, "plan.*", "Test Plugin functions not testable with unit tests.", "<feature to test>");
this.plugin = plugin;
}
@Override
public boolean onCommand(ISender sender, String cmd, String[] args) {
if (!Check.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
return true;
}
String feature = args[0];
switch (feature) {
case "webapi":
if (!Check.isTrue(args.length >= 2, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
if (!Condition.isTrue(args.length >= 2, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
break;
}
if (!webapi(args[1] + "webapi", args.length >= 3)) {

View File

@ -4,7 +4,6 @@ import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.settings.ColorScheme;
import com.djrapitops.plugin.settings.Version;
import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.locale.Locale;
@ -40,11 +39,11 @@ public class InfoCommand extends SubCommand {
String mColor = cs.getMainColor();
String sColor = cs.getSecondaryColor();
String tColor = cs.getTertiaryColor();
String ball = Locale.get(Msg.CMD_CONSTANT_LIST_BALL).toString();
String[] messages = {
Locale.get(Msg.CMD_HEADER_INFO).toString(),
Locale.get(Msg.CMD_CONSTANT_LIST_BALL).toString() + mColor + " Version: " + sColor + plugin.getDescription().getVersion(),
Locale.get(Msg.CMD_CONSTANT_LIST_BALL).toString() + tColor + " " + Version.checkVersion(plugin),
Locale.get(Msg.CMD_CONSTANT_LIST_BALL).toString() + mColor + " Active Database: " + tColor + plugin.getDB().getConfigName(),
ball + mColor + " Version: " + sColor + plugin.getDescription().getVersion(),
ball + mColor + " Active Database: " + tColor + plugin.getDB().getConfigName(),
Locale.get(Msg.CMD_CONSTANT_FOOTER).toString()
};
sender.sendMessage(messages);

View File

@ -1,19 +1,20 @@
package main.java.com.djrapitops.plan.command.commands;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.CommandUtils;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.command.ConditionUtils;
import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg;
import main.java.com.djrapitops.plan.systems.processing.info.InspectCacheRequestProcessor;
import main.java.com.djrapitops.plan.utilities.Check;
import main.java.com.djrapitops.plan.utilities.Condition;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility;
import org.bukkit.ChatColor;
@ -38,7 +39,7 @@ public class InspectCommand extends SubCommand {
*/
public InspectCommand(Plan plugin) {
super("inspect",
CommandType.CONSOLE_WITH_ARGUMENTS,
CommandType.PLAYER_OR_ARGS,
Permissions.INSPECT.getPermission(),
Locale.get(Msg.CMD_USG_INSPECT).toString(),
"<player>");
@ -61,18 +62,18 @@ public class InspectCommand extends SubCommand {
}
private void runInspectTask(String playerName, ISender sender) {
plugin.getRunnableFactory().createNew(new AbsRunnable("InspectTask") {
RunnableFactory.createNew(new AbsRunnable("InspectTask") {
@Override
public void run() {
try {
UUID uuid = UUIDUtility.getUUIDOf(playerName);
if (!Check.isTrue(Verify.notNull(uuid), Locale.get(Msg.CMD_FAIL_USERNAME_NOT_VALID).toString(), sender)) {
if (!Condition.isTrue(Verify.notNull(uuid), Locale.get(Msg.CMD_FAIL_USERNAME_NOT_VALID).toString(), sender)) {
return;
}
if (!Check.isTrue(ConditionUtils.playerHasPlayed(uuid), Locale.get(Msg.CMD_FAIL_USERNAME_NOT_SEEN).toString(), sender)) {
if (!Condition.isTrue(ConditionUtils.playerHasPlayed(uuid), Locale.get(Msg.CMD_FAIL_USERNAME_NOT_SEEN).toString(), sender)) {
return;
}
if (!Check.isTrue(plugin.getDB().wasSeenBefore(uuid), Locale.get(Msg.CMD_FAIL_USERNAME_NOT_KNOWN).toString(), sender)) {
if (!Condition.isTrue(plugin.getDB().wasSeenBefore(uuid), Locale.get(Msg.CMD_FAIL_USERNAME_NOT_KNOWN).toString(), sender)) {
return;
}
if (CommandUtils.isPlayer(sender) && plugin.getWebServer().isAuthRequired()) {

View File

@ -1,10 +1,10 @@
package main.java.com.djrapitops.plan.command.commands;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.settings.ColorScheme;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.locale.Locale;

View File

@ -25,7 +25,7 @@ public class ManageCommand extends TreeCommand<Plan> {
*/
public ManageCommand(Plan plugin) {
super(plugin, "manage,m", CommandType.CONSOLE, Permissions.MANAGE.getPermission(), Locale.get(Msg.CMD_USG_MANAGE).toString(), "plan m");
super.setColorScheme(plugin.getColorScheme());
}
@Override
@ -35,15 +35,17 @@ public class ManageCommand extends TreeCommand<Plan> {
@Override
public void addCommands() {
commands.add(new ManageMoveCommand(plugin));
commands.add(new ManageHotswapCommand(plugin));
commands.add(new ManageBackupCommand(plugin));
commands.add(new ManageRestoreCommand(plugin));
commands.add(new ManageImportCommand(plugin));
commands.add(new ManageRemoveCommand(plugin));
commands.add(new ManageClearCommand(plugin));
commands.add(new ManageDumpCommand(plugin));
commands.add(new ManageSetupCommand(plugin));
commands.add(new ManageDisableCommand());
add(
new ManageMoveCommand(plugin),
new ManageHotswapCommand(plugin),
new ManageBackupCommand(plugin),
new ManageRestoreCommand(plugin),
new ManageImportCommand(plugin),
new ManageRemoveCommand(plugin),
new ManageClearCommand(plugin),
new ManageDumpCommand(plugin),
new ManageSetupCommand(plugin),
new ManageDisableCommand()
);
}
}

View File

@ -1,19 +1,20 @@
package main.java.com.djrapitops.plan.command.commands;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.CommandUtils;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.utilities.Compatibility;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.task.RunnableFactory;
import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.data.WebUser;
import main.java.com.djrapitops.plan.database.tables.SecurityTable;
import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg;
import main.java.com.djrapitops.plan.utilities.Check;
import main.java.com.djrapitops.plan.utilities.Condition;
import main.java.com.djrapitops.plan.utilities.PassEncryptUtil;
/**
@ -34,12 +35,12 @@ public class RegisterCommand extends SubCommand {
public RegisterCommand(IPlan plugin) {
super("register",
CommandType.CONSOLE_WITH_ARGUMENTS,
CommandType.PLAYER_OR_ARGS,
"", // No Permission Requirement
Locale.get(Msg.CMD_USG_WEB_REGISTER).toString(),
"<password> [name] [access lvl]");
this.plugin = plugin;
if (Compatibility.isBukkitAvailable()) {
if (Check.isBukkitAvailable()) {
setupFilter();
}
}
@ -73,7 +74,7 @@ public class RegisterCommand extends SubCommand {
}
private void consoleRegister(String[] args, ISender sender, String notEnoughArgsMsg) throws PassEncryptUtil.CannotPerformOperationException {
if (Check.isTrue(args.length >= 3, notEnoughArgsMsg, sender)) {
if (Condition.isTrue(args.length >= 3, notEnoughArgsMsg, sender)) {
int permLevel;
permLevel = Integer.parseInt(args[2]);
String passHash = PassEncryptUtil.createHash(args[0]);
@ -113,7 +114,7 @@ public class RegisterCommand extends SubCommand {
}
private void registerUser(WebUser webUser, ISender sender) {
plugin.getRunnableFactory().createNew(new AbsRunnable("Register WebUser Task") {
RunnableFactory.createNew(new AbsRunnable("Register WebUser Task") {
@Override
public void run() {
final String existsMsg = "§cUser Already Exists!";
@ -122,7 +123,7 @@ public class RegisterCommand extends SubCommand {
try {
SecurityTable securityTable = plugin.getDB().getSecurityTable();
boolean userExists = securityTable.userExists(userName);
if (!Check.isTrue(!userExists, existsMsg, sender)) {
if (!Condition.isTrue(!userExists, existsMsg, sender)) {
return;
}
securityTable.addNewUser(webUser);

View File

@ -34,7 +34,7 @@ public class ReloadCommand extends SubCommand {
@Override
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
plugin.restart();
plugin.reloadPlugin(true);
sender.sendMessage(Locale.get(Msg.CMD_INFO_RELOAD_COMPLETE).toString());
return true;
}

View File

@ -4,13 +4,14 @@ import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.utilities.FormattingUtils;
import com.djrapitops.plugin.task.RunnableFactory;
import com.djrapitops.plugin.utilities.FormatUtils;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg;
import main.java.com.djrapitops.plan.utilities.Check;
import main.java.com.djrapitops.plan.utilities.Condition;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import java.util.Arrays;
@ -24,8 +25,6 @@ import java.util.List;
*/
public class SearchCommand extends SubCommand {
private final Plan plugin;
/**
* Class Constructor.
*
@ -33,11 +32,10 @@ public class SearchCommand extends SubCommand {
*/
public SearchCommand(Plan plugin) {
super("search",
CommandType.CONSOLE_WITH_ARGUMENTS,
CommandType.PLAYER_OR_ARGS,
Permissions.SEARCH.getPermission(),
Locale.get(Msg.CMD_USG_SEARCH).toString(),
"<part of playername>");
this.plugin = plugin;
}
@ -48,7 +46,7 @@ public class SearchCommand extends SubCommand {
@Override
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
if (!Check.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
return true;
}
sender.sendMessage(Locale.get(Msg.CMD_INFO_SEARCHING).toString());
@ -58,7 +56,7 @@ public class SearchCommand extends SubCommand {
}
private void runSearchTask(String[] args, ISender sender) {
plugin.getRunnableFactory().createNew(new AbsRunnable("SearchTask: " + Arrays.toString(args)) {
RunnableFactory.createNew(new AbsRunnable("SearchTask: " + Arrays.toString(args)) {
@Override
public void run() {
try {
@ -71,7 +69,7 @@ public class SearchCommand extends SubCommand {
if (empty) {
sender.sendMessage(Locale.get(Msg.CMD_INFO_NO_RESULTS).parse(Arrays.toString(args)));
} else {
sender.sendMessage(Locale.get(Msg.CMD_INFO_RESULTS).toString() + FormattingUtils.collectionToStringNoBrackets(names));
sender.sendMessage(Locale.get(Msg.CMD_INFO_RESULTS).toString() + FormatUtils.collectionToStringNoBrackets(names));
}
sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).toString());

View File

@ -27,7 +27,8 @@ public class WebUserCommand extends TreeCommand<IPlan> {
Permissions.MANAGE_WEB.getPerm(),
Locale.get(Msg.CMD_USG_WEB).toString(),
"plan web");
commands.add(register);
super.setColorScheme(plugin.getColorScheme());
add(register);
}
public WebUserCommand(PlanBungee plugin, RegisterCommand register) {
@ -36,7 +37,7 @@ public class WebUserCommand extends TreeCommand<IPlan> {
Permissions.MANAGE_WEB.getPerm(),
Locale.get(Msg.CMD_USG_WEB).toString(),
"planbungee web");
commands.add(register);
add(register);
}
@Override
@ -46,9 +47,11 @@ public class WebUserCommand extends TreeCommand<IPlan> {
@Override
public void addCommands() {
commands.add(new WebLevelCommand(plugin));
commands.add(new WebListUsersCommand(plugin));
commands.add(new WebCheckCommand(plugin));
commands.add(new WebDeleteCommand(plugin));
add(
new WebLevelCommand(plugin),
new WebListUsersCommand(plugin),
new WebCheckCommand(plugin),
new WebDeleteCommand(plugin)
);
}
}

View File

@ -1,18 +1,19 @@
package main.java.com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.api.exceptions.DatabaseInitException;
import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg;
import main.java.com.djrapitops.plan.utilities.Check;
import main.java.com.djrapitops.plan.utilities.Condition;
import main.java.com.djrapitops.plan.utilities.ManageUtils;
/**
@ -44,19 +45,19 @@ public class ManageBackupCommand extends SubCommand {
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
try {
if (!Check.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(this.getArguments()), sender)) {
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(this.getArguments()), sender)) {
return true;
}
String dbName = args[0].toLowerCase();
boolean isCorrectDB = "sqlite".equals(dbName) || "mysql".equals(dbName);
if (!Check.isTrue(isCorrectDB, Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + dbName, sender)) {
if (!Condition.isTrue(isCorrectDB, Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + dbName, sender)) {
return true;
}
final Database database = ManageUtils.getDB(plugin, dbName);
// If DB is null return
if (!Check.isTrue(Verify.notNull(database), Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString(), sender)) {
if (!Condition.isTrue(Verify.notNull(database), Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString(), sender)) {
Log.error(dbName + " was null!");
return true;
}
@ -71,7 +72,7 @@ public class ManageBackupCommand extends SubCommand {
}
private void runBackupTask(ISender sender, String[] args, final Database database) {
plugin.getRunnableFactory().createNew(new AbsRunnable("BackupTask") {
RunnableFactory.createNew(new AbsRunnable("BackupTask") {
@Override
public void run() {
try {

View File

@ -1,11 +1,12 @@
package main.java.com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.api.exceptions.DatabaseInitException;
@ -15,7 +16,7 @@ import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg;
import main.java.com.djrapitops.plan.systems.cache.DataCache;
import main.java.com.djrapitops.plan.systems.cache.SessionCache;
import main.java.com.djrapitops.plan.utilities.Check;
import main.java.com.djrapitops.plan.utilities.Condition;
import main.java.com.djrapitops.plan.utilities.ManageUtils;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
@ -38,7 +39,7 @@ public class ManageClearCommand extends SubCommand {
*/
public ManageClearCommand(Plan plugin) {
super("clear",
CommandType.CONSOLE_WITH_ARGUMENTS,
CommandType.PLAYER_OR_ARGS,
Permissions.MANAGE.getPermission(),
Locale.get(Msg.CMD_USG_MANAGE_CLEAR).toString(),
"<DB> [-a]");
@ -54,18 +55,18 @@ public class ManageClearCommand extends SubCommand {
@Override
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
if (!Check.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
return true;
}
String dbName = args[0].toLowerCase();
boolean isCorrectDB = "sqlite".equals(dbName) || "mysql".equals(dbName);
if (!Check.isTrue(isCorrectDB, Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + dbName, sender)) {
if (!Condition.isTrue(isCorrectDB, Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + dbName, sender)) {
return true;
}
if (!Check.isTrue(Verify.contains("-a", args), Locale.get(Msg.MANAGE_FAIL_CONFIRM).parse(Locale.get(Msg.MANAGE_NOTIFY_REMOVE).parse(args[0])), sender)) {
if (!Condition.isTrue(Verify.contains("-a", args), Locale.get(Msg.MANAGE_FAIL_CONFIRM).parse(Locale.get(Msg.MANAGE_NOTIFY_REMOVE).parse(args[0])), sender)) {
return true;
}
@ -79,7 +80,7 @@ public class ManageClearCommand extends SubCommand {
}
private void runClearTask(ISender sender, Database database) {
plugin.getRunnableFactory().createNew(new AbsRunnable("DBClearTask") {
RunnableFactory.createNew(new AbsRunnable("DBClearTask") {
@Override
public void run() {
try {

View File

@ -7,7 +7,7 @@ import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg;
import main.java.com.djrapitops.plan.systems.listeners.PlanPlayerListener;
import main.java.com.djrapitops.plan.utilities.Check;
import main.java.com.djrapitops.plan.utilities.Condition;
/**
* This manage SubCommand is used to disable some features of the plugin temporarily.
@ -21,7 +21,7 @@ public class ManageDisableCommand extends SubCommand {
*/
public ManageDisableCommand() {
super("disable",
CommandType.CONSOLE_WITH_ARGUMENTS,
CommandType.PLAYER_OR_ARGS,
Permissions.MANAGE.getPermission(),
"Used to disable some features of the Plugin temporarily",
"<feature>");
@ -29,7 +29,7 @@ public class ManageDisableCommand extends SubCommand {
@Override
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
if (!Check.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(this.getArguments()), sender)) {
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(this.getArguments()), sender)) {
return true;
}
switch (args[0].toLowerCase()) {

View File

@ -4,6 +4,7 @@ import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.locale.Locale;
@ -47,7 +48,7 @@ public class ManageDumpCommand extends SubCommand {
}
private void dump(ISender sender) {
plugin.getRunnableFactory().createNew(new AbsRunnable("DumpTask") {
RunnableFactory.createNew(new AbsRunnable("DumpTask") {
@Override
public void run() {
try {

View File

@ -1,18 +1,22 @@
package main.java.com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg;
import main.java.com.djrapitops.plan.utilities.Check;
import main.java.com.djrapitops.plan.utilities.Condition;
import main.java.com.djrapitops.plan.utilities.ManageUtils;
import java.io.IOException;
/**
* This manage subcommand is used to swap to a different database and reload the
* plugin if the connection to the new database can be established.
@ -31,7 +35,7 @@ public class ManageHotswapCommand extends SubCommand {
*/
public ManageHotswapCommand(Plan plugin) {
super("hotswap",
CommandType.CONSOLE_WITH_ARGUMENTS,
CommandType.PLAYER_OR_ARGS,
Permissions.MANAGE.getPermission(),
Locale.get(Msg.CMD_USG_MANAGE_HOTSWAP).toString(),
"<DB>");
@ -47,17 +51,17 @@ public class ManageHotswapCommand extends SubCommand {
@Override
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
if (!Check.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
return true;
}
String dbName = args[0].toLowerCase();
boolean isCorrectDB = "sqlite".equals(dbName) || "mysql".equals(dbName);
if (!Check.isTrue(isCorrectDB, Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + dbName, sender)) {
if (!Condition.isTrue(isCorrectDB, Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + dbName, sender)) {
return true;
}
if (Check.isTrue(dbName.equals(plugin.getDB().getConfigName()), Locale.get(Msg.MANAGE_FAIL_SAME_DB).toString(), sender)) {
if (Condition.isTrue(dbName.equals(plugin.getDB().getConfigName()), Locale.get(Msg.MANAGE_FAIL_SAME_DB).toString(), sender)) {
return true;
}
@ -65,7 +69,7 @@ public class ManageHotswapCommand extends SubCommand {
final Database database = ManageUtils.getDB(plugin, dbName);
// If DB is null return
if (!Check.isTrue(Verify.notNull(database), Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString(), sender)) {
if (!Condition.isTrue(Verify.notNull(database), Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString(), sender)) {
Log.error(dbName + " was null!");
return true;
}
@ -80,10 +84,14 @@ public class ManageHotswapCommand extends SubCommand {
return true;
}
plugin.getConfig().set("database.type", dbName);
plugin.saveConfig();
plugin.onDisable();
plugin.onEnable();
Config config = plugin.getMainConfig();
config.set(Settings.DB_TYPE.getPath(), dbName);
try {
config.save();
plugin.reloadPlugin(true);
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
}
return true;
}
}

View File

@ -4,15 +4,13 @@ import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.task.AbsRunnable;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.task.RunnableFactory;
import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg;
import main.java.com.djrapitops.plan.systems.info.ImporterManager;
import main.java.com.djrapitops.plan.utilities.Check;
import java.sql.SQLException;
import main.java.com.djrapitops.plan.utilities.Condition;
/**
* This manage subcommand is used to import data from 3rd party plugins.
@ -49,7 +47,7 @@ public class ManageImportCommand extends SubCommand {
@Override
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
if (!Check.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG) + " " + this.getArguments(), sender)) {
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG) + " " + this.getArguments(), sender)) {
return true;
}
@ -58,13 +56,11 @@ public class ManageImportCommand extends SubCommand {
}
private void runImport(String importer) {
plugin.getRunnableFactory().createNew("Import", new AbsRunnable() {
RunnableFactory.createNew("Import", new AbsRunnable() {
@Override
public void run() {
try {
ImporterManager.getImporter(importer).processImport();
} catch (SQLException e) {
Log.toLog(this.getClass().getName(), e);
} finally {
this.cancel();
}

View File

@ -1,17 +1,18 @@
package main.java.com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg;
import main.java.com.djrapitops.plan.utilities.Check;
import main.java.com.djrapitops.plan.utilities.Condition;
import main.java.com.djrapitops.plan.utilities.ManageUtils;
/**
@ -33,7 +34,7 @@ public class ManageMoveCommand extends SubCommand {
*/
public ManageMoveCommand(Plan plugin) {
super("move",
CommandType.CONSOLE_WITH_ARGUMENTS,
CommandType.PLAYER_OR_ARGS,
Permissions.MANAGE.getPermission(),
Locale.get(Msg.CMD_USG_MANAGE_MOVE).toString(),
"<fromDB> <toDB> [-a]");
@ -43,29 +44,29 @@ public class ManageMoveCommand extends SubCommand {
@Override
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
if (!Check.isTrue(args.length >= 2, Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(this.getArguments()), sender)) {
if (!Condition.isTrue(args.length >= 2, Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(this.getArguments()), sender)) {
return true;
}
String fromDB = args[0].toLowerCase();
boolean isCorrectDB = "sqlite".equals(fromDB) || "mysql".equals(fromDB);
if (!Check.isTrue(isCorrectDB, Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + fromDB, sender)) {
if (!Condition.isTrue(isCorrectDB, Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + fromDB, sender)) {
return true;
}
String toDB = args[1].toLowerCase();
isCorrectDB = "sqlite".equals(toDB) || "mysql".equals(toDB);
if (!Check.isTrue(isCorrectDB, Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + toDB, sender)) {
if (!Condition.isTrue(isCorrectDB, Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + toDB, sender)) {
return true;
}
if (!Check.isTrue(!Verify.equalsIgnoreCase(fromDB, toDB), Locale.get(Msg.MANAGE_FAIL_SAME_DB).toString(), sender)) {
if (!Condition.isTrue(!Verify.equalsIgnoreCase(fromDB, toDB), Locale.get(Msg.MANAGE_FAIL_SAME_DB).toString(), sender)) {
return true;
}
if (!Check.isTrue(Verify.contains("-a", args), Locale.get(Msg.MANAGE_FAIL_CONFIRM).parse(Locale.get(Msg.MANAGE_NOTIFY_REMOVE).parse(args[1])), sender)) {
if (!Condition.isTrue(Verify.contains("-a", args), Locale.get(Msg.MANAGE_FAIL_CONFIRM).parse(Locale.get(Msg.MANAGE_NOTIFY_REMOVE).parse(args[1])), sender)) {
return true;
}
@ -81,7 +82,7 @@ public class ManageMoveCommand extends SubCommand {
}
private void runMoveTask(final Database fromDatabase, final Database toDatabase, ISender sender) {
plugin.getRunnableFactory().createNew(new AbsRunnable("DBMoveTask") {
RunnableFactory.createNew(new AbsRunnable("DBMoveTask") {
@Override
public void run() {
try {
@ -90,7 +91,7 @@ public class ManageMoveCommand extends SubCommand {
ManageUtils.clearAndCopy(toDatabase, fromDatabase);
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_MOVE_SUCCESS).toString());
boolean movedToCurrentDatabase = Verify.equalsIgnoreCase(toDatabase.getConfigName(), plugin.getDB().getConfigName());
Check.isTrue(!movedToCurrentDatabase, Locale.get(Msg.MANAGE_INFO_CONFIG_REMINDER).toString(), sender);
Condition.isTrue(!movedToCurrentDatabase, Locale.get(Msg.MANAGE_INFO_CONFIG_REMINDER).toString(), sender);
} catch (Exception e) {
Log.toLog(this.getClass().getName() + " " + getTaskName(), e);
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString());

View File

@ -1,11 +1,12 @@
package main.java.com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.Session;
@ -13,7 +14,7 @@ import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg;
import main.java.com.djrapitops.plan.systems.cache.DataCache;
import main.java.com.djrapitops.plan.systems.cache.SessionCache;
import main.java.com.djrapitops.plan.utilities.Check;
import main.java.com.djrapitops.plan.utilities.Condition;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility;
import org.bukkit.entity.Player;
@ -40,7 +41,7 @@ public class ManageRemoveCommand extends SubCommand {
*/
public ManageRemoveCommand(Plan plugin) {
super("remove",
CommandType.CONSOLE_WITH_ARGUMENTS,
CommandType.PLAYER_OR_ARGS,
Permissions.MANAGE.getPermission(),
Locale.get(Msg.CMD_USG_MANAGE_REMOVE).toString(),
"<player> [-a]");
@ -56,7 +57,7 @@ public class ManageRemoveCommand extends SubCommand {
@Override
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
if (!Check.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
return true;
}
@ -67,24 +68,24 @@ public class ManageRemoveCommand extends SubCommand {
}
private void runRemoveTask(String playerName, ISender sender, String[] args) {
plugin.getRunnableFactory().createNew(new AbsRunnable("DBRemoveTask " + playerName) {
RunnableFactory.createNew(new AbsRunnable("DBRemoveTask " + playerName) {
@Override
public void run() {
try {
UUID uuid = UUIDUtility.getUUIDOf(playerName);
String message = Locale.get(Msg.CMD_FAIL_USERNAME_NOT_VALID).toString();
if (!Check.isTrue(Verify.notNull(uuid), message, sender)) {
if (!Condition.isTrue(Verify.notNull(uuid), message, sender)) {
return;
}
message = Locale.get(Msg.CMD_FAIL_USERNAME_NOT_KNOWN).toString();
if (!Check.isTrue(plugin.getDB().wasSeenBefore(uuid), message, sender)) {
if (!Condition.isTrue(plugin.getDB().wasSeenBefore(uuid), message, sender)) {
return;
}
message = Locale.get(Msg.MANAGE_FAIL_CONFIRM).parse(Locale.get(Msg.MANAGE_NOTIFY_REMOVE).parse(plugin.getDB().getConfigName()));
if (!Check.isTrue(Verify.contains("-a", args), message, sender)) {
if (!Condition.isTrue(Verify.contains("-a", args), message, sender)) {
return;
}

View File

@ -1,18 +1,19 @@
package main.java.com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg;
import main.java.com.djrapitops.plan.utilities.Check;
import main.java.com.djrapitops.plan.utilities.Condition;
import main.java.com.djrapitops.plan.utilities.ManageUtils;
import java.io.File;
@ -44,18 +45,18 @@ public class ManageRestoreCommand extends SubCommand {
@Override
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
if (!Check.isTrue(args.length >= 2, Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(this.getArguments()), sender)) {
if (!Condition.isTrue(args.length >= 2, Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(this.getArguments()), sender)) {
return true;
}
String db = args[1].toLowerCase();
boolean isCorrectDB = "sqlite".equals(db) || "mysql".equals(db);
if (!Check.isTrue(isCorrectDB, Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + db, sender)) {
if (!Condition.isTrue(isCorrectDB, Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + db, sender)) {
return true;
}
if (!Check.isTrue(Verify.contains("-a", args), Locale.get(Msg.MANAGE_FAIL_CONFIRM).parse(Locale.get(Msg.MANAGE_NOTIFY_REWRITE).parse(args[1])), sender)) {
if (!Condition.isTrue(Verify.contains("-a", args), Locale.get(Msg.MANAGE_FAIL_CONFIRM).parse(Locale.get(Msg.MANAGE_NOTIFY_REWRITE).parse(args[1])), sender)) {
return true;
}
@ -70,7 +71,7 @@ public class ManageRestoreCommand extends SubCommand {
}
private void runRestoreTask(String[] args, ISender sender, final Database database) {
plugin.getRunnableFactory().createNew(new AbsRunnable("RestoreTask") {
RunnableFactory.createNew(new AbsRunnable("RestoreTask") {
@Override
public void run() {
try {
@ -78,7 +79,7 @@ public class ManageRestoreCommand extends SubCommand {
boolean containsDBFileExtension = backupDBName.endsWith(".db");
File backupDBFile = new File(plugin.getDataFolder(), backupDBName + (containsDBFileExtension ? "" : ".db"));
if (!Check.isTrue(Verify.exists(backupDBFile), Locale.get(Msg.MANAGE_FAIL_FILE_NOT_FOUND) + " " + args[0], sender)) {
if (!Condition.isTrue(Verify.exists(backupDBFile), Locale.get(Msg.MANAGE_FAIL_FILE_NOT_FOUND) + " " + args[0], sender)) {
return;
}

View File

@ -1,17 +1,18 @@
package main.java.com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.api.exceptions.WebAPIException;
import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg;
import main.java.com.djrapitops.plan.systems.webserver.webapi.bungee.RequestSetupWebAPI;
import main.java.com.djrapitops.plan.systems.webserver.webapi.universal.PingWebAPI;
import main.java.com.djrapitops.plan.utilities.Check;
import main.java.com.djrapitops.plan.utilities.Condition;
/**
* This manage subcommand is used to swap to a different database and reload the
@ -31,7 +32,7 @@ public class ManageSetupCommand extends SubCommand {
*/
public ManageSetupCommand(Plan plugin) {
super("setup",
CommandType.CONSOLE_WITH_ARGUMENTS,
CommandType.PLAYER_OR_ARGS,
Permissions.MANAGE.getPermission(),
"Set-Up Bungee WebServer connection",
"<Bungee WebServer address>");
@ -47,7 +48,7 @@ public class ManageSetupCommand extends SubCommand {
@Override
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
if (!Check.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
return true;
}
if (!plugin.getWebServer().isEnabled()) {
@ -63,7 +64,10 @@ public class ManageSetupCommand extends SubCommand {
address = address.substring(0, address.length() - 1);
}
try {
plugin.getWebServer().getWebAPI().getAPI(PingWebAPI.class).sendRequest(address);
Config config = plugin.getMainConfig();
config.set(Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.getPath(), false);
config.set(Settings.BUNGEE_COPY_CONFIG.getPath(), true);
// plugin.getWebServer().getWebAPI().getAPI(PingWebAPI.class).sendRequest(address);
plugin.getWebServer().getWebAPI().getAPI(RequestSetupWebAPI.class).sendRequest(address);
sender.sendMessage("§eConnection successful, Plan may restart in a few seconds, if it doesn't something has gone wrong.");
} catch (WebAPIException e) {

View File

@ -1,17 +1,18 @@
package main.java.com.djrapitops.plan.command.commands.webuser;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.task.AbsRunnable;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.task.RunnableFactory;
import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.data.WebUser;
import main.java.com.djrapitops.plan.database.tables.SecurityTable;
import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg;
import main.java.com.djrapitops.plan.utilities.Check;
import main.java.com.djrapitops.plan.utilities.Condition;
import org.bukkit.ChatColor;
/**
@ -26,7 +27,7 @@ public class WebCheckCommand extends SubCommand {
public WebCheckCommand(IPlan plugin) {
super("check",
CommandType.CONSOLE_WITH_ARGUMENTS,
CommandType.PLAYER_OR_ARGS,
Permissions.MANAGE_WEB.getPerm(),
Locale.get(Msg.CMD_USG_WEB_CHECK).toString(),
"<username>");
@ -35,17 +36,17 @@ public class WebCheckCommand extends SubCommand {
@Override
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
if (!Check.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).parse() + " <username>", sender)) {
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).parse() + " <username>", sender)) {
return true;
}
SecurityTable table = plugin.getDB().getSecurityTable();
String user = args[0];
plugin.getRunnableFactory().createNew(new AbsRunnable("Webuser Check Task: " + user) {
RunnableFactory.createNew(new AbsRunnable("Webuser Check Task: " + user) {
@Override
public void run() {
try {
if (!Check.isTrue(table.userExists(user), ChatColor.RED + "[Plan] User Doesn't exist.", sender)) {
if (!Condition.isTrue(table.userExists(user), ChatColor.RED + "[Plan] User Doesn't exist.", sender)) {
return;
}
WebUser info = table.getWebUser(user);

View File

@ -1,16 +1,17 @@
package main.java.com.djrapitops.plan.command.commands.webuser;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.task.AbsRunnable;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.task.RunnableFactory;
import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.database.tables.SecurityTable;
import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg;
import main.java.com.djrapitops.plan.utilities.Check;
import main.java.com.djrapitops.plan.utilities.Condition;
import net.md_5.bungee.api.ChatColor;
/**
@ -25,7 +26,7 @@ public class WebDeleteCommand extends SubCommand {
public WebDeleteCommand(IPlan plugin) {
super("delete, remove",
CommandType.CONSOLE_WITH_ARGUMENTS,
CommandType.PLAYER_OR_ARGS,
Permissions.MANAGE_WEB.getPerm(),
Locale.get(Msg.CMD_USG_WEB_DELETE).toString(),
"<username>");
@ -34,17 +35,17 @@ public class WebDeleteCommand extends SubCommand {
@Override
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
if (!Check.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).parse() + " <username>", sender)) {
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).parse() + " <username>", sender)) {
return true;
}
SecurityTable table = plugin.getDB().getSecurityTable();
String user = args[0];
plugin.getRunnableFactory().createNew(new AbsRunnable("Webuser Delete Task: " + user) {
RunnableFactory.createNew(new AbsRunnable("Webuser Delete Task: " + user) {
@Override
public void run() {
try {
if (!Check.isTrue(table.userExists(user), ChatColor.RED + "[Plan] User Doesn't exist.", sender)) {
if (!Condition.isTrue(table.userExists(user), ChatColor.RED + "[Plan] User Doesn't exist.", sender)) {
return;
}
table.removeUser(user);

View File

@ -1,11 +1,12 @@
package main.java.com.djrapitops.plan.command.commands.webuser;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.settings.ColorScheme;
import com.djrapitops.plugin.task.AbsRunnable;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.task.RunnableFactory;
import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.data.WebUser;
@ -32,7 +33,7 @@ public class WebListUsersCommand extends SubCommand {
@Override
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
plugin.getRunnableFactory().createNew(new AbsRunnable("Webuser List Task") {
RunnableFactory.createNew(new AbsRunnable("Webuser List Task") {
@Override
public void run() {
try {

View File

@ -1,8 +1,8 @@
package main.java.com.djrapitops.plan.data;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.data.analysis.*;
import main.java.com.djrapitops.plan.utilities.Benchmark;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.html.HtmlUtils;

View File

@ -172,7 +172,7 @@ public class Session {
* Used to get the ID of the session in the Database.
*
* @return ID if present.
* @throws NullPointerException if Session was not fetched from DB. Check using {@code isFetchedFromDB}
* @throws NullPointerException if Session was not fetched from DB. Condition using {@code isFetchedFromDB}
*/
public int getSessionID() {
return sessionID;

View File

@ -1,7 +1,7 @@
package main.java.com.djrapitops.plan.data.additional;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.pluginbridge.plan.Bridge;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Plan;
import org.apache.commons.lang3.StringUtils;

View File

@ -1,8 +1,10 @@
package main.java.com.djrapitops.plan.data.additional;
import com.djrapitops.plugin.api.config.ConfigNode;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.Plan;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import java.io.IOException;
/**
* Class responsible for generating and generating settings for PluginData
@ -20,36 +22,37 @@ public class PluginConfigSectionHandler {
}
public boolean hasSection(PluginData dataSource) {
ConfigurationSection section = getPluginsSection();
ConfigNode section = getPluginsSection();
String pluginName = dataSource.getSourcePlugin();
if (!section.contains(pluginName)) {
if (!section.getChildren().containsKey(pluginName)) {
return false;
}
ConfigurationSection pluginSection = section.getConfigurationSection(pluginName);
return pluginSection.contains(dataSource.getPlaceholder());
ConfigNode pluginSection = section.getConfigNode(pluginName);
return pluginSection.getChildren().containsKey(dataSource.placeholder);
}
private ConfigurationSection getPluginsSection() {
FileConfiguration config = plan.getConfig();
return config.getConfigurationSection("Plugins");
private ConfigNode getPluginsSection() {
return plan.getMainConfig().getConfigNode("Plugins");
}
public void createSection(PluginData dataSource) {
ConfigurationSection section = getPluginsSection();
ConfigNode section = getPluginsSection();
String pluginName = dataSource.getSourcePlugin();
String source = dataSource.placeholder;
section.addDefault(pluginName + ".Enabled", true);
section.addDefault(pluginName + ".Data." + source, true);
FileConfiguration config = plan.getConfig();
config.set("Plugins", section);
plan.saveConfig();
section.set(pluginName + ".Enabled", true);
section.set(pluginName + ".Data." + source, true);
try {
section.sort();
section.save();
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
}
}
public boolean isEnabled(PluginData dataSource) {
ConfigurationSection section = getPluginsSection();
ConfigNode section = getPluginsSection();
String pluginName = dataSource.getSourcePlugin();
if (!section.getBoolean(pluginName + ".Enabled")) {

View File

@ -30,7 +30,7 @@ public abstract class RawData {
}
/**
* Check if analyseData() has been called.
* Condition if analyseData() has been called.
*
* @return true if the method has been called.
*/

View File

@ -57,7 +57,7 @@ public abstract class Database {
}
/**
* Check if the user is saved in the database.
* Condition if the user is saved in the database.
*
* @param uuid UUID of the user.
* @return true/false

View File

@ -1,15 +1,16 @@
package main.java.com.djrapitops.plan.database.databases;
import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.ITask;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.task.RunnableFactory;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.api.exceptions.DatabaseInitException;
import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.database.tables.*;
import main.java.com.djrapitops.plan.database.tables.move.Version8TransferTable;
import main.java.com.djrapitops.plan.utilities.Benchmark;
import org.apache.commons.dbcp2.BasicDataSource;
import java.sql.Connection;
@ -64,7 +65,7 @@ public abstract class SQLDB extends Database {
public void init() throws DatabaseInitException {
setStatus("Init");
String benchName = "Init " + getConfigName();
Benchmark.start(benchName);
Benchmark.start("Database", benchName);
try {
setupDataSource();
setupDatabase();
@ -77,7 +78,7 @@ public abstract class SQLDB extends Database {
}
public void scheduleClean(long secondsDelay) {
dbCleanTask = plugin.getRunnableFactory().createNew("DB Clean Task", new AbsRunnable() {
dbCleanTask = RunnableFactory.createNew("DB Clean Task", new AbsRunnable() {
@Override
public void run() {
try {
@ -116,7 +117,7 @@ public abstract class SQLDB extends Database {
final SQLDB db = this;
if (version < 10) {
plugin.getRunnableFactory().createNew("DB v8 -> v10 Task", new AbsRunnable() {
RunnableFactory.createNew("DB v8 -> v10 Task", new AbsRunnable() {
@Override
public void run() {
try {
@ -147,7 +148,7 @@ public abstract class SQLDB extends Database {
* Updates table columns to latest schema.
*/
private void createTables() throws DatabaseInitException {
Benchmark.start("Create tables");
Benchmark.start("Database", "Create tables");
for (Table table : getAllTables()) {
table.createTable();
}
@ -242,8 +243,8 @@ public abstract class SQLDB extends Database {
}
try {
Benchmark.start("Remove Account");
Log.debug("Database", "Removing Account: " + uuid);
Log.logDebug("Database", "Removing Account: " + uuid);
Benchmark.start("Database", "Remove Account");
for (Table t : getAllTablesInRemoveOrder()) {
if (!(t instanceof UserIDTable)) {
@ -278,7 +279,7 @@ public abstract class SQLDB extends Database {
}
private void setStatus(String status) {
Log.debug("Database", status);
Log.logDebug("Database", status);
}
public void setAvailable() {

View File

@ -1,8 +1,9 @@
package main.java.com.djrapitops.plan.database.databases;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.ITask;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.task.RunnableFactory;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.api.exceptions.DatabaseInitException;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
@ -85,7 +86,7 @@ public class SQLiteDB extends SQLDB {
stopConnectionPingTask();
// Maintains Connection.
connectionPingTask = plugin.getRunnableFactory().createNew(new AbsRunnable("DBConnectionPingTask " + getName()) {
connectionPingTask = RunnableFactory.createNew(new AbsRunnable("DBConnectionPingTask " + getName()) {
@Override
public void run() {
Statement statement = null;

View File

@ -74,7 +74,7 @@ public class ActionsTable extends UserIDTable {
.toString());
}
public void alterTableV12() throws SQLException {
public void alterTableV12() {
if (usingMySQL) {
executeUnsafe("ALTER TABLE " + tableName + " MODIFY " + columnAdditionalInfo + " VARCHAR(300)");
}

View File

@ -50,7 +50,7 @@ public class IPsTable extends UserIDTable {
);
}
public void alterTableV12() throws SQLException {
public void alterTableV12() {
if (usingMySQL) {
executeUnsafe("ALTER TABLE " + tableName + " MODIFY " + columnIP + " VARCHAR(39) NOT NULL");
}

View File

@ -78,10 +78,10 @@ public class ServerTable extends Table {
}
public void saveCurrentServerInfo(ServerInfo info) throws SQLException {
if (info.getId() == -1) {
saveNewServerInfo(info);
} else {
if (getServerID(info.getUuid()).isPresent()) {
updateServerInfo(info);
} else {
saveNewServerInfo(info);
}
}

View File

@ -184,7 +184,7 @@ public abstract class Table {
}
protected boolean execute(ExecStatement statement) throws SQLException {
boolean updatedSomething = false;
boolean updatedSomething;
Connection connection = null;
try {
connection = getConnection();

View File

@ -4,7 +4,7 @@
*/
package main.java.com.djrapitops.plan.database.tables.move;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.api.exceptions.DBCreateTableException;
import main.java.com.djrapitops.plan.data.UserInfo;
import main.java.com.djrapitops.plan.database.Database;

View File

@ -4,11 +4,11 @@
*/
package main.java.com.djrapitops.plan.database.tables.move;
import com.djrapitops.plugin.api.Benchmark;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.api.exceptions.DBCreateTableException;
import main.java.com.djrapitops.plan.database.databases.SQLDB;
import main.java.com.djrapitops.plan.database.tables.*;
import main.java.com.djrapitops.plan.utilities.Benchmark;
import java.sql.SQLException;
import java.util.Optional;

View File

@ -1,13 +1,13 @@
package main.java.com.djrapitops.plan.locale;
import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.settings.ColorScheme;
import com.djrapitops.plugin.settings.DefaultMessages;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.utilities.Benchmark;
import main.java.com.djrapitops.plan.utilities.comparators.LocaleEntryComparator;
import main.java.com.djrapitops.plan.utilities.comparators.StringLengthComparator;
import main.java.com.djrapitops.plan.utilities.file.FileUtil;
@ -97,7 +97,8 @@ public class Locale {
.map(entry -> getSpacedIdentifier(entry.getKey().getIdentifier(), length) + "|| " + entry.getValue().toString())
.collect(Collectors.toList());
Files.write(new File(plugin.getDataFolder(), "locale.txt").toPath(), lines, StandardCharsets.UTF_8);
plugin.getIConfig().getConfig().set(Settings.WRITE_NEW_LOCALE.getPath(), false);
plugin.getMainConfig().set(Settings.WRITE_NEW_LOCALE.getPath(), false);
plugin.getMainConfig().save();
}
private String getSpacedIdentifier(String identifier, int length) {
@ -150,7 +151,7 @@ public class Locale {
add(Msg.ANALYSIS_FETCH, analysis + "Fetching Data..");
add(Msg.ANALYSIS_PHASE_START, analysis + "Data Fetched (${0} users, took ${1}ms), beginning Analysis of data..");
add(Msg.ANALYSIS_3RD_PARTY, analysis + "Analyzing additional data sources (3rd party)");
add(Msg.ANALYSIS_FINISHED, analysis + "Analysis Complete. (took ${0}ms) ${1}");
add(Msg.ANALYSIS_FINISHED, analysis + "Analysis Complete. (took ${0} ms) ${1}");
add(Msg.ANALYSIS_FAIL_NO_PLAYERS, analysis + "Analysis failed, no known players.");
add(Msg.ANALYSIS_FAIL_NO_DATA, analysis + "Analysis failed, no data in the database.");
add(Msg.ANALYSIS_FAIL_FETCH_EXCEPTION, analysis + "Failed to fetch data for Analysis, Exception occurred.");

View File

@ -1,6 +1,6 @@
package main.java.com.djrapitops.plan.systems.cache;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.database.Database;
@ -114,7 +114,7 @@ public class DataCache extends SessionCache {
}
/**
* Check if a session is player's first session on the server.
* Condition if a session is player's first session on the server.
*
* @param uuid UUID of the player
* @return true / false

View File

@ -6,6 +6,7 @@ import com.maxmind.geoip2.DatabaseReader;
import com.maxmind.geoip2.exception.GeoIp2Exception;
import com.maxmind.geoip2.model.CountryResponse;
import com.maxmind.geoip2.record.Country;
import main.java.com.djrapitops.plan.api.exceptions.PlanEnableException;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import java.io.File;
@ -104,13 +105,12 @@ public class GeolocationCache {
/**
* Checks if the DB exists, if not, it downloads it
*
* @throws IOException when an error at download or saving the DB happens
* @throws PlanEnableException when an error at download or saving the DB happens
*/
public static void checkDB() throws IOException {
if (geolocationDB.exists()) {
return;
}
URL downloadSite = new URL("http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz");
try (ReadableByteChannel rbc = Channels.newChannel(new GZIPInputStream(downloadSite.openStream()));
FileOutputStream fos = new FileOutputStream(geolocationDB.getAbsoluteFile())) {

View File

@ -1,6 +1,6 @@
package main.java.com.djrapitops.plan.systems.cache;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.Session;
import main.java.com.djrapitops.plan.utilities.MiscUtils;

View File

@ -4,12 +4,10 @@
*/
package main.java.com.djrapitops.plan.systems.info;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.api.exceptions.ParseException;
import main.java.com.djrapitops.plan.api.exceptions.WebAPIConnectionFailException;
import main.java.com.djrapitops.plan.api.exceptions.WebAPIException;
import main.java.com.djrapitops.plan.api.exceptions.*;
import main.java.com.djrapitops.plan.command.commands.AnalyzeCommand;
import main.java.com.djrapitops.plan.data.AnalysisData;
import main.java.com.djrapitops.plan.data.additional.HookHandler;
@ -20,10 +18,7 @@ import main.java.com.djrapitops.plan.systems.info.parsing.InspectPageParser;
import main.java.com.djrapitops.plan.systems.processing.Processor;
import main.java.com.djrapitops.plan.systems.webserver.PageCache;
import main.java.com.djrapitops.plan.systems.webserver.WebServer;
import main.java.com.djrapitops.plan.systems.webserver.response.AnalysisPageResponse;
import main.java.com.djrapitops.plan.systems.webserver.response.InspectPageResponse;
import main.java.com.djrapitops.plan.systems.webserver.response.InternalErrorResponse;
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
import main.java.com.djrapitops.plan.systems.webserver.response.*;
import main.java.com.djrapitops.plan.systems.webserver.theme.Theme;
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPIManager;
import main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit.AnalysisReadyWebAPI;
@ -85,6 +80,8 @@ public class BukkitInformationManager extends InformationManager {
} else if (usingAnotherWebServer) {
try {
getWebAPI().getAPI(AnalyzeWebAPI.class).sendRequest(webServerAddress, serverUUID);
} catch (WebAPIFailException e) {
Log.error("Failed to request Analysis refresh from Bungee.");
} catch (WebAPIException e) {
attemptConnection();
refreshAnalysis(serverUUID);
@ -98,6 +95,8 @@ public class BukkitInformationManager extends InformationManager {
if (usingAnotherWebServer) {
try {
getWebAPI().getAPI(PostHtmlWebAPI.class).sendInspectHtml(webServerAddress, uuid, getPlayerHtml(uuid));
} catch (WebAPIFailException e) {
Log.error("Failed to request Inspect from Bungee.");
} catch (WebAPIException e) {
attemptConnection();
cachePlayer(uuid);
@ -121,6 +120,8 @@ public class BukkitInformationManager extends InformationManager {
if (usingAnotherWebServer && !origin.equals(RequestInspectPluginsTabBukkitWebAPI.class)) {
try {
getWebAPI().getAPI(RequestPluginsTabWebAPI.class).sendRequest(webServerAddress, uuid);
} catch (WebAPIFailException e) {
Log.error("Failed send Player Plugins tab contents to BungeeCord.");
} catch (WebAPIException e) {
attemptConnection();
cacheInspectPluginsTab(uuid, origin);
@ -139,6 +140,8 @@ public class BukkitInformationManager extends InformationManager {
if (usingAnotherWebServer) {
try {
getWebAPI().getAPI(PostInspectPluginsTabWebAPI.class).sendPluginsTab(webServerAddress, uuid, contents);
} catch (WebAPIFailException e) {
Log.error("Failed send Player HTML to BungeeCord.");
} catch (WebAPIException e) {
attemptConnection();
cacheInspectPluginsTab(uuid, contents);
@ -163,6 +166,8 @@ public class BukkitInformationManager extends InformationManager {
if (usingAnotherWebServer) {
try {
return getWebAPI().getAPI(IsCachedWebAPI.class).isInspectCached(webServerAddress, uuid);
} catch (WebAPIFailException e) {
Log.error("Failed check Bungee Player Cache status.");
} catch (WebAPIException e) {
attemptConnection();
return isCached(uuid);
@ -179,6 +184,8 @@ public class BukkitInformationManager extends InformationManager {
if (usingAnotherWebServer) {
try {
return getWebAPI().getAPI(IsCachedWebAPI.class).isAnalysisCached(webServerAddress, serverUUID);
} catch (WebAPIFailException e) {
Log.error("Failed check Bungee Analysis Cache status.");
} catch (WebAPIException e) {
attemptConnection();
return isAnalysisCached(serverUUID);
@ -200,7 +207,12 @@ public class BukkitInformationManager extends InformationManager {
@Override
public String getAnalysisHtml() {
if (analysisData == null) {
throw new NullPointerException("Analysis Data has not been cached.");
analysis.runAnalysis(this);
ErrorResponse analysisRefreshPage = new ErrorResponse();
analysisRefreshPage.setTitle("Analysis is being refreshed..");
analysisRefreshPage.setParagraph("<meta http-equiv=\"refresh\" content=\"25\" /><i class=\"fa fa-refresh fa-spin\" aria-hidden=\"true\"></i> Analysis is being run, refresh the page after a few seconds.. (F5)");
analysisRefreshPage.replacePlaceholders();
return analysisRefreshPage.getContent();
}
try {
return Theme.replaceColors(new AnalysisPageParser(analysisData, plugin).parse());
@ -233,6 +245,8 @@ public class BukkitInformationManager extends InformationManager {
getWebAPI().getAPI(AnalysisReadyWebAPI.class).sendRequest(webServerAddress, serverUUID);
updateNetworkPageContent();
return;
} catch (WebAPIFailException ignored) {
Log.error("Failed to notify Bungee of Analysis Completion.");
} catch (WebAPIException e) {
attemptConnection();
}
@ -248,9 +262,11 @@ public class BukkitInformationManager extends InformationManager {
if (usingAnotherWebServer) {
try {
getWebAPI().getAPI(PostHtmlWebAPI.class).sendAnalysisHtml(webServerAddress, html);
} catch (WebAPIFailException e) {
Log.error("Failed to send Analysis HTML to Bungee Server.");
} catch (WebAPIException e) {
attemptConnection();
cacheAnalysisHtml();
cacheAnalysisHtml(html);
}
} else {
PageCache.cachePage("analysisPage:" + Plan.getServerUUID(), () -> new AnalysisPageResponse(html));
@ -283,6 +299,8 @@ public class BukkitInformationManager extends InformationManager {
return true;
} catch (WebAPIConnectionFailException e) {
plugin.getServerInfoManager().markConnectionFail();
} catch (WebAPINotFoundException e) {
Log.info("Bungee reported that UUID of this server is not in the MySQL-database. Try using '/plan m setup " + webServerAddress + "' again");
} catch (WebAPIException e) {
Log.toLog(this.getClass().getName(), e);
}
@ -318,7 +336,11 @@ public class BukkitInformationManager extends InformationManager {
if (usingAnotherWebServer) {
try {
getWebAPI().getAPI(PostNetworkPageContentWebAPI.class).sendNetworkContent(webServerAddress, HtmlStructure.createServerContainer(plugin));
} catch (WebAPIFailException ignored) {
/* Do nothing */
} catch (WebAPIException ignored) {
attemptConnection();
updateNetworkPageContent();
}
}
}

View File

@ -4,7 +4,7 @@
*/
package main.java.com.djrapitops.plan.systems.info;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.PlanBungee;
import main.java.com.djrapitops.plan.api.exceptions.ParseException;
import main.java.com.djrapitops.plan.api.exceptions.WebAPIConnectionFailException;
@ -218,7 +218,7 @@ public class BungeeInformationManager extends InformationManager {
}
/**
* Check if analysis page for an UUID is cached.
* Condition if analysis page for an UUID is cached.
* <p>
* If serverUUID is that of Bungee, network page state is returned.
*

View File

@ -4,7 +4,8 @@
*/
package main.java.com.djrapitops.plan.systems.info.parsing;
import com.djrapitops.plugin.utilities.Compatibility;
import com.djrapitops.plugin.api.Check;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.PlanBungee;
import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.api.IPlan;
@ -15,7 +16,7 @@ import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.file.FileUtil;
import main.java.com.djrapitops.plan.utilities.html.HtmlUtils;
import java.io.FileNotFoundException;
import java.io.IOException;
/**
* Used for parsing a Html String out of AnalysisData and the html file.
@ -44,14 +45,14 @@ public class AnalysisPageParser extends PageParser {
addValue("playersOnline", getPlayersOnline());
try {
return HtmlUtils.replacePlaceholders(FileUtil.getStringFromResource("server.html"), placeHolders);
} catch (FileNotFoundException e) {
} catch (IOException e) {
throw new ParseException(e);
}
}
private int getPlayersOnline() {
if (Compatibility.isBukkitAvailable()) {
return plugin.fetch().getOnlinePlayers().size();
if (Check.isBukkitAvailable()) {
return ((Plan) plugin).getServer().getOnlinePlayers().size();
}
return ((PlanBungee) plugin).getProxy().getOnlineCount();
}

View File

@ -4,8 +4,9 @@
*/
package main.java.com.djrapitops.plan.systems.info.parsing;
import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.TimeAmount;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.api.exceptions.ParseException;
@ -17,7 +18,6 @@ import main.java.com.djrapitops.plan.data.time.WorldTimes;
import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.database.tables.SessionsTable;
import main.java.com.djrapitops.plan.database.tables.UsersTable;
import main.java.com.djrapitops.plan.utilities.Benchmark;
import main.java.com.djrapitops.plan.utilities.FormatUtils;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils;
@ -53,7 +53,7 @@ public class InspectPageParser extends PageParser {
public String parse() throws ParseException {
try {
// TODO Player is online parts
Log.debug("Database", "Inspect Parse Fetch");
Log.logDebug("Database", "Inspect Parse Fetch");
Benchmark.start("Inspect Parse, Fetch");
Database db = plugin.getDB();
SessionsTable sessionsTable = db.getSessionsTable();

View File

@ -1,65 +0,0 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package main.java.com.djrapitops.plan.systems.info.pluginchannel;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.Settings;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
/**
* //TODO Class Javadoc Comment
*
* @author Rsl1122
*/
public class BukkitPluginChannelListener implements PluginMessageListener {
private static String accessKey;
private final Plan plugin;
public BukkitPluginChannelListener(Plan plugin) {
this.plugin = plugin;
}
@Override
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
if (plugin.getInfoManager().isUsingAnotherWebServer() || Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.isTrue()) {
return;
}
try (DataInputStream in = new DataInputStream(new ByteArrayInputStream(message))) {
String subChannel = in.readUTF();
Log.debug("Received plugin message, channel: " + subChannel);
String[] data = in.readUTF().split("<!>");
String address = data[0];
accessKey = data[1];
if ("bungee_address".equals(subChannel)) {
plugin.getServerInfoManager().saveBungeeConnectionAddress(address);
Log.info("-----------------------------------");
Log.info("Received Bungee WebServer address through plugin channel, restarting Plan.");
Log.info("-----------------------------------");
plugin.restart();
notifyAll();
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static String getAccessKey() {
return accessKey;
}
public static void usedAccessKey() {
accessKey = null;
}
}

View File

@ -1,67 +0,0 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package main.java.com.djrapitops.plan.systems.info.pluginchannel;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.PlanBungee;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
import java.io.*;
/**
* //TODO Class Javadoc Comment
*
* @author Rsl1122
*/
public class BungeePluginChannelListener implements Listener {
private final PlanBungee plugin;
public BungeePluginChannelListener(PlanBungee plugin) {
this.plugin = plugin;
}
@EventHandler
public void onPluginMessage(PluginMessageEvent e) {
String tag = e.getTag();
Log.debug(tag);
if (!tag.equalsIgnoreCase("BungeeCord")) {
return;
}
try (DataInputStream in = new DataInputStream(new ByteArrayInputStream(e.getData()))) {
String channel = in.readUTF();
Log.debug("Received plugin channel message on channel: " + channel);
if ("bungee_address_get".equals(channel)) {
ServerInfo server = plugin.getProxy().getPlayer(e.getReceiver().toString()).getServer().getInfo();
sendToBukkit(server);
}
} catch (IOException e1) {
e1.printStackTrace();
}
}
private void sendToBukkit(ServerInfo server) {
Log.debug("Sending data to bukkit through plugin channel");
try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
String accessKey = plugin.getWebServer().getWebAPI().generateNewAccessKey();
try (DataOutputStream out = new DataOutputStream(stream)) {
out.writeUTF("Forward");
out.writeUTF(server.getName());
out.writeUTF("Plan");
out.writeUTF("bungee_address");
out.writeUTF(plugin.getWebServer().getAccessAddress() + "<!>" + accessKey);
}
server.sendData("Return", stream.toByteArray());
} catch (Exception e) {
Log.toLog(this.getClass().getName(), e);
}
}
}

View File

@ -5,7 +5,7 @@
package main.java.com.djrapitops.plan.systems.info.server;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.ServerVariableHolder;
import main.java.com.djrapitops.plan.Settings;
@ -134,21 +134,7 @@ public class BukkitServerInfoManager {
}
public void markConnectionFail() {
int timesFailed = serverInfoFile.markConnectionFail();
if (timesFailed == -1) {
return;
}
if (timesFailed >= 10) {
try {
serverInfoFile.saveInfo(serverInfo, new ServerInfo(-1, null, "Bungee", "", -1));
Log.info("----------------------------------");
Log.info("Bungee connection has failed 10 times in a row, assuming Bungee uninstalled - Restarting Plan..");
Log.info("----------------------------------");
plugin.restart();
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
}
}
serverInfoFile.markConnectionFail();
}
public void resetConnectionFails() {

View File

@ -5,8 +5,9 @@
package main.java.com.djrapitops.plan.systems.info.server;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.task.AbsRunnable;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.task.RunnableFactory;
import main.java.com.djrapitops.plan.PlanBungee;
import main.java.com.djrapitops.plan.ServerVariableHolder;
import main.java.com.djrapitops.plan.api.exceptions.PlanEnableException;
@ -35,7 +36,7 @@ public class BungeeServerInfoManager {
private final Set<UUID> onlineServers;
private ServerTable serverTable;
public BungeeServerInfoManager(PlanBungee plugin) throws PlanEnableException {
public BungeeServerInfoManager(PlanBungee plugin) {
this.plugin = plugin;
this.db = plugin.getDB();
serverTable = db.getServerTable();
@ -116,15 +117,17 @@ public class BungeeServerInfoManager {
}
public void sendConfigSettings(UUID serverUUID) {
String webAddress = null;
try {
ServerInfo server = bukkitServers.get(serverUUID);
if (server == null) {
return;
}
String webAddress = server.getWebAddress();
webAddress = server.getWebAddress();
Log.debug("Sending config settings to " + webAddress + "");
plugin.getWebServer().getWebAPI().getAPI(ConfigurationWebAPI.class).sendRequest(webAddress, serverUUID);
} catch (WebAPIException e) {
Log.info("Connection to Bukkit (" + webAddress + ") did not succeed.");
serverHasGoneOffline(serverUUID);
}
}
@ -135,32 +138,34 @@ public class BungeeServerInfoManager {
onlineServers.add(server.getUuid());
}
public void serverConnected(UUID serverUUID) {
public boolean serverConnected(UUID serverUUID) {
if (plugin.getServerUuid().equals(serverUUID)) {
return;
return false;
}
Log.info("Received a connection from a Bukkit server..");
if (onlineServers.contains(serverUUID)) {
sendConfigSettings(serverUUID);
return;
return true;
}
try {
Optional<ServerInfo> serverInfo = db.getServerTable().getServerInfo(serverUUID);
serverInfo.ifPresent(server -> {
Log.info("Server Info found from DB: " + server.getName());
plugin.getRunnableFactory().createNew("BukkitConnectionTask: " + server.getName(), new AbsRunnable() {
@Override
public void run() {
attemptConnection(server);
sendConfigSettings(serverUUID);
this.cancel();
}
}).runTaskLaterAsynchronously(TimeAmount.SECOND.ticks() * 3L);
if (serverInfo.isPresent()) {
ServerInfo server = serverInfo.get();
Log.info("Server Info found from DB: " + server.getName());
RunnableFactory.createNew("BukkitConnectionTask: " + server.getName(), new AbsRunnable() {
@Override
public void run() {
attemptConnection(server);
sendConfigSettings(serverUUID);
this.cancel();
}
);
}).runTaskLaterAsynchronously(TimeAmount.SECOND.ticks() * 3L);
return true;
}
} catch (SQLException e) {
Log.toLog(this.getClass().getName(), e);
}
return false;
}
public Collection<ServerInfo> getOnlineBukkitServers() {
@ -175,7 +180,6 @@ public class BungeeServerInfoManager {
}
public void serverHasGoneOffline(UUID serverUUID) {
Log.debug("Bukkit Server Marked Offline");
onlineServers.remove(serverUUID);
}
}

View File

@ -4,16 +4,14 @@
*/
package main.java.com.djrapitops.plan.systems.info.server;
import com.djrapitops.plugin.config.BukkitConfig;
import com.djrapitops.plugin.config.fileconfig.IFileConfig;
import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.utilities.file.FileUtil;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
@ -25,38 +23,28 @@ import java.util.UUID;
*
* @author Rsl1122
*/
public class ServerInfoFile extends BukkitConfig {
public class ServerInfoFile extends Config {
public ServerInfoFile(Plan plugin) throws IOException {
super(plugin, "ServerInfoFile.yml");
IFileConfig config = super.getConfig();
config.copyDefaults();
config.addDefault("Server.UUID", "");
config.addDefault("Bungee.WebAddress", "");
config.addDefault("Bungee.Fail", 0);
super(new File(plugin.getDataFolder(), "ServerInfoFile.yml"));
copyDefaults(FileUtil.lines(plugin, "DefaultServerInfoFile.yml"));
save();
}
public void saveInfo(ServerInfo thisServer, ServerInfo bungee) throws IOException {
IFileConfig config = getConfig();
Map<String, Serializable> serverMap = new HashMap<>();
Map<String, Serializable> bungeeMap = new HashMap<>();
set("Server.UUID", thisServer.getUuid().toString());
serverMap.put("UUID", thisServer.getUuid().toString());
config.set("Server", serverMap);
String oldAddress = config.getString("Bungee.WebAddress");
String oldAddress = getString("Bungee.WebAddress");
String newAddress = bungee.getWebAddress();
if (!newAddress.equals(oldAddress)) {
bungeeMap.put("Fail", 0);
bungeeMap.put("WebAddress", newAddress);
config.set("Bungee", bungeeMap);
set("Bungee.Fail", 0);
set("Bungee.WebAddress", newAddress);
}
save();
}
public Optional<UUID> getUUID() {
String uuidString = getConfig().getString("Server.UUID");
String uuidString = getString("Server.UUID");
if (Verify.isEmpty(uuidString)) {
return Optional.empty();
}
@ -64,14 +52,13 @@ public class ServerInfoFile extends BukkitConfig {
}
public String getBungeeWebAddress() {
return getConfig().getString("Bungee.WebAddress");
return getString("Bungee.WebAddress");
}
public int markConnectionFail() {
try {
IFileConfig config = getConfig();
int fails = config.getInt("Bungee.Fail");
config.set("Bungee.Fail", fails + 1);
int fails = getInt("Bungee.Fail");
set("Bungee.Fail", fails + 1);
save();
return fails;
} catch (IOException e) {
@ -82,8 +69,7 @@ public class ServerInfoFile extends BukkitConfig {
public void resetConnectionFails() {
try {
IFileConfig config = getConfig();
config.set("Bungee.Fail", 0);
set("Bungee.Fail", 0);
save();
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);

View File

@ -1,6 +1,6 @@
package main.java.com.djrapitops.plan.systems.listeners;
import com.djrapitops.plugin.utilities.player.Fetch;
import com.djrapitops.plugin.api.systems.NotificationCenter;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.Session;
import main.java.com.djrapitops.plan.systems.cache.DataCache;
@ -80,7 +80,7 @@ public class PlanPlayerListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
plugin.getNotificationCenter().checkNotifications(Fetch.wrapBukkit(player));
NotificationCenter.checkNotifications(player);
UUID uuid = player.getUniqueId();
long time = MiscUtils.getTime();

View File

@ -4,7 +4,7 @@
*/
package main.java.com.djrapitops.plan.systems.processing;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.Plan;
import java.sql.SQLException;

View File

@ -4,7 +4,7 @@
*/
package main.java.com.djrapitops.plan.systems.processing;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.Action;
import main.java.com.djrapitops.plan.database.tables.Actions;

View File

@ -4,7 +4,7 @@
*/
package main.java.com.djrapitops.plan.systems.processing;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.data.TPS;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;

View File

@ -4,10 +4,10 @@
*/
package main.java.com.djrapitops.plan.systems.processing.importing;
import com.djrapitops.plugin.utilities.player.UUIDFetcher;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.utility.UUIDFetcher;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.utilities.Benchmark;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;

View File

@ -4,9 +4,10 @@
*/
package main.java.com.djrapitops.plan.systems.processing.importing.importers;
import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.utilities.Verify;
import com.google.common.collect.ImmutableMap;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.Session;
import main.java.com.djrapitops.plan.data.UserInfo;
@ -16,7 +17,6 @@ import main.java.com.djrapitops.plan.systems.cache.GeolocationCache;
import main.java.com.djrapitops.plan.systems.processing.importing.ServerImportData;
import main.java.com.djrapitops.plan.systems.processing.importing.UserImportData;
import main.java.com.djrapitops.plan.systems.processing.importing.UserImportRefiner;
import main.java.com.djrapitops.plan.utilities.Benchmark;
import java.sql.SQLException;
import java.util.*;
@ -37,7 +37,7 @@ public abstract class Importer {
public abstract List<UserImportData> getUserImportData();
public final void processImport() throws SQLException {
public final void processImport() {
String benchmarkName = "Import processing";
String serverBenchmarkName = "Server Data processing";
String userDataBenchmarkName = "User Data processing";
@ -75,7 +75,7 @@ public abstract class Importer {
Benchmark.stop(benchmarkName);
}
private void processServerData() throws SQLException {
private void processServerData() {
String benchmarkName = "Processing Server Data";
String getDataBenchmarkName = "Getting Server Data";
String insertDataIntoDatabaseBenchmarkName = "Insert Server Data into Database";

View File

@ -4,7 +4,7 @@
*/
package main.java.com.djrapitops.plan.systems.processing.info;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.systems.processing.Processor;
import org.bukkit.entity.Player;

View File

@ -4,7 +4,7 @@
*/
package main.java.com.djrapitops.plan.systems.processing.player;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.Plan;
import java.sql.SQLException;

View File

@ -4,7 +4,7 @@
*/
package main.java.com.djrapitops.plan.systems.processing.player;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.PlanBungee;
import main.java.com.djrapitops.plan.database.tables.UsersTable;

View File

@ -4,7 +4,7 @@
*/
package main.java.com.djrapitops.plan.systems.processing.player;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.Action;
import main.java.com.djrapitops.plan.database.tables.Actions;

View File

@ -4,7 +4,7 @@
*/
package main.java.com.djrapitops.plan.systems.processing.player;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.systems.cache.GeolocationCache;

View File

@ -4,7 +4,7 @@
*/
package main.java.com.djrapitops.plan.systems.processing.player;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.Plan;
import java.sql.SQLException;

View File

@ -4,7 +4,7 @@
*/
package main.java.com.djrapitops.plan.systems.processing.player;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.database.tables.NicknamesTable;

View File

@ -4,7 +4,7 @@
*/
package main.java.com.djrapitops.plan.systems.processing.player;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.Action;
import main.java.com.djrapitops.plan.database.Database;

View File

@ -1,7 +1,6 @@
package main.java.com.djrapitops.plan.systems.queue;
import com.djrapitops.plugin.task.AbsRunnable;
import main.java.com.djrapitops.plan.Log;
import java.util.concurrent.BlockingQueue;
@ -35,7 +34,6 @@ public abstract class Consumer<T> extends AbsRunnable {
consume(queue.take());
}
} catch (InterruptedException ex) {
Log.error("Consumer interrupted: " + ex.getCause());
Thread.currentThread().interrupt();
}
}

View File

@ -1,8 +1,8 @@
package main.java.com.djrapitops.plan.systems.queue;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.systems.processing.Processor;
import main.java.com.djrapitops.plan.utilities.Benchmark;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

View File

@ -1,9 +1,6 @@
package main.java.com.djrapitops.plan.systems.queue;
import com.djrapitops.plugin.task.RunnableFactory;
import com.djrapitops.plugin.utilities.Compatibility;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.PlanBungee;
/**
* Abstract representation of a queue setup.
@ -27,7 +24,7 @@ public abstract class Setup<T> {
public void go() {
for (Consumer<T> consumer : consumers) {
getRunnableFactory().createNew(consumer).runTaskAsynchronously();
RunnableFactory.createNew(consumer).runTaskAsynchronously();
}
}
@ -36,12 +33,4 @@ public abstract class Setup<T> {
consumer.stop();
}
}
private RunnableFactory getRunnableFactory() {
if (Compatibility.isBukkitAvailable()) {
return Plan.getInstance().getRunnableFactory();
} else {
return PlanBungee.getInstance().getRunnableFactory();
}
}
}

View File

@ -1,9 +1,9 @@
package main.java.com.djrapitops.plan.systems.tasks;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.utilities.Compatibility;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.PlanBungee;
import main.java.com.djrapitops.plan.api.IPlan;
@ -38,7 +38,7 @@ public class TPSCountTimer extends AbsRunnable {
lastCheckNano = -1;
this.plugin = plugin;
history = new ArrayList<>();
usingBungee = Compatibility.isBungeeAvailable();
usingBungee = Check.isBungeeAvailable();
}
@Override

View File

@ -4,10 +4,11 @@
*/
package main.java.com.djrapitops.plan.systems.webserver;
import com.djrapitops.plugin.api.utility.log.Log;
import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPIManager;
@ -32,10 +33,15 @@ public class APIRequestHandler implements HttpHandler {
Request request = new Request(exchange);
try {
Response response = responseHandler.getAPIResponse(request);
if (Settings.DEV_MODE.isTrue()) {
Log.debug(request.toString(), response.toString());
}
response.setResponseHeaders(responseHeaders);
response.send(exchange);
} catch (Exception e) {
Log.toLog(this.getClass().getName(), e);
if (Settings.DEV_MODE.isTrue()) {
Log.toLog(this.getClass().getName(), e);
}
} finally {
exchange.close();
}

View File

@ -4,7 +4,7 @@
*/
package main.java.com.djrapitops.plan.systems.webserver;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.systems.webserver.response.*;
import main.java.com.djrapitops.plan.systems.webserver.response.api.BadRequestResponse;
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPI;

View File

@ -4,9 +4,11 @@
*/
package main.java.com.djrapitops.plan.systems.webserver;
import com.djrapitops.plugin.api.utility.log.Log;
import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.systems.webserver.response.PromptAuthorizationResponse;
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
@ -14,13 +16,12 @@ import main.java.com.djrapitops.plan.systems.webserver.response.Response;
import java.io.IOException;
/**
* HttpHandler for webserver request management.
* HttpHandler for WebServer request management.
*
* @author Rsl1122
*/
public class RequestHandler implements HttpHandler {
private final ResponseHandler responseHandler;
RequestHandler(IPlan plugin, WebServer webServer) {
@ -34,11 +35,18 @@ public class RequestHandler implements HttpHandler {
try {
Response response = responseHandler.getResponse(request);
if (Settings.DEV_MODE.isTrue()) {
Log.debug(request.toString(), response.toString());
}
if (response instanceof PromptAuthorizationResponse) {
responseHeaders.set("WWW-Authenticate", "Basic realm=\"/\";");
}
response.setResponseHeaders(responseHeaders);
response.send(exchange);
} catch (IOException e) {
if (Settings.DEV_MODE.isTrue()) {
Log.toLog(this.getClass().getName(), e);
}
} finally {
exchange.close();
}

View File

@ -4,7 +4,7 @@
*/
package main.java.com.djrapitops.plan.systems.webserver;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.api.exceptions.WebUserAuthException;
import main.java.com.djrapitops.plan.data.WebUser;
@ -115,7 +115,7 @@ public class ResponseHandler extends APIResponseHandler {
+ "This user has permission level of " + permLevel));
}
private boolean isAuthorized(int requiredPermLevel, int permLevel) throws Exception {
private boolean isAuthorized(int requiredPermLevel, int permLevel) {
return permLevel <= requiredPermLevel;
}

View File

@ -1,10 +1,11 @@
package main.java.com.djrapitops.plan.systems.webserver;
import com.djrapitops.plugin.StaticHolder;
import com.djrapitops.plugin.api.utility.log.Log;
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsParameters;
import com.sun.net.httpserver.HttpsServer;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.locale.Locale;
@ -48,6 +49,11 @@ public class WebServer {
this.port = Settings.WEBSERVER_PORT.getNumber();
webAPI = new WebAPIManager();
registerWebAPIs();
StaticHolder.saveInstance(APIRequestHandler.class, plugin.getClass());
StaticHolder.saveInstance(RequestHandler.class, plugin.getClass());
StaticHolder.saveInstance(ResponseHandler.class, plugin.getClass());
StaticHolder.saveInstance(APIResponseHandler.class, plugin.getClass());
}
private void registerWebAPIs() {

View File

@ -1,6 +1,7 @@
package main.java.com.djrapitops.plan.systems.webserver.response;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.AnalysisData;
import main.java.com.djrapitops.plan.systems.info.BukkitInformationManager;
@ -24,7 +25,7 @@ public class AnalysisPageResponse extends Response {
if (informationManager instanceof BukkitInformationManager) {
AnalysisData analysisData = ((BukkitInformationManager) informationManager).getAnalysisData();
if (analysisData == null) {
Plan.getInstance().getRunnableFactory().createNew("OnRequestAnalysisRefreshTask", new AbsRunnable() {
RunnableFactory.createNew("OnRequestAnalysisRefreshTask", new AbsRunnable() {
@Override
public void run() {
informationManager.refreshAnalysis(Plan.getServerUUID());

View File

@ -4,13 +4,13 @@
*/
package main.java.com.djrapitops.plan.systems.webserver.response;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.systems.webserver.theme.Theme;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.file.FileUtil;
import org.apache.commons.lang3.text.StrSubstitutor;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@ -27,7 +27,7 @@ public class ErrorResponse extends Response {
public ErrorResponse() {
try {
setContent(Theme.replaceColors(FileUtil.getStringFromResource("error.html")));
} catch (FileNotFoundException e) {
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
}
}

View File

@ -6,7 +6,7 @@ package main.java.com.djrapitops.plan.systems.webserver.response;
import main.java.com.djrapitops.plan.utilities.file.FileUtil;
import java.io.FileNotFoundException;
import java.io.IOException;
/**
* Response class for returning file contents.
@ -22,7 +22,7 @@ public class FileResponse extends Response {
super.setHeader("HTTP/1.1 200 OK");
try {
super.setContent(FileUtil.getStringFromResource(fileName));
} catch (FileNotFoundException e) {
} catch (IOException e) {
super.setContent(new NotFoundResponse(fileName + " was not found inside the .jar or /plugins/Plan/ folder").getContent());
}
}

View File

@ -1,6 +1,6 @@
package main.java.com.djrapitops.plan.systems.webserver.response;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.systems.webserver.theme.Theme;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
@ -8,7 +8,7 @@ import main.java.com.djrapitops.plan.utilities.file.FileUtil;
import main.java.com.djrapitops.plan.utilities.html.Html;
import org.apache.commons.lang3.text.StrSubstitutor;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.util.*;
@ -28,7 +28,7 @@ public class PlayersPageResponse extends Response {
replace.put("content", buildContent(names));
replace.put("version", plugin.getVersion());
super.setContent(Theme.replaceColors(StrSubstitutor.replace(FileUtil.getStringFromResource("players.html"), replace)));
} catch (SQLException | FileNotFoundException e) {
} catch (SQLException | IOException e) {
Log.toLog(this.getClass().getName(), e);
setContent(new InternalErrorResponse(e, "/players").getContent());
}

View File

@ -4,7 +4,7 @@
*/
package main.java.com.djrapitops.plan.systems.webserver.theme;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.Settings;
/**

View File

@ -4,7 +4,7 @@
*/
package main.java.com.djrapitops.plan.systems.webserver.theme;
import main.java.com.djrapitops.plan.Log;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.Settings;
/**

View File

@ -4,13 +4,11 @@
*/
package main.java.com.djrapitops.plan.systems.webserver.webapi;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.api.exceptions.WebAPIConnectionFailException;
import main.java.com.djrapitops.plan.api.exceptions.WebAPIException;
import main.java.com.djrapitops.plan.api.exceptions.WebAPIForbiddenException;
import main.java.com.djrapitops.plan.api.exceptions.WebAPINotFoundException;
import main.java.com.djrapitops.plan.api.exceptions.*;
import main.java.com.djrapitops.plan.systems.webserver.PageCache;
import main.java.com.djrapitops.plan.systems.webserver.response.NotFoundResponse;
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
@ -103,9 +101,6 @@ public abstract class WebAPI {
connection.setRequestProperty("Content-Length", Integer.toString(parameters.length()));
byte[] toSend = parameters.getBytes();
int length = toSend.length;
// connection.setRequestProperty("Content-Length", Integer.toString(length));
connection.setUseCaches(false);
Log.debug("Sending WebAPI Request: " + this.getClass().getSimpleName() + " to " + address);
@ -114,21 +109,27 @@ public abstract class WebAPI {
}
int responseCode = connection.getResponseCode();
Log.debug("Response: " + responseCode);
switch (responseCode) {
case 200:
return;
case 400:
throw new WebAPIException("Bad Request: " + url.toString() + "|" + parameters);
throw new WebAPIFailException("Bad Request: " + url.toString() + "|" + parameters);
case 403:
throw new WebAPIForbiddenException(url.toString());
case 404:
throw new WebAPINotFoundException();
case 500:
throw new WebAPIInternalErrorException();
default:
throw new WebAPIException(url.toString() + "| Wrong response code " + responseCode);
}
} catch (SocketTimeoutException e) {
throw new WebAPIConnectionFailException("Connection timed out after 10 seconds.", e);
} catch (NoSuchAlgorithmException | KeyManagementException | IOException e) {
if (Settings.DEV_MODE.isTrue()) {
Log.toLog(this.getClass().getName(), e);
}
throw new WebAPIConnectionFailException("API connection failed. address: " + address, e);
}
}

View File

@ -14,14 +14,13 @@ import java.util.*;
public class WebAPIManager {
private final Map<String, WebAPI> registry;
private final Set<String> accessKeys;
private static final Set<String> accessKeys = new HashSet<>();
/**
* Constructor used to hide the public constructor
*/
public WebAPIManager() {
registry = new HashMap<>();
accessKeys = new HashSet<>();
}
public void registerNewAPI(WebAPI... api) {

View File

@ -4,9 +4,13 @@
*/
package main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit;
import com.djrapitops.plugin.utilities.Compatibility;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.*;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.PlanBungee;
import main.java.com.djrapitops.plan.ServerSpecificSettings;
import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.api.exceptions.WebAPIException;
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
@ -23,12 +27,13 @@ public class ConfigurationWebAPI extends WebAPI {
@Override
public Response onRequest(IPlan plugin, Map<String, String> variables) {
if (!Compatibility.isBukkitAvailable()) {
if (!Check.isBukkitAvailable()) {
Log.debug("Called a wrong server type");
return badRequest("Called a Bungee Server");
}
if (Settings.BUNGEE_COPY_CONFIG.isFalse() || Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.isTrue()) {
Log.debug("Bungee Config settings overridden on this server.");
Log.info("Bungee Config settings overridden on this server.");
Log.debug(plugin.getMainConfig().getConfigNode("Plugin.Bungee-Override").getChildren().toString());
return success();
}
ServerSpecificSettings.updateSettings((Plan) plugin, variables);
@ -70,7 +75,7 @@ public class ConfigurationWebAPI extends WebAPI {
private Map<String, Object> getConfigValues(UUID serverUUID) throws WebAPIException {
Map<String, Object> configValues = new HashMap<>();
if (!Compatibility.isBungeeAvailable()) {
if (!Check.isBungeeAvailable()) {
throw new WebAPIException("Attempted to send config values from Bukkit to Bungee.");
}
addConfigValue(configValues, Settings.DB_TYPE, "mysql");

View File

@ -4,7 +4,7 @@
*/
package main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit;
import com.djrapitops.plugin.utilities.Compatibility;
import com.djrapitops.plugin.api.Check;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.api.exceptions.WebAPIException;
import main.java.com.djrapitops.plan.systems.info.BukkitInformationManager;
@ -29,7 +29,7 @@ public class RequestInspectPluginsTabBukkitWebAPI extends WebAPI {
@Override
public Response onRequest(IPlan plugin, Map<String, String> variables) {
if (!Compatibility.isBukkitAvailable()) {
if (!Check.isBukkitAvailable()) {
return badRequest("Called a Bungee Server");
}

Some files were not shown because too many files have changed in this diff Show More