diff --git a/Plan/src/main/java/com/djrapitops/plan/Plan.java b/Plan/src/main/java/com/djrapitops/plan/Plan.java
index 85d6905f4..2d8ade1ec 100644
--- a/Plan/src/main/java/com/djrapitops/plan/Plan.java
+++ b/Plan/src/main/java/com/djrapitops/plan/Plan.java
@@ -21,24 +21,77 @@ package com.djrapitops.plan;
import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.command.PlanCommand;
-import com.djrapitops.plan.system.BukkitSystem;
+import com.djrapitops.plan.modules.APFModule;
+import com.djrapitops.plan.modules.FilesModule;
+import com.djrapitops.plan.modules.SuperClassBindingModule;
+import com.djrapitops.plan.modules.SystemObjectBindingModule;
+import com.djrapitops.plan.modules.server.ServerSuperClassBindingModule;
+import com.djrapitops.plan.modules.server.bukkit.BukkitServerPropertiesModule;
+import com.djrapitops.plan.modules.server.bukkit.BukkitSuperClassBindingModule;
+import com.djrapitops.plan.system.PlanSystem;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.PluginLang;
-import com.djrapitops.plan.system.processing.importing.ImporterManager;
-import com.djrapitops.plan.system.processing.importing.importers.OfflinePlayerImporter;
import com.djrapitops.plan.system.settings.theme.PlanColorScheme;
import com.djrapitops.plan.utilities.metrics.BStatsBukkit;
import com.djrapitops.plugin.BukkitPlugin;
-import com.djrapitops.plugin.StaticHolder;
-import com.djrapitops.plugin.api.Benchmark;
-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.benchmarking.Benchmark;
+import com.djrapitops.plugin.command.ColorScheme;
+import com.djrapitops.plugin.command.CommandNode;
+import dagger.BindsInstance;
+import dagger.Component;
+import dagger.Module;
+import dagger.Provides;
import org.bukkit.configuration.file.FileConfiguration;
+import javax.inject.Named;
+import javax.inject.Singleton;
import java.util.logging.Level;
import java.util.logging.Logger;
+@Singleton
+@Component(modules = {
+ BukkitPlanModule.class,
+ SuperClassBindingModule.class,
+ SystemObjectBindingModule.class,
+ APFModule.class,
+ FilesModule.class,
+ BukkitServerPropertiesModule.class,
+ ServerSuperClassBindingModule.class,
+ BukkitSuperClassBindingModule.class
+})
+interface PlanComponent {
+
+ PlanCommand planCommand();
+
+ PlanSystem system();
+
+ @Component.Builder
+ interface Builder {
+
+ @BindsInstance
+ Builder plan(Plan plan);
+
+ PlanComponent build();
+ }
+}
+
+@Module
+class BukkitPlanModule {
+
+ @Provides
+ @Singleton
+ PlanPlugin providePlanPlugin(Plan plugin) {
+ return plugin;
+ }
+
+ @Provides
+ @Singleton
+ @Named("mainCommand")
+ CommandNode provideMainCommand(PlanCommand command) {
+ return command;
+ }
+}
+
/**
* Main class for Bukkit that manages the plugin.
*
@@ -47,55 +100,45 @@ import java.util.logging.Logger;
*/
public class Plan extends BukkitPlugin implements PlanPlugin {
- private BukkitSystem system;
+ private PlanSystem system;
private Locale locale;
- /**
- * Used to get the plugin-instance singleton.
- *
- * @return this object.
- */
- public static Plan getInstance() {
- return (Plan) StaticHolder.getInstance(Plan.class);
- }
-
@Override
public void onEnable() {
- super.onEnable();
+ PlanComponent component = DaggerPlanComponent.builder().plan(this).build();
try {
- Benchmark.start("Enable");
- system = new BukkitSystem(this);
+ timings.start("Enable");
+ system = component.system();
locale = system.getLocaleSystem().getLocale();
system.enable();
- ImporterManager.registerImporter(new OfflinePlayerImporter());
-
new BStatsBukkit(this).registerMetrics();
- Log.debug("Verbose debug messages are enabled.");
- Benchmark.stop("Enable", "Enable");
- Log.logDebug("Enable");
- Log.info(locale.getString(PluginLang.ENABLED));
+ logger.debug("Verbose debug messages are enabled.");
+ String benchTime = " (" + timings.end("Enable").map(Benchmark::toDurationString).orElse("-") + ")";
+ logger.info(locale.getString(PluginLang.ENABLED) + benchTime);
} catch (AbstractMethodError e) {
- Log.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart.");
+ logger.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart.");
} catch (EnableException e) {
- Log.error("----------------------------------------");
- Log.error("Error: " + e.getMessage());
- Log.error("----------------------------------------");
- Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
+ logger.error("----------------------------------------");
+ logger.error("Error: " + e.getMessage());
+ logger.error("----------------------------------------");
+ logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
onDisable();
} catch (Exception e) {
Logger.getGlobal().log(Level.SEVERE, this.getClass().getSimpleName() + "-v" + getVersion(), e);
- Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
- Log.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
+ logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
+ logger.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
onDisable();
}
- registerCommand("plan", new PlanCommand(this));
+ PlanCommand command = component.planCommand();
+ command.registerCommands();
+ registerCommand("plan", command);
}
@Override
public ColorScheme getColorScheme() {
- return PlanColorScheme.create();
+ return PlanColorScheme.create(system.getConfigSystem().getConfig(), logger);
}
/**
@@ -103,11 +146,11 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
*/
@Override
public void onDisable() {
- system.disable();
+ if (system != null) {
+ system.disable();
+ }
- Log.info(locale.getString(PluginLang.DISABLED));
- Benchmark.pluginDisabled(Plan.class);
- DebugLog.pluginDisabled(Plan.class);
+ logger.info(locale != null ? locale.getString(PluginLang.DISABLED) : PluginLang.DISABLED.getDefault());
}
@Override
@@ -162,7 +205,7 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
}
@Override
- public BukkitSystem getSystem() {
+ public PlanSystem getSystem() {
return system;
}
-}
+}
\ No newline at end of file
diff --git a/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java b/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java
index fa17df538..7154c0066 100644
--- a/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java
+++ b/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java
@@ -6,21 +6,74 @@ package com.djrapitops.plan;
import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.command.PlanBungeeCommand;
-import com.djrapitops.plan.system.BungeeSystem;
+import com.djrapitops.plan.modules.APFModule;
+import com.djrapitops.plan.modules.FilesModule;
+import com.djrapitops.plan.modules.SuperClassBindingModule;
+import com.djrapitops.plan.modules.SystemObjectBindingModule;
+import com.djrapitops.plan.modules.proxy.ProxySuperClassBindingModule;
+import com.djrapitops.plan.modules.proxy.bungee.BungeeServerPropertiesModule;
+import com.djrapitops.plan.modules.proxy.bungee.BungeeSuperClassBindingModule;
+import com.djrapitops.plan.system.PlanSystem;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.PluginLang;
import com.djrapitops.plan.system.settings.theme.PlanColorScheme;
import com.djrapitops.plan.utilities.metrics.BStatsBungee;
import com.djrapitops.plugin.BungeePlugin;
-import com.djrapitops.plugin.StaticHolder;
-import com.djrapitops.plugin.api.Benchmark;
-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.command.ColorScheme;
+import com.djrapitops.plugin.command.CommandNode;
+import com.djrapitops.plugin.logging.L;
+import dagger.BindsInstance;
+import dagger.Component;
+import dagger.Module;
+import dagger.Provides;
+import javax.inject.Named;
+import javax.inject.Singleton;
import java.io.InputStream;
-import java.util.logging.Level;
-import java.util.logging.Logger;
+
+@Singleton
+@Component(modules = {
+ BungeePlanModule.class,
+ SuperClassBindingModule.class,
+ SystemObjectBindingModule.class,
+ APFModule.class,
+ FilesModule.class,
+ ProxySuperClassBindingModule.class,
+ BungeeSuperClassBindingModule.class,
+ BungeeServerPropertiesModule.class
+})
+interface PlanBungeeComponent {
+
+ PlanBungeeCommand planCommand();
+
+ PlanSystem system();
+
+ @Component.Builder
+ interface Builder {
+
+ @BindsInstance
+ Builder plan(PlanBungee plan);
+
+ PlanBungeeComponent build();
+ }
+}
+
+@Module
+class BungeePlanModule {
+
+ @Provides
+ @Singleton
+ PlanPlugin providePlanPlugin(PlanBungee plugin) {
+ return plugin;
+ }
+
+ @Provides
+ @Singleton
+ @Named("mainCommand")
+ CommandNode provideMainCommand(PlanBungeeCommand command) {
+ return command;
+ }
+}
/**
* Bungee Main class.
@@ -29,48 +82,48 @@ import java.util.logging.Logger;
*/
public class PlanBungee extends BungeePlugin implements PlanPlugin {
- private BungeeSystem system;
+ private PlanSystem system;
private Locale locale;
- public static PlanBungee getInstance() {
- return (PlanBungee) StaticHolder.getInstance(PlanBungee.class);
- }
-
@Override
public void onEnable() {
- super.onEnable();
+ PlanBungeeComponent component = DaggerPlanBungeeComponent.builder().plan(this).build();
try {
- system = new BungeeSystem(this);
+ system = component.system();
locale = system.getLocaleSystem().getLocale();
system.enable();
- new BStatsBungee(this).registerMetrics();
+ new BStatsBungee(
+ this,
+ system.getDatabaseSystem().getActiveDatabase(),
+ system.getInfoSystem().getConnectionSystem()
+ ).registerMetrics();
- Log.info(locale.getString(PluginLang.ENABLED));
+ logger.info(locale.getString(PluginLang.ENABLED));
} catch (AbstractMethodError e) {
- Log.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart.");
+ logger.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart.");
} catch (EnableException e) {
- Log.error("----------------------------------------");
- Log.error("Error: " + e.getMessage());
- Log.error("----------------------------------------");
- Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planbungee reload");
+ logger.error("----------------------------------------");
+ logger.error("Error: " + e.getMessage());
+ logger.error("----------------------------------------");
+ logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planbungee reload");
onDisable();
} catch (Exception e) {
- Logger.getGlobal().log(Level.SEVERE, this.getClass().getSimpleName() + "-v" + getVersion(), e);
- Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planbungee reload");
- Log.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
+ errorHandler.log(L.CRITICAL, this.getClass(), e);
+ logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planbungee reload");
+ logger.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
onDisable();
}
- registerCommand("planbungee", new PlanBungeeCommand(this));
+ PlanBungeeCommand command = component.planCommand();
+ command.registerCommands();
+ registerCommand("planbungee", command);
}
@Override
public void onDisable() {
system.disable();
- Log.info(locale.getString(PluginLang.DISABLED));
- Benchmark.pluginDisabled(PlanBungee.class);
- DebugLog.pluginDisabled(PlanBungee.class);
+ logger.info(locale.getString(PluginLang.DISABLED));
}
@Override
@@ -90,11 +143,11 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
@Override
public ColorScheme getColorScheme() {
- return PlanColorScheme.create();
+ return PlanColorScheme.create(system.getConfigSystem().getConfig(), logger);
}
@Override
- public BungeeSystem getSystem() {
+ public PlanSystem getSystem() {
return system;
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/PlanPlugin.java b/Plan/src/main/java/com/djrapitops/plan/PlanPlugin.java
index c4d263d3e..4159cbedf 100644
--- a/Plan/src/main/java/com/djrapitops/plan/PlanPlugin.java
+++ b/Plan/src/main/java/com/djrapitops/plan/PlanPlugin.java
@@ -6,8 +6,7 @@ package com.djrapitops.plan;
import com.djrapitops.plan.system.PlanSystem;
import com.djrapitops.plugin.IPlugin;
-import com.djrapitops.plugin.api.Check;
-import com.djrapitops.plugin.settings.ColorScheme;
+import com.djrapitops.plugin.command.ColorScheme;
import java.io.File;
import java.io.InputStream;
@@ -18,39 +17,6 @@ import java.io.InputStream;
* @author Rsl1122
*/
public interface PlanPlugin extends IPlugin {
- static PlanPlugin getInstance() {
- boolean bukkitAvailable = Check.isBukkitAvailable();
- boolean bungeeAvailable = Check.isBungeeAvailable();
- boolean spongeAvailable = Check.isSpongeAvailable();
- if (bukkitAvailable) {
- try {
- Plan instance = Plan.getInstance();
- if (instance != null) {
- return instance;
- }
- } catch (IllegalStateException ignored) {
- }
- }
- if (bungeeAvailable) {
- try {
- PlanBungee instance = PlanBungee.getInstance();
- if (instance != null) {
- return instance;
- }
- } catch (IllegalStateException ignored) {
- }
- }
- if (spongeAvailable) {
- try {
- PlanSponge instance = PlanSponge.getInstance();
- if (instance != null) {
- return instance;
- }
- } catch (IllegalStateException ignored) {
- }
- }
- throw new IllegalAccessError("Plugin instance not available");
- }
@Override
File getDataFolder();
diff --git a/Plan/src/main/java/com/djrapitops/plan/PlanSponge.java b/Plan/src/main/java/com/djrapitops/plan/PlanSponge.java
index 858ed6b6c..7c47dd4ec 100644
--- a/Plan/src/main/java/com/djrapitops/plan/PlanSponge.java
+++ b/Plan/src/main/java/com/djrapitops/plan/PlanSponge.java
@@ -2,18 +2,26 @@ package com.djrapitops.plan;
import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.command.PlanCommand;
-import com.djrapitops.plan.system.SpongeSystem;
+import com.djrapitops.plan.modules.APFModule;
+import com.djrapitops.plan.modules.FilesModule;
+import com.djrapitops.plan.modules.SuperClassBindingModule;
+import com.djrapitops.plan.modules.SystemObjectBindingModule;
+import com.djrapitops.plan.modules.server.ServerSuperClassBindingModule;
+import com.djrapitops.plan.modules.server.sponge.SpongeServerPropertiesModule;
+import com.djrapitops.plan.modules.server.sponge.SpongeSuperClassBindingModule;
+import com.djrapitops.plan.system.PlanSystem;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.PluginLang;
import com.djrapitops.plan.system.settings.theme.PlanColorScheme;
import com.djrapitops.plan.utilities.metrics.BStatsSponge;
import com.djrapitops.plugin.SpongePlugin;
-import com.djrapitops.plugin.StaticHolder;
-import com.djrapitops.plugin.api.Benchmark;
-import com.djrapitops.plugin.api.utility.log.DebugLog;
-import com.djrapitops.plugin.api.utility.log.Log;
-import com.djrapitops.plugin.settings.ColorScheme;
-import com.google.inject.Inject;
+import com.djrapitops.plugin.command.ColorScheme;
+import com.djrapitops.plugin.command.CommandNode;
+import com.djrapitops.plugin.logging.L;
+import dagger.BindsInstance;
+import dagger.Component;
+import dagger.Module;
+import dagger.Provides;
import org.bstats.sponge.Metrics;
import org.slf4j.Logger;
import org.spongepowered.api.config.ConfigDir;
@@ -23,9 +31,55 @@ import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
import org.spongepowered.api.plugin.Dependency;
import org.spongepowered.api.plugin.Plugin;
+import javax.inject.Named;
+import javax.inject.Singleton;
import java.io.File;
import java.io.InputStream;
+@Singleton
+@Component(modules = {
+ SpongePlanModule.class,
+ SuperClassBindingModule.class,
+ SystemObjectBindingModule.class,
+ APFModule.class,
+ FilesModule.class,
+ ServerSuperClassBindingModule.class,
+ SpongeSuperClassBindingModule.class,
+ SpongeServerPropertiesModule.class
+})
+interface PlanSpongeComponent {
+
+ PlanCommand planCommand();
+
+ PlanSystem system();
+
+ @Component.Builder
+ interface Builder {
+
+ @BindsInstance
+ Builder plan(PlanSponge plan);
+
+ PlanSpongeComponent build();
+ }
+}
+
+@Module
+class SpongePlanModule {
+
+ @Provides
+ @Singleton
+ PlanPlugin providePlanPlugin(PlanSponge plugin) {
+ return plugin;
+ }
+
+ @Provides
+ @Singleton
+ @Named("mainCommand")
+ CommandNode provideMainCommand(PlanCommand command) {
+ return command;
+ }
+}
+
@Plugin(
id = "plan",
name = "Plan",
@@ -39,16 +93,16 @@ import java.io.InputStream;
)
public class PlanSponge extends SpongePlugin implements PlanPlugin {
- @Inject
+ @com.google.inject.Inject
private Metrics metrics;
- @Inject
- private Logger logger;
+ @com.google.inject.Inject
+ private Logger slf4jLogger;
- @Inject
+ @com.google.inject.Inject
@ConfigDir(sharedRoot = false)
private File dataFolder;
- private SpongeSystem system;
+ private PlanSystem system;
private Locale locale;
@Listener
@@ -61,36 +115,37 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
onDisable();
}
- public static PlanSponge getInstance() {
- return (PlanSponge) StaticHolder.getInstance(PlanSponge.class);
- }
-
@Override
public void onEnable() {
- super.onEnable();
+ PlanSpongeComponent component = DaggerPlanSpongeComponent.builder().plan(this).build();
try {
- system = new SpongeSystem(this);
+ system = component.system();
locale = system.getLocaleSystem().getLocale();
system.enable();
- new BStatsSponge(metrics).registerMetrics();
+ new BStatsSponge(
+ metrics,
+ system.getDatabaseSystem().getActiveDatabase()
+ ).registerMetrics();
- Log.info(locale.getString(PluginLang.ENABLED));
+ slf4jLogger.info(locale.getString(PluginLang.ENABLED));
} catch (AbstractMethodError e) {
- Log.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart.");
+ slf4jLogger.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart.");
} catch (EnableException e) {
- Log.error("----------------------------------------");
- Log.error("Error: " + e.getMessage());
- Log.error("----------------------------------------");
- Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
+ slf4jLogger.error("----------------------------------------");
+ slf4jLogger.error("Error: " + e.getMessage());
+ slf4jLogger.error("----------------------------------------");
+ slf4jLogger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
onDisable();
} catch (Exception e) {
- Log.toLog(this.getClass().getSimpleName() + "-v" + getVersion(), e);
- Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
- Log.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
+ errorHandler.log(L.CRITICAL, this.getClass(), e);
+ slf4jLogger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
+ slf4jLogger.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
onDisable();
}
- registerCommand("plan", new PlanCommand(this));
+ PlanCommand command = component.planCommand();
+ command.registerCommands();
+ registerCommand("plan", command);
}
@Override
@@ -99,9 +154,7 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
system.disable();
}
- Log.info(locale.getString(PluginLang.DISABLED));
- Benchmark.pluginDisabled(PlanSponge.class);
- DebugLog.pluginDisabled(PlanSponge.class);
+ logger.info(locale.getString(PluginLang.DISABLED));
}
@Override
@@ -111,7 +164,7 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
@Override
public ColorScheme getColorScheme() {
- return PlanColorScheme.create();
+ return PlanColorScheme.create(system.getConfigSystem().getConfig(), logger);
}
@Override
@@ -126,7 +179,7 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
@Override
public Logger getLogger() {
- return logger;
+ return slf4jLogger;
}
@Override
@@ -140,7 +193,7 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
}
@Override
- public SpongeSystem getSystem() {
+ public PlanSystem getSystem() {
return system;
}
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/PlanVelocity.java b/Plan/src/main/java/com/djrapitops/plan/PlanVelocity.java
index 7a9804902..1593a1a7b 100644
--- a/Plan/src/main/java/com/djrapitops/plan/PlanVelocity.java
+++ b/Plan/src/main/java/com/djrapitops/plan/PlanVelocity.java
@@ -6,29 +6,83 @@ package com.djrapitops.plan;
import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.command.PlanVelocityCommand;
-import com.djrapitops.plan.system.VelocitySystem;
+import com.djrapitops.plan.modules.APFModule;
+import com.djrapitops.plan.modules.FilesModule;
+import com.djrapitops.plan.modules.SuperClassBindingModule;
+import com.djrapitops.plan.modules.SystemObjectBindingModule;
+import com.djrapitops.plan.modules.proxy.ProxySuperClassBindingModule;
+import com.djrapitops.plan.modules.proxy.velocity.VelocityServerPropertiesModule;
+import com.djrapitops.plan.modules.proxy.velocity.VelocitySuperClassBindingModule;
+import com.djrapitops.plan.system.PlanSystem;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.PluginLang;
import com.djrapitops.plan.system.settings.theme.PlanColorScheme;
-import com.djrapitops.plugin.StaticHolder;
import com.djrapitops.plugin.VelocityPlugin;
-import com.djrapitops.plugin.api.Benchmark;
-import com.djrapitops.plugin.api.utility.log.DebugLog;
-import com.djrapitops.plugin.api.utility.log.Log;
-import com.djrapitops.plugin.settings.ColorScheme;
-import com.google.inject.Inject;
+import com.djrapitops.plugin.command.ColorScheme;
+import com.djrapitops.plugin.command.CommandNode;
+import com.djrapitops.plugin.logging.L;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
+import dagger.BindsInstance;
+import dagger.Component;
+import dagger.Module;
+import dagger.Provides;
import org.slf4j.Logger;
+import javax.inject.Named;
+import javax.inject.Singleton;
import java.io.File;
import java.io.InputStream;
import java.nio.file.Path;
+@Singleton
+@Component(modules = {
+ VelocityPlanModule.class,
+ SuperClassBindingModule.class,
+ SystemObjectBindingModule.class,
+ APFModule.class,
+ FilesModule.class,
+ ProxySuperClassBindingModule.class,
+ VelocitySuperClassBindingModule.class,
+ VelocityServerPropertiesModule.class
+})
+interface PlanVelocityComponent {
+
+ PlanVelocityCommand planCommand();
+
+ PlanSystem system();
+
+ @Component.Builder
+ interface Builder {
+
+ @BindsInstance
+ Builder plan(PlanVelocity plan);
+
+ PlanVelocityComponent build();
+ }
+}
+
+@Module
+class VelocityPlanModule {
+
+ @Provides
+ @Singleton
+ PlanPlugin providePlanPlugin(PlanVelocity plugin) {
+ return plugin;
+ }
+
+ @Provides
+ @Singleton
+ @Named("mainCommand")
+ CommandNode provideMainCommand(PlanVelocityCommand command) {
+ return command;
+ }
+}
+
/**
* Velocity Main class.
- *
+ *
* Based on the PlanBungee class
*
* @author MicleBrick
@@ -36,16 +90,16 @@ import java.nio.file.Path;
@Plugin(id = "plan", name = "Plan", version = "4.4.6", description = "Player Analytics Plugin by Rsl1122", authors = {"Rsl1122"})
public class PlanVelocity extends VelocityPlugin implements PlanPlugin {
- private VelocitySystem system;
+ private PlanSystem system;
private Locale locale;
- public static PlanVelocity getInstance() {
- return (PlanVelocity) StaticHolder.getInstance(PlanVelocity.class);
- }
-
- @Inject
+ @com.google.inject.Inject
@DataDirectory
private Path dataFolderPath;
+ @com.google.inject.Inject
+ private ProxyServer proxy;
+ @com.google.inject.Inject
+ private Logger slf4jLogger;
@Override
public File getDataFolder() {
@@ -54,45 +108,39 @@ public class PlanVelocity extends VelocityPlugin implements PlanPlugin {
@Override
public void onEnable() {
- super.onEnable();
+ PlanVelocityComponent component = DaggerPlanVelocityComponent.builder().plan(this).build();
try {
- system = new VelocitySystem(this);
+ system = component.system();
locale = system.getLocaleSystem().getLocale();
system.enable();
- Log.info(locale.getString(PluginLang.ENABLED));
+ logger.info(locale.getString(PluginLang.ENABLED));
} catch (AbstractMethodError e) {
- Log.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart.");
+ logger.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart.");
} catch (EnableException e) {
- Log.error("----------------------------------------");
- Log.error("Error: " + e.getMessage());
- Log.error("----------------------------------------");
- Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planvelocity reload");
+ logger.error("----------------------------------------");
+ logger.error("Error: " + e.getMessage());
+ logger.error("----------------------------------------");
+ logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planbungee reload");
onDisable();
} catch (Exception e) {
- getLogger().error(this.getClass().getSimpleName() + "-v" + getVersion(), e);
- Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planvelocity reload");
- Log.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
+ errorHandler.log(L.CRITICAL, this.getClass(), e);
+ logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planbungee reload");
+ logger.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
onDisable();
}
- registerCommand("planvelocity", new PlanVelocityCommand(this));
+ PlanVelocityCommand command = component.planCommand();
+ command.registerCommands();
+ registerCommand("planvelocity", command);
}
@Override
public void onDisable() {
system.disable();
- Log.info(locale.getString(PluginLang.DISABLED));
- Benchmark.pluginDisabled(PlanVelocity.class);
- DebugLog.pluginDisabled(PlanVelocity.class);
+ slf4jLogger.info(locale.getString(PluginLang.DISABLED));
}
- @Override
- public String getVersion() {
- return getClass().getAnnotation(Plugin.class).version();
- }
-
-
@Override
public void onReload() {
// Nothing to be done, systems are disabled
@@ -105,11 +153,11 @@ public class PlanVelocity extends VelocityPlugin implements PlanPlugin {
@Override
public ColorScheme getColorScheme() {
- return PlanColorScheme.create();
+ return PlanColorScheme.create(system.getConfigSystem().getConfig(), logger);
}
@Override
- public VelocitySystem getSystem() {
+ public PlanSystem getSystem() {
return system;
}
@@ -118,19 +166,13 @@ public class PlanVelocity extends VelocityPlugin implements PlanPlugin {
return reloading;
}
- @Inject
- private ProxyServer proxy;
-
@Override
public ProxyServer getProxy() {
return proxy;
}
- @Inject
- private Logger logger;
-
@Override
protected Logger getLogger() {
- return logger;
+ return slf4jLogger;
}
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/ShutdownHook.java b/Plan/src/main/java/com/djrapitops/plan/ShutdownHook.java
index 2a8a7adff..b7f66c131 100644
--- a/Plan/src/main/java/com/djrapitops/plan/ShutdownHook.java
+++ b/Plan/src/main/java/com/djrapitops/plan/ShutdownHook.java
@@ -11,8 +11,10 @@ import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.data.store.keys.SessionKeys;
import com.djrapitops.plan.system.cache.SessionCache;
import com.djrapitops.plan.system.database.databases.Database;
-import com.djrapitops.plugin.api.utility.log.Log;
+import com.djrapitops.plugin.logging.L;
+import com.djrapitops.plugin.logging.error.ErrorHandler;
+import javax.inject.Inject;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
@@ -26,50 +28,57 @@ import java.util.UUID;
*/
public class ShutdownHook extends Thread {
- private static boolean activated = false;
+ private static ShutdownHook activated;
+ private final Database database;
+ private final ErrorHandler errorHandler;
+
+ @Inject
+ public ShutdownHook(Database database, ErrorHandler errorHandler) {
+ this.database = database;
+ this.errorHandler = errorHandler;
+ }
private static boolean isActivated() {
- return activated;
+ return activated != null;
}
private static void activate(ShutdownHook hook) {
- activated = true;
+ activated = hook;
Runtime.getRuntime().addShutdownHook(hook);
}
+ private static void deactivate() {
+ Runtime.getRuntime().removeShutdownHook(activated);
+ activated = null;
+ }
+
public void register() {
if (isActivated()) {
- return;
+ deactivate();
}
activate(this);
}
@Override
public void run() {
- Log.debug("Shutdown hook triggered.");
-
- Database db = null;
try {
Map activeSessions = SessionCache.getActiveSessions();
long now = System.currentTimeMillis();
- db = Database.getActive();
- saveActiveSessions(db, activeSessions, now);
+ saveActiveSessions(activeSessions, now);
} catch (IllegalStateException ignored) {
/* Database is not initialized */
} catch (DBInitException e) {
- Log.toLog(this.getClass(), e);
+ errorHandler.log(L.ERROR, this.getClass(), e);
} finally {
- if (db != null) {
- try {
- db.close();
- } catch (DBException e) {
- Log.toLog(this.getClass(), e);
- }
+ try {
+ database.close();
+ } catch (DBException e) {
+ errorHandler.log(L.ERROR, this.getClass(), e);
}
}
}
- private void saveActiveSessions(Database db, Map activeSessions, long now) throws DBInitException {
+ private void saveActiveSessions(Map activeSessions, long now) throws DBInitException {
for (Map.Entry entry : activeSessions.entrySet()) {
UUID uuid = entry.getKey();
Session session = entry.getValue();
@@ -77,13 +86,13 @@ public class ShutdownHook extends Thread {
if (!end.isPresent()) {
session.endSession(now);
}
- if (!db.isOpen()) {
- db.init();
+ if (!database.isOpen()) {
+ database.init();
}
try {
- db.save().session(uuid, session);
+ database.save().session(uuid, session);
} catch (DBOpException e) {
- Log.toLog(this.getClass(), e);
+ errorHandler.log(L.ERROR, this.getClass(), e);
}
}
activeSessions.clear();
diff --git a/Plan/src/main/java/com/djrapitops/plan/api/BungeeAPI.java b/Plan/src/main/java/com/djrapitops/plan/api/BungeeAPI.java
deleted file mode 100644
index 394231e52..000000000
--- a/Plan/src/main/java/com/djrapitops/plan/api/BungeeAPI.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * License is provided in the jar as LICENSE also here:
- * https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/LICENSE
- */
-package com.djrapitops.plan.api;
-
-import com.djrapitops.plan.data.plugin.PluginData;
-import com.djrapitops.plan.system.BungeeSystem;
-import com.djrapitops.plan.system.database.databases.operation.FetchOperations;
-
-import java.util.UUID;
-
-/**
- * PlanAPI extension for Bungee.
- *
- * @author Rsl1122
- */
-public class BungeeAPI extends CommonAPI {
-
- private final BungeeSystem bungeeSystem;
-
- public BungeeAPI(BungeeSystem bungeeSystem) {
- this.bungeeSystem = bungeeSystem;
- }
-
- @Override
- public void addPluginDataSource(PluginData pluginData) {
- bungeeSystem.getHookHandler().addPluginDataSource(pluginData);
- }
-
- @Override
- public String getPlayerName(UUID uuid) {
- return bungeeSystem.getCacheSystem().getDataCache().getName(uuid);
- }
-
- @Override
- public FetchOperations fetchFromPlanDB() {
- return bungeeSystem.getDatabaseSystem().getActiveDatabase().fetch();
- }
-}
diff --git a/Plan/src/main/java/com/djrapitops/plan/api/CommonAPI.java b/Plan/src/main/java/com/djrapitops/plan/api/CommonAPI.java
index c87f9336d..0f6ecd529 100644
--- a/Plan/src/main/java/com/djrapitops/plan/api/CommonAPI.java
+++ b/Plan/src/main/java/com/djrapitops/plan/api/CommonAPI.java
@@ -6,7 +6,8 @@ package com.djrapitops.plan.api;
import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
-import com.djrapitops.plugin.api.utility.log.Log;
+import com.djrapitops.plugin.logging.L;
+import com.djrapitops.plugin.logging.error.ErrorHandler;
import java.util.HashMap;
import java.util.Map;
@@ -19,6 +20,15 @@ import java.util.UUID;
*/
public abstract class CommonAPI implements PlanAPI {
+ private final UUIDUtility uuidUtility;
+ private final ErrorHandler errorHandler;
+
+ CommonAPI(UUIDUtility uuidUtility, ErrorHandler errorHandler) {
+ this.uuidUtility = uuidUtility;
+ this.errorHandler = errorHandler;
+ PlanAPIHolder.set(this);
+ }
+
@Override
public String getPlayerInspectPageLink(UUID uuid) {
return getPlayerInspectPageLink(getPlayerName(uuid));
@@ -31,7 +41,7 @@ public abstract class CommonAPI implements PlanAPI {
@Override
public UUID playerNameToUUID(String playerName) {
- return UUIDUtility.getUUIDOf(playerName);
+ return uuidUtility.getUUIDOf(playerName);
}
@Override
@@ -39,7 +49,7 @@ public abstract class CommonAPI implements PlanAPI {
try {
return fetchFromPlanDB().getPlayerNames();
} catch (DBOpException e) {
- Log.toLog(this.getClass(), e);
+ errorHandler.log(L.ERROR, this.getClass(), e);
return new HashMap<>();
}
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/api/PlanAPI.java b/Plan/src/main/java/com/djrapitops/plan/api/PlanAPI.java
index 739910c6b..465d51633 100644
--- a/Plan/src/main/java/com/djrapitops/plan/api/PlanAPI.java
+++ b/Plan/src/main/java/com/djrapitops/plan/api/PlanAPI.java
@@ -5,10 +5,10 @@
package com.djrapitops.plan.api;
import com.djrapitops.plan.data.plugin.PluginData;
-import com.djrapitops.plan.system.PlanSystem;
import com.djrapitops.plan.system.database.databases.operation.FetchOperations;
import java.util.Map;
+import java.util.Optional;
import java.util.UUID;
/**
@@ -19,7 +19,16 @@ import java.util.UUID;
public interface PlanAPI {
static PlanAPI getInstance() {
- return PlanSystem.getInstance().getPlanAPI();
+ return Optional.ofNullable(PlanAPIHolder.API)
+ .orElseThrow(() -> new IllegalStateException("PlanAPI has not been initialised yet."));
+ }
+
+ class PlanAPIHolder {
+ static PlanAPI API;
+
+ static void set(PlanAPI api) {
+ PlanAPIHolder.API = api;
+ }
}
void addPluginDataSource(PluginData pluginData);
diff --git a/Plan/src/main/java/com/djrapitops/plan/api/ProxyAPI.java b/Plan/src/main/java/com/djrapitops/plan/api/ProxyAPI.java
new file mode 100644
index 000000000..02224726b
--- /dev/null
+++ b/Plan/src/main/java/com/djrapitops/plan/api/ProxyAPI.java
@@ -0,0 +1,56 @@
+/*
+ * License is provided in the jar as LICENSE also here:
+ * https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/LICENSE
+ */
+package com.djrapitops.plan.api;
+
+import com.djrapitops.plan.data.plugin.HookHandler;
+import com.djrapitops.plan.data.plugin.PluginData;
+import com.djrapitops.plan.system.database.databases.Database;
+import com.djrapitops.plan.system.database.databases.operation.FetchOperations;
+import com.djrapitops.plan.utilities.uuid.UUIDUtility;
+import com.djrapitops.plugin.logging.error.ErrorHandler;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import java.util.UUID;
+
+/**
+ * PlanAPI extension for proxy servers.
+ *
+ * @author Rsl1122
+ */
+@Singleton
+public class ProxyAPI extends CommonAPI {
+
+ private final HookHandler hookHandler;
+ private final Database database;
+
+ @Inject
+ public ProxyAPI(
+ UUIDUtility uuidUtility,
+ Database database,
+ HookHandler hookHandler,
+ ErrorHandler errorHandler
+ ) {
+ super(uuidUtility, errorHandler);
+
+ this.database = database;
+ this.hookHandler = hookHandler;
+ }
+
+ @Override
+ public void addPluginDataSource(PluginData pluginData) {
+ hookHandler.addPluginDataSource(pluginData);
+ }
+
+ @Override
+ public String getPlayerName(UUID uuid) {
+ return database.fetch().getPlayerName(uuid);
+ }
+
+ @Override
+ public FetchOperations fetchFromPlanDB() {
+ return database.fetch();
+ }
+}
diff --git a/Plan/src/main/java/com/djrapitops/plan/api/ServerAPI.java b/Plan/src/main/java/com/djrapitops/plan/api/ServerAPI.java
index adf22252a..48c6a4198 100644
--- a/Plan/src/main/java/com/djrapitops/plan/api/ServerAPI.java
+++ b/Plan/src/main/java/com/djrapitops/plan/api/ServerAPI.java
@@ -4,10 +4,15 @@
*/
package com.djrapitops.plan.api;
+import com.djrapitops.plan.data.plugin.HookHandler;
import com.djrapitops.plan.data.plugin.PluginData;
-import com.djrapitops.plan.system.ServerSystem;
+import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.database.databases.operation.FetchOperations;
+import com.djrapitops.plan.utilities.uuid.UUIDUtility;
+import com.djrapitops.plugin.logging.error.ErrorHandler;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import java.util.UUID;
/**
@@ -15,26 +20,36 @@ import java.util.UUID;
*
* @author Rsl1122
*/
+@Singleton
public class ServerAPI extends CommonAPI {
- private final ServerSystem serverSystem;
+ private final HookHandler hookHandler;
+ private final Database database;
- public ServerAPI(ServerSystem serverSystem) {
- this.serverSystem = serverSystem;
+ @Inject
+ public ServerAPI(
+ UUIDUtility uuidUtility,
+ HookHandler hookHandler,
+ Database database,
+ ErrorHandler errorHandler
+ ) {
+ super(uuidUtility, errorHandler);
+ this.hookHandler = hookHandler;
+ this.database = database;
}
@Override
public void addPluginDataSource(PluginData pluginData) {
- serverSystem.getHookHandler().addPluginDataSource(pluginData);
+ hookHandler.addPluginDataSource(pluginData);
}
@Override
public String getPlayerName(UUID uuid) {
- return serverSystem.getCacheSystem().getDataCache().getName(uuid);
+ return database.fetch().getPlayerName(uuid);
}
@Override
public FetchOperations fetchFromPlanDB() {
- return serverSystem.getDatabaseSystem().getActiveDatabase().fetch();
+ return database.fetch();
}
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/api/VelocityAPI.java b/Plan/src/main/java/com/djrapitops/plan/api/VelocityAPI.java
deleted file mode 100644
index ef6b63c30..000000000
--- a/Plan/src/main/java/com/djrapitops/plan/api/VelocityAPI.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * License is provided in the jar as LICENSE also here:
- * https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/LICENSE
- */
-package com.djrapitops.plan.api;
-
-import com.djrapitops.plan.data.plugin.PluginData;
-import com.djrapitops.plan.system.VelocitySystem;
-import com.djrapitops.plan.system.database.databases.operation.FetchOperations;
-
-import java.util.UUID;
-
-/**
- * PlanAPI extension for Velocity.
- *
- * Based on BungeeAPI
- *
- * @author MicleBrick
- */
-public class VelocityAPI extends CommonAPI {
-
- private final VelocitySystem velocitySystem;
-
- public VelocityAPI(VelocitySystem velocitySystem) {
- this.velocitySystem = velocitySystem;
- }
-
- @Override
- public void addPluginDataSource(PluginData pluginData) {
- velocitySystem.getHookHandler().addPluginDataSource(pluginData);
- }
-
- @Override
- public String getPlayerName(UUID uuid) {
- return velocitySystem.getCacheSystem().getDataCache().getName(uuid);
- }
-
- @Override
- public FetchOperations fetchFromPlanDB() {
- return velocitySystem.getDatabaseSystem().getActiveDatabase().fetch();
- }
-}
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/PlanBungeeCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/PlanBungeeCommand.java
index 7e37fd8f3..a1c2dc7b9 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/PlanBungeeCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/PlanBungeeCommand.java
@@ -1,6 +1,5 @@
package com.djrapitops.plan.command;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.command.commands.*;
import com.djrapitops.plan.command.commands.manage.ManageConDebugCommand;
import com.djrapitops.plan.command.commands.manage.ManageRawDataCommand;
@@ -8,10 +7,14 @@ import com.djrapitops.plan.command.commands.manage.ManageUninstalledCommand;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.settings.Permissions;
+import com.djrapitops.plugin.command.ColorScheme;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.TreeCmdNode;
-import com.djrapitops.plugin.command.defaultcmds.StatusCommand;
+import dagger.Lazy;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
/**
* TreeCommand for the /plan command, and all subcommands.
@@ -21,36 +24,85 @@ import com.djrapitops.plugin.command.defaultcmds.StatusCommand;
* @author Rsl1122
* @since 1.0.0
*/
+@Singleton
public class PlanBungeeCommand extends TreeCmdNode {
- public PlanBungeeCommand(PlanPlugin plugin) {
+ private final NetworkCommand networkCommand;
+ private final ListServersCommand listServersCommand;
+ private final ListPlayersCommand listPlayersCommand;
+ private final RegisterCommand registerCommand;
+ private final Lazy webUserCommand;
+ private final ManageConDebugCommand conDebugCommand;
+ private final ManageRawDataCommand rawDataCommand;
+ private final BungeeSetupToggleCommand setupToggleCommand;
+ private final ReloadCommand reloadCommand;
+ private final DisableCommand disableCommand;
+ private final ManageUninstalledCommand uninstalledCommand;
+
+ private boolean commandsRegistered;
+
+ @Inject
+ public PlanBungeeCommand(
+ ColorScheme colorScheme,
+ Locale locale,
+ // Group 1
+ NetworkCommand networkCommand,
+ ListServersCommand listServersCommand,
+ ListPlayersCommand listPlayersCommand,
+ // Group 2
+ RegisterCommand registerCommand,
+ Lazy webUserCommand,
+ // Group 3
+ ManageConDebugCommand conDebugCommand,
+ ManageRawDataCommand rawDataCommand,
+ BungeeSetupToggleCommand setupToggleCommand,
+ ManageUninstalledCommand uninstalledCommand,
+ ReloadCommand reloadCommand,
+ DisableCommand disableCommand
+ ) {
super("planbungee", Permissions.MANAGE.getPermission(), CommandType.CONSOLE, null);
- super.setColorScheme(plugin.getColorScheme());
+ this.uninstalledCommand = uninstalledCommand;
- Locale locale = plugin.getSystem().getLocaleSystem().getLocale();
+ commandsRegistered = false;
+ this.networkCommand = networkCommand;
+ this.listServersCommand = listServersCommand;
+ this.listPlayersCommand = listPlayersCommand;
+ this.registerCommand = registerCommand;
+ this.webUserCommand = webUserCommand;
+ this.conDebugCommand = conDebugCommand;
+ this.rawDataCommand = rawDataCommand;
+ this.setupToggleCommand = setupToggleCommand;
+ this.reloadCommand = reloadCommand;
+ this.disableCommand = disableCommand;
+
+ setColorScheme(colorScheme);
setInDepthHelp(locale.getArray(DeepHelpLang.PLAN));
+ }
+
+ public void registerCommands() {
+ if (commandsRegistered) {
+ return;
+ }
- RegisterCommand registerCommand = new RegisterCommand(plugin);
CommandNode[] analyticsGroup = {
- new NetworkCommand(plugin),
- new ListServersCommand(plugin),
- new ListPlayersCommand(plugin),
+ networkCommand,
+ listServersCommand,
+ listPlayersCommand
};
CommandNode[] webGroup = {
registerCommand,
- new WebUserCommand(plugin, registerCommand, this),
+ webUserCommand.get()
};
CommandNode[] manageGroup = {
- new ManageConDebugCommand(plugin),
- new ManageRawDataCommand(plugin),
- new BungeeSetupToggleCommand(plugin),
- new ManageUninstalledCommand(plugin),
- new ReloadCommand(plugin),
- new DisableCommand(plugin),
- new StatusCommand<>(plugin, Permissions.MANAGE.getPermission(), plugin.getColorScheme()),
-// (Settings.ALLOW_UPDATE.isTrue() ? new UpdateCommand() : null)
+ conDebugCommand,
+ rawDataCommand,
+ setupToggleCommand,
+ uninstalledCommand,
+ reloadCommand,
+ disableCommand
};
setNodeGroups(analyticsGroup, webGroup, manageGroup);
+ commandsRegistered = true;
}
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/PlanCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/PlanCommand.java
index e740df78a..8854676ee 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/PlanCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/PlanCommand.java
@@ -1,15 +1,18 @@
package com.djrapitops.plan.command;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.command.commands.*;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
-import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.Settings;
+import com.djrapitops.plan.system.settings.config.PlanConfig;
+import com.djrapitops.plugin.command.ColorScheme;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.TreeCmdNode;
-import com.djrapitops.plugin.command.defaultcmds.StatusCommand;
+import dagger.Lazy;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
/**
* TreeCommand for the /plan command, and all SubCommands.
@@ -19,39 +22,97 @@ import com.djrapitops.plugin.command.defaultcmds.StatusCommand;
* @author Rsl1122
* @since 1.0.0
*/
+@Singleton
public class PlanCommand extends TreeCmdNode {
- public PlanCommand(PlanPlugin plugin) {
+ private final PlanConfig config;
+ private final InspectCommand inspectCommand;
+ private final QInspectCommand qInspectCommand;
+ private final SearchCommand searchCommand;
+ private final ListPlayersCommand listPlayersCommand;
+ private final AnalyzeCommand analyzeCommand;
+ private final NetworkCommand networkCommand;
+ private final ListServersCommand listServersCommand;
+ private final Lazy webUserCommand;
+ private final RegisterCommand registerCommand;
+ private final InfoCommand infoCommand;
+ private final ReloadCommand reloadCommand;
+ private final Lazy manageCommand;
+ private final DevCommand devCommand;
+
+ private boolean commandsRegistered;
+
+ @Inject
+ public PlanCommand(
+ ColorScheme colorScheme,
+ Locale locale,
+ PlanConfig config,
+ // Group 1
+ InspectCommand inspectCommand,
+ QInspectCommand qInspectCommand,
+ SearchCommand searchCommand,
+ ListPlayersCommand listPlayersCommand,
+ AnalyzeCommand analyzeCommand,
+ NetworkCommand networkCommand,
+ ListServersCommand listServersCommand,
+ // Group 2
+ Lazy webUserCommand,
+ RegisterCommand registerCommand,
+ // Group 3
+ InfoCommand infoCommand,
+ ReloadCommand reloadCommand,
+ Lazy manageCommand,
+ DevCommand devCommand
+ ) {
super("plan", "", CommandType.CONSOLE, null);
- super.setDefaultCommand("inspect");
- super.setColorScheme(plugin.getColorScheme());
- Locale locale = plugin.getSystem().getLocaleSystem().getLocale();
+ commandsRegistered = false;
+ this.config = config;
+ this.inspectCommand = inspectCommand;
+ this.qInspectCommand = qInspectCommand;
+ this.searchCommand = searchCommand;
+ this.listPlayersCommand = listPlayersCommand;
+ this.analyzeCommand = analyzeCommand;
+ this.networkCommand = networkCommand;
+ this.listServersCommand = listServersCommand;
+ this.webUserCommand = webUserCommand;
+ this.registerCommand = registerCommand;
+ this.infoCommand = infoCommand;
+ this.reloadCommand = reloadCommand;
+ this.manageCommand = manageCommand;
+ this.devCommand = devCommand;
+
+ setDefaultCommand("inspect");
+ setColorScheme(colorScheme);
setInDepthHelp(locale.getArray(DeepHelpLang.PLAN));
+ }
+
+ public void registerCommands() {
+ if (commandsRegistered) {
+ return;
+ }
- RegisterCommand registerCommand = new RegisterCommand(plugin);
CommandNode[] analyticsGroup = {
- new InspectCommand(plugin),
- new QInspectCommand(plugin),
- new SearchCommand(plugin),
- new ListPlayersCommand(plugin),
- new AnalyzeCommand(plugin),
- new NetworkCommand(plugin),
- new ListServersCommand(plugin)
+ inspectCommand,
+ qInspectCommand,
+ searchCommand,
+ listPlayersCommand,
+ analyzeCommand,
+ networkCommand,
+ listServersCommand
};
CommandNode[] webGroup = {
- new WebUserCommand(plugin, registerCommand, this),
+ webUserCommand.get(),
registerCommand
};
CommandNode[] manageGroup = {
- new InfoCommand(plugin),
- new ReloadCommand(plugin),
- new ManageCommand(plugin, this),
- new StatusCommand<>(plugin, Permissions.MANAGE.getPermission(), plugin.getColorScheme()),
- (Settings.DEV_MODE.isTrue() ? new DevCommand(plugin) : null),
-// (Settings.ALLOW_UPDATE.isTrue() ? new UpdateCommand() : null)
+ infoCommand,
+ reloadCommand,
+ manageCommand.get(),
+ config.isTrue(Settings.DEV_MODE) ? devCommand : null
};
setNodeGroups(analyticsGroup, webGroup, manageGroup);
+ commandsRegistered = true;
}
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/PlanVelocityCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/PlanVelocityCommand.java
index 59f9e123f..d64dd61a4 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/PlanVelocityCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/PlanVelocityCommand.java
@@ -1,6 +1,5 @@
package com.djrapitops.plan.command;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.command.commands.*;
import com.djrapitops.plan.command.commands.manage.ManageConDebugCommand;
import com.djrapitops.plan.command.commands.manage.ManageRawDataCommand;
@@ -8,50 +7,102 @@ import com.djrapitops.plan.command.commands.manage.ManageUninstalledCommand;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.settings.Permissions;
+import com.djrapitops.plugin.command.ColorScheme;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.TreeCmdNode;
-import com.djrapitops.plugin.command.defaultcmds.StatusCommand;
+import dagger.Lazy;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
/**
* TreeCommand for the /plan command, and all subcommands.
*
* Uses the Abstract Plugin Framework for easier command management.
*
- * Based on PlanBungeeCommand
- *
- * @author MicleBrick
+ * @author Rsl1122
+ * @since 1.0.0
*/
+@Singleton
public class PlanVelocityCommand extends TreeCmdNode {
- public PlanVelocityCommand(PlanPlugin plugin) {
+ private final NetworkCommand networkCommand;
+ private final ListServersCommand listServersCommand;
+ private final ListPlayersCommand listPlayersCommand;
+ private final RegisterCommand registerCommand;
+ private final Lazy webUserCommand;
+ private final ManageConDebugCommand conDebugCommand;
+ private final ManageRawDataCommand rawDataCommand;
+ private final BungeeSetupToggleCommand setupToggleCommand;
+ private final ReloadCommand reloadCommand;
+ private final DisableCommand disableCommand;
+ private final ManageUninstalledCommand uninstalledCommand;
+
+ private boolean commandsRegistered;
+
+ @Inject
+ public PlanVelocityCommand(
+ ColorScheme colorScheme,
+ Locale locale,
+ // Group 1
+ NetworkCommand networkCommand,
+ ListServersCommand listServersCommand,
+ ListPlayersCommand listPlayersCommand,
+ // Group 2
+ RegisterCommand registerCommand,
+ Lazy webUserCommand,
+ // Group 3
+ ManageConDebugCommand conDebugCommand,
+ ManageRawDataCommand rawDataCommand,
+ BungeeSetupToggleCommand setupToggleCommand,
+ ManageUninstalledCommand uninstalledCommand,
+ ReloadCommand reloadCommand,
+ DisableCommand disableCommand
+ ) {
super("planvelocity", Permissions.MANAGE.getPermission(), CommandType.CONSOLE, null);
- super.setColorScheme(plugin.getColorScheme());
+ this.uninstalledCommand = uninstalledCommand;
- Locale locale = plugin.getSystem().getLocaleSystem().getLocale();
+ commandsRegistered = false;
+ this.networkCommand = networkCommand;
+ this.listServersCommand = listServersCommand;
+ this.listPlayersCommand = listPlayersCommand;
+ this.registerCommand = registerCommand;
+ this.webUserCommand = webUserCommand;
+ this.conDebugCommand = conDebugCommand;
+ this.rawDataCommand = rawDataCommand;
+ this.setupToggleCommand = setupToggleCommand;
+ this.reloadCommand = reloadCommand;
+ this.disableCommand = disableCommand;
+
+ setColorScheme(colorScheme);
setInDepthHelp(locale.getArray(DeepHelpLang.PLAN));
+ }
+
+ public void registerCommands() {
+ if (commandsRegistered) {
+ return;
+ }
- RegisterCommand registerCommand = new RegisterCommand(plugin);
CommandNode[] analyticsGroup = {
- new NetworkCommand(plugin),
- new ListServersCommand(plugin),
- new ListPlayersCommand(plugin),
+ networkCommand,
+ listServersCommand,
+ listPlayersCommand
};
CommandNode[] webGroup = {
registerCommand,
- new WebUserCommand(plugin, registerCommand, this),
+ webUserCommand.get()
};
CommandNode[] manageGroup = {
- new ManageConDebugCommand(plugin),
- new ManageRawDataCommand(plugin),
- new BungeeSetupToggleCommand(plugin), // perhaps rename to ProxySetupToggleCommand ?
- new ManageUninstalledCommand(plugin),
- new ReloadCommand(plugin),
- new DisableCommand(plugin),
- new StatusCommand<>(plugin, Permissions.MANAGE.getPermission(), plugin.getColorScheme()),
-// (Settings.ALLOW_UPDATE.isTrue() ? new UpdateCommand() : null)
+ conDebugCommand,
+ rawDataCommand,
+ setupToggleCommand,
+ uninstalledCommand,
+ reloadCommand,
+ disableCommand
};
setNodeGroups(analyticsGroup, webGroup, manageGroup);
+ commandsRegistered = true;
}
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java
index 47ef1639a..4b73d94de 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java
@@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.system.database.databases.Database;
@@ -15,13 +14,16 @@ import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.locale.lang.ManageLang;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions;
-import com.djrapitops.plan.system.webserver.WebServerSystem;
-import com.djrapitops.plugin.api.utility.log.Log;
+import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.CommandUtils;
-import com.djrapitops.plugin.command.ISender;
+import com.djrapitops.plugin.command.Sender;
+import com.djrapitops.plugin.logging.L;
+import com.djrapitops.plugin.logging.error.ErrorHandler;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
@@ -32,14 +34,38 @@ import java.util.UUID;
* @author Rsl1122
* @since 2.0.0
*/
+@Singleton
public class AnalyzeCommand extends CommandNode {
private final Locale locale;
+ private final Processing processing;
+ private final InfoSystem infoSystem;
+ private final ServerInfo serverInfo;
+ private final WebServer webServer;
+ private final Database database;
+ private final ConnectionSystem connectionSystem;
+ private final ErrorHandler errorHandler;
- public AnalyzeCommand(PlanPlugin plugin) {
+ @Inject
+ public AnalyzeCommand(
+ Locale locale,
+ Processing processing,
+ InfoSystem infoSystem,
+ ServerInfo serverInfo,
+ WebServer webServer,
+ Database database,
+ ErrorHandler errorHandler
+ ) {
super("analyze|analyse|analysis|a", Permissions.ANALYZE.getPermission(), CommandType.CONSOLE);
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.locale = locale;
+ this.processing = processing;
+ this.infoSystem = infoSystem;
+ connectionSystem = infoSystem.getConnectionSystem();
+ this.serverInfo = serverInfo;
+ this.webServer = webServer;
+ this.database = database;
+ this.errorHandler = errorHandler;
setShortHelp(locale.getString(CmdHelpLang.ANALYZE));
setInDepthHelp(locale.getArray(DeepHelpLang.ANALYZE));
@@ -47,27 +73,27 @@ public class AnalyzeCommand extends CommandNode {
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
- Processing.submitNonCritical(() -> {
+ processing.submitNonCritical(() -> {
try {
- Server server = getServer(args).orElseGet(ServerInfo::getServer);
+ Server server = getServer(args).orElseGet(serverInfo::getServer);
UUID serverUUID = server.getUuid();
- InfoSystem.getInstance().generateAnalysisPage(serverUUID);
+ infoSystem.generateAnalysisPage(serverUUID);
sendWebUserNotificationIfNecessary(sender);
sendLink(server, sender);
} catch (DBOpException | WebException e) {
sender.sendMessage("§cError occurred: " + e.toString());
- Log.toLog(this.getClass(), e);
+ errorHandler.log(L.ERROR, this.getClass(), e);
}
});
}
- private void sendLink(Server server, ISender sender) {
+ private void sendLink(Server server, Sender sender) {
String target = "/server/" + server.getName();
- String url = ConnectionSystem.getAddress() + target;
+ String url = connectionSystem.getMainAddress() + target;
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
sender.sendMessage(locale.getString(CommandLang.HEADER_ANALYSIS));
// Link
@@ -81,19 +107,17 @@ public class AnalyzeCommand extends CommandNode {
sender.sendMessage(">");
}
- private void sendWebUserNotificationIfNecessary(ISender sender) {
- if (WebServerSystem.getInstance().getWebServer().isAuthRequired() && CommandUtils.isPlayer(sender)) {
-
- boolean senderHasWebUser = Database.getActive().check().doesWebUserExists(sender.getName());
- if (!senderHasWebUser) {
- sender.sendMessage("§e" + locale.getString(CommandLang.NO_WEB_USER_NOTIFY));
- }
+ private void sendWebUserNotificationIfNecessary(Sender sender) {
+ if (webServer.isAuthRequired() &&
+ CommandUtils.isPlayer(sender) &&
+ !database.check().doesWebUserExists(sender.getName())) {
+ sender.sendMessage("§e" + locale.getString(CommandLang.NO_WEB_USER_NOTIFY));
}
}
private Optional getServer(String[] args) {
- if (args.length >= 1 && ConnectionSystem.getInstance().isServerAvailable()) {
- Map bukkitServers = Database.getActive().fetch().getBukkitServers();
+ if (args.length >= 1 && connectionSystem.isServerAvailable()) {
+ Map bukkitServers = database.fetch().getBukkitServers();
String serverIdentifier = getGivenIdentifier(args);
for (Map.Entry entry : bukkitServers.entrySet()) {
Server server = entry.getValue();
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/BungeeSetupToggleCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/BungeeSetupToggleCommand.java
index e4c23e393..1ad623968 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/BungeeSetupToggleCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/BungeeSetupToggleCommand.java
@@ -4,7 +4,6 @@
*/
package com.djrapitops.plan.command.commands;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
@@ -13,7 +12,9 @@ import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
-import com.djrapitops.plugin.command.ISender;
+import com.djrapitops.plugin.command.Sender;
+
+import javax.inject.Inject;
/**
* Command for Toggling whether or not BungeeCord accepts set up requests.
@@ -25,27 +26,28 @@ import com.djrapitops.plugin.command.ISender;
public class BungeeSetupToggleCommand extends CommandNode {
private final Locale locale;
+ private final ConnectionSystem connectionSystem;
- public BungeeSetupToggleCommand(PlanPlugin plugin) {
+ @Inject
+ public BungeeSetupToggleCommand(Locale locale, ConnectionSystem connectionSystem) {
super("setup", Permissions.MANAGE.getPermission(), CommandType.ALL);
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.locale = locale;
+ this.connectionSystem = connectionSystem;
setShortHelp(locale.getString(CmdHelpLang.SETUP));
setInDepthHelp(locale.getArray(DeepHelpLang.SETUP));
}
@Override
- public void onCommand(ISender sender, String s, String[] strings) {
- boolean setupAllowed = ConnectionSystem.isSetupAllowed();
- ConnectionSystem connectionSystem = ConnectionSystem.getInstance();
-
- if (setupAllowed) {
+ public void onCommand(Sender sender, String s, String[] strings) {
+ if (connectionSystem.isSetupAllowed()) {
connectionSystem.setSetupAllowed(false);
} else {
connectionSystem.setSetupAllowed(true);
}
- String msg = locale.getString(!setupAllowed ? CommandLang.SETUP_ALLOWED : CommandLang.CONNECT_FORBIDDEN);
+
+ String msg = locale.getString(connectionSystem.isSetupAllowed() ? CommandLang.SETUP_ALLOWED : CommandLang.CONNECT_FORBIDDEN);
sender.sendMessage(msg);
}
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/DevCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/DevCommand.java
index 8ca20e7f6..5784b46a9 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/DevCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/DevCommand.java
@@ -4,15 +4,15 @@
*/
package com.djrapitops.plan.command.commands;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
-import com.djrapitops.plugin.command.ISender;
+import com.djrapitops.plugin.command.Sender;
import com.djrapitops.plugin.utilities.Verify;
+import javax.inject.Inject;
import java.util.Arrays;
/**
@@ -24,17 +24,18 @@ public class DevCommand extends CommandNode {
private final Locale locale;
- public DevCommand(PlanPlugin plugin) {
+ @Inject
+ public DevCommand(Locale locale) {
super("dev", "plan.*", CommandType.PLAYER_OR_ARGS);
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.locale = locale;
setShortHelp(locale.get(CmdHelpLang.DEV).toString());
setArguments("");
}
@Override
- public void onCommand(ISender sender, String cmd, String[] args) {
+ public void onCommand(Sender sender, String cmd, String[] args) {
Verify.isTrue(args.length >= 1,
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/DisableCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/DisableCommand.java
index b54e40b34..9fa0ba748 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/DisableCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/DisableCommand.java
@@ -7,24 +7,29 @@ import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
-import com.djrapitops.plugin.command.ISender;
+import com.djrapitops.plugin.command.Sender;
+
+import javax.inject.Inject;
public class DisableCommand extends CommandNode {
private final Locale locale;
+ private final PlanPlugin plugin;
- public DisableCommand(PlanPlugin plugin) {
+ @Inject
+ public DisableCommand(PlanPlugin plugin, Locale locale) {
super("disable", "plan.reload", CommandType.ALL);
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.plugin = plugin;
+ this.locale = locale;
setShortHelp(locale.getString(CmdHelpLang.DISABLE));
setInDepthHelp(locale.getArray(DeepHelpLang.DISABLE));
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
- PlanPlugin.getInstance().onDisable();
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
+ plugin.onDisable();
sender.sendMessage(locale.getString(CommandLang.DISABLE_DISABLED));
}
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/InfoCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/InfoCommand.java
index 12210e0de..91cbe60ee 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/InfoCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/InfoCommand.java
@@ -11,7 +11,9 @@ import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.update.VersionCheckSystem;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
-import com.djrapitops.plugin.command.ISender;
+import com.djrapitops.plugin.command.Sender;
+
+import javax.inject.Inject;
/**
* This SubCommand is used to view the version and the database type in use.
@@ -23,29 +25,42 @@ public class InfoCommand extends CommandNode {
private final PlanPlugin plugin;
private final Locale locale;
+ private final Database database;
+ private final ConnectionSystem connectionSystem;
+ private final VersionCheckSystem versionCheckSystem;
- public InfoCommand(PlanPlugin plugin) {
+ @Inject
+ public InfoCommand(
+ PlanPlugin plugin,
+ Locale locale,
+ Database database,
+ ConnectionSystem connectionSystem,
+ VersionCheckSystem versionCheckSystem
+ ) {
super("info", Permissions.INFO.getPermission(), CommandType.CONSOLE);
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.plugin = plugin;
+ this.locale = locale;
+ this.database = database;
+ this.connectionSystem = connectionSystem;
+ this.versionCheckSystem = versionCheckSystem;
setShortHelp(locale.get(CmdHelpLang.INFO).toString());
- this.plugin = plugin;
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
String yes = locale.getString(GenericLang.YES);
String no = locale.getString(GenericLang.NO);
- String updateAvailable = VersionCheckSystem.isNewVersionAvailable() ? yes : no;
- String connectedToBungee = ConnectionSystem.getInstance().isServerAvailable() ? yes : no;
+ String updateAvailable = versionCheckSystem.isNewVersionAvailable() ? yes : no;
+ String connectedToBungee = connectionSystem.isServerAvailable() ? yes : no;
String[] messages = {
locale.getString(CommandLang.HEADER_INFO),
"",
locale.getString(CommandLang.INFO_VERSION, plugin.getVersion()),
locale.getString(CommandLang.INFO_UPDATE, updateAvailable),
- locale.getString(CommandLang.INFO_DATABASE, Database.getActive().getName()),
+ locale.getString(CommandLang.INFO_DATABASE, database.getName()),
locale.getString(CommandLang.INFO_BUNGEE_CONNECTION, connectedToBungee),
"",
">"
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java
index 1cb962999..69bb9f131 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java
@@ -1,26 +1,26 @@
package com.djrapitops.plan.command.commands;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.system.database.databases.Database;
+import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.processing.Processing;
-import com.djrapitops.plan.system.processing.processors.info.InspectCacheRequestProcessor;
+import com.djrapitops.plan.system.processing.processors.info.InfoProcessors;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
-import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.CommandUtils;
-import com.djrapitops.plugin.command.ISender;
-import com.djrapitops.plugin.task.AbsRunnable;
-import com.djrapitops.plugin.task.RunnableFactory;
+import com.djrapitops.plugin.command.Sender;
+import com.djrapitops.plugin.logging.L;
+import com.djrapitops.plugin.logging.error.ErrorHandler;
+import javax.inject.Inject;
import java.util.UUID;
/**
@@ -32,19 +32,43 @@ import java.util.UUID;
public class InspectCommand extends CommandNode {
private final Locale locale;
+ private final Database database;
+ private final WebServer webServer;
+ private final InfoProcessors processorFactory;
+ private final Processing processing;
+ private final ConnectionSystem connectionSystem;
+ private final UUIDUtility uuidUtility;
+ private final ErrorHandler errorHandler;
- public InspectCommand(PlanPlugin plugin) {
+ @Inject
+ public InspectCommand(
+ Locale locale,
+ InfoProcessors processorFactory,
+ Processing processing,
+ Database database,
+ WebServer webServer,
+ ConnectionSystem connectionSystem,
+ UUIDUtility uuidUtility,
+ ErrorHandler errorHandler
+ ) {
super("inspect", Permissions.INSPECT.getPermission(), CommandType.PLAYER_OR_ARGS);
+ this.processorFactory = processorFactory;
+ this.processing = processing;
+ this.connectionSystem = connectionSystem;
setArguments("");
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.locale = locale;
+ this.database = database;
+ this.webServer = webServer;
+ this.uuidUtility = uuidUtility;
+ this.errorHandler = errorHandler;
setShortHelp(locale.getString(CmdHelpLang.INSPECT));
setInDepthHelp(locale.getArray(DeepHelpLang.INSPECT));
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
String playerName = MiscUtils.getPlayerName(args, sender);
if (playerName == null) {
@@ -54,42 +78,53 @@ public class InspectCommand extends CommandNode {
runInspectTask(playerName, sender);
}
- private void runInspectTask(String playerName, ISender sender) {
- RunnableFactory.createNew(new AbsRunnable("InspectTask") {
- @Override
- public void run() {
- try {
- UUID uuid = UUIDUtility.getUUIDOf(playerName);
- if (uuid == null) {
- sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_VALID));
- return;
- }
-
- Database activeDB = Database.getActive();
- if (!activeDB.check().isPlayerRegistered(uuid)) {
- sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_KNOWN));
- return;
- }
-
- checkWebUserAndNotify(activeDB, sender);
- Processing.submit(new InspectCacheRequestProcessor(uuid, sender, playerName, locale));
- } catch (DBOpException e) {
- sender.sendMessage("§eDatabase exception occurred: " + e.getMessage());
- Log.toLog(this.getClass(), e);
- } finally {
- this.cancel();
+ private void runInspectTask(String playerName, Sender sender) {
+ processing.submitNonCritical(() -> {
+ try {
+ UUID uuid = uuidUtility.getUUIDOf(playerName);
+ if (uuid == null) {
+ sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_VALID));
+ return;
}
+
+ if (!database.check().isPlayerRegistered(uuid)) {
+ sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_KNOWN));
+ return;
+ }
+
+ checkWebUserAndNotify(sender);
+ processing.submit(processorFactory.inspectCacheRequestProcessor(uuid, sender, playerName, this::sendInspectMsg));
+ } catch (DBOpException e) {
+ sender.sendMessage("§eDatabase exception occurred: " + e.getMessage());
+ errorHandler.log(L.ERROR, this.getClass(), e);
}
- }).runTaskAsynchronously();
+ });
}
- private void checkWebUserAndNotify(Database activeDB, ISender sender) {
- if (CommandUtils.isPlayer(sender) && WebServer.getInstance().isAuthRequired()) {
- boolean senderHasWebUser = activeDB.check().doesWebUserExists(sender.getName());
+ private void checkWebUserAndNotify(Sender sender) {
+ if (CommandUtils.isPlayer(sender) && webServer.isAuthRequired()) {
+ boolean senderHasWebUser = database.check().doesWebUserExists(sender.getName());
if (!senderHasWebUser) {
sender.sendMessage("§e" + locale.getString(CommandLang.NO_WEB_USER_NOTIFY));
}
}
}
+
+ private void sendInspectMsg(Sender sender, String playerName) {
+ sender.sendMessage(locale.getString(CommandLang.HEADER_INSPECT, playerName));
+
+ String url = connectionSystem.getMainAddress() + "/player/" + playerName;
+ String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
+
+ boolean console = !CommandUtils.isPlayer(sender);
+ if (console) {
+ sender.sendMessage(linkPrefix + url);
+ } else {
+ sender.sendMessage(linkPrefix);
+ sender.sendLink(" ", locale.getString(CommandLang.LINK_CLICK_ME), url);
+ }
+
+ sender.sendMessage(">");
+ }
}
\ No newline at end of file
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/ListPlayersCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/ListPlayersCommand.java
index e5d903293..694c9f0cf 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/ListPlayersCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/ListPlayersCommand.java
@@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
@@ -10,7 +9,9 @@ import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.CommandUtils;
-import com.djrapitops.plugin.command.ISender;
+import com.djrapitops.plugin.command.Sender;
+
+import javax.inject.Inject;
/**
* Command used to display url to the player list page.
@@ -21,26 +22,29 @@ import com.djrapitops.plugin.command.ISender;
public class ListPlayersCommand extends CommandNode {
private final Locale locale;
+ private final ConnectionSystem connectionSystem;
- public ListPlayersCommand(PlanPlugin plugin) {
+ @Inject
+ public ListPlayersCommand(Locale locale, ConnectionSystem connectionSystem) {
super("players|pl|playerlist|list", Permissions.INSPECT_OTHER.getPermission(), CommandType.CONSOLE);
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.locale = locale;
+ this.connectionSystem = connectionSystem;
setShortHelp(locale.getString(CmdHelpLang.PLAYERS));
setInDepthHelp(locale.getArray(DeepHelpLang.PLAYERS));
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
sendListMsg(sender);
}
- private void sendListMsg(ISender sender) {
+ private void sendListMsg(Sender sender) {
sender.sendMessage(locale.getString(CommandLang.HEADER_PLAYERS));
// Link
- String url = ConnectionSystem.getAddress() + "/players/";
+ String url = connectionSystem.getMainAddress() + "/players/";
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
boolean console = !CommandUtils.isPlayer(sender);
if (console) {
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/ListServersCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/ListServersCommand.java
index 65c4bf3a1..ab7890275 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/ListServersCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/ListServersCommand.java
@@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.info.server.Server;
@@ -9,12 +8,15 @@ import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.settings.Permissions;
-import com.djrapitops.plugin.api.utility.log.Log;
+import com.djrapitops.plan.utilities.formatting.Formatter;
+import com.djrapitops.plugin.command.ColorScheme;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
-import com.djrapitops.plugin.command.ISender;
-import com.djrapitops.plugin.settings.ColorScheme;
+import com.djrapitops.plugin.command.Sender;
+import com.djrapitops.plugin.logging.L;
+import com.djrapitops.plugin.logging.error.ErrorHandler;
+import javax.inject.Inject;
import java.util.List;
/**
@@ -24,35 +26,48 @@ import java.util.List;
*/
public class ListServersCommand extends CommandNode {
- private final PlanPlugin plugin;
private final Locale locale;
+ private final ColorScheme colorScheme;
+ private final Database database;
+ private final ErrorHandler errorHandler;
- public ListServersCommand(PlanPlugin plugin) {
+ @Inject
+ public ListServersCommand(Locale locale, ColorScheme colorScheme, Database database, ErrorHandler errorHandler) {
super("servers|serverlist|listservers|sl|ls", Permissions.MANAGE.getPermission(), CommandType.CONSOLE);
- this.plugin = plugin;
- this.locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.locale = locale;
+ this.colorScheme = colorScheme;
+ this.database = database;
+ this.errorHandler = errorHandler;
setShortHelp(locale.getString(CmdHelpLang.SERVERS));
setInDepthHelp(locale.getArray(DeepHelpLang.SERVERS));
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
- ColorScheme colorScheme = plugin.getColorScheme();
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
String sCol = colorScheme.getSecondaryColor();
String tCol = colorScheme.getTertiaryColor();
+ Formatter serverFormatter = serverLister(sCol, tCol);
try {
sender.sendMessage(locale.getString(CommandLang.HEADER_SERVERS));
- List servers = Database.getActive().fetch().getServers();
- for (Server server : servers) {
- sender.sendMessage(" " + tCol + server.getId() + sCol + " : " + server.getName() + " : " + server.getWebAddress());
- }
+ sendServers(sender, serverFormatter);
sender.sendMessage(">");
} catch (DBOpException e) {
sender.sendMessage("§cDatabase Exception occurred.");
- Log.toLog(this.getClass(), e);
+ errorHandler.log(L.WARN, this.getClass(), e);
}
}
+ private void sendServers(Sender sender, Formatter serverFormatter) {
+ List servers = database.fetch().getServers();
+ for (Server server : servers) {
+ sender.sendMessage(serverFormatter.apply(server));
+ }
+ }
+
+ private Formatter serverLister(String tertiaryColor, String secondaryColor) {
+ return server -> " " + tertiaryColor + server.getId() + secondaryColor + " : " + server.getName() + " : " + server.getWebAddress();
+ }
+
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/ManageCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/ManageCommand.java
index 58a7a6020..82da516e1 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/ManageCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/ManageCommand.java
@@ -1,14 +1,18 @@
package com.djrapitops.plan.command.commands;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.command.commands.manage.*;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.settings.Permissions;
+import com.djrapitops.plugin.command.ColorScheme;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.TreeCmdNode;
+import dagger.Lazy;
+
+import javax.inject.Inject;
+import javax.inject.Named;
/**
* This SubCommand is used to manage the the plugin's database and components.
@@ -18,29 +22,43 @@ import com.djrapitops.plugin.command.TreeCmdNode;
*/
public class ManageCommand extends TreeCmdNode {
- public ManageCommand(PlanPlugin plugin, CommandNode parent) {
- super("manage|m", Permissions.MANAGE.getPermission(), CommandType.CONSOLE, parent);
-
- Locale locale = plugin.getSystem().getLocaleSystem().getLocale();
+ @Inject
+ public ManageCommand(ColorScheme colorScheme, Locale locale, @Named("mainCommand") Lazy parent,
+ // Group 1
+ ManageRawDataCommand rawDataCommand,
+ ManageMoveCommand moveCommand,
+ ManageBackupCommand backupCommand,
+ ManageRemoveCommand removeCommand,
+ ManageRestoreCommand restoreCommand,
+ ManageHotSwapCommand hotSwapCommand,
+ ManageClearCommand clearCommand,
+ // Group 2
+ ManageSetupCommand setupCommand,
+ ManageConDebugCommand conDebugCommand,
+ ManageImportCommand importCommand,
+ ManageDisableCommand disableCommand,
+ ManageUninstalledCommand uninstalledCommand
+ ) {
+ super("manage|m", Permissions.MANAGE.getPermission(), CommandType.CONSOLE, parent.get());
+ super.setColorScheme(colorScheme);
setShortHelp(locale.getString(CmdHelpLang.MANAGE));
setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE));
- super.setColorScheme(plugin.getColorScheme());
CommandNode[] databaseGroup = {
- new ManageRawDataCommand(plugin),
- new ManageMoveCommand(plugin),
- new ManageBackupCommand(plugin),
- new ManageRestoreCommand(plugin),
- new ManageRemoveCommand(plugin),
- new ManageHotSwapCommand(plugin),
- new ManageClearCommand(plugin),
+ rawDataCommand,
+ moveCommand,
+ backupCommand,
+ restoreCommand,
+ hotSwapCommand,
+ removeCommand,
+ clearCommand,
};
CommandNode[] pluginGroup = {
- new ManageSetupCommand(plugin),
- new ManageConDebugCommand(plugin),
- new ManageImportCommand(plugin),
- new ManageDisableCommand(plugin),
- new ManageUninstalledCommand(plugin)
+ setupCommand,
+ conDebugCommand,
+ importCommand,
+ disableCommand,
+ uninstalledCommand
};
setNodeGroups(databaseGroup, pluginGroup);
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/NetworkCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/NetworkCommand.java
index 85f165364..a899ff7f6 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/NetworkCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/NetworkCommand.java
@@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
@@ -10,7 +9,9 @@ import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.CommandUtils;
-import com.djrapitops.plugin.command.ISender;
+import com.djrapitops.plugin.command.Sender;
+
+import javax.inject.Inject;
/**
* Command used to display url to the network page.
@@ -20,26 +21,29 @@ import com.djrapitops.plugin.command.ISender;
public class NetworkCommand extends CommandNode {
private final Locale locale;
+ private final ConnectionSystem connectionSystem;
- public NetworkCommand(PlanPlugin plugin) {
+ @Inject
+ public NetworkCommand(Locale locale, ConnectionSystem connectionSystem) {
super("network|n|netw", Permissions.ANALYZE.getPermission(), CommandType.CONSOLE);
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.locale = locale;
+ this.connectionSystem = connectionSystem;
setShortHelp(locale.getString(CmdHelpLang.NETWORK));
setInDepthHelp(locale.getArray(DeepHelpLang.NETWORK));
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
sendNetworkMsg(sender);
}
- private void sendNetworkMsg(ISender sender) {
+ private void sendNetworkMsg(Sender sender) {
sender.sendMessage(locale.getString(CommandLang.HEADER_NETWORK));
// Link
- String url = ConnectionSystem.getAddress() + "/network/";
+ String url = connectionSystem.getMainAddress() + "/network/";
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
boolean console = !CommandUtils.isPlayer(sender);
if (console) {
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/QInspectCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/QInspectCommand.java
index 86ac1c98a..99b6cdbd8 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/QInspectCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/QInspectCommand.java
@@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.data.container.GeoInfo;
import com.djrapitops.plan.data.store.containers.PlayerContainer;
@@ -8,8 +7,6 @@ import com.djrapitops.plan.data.store.keys.PlayerKeys;
import com.djrapitops.plan.data.store.mutators.ActivityIndex;
import com.djrapitops.plan.data.store.mutators.GeoInfoMutator;
import com.djrapitops.plan.data.store.mutators.SessionsMutator;
-import com.djrapitops.plan.data.store.mutators.formatting.Formatter;
-import com.djrapitops.plan.data.store.mutators.formatting.Formatters;
import com.djrapitops.plan.data.store.objects.DateHolder;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.locale.Locale;
@@ -17,16 +14,22 @@ import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.locale.lang.GenericLang;
+import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions;
+import com.djrapitops.plan.system.settings.Settings;
+import com.djrapitops.plan.system.settings.config.PlanConfig;
import com.djrapitops.plan.utilities.MiscUtils;
+import com.djrapitops.plan.utilities.formatting.Formatter;
+import com.djrapitops.plan.utilities.formatting.Formatters;
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
-import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
-import com.djrapitops.plugin.command.ISender;
-import com.djrapitops.plugin.task.AbsRunnable;
-import com.djrapitops.plugin.task.RunnableFactory;
+import com.djrapitops.plugin.command.Sender;
+import com.djrapitops.plugin.logging.L;
+import com.djrapitops.plugin.logging.error.ErrorHandler;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@@ -38,27 +41,44 @@ import java.util.UUID;
* @author Rsl1122
* @since 1.0.0
*/
+@Singleton
public class QInspectCommand extends CommandNode {
private final Locale locale;
+ private final Database database;
+ private final PlanConfig config;
+ private final Processing processing;
+ private final Formatters formatters;
+ private final UUIDUtility uuidUtility;
+ private final ErrorHandler errorHandler;
- /**
- * Class Constructor.
- *
- * @param plugin Current instance of Plan
- */
- public QInspectCommand(PlanPlugin plugin) {
+ @Inject
+ public QInspectCommand(
+ PlanConfig config,
+ Locale locale,
+ Processing processing,
+ Database database,
+ UUIDUtility uuidUtility,
+ Formatters formatters,
+ ErrorHandler errorHandler
+ ) {
super("qinspect", Permissions.QUICK_INSPECT.getPermission(), CommandType.PLAYER_OR_ARGS);
+ this.config = config;
+ this.processing = processing;
+ this.formatters = formatters;
setArguments("");
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.locale = locale;
+ this.database = database;
+ this.uuidUtility = uuidUtility;
+ this.errorHandler = errorHandler;
setShortHelp(locale.getString(CmdHelpLang.QINSPECT));
setInDepthHelp(locale.getArray(DeepHelpLang.QINSPECT));
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
String playerName = MiscUtils.getPlayerName(args, sender, Permissions.QUICK_INSPECT_OTHER);
if (playerName == null) {
@@ -69,43 +89,42 @@ public class QInspectCommand extends CommandNode {
runInspectTask(playerName, sender);
}
- private void runInspectTask(String playerName, ISender sender) {
- RunnableFactory.createNew(new AbsRunnable("InspectTask") {
- @Override
- public void run() {
- try {
- UUID uuid = UUIDUtility.getUUIDOf(playerName);
- if (uuid == null) {
- sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_VALID));
- return;
- }
-
- PlayerContainer container = Database.getActive().fetch().getPlayerContainer(uuid);
- if (!container.getValue(PlayerKeys.REGISTERED).isPresent()) {
- sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_KNOWN));
- return;
- }
-
- sendMessages(sender, container);
- } catch (DBOpException e) {
- sender.sendMessage("§eDatabase exception occurred: " + e.getMessage());
- Log.toLog(this.getClass(), e);
- } finally {
- this.cancel();
+ private void runInspectTask(String playerName, Sender sender) {
+ processing.submitNonCritical(() -> {
+ try {
+ UUID uuid = uuidUtility.getUUIDOf(playerName);
+ if (uuid == null) {
+ sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_VALID));
+ return;
}
+
+ PlayerContainer container = database.fetch().getPlayerContainer(uuid);
+ if (!container.getValue(PlayerKeys.REGISTERED).isPresent()) {
+ sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_KNOWN));
+ return;
+ }
+
+ sendMessages(sender, container);
+ } catch (DBOpException e) {
+ sender.sendMessage("§eDatabase exception occurred: " + e.getMessage());
+ errorHandler.log(L.WARN, this.getClass(), e);
}
- }).runTaskAsynchronously();
+ });
}
- private void sendMessages(ISender sender, PlayerContainer player) {
+ private void sendMessages(Sender sender, PlayerContainer player) {
long now = System.currentTimeMillis();
- Formatter timestamp = Formatters.year();
- Formatter length = Formatters.timeAmount();
+ Formatter timestamp = formatters.year();
+ Formatter length = formatters.timeAmount();
String playerName = player.getValue(PlayerKeys.NAME).orElse(locale.getString(GenericLang.UNKNOWN));
- ActivityIndex activityIndex = player.getActivityIndex(now);
+ ActivityIndex activityIndex = player.getActivityIndex(
+ now,
+ config.getNumber(Settings.ACTIVE_PLAY_THRESHOLD),
+ config.getNumber(Settings.ACTIVE_LOGIN_THRESHOLD)
+ );
Long registered = player.getValue(PlayerKeys.REGISTERED).orElse(0L);
Long lastSeen = player.getValue(PlayerKeys.LAST_SEEN).orElse(0L);
List geoInfo = player.getValue(PlayerKeys.GEO_INFO).orElse(new ArrayList<>());
@@ -115,7 +134,7 @@ public class QInspectCommand extends CommandNode {
String[] messages = new String[]{
locale.getString(CommandLang.HEADER_INSPECT, playerName),
- locale.getString(CommandLang.QINSPECT_ACTIVITY_INDEX, activityIndex.getFormattedValue(), activityIndex.getGroup()),
+ locale.getString(CommandLang.QINSPECT_ACTIVITY_INDEX, activityIndex.getFormattedValue(formatters.decimals()), activityIndex.getGroup()),
locale.getString(CommandLang.QINSPECT_REGISTERED, timestamp.apply(() -> registered)),
locale.getString(CommandLang.QINSPECT_LAST_SEEN, timestamp.apply(() -> lastSeen)),
locale.getString(CommandLang.QINSPECT_GEOLOCATION, geolocation),
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/RegisterCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/RegisterCommand.java
index 133c5d583..dd45cd56e 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/RegisterCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/RegisterCommand.java
@@ -1,24 +1,26 @@
package com.djrapitops.plan.command.commands;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.data.WebUser;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
+import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.utilities.PassEncryptUtil;
import com.djrapitops.plugin.api.Check;
-import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.CommandUtils;
-import com.djrapitops.plugin.command.ISender;
-import com.djrapitops.plugin.task.AbsRunnable;
-import com.djrapitops.plugin.task.RunnableFactory;
+import com.djrapitops.plugin.command.Sender;
+import com.djrapitops.plugin.logging.L;
+import com.djrapitops.plugin.logging.console.PluginLogger;
+import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import java.util.Arrays;
/**
@@ -32,17 +34,31 @@ import java.util.Arrays;
* @author Rsl1122
* @since 3.5.2
*/
+@Singleton
public class RegisterCommand extends CommandNode {
private final String notEnoughArgsMsg;
- private final String hashErrorMsg;
private final Locale locale;
+ private final Processing processing;
+ private final Database database;
+ private final PluginLogger logger;
+ private final ErrorHandler errorHandler;
- public RegisterCommand(PlanPlugin plugin) {
+ @Inject
+ public RegisterCommand(
+ Locale locale,
+ Processing processing,
+ Database database,
+ PluginLogger logger,
+ ErrorHandler errorHandler) {
// No Permission Requirement
super("register", "", CommandType.PLAYER_OR_ARGS);
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.locale = locale;
+ this.processing = processing;
+ this.logger = logger;
+ this.database = database;
+ this.errorHandler = errorHandler;
setArguments("", "[name]", "[lvl]");
setShortHelp(locale.getString(CmdHelpLang.WEB_REGISTER));
@@ -52,11 +68,10 @@ public class RegisterCommand extends CommandNode {
}
notEnoughArgsMsg = locale.getString(CommandLang.FAIL_REQ_ARGS, 3, Arrays.toString(getArguments()));
- hashErrorMsg = "§cPassword hash error.";
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
try {
if (CommandUtils.isPlayer(sender)) {
playerRegister(args, sender);
@@ -64,16 +79,16 @@ public class RegisterCommand extends CommandNode {
consoleRegister(args, sender, notEnoughArgsMsg);
}
} catch (PassEncryptUtil.CannotPerformOperationException e) {
- Log.toLog(this.getClass().getSimpleName(), e);
- sender.sendMessage(hashErrorMsg);
+ errorHandler.log(L.WARN, this.getClass(), e);
+ sender.sendMessage("§cPassword hash error.");
} catch (NumberFormatException e) {
throw new NumberFormatException(args[2]);
} catch (Exception e) {
- Log.toLog(this.getClass().getSimpleName(), e);
+ errorHandler.log(L.WARN, this.getClass(), e);
}
}
- private void consoleRegister(String[] args, ISender sender, String notEnoughArgsMsg) throws PassEncryptUtil.CannotPerformOperationException {
+ private void consoleRegister(String[] args, Sender sender, String notEnoughArgsMsg) throws PassEncryptUtil.CannotPerformOperationException {
Verify.isTrue(args.length >= 3, () -> new IllegalArgumentException(notEnoughArgsMsg));
int permLevel;
@@ -82,7 +97,7 @@ public class RegisterCommand extends CommandNode {
registerUser(new WebUser(args[1], passHash, permLevel), sender);
}
- private void playerRegister(String[] args, ISender sender) throws PassEncryptUtil.CannotPerformOperationException {
+ private void playerRegister(String[] args, Sender sender) throws PassEncryptUtil.CannotPerformOperationException {
boolean registerSenderAsUser = args.length == 1;
if (registerSenderAsUser) {
String user = sender.getName();
@@ -96,7 +111,7 @@ public class RegisterCommand extends CommandNode {
}
}
- private int getPermissionLevel(ISender sender) {
+ private int getPermissionLevel(Sender sender) {
final String permAnalyze = Permissions.ANALYZE.getPerm();
final String permInspectOther = Permissions.INSPECT_OTHER.getPerm();
final String permInspect = Permissions.INSPECT.getPerm();
@@ -112,30 +127,22 @@ public class RegisterCommand extends CommandNode {
return 100;
}
- private void registerUser(WebUser webUser, ISender sender) {
- RunnableFactory.createNew(new AbsRunnable("Register WebUser Task") {
- @Override
- public void run() {
- final String existsMsg = locale.getString(CommandLang.FAIL_WEB_USER_EXISTS);
- final String userName = webUser.getName();
- final String successMsg = locale.getString(CommandLang.WEB_USER_REGISTER_SUCCESS);
- try {
- Database database = Database.getActive();
- boolean userExists = database.check().doesWebUserExists(userName);
- if (userExists) {
- sender.sendMessage(existsMsg);
- return;
- }
- database.save().webUser(webUser);
- sender.sendMessage(successMsg);
- Log.info(locale.getString(CommandLang.WEB_USER_REGISTER_NOTIFY, userName, webUser.getPermLevel()));
- } catch (Exception e) {
- Log.toLog(this.getClass(), e);
- } finally {
- this.cancel();
+ private void registerUser(WebUser webUser, Sender sender) {
+ processing.submitCritical(() -> {
+ String userName = webUser.getName();
+ try {
+ boolean userExists = database.check().doesWebUserExists(userName);
+ if (userExists) {
+ sender.sendMessage(locale.getString(CommandLang.FAIL_WEB_USER_EXISTS));
+ return;
}
+ database.save().webUser(webUser);
+ sender.sendMessage(locale.getString(CommandLang.WEB_USER_REGISTER_SUCCESS));
+ logger.info(locale.getString(CommandLang.WEB_USER_REGISTER_NOTIFY, userName, webUser.getPermLevel()));
+ } catch (Exception e) {
+ errorHandler.log(L.WARN, this.getClass(), e);
}
- }).runTaskAsynchronously();
+ });
}
/**
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/ReloadCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/ReloadCommand.java
index 4fb703aae..0cfe4fbdc 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/ReloadCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/ReloadCommand.java
@@ -6,13 +6,16 @@ import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.settings.Permissions;
-import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
-import com.djrapitops.plugin.command.ISender;
+import com.djrapitops.plugin.command.Sender;
+import com.djrapitops.plugin.logging.L;
+import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
+import javax.inject.Inject;
+
/**
* This SubCommand is used to reload the plugin.
*
@@ -23,26 +26,31 @@ public class ReloadCommand extends CommandNode {
private final PlanPlugin plugin;
private final Locale locale;
+ private final ErrorHandler errorHandler;
+ private final RunnableFactory runnableFactory;
- public ReloadCommand(PlanPlugin plugin) {
+ @Inject
+ public ReloadCommand(PlanPlugin plugin, Locale locale, RunnableFactory runnableFactory, ErrorHandler errorHandler) {
super("reload", Permissions.RELOAD.getPermission(), CommandType.CONSOLE);
- this.plugin = plugin;
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.plugin = plugin;
+ this.locale = locale;
+ this.runnableFactory = runnableFactory;
+ this.errorHandler = errorHandler;
setShortHelp(locale.getString(CmdHelpLang.RELOAD));
setInDepthHelp(locale.getArray(DeepHelpLang.RELOAD));
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
- RunnableFactory.createNew("Reload task", new AbsRunnable() {
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
+ runnableFactory.create("Reload task", new AbsRunnable() {
@Override
public void run() {
try {
plugin.reloadPlugin(true);
} catch (Exception e) {
- Log.toLog(this.getClass(), e);
+ errorHandler.log(L.CRITICAL, this.getClass(), e);
sender.sendMessage(locale.getString(CommandLang.RELOAD_FAILED));
}
sender.sendMessage(locale.getString(CommandLang.RELOAD_COMPLETE));
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/SearchCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/SearchCommand.java
index 5a0e33173..b42f2fd76 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/SearchCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/SearchCommand.java
@@ -1,24 +1,25 @@
package com.djrapitops.plan.command.commands;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.database.DBOpException;
+import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.locale.lang.ManageLang;
+import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions;
-import com.djrapitops.plan.utilities.MiscUtils;
-import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
-import com.djrapitops.plugin.command.ISender;
-import com.djrapitops.plugin.task.AbsRunnable;
-import com.djrapitops.plugin.task.RunnableFactory;
-import com.djrapitops.plugin.utilities.FormatUtils;
+import com.djrapitops.plugin.command.Sender;
+import com.djrapitops.plugin.logging.L;
+import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
/**
@@ -27,14 +28,26 @@ import java.util.List;
* @author Rsl1122
* @since 2.0.0
*/
+@Singleton
public class SearchCommand extends CommandNode {
private final Locale locale;
+ private final Processing processing;
+ private final Database database;
+ private final ErrorHandler errorHandler;
- public SearchCommand(PlanPlugin plugin) {
+ @Inject
+ public SearchCommand(
+ Locale locale,
+ Processing processing,
+ Database database,
+ ErrorHandler errorHandler) {
super("search", Permissions.SEARCH.getPermission(), CommandType.PLAYER_OR_ARGS);
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.locale = locale;
+ this.processing = processing;
+ this.database = database;
+ this.errorHandler = errorHandler;
setArguments("");
setShortHelp(locale.getString(CmdHelpLang.SEARCH));
@@ -42,7 +55,7 @@ public class SearchCommand extends CommandNode {
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
Verify.isTrue(args.length >= 1,
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
@@ -51,30 +64,26 @@ public class SearchCommand extends CommandNode {
runSearchTask(args, sender);
}
- private void runSearchTask(String[] args, ISender sender) {
- RunnableFactory.createNew(new AbsRunnable("SearchTask: " + Arrays.toString(args)) {
- @Override
- public void run() {
- try {
- String searchTerm = args[0];
- List names = MiscUtils.getMatchingPlayerNames(searchTerm);
+ private void runSearchTask(String[] args, Sender sender) {
+ processing.submitNonCritical(() -> {
+ try {
+ String searchTerm = args[0];
+ List names = database.search().matchingPlayers(searchTerm);
+ Collections.sort(names);
+ boolean empty = Verify.isEmpty(names);
- boolean empty = Verify.isEmpty(names);
-
- sender.sendMessage(locale.getString(CommandLang.HEADER_SEARCH, empty ? 0 : names.size(), searchTerm));
- // Results
- if (!empty) {
- sender.sendMessage(FormatUtils.collectionToStringNoBrackets(names));
- }
-
- sender.sendMessage(">");
- } catch (DBOpException e) {
- sender.sendMessage("§cDatabase error occurred: " + e.getMessage());
- Log.toLog(this.getClass(), e);
- } finally {
- this.cancel();
+ sender.sendMessage(locale.getString(CommandLang.HEADER_SEARCH, empty ? 0 : names.size(), searchTerm));
+ // Results
+ if (!empty) {
+ String message = names.toString();
+ sender.sendMessage(message.substring(1, message.length() - 1));
}
+
+ sender.sendMessage(">");
+ } catch (DBOpException e) {
+ sender.sendMessage("§cDatabase error occurred: " + e.getMessage());
+ errorHandler.log(L.ERROR, this.getClass(), e);
}
- }).runTaskAsynchronously();
+ });
}
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/UpdateCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/UpdateCommand.java
deleted file mode 100644
index 7e34f18aa..000000000
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/UpdateCommand.java
+++ /dev/null
@@ -1,237 +0,0 @@
-package com.djrapitops.plan.command.commands;
-
-import com.djrapitops.plan.PlanPlugin;
-import com.djrapitops.plan.api.exceptions.connection.*;
-import com.djrapitops.plan.api.exceptions.database.DBOpException;
-import com.djrapitops.plan.command.commands.manage.ManageConDebugCommand;
-import com.djrapitops.plan.system.database.databases.Database;
-import com.djrapitops.plan.system.database.databases.operation.FetchOperations;
-import com.djrapitops.plan.system.info.InfoSystem;
-import com.djrapitops.plan.system.info.request.UpdateCancelRequest;
-import com.djrapitops.plan.system.info.request.UpdateRequest;
-import com.djrapitops.plan.system.info.server.Server;
-import com.djrapitops.plan.system.locale.Locale;
-import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
-import com.djrapitops.plan.system.locale.lang.CommandLang;
-import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
-import com.djrapitops.plan.system.locale.lang.PluginLang;
-import com.djrapitops.plan.system.settings.Permissions;
-import com.djrapitops.plan.system.update.VersionCheckSystem;
-import com.djrapitops.plan.system.update.VersionInfo;
-import com.djrapitops.plan.system.webserver.WebServerSystem;
-import com.djrapitops.plugin.api.utility.log.Log;
-import com.djrapitops.plugin.command.CommandNode;
-import com.djrapitops.plugin.command.CommandType;
-import com.djrapitops.plugin.command.CommandUtils;
-import com.djrapitops.plugin.command.ISender;
-import com.djrapitops.plugin.task.AbsRunnable;
-import com.djrapitops.plugin.task.RunnableFactory;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.UUID;
-
-/**
- * Command that updates all servers in the network
- *
- * @author Rsl1122
- */
-public class UpdateCommand extends CommandNode {
-
- private final Locale locale;
-
- public UpdateCommand(PlanPlugin plugin) {
- super("update", Permissions.MANAGE.getPermission(), CommandType.ALL);
-
- locale = plugin.getSystem().getLocaleSystem().getLocale();
-
- setArguments("[-u]/[cancel]");
- setShortHelp(locale.getString(CmdHelpLang.UPDATE));
- setInDepthHelp(locale.getArray(DeepHelpLang.UPDATE));
- }
-
- @Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
- if (!VersionCheckSystem.isNewVersionAvailable()) {
- sender.sendMessage("§a" + locale.getString(PluginLang.VERSION_NEWEST));
- return;
- }
-
- VersionInfo available = VersionCheckSystem.getInstance().getNewVersionAvailable();
- String downloadUrl = available.getDownloadUrl();
-
- if (!available.isTrusted()) {
- sender.sendMessage(locale.getString(CommandLang.UPDATE_WRONG_URL, "https://github.com/Rsl1122/Plan-PlayerAnalytics/releases/"));
- sender.sendLink(downloadUrl, downloadUrl);
- return;
- }
-
- if (args.length == 0) {
- String message = locale.getString(CommandLang.UPDATE_CHANGE_LOG, available.getVersion().toString());
- String url = available.getChangeLogUrl();
- if (CommandUtils.isConsole(sender)) {
- sender.sendMessage(message + url);
- } else {
- sender.sendMessage(message);
- sender.sendLink(" ", locale.getString(CommandLang.LINK_CLICK_ME), url);
- }
- return;
- }
-
- String firstArgument = args[0];
- RunnableFactory.createNew("Update Command Task", new AbsRunnable() {
- @Override
- public void run() {
- try {
- if ("-u".equals(firstArgument)) {
- handleUpdate(sender, args);
- } else if ("cancel".equals(firstArgument)) {
- handleCancel(sender);
- } else {
- throw new IllegalArgumentException("Unknown argument, use '-u' or 'cancel'");
- }
- } finally {
- cancel();
- }
- }
- }).runTaskAsynchronously();
- }
-
- private void handleCancel(ISender sender) {
- try {
- cancel(sender, Database.getActive().fetch().getServers());
- sender.sendMessage(locale.getString(CommandLang.UPDATE_CANCEL_SUCCESS));
- } catch (DBOpException e) {
- sender.sendMessage("§cDatabase error occurred, cancel could not be performed.");
- Log.toLog(this.getClass().getName(), e);
- }
- }
-
- private void handleUpdate(ISender sender, String[] args) {
- sender.sendMessage(locale.getString(CommandLang.UPDATE_NOTIFY_CANCEL));
- sender.sendMessage(locale.getString(CommandLang.UPDATE_ONLINE_CHECK));
- if (!checkNetworkStatus(sender)) {
- sender.sendMessage(locale.getString(CommandLang.UPDATE_FAIL_NOT_ONLINE));
- // If -force, continue, otherwise return.
- if (args.length < 2 || !"-force".equals(args[1])) {
- return;
- }
- }
- try {
- List servers = Database.getActive().fetch().getServers();
- update(sender, servers, args);
- } catch (DBOpException e) {
- Log.toLog(this.getClass().getName(), e);
- }
- }
-
- private void update(ISender sender, List servers, String[] args) {
- for (Server server : servers) {
- if (update(sender, server)) {
- sender.sendMessage(locale.getString(CommandLang.UPDATE_SCHEDULED, server.getName()));
- } else {
- if (args.length > 1 && "-force".equals(args[1])) {
- sender.sendMessage(locale.getString(CommandLang.UPDATE_FAIL_FORCED));
- continue;
- }
- sender.sendMessage(locale.getString(CommandLang.UPDATE_FAIL_CANCEL));
- cancel(sender, servers);
- sender.sendMessage(locale.getString(CommandLang.UPDATE_CANCELLED));
- break;
- }
- }
- }
-
- private void cancel(ISender sender, List servers) {
- for (Server server : servers) {
- cancel(sender, server);
- }
- }
-
- private void cancel(ISender sender, Server server) {
- try {
- InfoSystem.getInstance().getConnectionSystem().sendInfoRequest(new UpdateCancelRequest(), server);
- } catch (ForbiddenException | GatewayException | InternalErrorException e) {
- sender.sendMessage("§cCancel failed on " + server.getName() + ": Odd Exception: " + e.getClass().getSimpleName());
- } catch (UnauthorizedServerException e) {
- sender.sendMessage("§cCancel failed on " + server.getName() + ": Unauthorized. " + server.getName() + " might be using different database.");
- } catch (ConnectionFailException e) {
- sender.sendMessage("§cCancel failed on " + server.getName() + ": " + e.getCause().getClass().getSimpleName() + " " + e.getCause().getMessage());
- String address = server.getWebAddress();
- boolean local = address.contains("localhost")
- || address.startsWith("https://:") // IP empty = Localhost
- || address.startsWith("http://:") // IP empty = Localhost
- || address.contains("127.0.0.1");
- if (!local) {
- sender.sendMessage("§cNon-local address, check that port is open");
- }
- } catch (NotFoundException e) {
- /* Ignored, older version */
- } catch (WebException e) {
- sender.sendMessage("§cCancel failed on " + server.getName() + ": Odd Exception:" + e.getClass().getSimpleName());
- }
- }
-
- private boolean update(ISender sender, Server server) {
- try {
- InfoSystem.getInstance().getConnectionSystem().sendInfoRequest(new UpdateRequest(), server);
- return true;
- } catch (BadRequestException e) {
- sender.sendMessage("§c" + server.getName() + " has Allow-Update set to false, aborting update.");
- return false;
- } catch (ForbiddenException | GatewayException | InternalErrorException | NoServersException e) {
- sender.sendMessage("§c" + server.getName() + ": Odd Exception: " + e.getClass().getSimpleName());
- return false;
- } catch (UnauthorizedServerException e) {
- sender.sendMessage("§cFail reason: Unauthorized. " + server.getName() + " might be using different database.");
- return false;
- } catch (ConnectionFailException e) {
- sender.sendMessage("§cFail reason: " + e.getCause().getClass().getSimpleName() + " " + e.getCause().getMessage());
- String address = server.getWebAddress();
- boolean local = address.contains("localhost")
- || address.startsWith("https://:") // IP empty = Localhost
- || address.startsWith("http://:") // IP empty = Localhost
- || address.contains("127.0.0.1");
- if (!local) {
- sender.sendMessage("§cNon-local address, check that port is open");
- }
- return false;
- } catch (NotFoundException e) {
- sender.sendMessage("§e" + server.getName() + " is using older version and can not be scheduled for update. " +
- "You can update it manually, update will proceed.");
- return true;
- } catch (WebException e) {
- sender.sendMessage("§eOdd Exception: " + e.getClass().getSimpleName());
- return false;
- }
- }
-
- private boolean checkNetworkStatus(ISender sender) {
- try {
- FetchOperations fetch = Database.getActive().fetch();
- Optional bungeeInformation = fetch.getBungeeInformation();
- if (!bungeeInformation.isPresent()) {
- sender.sendMessage("Bungee address not found in the database, assuming this is not a network.");
- return true;
- }
- Map bukkitServers = fetch.getBukkitServers();
- String accessAddress = WebServerSystem.getInstance().getWebServer().getAccessAddress();
- boolean success = true;
- for (Server server : bukkitServers.values()) {
- if (!ManageConDebugCommand.testServer(sender, accessAddress, server, locale)) {
- success = false;
- }
- }
- Server bungee = bungeeInformation.get();
- if (!ManageConDebugCommand.testServer(sender, accessAddress, bungee, locale)) {
- success = false;
- }
- return success;
- } catch (DBOpException e) {
- sender.sendMessage("§cDatabase error occurred, update has been cancelled.");
- Log.toLog(this.getClass().getName(), e);
- return false;
- }
- }
-}
\ No newline at end of file
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/WebUserCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/WebUserCommand.java
index 61eacf38f..dfbcbcb9c 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/WebUserCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/WebUserCommand.java
@@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.command.commands.webuser.WebCheckCommand;
import com.djrapitops.plan.command.commands.webuser.WebDeleteCommand;
import com.djrapitops.plan.command.commands.webuser.WebLevelCommand;
@@ -9,9 +8,14 @@ import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.settings.Permissions;
+import com.djrapitops.plugin.command.ColorScheme;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.TreeCmdNode;
+import dagger.Lazy;
+
+import javax.inject.Inject;
+import javax.inject.Named;
/**
* Web subcommand used to manage Web users.
@@ -21,20 +25,25 @@ import com.djrapitops.plugin.command.TreeCmdNode;
*/
public class WebUserCommand extends TreeCmdNode {
- public WebUserCommand(PlanPlugin plugin, RegisterCommand register, CommandNode parent) {
- super("webuser|web", Permissions.MANAGE_WEB.getPerm(), CommandType.CONSOLE, parent);
- super.setColorScheme(plugin.getColorScheme());
-
- Locale locale = plugin.getSystem().getLocaleSystem().getLocale();
+ @Inject
+ public WebUserCommand(ColorScheme colorScheme, Locale locale, @Named("mainCommand") Lazy parent,
+ RegisterCommand registerCommand,
+ WebLevelCommand levelCommand,
+ WebListUsersCommand listUsersCommand,
+ WebCheckCommand checkCommand,
+ WebDeleteCommand deleteCommand
+ ) {
+ super("webuser|web", Permissions.MANAGE_WEB.getPerm(), CommandType.CONSOLE, parent.get());
+ super.setColorScheme(colorScheme);
setShortHelp(locale.getString(CmdHelpLang.WEB));
setInDepthHelp(locale.getArray(DeepHelpLang.WEB));
CommandNode[] webGroup = {
- register,
- new WebLevelCommand(plugin),
- new WebListUsersCommand(plugin),
- new WebCheckCommand(plugin),
- new WebDeleteCommand(plugin)
+ registerCommand,
+ levelCommand,
+ listUsersCommand,
+ checkCommand,
+ deleteCommand
};
setNodeGroups(webGroup);
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java
index 61c7cb34c..6a7d3995b 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java
@@ -1,9 +1,7 @@
package com.djrapitops.plan.command.commands.manage;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
-import com.djrapitops.plan.data.store.mutators.formatting.Formatters;
import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.database.databases.sql.SQLiteDB;
@@ -12,15 +10,19 @@ import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.locale.lang.ManageLang;
+import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions;
-import com.djrapitops.plugin.api.utility.log.Log;
+import com.djrapitops.plan.utilities.formatting.Formatter;
+import com.djrapitops.plan.utilities.formatting.Formatters;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
-import com.djrapitops.plugin.command.ISender;
-import com.djrapitops.plugin.task.AbsRunnable;
-import com.djrapitops.plugin.task.RunnableFactory;
+import com.djrapitops.plugin.command.Sender;
+import com.djrapitops.plugin.logging.L;
+import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import java.util.Arrays;
import java.util.Collection;
import java.util.UUID;
@@ -31,14 +33,35 @@ import java.util.UUID;
* @author Rsl1122
* @since 2.3.0
*/
+@Singleton
public class ManageBackupCommand extends CommandNode {
private final Locale locale;
+ private final Processing processing;
+ private final DBSystem dbSystem;
+ private final SQLiteDB.Factory sqliteFactory;
+ private final ErrorHandler errorHandler;
- public ManageBackupCommand(PlanPlugin plugin) {
+ private final Formatter iso8601LongFormatter;
+
+ @Inject
+ public ManageBackupCommand(
+ Locale locale,
+ Processing processing,
+ DBSystem dbSystem,
+ SQLiteDB.Factory sqliteFactory,
+ Formatters formatters,
+ ErrorHandler errorHandler
+ ) {
super("backup", Permissions.MANAGE.getPermission(), CommandType.CONSOLE);
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.locale = locale;
+ this.processing = processing;
+ this.dbSystem = dbSystem;
+ this.sqliteFactory = sqliteFactory;
+ this.errorHandler = errorHandler;
+
+ this.iso8601LongFormatter = formatters.iso8601NoClockLong();
setShortHelp(locale.getString(CmdHelpLang.MANAGE_BACKUP));
setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE_BACKUP));
@@ -47,7 +70,7 @@ public class ManageBackupCommand extends CommandNode {
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
try {
Verify.isTrue(args.length >= 1,
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
@@ -58,7 +81,8 @@ public class ManageBackupCommand extends CommandNode {
Verify.isTrue(isCorrectDB,
() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_INCORRECT_DB, dbName)));
- Database database = DBSystem.getActiveDatabaseByName(dbName);
+ Database database = dbSystem.getActiveDatabaseByName(dbName);
+ database.init();
runBackupTask(sender, args, database);
} catch (DBInitException e) {
@@ -66,24 +90,17 @@ public class ManageBackupCommand extends CommandNode {
}
}
- private void runBackupTask(ISender sender, String[] args, Database database) {
- RunnableFactory.createNew(new AbsRunnable("BackupTask") {
- @Override
- public void run() {
- try {
- Log.debug("Backup", "Start");
- sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
- createNewBackup(args[0], database);
- sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
- } catch (Exception e) {
- Log.toLog(ManageBackupCommand.class, e);
- sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
- } finally {
- Log.logDebug("Backup");
- this.cancel();
- }
+ private void runBackupTask(Sender sender, String[] args, Database database) {
+ processing.submitCritical(() -> {
+ try {
+ sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
+ createNewBackup(args[0], database);
+ sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
+ } catch (Exception e) {
+ errorHandler.log(L.ERROR, ManageBackupCommand.class, e);
+ sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
}
- }).runTaskAsynchronously();
+ });
}
/**
@@ -95,9 +112,9 @@ public class ManageBackupCommand extends CommandNode {
private void createNewBackup(String dbName, Database copyFromDB) {
SQLiteDB backupDB = null;
try {
- String timeStamp = Formatters.iso8601NoClock().apply(System::currentTimeMillis);
+ String timeStamp = iso8601LongFormatter.apply(System.currentTimeMillis());
String fileName = dbName + "-backup-" + timeStamp;
- backupDB = new SQLiteDB(fileName, () -> locale);
+ backupDB = sqliteFactory.usingFileCalled(fileName);
Collection uuids = copyFromDB.fetch().getSavedUUIDs();
if (uuids.isEmpty()) {
return;
@@ -105,7 +122,7 @@ public class ManageBackupCommand extends CommandNode {
backupDB.init();
copyFromDB.backup().backup(backupDB);
} catch (DBException e) {
- Log.toLog(this.getClass(), e);
+ errorHandler.log(L.ERROR, this.getClass(), e);
} finally {
if (backupDB != null) {
backupDB.close();
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageClearCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageClearCommand.java
index 3da5ee20b..e3c153c8f 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageClearCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageClearCommand.java
@@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands.manage;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.system.database.DBSystem;
@@ -10,15 +9,17 @@ import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.locale.lang.ManageLang;
+import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions;
-import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
-import com.djrapitops.plugin.command.ISender;
-import com.djrapitops.plugin.task.AbsRunnable;
-import com.djrapitops.plugin.task.RunnableFactory;
+import com.djrapitops.plugin.command.Sender;
+import com.djrapitops.plugin.logging.L;
+import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import java.util.Arrays;
/**
@@ -27,14 +28,27 @@ import java.util.Arrays;
* @author Rsl1122
* @since 2.3.0
*/
+@Singleton
public class ManageClearCommand extends CommandNode {
private final Locale locale;
+ private final Processing processing;
+ private final DBSystem dbSystem;
+ private final ErrorHandler errorHandler;
- public ManageClearCommand(PlanPlugin plugin) {
+ @Inject
+ public ManageClearCommand(
+ Locale locale,
+ Processing processing,
+ DBSystem dbSystem,
+ ErrorHandler errorHandler
+ ) {
super("clear", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.locale = locale;
+ this.processing = processing;
+ this.dbSystem = dbSystem;
+ this.errorHandler = errorHandler;
setArguments("", "[-a]");
setShortHelp(locale.getString(CmdHelpLang.MANAGE_CLEAR));
@@ -42,7 +56,7 @@ public class ManageClearCommand extends CommandNode {
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
Verify.isTrue(args.length >= 1,
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
@@ -58,30 +72,26 @@ public class ManageClearCommand extends CommandNode {
}
try {
- Database database = DBSystem.getActiveDatabaseByName(dbName);
+ Database database = dbSystem.getActiveDatabaseByName(dbName);
+ database.init();
runClearTask(sender, database);
} catch (DBInitException e) {
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
}
}
- private void runClearTask(ISender sender, Database database) {
- RunnableFactory.createNew(new AbsRunnable("DBClearTask") {
- @Override
- public void run() {
- try {
- sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
+ private void runClearTask(Sender sender, Database database) {
+ processing.submitCritical(() -> {
+ try {
+ sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
- database.remove().everything();
+ database.remove().everything();
- sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
- } catch (DBOpException e) {
- sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
- Log.toLog(this.getClass(), e);
- } finally {
- this.cancel();
- }
+ sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
+ } catch (DBOpException e) {
+ sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
+ errorHandler.log(L.ERROR, this.getClass(), e);
}
- }).runTaskAsynchronously();
+ });
}
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageConDebugCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageConDebugCommand.java
index 8c1f163cd..aadd3fc02 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageConDebugCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageConDebugCommand.java
@@ -1,10 +1,9 @@
package com.djrapitops.plan.command.commands.manage;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.connection.*;
import com.djrapitops.plan.system.database.databases.Database;
-import com.djrapitops.plan.system.info.InfoSystem;
-import com.djrapitops.plan.system.info.request.CheckConnectionRequest;
+import com.djrapitops.plan.system.info.connection.ConnectionSystem;
+import com.djrapitops.plan.system.info.request.InfoRequestFactory;
import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.locale.Locale;
@@ -14,13 +13,15 @@ import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.locale.lang.ManageLang;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions;
-import com.djrapitops.plan.system.webserver.WebServerSystem;
+import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plugin.api.Check;
+import com.djrapitops.plugin.command.ColorScheme;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
-import com.djrapitops.plugin.command.ISender;
-import com.djrapitops.plugin.settings.ColorScheme;
+import com.djrapitops.plugin.command.Sender;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import java.util.List;
import java.util.UUID;
@@ -30,20 +31,45 @@ import java.util.UUID;
* @author Rsl1122
* @since 2.3.0
*/
+@Singleton
public class ManageConDebugCommand extends CommandNode {
+ private final ColorScheme colorScheme;
private final Locale locale;
+ private final Processing processing;
+ private final ServerInfo serverInfo;
+ private final ConnectionSystem connectionSystem;
+ private final InfoRequestFactory infoRequestFactory;
+ private final WebServer webServer;
+ private final Database database;
- public ManageConDebugCommand(PlanPlugin plugin) {
+ @Inject
+ public ManageConDebugCommand(
+ ColorScheme colorScheme,
+ Locale locale,
+ Processing processing,
+ ServerInfo serverInfo,
+ ConnectionSystem connectionSystem,
+ InfoRequestFactory infoRequestFactory,
+ WebServer webServer,
+ Database database
+ ) {
super("con", Permissions.MANAGE.getPermission(), CommandType.ALL);
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.colorScheme = colorScheme;
+ this.locale = locale;
+ this.processing = processing;
+ this.serverInfo = serverInfo;
+ this.connectionSystem = connectionSystem;
+ this.infoRequestFactory = infoRequestFactory;
+ this.webServer = webServer;
+ this.database = database;
setShortHelp(locale.getString(Check.isBungeeAvailable() ? CmdHelpLang.CON : CmdHelpLang.MANAGE_CON));
setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE_CON));
}
- public static boolean testServer(ISender sender, String accessAddress, Server server, Locale locale) {
+ private void testServer(Sender sender, String accessAddress, Server server, Locale locale) {
String address = server.getWebAddress().toLowerCase();
boolean usingHttps = address.startsWith("https");
boolean local = address.contains("localhost")
@@ -52,11 +78,8 @@ public class ManageConDebugCommand extends CommandNode {
|| address.contains("127.0.0.1");
try {
-
- InfoSystem.getInstance().getConnectionSystem().sendInfoRequest(new CheckConnectionRequest(accessAddress), server);
+ connectionSystem.sendInfoRequest(infoRequestFactory.checkConnectionRequest(address), server);
sender.sendMessage(getMsgFor(address, usingHttps, local, true, true));
- return true;
-
} catch (ForbiddenException | BadRequestException | InternalErrorException e) {
sender.sendMessage(getMsgFor(address, usingHttps, local, false, false));
sender.sendMessage(locale.getString(ManageLang.CON_EXCEPTION, e.getClass().getSimpleName()));
@@ -78,28 +101,27 @@ public class ManageConDebugCommand extends CommandNode {
sender.sendMessage(getMsgFor(address, usingHttps, local, false, false));
sender.sendMessage(locale.getString(ManageLang.CON_EXCEPTION, e.getClass().getSimpleName()));
}
- return false;
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
- if (!WebServerSystem.isWebServerEnabled()) {
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
+ if (!webServer.isEnabled()) {
sender.sendMessage(locale.getString(CommandLang.CONNECT_WEBSERVER_NOT_ENABLED));
return;
}
- Processing.submitNonCritical(() -> testServers(sender));
+ processing.submitNonCritical(() -> testServers(sender));
}
- private void testServers(ISender sender) {
- List servers = Database.getActive().fetch().getServers();
+ private void testServers(Sender sender) {
+ List servers = database.fetch().getServers();
if (servers.isEmpty()) {
sender.sendMessage(locale.getString(ManageLang.CON_NO_SERVERS));
}
- String accessAddress = WebServerSystem.getInstance().getWebServer().getAccessAddress();
- UUID thisServer = ServerInfo.getServerUUID();
+ String accessAddress = webServer.getAccessAddress();
+ UUID thisServer = serverInfo.getServerUUID();
for (Server server : servers) {
if (thisServer.equals(server.getUuid())) {
continue;
@@ -108,10 +130,9 @@ public class ManageConDebugCommand extends CommandNode {
}
}
- private static String getMsgFor(String address, boolean usingHttps, boolean local, boolean successTo, boolean successFrom) {
- ColorScheme cs = PlanPlugin.getInstance().getColorScheme();
- String tCol = cs.getTertiaryColor();
- String sCol = cs.getSecondaryColor();
+ private String getMsgFor(String address, boolean usingHttps, boolean local, boolean successTo, boolean successFrom) {
+ String tCol = colorScheme.getTertiaryColor();
+ String sCol = colorScheme.getSecondaryColor();
return tCol + address + sCol + ": "
+ (usingHttps ? "HTTPS" : "HTTP") + " : "
+ (local ? "Local" : "External") + " : "
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageDisableCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageDisableCommand.java
index 30725c900..963c9c95c 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageDisableCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageDisableCommand.java
@@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands.manage;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.listeners.bukkit.PlayerOnlineListener;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
@@ -9,9 +8,10 @@ import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
-import com.djrapitops.plugin.command.ISender;
+import com.djrapitops.plugin.command.Sender;
import com.djrapitops.plugin.utilities.Verify;
+import javax.inject.Inject;
import java.util.Arrays;
/**
@@ -24,10 +24,11 @@ public class ManageDisableCommand extends CommandNode {
private final Locale locale;
- public ManageDisableCommand(PlanPlugin plugin) {
+ @Inject
+ public ManageDisableCommand(Locale locale) {
super("disable", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.locale = locale;
setArguments("");
setShortHelp(locale.getString(CmdHelpLang.MANAGE_DISABLE));
@@ -35,7 +36,7 @@ public class ManageDisableCommand extends CommandNode {
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
Verify.isTrue(args.length >= 1,
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageHotSwapCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageHotSwapCommand.java
index d8194edce..f2129231b 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageHotSwapCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageHotSwapCommand.java
@@ -9,12 +9,16 @@ import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.ManageLang;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.Settings;
-import com.djrapitops.plugin.api.utility.log.Log;
+import com.djrapitops.plan.system.settings.config.PlanConfig;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
-import com.djrapitops.plugin.command.ISender;
+import com.djrapitops.plugin.command.Sender;
+import com.djrapitops.plugin.logging.L;
+import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify;
+import javax.inject.Inject;
+import java.io.IOException;
import java.util.Arrays;
/**
@@ -28,19 +32,26 @@ public class ManageHotSwapCommand extends CommandNode {
private final PlanPlugin plugin;
private final Locale locale;
+ private final DBSystem dbSystem;
+ private final PlanConfig config;
+ private final ErrorHandler errorHandler;
- public ManageHotSwapCommand(PlanPlugin plugin) {
+ @Inject
+ public ManageHotSwapCommand(PlanPlugin plugin, Locale locale, DBSystem dbSystem, PlanConfig config, ErrorHandler errorHandler) {
super("hotswap", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
- this.plugin = plugin;
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.plugin = plugin;
+ this.locale = locale;
+ this.dbSystem = dbSystem;
+ this.config = config;
+ this.errorHandler = errorHandler;
setArguments("");
setShortHelp(locale.getString(CmdHelpLang.MANAGE_HOTSWAP));
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
Verify.isTrue(args.length >= 1,
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
@@ -50,24 +61,29 @@ public class ManageHotSwapCommand extends CommandNode {
Verify.isTrue(isCorrectDB,
() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_INCORRECT_DB, dbName)));
- Verify.isFalse(dbName.equals(Database.getActive().getConfigName()),
+ Verify.isFalse(dbName.equals(dbSystem.getActiveDatabase().getConfigName()),
() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_SAME_DB)));
try {
- Database database = DBSystem.getActiveDatabaseByName(dbName);
+ Database database = dbSystem.getActiveDatabaseByName(dbName);
+ database.init();
if (!database.isOpen()) {
return;
}
} catch (Exception e) {
- Log.toLog(this.getClass(), e);
+ errorHandler.log(L.ERROR, this.getClass(), e);
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
return;
}
- Settings.DB_TYPE.set(dbName);
-
- Settings.save();
+ try {
+ config.set(Settings.DB_TYPE, dbName);
+ config.save();
+ } catch (IOException e) {
+ errorHandler.log(L.ERROR, this.getClass(), e);
+ return;
+ }
plugin.reloadPlugin(true);
}
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageImportCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageImportCommand.java
index 86dcfd8e8..82f4d3f5c 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageImportCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageImportCommand.java
@@ -1,22 +1,23 @@
package com.djrapitops.plan.command.commands.manage;
-import com.djrapitops.plan.PlanPlugin;
+import com.djrapitops.plan.system.importing.ImportSystem;
+import com.djrapitops.plan.system.importing.importers.Importer;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.locale.lang.ManageLang;
-import com.djrapitops.plan.system.processing.importing.ImporterManager;
-import com.djrapitops.plan.system.processing.importing.importers.Importer;
+import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
-import com.djrapitops.plugin.command.ISender;
-import com.djrapitops.plugin.task.AbsRunnable;
-import com.djrapitops.plugin.task.RunnableFactory;
+import com.djrapitops.plugin.command.Sender;
import com.djrapitops.plugin.utilities.Verify;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import java.util.Arrays;
+import java.util.Optional;
/**
* This manage SubCommand is used to import data from 3rd party plugins.
@@ -24,14 +25,24 @@ import java.util.Arrays;
* @author Rsl1122
* @since 2.3.0
*/
+@Singleton
public class ManageImportCommand extends CommandNode {
private final Locale locale;
+ private final Processing processing;
+ private final ImportSystem importSystem;
- public ManageImportCommand(PlanPlugin plugin) {
+ @Inject
+ public ManageImportCommand(
+ Locale locale,
+ Processing processing,
+ ImportSystem importSystem
+ ) {
super("import", Permissions.MANAGE.getPermission(), CommandType.CONSOLE);
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.locale = locale;
+ this.processing = processing;
+ this.importSystem = importSystem;
setArguments("/list", "[import args]");
setShortHelp(locale.getString(CmdHelpLang.MANAGE_IMPORT));
@@ -39,7 +50,7 @@ public class ManageImportCommand extends CommandNode {
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
Verify.isTrue(args.length >= 1,
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ARGS, "1+", Arrays.toString(this.getArguments()))));
@@ -47,28 +58,20 @@ public class ManageImportCommand extends CommandNode {
if (importArg.equals("list")) {
sender.sendMessage(locale.getString(ManageLang.IMPORTERS));
- ImporterManager.getImporters().stream()
- .map(Importer::getNames)
- .map(list -> list.get(0))
- .forEach(name -> sender.sendMessage("- " + name));
+ importSystem.getImporterNames().forEach(name -> sender.sendMessage("- " + name));
return;
}
- Importer importer = ImporterManager.getImporter(importArg);
- if (importer == null) {
+ findImporter(sender, importArg);
+ }
+
+ private void findImporter(Sender sender, String importArg) {
+ Optional foundImporter = importSystem.getImporter(importArg);
+ if (foundImporter.isPresent()) {
+ Importer importer = foundImporter.get();
+ processing.submitNonCritical(importer::processImport);
+ } else {
sender.sendMessage(locale.getString(ManageLang.FAIL_IMPORTER_NOT_FOUND, importArg));
- return;
}
-
- RunnableFactory.createNew("Import:" + importArg, new AbsRunnable() {
- @Override
- public void run() {
- try {
- importer.processImport();
- } finally {
- cancel();
- }
- }
- }).runTaskAsynchronously();
}
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageMoveCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageMoveCommand.java
index 4f8d59075..31a1dd1f8 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageMoveCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageMoveCommand.java
@@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands.manage;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.locale.Locale;
@@ -8,15 +7,17 @@ import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.locale.lang.ManageLang;
+import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions;
-import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
-import com.djrapitops.plugin.command.ISender;
-import com.djrapitops.plugin.task.AbsRunnable;
-import com.djrapitops.plugin.task.RunnableFactory;
+import com.djrapitops.plugin.command.Sender;
+import com.djrapitops.plugin.logging.L;
+import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import java.util.Arrays;
/**
@@ -27,14 +28,27 @@ import java.util.Arrays;
* @author Rsl1122
* @since 2.3.0
*/
+@Singleton
public class ManageMoveCommand extends CommandNode {
private final Locale locale;
+ private final Processing processing;
+ private final DBSystem dbSystem;
+ private final ErrorHandler errorHandler;
- public ManageMoveCommand(PlanPlugin plugin) {
+ @Inject
+ public ManageMoveCommand(
+ Locale locale,
+ Processing processing,
+ DBSystem dbSystem,
+ ErrorHandler errorHandler
+ ) {
super("move", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.locale = locale;
+ this.processing = processing;
+ this.dbSystem = dbSystem;
+ this.errorHandler = errorHandler;
setArguments("", "", "[-a]");
setShortHelp(locale.getString(CmdHelpLang.MANAGE_MOVE));
@@ -42,7 +56,7 @@ public class ManageMoveCommand extends CommandNode {
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
Verify.isTrue(args.length >= 2,
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ARGS, 2, Arrays.toString(this.getArguments()))));
@@ -65,8 +79,10 @@ public class ManageMoveCommand extends CommandNode {
}
try {
- final Database fromDatabase = DBSystem.getActiveDatabaseByName(fromDB);
- final Database toDatabase = DBSystem.getActiveDatabaseByName(toDB);
+ final Database fromDatabase = dbSystem.getActiveDatabaseByName(fromDB);
+ final Database toDatabase = dbSystem.getActiveDatabaseByName(toDB);
+ fromDatabase.init();
+ toDatabase.init();
runMoveTask(fromDatabase, toDatabase, sender);
} catch (Exception e) {
@@ -74,28 +90,23 @@ public class ManageMoveCommand extends CommandNode {
}
}
- private void runMoveTask(final Database fromDatabase, final Database toDatabase, ISender sender) {
- RunnableFactory.createNew(new AbsRunnable("DBMoveTask") {
- @Override
- public void run() {
- try {
- sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
+ private void runMoveTask(final Database fromDatabase, final Database toDatabase, Sender sender) {
+ processing.submitCritical(() -> {
+ try {
+ sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
- fromDatabase.backup().backup(toDatabase);
+ fromDatabase.backup().backup(toDatabase);
- sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
+ sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
- boolean movingToCurrentDB = toDatabase.getConfigName().equalsIgnoreCase(Database.getActive().getConfigName());
- if (movingToCurrentDB) {
- sender.sendMessage(locale.getString(ManageLang.HOTSWAP_REMINDER, toDatabase.getConfigName()));
- }
- } catch (Exception e) {
- Log.toLog(this.getClass(), e);
- sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
- } finally {
- this.cancel();
+ boolean movingToCurrentDB = toDatabase.getConfigName().equalsIgnoreCase(dbSystem.getActiveDatabase().getConfigName());
+ if (movingToCurrentDB) {
+ sender.sendMessage(locale.getString(ManageLang.HOTSWAP_REMINDER, toDatabase.getConfigName()));
}
+ } catch (Exception e) {
+ errorHandler.log(L.ERROR, this.getClass(), e);
+ sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
}
- }).runTaskAsynchronously();
+ });
}
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRawDataCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRawDataCommand.java
index 6cbf86df0..2773d7094 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRawDataCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRawDataCommand.java
@@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands.manage;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
@@ -11,9 +10,10 @@ import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.CommandUtils;
-import com.djrapitops.plugin.command.ISender;
+import com.djrapitops.plugin.command.Sender;
import com.djrapitops.plugin.utilities.Verify;
+import javax.inject.Inject;
import java.util.Arrays;
/**
@@ -25,11 +25,14 @@ import java.util.Arrays;
public class ManageRawDataCommand extends CommandNode {
private final Locale locale;
+ private final ConnectionSystem connectionSystem;
- public ManageRawDataCommand(PlanPlugin plugin) {
+ @Inject
+ public ManageRawDataCommand(Locale locale, ConnectionSystem connectionSystem) {
super("raw", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.locale = locale;
+ this.connectionSystem = connectionSystem;
setArguments("");
setShortHelp(locale.getString(CmdHelpLang.MANAGE_RAW_DATA));
@@ -37,7 +40,7 @@ public class ManageRawDataCommand extends CommandNode {
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
Verify.isTrue(args.length >= 1,
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
@@ -45,7 +48,7 @@ public class ManageRawDataCommand extends CommandNode {
sender.sendMessage(locale.getString(CommandLang.HEADER_INSPECT, playerName));
// Link
- String url = ConnectionSystem.getInstance().getMainAddress() + "/player/" + playerName + "/raw";
+ String url = connectionSystem.getMainAddress() + "/player/" + playerName + "/raw";
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
boolean console = !CommandUtils.isPlayer(sender);
if (console) {
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRemoveCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRemoveCommand.java
index 25cba8866..432ee9fe5 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRemoveCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRemoveCommand.java
@@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands.manage;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.locale.Locale;
@@ -8,17 +7,19 @@ import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.locale.lang.ManageLang;
+import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
-import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
-import com.djrapitops.plugin.command.ISender;
-import com.djrapitops.plugin.task.AbsRunnable;
-import com.djrapitops.plugin.task.RunnableFactory;
+import com.djrapitops.plugin.command.Sender;
+import com.djrapitops.plugin.logging.L;
+import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import java.util.Arrays;
import java.util.UUID;
@@ -28,14 +29,30 @@ import java.util.UUID;
*
* @author Rsl1122
*/
+@Singleton
public class ManageRemoveCommand extends CommandNode {
private final Locale locale;
+ private final Processing processing;
+ private final Database database;
+ private final UUIDUtility uuidUtility;
+ private final ErrorHandler errorHandler;
- public ManageRemoveCommand(PlanPlugin plugin) {
+ @Inject
+ public ManageRemoveCommand(
+ Locale locale,
+ Processing processing,
+ Database database,
+ UUIDUtility uuidUtility,
+ ErrorHandler errorHandler
+ ) {
super("remove|delete", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.locale = locale;
+ this.processing = processing;
+ this.database = database;
+ this.uuidUtility = uuidUtility;
+ this.errorHandler = errorHandler;
setArguments("", "[-a]");
setShortHelp(locale.getString(CmdHelpLang.MANAGE_REMOVE));
@@ -43,7 +60,7 @@ public class ManageRemoveCommand extends CommandNode {
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
Verify.isTrue(args.length >= 1,
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
@@ -57,41 +74,35 @@ public class ManageRemoveCommand extends CommandNode {
runRemoveTask(playerName, sender, args);
}
- private void runRemoveTask(String playerName, ISender sender, String[] args) {
- RunnableFactory.createNew(new AbsRunnable("DBRemoveTask " + playerName) {
- @Override
- public void run() {
- try {
- UUID uuid = UUIDUtility.getUUIDOf(playerName);
+ private void runRemoveTask(String playerName, Sender sender, String[] args) {
+ processing.submitCritical(() -> {
+ try {
+ UUID uuid = uuidUtility.getUUIDOf(playerName);
- if (uuid == null) {
- sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_VALID));
- return;
- }
-
- Database database = Database.getActive();
- if (!database.check().isPlayerRegistered(uuid)) {
- sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_KNOWN));
- return;
- }
-
- if (!Verify.contains("-a", args)) {
- sender.sendMessage(locale.getString(ManageLang.CONFIRMATION, locale.getString(ManageLang.CONFIRM_REMOVAL, database.getName())));
- return;
- }
-
- sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
-
- database.remove().player(uuid);
-
- sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
- } catch (DBOpException e) {
- Log.toLog(this.getClass(), e);
- sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
- } finally {
- this.cancel();
+ if (uuid == null) {
+ sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_VALID));
+ return;
}
+
+ if (!database.check().isPlayerRegistered(uuid)) {
+ sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_KNOWN));
+ return;
+ }
+
+ if (!Verify.contains("-a", args)) {
+ sender.sendMessage(locale.getString(ManageLang.CONFIRMATION, locale.getString(ManageLang.CONFIRM_REMOVAL, database.getName())));
+ return;
+ }
+
+ sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
+
+ database.remove().player(uuid);
+
+ sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
+ } catch (DBOpException e) {
+ errorHandler.log(L.ERROR, this.getClass(), e);
+ sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
}
- }).runTaskAsynchronously();
+ });
}
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRestoreCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRestoreCommand.java
index db56b97d1..12dd7cfa3 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRestoreCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRestoreCommand.java
@@ -1,23 +1,24 @@
package com.djrapitops.plan.command.commands.manage;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.database.databases.sql.SQLiteDB;
+import com.djrapitops.plan.system.file.PlanFiles;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.locale.lang.ManageLang;
+import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions;
-import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
-import com.djrapitops.plugin.command.ISender;
-import com.djrapitops.plugin.task.AbsRunnable;
-import com.djrapitops.plugin.task.RunnableFactory;
+import com.djrapitops.plugin.command.Sender;
+import com.djrapitops.plugin.logging.L;
+import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify;
+import javax.inject.Inject;
import java.io.File;
import java.util.Arrays;
@@ -29,14 +30,30 @@ import java.util.Arrays;
*/
public class ManageRestoreCommand extends CommandNode {
- private final PlanPlugin plugin;
private final Locale locale;
+ private final Processing processing;
+ private final DBSystem dbSystem;
+ private final ErrorHandler errorHandler;
+ private final SQLiteDB.Factory sqliteFactory;
+ private final PlanFiles files;
- public ManageRestoreCommand(PlanPlugin plugin) {
+ @Inject
+ public ManageRestoreCommand(
+ Locale locale,
+ Processing processing,
+ DBSystem dbSystem,
+ SQLiteDB.Factory sqliteFactory,
+ PlanFiles files,
+ ErrorHandler errorHandler
+ ) {
super("restore", Permissions.MANAGE.getPermission(), CommandType.CONSOLE);
- this.plugin = plugin;
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.locale = locale;
+ this.processing = processing;
+ this.dbSystem = dbSystem;
+ this.sqliteFactory = sqliteFactory;
+ this.files = files;
+ this.errorHandler = errorHandler;
setArguments("", "", "[-a]");
setShortHelp(locale.getString(CmdHelpLang.MANAGE_RESTORE));
@@ -44,7 +61,7 @@ public class ManageRestoreCommand extends CommandNode {
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
Verify.isTrue(args.length >= 2,
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ARGS, 2, Arrays.toString(this.getArguments()))));
@@ -56,9 +73,11 @@ public class ManageRestoreCommand extends CommandNode {
() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_INCORRECT_DB, dbName)));
try {
- Database database = DBSystem.getActiveDatabaseByName(dbName);
+ Database database = dbSystem.getActiveDatabaseByName(dbName);
+
Verify.isFalse(backupDbName.contains("database") && database instanceof SQLiteDB,
() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_SAME_DB)));
+ database.init();
if (!Verify.contains("-a", args)) {
sender.sendMessage(locale.getString(ManageLang.CONFIRMATION, locale.getString(ManageLang.CONFIRM_OVERWRITE, database.getName())));
@@ -71,40 +90,35 @@ public class ManageRestoreCommand extends CommandNode {
}
}
- private void runRestoreTask(String backupDbName, ISender sender, final Database database) {
- RunnableFactory.createNew(new AbsRunnable("RestoreTask") {
- @Override
- public void run() {
- try {
- String backupDBName = backupDbName;
- boolean containsDBFileExtension = backupDBName.endsWith(".db");
+ private void runRestoreTask(String backupDbName, Sender sender, Database database) {
+ processing.submitCritical(() -> {
+ try {
+ String backupDBName = backupDbName;
+ boolean containsDBFileExtension = backupDBName.endsWith(".db");
- File backupDBFile = new File(plugin.getDataFolder(), backupDBName + (containsDBFileExtension ? "" : ".db"));
+ File backupDBFile = files.getFileFromPluginFolder(backupDBName + (containsDBFileExtension ? "" : ".db"));
- if (!backupDBFile.exists()) {
- sender.sendMessage(locale.getString(ManageLang.FAIL_FILE_NOT_FOUND, backupDBFile.getAbsolutePath()));
- return;
- }
-
- if (containsDBFileExtension) {
- backupDBName = backupDBName.substring(0, backupDBName.length() - 3);
- }
-
- SQLiteDB backupDB = new SQLiteDB(backupDBName, () -> locale);
- backupDB.init();
-
- sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
-
- database.backup().restore(backupDB);
-
- sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
- } catch (Exception e) {
- Log.toLog(this.getClass(), e);
- sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
- } finally {
- this.cancel();
+ if (!backupDBFile.exists()) {
+ sender.sendMessage(locale.getString(ManageLang.FAIL_FILE_NOT_FOUND, backupDBFile.getAbsolutePath()));
+ return;
}
+
+ if (containsDBFileExtension) {
+ backupDBName = backupDBName.substring(0, backupDBName.length() - 3);
+ }
+
+ SQLiteDB backupDB = sqliteFactory.usingFile(backupDBFile);
+ backupDB.init();
+
+ sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
+
+ database.backup().restore(backupDB);
+
+ sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
+ } catch (Exception e) {
+ errorHandler.log(L.ERROR, this.getClass(), e);
+ sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
}
- }).runTaskAsynchronously();
+ });
}
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageSetupCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageSetupCommand.java
index cbd00231a..dff524d68 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageSetupCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageSetupCommand.java
@@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands.manage;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.connection.*;
import com.djrapitops.plan.system.info.InfoSystem;
import com.djrapitops.plan.system.locale.Locale;
@@ -10,13 +9,17 @@ import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.Settings;
-import com.djrapitops.plan.system.webserver.WebServerSystem;
-import com.djrapitops.plugin.api.utility.log.Log;
+import com.djrapitops.plan.system.settings.config.PlanConfig;
+import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
-import com.djrapitops.plugin.command.ISender;
+import com.djrapitops.plugin.command.Sender;
+import com.djrapitops.plugin.logging.L;
+import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import java.util.Arrays;
/**
@@ -25,14 +28,33 @@ import java.util.Arrays;
* @author Rsl1122
* @since 2.3.0
*/
+@Singleton
public class ManageSetupCommand extends CommandNode {
private final Locale locale;
+ private final PlanConfig config;
+ private final Processing processing;
+ private final InfoSystem infoSystem;
+ private final WebServer webServer;
+ private final ErrorHandler errorHandler;
- public ManageSetupCommand(PlanPlugin plugin) {
+ @Inject
+ public ManageSetupCommand(
+ Locale locale,
+ PlanConfig config,
+ Processing processing,
+ InfoSystem infoSystem,
+ WebServer webServer,
+ ErrorHandler errorHandler
+ ) {
super("setup", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.locale = locale;
+ this.config = config;
+ this.processing = processing;
+ this.infoSystem = infoSystem;
+ this.webServer = webServer;
+ this.errorHandler = errorHandler;
setArguments("");
setShortHelp(locale.getString(CmdHelpLang.MANAGE_SETUP));
@@ -40,11 +62,11 @@ public class ManageSetupCommand extends CommandNode {
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
Verify.isTrue(args.length >= 1,
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
- if (!WebServerSystem.isWebServerEnabled()) {
+ if (!webServer.isEnabled()) {
sender.sendMessage(locale.getString(CommandLang.CONNECT_WEBSERVER_NOT_ENABLED));
return;
}
@@ -60,13 +82,13 @@ public class ManageSetupCommand extends CommandNode {
requestSetup(sender, address);
}
- private void requestSetup(ISender sender, String address) {
- Processing.submitNonCritical(() -> {
+ private void requestSetup(Sender sender, String address) {
+ processing.submitNonCritical(() -> {
try {
- Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.set(false);
- Settings.BUNGEE_COPY_CONFIG.set(true);
+ config.set(Settings.BUNGEE_OVERRIDE_STANDALONE_MODE, false);
+ config.set(Settings.BUNGEE_COPY_CONFIG, true);
- InfoSystem.getInstance().requestSetUp(address);
+ infoSystem.requestSetUp(address);
sender.sendMessage(locale.getString(CommandLang.CONNECT_SUCCESS));
} catch (ForbiddenException e) {
@@ -82,7 +104,7 @@ public class ManageSetupCommand extends CommandNode {
} catch (GatewayException e) {
sender.sendMessage(locale.getString(CommandLang.CONNECT_GATEWAY));
} catch (WebException e) {
- Log.toLog(this.getClass(), e);
+ errorHandler.log(L.WARN, this.getClass(), e);
sender.sendMessage(locale.getString(CommandLang.CONNECT_FAIL, e.toString()));
}
});
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageUninstalledCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageUninstalledCommand.java
index 456f388f0..4aaf4acc3 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageUninstalledCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageUninstalledCommand.java
@@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands.manage;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.info.server.Server;
@@ -11,11 +10,14 @@ import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.locale.lang.ManageLang;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions;
-import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
-import com.djrapitops.plugin.command.ISender;
+import com.djrapitops.plugin.command.Sender;
+import com.djrapitops.plugin.logging.L;
+import com.djrapitops.plugin.logging.error.ErrorHandler;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
@@ -26,14 +28,30 @@ import java.util.UUID;
* @author Rsl1122
* @since 2.0.0
*/
+@Singleton
public class ManageUninstalledCommand extends CommandNode {
private final Locale locale;
+ private final Processing processing;
+ private final Database database;
+ private final ErrorHandler errorHandler;
+ private final ServerInfo serverInfo;
- public ManageUninstalledCommand(PlanPlugin plugin) {
+ @Inject
+ public ManageUninstalledCommand(
+ Locale locale,
+ Processing processing,
+ Database database,
+ ServerInfo serverInfo,
+ ErrorHandler errorHandler
+ ) {
super("uninstalled", Permissions.MANAGE.getPermission(), CommandType.ALL_WITH_ARGS);
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.locale = locale;
+ this.processing = processing;
+ this.database = database;
+ this.serverInfo = serverInfo;
+ this.errorHandler = errorHandler;
setShortHelp(locale.getString(CmdHelpLang.MANAGE_UNINSTALLED));
setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE_UNINSTALLED));
@@ -41,10 +59,10 @@ public class ManageUninstalledCommand extends CommandNode {
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
- Processing.submitNonCritical(() -> {
+ processing.submitNonCritical(() -> {
try {
Optional serverOptional = getServer(args);
if (!serverOptional.isPresent()) {
@@ -53,23 +71,23 @@ public class ManageUninstalledCommand extends CommandNode {
}
Server server = serverOptional.get();
UUID serverUUID = server.getUuid();
- if (ServerInfo.getServerUUID().equals(serverUUID)) {
+ if (serverInfo.getServerUUID().equals(serverUUID)) {
sender.sendMessage(locale.getString(ManageLang.UNINSTALLING_SAME_SERVER));
return;
}
- Database.getActive().save().setAsUninstalled(serverUUID);
+ database.save().setAsUninstalled(serverUUID);
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
} catch (DBOpException e) {
sender.sendMessage("§cError occurred: " + e.toString());
- Log.toLog(this.getClass(), e);
+ errorHandler.log(L.ERROR, this.getClass(), e);
}
});
}
private Optional getServer(String[] args) {
if (args.length >= 1) {
- Map bukkitServers = Database.getActive().fetch().getBukkitServers();
+ Map bukkitServers = database.fetch().getBukkitServers();
String serverIdentifier = getGivenIdentifier(args);
for (Map.Entry entry : bukkitServers.entrySet()) {
Server server = entry.getValue();
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebCheckCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebCheckCommand.java
index 85b327061..3be0c67b6 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebCheckCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebCheckCommand.java
@@ -1,21 +1,22 @@
package com.djrapitops.plan.command.commands.webuser;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.data.WebUser;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.ManageLang;
+import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions;
-import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
-import com.djrapitops.plugin.command.ISender;
-import com.djrapitops.plugin.task.AbsRunnable;
-import com.djrapitops.plugin.task.RunnableFactory;
+import com.djrapitops.plugin.command.Sender;
+import com.djrapitops.plugin.logging.L;
+import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import java.util.Arrays;
/**
@@ -24,45 +25,51 @@ import java.util.Arrays;
* @author Rsl1122
* @since 3.5.2
*/
+@Singleton
public class WebCheckCommand extends CommandNode {
private final Locale locale;
+ private final Processing processing;
+ private final Database database;
+ private final ErrorHandler errorHandler;
- public WebCheckCommand(PlanPlugin plugin) {
+ @Inject
+ public WebCheckCommand(
+ Locale locale,
+ Processing processing,
+ Database database,
+ ErrorHandler errorHandler) {
super("check", Permissions.MANAGE_WEB.getPerm(), CommandType.PLAYER_OR_ARGS);
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.locale = locale;
+ this.processing = processing;
+ this.database = database;
+ this.errorHandler = errorHandler;
setShortHelp(locale.getString(CmdHelpLang.WEB_CHECK));
setArguments("");
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
Verify.isTrue(args.length >= 1,
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
- Database database = Database.getActive();
String user = args[0];
- RunnableFactory.createNew(new AbsRunnable("Webuser Check Task: " + user) {
- @Override
- public void run() {
- try {
- if (!database.check().doesWebUserExists(user)) {
- sender.sendMessage(locale.getString(CommandLang.FAIL_WEB_USER_NOT_EXISTS));
- return;
- }
- WebUser info = database.fetch().getWebUser(user);
- sender.sendMessage(locale.getString(CommandLang.WEB_USER_LIST, info.getName(), info.getPermLevel()));
- } catch (Exception e) {
- Log.toLog(this.getClass(), e);
- sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
- } finally {
- this.cancel();
+ processing.submitNonCritical(() -> {
+ try {
+ if (!database.check().doesWebUserExists(user)) {
+ sender.sendMessage(locale.getString(CommandLang.FAIL_WEB_USER_NOT_EXISTS));
+ return;
}
+ WebUser info = database.fetch().getWebUser(user);
+ sender.sendMessage(locale.getString(CommandLang.WEB_USER_LIST, info.getName(), info.getPermLevel()));
+ } catch (Exception e) {
+ errorHandler.log(L.ERROR, this.getClass(), e);
+ sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
}
- }).runTaskAsynchronously();
+ });
}
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebDeleteCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebDeleteCommand.java
index bd9df7675..b5b591086 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebDeleteCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebDeleteCommand.java
@@ -1,20 +1,21 @@
package com.djrapitops.plan.command.commands.webuser;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.ManageLang;
+import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions;
-import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
-import com.djrapitops.plugin.command.ISender;
-import com.djrapitops.plugin.task.AbsRunnable;
-import com.djrapitops.plugin.task.RunnableFactory;
+import com.djrapitops.plugin.command.Sender;
+import com.djrapitops.plugin.logging.L;
+import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import java.util.Arrays;
/**
@@ -23,45 +24,52 @@ import java.util.Arrays;
* @author Rsl1122
* @since 3.5.2
*/
+@Singleton
public class WebDeleteCommand extends CommandNode {
private final Locale locale;
+ private final Processing processing;
+ private final Database database;
+ private final ErrorHandler errorHandler;
- public WebDeleteCommand(PlanPlugin plugin) {
+ @Inject
+ public WebDeleteCommand(
+ Locale locale,
+ Processing processing,
+ Database database,
+ ErrorHandler errorHandler
+ ) {
super("delete|remove", Permissions.MANAGE_WEB.getPerm(), CommandType.PLAYER_OR_ARGS);
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.locale = locale;
+ this.processing = processing;
+ this.database = database;
+ this.errorHandler = errorHandler;
setShortHelp(locale.getString(CmdHelpLang.WEB_DELETE));
setArguments("");
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
Verify.isTrue(args.length >= 1,
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
- Database database = Database.getActive();
String user = args[0];
- RunnableFactory.createNew("Webuser Delete Task: " + user, new AbsRunnable() {
- @Override
- public void run() {
- try {
- if (!database.check().doesWebUserExists(user)) {
- sender.sendMessage("§c[Plan] User Doesn't exist.");
- return;
- }
- database.remove().webUser(user);
- sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
- } catch (Exception e) {
- Log.toLog(this.getClass(), e);
- sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
- } finally {
- this.cancel();
+ processing.submitNonCritical(() -> {
+ try {
+ if (!database.check().doesWebUserExists(user)) {
+ sender.sendMessage("§c[Plan] User Doesn't exist.");
+ return;
}
+ database.remove().webUser(user);
+ sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
+ } catch (Exception e) {
+ errorHandler.log(L.ERROR, this.getClass(), e);
+ sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
}
- }).runTaskAsynchronously();
+ });
}
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebLevelCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebLevelCommand.java
index 105fdbb6a..27e8589d0 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebLevelCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebLevelCommand.java
@@ -1,13 +1,14 @@
package com.djrapitops.plan.command.commands.webuser;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
-import com.djrapitops.plugin.command.ISender;
+import com.djrapitops.plugin.command.Sender;
+
+import javax.inject.Inject;
/**
* Subcommand for info about permission levels.
@@ -19,16 +20,17 @@ public class WebLevelCommand extends CommandNode {
private final Locale locale;
- public WebLevelCommand(PlanPlugin plugin) {
+ @Inject
+ public WebLevelCommand(Locale locale) {
super("level", Permissions.MANAGE_WEB.getPerm(), CommandType.CONSOLE);
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.locale = locale;
setShortHelp(locale.getString(CmdHelpLang.WEB_LEVEL));
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
sender.sendMessage(locale.getArray(CommandLang.WEB_PERMISSION_LEVELS));
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebListUsersCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebListUsersCommand.java
index 87780fc78..35804ca5f 100644
--- a/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebListUsersCommand.java
+++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebListUsersCommand.java
@@ -1,21 +1,22 @@
package com.djrapitops.plan.command.commands.webuser;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.data.WebUser;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.ManageLang;
+import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.utilities.comparators.WebUserComparator;
-import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
-import com.djrapitops.plugin.command.ISender;
-import com.djrapitops.plugin.task.AbsRunnable;
-import com.djrapitops.plugin.task.RunnableFactory;
+import com.djrapitops.plugin.command.Sender;
+import com.djrapitops.plugin.logging.L;
+import com.djrapitops.plugin.logging.error.ErrorHandler;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import java.util.List;
/**
@@ -24,39 +25,47 @@ import java.util.List;
* @author Rsl1122
* @since 3.5.2
*/
+@Singleton
public class WebListUsersCommand extends CommandNode {
private final Locale locale;
+ private final Processing processing;
+ private final Database database;
+ private final ErrorHandler errorHandler;
- public WebListUsersCommand(PlanPlugin plugin) {
+ @Inject
+ public WebListUsersCommand(
+ Locale locale,
+ Processing processing,
+ Database database,
+ ErrorHandler errorHandler
+ ) {
super("list", Permissions.MANAGE_WEB.getPerm(), CommandType.CONSOLE);
- locale = plugin.getSystem().getLocaleSystem().getLocale();
+ this.locale = locale;
+ this.processing = processing;
+ this.database = database;
+ this.errorHandler = errorHandler;
setShortHelp(locale.getString(CmdHelpLang.WEB_LIST));
}
@Override
- public void onCommand(ISender sender, String commandLabel, String[] args) {
- RunnableFactory.createNew(new AbsRunnable("Web user List Task") {
- @Override
- public void run() {
- try {
- List users = Database.getActive().fetch().getWebUsers();
- users.sort(new WebUserComparator());
- sender.sendMessage(locale.getString(CommandLang.HEADER_WEB_USERS, users.size()));
- for (WebUser user : users) {
- sender.sendMessage(locale.getString(CommandLang.WEB_USER_LIST, user.getName(), user.getPermLevel()));
- }
- sender.sendMessage(">");
- } catch (Exception e) {
- Log.toLog(this.getClass(), e);
- sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
- } finally {
- this.cancel();
+ public void onCommand(Sender sender, String commandLabel, String[] args) {
+ processing.submitNonCritical(() -> {
+ try {
+ List users = database.fetch().getWebUsers();
+ users.sort(new WebUserComparator());
+ sender.sendMessage(locale.getString(CommandLang.HEADER_WEB_USERS, users.size()));
+ for (WebUser user : users) {
+ sender.sendMessage(locale.getString(CommandLang.WEB_USER_LIST, user.getName(), user.getPermLevel()));
}
+ sender.sendMessage(">");
+ } catch (Exception e) {
+ errorHandler.log(L.ERROR, this.getClass(), e);
+ sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
}
- }).runTaskAsynchronously();
+ });
}
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/data/container/GeoInfo.java b/Plan/src/main/java/com/djrapitops/plan/data/container/GeoInfo.java
index 2ed38a28d..72a59b33e 100644
--- a/Plan/src/main/java/com/djrapitops/plan/data/container/GeoInfo.java
+++ b/Plan/src/main/java/com/djrapitops/plan/data/container/GeoInfo.java
@@ -6,11 +6,11 @@ package com.djrapitops.plan.data.container;
import com.djrapitops.plan.data.store.objects.DateHolder;
import com.djrapitops.plan.data.store.objects.DateMap;
-import com.djrapitops.plan.utilities.FormatUtils;
import com.djrapitops.plan.utilities.SHA256Hash;
import com.google.common.base.Objects;
import java.io.Serializable;
+import java.net.Inet6Address;
import java.net.InetAddress;
import java.security.NoSuchAlgorithmException;
@@ -26,9 +26,8 @@ public class GeoInfo implements DateHolder, Serializable {
private final String ipHash;
private final long date;
- public GeoInfo(InetAddress address, String geolocation, long lastUsed)
- throws NoSuchAlgorithmException {
- this(FormatUtils.formatIP(address), geolocation, lastUsed, new SHA256Hash(address.getHostAddress()).create());
+ public GeoInfo(InetAddress address, String geolocation, long lastUsed) throws NoSuchAlgorithmException {
+ this(formatIP(address), geolocation, lastUsed, new SHA256Hash(address.getHostAddress()).create());
}
public GeoInfo(String ip, String geolocation, long date, String ipHash) {
@@ -46,6 +45,42 @@ public class GeoInfo implements DateHolder, Serializable {
return map;
}
+ static String formatIP(InetAddress address) {
+ String ip = address.getHostAddress();
+ if ("localhost".equals(ip)) {
+ return ip;
+ }
+ if (address instanceof Inet6Address) {
+ StringBuilder b = new StringBuilder();
+ int i = 0;
+ for (String part : ip.split(":")) {
+ if (i >= 3) {
+ break;
+ }
+
+ b.append(part).append(':');
+
+ i++;
+ }
+
+ return b.append("xx..").toString();
+ } else {
+ StringBuilder b = new StringBuilder();
+ int i = 0;
+ for (String part : ip.split("\\.")) {
+ if (i >= 2) {
+ break;
+ }
+
+ b.append(part).append('.');
+
+ i++;
+ }
+
+ return b.append("xx.xx").toString();
+ }
+ }
+
public String getIp() {
return ip;
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/data/container/PlayerDeath.java b/Plan/src/main/java/com/djrapitops/plan/data/container/PlayerDeath.java
index 1eb7f35b5..dd28dc674 100644
--- a/Plan/src/main/java/com/djrapitops/plan/data/container/PlayerDeath.java
+++ b/Plan/src/main/java/com/djrapitops/plan/data/container/PlayerDeath.java
@@ -7,11 +7,13 @@ import java.util.UUID;
public class PlayerDeath implements DateHolder {
private final UUID killer;
+ private final String killerName;
private final long date;
private final String weapon;
- public PlayerDeath(UUID killer, String weapon, long date) {
+ public PlayerDeath(UUID killer, String killerName, String weapon, long date) {
this.killer = killer;
+ this.killerName = killerName;
this.date = date;
this.weapon = weapon;
}
@@ -20,6 +22,10 @@ public class PlayerDeath implements DateHolder {
return killer;
}
+ public String getKillerName() {
+ return killerName;
+ }
+
@Override
public long getDate() {
return date;
diff --git a/Plan/src/main/java/com/djrapitops/plan/data/container/PlayerKill.java b/Plan/src/main/java/com/djrapitops/plan/data/container/PlayerKill.java
index 7eece6d25..8b865f210 100644
--- a/Plan/src/main/java/com/djrapitops/plan/data/container/PlayerKill.java
+++ b/Plan/src/main/java/com/djrapitops/plan/data/container/PlayerKill.java
@@ -2,8 +2,8 @@ package com.djrapitops.plan.data.container;
import com.djrapitops.plan.data.store.objects.DateHolder;
-import java.io.Serializable;
import java.util.Objects;
+import java.util.Optional;
import java.util.UUID;
/**
@@ -12,11 +12,13 @@ import java.util.UUID;
*
* @author Rsl1122
*/
-public class PlayerKill implements DateHolder, Serializable {
+public class PlayerKill implements DateHolder {
private final UUID victim;
- private final long date;
private final String weapon;
+ private final long date;
+
+ private String victimName;
/**
* Creates a PlayerKill object with given parameters.
@@ -31,6 +33,13 @@ public class PlayerKill implements DateHolder, Serializable {
this.date = date;
}
+ public PlayerKill(UUID victim, String weapon, long date, String victimName) {
+ this.victim = victim;
+ this.date = date;
+ this.weapon = weapon;
+ this.victimName = victimName;
+ }
+
/**
* Get the victim's UUID.
*
@@ -40,6 +49,10 @@ public class PlayerKill implements DateHolder, Serializable {
return victim;
}
+ public Optional getVictimName() {
+ return Optional.ofNullable(victimName);
+ }
+
@Override
public long getDate() {
return date;
diff --git a/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java b/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java
index 704ad2346..6522dcf7f 100644
--- a/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java
+++ b/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java
@@ -2,11 +2,8 @@ package com.djrapitops.plan.data.container;
import com.djrapitops.plan.data.store.containers.DataContainer;
import com.djrapitops.plan.data.store.keys.SessionKeys;
-import com.djrapitops.plan.data.store.mutators.formatting.Formatters;
import com.djrapitops.plan.data.store.objects.DateHolder;
import com.djrapitops.plan.data.time.WorldTimes;
-import com.djrapitops.plan.system.info.server.ServerInfo;
-import com.djrapitops.plan.system.settings.WorldAliasSettings;
import java.util.*;
@@ -30,11 +27,12 @@ public class Session extends DataContainer implements DateHolder {
* Creates a new session.
*
* @param uuid UUID of the Player.
+ * @param serverUUID UUID of the server.
* @param sessionStart Epoch ms the session started.
* @param world Starting world.
* @param gm Starting GameMode.
*/
- public Session(UUID uuid, long sessionStart, String world, String gm) {
+ public Session(UUID uuid, UUID serverUUID, long sessionStart, String world, String gm) {
this.sessionStart = sessionStart;
worldTimes = new WorldTimes(world, gm, sessionStart);
playerKills = new ArrayList<>();
@@ -44,6 +42,7 @@ public class Session extends DataContainer implements DateHolder {
afkTime = 0;
putRawData(SessionKeys.UUID, uuid);
+ putRawData(SessionKeys.SERVER_UUID, serverUUID);
putSupplier(SessionKeys.START, this::getSessionStart);
putSupplier(SessionKeys.WORLD_TIMES, this::getWorldTimes);
putSupplier(SessionKeys.PLAYER_KILLS, this::getPlayerKills);
@@ -56,9 +55,8 @@ public class Session extends DataContainer implements DateHolder {
putSupplier(SessionKeys.LENGTH, () ->
getValue(SessionKeys.END).orElse(System.currentTimeMillis()) - getUnsafe(SessionKeys.START));
putSupplier(SessionKeys.ACTIVE_TIME, () -> getUnsafe(SessionKeys.LENGTH) - getUnsafe(SessionKeys.AFK_TIME));
- putSupplier(SessionKeys.SERVER_UUID, ServerInfo::getServerUUID);
- putSupplier(SessionKeys.LONGEST_WORLD_PLAYED, this::getLongestWorldPlayed);
+ putRawData(SessionKeys.LONGEST_WORLD_PLAYED, "Key is Deprecated, use WorldAliasSettings#getLongestWorldPlayed(Session) instead.");
}
/**
@@ -101,7 +99,7 @@ public class Session extends DataContainer implements DateHolder {
getValue(SessionKeys.END).orElse(System.currentTimeMillis()) - getUnsafe(SessionKeys.START));
putSupplier(SessionKeys.ACTIVE_TIME, () -> getUnsafe(SessionKeys.LENGTH) - getUnsafe(SessionKeys.AFK_TIME));
- putSupplier(SessionKeys.LONGEST_WORLD_PLAYED, this::getLongestWorldPlayed);
+ putRawData(SessionKeys.LONGEST_WORLD_PLAYED, "Key is Deprecated, use WorldAliasSettings#getLongestWorldPlayed(Session) instead.");
}
/**
@@ -157,8 +155,17 @@ public class Session extends DataContainer implements DateHolder {
this.worldTimes = worldTimes;
}
- public void setPlayerKills(List playerKills) {
- this.playerKills = playerKills;
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ Session session = (Session) o;
+ return getUnsafe(SessionKeys.START).equals(session.getUnsafe(SessionKeys.START)) &&
+ getValue(SessionKeys.END).orElse(-1L).equals(session.getValue(SessionKeys.END).orElse(-1L)) &&
+ mobKills == session.mobKills &&
+ deaths == session.deaths &&
+ Objects.equals(playerKills, session.playerKills) &&
+ Objects.equals(worldTimes, session.worldTimes);
}
public boolean isFetchedFromDB() {
@@ -173,17 +180,8 @@ public class Session extends DataContainer implements DateHolder {
putRawData(SessionKeys.DB_ID, sessionID);
}
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- Session session = (Session) o;
- return getUnsafe(SessionKeys.START).equals(session.getUnsafe(SessionKeys.START)) &&
- getValue(SessionKeys.END).orElse(-1L).equals(session.getValue(SessionKeys.END).orElse(-1L)) &&
- mobKills == session.mobKills &&
- deaths == session.deaths &&
- Objects.equals(playerKills, session.playerKills) &&
- Objects.equals(worldTimes, session.worldTimes);
+ public List getPlayerKills() {
+ return playerKills;
}
@Override
@@ -199,8 +197,8 @@ public class Session extends DataContainer implements DateHolder {
return worldTimes;
}
- public List getPlayerKills() {
- return playerKills;
+ public void setPlayerKills(List playerKills) {
+ this.playerKills = playerKills;
}
private int getMobKills() {
@@ -214,48 +212,4 @@ public class Session extends DataContainer implements DateHolder {
private long getAfkTime() {
return afkTime;
}
-
- private String getLongestWorldPlayed() {
- Map aliases = WorldAliasSettings.getAliases();
- if (worldTimes == null) {
- return "No World Time Data";
- }
- if (!supports(SessionKeys.END)) {
- return "Current: " + aliases.get(worldTimes.getCurrentWorld());
- }
-
- Map playtimePerAlias = worldTimes.getPlaytimePerAlias();
-
- long longest = 0;
- String theWorld = "-";
- for (Map.Entry entry : playtimePerAlias.entrySet()) {
- String world = entry.getKey();
- long time = entry.getValue();
- if (time > longest) {
- longest = time;
- theWorld = world;
- }
- }
-
- long total = worldTimes.getTotal();
- // Prevent arithmetic error if 0
- if (total <= 0) {
- total = -1;
- }
- double quotient = longest * 1.0 / total;
-
- return theWorld + " (" + Formatters.percentage().apply(quotient) + ")";
- }
-
- @Override
- public String toString() {
- return "Session{" +
- "sessionStart=" + sessionStart +
- ", worldTimes=" + worldTimes +
- ", playerKills=" + playerKills +
- ", mobKills=" + mobKills +
- ", deaths=" + deaths +
- ", afkTime=" + afkTime +
- '}';
- }
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/data/element/TableContainer.java b/Plan/src/main/java/com/djrapitops/plan/data/element/TableContainer.java
index 76ec2cba4..fc4b6f6fb 100644
--- a/Plan/src/main/java/com/djrapitops/plan/data/element/TableContainer.java
+++ b/Plan/src/main/java/com/djrapitops/plan/data/element/TableContainer.java
@@ -4,10 +4,10 @@
*/
package com.djrapitops.plan.data.element;
-import com.djrapitops.plan.data.store.mutators.formatting.Formatter;
-import com.djrapitops.plan.utilities.FormatUtils;
+import com.djrapitops.plan.utilities.formatting.Formatter;
import com.djrapitops.plan.utilities.html.Html;
import com.djrapitops.plan.utilities.html.icon.Icon;
+import com.djrapitops.plugin.utilities.ArrayUtil;
import java.io.Serializable;
import java.util.ArrayList;
@@ -40,10 +40,9 @@ public class TableContainer {
}
public TableContainer(boolean players, String... header) {
- this(FormatUtils.mergeArrays(
- new String[]{Icon.called("user").build() + " Player"},
- header
- ));
+ this(
+ ArrayUtil.merge(new String[]{Icon.called("user").build() + " Player"}, header)
+ );
}
public final void addRow(Serializable... values) {
diff --git a/Plan/src/main/java/com/djrapitops/plan/data/plugin/HookHandler.java b/Plan/src/main/java/com/djrapitops/plan/data/plugin/HookHandler.java
index a6dd3824d..3c40920c5 100644
--- a/Plan/src/main/java/com/djrapitops/plan/data/plugin/HookHandler.java
+++ b/Plan/src/main/java/com/djrapitops/plan/data/plugin/HookHandler.java
@@ -1,14 +1,13 @@
package com.djrapitops.plan.data.plugin;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.data.element.InspectContainer;
-import com.djrapitops.plan.system.PlanSystem;
import com.djrapitops.plan.system.SubSystem;
-import com.djrapitops.plugin.StaticHolder;
-import com.djrapitops.plugin.api.utility.log.Log;
-import com.djrapitops.plugin.utilities.Verify;
-import com.djrapitops.pluginbridge.plan.Bridge;
+import com.djrapitops.plugin.logging.L;
+import com.djrapitops.plugin.logging.console.PluginLogger;
+import com.djrapitops.plugin.logging.error.ErrorHandler;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import java.util.*;
import java.util.stream.Collectors;
@@ -19,29 +18,30 @@ import java.util.stream.Collectors;
* @author Rsl1122
* @since 2.6.0
*/
+@Singleton
public class HookHandler implements SubSystem {
private final List additionalDataSources;
private PluginsConfigSection configHandler;
+ private final PluginLogger logger;
+ private final ErrorHandler errorHandler;
+
+ @Inject
+ public HookHandler(PluginsConfigSection configHandler, PluginLogger logger, ErrorHandler errorHandler) {
+ this.configHandler = configHandler;
+ this.logger = logger;
+ this.errorHandler = errorHandler;
- public HookHandler() {
additionalDataSources = new ArrayList<>();
}
- public static HookHandler getInstance() {
- HookHandler hookHandler = PlanSystem.getInstance().getHookHandler();
- Verify.nullCheck(hookHandler, () -> new IllegalStateException("Plugin Hooks were not initialized."));
- return hookHandler;
- }
-
@Override
public void enable() {
- configHandler = new PluginsConfigSection();
try {
- Bridge.hook(this);
+// Bridge.hook(this);
} catch (Exception e) {
- Log.toLog(this.getClass(), e);
- Log.error("Plan Plugin Bridge not included in the plugin jar.");
+ errorHandler.log(L.ERROR, this.getClass(), e);
+ logger.error("Plan Plugin Bridge not included in the plugin jar.");
}
}
@@ -65,17 +65,16 @@ public class HookHandler implements SubSystem {
return;
}
try {
- StaticHolder.saveInstance(dataSource.getClass(), PlanPlugin.getInstance().getClass());
if (!configHandler.hasSection(dataSource)) {
configHandler.createSection(dataSource);
}
if (configHandler.isEnabled(dataSource)) {
- Log.debug("Registered a new datasource: " + dataSource.getSourcePlugin());
+ logger.debug("Registered a new datasource: " + dataSource.getSourcePlugin());
additionalDataSources.add(dataSource);
}
} catch (Exception e) {
- Log.toLog(this.getClass(), e);
- Log.error("Attempting to register PluginDataSource caused an exception.");
+ errorHandler.log(L.WARN, this.getClass(), e);
+ logger.error("Attempting to register PluginDataSource caused an exception.");
}
}
@@ -107,8 +106,8 @@ public class HookHandler implements SubSystem {
}
} catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError e) {
String sourcePlugin = pluginData.getSourcePlugin();
- Log.error("PluginData caused exception: " + sourcePlugin);
- Log.toLog(this.getClass().getName() + " " + sourcePlugin, e);
+ logger.error("PluginData caused exception: " + sourcePlugin);
+ errorHandler.log(L.WARN, pluginData.getClass(), e);
}
}
return containers;
diff --git a/Plan/src/main/java/com/djrapitops/plan/data/plugin/PluginsConfigSection.java b/Plan/src/main/java/com/djrapitops/plan/data/plugin/PluginsConfigSection.java
index efcd64f4a..60f973aaa 100644
--- a/Plan/src/main/java/com/djrapitops/plan/data/plugin/PluginsConfigSection.java
+++ b/Plan/src/main/java/com/djrapitops/plan/data/plugin/PluginsConfigSection.java
@@ -1,8 +1,7 @@
package com.djrapitops.plan.data.plugin;
-import com.djrapitops.plan.system.settings.config.ConfigSystem;
-import com.djrapitops.plugin.api.config.ConfigNode;
-import com.djrapitops.plugin.api.utility.log.Log;
+import com.djrapitops.plan.system.settings.config.PlanConfig;
+import com.djrapitops.plugin.config.ConfigNode;
import java.io.IOException;
@@ -15,6 +14,14 @@ import java.io.IOException;
*/
public class PluginsConfigSection {
+ private final PlanConfig config;
+
+ public PluginsConfigSection(
+ PlanConfig config
+ ) {
+ this.config = config;
+ }
+
public boolean hasSection(PluginData dataSource) {
ConfigNode section = getPluginsSection();
String pluginName = dataSource.getSourcePlugin();
@@ -23,20 +30,16 @@ public class PluginsConfigSection {
}
private ConfigNode getPluginsSection() {
- return ConfigSystem.getConfig().getConfigNode("Plugins");
+ return config.getConfigNode("Plugins");
}
- public void createSection(PluginData dataSource) {
+ public void createSection(PluginData dataSource) throws IOException {
ConfigNode section = getPluginsSection();
String pluginName = dataSource.getSourcePlugin();
section.set(pluginName + ".Enabled", true);
- try {
- section.sort();
- section.save();
- } catch (IOException e) {
- Log.toLog(this.getClass(), e);
- }
+ section.sort();
+ section.save();
}
public boolean isEnabled(PluginData dataSource) {
diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/CachingSupplier.java b/Plan/src/main/java/com/djrapitops/plan/data/store/CachingSupplier.java
index ec3abff37..c05893c66 100644
--- a/Plan/src/main/java/com/djrapitops/plan/data/store/CachingSupplier.java
+++ b/Plan/src/main/java/com/djrapitops/plan/data/store/CachingSupplier.java
@@ -1,12 +1,11 @@
package com.djrapitops.plan.data.store;
-import com.djrapitops.plugin.api.TimeAmount;
-
+import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
/**
* Caching layer between Supplier and caller.
- *
+ *
* Refreshes the value if 30 seconds have passed since the last call.
*
* @author Rsl1122
@@ -19,7 +18,7 @@ public class CachingSupplier implements Supplier {
private long timeToLive;
public CachingSupplier(Supplier original) {
- this(original, TimeAmount.SECOND.ms() * 30L);
+ this(original, TimeUnit.SECONDS.toMillis(30L));
}
public CachingSupplier(Supplier original, long timeToLive) {
diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/containers/AnalysisContainer.java b/Plan/src/main/java/com/djrapitops/plan/data/store/containers/AnalysisContainer.java
index d871e35c0..749e0023e 100644
--- a/Plan/src/main/java/com/djrapitops/plan/data/store/containers/AnalysisContainer.java
+++ b/Plan/src/main/java/com/djrapitops/plan/data/store/containers/AnalysisContainer.java
@@ -1,42 +1,37 @@
package com.djrapitops.plan.data.store.containers;
-import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.data.store.Key;
import com.djrapitops.plan.data.store.Type;
import com.djrapitops.plan.data.store.keys.AnalysisKeys;
import com.djrapitops.plan.data.store.keys.PlayerKeys;
import com.djrapitops.plan.data.store.keys.ServerKeys;
import com.djrapitops.plan.data.store.mutators.*;
-import com.djrapitops.plan.data.store.mutators.combiners.MultiBanCombiner;
-import com.djrapitops.plan.data.store.mutators.formatting.Formatters;
import com.djrapitops.plan.data.store.mutators.health.HealthInformation;
import com.djrapitops.plan.data.time.WorldTimes;
import com.djrapitops.plan.system.database.databases.Database;
-import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.info.server.properties.ServerProperties;
import com.djrapitops.plan.system.settings.Settings;
+import com.djrapitops.plan.system.settings.config.PlanConfig;
import com.djrapitops.plan.system.settings.theme.Theme;
import com.djrapitops.plan.system.settings.theme.ThemeVal;
-import com.djrapitops.plan.utilities.MiscUtils;
-import com.djrapitops.plan.utilities.analysis.ServerBanDataReader;
-import com.djrapitops.plan.utilities.html.graphs.ActivityStackGraph;
-import com.djrapitops.plan.utilities.html.graphs.PunchCardGraph;
-import com.djrapitops.plan.utilities.html.graphs.WorldMap;
-import com.djrapitops.plan.utilities.html.graphs.bar.GeolocationBarGraph;
-import com.djrapitops.plan.utilities.html.graphs.calendar.ServerCalendar;
-import com.djrapitops.plan.utilities.html.graphs.line.*;
-import com.djrapitops.plan.utilities.html.graphs.pie.ActivityPie;
+import com.djrapitops.plan.utilities.formatting.Formatters;
+import com.djrapitops.plan.utilities.html.graphs.Graphs;
+import com.djrapitops.plan.utilities.html.graphs.bar.BarGraph;
+import com.djrapitops.plan.utilities.html.graphs.line.PingGraph;
import com.djrapitops.plan.utilities.html.graphs.pie.WorldPie;
+import com.djrapitops.plan.utilities.html.graphs.stack.StackGraph;
+import com.djrapitops.plan.utilities.html.structure.Accordions;
import com.djrapitops.plan.utilities.html.structure.AnalysisPluginsTabContentCreator;
import com.djrapitops.plan.utilities.html.structure.RecentLoginList;
import com.djrapitops.plan.utilities.html.structure.SessionAccordion;
-import com.djrapitops.plan.utilities.html.tables.CommandUseTable;
-import com.djrapitops.plan.utilities.html.tables.PingTable;
-import com.djrapitops.plan.utilities.html.tables.PlayersTable;
-import com.djrapitops.plan.utilities.html.tables.ServerSessionTable;
+import com.djrapitops.plan.utilities.html.tables.HtmlTables;
import com.djrapitops.plugin.api.TimeAmount;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
import java.util.*;
+import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
@@ -50,10 +45,43 @@ public class AnalysisContainer extends DataContainer {
private final ServerContainer serverContainer;
+ private final String version;
+ private final PlanConfig config;
+ private final Theme theme;
+ private final Database database;
+ private final ServerProperties serverProperties;
+ private final Formatters formatters;
+ private final Graphs graphs;
+ private final HtmlTables tables;
+ private final Accordions accordions;
+ private final AnalysisPluginsTabContentCreator pluginsTabContentCreator;
+
private static final Key