mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-11 14:20:54 +01:00
Merge branch 'apf-3.3.0' into apf-3.3.0-merging
This commit is contained in:
commit
82c183e63e
@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.djrapitops</groupId>
|
<groupId>com.djrapitops</groupId>
|
||||||
<artifactId>Plan</artifactId>
|
<artifactId>Plan</artifactId>
|
||||||
<version>4.3.0-SNAPSHOT</version>
|
<version>4.5.0-SNAPSHOT</version>
|
||||||
<build>
|
<build>
|
||||||
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
|
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
|
||||||
<testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
|
<testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
|
||||||
@ -31,6 +31,13 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<source>1.8</source>
|
<source>1.8</source>
|
||||||
<target>1.8</target>
|
<target>1.8</target>
|
||||||
|
<annotationProcessorPaths>
|
||||||
|
<path>
|
||||||
|
<groupId>com.google.dagger</groupId>
|
||||||
|
<artifactId>dagger-compiler</artifactId>
|
||||||
|
<version>2.16</version>
|
||||||
|
</path>
|
||||||
|
</annotationProcessorPaths>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
17
Plan/pom.xml
17
Plan/pom.xml
@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.djrapitops</groupId>
|
<groupId>com.djrapitops</groupId>
|
||||||
<artifactId>Plan</artifactId>
|
<artifactId>Plan</artifactId>
|
||||||
<version>4.3.0-SNAPSHOT</version>
|
<version>4.5.0-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
@ -45,7 +45,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.djrapitops</groupId>
|
<groupId>com.djrapitops</groupId>
|
||||||
<artifactId>AbstractPluginFramework</artifactId>
|
<artifactId>AbstractPluginFramework</artifactId>
|
||||||
<version>3.2.0</version>
|
<version>3.3.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- SoftDepended Plugins -->
|
<!-- SoftDepended Plugins -->
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -192,6 +192,12 @@
|
|||||||
<version>1.3</version>
|
<version>1.3</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.dagger</groupId>
|
||||||
|
<artifactId>dagger</artifactId>
|
||||||
|
<version>2.16</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@ -221,6 +227,13 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<source>1.8</source>
|
<source>1.8</source>
|
||||||
<target>1.8</target>
|
<target>1.8</target>
|
||||||
|
<annotationProcessorPaths>
|
||||||
|
<path>
|
||||||
|
<groupId>com.google.dagger</groupId>
|
||||||
|
<artifactId>dagger-compiler</artifactId>
|
||||||
|
<version>2.16</version>
|
||||||
|
</path>
|
||||||
|
</annotationProcessorPaths>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -21,24 +21,77 @@ package com.djrapitops.plan;
|
|||||||
|
|
||||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||||
import com.djrapitops.plan.command.PlanCommand;
|
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.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.PluginLang;
|
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.system.settings.theme.PlanColorScheme;
|
||||||
import com.djrapitops.plan.utilities.metrics.BStatsBukkit;
|
import com.djrapitops.plan.utilities.metrics.BStatsBukkit;
|
||||||
import com.djrapitops.plugin.BukkitPlugin;
|
import com.djrapitops.plugin.BukkitPlugin;
|
||||||
import com.djrapitops.plugin.StaticHolder;
|
import com.djrapitops.plugin.benchmarking.Benchmark;
|
||||||
import com.djrapitops.plugin.api.Benchmark;
|
import com.djrapitops.plugin.command.ColorScheme;
|
||||||
import com.djrapitops.plugin.api.utility.log.DebugLog;
|
import com.djrapitops.plugin.command.CommandNode;
|
||||||
import com.djrapitops.plugin.api.utility.log.Log;
|
import dagger.BindsInstance;
|
||||||
import com.djrapitops.plugin.settings.ColorScheme;
|
import dagger.Component;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
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.
|
* Main class for Bukkit that manages the plugin.
|
||||||
*
|
*
|
||||||
@ -47,55 +100,45 @@ import java.util.logging.Logger;
|
|||||||
*/
|
*/
|
||||||
public class Plan extends BukkitPlugin implements PlanPlugin {
|
public class Plan extends BukkitPlugin implements PlanPlugin {
|
||||||
|
|
||||||
private BukkitSystem system;
|
private PlanSystem system;
|
||||||
private Locale locale;
|
private Locale locale;
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to get the plugin-instance singleton.
|
|
||||||
*
|
|
||||||
* @return this object.
|
|
||||||
*/
|
|
||||||
public static Plan getInstance() {
|
|
||||||
return (Plan) StaticHolder.getInstance(Plan.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
super.onEnable();
|
PlanComponent component = DaggerPlanComponent.builder().plan(this).build();
|
||||||
try {
|
try {
|
||||||
Benchmark.start("Enable");
|
timings.start("Enable");
|
||||||
system = new BukkitSystem(this);
|
system = component.system();
|
||||||
locale = system.getLocaleSystem().getLocale();
|
locale = system.getLocaleSystem().getLocale();
|
||||||
system.enable();
|
system.enable();
|
||||||
|
|
||||||
ImporterManager.registerImporter(new OfflinePlayerImporter());
|
|
||||||
|
|
||||||
new BStatsBukkit(this).registerMetrics();
|
new BStatsBukkit(this).registerMetrics();
|
||||||
|
|
||||||
Log.debug("Verbose debug messages are enabled.");
|
logger.debug("Verbose debug messages are enabled.");
|
||||||
Benchmark.stop("Enable", "Enable");
|
String benchTime = " (" + timings.end("Enable").map(Benchmark::toDurationString).orElse("-") + ")";
|
||||||
Log.logDebug("Enable");
|
logger.info(locale.getString(PluginLang.ENABLED) + benchTime);
|
||||||
Log.info(locale.getString(PluginLang.ENABLED));
|
|
||||||
} catch (AbstractMethodError e) {
|
} 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) {
|
} catch (EnableException e) {
|
||||||
Log.error("----------------------------------------");
|
logger.error("----------------------------------------");
|
||||||
Log.error("Error: " + e.getMessage());
|
logger.error("Error: " + e.getMessage());
|
||||||
Log.error("----------------------------------------");
|
logger.error("----------------------------------------");
|
||||||
Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
|
logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
|
||||||
onDisable();
|
onDisable();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.getGlobal().log(Level.SEVERE, this.getClass().getSimpleName() + "-v" + getVersion(), 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");
|
logger.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("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
|
||||||
onDisable();
|
onDisable();
|
||||||
}
|
}
|
||||||
registerCommand("plan", new PlanCommand(this));
|
PlanCommand command = component.planCommand();
|
||||||
|
command.registerCommands();
|
||||||
|
registerCommand("plan", command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ColorScheme getColorScheme() {
|
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
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
system.disable();
|
if (system != null) {
|
||||||
|
system.disable();
|
||||||
|
}
|
||||||
|
|
||||||
Log.info(locale.getString(PluginLang.DISABLED));
|
logger.info(locale != null ? locale.getString(PluginLang.DISABLED) : PluginLang.DISABLED.getDefault());
|
||||||
Benchmark.pluginDisabled(Plan.class);
|
|
||||||
DebugLog.pluginDisabled(Plan.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -162,7 +205,7 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BukkitSystem getSystem() {
|
public PlanSystem getSystem() {
|
||||||
return system;
|
return system;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,21 +6,74 @@ package com.djrapitops.plan;
|
|||||||
|
|
||||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||||
import com.djrapitops.plan.command.PlanBungeeCommand;
|
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.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.PluginLang;
|
import com.djrapitops.plan.system.locale.lang.PluginLang;
|
||||||
import com.djrapitops.plan.system.settings.theme.PlanColorScheme;
|
import com.djrapitops.plan.system.settings.theme.PlanColorScheme;
|
||||||
import com.djrapitops.plan.utilities.metrics.BStatsBungee;
|
import com.djrapitops.plan.utilities.metrics.BStatsBungee;
|
||||||
import com.djrapitops.plugin.BungeePlugin;
|
import com.djrapitops.plugin.BungeePlugin;
|
||||||
import com.djrapitops.plugin.StaticHolder;
|
import com.djrapitops.plugin.command.ColorScheme;
|
||||||
import com.djrapitops.plugin.api.Benchmark;
|
import com.djrapitops.plugin.command.CommandNode;
|
||||||
import com.djrapitops.plugin.api.utility.log.DebugLog;
|
import com.djrapitops.plugin.logging.L;
|
||||||
import com.djrapitops.plugin.api.utility.log.Log;
|
import dagger.BindsInstance;
|
||||||
import com.djrapitops.plugin.settings.ColorScheme;
|
import dagger.Component;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.io.InputStream;
|
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.
|
* Bungee Main class.
|
||||||
@ -29,48 +82,48 @@ import java.util.logging.Logger;
|
|||||||
*/
|
*/
|
||||||
public class PlanBungee extends BungeePlugin implements PlanPlugin {
|
public class PlanBungee extends BungeePlugin implements PlanPlugin {
|
||||||
|
|
||||||
private BungeeSystem system;
|
private PlanSystem system;
|
||||||
private Locale locale;
|
private Locale locale;
|
||||||
|
|
||||||
public static PlanBungee getInstance() {
|
|
||||||
return (PlanBungee) StaticHolder.getInstance(PlanBungee.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
super.onEnable();
|
PlanBungeeComponent component = DaggerPlanBungeeComponent.builder().plan(this).build();
|
||||||
try {
|
try {
|
||||||
system = new BungeeSystem(this);
|
system = component.system();
|
||||||
locale = system.getLocaleSystem().getLocale();
|
locale = system.getLocaleSystem().getLocale();
|
||||||
system.enable();
|
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) {
|
} 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) {
|
} catch (EnableException e) {
|
||||||
Log.error("----------------------------------------");
|
logger.error("----------------------------------------");
|
||||||
Log.error("Error: " + e.getMessage());
|
logger.error("Error: " + e.getMessage());
|
||||||
Log.error("----------------------------------------");
|
logger.error("----------------------------------------");
|
||||||
Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planbungee reload");
|
logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planbungee reload");
|
||||||
onDisable();
|
onDisable();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.getGlobal().log(Level.SEVERE, this.getClass().getSimpleName() + "-v" + getVersion(), e);
|
errorHandler.log(L.CRITICAL, this.getClass(), e);
|
||||||
Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planbungee reload");
|
logger.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");
|
logger.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
|
||||||
onDisable();
|
onDisable();
|
||||||
}
|
}
|
||||||
registerCommand("planbungee", new PlanBungeeCommand(this));
|
PlanBungeeCommand command = component.planCommand();
|
||||||
|
command.registerCommands();
|
||||||
|
registerCommand("planbungee", command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
system.disable();
|
system.disable();
|
||||||
|
|
||||||
Log.info(locale.getString(PluginLang.DISABLED));
|
logger.info(locale.getString(PluginLang.DISABLED));
|
||||||
Benchmark.pluginDisabled(PlanBungee.class);
|
|
||||||
DebugLog.pluginDisabled(PlanBungee.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -90,11 +143,11 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ColorScheme getColorScheme() {
|
public ColorScheme getColorScheme() {
|
||||||
return PlanColorScheme.create();
|
return PlanColorScheme.create(system.getConfigSystem().getConfig(), logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BungeeSystem getSystem() {
|
public PlanSystem getSystem() {
|
||||||
return system;
|
return system;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,8 +6,7 @@ package com.djrapitops.plan;
|
|||||||
|
|
||||||
import com.djrapitops.plan.system.PlanSystem;
|
import com.djrapitops.plan.system.PlanSystem;
|
||||||
import com.djrapitops.plugin.IPlugin;
|
import com.djrapitops.plugin.IPlugin;
|
||||||
import com.djrapitops.plugin.api.Check;
|
import com.djrapitops.plugin.command.ColorScheme;
|
||||||
import com.djrapitops.plugin.settings.ColorScheme;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -18,39 +17,6 @@ import java.io.InputStream;
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public interface PlanPlugin extends IPlugin {
|
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
|
@Override
|
||||||
File getDataFolder();
|
File getDataFolder();
|
||||||
|
@ -2,18 +2,26 @@ package com.djrapitops.plan;
|
|||||||
|
|
||||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||||
import com.djrapitops.plan.command.PlanCommand;
|
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.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.PluginLang;
|
import com.djrapitops.plan.system.locale.lang.PluginLang;
|
||||||
import com.djrapitops.plan.system.settings.theme.PlanColorScheme;
|
import com.djrapitops.plan.system.settings.theme.PlanColorScheme;
|
||||||
import com.djrapitops.plan.utilities.metrics.BStatsSponge;
|
import com.djrapitops.plan.utilities.metrics.BStatsSponge;
|
||||||
import com.djrapitops.plugin.SpongePlugin;
|
import com.djrapitops.plugin.SpongePlugin;
|
||||||
import com.djrapitops.plugin.StaticHolder;
|
import com.djrapitops.plugin.command.ColorScheme;
|
||||||
import com.djrapitops.plugin.api.Benchmark;
|
import com.djrapitops.plugin.command.CommandNode;
|
||||||
import com.djrapitops.plugin.api.utility.log.DebugLog;
|
import com.djrapitops.plugin.logging.L;
|
||||||
import com.djrapitops.plugin.api.utility.log.Log;
|
import dagger.BindsInstance;
|
||||||
import com.djrapitops.plugin.settings.ColorScheme;
|
import dagger.Component;
|
||||||
import com.google.inject.Inject;
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
import org.bstats.sponge.Metrics;
|
import org.bstats.sponge.Metrics;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.spongepowered.api.config.ConfigDir;
|
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.Dependency;
|
||||||
import org.spongepowered.api.plugin.Plugin;
|
import org.spongepowered.api.plugin.Plugin;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
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(
|
@Plugin(
|
||||||
id = "plan",
|
id = "plan",
|
||||||
name = "Plan",
|
name = "Plan",
|
||||||
@ -39,16 +93,16 @@ import java.io.InputStream;
|
|||||||
)
|
)
|
||||||
public class PlanSponge extends SpongePlugin implements PlanPlugin {
|
public class PlanSponge extends SpongePlugin implements PlanPlugin {
|
||||||
|
|
||||||
@Inject
|
@com.google.inject.Inject
|
||||||
private Metrics metrics;
|
private Metrics metrics;
|
||||||
|
|
||||||
@Inject
|
@com.google.inject.Inject
|
||||||
private Logger logger;
|
private Logger slf4jLogger;
|
||||||
|
|
||||||
@Inject
|
@com.google.inject.Inject
|
||||||
@ConfigDir(sharedRoot = false)
|
@ConfigDir(sharedRoot = false)
|
||||||
private File dataFolder;
|
private File dataFolder;
|
||||||
private SpongeSystem system;
|
private PlanSystem system;
|
||||||
private Locale locale;
|
private Locale locale;
|
||||||
|
|
||||||
@Listener
|
@Listener
|
||||||
@ -61,36 +115,37 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
|
|||||||
onDisable();
|
onDisable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlanSponge getInstance() {
|
|
||||||
return (PlanSponge) StaticHolder.getInstance(PlanSponge.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
super.onEnable();
|
PlanSpongeComponent component = DaggerPlanSpongeComponent.builder().plan(this).build();
|
||||||
try {
|
try {
|
||||||
system = new SpongeSystem(this);
|
system = component.system();
|
||||||
locale = system.getLocaleSystem().getLocale();
|
locale = system.getLocaleSystem().getLocale();
|
||||||
system.enable();
|
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) {
|
} 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) {
|
} catch (EnableException e) {
|
||||||
Log.error("----------------------------------------");
|
slf4jLogger.error("----------------------------------------");
|
||||||
Log.error("Error: " + e.getMessage());
|
slf4jLogger.error("Error: " + e.getMessage());
|
||||||
Log.error("----------------------------------------");
|
slf4jLogger.error("----------------------------------------");
|
||||||
Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
|
slf4jLogger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
|
||||||
onDisable();
|
onDisable();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.toLog(this.getClass().getSimpleName() + "-v" + getVersion(), e);
|
errorHandler.log(L.CRITICAL, this.getClass(), e);
|
||||||
Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
|
slf4jLogger.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");
|
slf4jLogger.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
|
||||||
onDisable();
|
onDisable();
|
||||||
}
|
}
|
||||||
registerCommand("plan", new PlanCommand(this));
|
PlanCommand command = component.planCommand();
|
||||||
|
command.registerCommands();
|
||||||
|
registerCommand("plan", command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -99,9 +154,7 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
|
|||||||
system.disable();
|
system.disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.info(locale.getString(PluginLang.DISABLED));
|
logger.info(locale.getString(PluginLang.DISABLED));
|
||||||
Benchmark.pluginDisabled(PlanSponge.class);
|
|
||||||
DebugLog.pluginDisabled(PlanSponge.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -111,7 +164,7 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ColorScheme getColorScheme() {
|
public ColorScheme getColorScheme() {
|
||||||
return PlanColorScheme.create();
|
return PlanColorScheme.create(system.getConfigSystem().getConfig(), logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -126,7 +179,7 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Logger getLogger() {
|
public Logger getLogger() {
|
||||||
return logger;
|
return slf4jLogger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -140,7 +193,7 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SpongeSystem getSystem() {
|
public PlanSystem getSystem() {
|
||||||
return system;
|
return system;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,29 +6,83 @@ package com.djrapitops.plan;
|
|||||||
|
|
||||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||||
import com.djrapitops.plan.command.PlanVelocityCommand;
|
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.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.PluginLang;
|
import com.djrapitops.plan.system.locale.lang.PluginLang;
|
||||||
import com.djrapitops.plan.system.settings.theme.PlanColorScheme;
|
import com.djrapitops.plan.system.settings.theme.PlanColorScheme;
|
||||||
import com.djrapitops.plugin.StaticHolder;
|
|
||||||
import com.djrapitops.plugin.VelocityPlugin;
|
import com.djrapitops.plugin.VelocityPlugin;
|
||||||
import com.djrapitops.plugin.api.Benchmark;
|
import com.djrapitops.plugin.command.ColorScheme;
|
||||||
import com.djrapitops.plugin.api.utility.log.DebugLog;
|
import com.djrapitops.plugin.command.CommandNode;
|
||||||
import com.djrapitops.plugin.api.utility.log.Log;
|
import com.djrapitops.plugin.logging.L;
|
||||||
import com.djrapitops.plugin.settings.ColorScheme;
|
|
||||||
import com.google.inject.Inject;
|
|
||||||
import com.velocitypowered.api.plugin.Plugin;
|
import com.velocitypowered.api.plugin.Plugin;
|
||||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
import dagger.BindsInstance;
|
||||||
|
import dagger.Component;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.file.Path;
|
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.
|
* Velocity Main class.
|
||||||
*
|
* <p>
|
||||||
* Based on the PlanBungee class
|
* Based on the PlanBungee class
|
||||||
*
|
*
|
||||||
* @author MicleBrick
|
* @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"})
|
@Plugin(id = "plan", name = "Plan", version = "4.4.6", description = "Player Analytics Plugin by Rsl1122", authors = {"Rsl1122"})
|
||||||
public class PlanVelocity extends VelocityPlugin implements PlanPlugin {
|
public class PlanVelocity extends VelocityPlugin implements PlanPlugin {
|
||||||
|
|
||||||
private VelocitySystem system;
|
private PlanSystem system;
|
||||||
private Locale locale;
|
private Locale locale;
|
||||||
|
|
||||||
public static PlanVelocity getInstance() {
|
@com.google.inject.Inject
|
||||||
return (PlanVelocity) StaticHolder.getInstance(PlanVelocity.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
@DataDirectory
|
@DataDirectory
|
||||||
private Path dataFolderPath;
|
private Path dataFolderPath;
|
||||||
|
@com.google.inject.Inject
|
||||||
|
private ProxyServer proxy;
|
||||||
|
@com.google.inject.Inject
|
||||||
|
private Logger slf4jLogger;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getDataFolder() {
|
public File getDataFolder() {
|
||||||
@ -54,45 +108,39 @@ public class PlanVelocity extends VelocityPlugin implements PlanPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
super.onEnable();
|
PlanVelocityComponent component = DaggerPlanVelocityComponent.builder().plan(this).build();
|
||||||
try {
|
try {
|
||||||
system = new VelocitySystem(this);
|
system = component.system();
|
||||||
locale = system.getLocaleSystem().getLocale();
|
locale = system.getLocaleSystem().getLocale();
|
||||||
system.enable();
|
system.enable();
|
||||||
|
|
||||||
Log.info(locale.getString(PluginLang.ENABLED));
|
logger.info(locale.getString(PluginLang.ENABLED));
|
||||||
} catch (AbstractMethodError e) {
|
} 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) {
|
} catch (EnableException e) {
|
||||||
Log.error("----------------------------------------");
|
logger.error("----------------------------------------");
|
||||||
Log.error("Error: " + e.getMessage());
|
logger.error("Error: " + e.getMessage());
|
||||||
Log.error("----------------------------------------");
|
logger.error("----------------------------------------");
|
||||||
Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planvelocity reload");
|
logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planbungee reload");
|
||||||
onDisable();
|
onDisable();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
getLogger().error(this.getClass().getSimpleName() + "-v" + getVersion(), e);
|
errorHandler.log(L.CRITICAL, this.getClass(), e);
|
||||||
Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planvelocity reload");
|
logger.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");
|
logger.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
|
||||||
onDisable();
|
onDisable();
|
||||||
}
|
}
|
||||||
registerCommand("planvelocity", new PlanVelocityCommand(this));
|
PlanVelocityCommand command = component.planCommand();
|
||||||
|
command.registerCommands();
|
||||||
|
registerCommand("planvelocity", command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
system.disable();
|
system.disable();
|
||||||
|
|
||||||
Log.info(locale.getString(PluginLang.DISABLED));
|
slf4jLogger.info(locale.getString(PluginLang.DISABLED));
|
||||||
Benchmark.pluginDisabled(PlanVelocity.class);
|
|
||||||
DebugLog.pluginDisabled(PlanVelocity.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getVersion() {
|
|
||||||
return getClass().getAnnotation(Plugin.class).version();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReload() {
|
public void onReload() {
|
||||||
// Nothing to be done, systems are disabled
|
// Nothing to be done, systems are disabled
|
||||||
@ -105,11 +153,11 @@ public class PlanVelocity extends VelocityPlugin implements PlanPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ColorScheme getColorScheme() {
|
public ColorScheme getColorScheme() {
|
||||||
return PlanColorScheme.create();
|
return PlanColorScheme.create(system.getConfigSystem().getConfig(), logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VelocitySystem getSystem() {
|
public PlanSystem getSystem() {
|
||||||
return system;
|
return system;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,19 +166,13 @@ public class PlanVelocity extends VelocityPlugin implements PlanPlugin {
|
|||||||
return reloading;
|
return reloading;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ProxyServer proxy;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProxyServer getProxy() {
|
public ProxyServer getProxy() {
|
||||||
return proxy;
|
return proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
|
||||||
private Logger logger;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Logger getLogger() {
|
protected Logger getLogger() {
|
||||||
return logger;
|
return slf4jLogger;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,10 @@ import com.djrapitops.plan.data.container.Session;
|
|||||||
import com.djrapitops.plan.data.store.keys.SessionKeys;
|
import com.djrapitops.plan.data.store.keys.SessionKeys;
|
||||||
import com.djrapitops.plan.system.cache.SessionCache;
|
import com.djrapitops.plan.system.cache.SessionCache;
|
||||||
import com.djrapitops.plan.system.database.databases.Database;
|
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.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -26,50 +28,57 @@ import java.util.UUID;
|
|||||||
*/
|
*/
|
||||||
public class ShutdownHook extends Thread {
|
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() {
|
private static boolean isActivated() {
|
||||||
return activated;
|
return activated != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void activate(ShutdownHook hook) {
|
private static void activate(ShutdownHook hook) {
|
||||||
activated = true;
|
activated = hook;
|
||||||
Runtime.getRuntime().addShutdownHook(hook);
|
Runtime.getRuntime().addShutdownHook(hook);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void deactivate() {
|
||||||
|
Runtime.getRuntime().removeShutdownHook(activated);
|
||||||
|
activated = null;
|
||||||
|
}
|
||||||
|
|
||||||
public void register() {
|
public void register() {
|
||||||
if (isActivated()) {
|
if (isActivated()) {
|
||||||
return;
|
deactivate();
|
||||||
}
|
}
|
||||||
activate(this);
|
activate(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Log.debug("Shutdown hook triggered.");
|
|
||||||
|
|
||||||
Database db = null;
|
|
||||||
try {
|
try {
|
||||||
Map<UUID, Session> activeSessions = SessionCache.getActiveSessions();
|
Map<UUID, Session> activeSessions = SessionCache.getActiveSessions();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
db = Database.getActive();
|
saveActiveSessions(activeSessions, now);
|
||||||
saveActiveSessions(db, activeSessions, now);
|
|
||||||
} catch (IllegalStateException ignored) {
|
} catch (IllegalStateException ignored) {
|
||||||
/* Database is not initialized */
|
/* Database is not initialized */
|
||||||
} catch (DBInitException e) {
|
} catch (DBInitException e) {
|
||||||
Log.toLog(this.getClass(), e);
|
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||||
} finally {
|
} finally {
|
||||||
if (db != null) {
|
try {
|
||||||
try {
|
database.close();
|
||||||
db.close();
|
} catch (DBException e) {
|
||||||
} catch (DBException e) {
|
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||||
Log.toLog(this.getClass(), e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveActiveSessions(Database db, Map<UUID, Session> activeSessions, long now) throws DBInitException {
|
private void saveActiveSessions(Map<UUID, Session> activeSessions, long now) throws DBInitException {
|
||||||
for (Map.Entry<UUID, Session> entry : activeSessions.entrySet()) {
|
for (Map.Entry<UUID, Session> entry : activeSessions.entrySet()) {
|
||||||
UUID uuid = entry.getKey();
|
UUID uuid = entry.getKey();
|
||||||
Session session = entry.getValue();
|
Session session = entry.getValue();
|
||||||
@ -77,13 +86,13 @@ public class ShutdownHook extends Thread {
|
|||||||
if (!end.isPresent()) {
|
if (!end.isPresent()) {
|
||||||
session.endSession(now);
|
session.endSession(now);
|
||||||
}
|
}
|
||||||
if (!db.isOpen()) {
|
if (!database.isOpen()) {
|
||||||
db.init();
|
database.init();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
db.save().session(uuid, session);
|
database.save().session(uuid, session);
|
||||||
} catch (DBOpException e) {
|
} catch (DBOpException e) {
|
||||||
Log.toLog(this.getClass(), e);
|
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
activeSessions.clear();
|
activeSessions.clear();
|
||||||
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,7 +6,8 @@ package com.djrapitops.plan.api;
|
|||||||
|
|
||||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||||
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
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.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -19,6 +20,15 @@ import java.util.UUID;
|
|||||||
*/
|
*/
|
||||||
public abstract class CommonAPI implements PlanAPI {
|
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
|
@Override
|
||||||
public String getPlayerInspectPageLink(UUID uuid) {
|
public String getPlayerInspectPageLink(UUID uuid) {
|
||||||
return getPlayerInspectPageLink(getPlayerName(uuid));
|
return getPlayerInspectPageLink(getPlayerName(uuid));
|
||||||
@ -31,7 +41,7 @@ public abstract class CommonAPI implements PlanAPI {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UUID playerNameToUUID(String playerName) {
|
public UUID playerNameToUUID(String playerName) {
|
||||||
return UUIDUtility.getUUIDOf(playerName);
|
return uuidUtility.getUUIDOf(playerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -39,7 +49,7 @@ public abstract class CommonAPI implements PlanAPI {
|
|||||||
try {
|
try {
|
||||||
return fetchFromPlanDB().getPlayerNames();
|
return fetchFromPlanDB().getPlayerNames();
|
||||||
} catch (DBOpException e) {
|
} catch (DBOpException e) {
|
||||||
Log.toLog(this.getClass(), e);
|
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||||
return new HashMap<>();
|
return new HashMap<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,10 @@
|
|||||||
package com.djrapitops.plan.api;
|
package com.djrapitops.plan.api;
|
||||||
|
|
||||||
import com.djrapitops.plan.data.plugin.PluginData;
|
import com.djrapitops.plan.data.plugin.PluginData;
|
||||||
import com.djrapitops.plan.system.PlanSystem;
|
|
||||||
import com.djrapitops.plan.system.database.databases.operation.FetchOperations;
|
import com.djrapitops.plan.system.database.databases.operation.FetchOperations;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -19,7 +19,16 @@ import java.util.UUID;
|
|||||||
public interface PlanAPI {
|
public interface PlanAPI {
|
||||||
|
|
||||||
static PlanAPI getInstance() {
|
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);
|
void addPluginDataSource(PluginData pluginData);
|
||||||
|
56
Plan/src/main/java/com/djrapitops/plan/api/ProxyAPI.java
Normal file
56
Plan/src/main/java/com/djrapitops/plan/api/ProxyAPI.java
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -4,10 +4,15 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.api;
|
package com.djrapitops.plan.api;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.data.plugin.HookHandler;
|
||||||
import com.djrapitops.plan.data.plugin.PluginData;
|
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.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;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -15,26 +20,36 @@ import java.util.UUID;
|
|||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class ServerAPI extends CommonAPI {
|
public class ServerAPI extends CommonAPI {
|
||||||
|
|
||||||
private final ServerSystem serverSystem;
|
private final HookHandler hookHandler;
|
||||||
|
private final Database database;
|
||||||
|
|
||||||
public ServerAPI(ServerSystem serverSystem) {
|
@Inject
|
||||||
this.serverSystem = serverSystem;
|
public ServerAPI(
|
||||||
|
UUIDUtility uuidUtility,
|
||||||
|
HookHandler hookHandler,
|
||||||
|
Database database,
|
||||||
|
ErrorHandler errorHandler
|
||||||
|
) {
|
||||||
|
super(uuidUtility, errorHandler);
|
||||||
|
this.hookHandler = hookHandler;
|
||||||
|
this.database = database;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addPluginDataSource(PluginData pluginData) {
|
public void addPluginDataSource(PluginData pluginData) {
|
||||||
serverSystem.getHookHandler().addPluginDataSource(pluginData);
|
hookHandler.addPluginDataSource(pluginData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPlayerName(UUID uuid) {
|
public String getPlayerName(UUID uuid) {
|
||||||
return serverSystem.getCacheSystem().getDataCache().getName(uuid);
|
return database.fetch().getPlayerName(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FetchOperations fetchFromPlanDB() {
|
public FetchOperations fetchFromPlanDB() {
|
||||||
return serverSystem.getDatabaseSystem().getActiveDatabase().fetch();
|
return database.fetch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,5 @@
|
|||||||
package com.djrapitops.plan.command;
|
package com.djrapitops.plan.command;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanPlugin;
|
|
||||||
import com.djrapitops.plan.command.commands.*;
|
import com.djrapitops.plan.command.commands.*;
|
||||||
import com.djrapitops.plan.command.commands.manage.ManageConDebugCommand;
|
import com.djrapitops.plan.command.commands.manage.ManageConDebugCommand;
|
||||||
import com.djrapitops.plan.command.commands.manage.ManageRawDataCommand;
|
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.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||||
import com.djrapitops.plan.system.settings.Permissions;
|
import com.djrapitops.plan.system.settings.Permissions;
|
||||||
|
import com.djrapitops.plugin.command.ColorScheme;
|
||||||
import com.djrapitops.plugin.command.CommandNode;
|
import com.djrapitops.plugin.command.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
import com.djrapitops.plugin.command.CommandType;
|
||||||
import com.djrapitops.plugin.command.TreeCmdNode;
|
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.
|
* TreeCommand for the /plan command, and all subcommands.
|
||||||
@ -21,36 +24,85 @@ import com.djrapitops.plugin.command.defaultcmds.StatusCommand;
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class PlanBungeeCommand extends TreeCmdNode {
|
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> 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> webUserCommand,
|
||||||
|
// Group 3
|
||||||
|
ManageConDebugCommand conDebugCommand,
|
||||||
|
ManageRawDataCommand rawDataCommand,
|
||||||
|
BungeeSetupToggleCommand setupToggleCommand,
|
||||||
|
ManageUninstalledCommand uninstalledCommand,
|
||||||
|
ReloadCommand reloadCommand,
|
||||||
|
DisableCommand disableCommand
|
||||||
|
) {
|
||||||
super("planbungee", Permissions.MANAGE.getPermission(), CommandType.CONSOLE, null);
|
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));
|
setInDepthHelp(locale.getArray(DeepHelpLang.PLAN));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerCommands() {
|
||||||
|
if (commandsRegistered) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
RegisterCommand registerCommand = new RegisterCommand(plugin);
|
|
||||||
CommandNode[] analyticsGroup = {
|
CommandNode[] analyticsGroup = {
|
||||||
new NetworkCommand(plugin),
|
networkCommand,
|
||||||
new ListServersCommand(plugin),
|
listServersCommand,
|
||||||
new ListPlayersCommand(plugin),
|
listPlayersCommand
|
||||||
};
|
};
|
||||||
CommandNode[] webGroup = {
|
CommandNode[] webGroup = {
|
||||||
registerCommand,
|
registerCommand,
|
||||||
new WebUserCommand(plugin, registerCommand, this),
|
webUserCommand.get()
|
||||||
};
|
};
|
||||||
CommandNode[] manageGroup = {
|
CommandNode[] manageGroup = {
|
||||||
new ManageConDebugCommand(plugin),
|
conDebugCommand,
|
||||||
new ManageRawDataCommand(plugin),
|
rawDataCommand,
|
||||||
new BungeeSetupToggleCommand(plugin),
|
setupToggleCommand,
|
||||||
new ManageUninstalledCommand(plugin),
|
uninstalledCommand,
|
||||||
new ReloadCommand(plugin),
|
reloadCommand,
|
||||||
new DisableCommand(plugin),
|
disableCommand
|
||||||
new StatusCommand<>(plugin, Permissions.MANAGE.getPermission(), plugin.getColorScheme()),
|
|
||||||
// (Settings.ALLOW_UPDATE.isTrue() ? new UpdateCommand() : null)
|
|
||||||
};
|
};
|
||||||
setNodeGroups(analyticsGroup, webGroup, manageGroup);
|
setNodeGroups(analyticsGroup, webGroup, manageGroup);
|
||||||
|
commandsRegistered = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
package com.djrapitops.plan.command;
|
package com.djrapitops.plan.command;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanPlugin;
|
|
||||||
import com.djrapitops.plan.command.commands.*;
|
import com.djrapitops.plan.command.commands.*;
|
||||||
import com.djrapitops.plan.system.locale.Locale;
|
import com.djrapitops.plan.system.locale.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
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.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.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
import com.djrapitops.plugin.command.CommandType;
|
||||||
import com.djrapitops.plugin.command.TreeCmdNode;
|
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.
|
* TreeCommand for the /plan command, and all SubCommands.
|
||||||
@ -19,39 +22,97 @@ import com.djrapitops.plugin.command.defaultcmds.StatusCommand;
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class PlanCommand extends TreeCmdNode {
|
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> webUserCommand;
|
||||||
|
private final RegisterCommand registerCommand;
|
||||||
|
private final InfoCommand infoCommand;
|
||||||
|
private final ReloadCommand reloadCommand;
|
||||||
|
private final Lazy<ManageCommand> 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> webUserCommand,
|
||||||
|
RegisterCommand registerCommand,
|
||||||
|
// Group 3
|
||||||
|
InfoCommand infoCommand,
|
||||||
|
ReloadCommand reloadCommand,
|
||||||
|
Lazy<ManageCommand> manageCommand,
|
||||||
|
DevCommand devCommand
|
||||||
|
) {
|
||||||
super("plan", "", CommandType.CONSOLE, null);
|
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));
|
setInDepthHelp(locale.getArray(DeepHelpLang.PLAN));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerCommands() {
|
||||||
|
if (commandsRegistered) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
RegisterCommand registerCommand = new RegisterCommand(plugin);
|
|
||||||
CommandNode[] analyticsGroup = {
|
CommandNode[] analyticsGroup = {
|
||||||
new InspectCommand(plugin),
|
inspectCommand,
|
||||||
new QInspectCommand(plugin),
|
qInspectCommand,
|
||||||
new SearchCommand(plugin),
|
searchCommand,
|
||||||
new ListPlayersCommand(plugin),
|
listPlayersCommand,
|
||||||
new AnalyzeCommand(plugin),
|
analyzeCommand,
|
||||||
new NetworkCommand(plugin),
|
networkCommand,
|
||||||
new ListServersCommand(plugin)
|
listServersCommand
|
||||||
};
|
};
|
||||||
CommandNode[] webGroup = {
|
CommandNode[] webGroup = {
|
||||||
new WebUserCommand(plugin, registerCommand, this),
|
webUserCommand.get(),
|
||||||
registerCommand
|
registerCommand
|
||||||
};
|
};
|
||||||
CommandNode[] manageGroup = {
|
CommandNode[] manageGroup = {
|
||||||
new InfoCommand(plugin),
|
infoCommand,
|
||||||
new ReloadCommand(plugin),
|
reloadCommand,
|
||||||
new ManageCommand(plugin, this),
|
manageCommand.get(),
|
||||||
new StatusCommand<>(plugin, Permissions.MANAGE.getPermission(), plugin.getColorScheme()),
|
config.isTrue(Settings.DEV_MODE) ? devCommand : null
|
||||||
(Settings.DEV_MODE.isTrue() ? new DevCommand(plugin) : null),
|
|
||||||
// (Settings.ALLOW_UPDATE.isTrue() ? new UpdateCommand() : null)
|
|
||||||
};
|
};
|
||||||
setNodeGroups(analyticsGroup, webGroup, manageGroup);
|
setNodeGroups(analyticsGroup, webGroup, manageGroup);
|
||||||
|
commandsRegistered = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.djrapitops.plan.command;
|
package com.djrapitops.plan.command;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanPlugin;
|
|
||||||
import com.djrapitops.plan.command.commands.*;
|
import com.djrapitops.plan.command.commands.*;
|
||||||
import com.djrapitops.plan.command.commands.manage.ManageConDebugCommand;
|
import com.djrapitops.plan.command.commands.manage.ManageConDebugCommand;
|
||||||
import com.djrapitops.plan.command.commands.manage.ManageRawDataCommand;
|
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.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||||
import com.djrapitops.plan.system.settings.Permissions;
|
import com.djrapitops.plan.system.settings.Permissions;
|
||||||
|
import com.djrapitops.plugin.command.ColorScheme;
|
||||||
import com.djrapitops.plugin.command.CommandNode;
|
import com.djrapitops.plugin.command.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
import com.djrapitops.plugin.command.CommandType;
|
||||||
import com.djrapitops.plugin.command.TreeCmdNode;
|
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.
|
* TreeCommand for the /plan command, and all subcommands.
|
||||||
* <p>
|
* <p>
|
||||||
* Uses the Abstract Plugin Framework for easier command management.
|
* Uses the Abstract Plugin Framework for easier command management.
|
||||||
*
|
*
|
||||||
* Based on PlanBungeeCommand
|
* @author Rsl1122
|
||||||
*
|
* @since 1.0.0
|
||||||
* @author MicleBrick
|
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class PlanVelocityCommand extends TreeCmdNode {
|
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> 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> webUserCommand,
|
||||||
|
// Group 3
|
||||||
|
ManageConDebugCommand conDebugCommand,
|
||||||
|
ManageRawDataCommand rawDataCommand,
|
||||||
|
BungeeSetupToggleCommand setupToggleCommand,
|
||||||
|
ManageUninstalledCommand uninstalledCommand,
|
||||||
|
ReloadCommand reloadCommand,
|
||||||
|
DisableCommand disableCommand
|
||||||
|
) {
|
||||||
super("planvelocity", Permissions.MANAGE.getPermission(), CommandType.CONSOLE, null);
|
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));
|
setInDepthHelp(locale.getArray(DeepHelpLang.PLAN));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerCommands() {
|
||||||
|
if (commandsRegistered) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
RegisterCommand registerCommand = new RegisterCommand(plugin);
|
|
||||||
CommandNode[] analyticsGroup = {
|
CommandNode[] analyticsGroup = {
|
||||||
new NetworkCommand(plugin),
|
networkCommand,
|
||||||
new ListServersCommand(plugin),
|
listServersCommand,
|
||||||
new ListPlayersCommand(plugin),
|
listPlayersCommand
|
||||||
};
|
};
|
||||||
CommandNode[] webGroup = {
|
CommandNode[] webGroup = {
|
||||||
registerCommand,
|
registerCommand,
|
||||||
new WebUserCommand(plugin, registerCommand, this),
|
webUserCommand.get()
|
||||||
};
|
};
|
||||||
CommandNode[] manageGroup = {
|
CommandNode[] manageGroup = {
|
||||||
new ManageConDebugCommand(plugin),
|
conDebugCommand,
|
||||||
new ManageRawDataCommand(plugin),
|
rawDataCommand,
|
||||||
new BungeeSetupToggleCommand(plugin), // perhaps rename to ProxySetupToggleCommand ?
|
setupToggleCommand,
|
||||||
new ManageUninstalledCommand(plugin),
|
uninstalledCommand,
|
||||||
new ReloadCommand(plugin),
|
reloadCommand,
|
||||||
new DisableCommand(plugin),
|
disableCommand
|
||||||
new StatusCommand<>(plugin, Permissions.MANAGE.getPermission(), plugin.getColorScheme()),
|
|
||||||
// (Settings.ALLOW_UPDATE.isTrue() ? new UpdateCommand() : null)
|
|
||||||
};
|
};
|
||||||
setNodeGroups(analyticsGroup, webGroup, manageGroup);
|
setNodeGroups(analyticsGroup, webGroup, manageGroup);
|
||||||
|
commandsRegistered = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.djrapitops.plan.command.commands;
|
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.connection.WebException;
|
||||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||||
import com.djrapitops.plan.system.database.databases.Database;
|
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.locale.lang.ManageLang;
|
||||||
import com.djrapitops.plan.system.processing.Processing;
|
import com.djrapitops.plan.system.processing.Processing;
|
||||||
import com.djrapitops.plan.system.settings.Permissions;
|
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.utility.log.Log;
|
|
||||||
import com.djrapitops.plugin.command.CommandNode;
|
import com.djrapitops.plugin.command.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
import com.djrapitops.plugin.command.CommandType;
|
||||||
import com.djrapitops.plugin.command.CommandUtils;
|
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.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -32,14 +34,38 @@ import java.util.UUID;
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class AnalyzeCommand extends CommandNode {
|
public class AnalyzeCommand extends CommandNode {
|
||||||
|
|
||||||
private final Locale locale;
|
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);
|
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));
|
setShortHelp(locale.getString(CmdHelpLang.ANALYZE));
|
||||||
setInDepthHelp(locale.getArray(DeepHelpLang.ANALYZE));
|
setInDepthHelp(locale.getArray(DeepHelpLang.ANALYZE));
|
||||||
@ -47,27 +73,27 @@ public class AnalyzeCommand extends CommandNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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));
|
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
|
||||||
|
|
||||||
Processing.submitNonCritical(() -> {
|
processing.submitNonCritical(() -> {
|
||||||
try {
|
try {
|
||||||
Server server = getServer(args).orElseGet(ServerInfo::getServer);
|
Server server = getServer(args).orElseGet(serverInfo::getServer);
|
||||||
UUID serverUUID = server.getUuid();
|
UUID serverUUID = server.getUuid();
|
||||||
|
|
||||||
InfoSystem.getInstance().generateAnalysisPage(serverUUID);
|
infoSystem.generateAnalysisPage(serverUUID);
|
||||||
sendWebUserNotificationIfNecessary(sender);
|
sendWebUserNotificationIfNecessary(sender);
|
||||||
sendLink(server, sender);
|
sendLink(server, sender);
|
||||||
} catch (DBOpException | WebException e) {
|
} catch (DBOpException | WebException e) {
|
||||||
sender.sendMessage("§cError occurred: " + e.toString());
|
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 target = "/server/" + server.getName();
|
||||||
String url = ConnectionSystem.getAddress() + target;
|
String url = connectionSystem.getMainAddress() + target;
|
||||||
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
|
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
|
||||||
sender.sendMessage(locale.getString(CommandLang.HEADER_ANALYSIS));
|
sender.sendMessage(locale.getString(CommandLang.HEADER_ANALYSIS));
|
||||||
// Link
|
// Link
|
||||||
@ -81,19 +107,17 @@ public class AnalyzeCommand extends CommandNode {
|
|||||||
sender.sendMessage(">");
|
sender.sendMessage(">");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendWebUserNotificationIfNecessary(ISender sender) {
|
private void sendWebUserNotificationIfNecessary(Sender sender) {
|
||||||
if (WebServerSystem.getInstance().getWebServer().isAuthRequired() && CommandUtils.isPlayer(sender)) {
|
if (webServer.isAuthRequired() &&
|
||||||
|
CommandUtils.isPlayer(sender) &&
|
||||||
boolean senderHasWebUser = Database.getActive().check().doesWebUserExists(sender.getName());
|
!database.check().doesWebUserExists(sender.getName())) {
|
||||||
if (!senderHasWebUser) {
|
sender.sendMessage("§e" + locale.getString(CommandLang.NO_WEB_USER_NOTIFY));
|
||||||
sender.sendMessage("§e" + locale.getString(CommandLang.NO_WEB_USER_NOTIFY));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<Server> getServer(String[] args) {
|
private Optional<Server> getServer(String[] args) {
|
||||||
if (args.length >= 1 && ConnectionSystem.getInstance().isServerAvailable()) {
|
if (args.length >= 1 && connectionSystem.isServerAvailable()) {
|
||||||
Map<UUID, Server> bukkitServers = Database.getActive().fetch().getBukkitServers();
|
Map<UUID, Server> bukkitServers = database.fetch().getBukkitServers();
|
||||||
String serverIdentifier = getGivenIdentifier(args);
|
String serverIdentifier = getGivenIdentifier(args);
|
||||||
for (Map.Entry<UUID, Server> entry : bukkitServers.entrySet()) {
|
for (Map.Entry<UUID, Server> entry : bukkitServers.entrySet()) {
|
||||||
Server server = entry.getValue();
|
Server server = entry.getValue();
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.command.commands;
|
package com.djrapitops.plan.command.commands;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanPlugin;
|
|
||||||
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||||
import com.djrapitops.plan.system.locale.Locale;
|
import com.djrapitops.plan.system.locale.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
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.plan.system.settings.Permissions;
|
||||||
import com.djrapitops.plugin.command.CommandNode;
|
import com.djrapitops.plugin.command.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
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.
|
* 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 {
|
public class BungeeSetupToggleCommand extends CommandNode {
|
||||||
|
|
||||||
private final Locale locale;
|
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);
|
super("setup", Permissions.MANAGE.getPermission(), CommandType.ALL);
|
||||||
|
|
||||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
this.locale = locale;
|
||||||
|
this.connectionSystem = connectionSystem;
|
||||||
|
|
||||||
setShortHelp(locale.getString(CmdHelpLang.SETUP));
|
setShortHelp(locale.getString(CmdHelpLang.SETUP));
|
||||||
setInDepthHelp(locale.getArray(DeepHelpLang.SETUP));
|
setInDepthHelp(locale.getArray(DeepHelpLang.SETUP));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(ISender sender, String s, String[] strings) {
|
public void onCommand(Sender sender, String s, String[] strings) {
|
||||||
boolean setupAllowed = ConnectionSystem.isSetupAllowed();
|
if (connectionSystem.isSetupAllowed()) {
|
||||||
ConnectionSystem connectionSystem = ConnectionSystem.getInstance();
|
|
||||||
|
|
||||||
if (setupAllowed) {
|
|
||||||
connectionSystem.setSetupAllowed(false);
|
connectionSystem.setSetupAllowed(false);
|
||||||
} else {
|
} else {
|
||||||
connectionSystem.setSetupAllowed(true);
|
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);
|
sender.sendMessage(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,15 +4,15 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.command.commands;
|
package com.djrapitops.plan.command.commands;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanPlugin;
|
|
||||||
import com.djrapitops.plan.system.locale.Locale;
|
import com.djrapitops.plan.system.locale.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||||
import com.djrapitops.plugin.command.CommandNode;
|
import com.djrapitops.plugin.command.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
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 com.djrapitops.plugin.utilities.Verify;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,17 +24,18 @@ public class DevCommand extends CommandNode {
|
|||||||
|
|
||||||
private final Locale locale;
|
private final Locale locale;
|
||||||
|
|
||||||
public DevCommand(PlanPlugin plugin) {
|
@Inject
|
||||||
|
public DevCommand(Locale locale) {
|
||||||
super("dev", "plan.*", CommandType.PLAYER_OR_ARGS);
|
super("dev", "plan.*", CommandType.PLAYER_OR_ARGS);
|
||||||
|
|
||||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
this.locale = locale;
|
||||||
|
|
||||||
setShortHelp(locale.get(CmdHelpLang.DEV).toString());
|
setShortHelp(locale.get(CmdHelpLang.DEV).toString());
|
||||||
setArguments("<feature>");
|
setArguments("<feature>");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(ISender sender, String cmd, String[] args) {
|
public void onCommand(Sender sender, String cmd, String[] args) {
|
||||||
Verify.isTrue(args.length >= 1,
|
Verify.isTrue(args.length >= 1,
|
||||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
||||||
|
|
||||||
|
@ -7,24 +7,29 @@ import com.djrapitops.plan.system.locale.lang.CommandLang;
|
|||||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||||
import com.djrapitops.plugin.command.CommandNode;
|
import com.djrapitops.plugin.command.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
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 {
|
public class DisableCommand extends CommandNode {
|
||||||
|
|
||||||
private final Locale locale;
|
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);
|
super("disable", "plan.reload", CommandType.ALL);
|
||||||
|
|
||||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
this.plugin = plugin;
|
||||||
|
this.locale = locale;
|
||||||
|
|
||||||
setShortHelp(locale.getString(CmdHelpLang.DISABLE));
|
setShortHelp(locale.getString(CmdHelpLang.DISABLE));
|
||||||
setInDepthHelp(locale.getArray(DeepHelpLang.DISABLE));
|
setInDepthHelp(locale.getArray(DeepHelpLang.DISABLE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||||
PlanPlugin.getInstance().onDisable();
|
plugin.onDisable();
|
||||||
sender.sendMessage(locale.getString(CommandLang.DISABLE_DISABLED));
|
sender.sendMessage(locale.getString(CommandLang.DISABLE_DISABLED));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,9 @@ import com.djrapitops.plan.system.settings.Permissions;
|
|||||||
import com.djrapitops.plan.system.update.VersionCheckSystem;
|
import com.djrapitops.plan.system.update.VersionCheckSystem;
|
||||||
import com.djrapitops.plugin.command.CommandNode;
|
import com.djrapitops.plugin.command.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
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.
|
* 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 PlanPlugin plugin;
|
||||||
private final Locale locale;
|
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);
|
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());
|
setShortHelp(locale.get(CmdHelpLang.INFO).toString());
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 yes = locale.getString(GenericLang.YES);
|
||||||
String no = locale.getString(GenericLang.NO);
|
String no = locale.getString(GenericLang.NO);
|
||||||
|
|
||||||
String updateAvailable = VersionCheckSystem.isNewVersionAvailable() ? yes : no;
|
String updateAvailable = versionCheckSystem.isNewVersionAvailable() ? yes : no;
|
||||||
String connectedToBungee = ConnectionSystem.getInstance().isServerAvailable() ? yes : no;
|
String connectedToBungee = connectionSystem.isServerAvailable() ? yes : no;
|
||||||
String[] messages = {
|
String[] messages = {
|
||||||
locale.getString(CommandLang.HEADER_INFO),
|
locale.getString(CommandLang.HEADER_INFO),
|
||||||
"",
|
"",
|
||||||
locale.getString(CommandLang.INFO_VERSION, plugin.getVersion()),
|
locale.getString(CommandLang.INFO_VERSION, plugin.getVersion()),
|
||||||
locale.getString(CommandLang.INFO_UPDATE, updateAvailable),
|
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),
|
locale.getString(CommandLang.INFO_BUNGEE_CONNECTION, connectedToBungee),
|
||||||
"",
|
"",
|
||||||
">"
|
">"
|
||||||
|
@ -1,26 +1,26 @@
|
|||||||
package com.djrapitops.plan.command.commands;
|
package com.djrapitops.plan.command.commands;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanPlugin;
|
|
||||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||||
import com.djrapitops.plan.system.database.databases.Database;
|
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.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||||
import com.djrapitops.plan.system.processing.Processing;
|
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.settings.Permissions;
|
||||||
import com.djrapitops.plan.system.webserver.WebServer;
|
import com.djrapitops.plan.system.webserver.WebServer;
|
||||||
import com.djrapitops.plan.utilities.MiscUtils;
|
import com.djrapitops.plan.utilities.MiscUtils;
|
||||||
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
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.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
import com.djrapitops.plugin.command.CommandType;
|
||||||
import com.djrapitops.plugin.command.CommandUtils;
|
import com.djrapitops.plugin.command.CommandUtils;
|
||||||
import com.djrapitops.plugin.command.ISender;
|
import com.djrapitops.plugin.command.Sender;
|
||||||
import com.djrapitops.plugin.task.AbsRunnable;
|
import com.djrapitops.plugin.logging.L;
|
||||||
import com.djrapitops.plugin.task.RunnableFactory;
|
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,19 +32,43 @@ import java.util.UUID;
|
|||||||
public class InspectCommand extends CommandNode {
|
public class InspectCommand extends CommandNode {
|
||||||
|
|
||||||
private final Locale locale;
|
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);
|
super("inspect", Permissions.INSPECT.getPermission(), CommandType.PLAYER_OR_ARGS);
|
||||||
|
this.processorFactory = processorFactory;
|
||||||
|
this.processing = processing;
|
||||||
|
this.connectionSystem = connectionSystem;
|
||||||
setArguments("<player>");
|
setArguments("<player>");
|
||||||
|
|
||||||
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));
|
setShortHelp(locale.getString(CmdHelpLang.INSPECT));
|
||||||
setInDepthHelp(locale.getArray(DeepHelpLang.INSPECT));
|
setInDepthHelp(locale.getArray(DeepHelpLang.INSPECT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
String playerName = MiscUtils.getPlayerName(args, sender);
|
||||||
|
|
||||||
if (playerName == null) {
|
if (playerName == null) {
|
||||||
@ -54,42 +78,53 @@ public class InspectCommand extends CommandNode {
|
|||||||
runInspectTask(playerName, sender);
|
runInspectTask(playerName, sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runInspectTask(String playerName, ISender sender) {
|
private void runInspectTask(String playerName, Sender sender) {
|
||||||
RunnableFactory.createNew(new AbsRunnable("InspectTask") {
|
processing.submitNonCritical(() -> {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
UUID uuid = uuidUtility.getUUIDOf(playerName);
|
||||||
try {
|
if (uuid == null) {
|
||||||
UUID uuid = UUIDUtility.getUUIDOf(playerName);
|
sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_VALID));
|
||||||
if (uuid == null) {
|
return;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
private void checkWebUserAndNotify(Sender sender) {
|
||||||
if (CommandUtils.isPlayer(sender) && WebServer.getInstance().isAuthRequired()) {
|
if (CommandUtils.isPlayer(sender) && webServer.isAuthRequired()) {
|
||||||
boolean senderHasWebUser = activeDB.check().doesWebUserExists(sender.getName());
|
boolean senderHasWebUser = database.check().doesWebUserExists(sender.getName());
|
||||||
|
|
||||||
if (!senderHasWebUser) {
|
if (!senderHasWebUser) {
|
||||||
sender.sendMessage("§e" + locale.getString(CommandLang.NO_WEB_USER_NOTIFY));
|
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(">");
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,6 +1,5 @@
|
|||||||
package com.djrapitops.plan.command.commands;
|
package com.djrapitops.plan.command.commands;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanPlugin;
|
|
||||||
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||||
import com.djrapitops.plan.system.locale.Locale;
|
import com.djrapitops.plan.system.locale.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
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.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
import com.djrapitops.plugin.command.CommandType;
|
||||||
import com.djrapitops.plugin.command.CommandUtils;
|
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.
|
* 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 {
|
public class ListPlayersCommand extends CommandNode {
|
||||||
|
|
||||||
private final Locale locale;
|
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);
|
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));
|
setShortHelp(locale.getString(CmdHelpLang.PLAYERS));
|
||||||
setInDepthHelp(locale.getArray(DeepHelpLang.PLAYERS));
|
setInDepthHelp(locale.getArray(DeepHelpLang.PLAYERS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||||
sendListMsg(sender);
|
sendListMsg(sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendListMsg(ISender sender) {
|
private void sendListMsg(Sender sender) {
|
||||||
sender.sendMessage(locale.getString(CommandLang.HEADER_PLAYERS));
|
sender.sendMessage(locale.getString(CommandLang.HEADER_PLAYERS));
|
||||||
|
|
||||||
// Link
|
// Link
|
||||||
String url = ConnectionSystem.getAddress() + "/players/";
|
String url = connectionSystem.getMainAddress() + "/players/";
|
||||||
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
|
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
|
||||||
boolean console = !CommandUtils.isPlayer(sender);
|
boolean console = !CommandUtils.isPlayer(sender);
|
||||||
if (console) {
|
if (console) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.djrapitops.plan.command.commands;
|
package com.djrapitops.plan.command.commands;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanPlugin;
|
|
||||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||||
import com.djrapitops.plan.system.database.databases.Database;
|
import com.djrapitops.plan.system.database.databases.Database;
|
||||||
import com.djrapitops.plan.system.info.server.Server;
|
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.CommandLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||||
import com.djrapitops.plan.system.settings.Permissions;
|
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.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
import com.djrapitops.plugin.command.CommandType;
|
||||||
import com.djrapitops.plugin.command.ISender;
|
import com.djrapitops.plugin.command.Sender;
|
||||||
import com.djrapitops.plugin.settings.ColorScheme;
|
import com.djrapitops.plugin.logging.L;
|
||||||
|
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,35 +26,48 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class ListServersCommand extends CommandNode {
|
public class ListServersCommand extends CommandNode {
|
||||||
|
|
||||||
private final PlanPlugin plugin;
|
|
||||||
private final Locale locale;
|
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);
|
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));
|
setShortHelp(locale.getString(CmdHelpLang.SERVERS));
|
||||||
setInDepthHelp(locale.getArray(DeepHelpLang.SERVERS));
|
setInDepthHelp(locale.getArray(DeepHelpLang.SERVERS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||||
ColorScheme colorScheme = plugin.getColorScheme();
|
|
||||||
String sCol = colorScheme.getSecondaryColor();
|
String sCol = colorScheme.getSecondaryColor();
|
||||||
String tCol = colorScheme.getTertiaryColor();
|
String tCol = colorScheme.getTertiaryColor();
|
||||||
|
Formatter<Server> serverFormatter = serverLister(sCol, tCol);
|
||||||
try {
|
try {
|
||||||
sender.sendMessage(locale.getString(CommandLang.HEADER_SERVERS));
|
sender.sendMessage(locale.getString(CommandLang.HEADER_SERVERS));
|
||||||
List<Server> servers = Database.getActive().fetch().getServers();
|
sendServers(sender, serverFormatter);
|
||||||
for (Server server : servers) {
|
|
||||||
sender.sendMessage(" " + tCol + server.getId() + sCol + " : " + server.getName() + " : " + server.getWebAddress());
|
|
||||||
}
|
|
||||||
sender.sendMessage(">");
|
sender.sendMessage(">");
|
||||||
} catch (DBOpException e) {
|
} catch (DBOpException e) {
|
||||||
sender.sendMessage("§cDatabase Exception occurred.");
|
sender.sendMessage("§cDatabase Exception occurred.");
|
||||||
Log.toLog(this.getClass(), e);
|
errorHandler.log(L.WARN, this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendServers(Sender sender, Formatter<Server> serverFormatter) {
|
||||||
|
List<Server> servers = database.fetch().getServers();
|
||||||
|
for (Server server : servers) {
|
||||||
|
sender.sendMessage(serverFormatter.apply(server));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Formatter<Server> serverLister(String tertiaryColor, String secondaryColor) {
|
||||||
|
return server -> " " + tertiaryColor + server.getId() + secondaryColor + " : " + server.getName() + " : " + server.getWebAddress();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
package com.djrapitops.plan.command.commands;
|
package com.djrapitops.plan.command.commands;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanPlugin;
|
|
||||||
import com.djrapitops.plan.command.commands.manage.*;
|
import com.djrapitops.plan.command.commands.manage.*;
|
||||||
import com.djrapitops.plan.system.locale.Locale;
|
import com.djrapitops.plan.system.locale.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||||
import com.djrapitops.plan.system.settings.Permissions;
|
import com.djrapitops.plan.system.settings.Permissions;
|
||||||
|
import com.djrapitops.plugin.command.ColorScheme;
|
||||||
import com.djrapitops.plugin.command.CommandNode;
|
import com.djrapitops.plugin.command.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
import com.djrapitops.plugin.command.CommandType;
|
||||||
import com.djrapitops.plugin.command.TreeCmdNode;
|
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.
|
* 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 class ManageCommand extends TreeCmdNode {
|
||||||
|
|
||||||
public ManageCommand(PlanPlugin plugin, CommandNode parent) {
|
@Inject
|
||||||
super("manage|m", Permissions.MANAGE.getPermission(), CommandType.CONSOLE, parent);
|
public ManageCommand(ColorScheme colorScheme, Locale locale, @Named("mainCommand") Lazy<CommandNode> parent,
|
||||||
|
// Group 1
|
||||||
Locale locale = plugin.getSystem().getLocaleSystem().getLocale();
|
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));
|
setShortHelp(locale.getString(CmdHelpLang.MANAGE));
|
||||||
setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE));
|
setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE));
|
||||||
super.setColorScheme(plugin.getColorScheme());
|
|
||||||
CommandNode[] databaseGroup = {
|
CommandNode[] databaseGroup = {
|
||||||
new ManageRawDataCommand(plugin),
|
rawDataCommand,
|
||||||
new ManageMoveCommand(plugin),
|
moveCommand,
|
||||||
new ManageBackupCommand(plugin),
|
backupCommand,
|
||||||
new ManageRestoreCommand(plugin),
|
restoreCommand,
|
||||||
new ManageRemoveCommand(plugin),
|
hotSwapCommand,
|
||||||
new ManageHotSwapCommand(plugin),
|
removeCommand,
|
||||||
new ManageClearCommand(plugin),
|
clearCommand,
|
||||||
};
|
};
|
||||||
CommandNode[] pluginGroup = {
|
CommandNode[] pluginGroup = {
|
||||||
new ManageSetupCommand(plugin),
|
setupCommand,
|
||||||
new ManageConDebugCommand(plugin),
|
conDebugCommand,
|
||||||
new ManageImportCommand(plugin),
|
importCommand,
|
||||||
new ManageDisableCommand(plugin),
|
disableCommand,
|
||||||
new ManageUninstalledCommand(plugin)
|
uninstalledCommand
|
||||||
};
|
};
|
||||||
setNodeGroups(databaseGroup, pluginGroup);
|
setNodeGroups(databaseGroup, pluginGroup);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.djrapitops.plan.command.commands;
|
package com.djrapitops.plan.command.commands;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanPlugin;
|
|
||||||
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||||
import com.djrapitops.plan.system.locale.Locale;
|
import com.djrapitops.plan.system.locale.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
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.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
import com.djrapitops.plugin.command.CommandType;
|
||||||
import com.djrapitops.plugin.command.CommandUtils;
|
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.
|
* Command used to display url to the network page.
|
||||||
@ -20,26 +21,29 @@ import com.djrapitops.plugin.command.ISender;
|
|||||||
public class NetworkCommand extends CommandNode {
|
public class NetworkCommand extends CommandNode {
|
||||||
|
|
||||||
private final Locale locale;
|
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);
|
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));
|
setShortHelp(locale.getString(CmdHelpLang.NETWORK));
|
||||||
setInDepthHelp(locale.getArray(DeepHelpLang.NETWORK));
|
setInDepthHelp(locale.getArray(DeepHelpLang.NETWORK));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||||
sendNetworkMsg(sender);
|
sendNetworkMsg(sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendNetworkMsg(ISender sender) {
|
private void sendNetworkMsg(Sender sender) {
|
||||||
sender.sendMessage(locale.getString(CommandLang.HEADER_NETWORK));
|
sender.sendMessage(locale.getString(CommandLang.HEADER_NETWORK));
|
||||||
|
|
||||||
// Link
|
// Link
|
||||||
String url = ConnectionSystem.getAddress() + "/network/";
|
String url = connectionSystem.getMainAddress() + "/network/";
|
||||||
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
|
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
|
||||||
boolean console = !CommandUtils.isPlayer(sender);
|
boolean console = !CommandUtils.isPlayer(sender);
|
||||||
if (console) {
|
if (console) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.djrapitops.plan.command.commands;
|
package com.djrapitops.plan.command.commands;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanPlugin;
|
|
||||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||||
import com.djrapitops.plan.data.container.GeoInfo;
|
import com.djrapitops.plan.data.container.GeoInfo;
|
||||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
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.ActivityIndex;
|
||||||
import com.djrapitops.plan.data.store.mutators.GeoInfoMutator;
|
import com.djrapitops.plan.data.store.mutators.GeoInfoMutator;
|
||||||
import com.djrapitops.plan.data.store.mutators.SessionsMutator;
|
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.data.store.objects.DateHolder;
|
||||||
import com.djrapitops.plan.system.database.databases.Database;
|
import com.djrapitops.plan.system.database.databases.Database;
|
||||||
import com.djrapitops.plan.system.locale.Locale;
|
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.CommandLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.GenericLang;
|
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.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.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.plan.utilities.uuid.UUIDUtility;
|
||||||
import com.djrapitops.plugin.api.utility.log.Log;
|
|
||||||
import com.djrapitops.plugin.command.CommandNode;
|
import com.djrapitops.plugin.command.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
import com.djrapitops.plugin.command.CommandType;
|
||||||
import com.djrapitops.plugin.command.ISender;
|
import com.djrapitops.plugin.command.Sender;
|
||||||
import com.djrapitops.plugin.task.AbsRunnable;
|
import com.djrapitops.plugin.logging.L;
|
||||||
import com.djrapitops.plugin.task.RunnableFactory;
|
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -38,27 +41,44 @@ import java.util.UUID;
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class QInspectCommand extends CommandNode {
|
public class QInspectCommand extends CommandNode {
|
||||||
|
|
||||||
private final Locale locale;
|
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;
|
||||||
|
|
||||||
/**
|
@Inject
|
||||||
* Class Constructor.
|
public QInspectCommand(
|
||||||
*
|
PlanConfig config,
|
||||||
* @param plugin Current instance of Plan
|
Locale locale,
|
||||||
*/
|
Processing processing,
|
||||||
public QInspectCommand(PlanPlugin plugin) {
|
Database database,
|
||||||
|
UUIDUtility uuidUtility,
|
||||||
|
Formatters formatters,
|
||||||
|
ErrorHandler errorHandler
|
||||||
|
) {
|
||||||
super("qinspect", Permissions.QUICK_INSPECT.getPermission(), CommandType.PLAYER_OR_ARGS);
|
super("qinspect", Permissions.QUICK_INSPECT.getPermission(), CommandType.PLAYER_OR_ARGS);
|
||||||
|
this.config = config;
|
||||||
|
this.processing = processing;
|
||||||
|
this.formatters = formatters;
|
||||||
setArguments("<player>");
|
setArguments("<player>");
|
||||||
|
|
||||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
this.locale = locale;
|
||||||
|
this.database = database;
|
||||||
|
this.uuidUtility = uuidUtility;
|
||||||
|
this.errorHandler = errorHandler;
|
||||||
|
|
||||||
setShortHelp(locale.getString(CmdHelpLang.QINSPECT));
|
setShortHelp(locale.getString(CmdHelpLang.QINSPECT));
|
||||||
setInDepthHelp(locale.getArray(DeepHelpLang.QINSPECT));
|
setInDepthHelp(locale.getArray(DeepHelpLang.QINSPECT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
String playerName = MiscUtils.getPlayerName(args, sender, Permissions.QUICK_INSPECT_OTHER);
|
||||||
|
|
||||||
if (playerName == null) {
|
if (playerName == null) {
|
||||||
@ -69,43 +89,42 @@ public class QInspectCommand extends CommandNode {
|
|||||||
runInspectTask(playerName, sender);
|
runInspectTask(playerName, sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runInspectTask(String playerName, ISender sender) {
|
private void runInspectTask(String playerName, Sender sender) {
|
||||||
RunnableFactory.createNew(new AbsRunnable("InspectTask") {
|
processing.submitNonCritical(() -> {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
UUID uuid = uuidUtility.getUUIDOf(playerName);
|
||||||
try {
|
if (uuid == null) {
|
||||||
UUID uuid = UUIDUtility.getUUIDOf(playerName);
|
sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_VALID));
|
||||||
if (uuid == null) {
|
return;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
long now = System.currentTimeMillis();
|
||||||
|
|
||||||
Formatter<DateHolder> timestamp = Formatters.year();
|
Formatter<DateHolder> timestamp = formatters.year();
|
||||||
Formatter<Long> length = Formatters.timeAmount();
|
Formatter<Long> length = formatters.timeAmount();
|
||||||
|
|
||||||
String playerName = player.getValue(PlayerKeys.NAME).orElse(locale.getString(GenericLang.UNKNOWN));
|
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 registered = player.getValue(PlayerKeys.REGISTERED).orElse(0L);
|
||||||
Long lastSeen = player.getValue(PlayerKeys.LAST_SEEN).orElse(0L);
|
Long lastSeen = player.getValue(PlayerKeys.LAST_SEEN).orElse(0L);
|
||||||
List<GeoInfo> geoInfo = player.getValue(PlayerKeys.GEO_INFO).orElse(new ArrayList<>());
|
List<GeoInfo> geoInfo = player.getValue(PlayerKeys.GEO_INFO).orElse(new ArrayList<>());
|
||||||
@ -115,7 +134,7 @@ public class QInspectCommand extends CommandNode {
|
|||||||
|
|
||||||
String[] messages = new String[]{
|
String[] messages = new String[]{
|
||||||
locale.getString(CommandLang.HEADER_INSPECT, playerName),
|
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_REGISTERED, timestamp.apply(() -> registered)),
|
||||||
locale.getString(CommandLang.QINSPECT_LAST_SEEN, timestamp.apply(() -> lastSeen)),
|
locale.getString(CommandLang.QINSPECT_LAST_SEEN, timestamp.apply(() -> lastSeen)),
|
||||||
locale.getString(CommandLang.QINSPECT_GEOLOCATION, geolocation),
|
locale.getString(CommandLang.QINSPECT_GEOLOCATION, geolocation),
|
||||||
|
@ -1,24 +1,26 @@
|
|||||||
package com.djrapitops.plan.command.commands;
|
package com.djrapitops.plan.command.commands;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanPlugin;
|
|
||||||
import com.djrapitops.plan.data.WebUser;
|
import com.djrapitops.plan.data.WebUser;
|
||||||
import com.djrapitops.plan.system.database.databases.Database;
|
import com.djrapitops.plan.system.database.databases.Database;
|
||||||
import com.djrapitops.plan.system.locale.Locale;
|
import com.djrapitops.plan.system.locale.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
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.Permissions;
|
||||||
import com.djrapitops.plan.utilities.PassEncryptUtil;
|
import com.djrapitops.plan.utilities.PassEncryptUtil;
|
||||||
import com.djrapitops.plugin.api.Check;
|
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.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
import com.djrapitops.plugin.command.CommandType;
|
||||||
import com.djrapitops.plugin.command.CommandUtils;
|
import com.djrapitops.plugin.command.CommandUtils;
|
||||||
import com.djrapitops.plugin.command.ISender;
|
import com.djrapitops.plugin.command.Sender;
|
||||||
import com.djrapitops.plugin.task.AbsRunnable;
|
import com.djrapitops.plugin.logging.L;
|
||||||
import com.djrapitops.plugin.task.RunnableFactory;
|
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||||
|
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,17 +34,31 @@ import java.util.Arrays;
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
* @since 3.5.2
|
* @since 3.5.2
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class RegisterCommand extends CommandNode {
|
public class RegisterCommand extends CommandNode {
|
||||||
|
|
||||||
private final String notEnoughArgsMsg;
|
private final String notEnoughArgsMsg;
|
||||||
private final String hashErrorMsg;
|
|
||||||
private final Locale locale;
|
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
|
// No Permission Requirement
|
||||||
super("register", "", CommandType.PLAYER_OR_ARGS);
|
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("<password>", "[name]", "[lvl]");
|
setArguments("<password>", "[name]", "[lvl]");
|
||||||
setShortHelp(locale.getString(CmdHelpLang.WEB_REGISTER));
|
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()));
|
notEnoughArgsMsg = locale.getString(CommandLang.FAIL_REQ_ARGS, 3, Arrays.toString(getArguments()));
|
||||||
hashErrorMsg = "§cPassword hash error.";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||||
try {
|
try {
|
||||||
if (CommandUtils.isPlayer(sender)) {
|
if (CommandUtils.isPlayer(sender)) {
|
||||||
playerRegister(args, sender);
|
playerRegister(args, sender);
|
||||||
@ -64,16 +79,16 @@ public class RegisterCommand extends CommandNode {
|
|||||||
consoleRegister(args, sender, notEnoughArgsMsg);
|
consoleRegister(args, sender, notEnoughArgsMsg);
|
||||||
}
|
}
|
||||||
} catch (PassEncryptUtil.CannotPerformOperationException e) {
|
} catch (PassEncryptUtil.CannotPerformOperationException e) {
|
||||||
Log.toLog(this.getClass().getSimpleName(), e);
|
errorHandler.log(L.WARN, this.getClass(), e);
|
||||||
sender.sendMessage(hashErrorMsg);
|
sender.sendMessage("§cPassword hash error.");
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw new NumberFormatException(args[2]);
|
throw new NumberFormatException(args[2]);
|
||||||
} catch (Exception e) {
|
} 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));
|
Verify.isTrue(args.length >= 3, () -> new IllegalArgumentException(notEnoughArgsMsg));
|
||||||
|
|
||||||
int permLevel;
|
int permLevel;
|
||||||
@ -82,7 +97,7 @@ public class RegisterCommand extends CommandNode {
|
|||||||
registerUser(new WebUser(args[1], passHash, permLevel), sender);
|
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;
|
boolean registerSenderAsUser = args.length == 1;
|
||||||
if (registerSenderAsUser) {
|
if (registerSenderAsUser) {
|
||||||
String user = sender.getName();
|
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 permAnalyze = Permissions.ANALYZE.getPerm();
|
||||||
final String permInspectOther = Permissions.INSPECT_OTHER.getPerm();
|
final String permInspectOther = Permissions.INSPECT_OTHER.getPerm();
|
||||||
final String permInspect = Permissions.INSPECT.getPerm();
|
final String permInspect = Permissions.INSPECT.getPerm();
|
||||||
@ -112,30 +127,22 @@ public class RegisterCommand extends CommandNode {
|
|||||||
return 100;
|
return 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerUser(WebUser webUser, ISender sender) {
|
private void registerUser(WebUser webUser, Sender sender) {
|
||||||
RunnableFactory.createNew(new AbsRunnable("Register WebUser Task") {
|
processing.submitCritical(() -> {
|
||||||
@Override
|
String userName = webUser.getName();
|
||||||
public void run() {
|
try {
|
||||||
final String existsMsg = locale.getString(CommandLang.FAIL_WEB_USER_EXISTS);
|
boolean userExists = database.check().doesWebUserExists(userName);
|
||||||
final String userName = webUser.getName();
|
if (userExists) {
|
||||||
final String successMsg = locale.getString(CommandLang.WEB_USER_REGISTER_SUCCESS);
|
sender.sendMessage(locale.getString(CommandLang.FAIL_WEB_USER_EXISTS));
|
||||||
try {
|
return;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
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();
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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.CommandLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||||
import com.djrapitops.plan.system.settings.Permissions;
|
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.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
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.AbsRunnable;
|
||||||
import com.djrapitops.plugin.task.RunnableFactory;
|
import com.djrapitops.plugin.task.RunnableFactory;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This SubCommand is used to reload the plugin.
|
* This SubCommand is used to reload the plugin.
|
||||||
*
|
*
|
||||||
@ -23,26 +26,31 @@ public class ReloadCommand extends CommandNode {
|
|||||||
|
|
||||||
private final PlanPlugin plugin;
|
private final PlanPlugin plugin;
|
||||||
private final Locale locale;
|
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);
|
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));
|
setShortHelp(locale.getString(CmdHelpLang.RELOAD));
|
||||||
setInDepthHelp(locale.getArray(DeepHelpLang.RELOAD));
|
setInDepthHelp(locale.getArray(DeepHelpLang.RELOAD));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||||
RunnableFactory.createNew("Reload task", new AbsRunnable() {
|
runnableFactory.create("Reload task", new AbsRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
plugin.reloadPlugin(true);
|
plugin.reloadPlugin(true);
|
||||||
} catch (Exception e) {
|
} 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_FAILED));
|
||||||
}
|
}
|
||||||
sender.sendMessage(locale.getString(CommandLang.RELOAD_COMPLETE));
|
sender.sendMessage(locale.getString(CommandLang.RELOAD_COMPLETE));
|
||||||
|
@ -1,24 +1,25 @@
|
|||||||
package com.djrapitops.plan.command.commands;
|
package com.djrapitops.plan.command.commands;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanPlugin;
|
|
||||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
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.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
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.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.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
import com.djrapitops.plugin.command.CommandType;
|
||||||
import com.djrapitops.plugin.command.ISender;
|
import com.djrapitops.plugin.command.Sender;
|
||||||
import com.djrapitops.plugin.task.AbsRunnable;
|
import com.djrapitops.plugin.logging.L;
|
||||||
import com.djrapitops.plugin.task.RunnableFactory;
|
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||||
import com.djrapitops.plugin.utilities.FormatUtils;
|
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,14 +28,26 @@ import java.util.List;
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class SearchCommand extends CommandNode {
|
public class SearchCommand extends CommandNode {
|
||||||
|
|
||||||
private final Locale locale;
|
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);
|
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("<text>");
|
setArguments("<text>");
|
||||||
setShortHelp(locale.getString(CmdHelpLang.SEARCH));
|
setShortHelp(locale.getString(CmdHelpLang.SEARCH));
|
||||||
@ -42,7 +55,7 @@ public class SearchCommand extends CommandNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||||
Verify.isTrue(args.length >= 1,
|
Verify.isTrue(args.length >= 1,
|
||||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
() -> 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);
|
runSearchTask(args, sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runSearchTask(String[] args, ISender sender) {
|
private void runSearchTask(String[] args, Sender sender) {
|
||||||
RunnableFactory.createNew(new AbsRunnable("SearchTask: " + Arrays.toString(args)) {
|
processing.submitNonCritical(() -> {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
String searchTerm = args[0];
|
||||||
try {
|
List<String> names = database.search().matchingPlayers(searchTerm);
|
||||||
String searchTerm = args[0];
|
Collections.sort(names);
|
||||||
List<String> names = MiscUtils.getMatchingPlayerNames(searchTerm);
|
boolean empty = Verify.isEmpty(names);
|
||||||
|
|
||||||
boolean empty = Verify.isEmpty(names);
|
sender.sendMessage(locale.getString(CommandLang.HEADER_SEARCH, empty ? 0 : names.size(), searchTerm));
|
||||||
|
// Results
|
||||||
sender.sendMessage(locale.getString(CommandLang.HEADER_SEARCH, empty ? 0 : names.size(), searchTerm));
|
if (!empty) {
|
||||||
// Results
|
String message = names.toString();
|
||||||
if (!empty) {
|
sender.sendMessage(message.substring(1, message.length() - 1));
|
||||||
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(">");
|
||||||
|
} catch (DBOpException e) {
|
||||||
|
sender.sendMessage("§cDatabase error occurred: " + e.getMessage());
|
||||||
|
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||||
}
|
}
|
||||||
}).runTaskAsynchronously();
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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<Server> servers = Database.getActive().fetch().getServers();
|
|
||||||
update(sender, servers, args);
|
|
||||||
} catch (DBOpException e) {
|
|
||||||
Log.toLog(this.getClass().getName(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void update(ISender sender, List<Server> 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<Server> 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<Server> bungeeInformation = fetch.getBungeeInformation();
|
|
||||||
if (!bungeeInformation.isPresent()) {
|
|
||||||
sender.sendMessage("Bungee address not found in the database, assuming this is not a network.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Map<UUID, Server> 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,5 @@
|
|||||||
package com.djrapitops.plan.command.commands;
|
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.WebCheckCommand;
|
||||||
import com.djrapitops.plan.command.commands.webuser.WebDeleteCommand;
|
import com.djrapitops.plan.command.commands.webuser.WebDeleteCommand;
|
||||||
import com.djrapitops.plan.command.commands.webuser.WebLevelCommand;
|
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.CmdHelpLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||||
import com.djrapitops.plan.system.settings.Permissions;
|
import com.djrapitops.plan.system.settings.Permissions;
|
||||||
|
import com.djrapitops.plugin.command.ColorScheme;
|
||||||
import com.djrapitops.plugin.command.CommandNode;
|
import com.djrapitops.plugin.command.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
import com.djrapitops.plugin.command.CommandType;
|
||||||
import com.djrapitops.plugin.command.TreeCmdNode;
|
import com.djrapitops.plugin.command.TreeCmdNode;
|
||||||
|
import dagger.Lazy;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Web subcommand used to manage Web users.
|
* Web subcommand used to manage Web users.
|
||||||
@ -21,20 +25,25 @@ import com.djrapitops.plugin.command.TreeCmdNode;
|
|||||||
*/
|
*/
|
||||||
public class WebUserCommand extends TreeCmdNode {
|
public class WebUserCommand extends TreeCmdNode {
|
||||||
|
|
||||||
public WebUserCommand(PlanPlugin plugin, RegisterCommand register, CommandNode parent) {
|
@Inject
|
||||||
super("webuser|web", Permissions.MANAGE_WEB.getPerm(), CommandType.CONSOLE, parent);
|
public WebUserCommand(ColorScheme colorScheme, Locale locale, @Named("mainCommand") Lazy<CommandNode> parent,
|
||||||
super.setColorScheme(plugin.getColorScheme());
|
RegisterCommand registerCommand,
|
||||||
|
WebLevelCommand levelCommand,
|
||||||
Locale locale = plugin.getSystem().getLocaleSystem().getLocale();
|
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));
|
setShortHelp(locale.getString(CmdHelpLang.WEB));
|
||||||
setInDepthHelp(locale.getArray(DeepHelpLang.WEB));
|
setInDepthHelp(locale.getArray(DeepHelpLang.WEB));
|
||||||
CommandNode[] webGroup = {
|
CommandNode[] webGroup = {
|
||||||
register,
|
registerCommand,
|
||||||
new WebLevelCommand(plugin),
|
levelCommand,
|
||||||
new WebListUsersCommand(plugin),
|
listUsersCommand,
|
||||||
new WebCheckCommand(plugin),
|
checkCommand,
|
||||||
new WebDeleteCommand(plugin)
|
deleteCommand
|
||||||
};
|
};
|
||||||
setNodeGroups(webGroup);
|
setNodeGroups(webGroup);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package com.djrapitops.plan.command.commands.manage;
|
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.DBException;
|
||||||
import com.djrapitops.plan.api.exceptions.database.DBInitException;
|
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.DBSystem;
|
||||||
import com.djrapitops.plan.system.database.databases.Database;
|
import com.djrapitops.plan.system.database.databases.Database;
|
||||||
import com.djrapitops.plan.system.database.databases.sql.SQLiteDB;
|
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.CommandLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
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.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.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
import com.djrapitops.plugin.command.CommandType;
|
||||||
import com.djrapitops.plugin.command.ISender;
|
import com.djrapitops.plugin.command.Sender;
|
||||||
import com.djrapitops.plugin.task.AbsRunnable;
|
import com.djrapitops.plugin.logging.L;
|
||||||
import com.djrapitops.plugin.task.RunnableFactory;
|
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -31,14 +33,35 @@ import java.util.UUID;
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
* @since 2.3.0
|
* @since 2.3.0
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class ManageBackupCommand extends CommandNode {
|
public class ManageBackupCommand extends CommandNode {
|
||||||
|
|
||||||
private final Locale locale;
|
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<Long> iso8601LongFormatter;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public ManageBackupCommand(
|
||||||
|
Locale locale,
|
||||||
|
Processing processing,
|
||||||
|
DBSystem dbSystem,
|
||||||
|
SQLiteDB.Factory sqliteFactory,
|
||||||
|
Formatters formatters,
|
||||||
|
ErrorHandler errorHandler
|
||||||
|
) {
|
||||||
super("backup", Permissions.MANAGE.getPermission(), CommandType.CONSOLE);
|
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));
|
setShortHelp(locale.getString(CmdHelpLang.MANAGE_BACKUP));
|
||||||
setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE_BACKUP));
|
setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE_BACKUP));
|
||||||
@ -47,7 +70,7 @@ public class ManageBackupCommand extends CommandNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||||
try {
|
try {
|
||||||
Verify.isTrue(args.length >= 1,
|
Verify.isTrue(args.length >= 1,
|
||||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
() -> 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,
|
Verify.isTrue(isCorrectDB,
|
||||||
() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_INCORRECT_DB, dbName)));
|
() -> 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);
|
runBackupTask(sender, args, database);
|
||||||
} catch (DBInitException e) {
|
} catch (DBInitException e) {
|
||||||
@ -66,24 +90,17 @@ public class ManageBackupCommand extends CommandNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runBackupTask(ISender sender, String[] args, Database database) {
|
private void runBackupTask(Sender sender, String[] args, Database database) {
|
||||||
RunnableFactory.createNew(new AbsRunnable("BackupTask") {
|
processing.submitCritical(() -> {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
|
||||||
try {
|
createNewBackup(args[0], database);
|
||||||
Log.debug("Backup", "Start");
|
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
|
||||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
|
} catch (Exception e) {
|
||||||
createNewBackup(args[0], database);
|
errorHandler.log(L.ERROR, ManageBackupCommand.class, e);
|
||||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
|
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||||
} catch (Exception e) {
|
|
||||||
Log.toLog(ManageBackupCommand.class, e);
|
|
||||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
|
||||||
} finally {
|
|
||||||
Log.logDebug("Backup");
|
|
||||||
this.cancel();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}).runTaskAsynchronously();
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,9 +112,9 @@ public class ManageBackupCommand extends CommandNode {
|
|||||||
private void createNewBackup(String dbName, Database copyFromDB) {
|
private void createNewBackup(String dbName, Database copyFromDB) {
|
||||||
SQLiteDB backupDB = null;
|
SQLiteDB backupDB = null;
|
||||||
try {
|
try {
|
||||||
String timeStamp = Formatters.iso8601NoClock().apply(System::currentTimeMillis);
|
String timeStamp = iso8601LongFormatter.apply(System.currentTimeMillis());
|
||||||
String fileName = dbName + "-backup-" + timeStamp;
|
String fileName = dbName + "-backup-" + timeStamp;
|
||||||
backupDB = new SQLiteDB(fileName, () -> locale);
|
backupDB = sqliteFactory.usingFileCalled(fileName);
|
||||||
Collection<UUID> uuids = copyFromDB.fetch().getSavedUUIDs();
|
Collection<UUID> uuids = copyFromDB.fetch().getSavedUUIDs();
|
||||||
if (uuids.isEmpty()) {
|
if (uuids.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
@ -105,7 +122,7 @@ public class ManageBackupCommand extends CommandNode {
|
|||||||
backupDB.init();
|
backupDB.init();
|
||||||
copyFromDB.backup().backup(backupDB);
|
copyFromDB.backup().backup(backupDB);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
Log.toLog(this.getClass(), e);
|
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||||
} finally {
|
} finally {
|
||||||
if (backupDB != null) {
|
if (backupDB != null) {
|
||||||
backupDB.close();
|
backupDB.close();
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.djrapitops.plan.command.commands.manage;
|
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.DBInitException;
|
||||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||||
import com.djrapitops.plan.system.database.DBSystem;
|
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.CommandLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
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.settings.Permissions;
|
||||||
import com.djrapitops.plugin.api.utility.log.Log;
|
|
||||||
import com.djrapitops.plugin.command.CommandNode;
|
import com.djrapitops.plugin.command.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
import com.djrapitops.plugin.command.CommandType;
|
||||||
import com.djrapitops.plugin.command.ISender;
|
import com.djrapitops.plugin.command.Sender;
|
||||||
import com.djrapitops.plugin.task.AbsRunnable;
|
import com.djrapitops.plugin.logging.L;
|
||||||
import com.djrapitops.plugin.task.RunnableFactory;
|
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,14 +28,27 @@ import java.util.Arrays;
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
* @since 2.3.0
|
* @since 2.3.0
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class ManageClearCommand extends CommandNode {
|
public class ManageClearCommand extends CommandNode {
|
||||||
|
|
||||||
private final Locale locale;
|
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);
|
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("<DB>", "[-a]");
|
setArguments("<DB>", "[-a]");
|
||||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE_CLEAR));
|
setShortHelp(locale.getString(CmdHelpLang.MANAGE_CLEAR));
|
||||||
@ -42,7 +56,7 @@ public class ManageClearCommand extends CommandNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||||
Verify.isTrue(args.length >= 1,
|
Verify.isTrue(args.length >= 1,
|
||||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
||||||
|
|
||||||
@ -58,30 +72,26 @@ public class ManageClearCommand extends CommandNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Database database = DBSystem.getActiveDatabaseByName(dbName);
|
Database database = dbSystem.getActiveDatabaseByName(dbName);
|
||||||
|
database.init();
|
||||||
runClearTask(sender, database);
|
runClearTask(sender, database);
|
||||||
} catch (DBInitException e) {
|
} catch (DBInitException e) {
|
||||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runClearTask(ISender sender, Database database) {
|
private void runClearTask(Sender sender, Database database) {
|
||||||
RunnableFactory.createNew(new AbsRunnable("DBClearTask") {
|
processing.submitCritical(() -> {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
|
||||||
try {
|
|
||||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
|
|
||||||
|
|
||||||
database.remove().everything();
|
database.remove().everything();
|
||||||
|
|
||||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
|
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
|
||||||
} catch (DBOpException e) {
|
} catch (DBOpException e) {
|
||||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||||
Log.toLog(this.getClass(), e);
|
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||||
} finally {
|
|
||||||
this.cancel();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}).runTaskAsynchronously();
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
package com.djrapitops.plan.command.commands.manage;
|
package com.djrapitops.plan.command.commands.manage;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanPlugin;
|
|
||||||
import com.djrapitops.plan.api.exceptions.connection.*;
|
import com.djrapitops.plan.api.exceptions.connection.*;
|
||||||
import com.djrapitops.plan.system.database.databases.Database;
|
import com.djrapitops.plan.system.database.databases.Database;
|
||||||
import com.djrapitops.plan.system.info.InfoSystem;
|
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||||
import com.djrapitops.plan.system.info.request.CheckConnectionRequest;
|
import com.djrapitops.plan.system.info.request.InfoRequestFactory;
|
||||||
import com.djrapitops.plan.system.info.server.Server;
|
import com.djrapitops.plan.system.info.server.Server;
|
||||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||||
import com.djrapitops.plan.system.locale.Locale;
|
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.locale.lang.ManageLang;
|
||||||
import com.djrapitops.plan.system.processing.Processing;
|
import com.djrapitops.plan.system.processing.Processing;
|
||||||
import com.djrapitops.plan.system.settings.Permissions;
|
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.api.Check;
|
||||||
|
import com.djrapitops.plugin.command.ColorScheme;
|
||||||
import com.djrapitops.plugin.command.CommandNode;
|
import com.djrapitops.plugin.command.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
import com.djrapitops.plugin.command.CommandType;
|
||||||
import com.djrapitops.plugin.command.ISender;
|
import com.djrapitops.plugin.command.Sender;
|
||||||
import com.djrapitops.plugin.settings.ColorScheme;
|
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -30,20 +31,45 @@ import java.util.UUID;
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
* @since 2.3.0
|
* @since 2.3.0
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class ManageConDebugCommand extends CommandNode {
|
public class ManageConDebugCommand extends CommandNode {
|
||||||
|
|
||||||
|
private final ColorScheme colorScheme;
|
||||||
private final Locale locale;
|
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);
|
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));
|
setShortHelp(locale.getString(Check.isBungeeAvailable() ? CmdHelpLang.CON : CmdHelpLang.MANAGE_CON));
|
||||||
setInDepthHelp(locale.getArray(DeepHelpLang.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();
|
String address = server.getWebAddress().toLowerCase();
|
||||||
boolean usingHttps = address.startsWith("https");
|
boolean usingHttps = address.startsWith("https");
|
||||||
boolean local = address.contains("localhost")
|
boolean local = address.contains("localhost")
|
||||||
@ -52,11 +78,8 @@ public class ManageConDebugCommand extends CommandNode {
|
|||||||
|| address.contains("127.0.0.1");
|
|| address.contains("127.0.0.1");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
connectionSystem.sendInfoRequest(infoRequestFactory.checkConnectionRequest(address), server);
|
||||||
InfoSystem.getInstance().getConnectionSystem().sendInfoRequest(new CheckConnectionRequest(accessAddress), server);
|
|
||||||
sender.sendMessage(getMsgFor(address, usingHttps, local, true, true));
|
sender.sendMessage(getMsgFor(address, usingHttps, local, true, true));
|
||||||
return true;
|
|
||||||
|
|
||||||
} catch (ForbiddenException | BadRequestException | InternalErrorException e) {
|
} catch (ForbiddenException | BadRequestException | InternalErrorException e) {
|
||||||
sender.sendMessage(getMsgFor(address, usingHttps, local, false, false));
|
sender.sendMessage(getMsgFor(address, usingHttps, local, false, false));
|
||||||
sender.sendMessage(locale.getString(ManageLang.CON_EXCEPTION, e.getClass().getSimpleName()));
|
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(getMsgFor(address, usingHttps, local, false, false));
|
||||||
sender.sendMessage(locale.getString(ManageLang.CON_EXCEPTION, e.getClass().getSimpleName()));
|
sender.sendMessage(locale.getString(ManageLang.CON_EXCEPTION, e.getClass().getSimpleName()));
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||||
if (!WebServerSystem.isWebServerEnabled()) {
|
if (!webServer.isEnabled()) {
|
||||||
sender.sendMessage(locale.getString(CommandLang.CONNECT_WEBSERVER_NOT_ENABLED));
|
sender.sendMessage(locale.getString(CommandLang.CONNECT_WEBSERVER_NOT_ENABLED));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Processing.submitNonCritical(() -> testServers(sender));
|
processing.submitNonCritical(() -> testServers(sender));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testServers(ISender sender) {
|
private void testServers(Sender sender) {
|
||||||
List<Server> servers = Database.getActive().fetch().getServers();
|
List<Server> servers = database.fetch().getServers();
|
||||||
|
|
||||||
if (servers.isEmpty()) {
|
if (servers.isEmpty()) {
|
||||||
sender.sendMessage(locale.getString(ManageLang.CON_NO_SERVERS));
|
sender.sendMessage(locale.getString(ManageLang.CON_NO_SERVERS));
|
||||||
}
|
}
|
||||||
|
|
||||||
String accessAddress = WebServerSystem.getInstance().getWebServer().getAccessAddress();
|
String accessAddress = webServer.getAccessAddress();
|
||||||
UUID thisServer = ServerInfo.getServerUUID();
|
UUID thisServer = serverInfo.getServerUUID();
|
||||||
for (Server server : servers) {
|
for (Server server : servers) {
|
||||||
if (thisServer.equals(server.getUuid())) {
|
if (thisServer.equals(server.getUuid())) {
|
||||||
continue;
|
continue;
|
||||||
@ -108,10 +130,9 @@ public class ManageConDebugCommand extends CommandNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getMsgFor(String address, boolean usingHttps, boolean local, boolean successTo, boolean successFrom) {
|
private String getMsgFor(String address, boolean usingHttps, boolean local, boolean successTo, boolean successFrom) {
|
||||||
ColorScheme cs = PlanPlugin.getInstance().getColorScheme();
|
String tCol = colorScheme.getTertiaryColor();
|
||||||
String tCol = cs.getTertiaryColor();
|
String sCol = colorScheme.getSecondaryColor();
|
||||||
String sCol = cs.getSecondaryColor();
|
|
||||||
return tCol + address + sCol + ": "
|
return tCol + address + sCol + ": "
|
||||||
+ (usingHttps ? "HTTPS" : "HTTP") + " : "
|
+ (usingHttps ? "HTTPS" : "HTTP") + " : "
|
||||||
+ (local ? "Local" : "External") + " : "
|
+ (local ? "Local" : "External") + " : "
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.djrapitops.plan.command.commands.manage;
|
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.listeners.bukkit.PlayerOnlineListener;
|
||||||
import com.djrapitops.plan.system.locale.Locale;
|
import com.djrapitops.plan.system.locale.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
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.plan.system.settings.Permissions;
|
||||||
import com.djrapitops.plugin.command.CommandNode;
|
import com.djrapitops.plugin.command.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
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 com.djrapitops.plugin.utilities.Verify;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,10 +24,11 @@ public class ManageDisableCommand extends CommandNode {
|
|||||||
|
|
||||||
private final Locale locale;
|
private final Locale locale;
|
||||||
|
|
||||||
public ManageDisableCommand(PlanPlugin plugin) {
|
@Inject
|
||||||
|
public ManageDisableCommand(Locale locale) {
|
||||||
super("disable", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
|
super("disable", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
|
||||||
|
|
||||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
this.locale = locale;
|
||||||
|
|
||||||
setArguments("<feature>");
|
setArguments("<feature>");
|
||||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE_DISABLE));
|
setShortHelp(locale.getString(CmdHelpLang.MANAGE_DISABLE));
|
||||||
@ -35,7 +36,7 @@ public class ManageDisableCommand extends CommandNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||||
Verify.isTrue(args.length >= 1,
|
Verify.isTrue(args.length >= 1,
|
||||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
||||||
|
|
||||||
|
@ -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.locale.lang.ManageLang;
|
||||||
import com.djrapitops.plan.system.settings.Permissions;
|
import com.djrapitops.plan.system.settings.Permissions;
|
||||||
import com.djrapitops.plan.system.settings.Settings;
|
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.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
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 com.djrapitops.plugin.utilities.Verify;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,19 +32,26 @@ public class ManageHotSwapCommand extends CommandNode {
|
|||||||
|
|
||||||
private final PlanPlugin plugin;
|
private final PlanPlugin plugin;
|
||||||
private final Locale locale;
|
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);
|
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("<DB>");
|
setArguments("<DB>");
|
||||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE_HOTSWAP));
|
setShortHelp(locale.getString(CmdHelpLang.MANAGE_HOTSWAP));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||||
Verify.isTrue(args.length >= 1,
|
Verify.isTrue(args.length >= 1,
|
||||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
() -> 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,
|
Verify.isTrue(isCorrectDB,
|
||||||
() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_INCORRECT_DB, dbName)));
|
() -> 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)));
|
() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_SAME_DB)));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Database database = DBSystem.getActiveDatabaseByName(dbName);
|
Database database = dbSystem.getActiveDatabaseByName(dbName);
|
||||||
|
database.init();
|
||||||
|
|
||||||
if (!database.isOpen()) {
|
if (!database.isOpen()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.toLog(this.getClass(), e);
|
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings.DB_TYPE.set(dbName);
|
try {
|
||||||
|
config.set(Settings.DB_TYPE, dbName);
|
||||||
Settings.save();
|
config.save();
|
||||||
|
} catch (IOException e) {
|
||||||
|
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
plugin.reloadPlugin(true);
|
plugin.reloadPlugin(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,23 @@
|
|||||||
package com.djrapitops.plan.command.commands.manage;
|
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.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
||||||
import com.djrapitops.plan.system.processing.importing.ImporterManager;
|
import com.djrapitops.plan.system.processing.Processing;
|
||||||
import com.djrapitops.plan.system.processing.importing.importers.Importer;
|
|
||||||
import com.djrapitops.plan.system.settings.Permissions;
|
import com.djrapitops.plan.system.settings.Permissions;
|
||||||
import com.djrapitops.plugin.command.CommandNode;
|
import com.djrapitops.plugin.command.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
import com.djrapitops.plugin.command.CommandType;
|
||||||
import com.djrapitops.plugin.command.ISender;
|
import com.djrapitops.plugin.command.Sender;
|
||||||
import com.djrapitops.plugin.task.AbsRunnable;
|
|
||||||
import com.djrapitops.plugin.task.RunnableFactory;
|
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This manage SubCommand is used to import data from 3rd party plugins.
|
* This manage SubCommand is used to import data from 3rd party plugins.
|
||||||
@ -24,14 +25,24 @@ import java.util.Arrays;
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
* @since 2.3.0
|
* @since 2.3.0
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class ManageImportCommand extends CommandNode {
|
public class ManageImportCommand extends CommandNode {
|
||||||
|
|
||||||
private final Locale locale;
|
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);
|
super("import", Permissions.MANAGE.getPermission(), CommandType.CONSOLE);
|
||||||
|
|
||||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
this.locale = locale;
|
||||||
|
this.processing = processing;
|
||||||
|
this.importSystem = importSystem;
|
||||||
|
|
||||||
setArguments("<plugin>/list", "[import args]");
|
setArguments("<plugin>/list", "[import args]");
|
||||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE_IMPORT));
|
setShortHelp(locale.getString(CmdHelpLang.MANAGE_IMPORT));
|
||||||
@ -39,7 +50,7 @@ public class ManageImportCommand extends CommandNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||||
Verify.isTrue(args.length >= 1,
|
Verify.isTrue(args.length >= 1,
|
||||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ARGS, "1+", Arrays.toString(this.getArguments()))));
|
() -> 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")) {
|
if (importArg.equals("list")) {
|
||||||
sender.sendMessage(locale.getString(ManageLang.IMPORTERS));
|
sender.sendMessage(locale.getString(ManageLang.IMPORTERS));
|
||||||
ImporterManager.getImporters().stream()
|
importSystem.getImporterNames().forEach(name -> sender.sendMessage("- " + name));
|
||||||
.map(Importer::getNames)
|
|
||||||
.map(list -> list.get(0))
|
|
||||||
.forEach(name -> sender.sendMessage("- " + name));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Importer importer = ImporterManager.getImporter(importArg);
|
findImporter(sender, importArg);
|
||||||
if (importer == null) {
|
}
|
||||||
|
|
||||||
|
private void findImporter(Sender sender, String importArg) {
|
||||||
|
Optional<Importer> 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));
|
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.djrapitops.plan.command.commands.manage;
|
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.DBSystem;
|
||||||
import com.djrapitops.plan.system.database.databases.Database;
|
import com.djrapitops.plan.system.database.databases.Database;
|
||||||
import com.djrapitops.plan.system.locale.Locale;
|
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.CommandLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
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.settings.Permissions;
|
||||||
import com.djrapitops.plugin.api.utility.log.Log;
|
|
||||||
import com.djrapitops.plugin.command.CommandNode;
|
import com.djrapitops.plugin.command.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
import com.djrapitops.plugin.command.CommandType;
|
||||||
import com.djrapitops.plugin.command.ISender;
|
import com.djrapitops.plugin.command.Sender;
|
||||||
import com.djrapitops.plugin.task.AbsRunnable;
|
import com.djrapitops.plugin.logging.L;
|
||||||
import com.djrapitops.plugin.task.RunnableFactory;
|
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,14 +28,27 @@ import java.util.Arrays;
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
* @since 2.3.0
|
* @since 2.3.0
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class ManageMoveCommand extends CommandNode {
|
public class ManageMoveCommand extends CommandNode {
|
||||||
|
|
||||||
private final Locale locale;
|
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);
|
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("<fromDB>", "<toDB>", "[-a]");
|
setArguments("<fromDB>", "<toDB>", "[-a]");
|
||||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE_MOVE));
|
setShortHelp(locale.getString(CmdHelpLang.MANAGE_MOVE));
|
||||||
@ -42,7 +56,7 @@ public class ManageMoveCommand extends CommandNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||||
Verify.isTrue(args.length >= 2,
|
Verify.isTrue(args.length >= 2,
|
||||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ARGS, 2, Arrays.toString(this.getArguments()))));
|
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ARGS, 2, Arrays.toString(this.getArguments()))));
|
||||||
|
|
||||||
@ -65,8 +79,10 @@ public class ManageMoveCommand extends CommandNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final Database fromDatabase = DBSystem.getActiveDatabaseByName(fromDB);
|
final Database fromDatabase = dbSystem.getActiveDatabaseByName(fromDB);
|
||||||
final Database toDatabase = DBSystem.getActiveDatabaseByName(toDB);
|
final Database toDatabase = dbSystem.getActiveDatabaseByName(toDB);
|
||||||
|
fromDatabase.init();
|
||||||
|
toDatabase.init();
|
||||||
|
|
||||||
runMoveTask(fromDatabase, toDatabase, sender);
|
runMoveTask(fromDatabase, toDatabase, sender);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -74,28 +90,23 @@ public class ManageMoveCommand extends CommandNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runMoveTask(final Database fromDatabase, final Database toDatabase, ISender sender) {
|
private void runMoveTask(final Database fromDatabase, final Database toDatabase, Sender sender) {
|
||||||
RunnableFactory.createNew(new AbsRunnable("DBMoveTask") {
|
processing.submitCritical(() -> {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
|
||||||
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());
|
boolean movingToCurrentDB = toDatabase.getConfigName().equalsIgnoreCase(dbSystem.getActiveDatabase().getConfigName());
|
||||||
if (movingToCurrentDB) {
|
if (movingToCurrentDB) {
|
||||||
sender.sendMessage(locale.getString(ManageLang.HOTSWAP_REMINDER, toDatabase.getConfigName()));
|
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();
|
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||||
|
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||||
}
|
}
|
||||||
}).runTaskAsynchronously();
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.djrapitops.plan.command.commands.manage;
|
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.info.connection.ConnectionSystem;
|
||||||
import com.djrapitops.plan.system.locale.Locale;
|
import com.djrapitops.plan.system.locale.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
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.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
import com.djrapitops.plugin.command.CommandType;
|
||||||
import com.djrapitops.plugin.command.CommandUtils;
|
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 com.djrapitops.plugin.utilities.Verify;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,11 +25,14 @@ import java.util.Arrays;
|
|||||||
public class ManageRawDataCommand extends CommandNode {
|
public class ManageRawDataCommand extends CommandNode {
|
||||||
|
|
||||||
private final Locale locale;
|
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);
|
super("raw", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
|
||||||
|
|
||||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
this.locale = locale;
|
||||||
|
this.connectionSystem = connectionSystem;
|
||||||
|
|
||||||
setArguments("<player>");
|
setArguments("<player>");
|
||||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE_RAW_DATA));
|
setShortHelp(locale.getString(CmdHelpLang.MANAGE_RAW_DATA));
|
||||||
@ -37,7 +40,7 @@ public class ManageRawDataCommand extends CommandNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||||
Verify.isTrue(args.length >= 1,
|
Verify.isTrue(args.length >= 1,
|
||||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
() -> 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));
|
sender.sendMessage(locale.getString(CommandLang.HEADER_INSPECT, playerName));
|
||||||
// Link
|
// Link
|
||||||
String url = ConnectionSystem.getInstance().getMainAddress() + "/player/" + playerName + "/raw";
|
String url = connectionSystem.getMainAddress() + "/player/" + playerName + "/raw";
|
||||||
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
|
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
|
||||||
boolean console = !CommandUtils.isPlayer(sender);
|
boolean console = !CommandUtils.isPlayer(sender);
|
||||||
if (console) {
|
if (console) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.djrapitops.plan.command.commands.manage;
|
package com.djrapitops.plan.command.commands.manage;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanPlugin;
|
|
||||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||||
import com.djrapitops.plan.system.database.databases.Database;
|
import com.djrapitops.plan.system.database.databases.Database;
|
||||||
import com.djrapitops.plan.system.locale.Locale;
|
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.CommandLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
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.settings.Permissions;
|
||||||
import com.djrapitops.plan.utilities.MiscUtils;
|
import com.djrapitops.plan.utilities.MiscUtils;
|
||||||
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
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.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
import com.djrapitops.plugin.command.CommandType;
|
||||||
import com.djrapitops.plugin.command.ISender;
|
import com.djrapitops.plugin.command.Sender;
|
||||||
import com.djrapitops.plugin.task.AbsRunnable;
|
import com.djrapitops.plugin.logging.L;
|
||||||
import com.djrapitops.plugin.task.RunnableFactory;
|
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -28,14 +29,30 @@ import java.util.UUID;
|
|||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class ManageRemoveCommand extends CommandNode {
|
public class ManageRemoveCommand extends CommandNode {
|
||||||
|
|
||||||
private final Locale locale;
|
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);
|
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("<player>", "[-a]");
|
setArguments("<player>", "[-a]");
|
||||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE_REMOVE));
|
setShortHelp(locale.getString(CmdHelpLang.MANAGE_REMOVE));
|
||||||
@ -43,7 +60,7 @@ public class ManageRemoveCommand extends CommandNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||||
Verify.isTrue(args.length >= 1,
|
Verify.isTrue(args.length >= 1,
|
||||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
() -> 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);
|
runRemoveTask(playerName, sender, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runRemoveTask(String playerName, ISender sender, String[] args) {
|
private void runRemoveTask(String playerName, Sender sender, String[] args) {
|
||||||
RunnableFactory.createNew(new AbsRunnable("DBRemoveTask " + playerName) {
|
processing.submitCritical(() -> {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
UUID uuid = uuidUtility.getUUIDOf(playerName);
|
||||||
try {
|
|
||||||
UUID uuid = UUIDUtility.getUUIDOf(playerName);
|
|
||||||
|
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_VALID));
|
sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_VALID));
|
||||||
return;
|
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 (!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();
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,24 @@
|
|||||||
package com.djrapitops.plan.command.commands.manage;
|
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.DBSystem;
|
||||||
import com.djrapitops.plan.system.database.databases.Database;
|
import com.djrapitops.plan.system.database.databases.Database;
|
||||||
import com.djrapitops.plan.system.database.databases.sql.SQLiteDB;
|
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.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
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.settings.Permissions;
|
||||||
import com.djrapitops.plugin.api.utility.log.Log;
|
|
||||||
import com.djrapitops.plugin.command.CommandNode;
|
import com.djrapitops.plugin.command.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
import com.djrapitops.plugin.command.CommandType;
|
||||||
import com.djrapitops.plugin.command.ISender;
|
import com.djrapitops.plugin.command.Sender;
|
||||||
import com.djrapitops.plugin.task.AbsRunnable;
|
import com.djrapitops.plugin.logging.L;
|
||||||
import com.djrapitops.plugin.task.RunnableFactory;
|
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@ -29,14 +30,30 @@ import java.util.Arrays;
|
|||||||
*/
|
*/
|
||||||
public class ManageRestoreCommand extends CommandNode {
|
public class ManageRestoreCommand extends CommandNode {
|
||||||
|
|
||||||
private final PlanPlugin plugin;
|
|
||||||
private final Locale locale;
|
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);
|
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("<Filename.db>", "<dbTo>", "[-a]");
|
setArguments("<Filename.db>", "<dbTo>", "[-a]");
|
||||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE_RESTORE));
|
setShortHelp(locale.getString(CmdHelpLang.MANAGE_RESTORE));
|
||||||
@ -44,7 +61,7 @@ public class ManageRestoreCommand extends CommandNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||||
Verify.isTrue(args.length >= 2,
|
Verify.isTrue(args.length >= 2,
|
||||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ARGS, 2, Arrays.toString(this.getArguments()))));
|
() -> 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)));
|
() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_INCORRECT_DB, dbName)));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Database database = DBSystem.getActiveDatabaseByName(dbName);
|
Database database = dbSystem.getActiveDatabaseByName(dbName);
|
||||||
|
|
||||||
Verify.isFalse(backupDbName.contains("database") && database instanceof SQLiteDB,
|
Verify.isFalse(backupDbName.contains("database") && database instanceof SQLiteDB,
|
||||||
() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_SAME_DB)));
|
() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_SAME_DB)));
|
||||||
|
database.init();
|
||||||
|
|
||||||
if (!Verify.contains("-a", args)) {
|
if (!Verify.contains("-a", args)) {
|
||||||
sender.sendMessage(locale.getString(ManageLang.CONFIRMATION, locale.getString(ManageLang.CONFIRM_OVERWRITE, database.getName())));
|
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) {
|
private void runRestoreTask(String backupDbName, Sender sender, Database database) {
|
||||||
RunnableFactory.createNew(new AbsRunnable("RestoreTask") {
|
processing.submitCritical(() -> {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
String backupDBName = backupDbName;
|
||||||
try {
|
boolean containsDBFileExtension = backupDBName.endsWith(".db");
|
||||||
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()) {
|
if (!backupDBFile.exists()) {
|
||||||
sender.sendMessage(locale.getString(ManageLang.FAIL_FILE_NOT_FOUND, backupDBFile.getAbsolutePath()));
|
sender.sendMessage(locale.getString(ManageLang.FAIL_FILE_NOT_FOUND, backupDBFile.getAbsolutePath()));
|
||||||
return;
|
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 (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();
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.djrapitops.plan.command.commands.manage;
|
package com.djrapitops.plan.command.commands.manage;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanPlugin;
|
|
||||||
import com.djrapitops.plan.api.exceptions.connection.*;
|
import com.djrapitops.plan.api.exceptions.connection.*;
|
||||||
import com.djrapitops.plan.system.info.InfoSystem;
|
import com.djrapitops.plan.system.info.InfoSystem;
|
||||||
import com.djrapitops.plan.system.locale.Locale;
|
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.processing.Processing;
|
||||||
import com.djrapitops.plan.system.settings.Permissions;
|
import com.djrapitops.plan.system.settings.Permissions;
|
||||||
import com.djrapitops.plan.system.settings.Settings;
|
import com.djrapitops.plan.system.settings.Settings;
|
||||||
import com.djrapitops.plan.system.webserver.WebServerSystem;
|
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||||
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.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
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 com.djrapitops.plugin.utilities.Verify;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,14 +28,33 @@ import java.util.Arrays;
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
* @since 2.3.0
|
* @since 2.3.0
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class ManageSetupCommand extends CommandNode {
|
public class ManageSetupCommand extends CommandNode {
|
||||||
|
|
||||||
private final Locale locale;
|
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);
|
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("<BungeeAddress>");
|
setArguments("<BungeeAddress>");
|
||||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE_SETUP));
|
setShortHelp(locale.getString(CmdHelpLang.MANAGE_SETUP));
|
||||||
@ -40,11 +62,11 @@ public class ManageSetupCommand extends CommandNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||||
Verify.isTrue(args.length >= 1,
|
Verify.isTrue(args.length >= 1,
|
||||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
() -> 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));
|
sender.sendMessage(locale.getString(CommandLang.CONNECT_WEBSERVER_NOT_ENABLED));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -60,13 +82,13 @@ public class ManageSetupCommand extends CommandNode {
|
|||||||
requestSetup(sender, address);
|
requestSetup(sender, address);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void requestSetup(ISender sender, String address) {
|
private void requestSetup(Sender sender, String address) {
|
||||||
Processing.submitNonCritical(() -> {
|
processing.submitNonCritical(() -> {
|
||||||
try {
|
try {
|
||||||
Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.set(false);
|
config.set(Settings.BUNGEE_OVERRIDE_STANDALONE_MODE, false);
|
||||||
Settings.BUNGEE_COPY_CONFIG.set(true);
|
config.set(Settings.BUNGEE_COPY_CONFIG, true);
|
||||||
|
|
||||||
InfoSystem.getInstance().requestSetUp(address);
|
infoSystem.requestSetUp(address);
|
||||||
|
|
||||||
sender.sendMessage(locale.getString(CommandLang.CONNECT_SUCCESS));
|
sender.sendMessage(locale.getString(CommandLang.CONNECT_SUCCESS));
|
||||||
} catch (ForbiddenException e) {
|
} catch (ForbiddenException e) {
|
||||||
@ -82,7 +104,7 @@ public class ManageSetupCommand extends CommandNode {
|
|||||||
} catch (GatewayException e) {
|
} catch (GatewayException e) {
|
||||||
sender.sendMessage(locale.getString(CommandLang.CONNECT_GATEWAY));
|
sender.sendMessage(locale.getString(CommandLang.CONNECT_GATEWAY));
|
||||||
} catch (WebException e) {
|
} catch (WebException e) {
|
||||||
Log.toLog(this.getClass(), e);
|
errorHandler.log(L.WARN, this.getClass(), e);
|
||||||
sender.sendMessage(locale.getString(CommandLang.CONNECT_FAIL, e.toString()));
|
sender.sendMessage(locale.getString(CommandLang.CONNECT_FAIL, e.toString()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.djrapitops.plan.command.commands.manage;
|
package com.djrapitops.plan.command.commands.manage;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanPlugin;
|
|
||||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||||
import com.djrapitops.plan.system.database.databases.Database;
|
import com.djrapitops.plan.system.database.databases.Database;
|
||||||
import com.djrapitops.plan.system.info.server.Server;
|
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.locale.lang.ManageLang;
|
||||||
import com.djrapitops.plan.system.processing.Processing;
|
import com.djrapitops.plan.system.processing.Processing;
|
||||||
import com.djrapitops.plan.system.settings.Permissions;
|
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.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
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.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -26,14 +28,30 @@ import java.util.UUID;
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class ManageUninstalledCommand extends CommandNode {
|
public class ManageUninstalledCommand extends CommandNode {
|
||||||
|
|
||||||
private final Locale locale;
|
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);
|
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));
|
setShortHelp(locale.getString(CmdHelpLang.MANAGE_UNINSTALLED));
|
||||||
setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE_UNINSTALLED));
|
setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE_UNINSTALLED));
|
||||||
@ -41,10 +59,10 @@ public class ManageUninstalledCommand extends CommandNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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));
|
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
|
||||||
|
|
||||||
Processing.submitNonCritical(() -> {
|
processing.submitNonCritical(() -> {
|
||||||
try {
|
try {
|
||||||
Optional<Server> serverOptional = getServer(args);
|
Optional<Server> serverOptional = getServer(args);
|
||||||
if (!serverOptional.isPresent()) {
|
if (!serverOptional.isPresent()) {
|
||||||
@ -53,23 +71,23 @@ public class ManageUninstalledCommand extends CommandNode {
|
|||||||
}
|
}
|
||||||
Server server = serverOptional.get();
|
Server server = serverOptional.get();
|
||||||
UUID serverUUID = server.getUuid();
|
UUID serverUUID = server.getUuid();
|
||||||
if (ServerInfo.getServerUUID().equals(serverUUID)) {
|
if (serverInfo.getServerUUID().equals(serverUUID)) {
|
||||||
sender.sendMessage(locale.getString(ManageLang.UNINSTALLING_SAME_SERVER));
|
sender.sendMessage(locale.getString(ManageLang.UNINSTALLING_SAME_SERVER));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Database.getActive().save().setAsUninstalled(serverUUID);
|
database.save().setAsUninstalled(serverUUID);
|
||||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
|
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
|
||||||
} catch (DBOpException e) {
|
} catch (DBOpException e) {
|
||||||
sender.sendMessage("§cError occurred: " + e.toString());
|
sender.sendMessage("§cError occurred: " + e.toString());
|
||||||
Log.toLog(this.getClass(), e);
|
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<Server> getServer(String[] args) {
|
private Optional<Server> getServer(String[] args) {
|
||||||
if (args.length >= 1) {
|
if (args.length >= 1) {
|
||||||
Map<UUID, Server> bukkitServers = Database.getActive().fetch().getBukkitServers();
|
Map<UUID, Server> bukkitServers = database.fetch().getBukkitServers();
|
||||||
String serverIdentifier = getGivenIdentifier(args);
|
String serverIdentifier = getGivenIdentifier(args);
|
||||||
for (Map.Entry<UUID, Server> entry : bukkitServers.entrySet()) {
|
for (Map.Entry<UUID, Server> entry : bukkitServers.entrySet()) {
|
||||||
Server server = entry.getValue();
|
Server server = entry.getValue();
|
||||||
|
@ -1,21 +1,22 @@
|
|||||||
package com.djrapitops.plan.command.commands.webuser;
|
package com.djrapitops.plan.command.commands.webuser;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanPlugin;
|
|
||||||
import com.djrapitops.plan.data.WebUser;
|
import com.djrapitops.plan.data.WebUser;
|
||||||
import com.djrapitops.plan.system.database.databases.Database;
|
import com.djrapitops.plan.system.database.databases.Database;
|
||||||
import com.djrapitops.plan.system.locale.Locale;
|
import com.djrapitops.plan.system.locale.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
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.settings.Permissions;
|
||||||
import com.djrapitops.plugin.api.utility.log.Log;
|
|
||||||
import com.djrapitops.plugin.command.CommandNode;
|
import com.djrapitops.plugin.command.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
import com.djrapitops.plugin.command.CommandType;
|
||||||
import com.djrapitops.plugin.command.ISender;
|
import com.djrapitops.plugin.command.Sender;
|
||||||
import com.djrapitops.plugin.task.AbsRunnable;
|
import com.djrapitops.plugin.logging.L;
|
||||||
import com.djrapitops.plugin.task.RunnableFactory;
|
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,45 +25,51 @@ import java.util.Arrays;
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
* @since 3.5.2
|
* @since 3.5.2
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class WebCheckCommand extends CommandNode {
|
public class WebCheckCommand extends CommandNode {
|
||||||
|
|
||||||
private final Locale locale;
|
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);
|
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));
|
setShortHelp(locale.getString(CmdHelpLang.WEB_CHECK));
|
||||||
setArguments("<username>");
|
setArguments("<username>");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||||
Verify.isTrue(args.length >= 1,
|
Verify.isTrue(args.length >= 1,
|
||||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
||||||
|
|
||||||
Database database = Database.getActive();
|
|
||||||
String user = args[0];
|
String user = args[0];
|
||||||
|
|
||||||
RunnableFactory.createNew(new AbsRunnable("Webuser Check Task: " + user) {
|
processing.submitNonCritical(() -> {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
if (!database.check().doesWebUserExists(user)) {
|
||||||
try {
|
sender.sendMessage(locale.getString(CommandLang.FAIL_WEB_USER_NOT_EXISTS));
|
||||||
if (!database.check().doesWebUserExists(user)) {
|
return;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
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();
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,21 @@
|
|||||||
package com.djrapitops.plan.command.commands.webuser;
|
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.database.databases.Database;
|
||||||
import com.djrapitops.plan.system.locale.Locale;
|
import com.djrapitops.plan.system.locale.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
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.settings.Permissions;
|
||||||
import com.djrapitops.plugin.api.utility.log.Log;
|
|
||||||
import com.djrapitops.plugin.command.CommandNode;
|
import com.djrapitops.plugin.command.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
import com.djrapitops.plugin.command.CommandType;
|
||||||
import com.djrapitops.plugin.command.ISender;
|
import com.djrapitops.plugin.command.Sender;
|
||||||
import com.djrapitops.plugin.task.AbsRunnable;
|
import com.djrapitops.plugin.logging.L;
|
||||||
import com.djrapitops.plugin.task.RunnableFactory;
|
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,45 +24,52 @@ import java.util.Arrays;
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
* @since 3.5.2
|
* @since 3.5.2
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class WebDeleteCommand extends CommandNode {
|
public class WebDeleteCommand extends CommandNode {
|
||||||
|
|
||||||
private final Locale locale;
|
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);
|
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));
|
setShortHelp(locale.getString(CmdHelpLang.WEB_DELETE));
|
||||||
setArguments("<username>");
|
setArguments("<username>");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||||
Verify.isTrue(args.length >= 1,
|
Verify.isTrue(args.length >= 1,
|
||||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
||||||
|
|
||||||
Database database = Database.getActive();
|
|
||||||
String user = args[0];
|
String user = args[0];
|
||||||
|
|
||||||
RunnableFactory.createNew("Webuser Delete Task: " + user, new AbsRunnable() {
|
processing.submitNonCritical(() -> {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
if (!database.check().doesWebUserExists(user)) {
|
||||||
try {
|
sender.sendMessage("§c[Plan] User Doesn't exist.");
|
||||||
if (!database.check().doesWebUserExists(user)) {
|
return;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
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();
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
package com.djrapitops.plan.command.commands.webuser;
|
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.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||||
import com.djrapitops.plan.system.settings.Permissions;
|
import com.djrapitops.plan.system.settings.Permissions;
|
||||||
import com.djrapitops.plugin.command.CommandNode;
|
import com.djrapitops.plugin.command.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
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.
|
* Subcommand for info about permission levels.
|
||||||
@ -19,16 +20,17 @@ public class WebLevelCommand extends CommandNode {
|
|||||||
|
|
||||||
private final Locale locale;
|
private final Locale locale;
|
||||||
|
|
||||||
public WebLevelCommand(PlanPlugin plugin) {
|
@Inject
|
||||||
|
public WebLevelCommand(Locale locale) {
|
||||||
super("level", Permissions.MANAGE_WEB.getPerm(), CommandType.CONSOLE);
|
super("level", Permissions.MANAGE_WEB.getPerm(), CommandType.CONSOLE);
|
||||||
|
|
||||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
this.locale = locale;
|
||||||
|
|
||||||
setShortHelp(locale.getString(CmdHelpLang.WEB_LEVEL));
|
setShortHelp(locale.getString(CmdHelpLang.WEB_LEVEL));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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));
|
sender.sendMessage(locale.getArray(CommandLang.WEB_PERMISSION_LEVELS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,21 +1,22 @@
|
|||||||
package com.djrapitops.plan.command.commands.webuser;
|
package com.djrapitops.plan.command.commands.webuser;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanPlugin;
|
|
||||||
import com.djrapitops.plan.data.WebUser;
|
import com.djrapitops.plan.data.WebUser;
|
||||||
import com.djrapitops.plan.system.database.databases.Database;
|
import com.djrapitops.plan.system.database.databases.Database;
|
||||||
import com.djrapitops.plan.system.locale.Locale;
|
import com.djrapitops.plan.system.locale.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
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.settings.Permissions;
|
||||||
import com.djrapitops.plan.utilities.comparators.WebUserComparator;
|
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.CommandNode;
|
||||||
import com.djrapitops.plugin.command.CommandType;
|
import com.djrapitops.plugin.command.CommandType;
|
||||||
import com.djrapitops.plugin.command.ISender;
|
import com.djrapitops.plugin.command.Sender;
|
||||||
import com.djrapitops.plugin.task.AbsRunnable;
|
import com.djrapitops.plugin.logging.L;
|
||||||
import com.djrapitops.plugin.task.RunnableFactory;
|
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,39 +25,47 @@ import java.util.List;
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
* @since 3.5.2
|
* @since 3.5.2
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class WebListUsersCommand extends CommandNode {
|
public class WebListUsersCommand extends CommandNode {
|
||||||
|
|
||||||
private final Locale locale;
|
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);
|
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));
|
setShortHelp(locale.getString(CmdHelpLang.WEB_LIST));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||||
RunnableFactory.createNew(new AbsRunnable("Web user List Task") {
|
processing.submitNonCritical(() -> {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
List<WebUser> users = database.fetch().getWebUsers();
|
||||||
try {
|
users.sort(new WebUserComparator());
|
||||||
List<WebUser> users = Database.getActive().fetch().getWebUsers();
|
sender.sendMessage(locale.getString(CommandLang.HEADER_WEB_USERS, users.size()));
|
||||||
users.sort(new WebUserComparator());
|
for (WebUser user : users) {
|
||||||
sender.sendMessage(locale.getString(CommandLang.HEADER_WEB_USERS, users.size()));
|
sender.sendMessage(locale.getString(CommandLang.WEB_USER_LIST, user.getName(), user.getPermLevel()));
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
sender.sendMessage(">");
|
||||||
|
} catch (Exception e) {
|
||||||
|
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||||
|
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||||
}
|
}
|
||||||
}).runTaskAsynchronously();
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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.DateHolder;
|
||||||
import com.djrapitops.plan.data.store.objects.DateMap;
|
import com.djrapitops.plan.data.store.objects.DateMap;
|
||||||
import com.djrapitops.plan.utilities.FormatUtils;
|
|
||||||
import com.djrapitops.plan.utilities.SHA256Hash;
|
import com.djrapitops.plan.utilities.SHA256Hash;
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.net.Inet6Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
@ -26,9 +26,8 @@ public class GeoInfo implements DateHolder, Serializable {
|
|||||||
private final String ipHash;
|
private final String ipHash;
|
||||||
private final long date;
|
private final long date;
|
||||||
|
|
||||||
public GeoInfo(InetAddress address, String geolocation, long lastUsed)
|
public GeoInfo(InetAddress address, String geolocation, long lastUsed) throws NoSuchAlgorithmException {
|
||||||
throws NoSuchAlgorithmException {
|
this(formatIP(address), geolocation, lastUsed, new SHA256Hash(address.getHostAddress()).create());
|
||||||
this(FormatUtils.formatIP(address), geolocation, lastUsed, new SHA256Hash(address.getHostAddress()).create());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GeoInfo(String ip, String geolocation, long date, String ipHash) {
|
public GeoInfo(String ip, String geolocation, long date, String ipHash) {
|
||||||
@ -46,6 +45,42 @@ public class GeoInfo implements DateHolder, Serializable {
|
|||||||
return map;
|
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() {
|
public String getIp() {
|
||||||
return ip;
|
return ip;
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,13 @@ import java.util.UUID;
|
|||||||
public class PlayerDeath implements DateHolder {
|
public class PlayerDeath implements DateHolder {
|
||||||
|
|
||||||
private final UUID killer;
|
private final UUID killer;
|
||||||
|
private final String killerName;
|
||||||
private final long date;
|
private final long date;
|
||||||
private final String weapon;
|
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.killer = killer;
|
||||||
|
this.killerName = killerName;
|
||||||
this.date = date;
|
this.date = date;
|
||||||
this.weapon = weapon;
|
this.weapon = weapon;
|
||||||
}
|
}
|
||||||
@ -20,6 +22,10 @@ public class PlayerDeath implements DateHolder {
|
|||||||
return killer;
|
return killer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getKillerName() {
|
||||||
|
return killerName;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getDate() {
|
public long getDate() {
|
||||||
return date;
|
return date;
|
||||||
|
@ -2,8 +2,8 @@ package com.djrapitops.plan.data.container;
|
|||||||
|
|
||||||
import com.djrapitops.plan.data.store.objects.DateHolder;
|
import com.djrapitops.plan.data.store.objects.DateHolder;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -12,11 +12,13 @@ import java.util.UUID;
|
|||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class PlayerKill implements DateHolder, Serializable {
|
public class PlayerKill implements DateHolder {
|
||||||
|
|
||||||
private final UUID victim;
|
private final UUID victim;
|
||||||
private final long date;
|
|
||||||
private final String weapon;
|
private final String weapon;
|
||||||
|
private final long date;
|
||||||
|
|
||||||
|
private String victimName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a PlayerKill object with given parameters.
|
* Creates a PlayerKill object with given parameters.
|
||||||
@ -31,6 +33,13 @@ public class PlayerKill implements DateHolder, Serializable {
|
|||||||
this.date = date;
|
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.
|
* Get the victim's UUID.
|
||||||
*
|
*
|
||||||
@ -40,6 +49,10 @@ public class PlayerKill implements DateHolder, Serializable {
|
|||||||
return victim;
|
return victim;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<String> getVictimName() {
|
||||||
|
return Optional.ofNullable(victimName);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getDate() {
|
public long getDate() {
|
||||||
return date;
|
return date;
|
||||||
|
@ -2,11 +2,8 @@ package com.djrapitops.plan.data.container;
|
|||||||
|
|
||||||
import com.djrapitops.plan.data.store.containers.DataContainer;
|
import com.djrapitops.plan.data.store.containers.DataContainer;
|
||||||
import com.djrapitops.plan.data.store.keys.SessionKeys;
|
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.store.objects.DateHolder;
|
||||||
import com.djrapitops.plan.data.time.WorldTimes;
|
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.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -30,11 +27,12 @@ public class Session extends DataContainer implements DateHolder {
|
|||||||
* Creates a new session.
|
* Creates a new session.
|
||||||
*
|
*
|
||||||
* @param uuid UUID of the Player.
|
* @param uuid UUID of the Player.
|
||||||
|
* @param serverUUID UUID of the server.
|
||||||
* @param sessionStart Epoch ms the session started.
|
* @param sessionStart Epoch ms the session started.
|
||||||
* @param world Starting world.
|
* @param world Starting world.
|
||||||
* @param gm Starting GameMode.
|
* @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;
|
this.sessionStart = sessionStart;
|
||||||
worldTimes = new WorldTimes(world, gm, sessionStart);
|
worldTimes = new WorldTimes(world, gm, sessionStart);
|
||||||
playerKills = new ArrayList<>();
|
playerKills = new ArrayList<>();
|
||||||
@ -44,6 +42,7 @@ public class Session extends DataContainer implements DateHolder {
|
|||||||
afkTime = 0;
|
afkTime = 0;
|
||||||
|
|
||||||
putRawData(SessionKeys.UUID, uuid);
|
putRawData(SessionKeys.UUID, uuid);
|
||||||
|
putRawData(SessionKeys.SERVER_UUID, serverUUID);
|
||||||
putSupplier(SessionKeys.START, this::getSessionStart);
|
putSupplier(SessionKeys.START, this::getSessionStart);
|
||||||
putSupplier(SessionKeys.WORLD_TIMES, this::getWorldTimes);
|
putSupplier(SessionKeys.WORLD_TIMES, this::getWorldTimes);
|
||||||
putSupplier(SessionKeys.PLAYER_KILLS, this::getPlayerKills);
|
putSupplier(SessionKeys.PLAYER_KILLS, this::getPlayerKills);
|
||||||
@ -56,9 +55,8 @@ public class Session extends DataContainer implements DateHolder {
|
|||||||
putSupplier(SessionKeys.LENGTH, () ->
|
putSupplier(SessionKeys.LENGTH, () ->
|
||||||
getValue(SessionKeys.END).orElse(System.currentTimeMillis()) - getUnsafe(SessionKeys.START));
|
getValue(SessionKeys.END).orElse(System.currentTimeMillis()) - getUnsafe(SessionKeys.START));
|
||||||
putSupplier(SessionKeys.ACTIVE_TIME, () -> getUnsafe(SessionKeys.LENGTH) - getUnsafe(SessionKeys.AFK_TIME));
|
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));
|
getValue(SessionKeys.END).orElse(System.currentTimeMillis()) - getUnsafe(SessionKeys.START));
|
||||||
putSupplier(SessionKeys.ACTIVE_TIME, () -> getUnsafe(SessionKeys.LENGTH) - getUnsafe(SessionKeys.AFK_TIME));
|
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;
|
this.worldTimes = worldTimes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPlayerKills(List<PlayerKill> playerKills) {
|
@Override
|
||||||
this.playerKills = playerKills;
|
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() {
|
public boolean isFetchedFromDB() {
|
||||||
@ -173,17 +180,8 @@ public class Session extends DataContainer implements DateHolder {
|
|||||||
putRawData(SessionKeys.DB_ID, sessionID);
|
putRawData(SessionKeys.DB_ID, sessionID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public List<PlayerKill> getPlayerKills() {
|
||||||
public boolean equals(Object o) {
|
return playerKills;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -199,8 +197,8 @@ public class Session extends DataContainer implements DateHolder {
|
|||||||
return worldTimes;
|
return worldTimes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PlayerKill> getPlayerKills() {
|
public void setPlayerKills(List<PlayerKill> playerKills) {
|
||||||
return playerKills;
|
this.playerKills = playerKills;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getMobKills() {
|
private int getMobKills() {
|
||||||
@ -214,48 +212,4 @@ public class Session extends DataContainer implements DateHolder {
|
|||||||
private long getAfkTime() {
|
private long getAfkTime() {
|
||||||
return afkTime;
|
return afkTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getLongestWorldPlayed() {
|
|
||||||
Map<String, String> aliases = WorldAliasSettings.getAliases();
|
|
||||||
if (worldTimes == null) {
|
|
||||||
return "No World Time Data";
|
|
||||||
}
|
|
||||||
if (!supports(SessionKeys.END)) {
|
|
||||||
return "Current: " + aliases.get(worldTimes.getCurrentWorld());
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, Long> playtimePerAlias = worldTimes.getPlaytimePerAlias();
|
|
||||||
|
|
||||||
long longest = 0;
|
|
||||||
String theWorld = "-";
|
|
||||||
for (Map.Entry<String, Long> 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 +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,10 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.data.element;
|
package com.djrapitops.plan.data.element;
|
||||||
|
|
||||||
import com.djrapitops.plan.data.store.mutators.formatting.Formatter;
|
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||||
import com.djrapitops.plan.utilities.FormatUtils;
|
|
||||||
import com.djrapitops.plan.utilities.html.Html;
|
import com.djrapitops.plan.utilities.html.Html;
|
||||||
import com.djrapitops.plan.utilities.html.icon.Icon;
|
import com.djrapitops.plan.utilities.html.icon.Icon;
|
||||||
|
import com.djrapitops.plugin.utilities.ArrayUtil;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -40,10 +40,9 @@ public class TableContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public TableContainer(boolean players, String... header) {
|
public TableContainer(boolean players, String... header) {
|
||||||
this(FormatUtils.mergeArrays(
|
this(
|
||||||
new String[]{Icon.called("user").build() + " Player"},
|
ArrayUtil.merge(new String[]{Icon.called("user").build() + " Player"}, header)
|
||||||
header
|
);
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void addRow(Serializable... values) {
|
public final void addRow(Serializable... values) {
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
package com.djrapitops.plan.data.plugin;
|
package com.djrapitops.plan.data.plugin;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanPlugin;
|
|
||||||
import com.djrapitops.plan.data.element.InspectContainer;
|
import com.djrapitops.plan.data.element.InspectContainer;
|
||||||
import com.djrapitops.plan.system.PlanSystem;
|
|
||||||
import com.djrapitops.plan.system.SubSystem;
|
import com.djrapitops.plan.system.SubSystem;
|
||||||
import com.djrapitops.plugin.StaticHolder;
|
import com.djrapitops.plugin.logging.L;
|
||||||
import com.djrapitops.plugin.api.utility.log.Log;
|
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||||
import com.djrapitops.pluginbridge.plan.Bridge;
|
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -19,29 +18,30 @@ import java.util.stream.Collectors;
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class HookHandler implements SubSystem {
|
public class HookHandler implements SubSystem {
|
||||||
|
|
||||||
private final List<PluginData> additionalDataSources;
|
private final List<PluginData> additionalDataSources;
|
||||||
private PluginsConfigSection configHandler;
|
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<>();
|
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
|
@Override
|
||||||
public void enable() {
|
public void enable() {
|
||||||
configHandler = new PluginsConfigSection();
|
|
||||||
try {
|
try {
|
||||||
Bridge.hook(this);
|
// Bridge.hook(this);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.toLog(this.getClass(), e);
|
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||||
Log.error("Plan Plugin Bridge not included in the plugin jar.");
|
logger.error("Plan Plugin Bridge not included in the plugin jar.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,17 +65,16 @@ public class HookHandler implements SubSystem {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
StaticHolder.saveInstance(dataSource.getClass(), PlanPlugin.getInstance().getClass());
|
|
||||||
if (!configHandler.hasSection(dataSource)) {
|
if (!configHandler.hasSection(dataSource)) {
|
||||||
configHandler.createSection(dataSource);
|
configHandler.createSection(dataSource);
|
||||||
}
|
}
|
||||||
if (configHandler.isEnabled(dataSource)) {
|
if (configHandler.isEnabled(dataSource)) {
|
||||||
Log.debug("Registered a new datasource: " + dataSource.getSourcePlugin());
|
logger.debug("Registered a new datasource: " + dataSource.getSourcePlugin());
|
||||||
additionalDataSources.add(dataSource);
|
additionalDataSources.add(dataSource);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.toLog(this.getClass(), e);
|
errorHandler.log(L.WARN, this.getClass(), e);
|
||||||
Log.error("Attempting to register PluginDataSource caused an exception.");
|
logger.error("Attempting to register PluginDataSource caused an exception.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,8 +106,8 @@ public class HookHandler implements SubSystem {
|
|||||||
}
|
}
|
||||||
} catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError e) {
|
} catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError e) {
|
||||||
String sourcePlugin = pluginData.getSourcePlugin();
|
String sourcePlugin = pluginData.getSourcePlugin();
|
||||||
Log.error("PluginData caused exception: " + sourcePlugin);
|
logger.error("PluginData caused exception: " + sourcePlugin);
|
||||||
Log.toLog(this.getClass().getName() + " " + sourcePlugin, e);
|
errorHandler.log(L.WARN, pluginData.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return containers;
|
return containers;
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package com.djrapitops.plan.data.plugin;
|
package com.djrapitops.plan.data.plugin;
|
||||||
|
|
||||||
import com.djrapitops.plan.system.settings.config.ConfigSystem;
|
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||||
import com.djrapitops.plugin.api.config.ConfigNode;
|
import com.djrapitops.plugin.config.ConfigNode;
|
||||||
import com.djrapitops.plugin.api.utility.log.Log;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@ -15,6 +14,14 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public class PluginsConfigSection {
|
public class PluginsConfigSection {
|
||||||
|
|
||||||
|
private final PlanConfig config;
|
||||||
|
|
||||||
|
public PluginsConfigSection(
|
||||||
|
PlanConfig config
|
||||||
|
) {
|
||||||
|
this.config = config;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasSection(PluginData dataSource) {
|
public boolean hasSection(PluginData dataSource) {
|
||||||
ConfigNode section = getPluginsSection();
|
ConfigNode section = getPluginsSection();
|
||||||
String pluginName = dataSource.getSourcePlugin();
|
String pluginName = dataSource.getSourcePlugin();
|
||||||
@ -23,20 +30,16 @@ public class PluginsConfigSection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ConfigNode getPluginsSection() {
|
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();
|
ConfigNode section = getPluginsSection();
|
||||||
String pluginName = dataSource.getSourcePlugin();
|
String pluginName = dataSource.getSourcePlugin();
|
||||||
|
|
||||||
section.set(pluginName + ".Enabled", true);
|
section.set(pluginName + ".Enabled", true);
|
||||||
try {
|
section.sort();
|
||||||
section.sort();
|
section.save();
|
||||||
section.save();
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.toLog(this.getClass(), e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnabled(PluginData dataSource) {
|
public boolean isEnabled(PluginData dataSource) {
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
package com.djrapitops.plan.data.store;
|
package com.djrapitops.plan.data.store;
|
||||||
|
|
||||||
import com.djrapitops.plugin.api.TimeAmount;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caching layer between Supplier and caller.
|
* Caching layer between Supplier and caller.
|
||||||
*
|
* <p>
|
||||||
* Refreshes the value if 30 seconds have passed since the last call.
|
* Refreshes the value if 30 seconds have passed since the last call.
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
@ -19,7 +18,7 @@ public class CachingSupplier<T> implements Supplier<T> {
|
|||||||
private long timeToLive;
|
private long timeToLive;
|
||||||
|
|
||||||
public CachingSupplier(Supplier<T> original) {
|
public CachingSupplier(Supplier<T> original) {
|
||||||
this(original, TimeAmount.SECOND.ms() * 30L);
|
this(original, TimeUnit.SECONDS.toMillis(30L));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CachingSupplier(Supplier<T> original, long timeToLive) {
|
public CachingSupplier(Supplier<T> original, long timeToLive) {
|
||||||
|
@ -1,42 +1,37 @@
|
|||||||
package com.djrapitops.plan.data.store.containers;
|
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.Key;
|
||||||
import com.djrapitops.plan.data.store.Type;
|
import com.djrapitops.plan.data.store.Type;
|
||||||
import com.djrapitops.plan.data.store.keys.AnalysisKeys;
|
import com.djrapitops.plan.data.store.keys.AnalysisKeys;
|
||||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
||||||
import com.djrapitops.plan.data.store.keys.ServerKeys;
|
import com.djrapitops.plan.data.store.keys.ServerKeys;
|
||||||
import com.djrapitops.plan.data.store.mutators.*;
|
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.store.mutators.health.HealthInformation;
|
||||||
import com.djrapitops.plan.data.time.WorldTimes;
|
import com.djrapitops.plan.data.time.WorldTimes;
|
||||||
import com.djrapitops.plan.system.database.databases.Database;
|
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.info.server.properties.ServerProperties;
|
||||||
import com.djrapitops.plan.system.settings.Settings;
|
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.Theme;
|
||||||
import com.djrapitops.plan.system.settings.theme.ThemeVal;
|
import com.djrapitops.plan.system.settings.theme.ThemeVal;
|
||||||
import com.djrapitops.plan.utilities.MiscUtils;
|
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||||
import com.djrapitops.plan.utilities.analysis.ServerBanDataReader;
|
import com.djrapitops.plan.utilities.html.graphs.Graphs;
|
||||||
import com.djrapitops.plan.utilities.html.graphs.ActivityStackGraph;
|
import com.djrapitops.plan.utilities.html.graphs.bar.BarGraph;
|
||||||
import com.djrapitops.plan.utilities.html.graphs.PunchCardGraph;
|
import com.djrapitops.plan.utilities.html.graphs.line.PingGraph;
|
||||||
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.html.graphs.pie.WorldPie;
|
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.AnalysisPluginsTabContentCreator;
|
||||||
import com.djrapitops.plan.utilities.html.structure.RecentLoginList;
|
import com.djrapitops.plan.utilities.html.structure.RecentLoginList;
|
||||||
import com.djrapitops.plan.utilities.html.structure.SessionAccordion;
|
import com.djrapitops.plan.utilities.html.structure.SessionAccordion;
|
||||||
import com.djrapitops.plan.utilities.html.tables.CommandUseTable;
|
import com.djrapitops.plan.utilities.html.tables.HtmlTables;
|
||||||
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.plugin.api.TimeAmount;
|
import com.djrapitops.plugin.api.TimeAmount;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,10 +45,43 @@ public class AnalysisContainer extends DataContainer {
|
|||||||
|
|
||||||
private final ServerContainer serverContainer;
|
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<Map<UUID, String>> serverNames = new Key<>(new Type<Map<UUID, String>>() {}, "SERVER_NAMES");
|
private static final Key<Map<UUID, String>> serverNames = new Key<>(new Type<Map<UUID, String>>() {}, "SERVER_NAMES");
|
||||||
|
|
||||||
public AnalysisContainer(ServerContainer serverContainer) {
|
public AnalysisContainer(
|
||||||
|
ServerContainer serverContainer,
|
||||||
|
String version,
|
||||||
|
PlanConfig config,
|
||||||
|
Theme theme,
|
||||||
|
Database database,
|
||||||
|
ServerProperties serverProperties,
|
||||||
|
Formatters formatters,
|
||||||
|
Graphs graphs,
|
||||||
|
HtmlTables tables,
|
||||||
|
Accordions accordions,
|
||||||
|
AnalysisPluginsTabContentCreator pluginsTabContentCreator
|
||||||
|
) {
|
||||||
this.serverContainer = serverContainer;
|
this.serverContainer = serverContainer;
|
||||||
|
this.version = version;
|
||||||
|
this.config = config;
|
||||||
|
this.theme = theme;
|
||||||
|
this.database = database;
|
||||||
|
this.serverProperties = serverProperties;
|
||||||
|
this.formatters = formatters;
|
||||||
|
this.graphs = graphs;
|
||||||
|
this.tables = tables;
|
||||||
|
this.accordions = accordions;
|
||||||
|
this.pluginsTabContentCreator = pluginsTabContentCreator;
|
||||||
addAnalysisSuppliers();
|
addAnalysisSuppliers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,27 +102,21 @@ public class AnalysisContainer extends DataContainer {
|
|||||||
addCommandSuppliers();
|
addCommandSuppliers();
|
||||||
addServerHealth();
|
addServerHealth();
|
||||||
addPluginSuppliers();
|
addPluginSuppliers();
|
||||||
|
|
||||||
runCombiners();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void runCombiners() {
|
|
||||||
new MultiBanCombiner(this.serverContainer).combine(getUnsafe(AnalysisKeys.BAN_DATA));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addConstants() {
|
private void addConstants() {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
putRawData(AnalysisKeys.ANALYSIS_TIME, now);
|
putRawData(AnalysisKeys.ANALYSIS_TIME, now);
|
||||||
putRawData(AnalysisKeys.ANALYSIS_TIME_DAY_AGO, now - TimeAmount.DAY.ms());
|
putRawData(AnalysisKeys.ANALYSIS_TIME_DAY_AGO, now - TimeUnit.DAYS.toMillis(1L));
|
||||||
putRawData(AnalysisKeys.ANALYSIS_TIME_WEEK_AGO, now - TimeAmount.WEEK.ms());
|
putRawData(AnalysisKeys.ANALYSIS_TIME_WEEK_AGO, now - TimeAmount.WEEK.toMillis(1L));
|
||||||
putRawData(AnalysisKeys.ANALYSIS_TIME_MONTH_AGO, now - TimeAmount.MONTH.ms());
|
putRawData(AnalysisKeys.ANALYSIS_TIME_MONTH_AGO, now - TimeAmount.MONTH.toMillis(1L));
|
||||||
putSupplier(AnalysisKeys.REFRESH_TIME_F, () -> Formatters.second().apply(() -> getUnsafe(AnalysisKeys.ANALYSIS_TIME)));
|
putSupplier(AnalysisKeys.REFRESH_TIME_F, () -> formatters.secondLong().apply(getUnsafe(AnalysisKeys.ANALYSIS_TIME)));
|
||||||
|
|
||||||
putRawData(AnalysisKeys.VERSION, PlanPlugin.getInstance().getVersion());
|
putRawData(AnalysisKeys.VERSION, version);
|
||||||
putSupplier(AnalysisKeys.TIME_ZONE, MiscUtils::getTimeZoneOffsetHours);
|
putSupplier(AnalysisKeys.TIME_ZONE, config::getTimeZoneOffsetHours);
|
||||||
putRawData(AnalysisKeys.FIRST_DAY, 1);
|
putRawData(AnalysisKeys.FIRST_DAY, 1);
|
||||||
putRawData(AnalysisKeys.TPS_MEDIUM, Settings.THEME_GRAPH_TPS_THRESHOLD_MED.getNumber());
|
putRawData(AnalysisKeys.TPS_MEDIUM, config.getNumber(Settings.THEME_GRAPH_TPS_THRESHOLD_MED));
|
||||||
putRawData(AnalysisKeys.TPS_HIGH, Settings.THEME_GRAPH_TPS_THRESHOLD_HIGH.getNumber());
|
putRawData(AnalysisKeys.TPS_HIGH, config.getNumber(Settings.THEME_GRAPH_TPS_THRESHOLD_HIGH));
|
||||||
|
|
||||||
addServerProperties();
|
addServerProperties();
|
||||||
addThemeColors();
|
addThemeColors();
|
||||||
@ -105,24 +127,23 @@ public class AnalysisContainer extends DataContainer {
|
|||||||
getUnsafe(serverNames).getOrDefault(serverContainer.getUnsafe(ServerKeys.SERVER_UUID), "Plan")
|
getUnsafe(serverNames).getOrDefault(serverContainer.getUnsafe(ServerKeys.SERVER_UUID), "Plan")
|
||||||
);
|
);
|
||||||
|
|
||||||
ServerProperties serverProperties = ServerInfo.getServerProperties();
|
|
||||||
putRawData(AnalysisKeys.PLAYERS_MAX, serverProperties.getMaxPlayers());
|
putRawData(AnalysisKeys.PLAYERS_MAX, serverProperties.getMaxPlayers());
|
||||||
putRawData(AnalysisKeys.PLAYERS_ONLINE, serverProperties.getOnlinePlayers());
|
putRawData(AnalysisKeys.PLAYERS_ONLINE, serverProperties.getOnlinePlayers());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addThemeColors() {
|
private void addThemeColors() {
|
||||||
putRawData(AnalysisKeys.ACTIVITY_PIE_COLORS, Theme.getValue(ThemeVal.GRAPH_ACTIVITY_PIE));
|
putRawData(AnalysisKeys.ACTIVITY_PIE_COLORS, theme.getValue(ThemeVal.GRAPH_ACTIVITY_PIE));
|
||||||
putRawData(AnalysisKeys.GM_PIE_COLORS, Theme.getValue(ThemeVal.GRAPH_GM_PIE));
|
putRawData(AnalysisKeys.GM_PIE_COLORS, theme.getValue(ThemeVal.GRAPH_GM_PIE));
|
||||||
putRawData(AnalysisKeys.PLAYERS_GRAPH_COLOR, Theme.getValue(ThemeVal.GRAPH_PLAYERS_ONLINE));
|
putRawData(AnalysisKeys.PLAYERS_GRAPH_COLOR, theme.getValue(ThemeVal.GRAPH_PLAYERS_ONLINE));
|
||||||
putRawData(AnalysisKeys.TPS_LOW_COLOR, Theme.getValue(ThemeVal.GRAPH_TPS_LOW));
|
putRawData(AnalysisKeys.TPS_LOW_COLOR, theme.getValue(ThemeVal.GRAPH_TPS_LOW));
|
||||||
putRawData(AnalysisKeys.TPS_MEDIUM_COLOR, Theme.getValue(ThemeVal.GRAPH_TPS_MED));
|
putRawData(AnalysisKeys.TPS_MEDIUM_COLOR, theme.getValue(ThemeVal.GRAPH_TPS_MED));
|
||||||
putRawData(AnalysisKeys.TPS_HIGH_COLOR, Theme.getValue(ThemeVal.GRAPH_TPS_HIGH));
|
putRawData(AnalysisKeys.TPS_HIGH_COLOR, theme.getValue(ThemeVal.GRAPH_TPS_HIGH));
|
||||||
putRawData(AnalysisKeys.WORLD_MAP_LOW_COLOR, Theme.getValue(ThemeVal.WORLD_MAP_LOW));
|
putRawData(AnalysisKeys.WORLD_MAP_LOW_COLOR, theme.getValue(ThemeVal.WORLD_MAP_LOW));
|
||||||
putRawData(AnalysisKeys.WORLD_MAP_HIGH_COLOR, Theme.getValue(ThemeVal.WORLD_MAP_HIGH));
|
putRawData(AnalysisKeys.WORLD_MAP_HIGH_COLOR, theme.getValue(ThemeVal.WORLD_MAP_HIGH));
|
||||||
putRawData(AnalysisKeys.WORLD_PIE_COLORS, Theme.getValue(ThemeVal.GRAPH_WORLD_PIE));
|
putRawData(AnalysisKeys.WORLD_PIE_COLORS, theme.getValue(ThemeVal.GRAPH_WORLD_PIE));
|
||||||
putRawData(AnalysisKeys.AVG_PING_COLOR, Theme.getValue(ThemeVal.GRAPH_AVG_PING));
|
putRawData(AnalysisKeys.AVG_PING_COLOR, theme.getValue(ThemeVal.GRAPH_AVG_PING));
|
||||||
putRawData(AnalysisKeys.MAX_PING_COLOR, Theme.getValue(ThemeVal.GRAPH_MAX_PING));
|
putRawData(AnalysisKeys.MAX_PING_COLOR, theme.getValue(ThemeVal.GRAPH_MAX_PING));
|
||||||
putRawData(AnalysisKeys.MIN_PING_COLOR, Theme.getValue(ThemeVal.GRAPH_MIN_PING));
|
putRawData(AnalysisKeys.MIN_PING_COLOR, theme.getValue(ThemeVal.GRAPH_MIN_PING));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addPlayerSuppliers() {
|
private void addPlayerSuppliers() {
|
||||||
@ -142,18 +163,18 @@ public class AnalysisContainer extends DataContainer {
|
|||||||
);
|
);
|
||||||
putSupplier(AnalysisKeys.LAST_PEAK_TIME_F, () ->
|
putSupplier(AnalysisKeys.LAST_PEAK_TIME_F, () ->
|
||||||
serverContainer.getValue(ServerKeys.RECENT_PEAK_PLAYERS)
|
serverContainer.getValue(ServerKeys.RECENT_PEAK_PLAYERS)
|
||||||
.map(dateObj -> Formatters.year().apply(dateObj)).orElse("-")
|
.map(dateObj -> formatters.year().apply(dateObj)).orElse("-")
|
||||||
);
|
);
|
||||||
putSupplier(AnalysisKeys.ALL_TIME_PEAK_TIME_F, () ->
|
putSupplier(AnalysisKeys.ALL_TIME_PEAK_TIME_F, () ->
|
||||||
serverContainer.getValue(ServerKeys.ALL_TIME_PEAK_PLAYERS)
|
serverContainer.getValue(ServerKeys.ALL_TIME_PEAK_PLAYERS)
|
||||||
.map(dateObj -> Formatters.year().apply(dateObj)).orElse("-")
|
.map(dateObj -> formatters.year().apply(dateObj)).orElse("-")
|
||||||
);
|
);
|
||||||
putSupplier(AnalysisKeys.OPERATORS, () -> serverContainer.getValue(ServerKeys.OPERATORS).map(List::size).orElse(0));
|
putSupplier(AnalysisKeys.OPERATORS, () -> serverContainer.getValue(ServerKeys.OPERATORS).map(List::size).orElse(0));
|
||||||
putSupplier(AnalysisKeys.PLAYERS_TABLE, () ->
|
putSupplier(AnalysisKeys.PLAYERS_TABLE, () ->
|
||||||
PlayersTable.forServerPage(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).all()).parseHtml()
|
tables.playerTableForServerPage(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).all()).parseHtml()
|
||||||
);
|
);
|
||||||
putSupplier(AnalysisKeys.PING_TABLE, () ->
|
putSupplier(AnalysisKeys.PING_TABLE, () ->
|
||||||
new PingTable(
|
tables.pingTable(
|
||||||
getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)
|
getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)
|
||||||
.getPingPerCountry(serverContainer.getUnsafe(ServerKeys.SERVER_UUID))
|
.getPingPerCountry(serverContainer.getUnsafe(ServerKeys.SERVER_UUID))
|
||||||
).parseHtml()
|
).parseHtml()
|
||||||
@ -201,20 +222,20 @@ public class AnalysisContainer extends DataContainer {
|
|||||||
|
|
||||||
putSupplier(AnalysisKeys.UNIQUE_PLAYERS_PER_DAY, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).uniqueJoinsPerDay());
|
putSupplier(AnalysisKeys.UNIQUE_PLAYERS_PER_DAY, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).uniqueJoinsPerDay());
|
||||||
putSupplier(AnalysisKeys.NEW_PLAYERS_PER_DAY, () -> getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).newPerDay());
|
putSupplier(AnalysisKeys.NEW_PLAYERS_PER_DAY, () -> getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).newPerDay());
|
||||||
putSupplier(AnalysisKeys.UNIQUE_PLAYERS_SERIES, () -> new AbstractLineGraph(
|
putSupplier(AnalysisKeys.UNIQUE_PLAYERS_SERIES, () -> graphs.line().lineGraph(
|
||||||
MutatorFunctions.toPoints(getUnsafe(AnalysisKeys.UNIQUE_PLAYERS_PER_DAY))
|
MutatorFunctions.toPoints(getUnsafe(AnalysisKeys.UNIQUE_PLAYERS_PER_DAY))).toHighChartsSeries()
|
||||||
).toHighChartsSeries()
|
|
||||||
);
|
);
|
||||||
putSupplier(AnalysisKeys.NEW_PLAYERS_SERIES, () -> new AbstractLineGraph(
|
putSupplier(AnalysisKeys.NEW_PLAYERS_SERIES, () -> graphs.line().lineGraph(
|
||||||
MutatorFunctions.toPoints(getUnsafe(AnalysisKeys.NEW_PLAYERS_PER_DAY))
|
MutatorFunctions.toPoints(getUnsafe(AnalysisKeys.NEW_PLAYERS_PER_DAY))).toHighChartsSeries()
|
||||||
).toHighChartsSeries()
|
|
||||||
);
|
);
|
||||||
|
|
||||||
Key<Integer> retentionDay = new Key<>(Integer.class, "RETENTION_DAY");
|
Key<Integer> retentionDay = new Key<>(Integer.class, "RETENTION_DAY");
|
||||||
// compareAndFindThoseLikelyToBeRetained can throw exception.
|
// compareAndFindThoseLikelyToBeRetained can throw exception.
|
||||||
putCachingSupplier(retentionDay, () -> getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).compareAndFindThoseLikelyToBeRetained(
|
putCachingSupplier(retentionDay, () -> getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).compareAndFindThoseLikelyToBeRetained(
|
||||||
getUnsafe(newDay).all(), getUnsafe(AnalysisKeys.ANALYSIS_TIME_MONTH_AGO),
|
getUnsafe(newDay).all(), getUnsafe(AnalysisKeys.ANALYSIS_TIME_MONTH_AGO),
|
||||||
getUnsafe(AnalysisKeys.PLAYERS_ONLINE_RESOLVER)
|
getUnsafe(AnalysisKeys.PLAYERS_ONLINE_RESOLVER),
|
||||||
|
config.getNumber(Settings.ACTIVE_PLAY_THRESHOLD),
|
||||||
|
config.getNumber(Settings.ACTIVE_LOGIN_THRESHOLD)
|
||||||
).count()
|
).count()
|
||||||
);
|
);
|
||||||
putSupplier(AnalysisKeys.PLAYERS_RETAINED_DAY, () -> {
|
putSupplier(AnalysisKeys.PLAYERS_RETAINED_DAY, () -> {
|
||||||
@ -239,29 +260,31 @@ public class AnalysisContainer extends DataContainer {
|
|||||||
putSupplier(AnalysisKeys.PLAYERS_RETAINED_DAY_PERC, () -> {
|
putSupplier(AnalysisKeys.PLAYERS_RETAINED_DAY_PERC, () -> {
|
||||||
try {
|
try {
|
||||||
Integer playersNewDay = getUnsafe(AnalysisKeys.PLAYERS_NEW_DAY);
|
Integer playersNewDay = getUnsafe(AnalysisKeys.PLAYERS_NEW_DAY);
|
||||||
return playersNewDay != 0 ? Formatters.percentage().apply(1.0 * getUnsafe(retentionDay) / playersNewDay) : "-";
|
return playersNewDay != 0
|
||||||
|
? formatters.percentage().apply(1.0 * getUnsafe(retentionDay) / playersNewDay)
|
||||||
|
: "-";
|
||||||
} catch (IllegalStateException noPlayersAfterDateFiltering) {
|
} catch (IllegalStateException noPlayersAfterDateFiltering) {
|
||||||
return "Not enough data";
|
return "Not enough data";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
putSupplier(AnalysisKeys.PLAYERS_RETAINED_WEEK_PERC, () -> {
|
putSupplier(AnalysisKeys.PLAYERS_RETAINED_WEEK_PERC, () -> {
|
||||||
Integer playersNewWeek = getUnsafe(AnalysisKeys.PLAYERS_NEW_WEEK);
|
Integer playersNewWeek = getUnsafe(AnalysisKeys.PLAYERS_NEW_WEEK);
|
||||||
return playersNewWeek != 0 ? Formatters.percentage().apply(
|
return playersNewWeek != 0 ? formatters.percentage().apply(1.0 * getUnsafe(AnalysisKeys.PLAYERS_RETAINED_WEEK) / playersNewWeek) : "-";
|
||||||
1.0 * getUnsafe(AnalysisKeys.PLAYERS_RETAINED_WEEK) / playersNewWeek) : "-";
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
putSupplier(AnalysisKeys.PLAYERS_RETAINED_MONTH_PERC, () -> {
|
putSupplier(AnalysisKeys.PLAYERS_RETAINED_MONTH_PERC, () -> {
|
||||||
Integer playersNewMonth = getUnsafe(AnalysisKeys.PLAYERS_NEW_MONTH);
|
Integer playersNewMonth = getUnsafe(AnalysisKeys.PLAYERS_NEW_MONTH);
|
||||||
return playersNewMonth != 0 ? Formatters.percentage().apply(
|
return playersNewMonth != 0
|
||||||
1.0 * getUnsafe(AnalysisKeys.PLAYERS_RETAINED_MONTH) / playersNewMonth) : "-";
|
? formatters.percentage().apply(1.0 * getUnsafe(AnalysisKeys.PLAYERS_RETAINED_MONTH) / playersNewMonth)
|
||||||
|
: "-";
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addSessionSuppliers() {
|
private void addSessionSuppliers() {
|
||||||
Key<SessionAccordion> sessionAccordion = new Key<>(SessionAccordion.class, "SESSION_ACCORDION");
|
Key<SessionAccordion> sessionAccordion = new Key<>(SessionAccordion.class, "SESSION_ACCORDION");
|
||||||
putCachingSupplier(serverNames, () -> Database.getActive().fetch().getServerNames());
|
putCachingSupplier(serverNames, () -> database.fetch().getServerNames());
|
||||||
putCachingSupplier(sessionAccordion, () -> SessionAccordion.forServer(
|
putCachingSupplier(sessionAccordion, () -> accordions.serverSessionAccordion(
|
||||||
getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).all(),
|
getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).all(),
|
||||||
getSupplier(serverNames),
|
getSupplier(serverNames),
|
||||||
() -> getUnsafe(AnalysisKeys.PLAYER_NAMES)
|
() -> getUnsafe(AnalysisKeys.PLAYER_NAMES)
|
||||||
@ -270,32 +293,33 @@ public class AnalysisContainer extends DataContainer {
|
|||||||
putSupplier(AnalysisKeys.SESSION_ACCORDION_FUNCTIONS, () -> getUnsafe(sessionAccordion).toViewScript());
|
putSupplier(AnalysisKeys.SESSION_ACCORDION_FUNCTIONS, () -> getUnsafe(sessionAccordion).toViewScript());
|
||||||
|
|
||||||
putSupplier(AnalysisKeys.RECENT_LOGINS, () -> new RecentLoginList(
|
putSupplier(AnalysisKeys.RECENT_LOGINS, () -> new RecentLoginList(
|
||||||
serverContainer.getValue(ServerKeys.PLAYERS).orElse(new ArrayList<>())
|
serverContainer.getValue(ServerKeys.PLAYERS).orElse(new ArrayList<>()),
|
||||||
).toHtml()
|
formatters.secondLong()).toHtml()
|
||||||
);
|
);
|
||||||
putSupplier(AnalysisKeys.SESSION_TABLE, () -> new ServerSessionTable(
|
putSupplier(AnalysisKeys.SESSION_TABLE, () -> tables.serverSessionTable(
|
||||||
getUnsafe(AnalysisKeys.PLAYER_NAMES), getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).all()).parseHtml()
|
getUnsafe(AnalysisKeys.PLAYER_NAMES), getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).all()).parseHtml()
|
||||||
);
|
);
|
||||||
|
|
||||||
putSupplier(AnalysisKeys.AVERAGE_SESSION_LENGTH_F, () -> Formatters.timeAmount()
|
putSupplier(AnalysisKeys.AVERAGE_SESSION_LENGTH_F,
|
||||||
.apply(getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toAverageSessionLength())
|
() -> formatters.timeAmount().apply(getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toAverageSessionLength())
|
||||||
);
|
);
|
||||||
putSupplier(AnalysisKeys.SESSION_COUNT, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).count());
|
putSupplier(AnalysisKeys.SESSION_COUNT, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).count());
|
||||||
putSupplier(AnalysisKeys.PLAYTIME_TOTAL, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toPlaytime());
|
putSupplier(AnalysisKeys.PLAYTIME_TOTAL, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toPlaytime());
|
||||||
putSupplier(AnalysisKeys.DEATHS, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toDeathCount());
|
putSupplier(AnalysisKeys.DEATHS, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toDeathCount());
|
||||||
putSupplier(AnalysisKeys.MOB_KILL_COUNT, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toMobKillCount());
|
putSupplier(AnalysisKeys.MOB_KILL_COUNT, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toMobKillCount());
|
||||||
putSupplier(AnalysisKeys.PLAYER_KILL_COUNT, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toPlayerKillCount());
|
putSupplier(AnalysisKeys.PLAYER_KILL_COUNT, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toPlayerKillCount());
|
||||||
putSupplier(AnalysisKeys.PLAYTIME_F, () -> Formatters.timeAmount()
|
putSupplier(AnalysisKeys.PLAYTIME_F,
|
||||||
.apply(getUnsafe(AnalysisKeys.PLAYTIME_TOTAL))
|
() -> formatters.timeAmount().apply(getUnsafe(AnalysisKeys.PLAYTIME_TOTAL))
|
||||||
);
|
);
|
||||||
putSupplier(AnalysisKeys.AVERAGE_PLAYTIME_F, () -> {
|
putSupplier(AnalysisKeys.AVERAGE_PLAYTIME_F, () -> {
|
||||||
long players = getUnsafe(AnalysisKeys.PLAYERS_TOTAL);
|
long players = getUnsafe(AnalysisKeys.PLAYERS_TOTAL);
|
||||||
return players != 0 ? Formatters.timeAmount()
|
return players != 0
|
||||||
.apply(getUnsafe(AnalysisKeys.PLAYTIME_TOTAL) / players) : "-";
|
? formatters.timeAmount().apply(getUnsafe(AnalysisKeys.PLAYTIME_TOTAL) / players)
|
||||||
|
: "-";
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
putSupplier(AnalysisKeys.AVERAGE_SESSION_LENGTH_F, () -> Formatters.timeAmount()
|
putSupplier(AnalysisKeys.AVERAGE_SESSION_LENGTH_F,
|
||||||
.apply(getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toAverageSessionLength())
|
() -> formatters.timeAmount().apply(getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toAverageSessionLength())
|
||||||
);
|
);
|
||||||
|
|
||||||
Key<SessionsMutator> sessionsDay = new Key<>(SessionsMutator.class, "SESSIONS_DAY");
|
Key<SessionsMutator> sessionsDay = new Key<>(SessionsMutator.class, "SESSIONS_DAY");
|
||||||
@ -311,7 +335,7 @@ public class AnalysisContainer extends DataContainer {
|
|||||||
.filterSessionsBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_MONTH_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME))
|
.filterSessionsBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_MONTH_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME))
|
||||||
);
|
);
|
||||||
|
|
||||||
putSupplier(AnalysisKeys.PUNCHCARD_SERIES, () -> new PunchCardGraph(getUnsafe(sessionsMonth).all()).toHighChartsSeries());
|
putSupplier(AnalysisKeys.PUNCHCARD_SERIES, () -> graphs.special().punchCard(getUnsafe(sessionsMonth).all()).toHighChartsSeries());
|
||||||
putSupplier(AnalysisKeys.AVG_PLAYERS, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toAverageUniqueJoinsPerDay());
|
putSupplier(AnalysisKeys.AVG_PLAYERS, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toAverageUniqueJoinsPerDay());
|
||||||
putSupplier(AnalysisKeys.AVG_PLAYERS_DAY, () -> getUnsafe(sessionsDay).toAverageUniqueJoinsPerDay());
|
putSupplier(AnalysisKeys.AVG_PLAYERS_DAY, () -> getUnsafe(sessionsDay).toAverageUniqueJoinsPerDay());
|
||||||
putSupplier(AnalysisKeys.AVG_PLAYERS_WEEK, () -> getUnsafe(sessionsWeek).toAverageUniqueJoinsPerDay());
|
putSupplier(AnalysisKeys.AVG_PLAYERS_WEEK, () -> getUnsafe(sessionsWeek).toAverageUniqueJoinsPerDay());
|
||||||
@ -320,46 +344,48 @@ public class AnalysisContainer extends DataContainer {
|
|||||||
|
|
||||||
private void addGraphSuppliers() {
|
private void addGraphSuppliers() {
|
||||||
Key<WorldPie> worldPie = new Key<>(WorldPie.class, "WORLD_PIE");
|
Key<WorldPie> worldPie = new Key<>(WorldPie.class, "WORLD_PIE");
|
||||||
putCachingSupplier(worldPie, () -> new WorldPie(serverContainer.getValue(ServerKeys.WORLD_TIMES).orElse(new WorldTimes(new HashMap<>()))));
|
putCachingSupplier(worldPie, () -> graphs.pie().worldPie(
|
||||||
|
serverContainer.getValue(ServerKeys.WORLD_TIMES).orElse(new WorldTimes(new HashMap<>()))
|
||||||
|
));
|
||||||
putSupplier(AnalysisKeys.WORLD_PIE_SERIES, () -> getUnsafe(worldPie).toHighChartsSeries());
|
putSupplier(AnalysisKeys.WORLD_PIE_SERIES, () -> getUnsafe(worldPie).toHighChartsSeries());
|
||||||
putSupplier(AnalysisKeys.GM_PIE_SERIES, () -> getUnsafe(worldPie).toHighChartsDrilldown());
|
putSupplier(AnalysisKeys.GM_PIE_SERIES, () -> getUnsafe(worldPie).toHighChartsDrilldown());
|
||||||
putSupplier(AnalysisKeys.PLAYERS_ONLINE_SERIES, () ->
|
putSupplier(AnalysisKeys.PLAYERS_ONLINE_SERIES, () ->
|
||||||
new OnlineActivityGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries()
|
graphs.line().playersOnlineGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries()
|
||||||
);
|
);
|
||||||
putSupplier(AnalysisKeys.TPS_SERIES, () -> new TPSGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
putSupplier(AnalysisKeys.TPS_SERIES, () -> graphs.line().tpsGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
||||||
putSupplier(AnalysisKeys.CPU_SERIES, () -> new CPUGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
putSupplier(AnalysisKeys.CPU_SERIES, () -> graphs.line().cpuGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
||||||
putSupplier(AnalysisKeys.RAM_SERIES, () -> new RamGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
putSupplier(AnalysisKeys.RAM_SERIES, () -> graphs.line().ramGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
||||||
putSupplier(AnalysisKeys.ENTITY_SERIES, () -> new EntityGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
putSupplier(AnalysisKeys.ENTITY_SERIES, () -> graphs.line().entityGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
||||||
putSupplier(AnalysisKeys.CHUNK_SERIES, () -> new ChunkGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
putSupplier(AnalysisKeys.CHUNK_SERIES, () -> graphs.line().cpuGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
||||||
putSupplier(AnalysisKeys.WORLD_MAP_SERIES, () ->
|
putSupplier(AnalysisKeys.WORLD_MAP_SERIES, () ->
|
||||||
new WorldMap(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).getGeolocations()).toHighChartsSeries()
|
graphs.special().worldMap(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)).toHighChartsSeries()
|
||||||
);
|
);
|
||||||
Key<GeolocationBarGraph> geolocationBarChart = new Key<>(GeolocationBarGraph.class, "GEOLOCATION_BAR_CHART");
|
Key<BarGraph> geolocationBarChart = new Key<>(BarGraph.class, "GEOLOCATION_BAR_GRAPH");
|
||||||
putCachingSupplier(geolocationBarChart, () -> new GeolocationBarGraph(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)));
|
putCachingSupplier(geolocationBarChart, () -> graphs.bar().geolocationBarGraph(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)));
|
||||||
putSupplier(AnalysisKeys.COUNTRY_CATEGORIES, () -> getUnsafe(geolocationBarChart).toHighChartsCategories());
|
putSupplier(AnalysisKeys.COUNTRY_CATEGORIES, () -> getUnsafe(geolocationBarChart).toHighChartsCategories());
|
||||||
putSupplier(AnalysisKeys.COUNTRY_SERIES, () -> getUnsafe(geolocationBarChart).toHighChartsSeries());
|
putSupplier(AnalysisKeys.COUNTRY_SERIES, () -> getUnsafe(geolocationBarChart).toHighChartsSeries());
|
||||||
|
|
||||||
Key<PingGraph> pingGraph = new Key<>(PingGraph.class, "PING_GRAPH");
|
Key<PingGraph> pingGraph = new Key<>(PingGraph.class, "PING_GRAPH");
|
||||||
putCachingSupplier(pingGraph, () -> new PingGraph(
|
putCachingSupplier(pingGraph, () ->
|
||||||
PingMutator.forContainer(serverContainer).mutateToByMinutePings().all()
|
graphs.line().pingGraph(PingMutator.forContainer(serverContainer).mutateToByMinutePings().all())
|
||||||
));
|
);
|
||||||
putSupplier(AnalysisKeys.AVG_PING_SERIES, () -> getUnsafe(pingGraph).toAvgSeries());
|
putSupplier(AnalysisKeys.AVG_PING_SERIES, () -> getUnsafe(pingGraph).toAvgSeries());
|
||||||
putSupplier(AnalysisKeys.MAX_PING_SERIES, () -> getUnsafe(pingGraph).toMaxSeries());
|
putSupplier(AnalysisKeys.MAX_PING_SERIES, () -> getUnsafe(pingGraph).toMaxSeries());
|
||||||
putSupplier(AnalysisKeys.MIN_PING_SERIES, () -> getUnsafe(pingGraph).toMinSeries());
|
putSupplier(AnalysisKeys.MIN_PING_SERIES, () -> getUnsafe(pingGraph).toMinSeries());
|
||||||
|
|
||||||
putSupplier(AnalysisKeys.CALENDAR_SERIES, () -> new ServerCalendar(
|
putSupplier(AnalysisKeys.CALENDAR_SERIES, () -> graphs.calendar().serverCalendar(
|
||||||
getUnsafe(AnalysisKeys.PLAYERS_MUTATOR),
|
getUnsafe(AnalysisKeys.PLAYERS_MUTATOR),
|
||||||
getUnsafe(AnalysisKeys.UNIQUE_PLAYERS_PER_DAY),
|
getUnsafe(AnalysisKeys.UNIQUE_PLAYERS_PER_DAY),
|
||||||
getUnsafe(AnalysisKeys.NEW_PLAYERS_PER_DAY)
|
getUnsafe(AnalysisKeys.NEW_PLAYERS_PER_DAY)
|
||||||
).toCalendarSeries());
|
).toCalendarSeries());
|
||||||
|
|
||||||
putCachingSupplier(AnalysisKeys.ACTIVITY_DATA, () -> getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).toActivityDataMap(getUnsafe(AnalysisKeys.ANALYSIS_TIME)));
|
putCachingSupplier(AnalysisKeys.ACTIVITY_DATA, () -> getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).toActivityDataMap(getUnsafe(AnalysisKeys.ANALYSIS_TIME), config.getNumber(Settings.ACTIVE_PLAY_THRESHOLD), config.getNumber(Settings.ACTIVE_LOGIN_THRESHOLD)));
|
||||||
Key<ActivityStackGraph> activityStackGraph = new Key<>(ActivityStackGraph.class, "ACTIVITY_STACK_GRAPH");
|
Key<StackGraph> activityStackGraph = new Key<>(StackGraph.class, "ACTIVITY_STACK_GRAPH");
|
||||||
putCachingSupplier(activityStackGraph, () -> new ActivityStackGraph(getUnsafe(AnalysisKeys.ACTIVITY_DATA)));
|
putCachingSupplier(activityStackGraph, () -> graphs.stack().activityStackGraph(getUnsafe(AnalysisKeys.ACTIVITY_DATA)));
|
||||||
putSupplier(AnalysisKeys.ACTIVITY_STACK_CATEGORIES, () -> getUnsafe(activityStackGraph).toHighChartsLabels());
|
putSupplier(AnalysisKeys.ACTIVITY_STACK_CATEGORIES, () -> getUnsafe(activityStackGraph).toHighChartsLabels());
|
||||||
putSupplier(AnalysisKeys.ACTIVITY_STACK_SERIES, () -> getUnsafe(activityStackGraph).toHighChartsSeries());
|
putSupplier(AnalysisKeys.ACTIVITY_STACK_SERIES, () -> getUnsafe(activityStackGraph).toHighChartsSeries());
|
||||||
putSupplier(AnalysisKeys.ACTIVITY_PIE_SERIES, () ->
|
putSupplier(AnalysisKeys.ACTIVITY_PIE_SERIES, () -> graphs.pie().activityPie(
|
||||||
new ActivityPie(getUnsafe(AnalysisKeys.ACTIVITY_DATA).get(getUnsafe(AnalysisKeys.ANALYSIS_TIME))).toHighChartsSeries()
|
getUnsafe(AnalysisKeys.ACTIVITY_DATA).get(getUnsafe(AnalysisKeys.ANALYSIS_TIME))).toHighChartsSeries()
|
||||||
);
|
);
|
||||||
putSupplier(AnalysisKeys.PLAYERS_REGULAR, () -> {
|
putSupplier(AnalysisKeys.PLAYERS_REGULAR, () -> {
|
||||||
Map<String, Set<UUID>> activityNow = getUnsafe(AnalysisKeys.ACTIVITY_DATA)
|
Map<String, Set<UUID>> activityNow = getUnsafe(AnalysisKeys.ACTIVITY_DATA)
|
||||||
@ -388,19 +414,21 @@ public class AnalysisContainer extends DataContainer {
|
|||||||
|
|
||||||
putCachingSupplier(AnalysisKeys.PLAYERS_ONLINE_RESOLVER, () -> new PlayersOnlineResolver(getUnsafe(AnalysisKeys.TPS_MUTATOR)));
|
putCachingSupplier(AnalysisKeys.PLAYERS_ONLINE_RESOLVER, () -> new PlayersOnlineResolver(getUnsafe(AnalysisKeys.TPS_MUTATOR)));
|
||||||
|
|
||||||
putSupplier(AnalysisKeys.TPS_SPIKE_MONTH, () -> getUnsafe(tpsMonth).lowTpsSpikeCount());
|
int threshold = config.getNumber(Settings.THEME_GRAPH_TPS_THRESHOLD_MED);
|
||||||
|
|
||||||
|
putSupplier(AnalysisKeys.TPS_SPIKE_MONTH, () -> getUnsafe(tpsMonth).lowTpsSpikeCount(threshold));
|
||||||
putSupplier(AnalysisKeys.AVG_TPS_MONTH, () -> getUnsafe(tpsMonth).averageTPS());
|
putSupplier(AnalysisKeys.AVG_TPS_MONTH, () -> getUnsafe(tpsMonth).averageTPS());
|
||||||
putSupplier(AnalysisKeys.AVG_CPU_MONTH, () -> getUnsafe(tpsMonth).averageCPU());
|
putSupplier(AnalysisKeys.AVG_CPU_MONTH, () -> getUnsafe(tpsMonth).averageCPU());
|
||||||
putSupplier(AnalysisKeys.AVG_RAM_MONTH, () -> getUnsafe(tpsMonth).averageRAM());
|
putSupplier(AnalysisKeys.AVG_RAM_MONTH, () -> getUnsafe(tpsMonth).averageRAM());
|
||||||
putSupplier(AnalysisKeys.AVG_ENTITY_MONTH, () -> getUnsafe(tpsMonth).averageEntities());
|
putSupplier(AnalysisKeys.AVG_ENTITY_MONTH, () -> getUnsafe(tpsMonth).averageEntities());
|
||||||
putSupplier(AnalysisKeys.AVG_CHUNK_MONTH, () -> getUnsafe(tpsMonth).averageChunks());
|
putSupplier(AnalysisKeys.AVG_CHUNK_MONTH, () -> getUnsafe(tpsMonth).averageChunks());
|
||||||
putSupplier(AnalysisKeys.TPS_SPIKE_WEEK, () -> getUnsafe(tpsWeek).lowTpsSpikeCount());
|
putSupplier(AnalysisKeys.TPS_SPIKE_WEEK, () -> getUnsafe(tpsWeek).lowTpsSpikeCount(threshold));
|
||||||
putSupplier(AnalysisKeys.AVG_TPS_WEEK, () -> getUnsafe(tpsWeek).averageTPS());
|
putSupplier(AnalysisKeys.AVG_TPS_WEEK, () -> getUnsafe(tpsWeek).averageTPS());
|
||||||
putSupplier(AnalysisKeys.AVG_CPU_WEEK, () -> getUnsafe(tpsWeek).averageCPU());
|
putSupplier(AnalysisKeys.AVG_CPU_WEEK, () -> getUnsafe(tpsWeek).averageCPU());
|
||||||
putSupplier(AnalysisKeys.AVG_RAM_WEEK, () -> getUnsafe(tpsWeek).averageRAM());
|
putSupplier(AnalysisKeys.AVG_RAM_WEEK, () -> getUnsafe(tpsWeek).averageRAM());
|
||||||
putSupplier(AnalysisKeys.AVG_ENTITY_WEEK, () -> getUnsafe(tpsWeek).averageEntities());
|
putSupplier(AnalysisKeys.AVG_ENTITY_WEEK, () -> getUnsafe(tpsWeek).averageEntities());
|
||||||
putSupplier(AnalysisKeys.AVG_CHUNK_WEEK, () -> getUnsafe(tpsWeek).averageChunks());
|
putSupplier(AnalysisKeys.AVG_CHUNK_WEEK, () -> getUnsafe(tpsWeek).averageChunks());
|
||||||
putSupplier(AnalysisKeys.TPS_SPIKE_DAY, () -> getUnsafe(tpsDay).lowTpsSpikeCount());
|
putSupplier(AnalysisKeys.TPS_SPIKE_DAY, () -> getUnsafe(tpsDay).lowTpsSpikeCount(threshold));
|
||||||
putSupplier(AnalysisKeys.AVG_TPS_DAY, () -> getUnsafe(tpsDay).averageTPS());
|
putSupplier(AnalysisKeys.AVG_TPS_DAY, () -> getUnsafe(tpsDay).averageTPS());
|
||||||
putSupplier(AnalysisKeys.AVG_CPU_DAY, () -> getUnsafe(tpsDay).averageCPU());
|
putSupplier(AnalysisKeys.AVG_CPU_DAY, () -> getUnsafe(tpsDay).averageCPU());
|
||||||
putSupplier(AnalysisKeys.AVG_RAM_DAY, () -> getUnsafe(tpsDay).averageRAM());
|
putSupplier(AnalysisKeys.AVG_RAM_DAY, () -> getUnsafe(tpsDay).averageRAM());
|
||||||
@ -409,14 +437,20 @@ public class AnalysisContainer extends DataContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addCommandSuppliers() {
|
private void addCommandSuppliers() {
|
||||||
putSupplier(AnalysisKeys.COMMAND_USAGE_TABLE, () -> new CommandUseTable(serverContainer).parseHtml());
|
putSupplier(AnalysisKeys.COMMAND_USAGE_TABLE, () -> tables.commandUseTable(serverContainer).parseHtml());
|
||||||
putSupplier(AnalysisKeys.COMMAND_COUNT_UNIQUE, () -> serverContainer.getValue(ServerKeys.COMMAND_USAGE).map(Map::size).orElse(0));
|
putSupplier(AnalysisKeys.COMMAND_COUNT_UNIQUE, () -> serverContainer.getValue(ServerKeys.COMMAND_USAGE).map(Map::size).orElse(0));
|
||||||
putSupplier(AnalysisKeys.COMMAND_COUNT, () -> CommandUseMutator.forContainer(serverContainer).commandUsageCount());
|
putSupplier(AnalysisKeys.COMMAND_COUNT, () -> CommandUseMutator.forContainer(serverContainer).commandUsageCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addServerHealth() {
|
private void addServerHealth() {
|
||||||
Key<HealthInformation> healthInformation = new Key<>(HealthInformation.class, "HEALTH_INFORMATION");
|
Key<HealthInformation> healthInformation = new Key<>(HealthInformation.class, "HEALTH_INFORMATION");
|
||||||
putCachingSupplier(healthInformation, () -> new HealthInformation(this));
|
putCachingSupplier(healthInformation, () -> new HealthInformation(
|
||||||
|
this,
|
||||||
|
config.getNumber(Settings.THEME_GRAPH_TPS_THRESHOLD_MED),
|
||||||
|
config.getNumber(Settings.ACTIVE_PLAY_THRESHOLD),
|
||||||
|
config.getNumber(Settings.ACTIVE_LOGIN_THRESHOLD),
|
||||||
|
formatters.timeAmount(), formatters.decimals(), formatters.percentage()
|
||||||
|
));
|
||||||
putSupplier(AnalysisKeys.HEALTH_INDEX, () -> getUnsafe(healthInformation).getServerHealth());
|
putSupplier(AnalysisKeys.HEALTH_INDEX, () -> getUnsafe(healthInformation).getServerHealth());
|
||||||
putSupplier(AnalysisKeys.HEALTH_NOTES, () -> getUnsafe(healthInformation).toHtml());
|
putSupplier(AnalysisKeys.HEALTH_NOTES, () -> getUnsafe(healthInformation).toHtml());
|
||||||
}
|
}
|
||||||
@ -424,14 +458,66 @@ public class AnalysisContainer extends DataContainer {
|
|||||||
private void addPluginSuppliers() {
|
private void addPluginSuppliers() {
|
||||||
// TODO Refactor into a system that supports running the analysis on Bungee
|
// TODO Refactor into a system that supports running the analysis on Bungee
|
||||||
Key<String[]> navAndTabs = new Key<>(new Type<String[]>() {}, "NAV_AND_TABS");
|
Key<String[]> navAndTabs = new Key<>(new Type<String[]>() {}, "NAV_AND_TABS");
|
||||||
putCachingSupplier(navAndTabs, () ->
|
putCachingSupplier(navAndTabs, () -> pluginsTabContentCreator.createContent(
|
||||||
AnalysisPluginsTabContentCreator.createContent(
|
this, getValue(AnalysisKeys.PLAYERS_MUTATOR).orElse(new PlayersMutator(new ArrayList<>()))
|
||||||
getUnsafe(AnalysisKeys.PLAYERS_MUTATOR),
|
));
|
||||||
this
|
|
||||||
)
|
|
||||||
);
|
|
||||||
putCachingSupplier(AnalysisKeys.BAN_DATA, () -> new ServerBanDataReader().readBanDataForContainer(this));
|
|
||||||
putSupplier(AnalysisKeys.PLUGINS_TAB_NAV, () -> getUnsafe(navAndTabs)[0]);
|
putSupplier(AnalysisKeys.PLUGINS_TAB_NAV, () -> getUnsafe(navAndTabs)[0]);
|
||||||
putSupplier(AnalysisKeys.PLUGINS_TAB, () -> getUnsafe(navAndTabs)[1]);
|
putSupplier(AnalysisKeys.PLUGINS_TAB, () -> getUnsafe(navAndTabs)[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public static class Factory {
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public Factory(
|
||||||
|
@Named("currentVersion") String version,
|
||||||
|
PlanConfig config,
|
||||||
|
Theme theme,
|
||||||
|
Database database,
|
||||||
|
ServerProperties serverProperties,
|
||||||
|
Formatters formatters,
|
||||||
|
Graphs graphs,
|
||||||
|
HtmlTables tables,
|
||||||
|
Accordions accordions,
|
||||||
|
AnalysisPluginsTabContentCreator pluginsTabContentCreator
|
||||||
|
) {
|
||||||
|
this.version = version;
|
||||||
|
this.config = config;
|
||||||
|
this.theme = theme;
|
||||||
|
this.database = database;
|
||||||
|
this.serverProperties = serverProperties;
|
||||||
|
this.formatters = formatters;
|
||||||
|
this.graphs = graphs;
|
||||||
|
this.tables = tables;
|
||||||
|
this.accordions = accordions;
|
||||||
|
this.pluginsTabContentCreator = pluginsTabContentCreator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AnalysisContainer forServerContainer(ServerContainer serverContainer) {
|
||||||
|
return new AnalysisContainer(
|
||||||
|
serverContainer,
|
||||||
|
version,
|
||||||
|
config,
|
||||||
|
theme,
|
||||||
|
database,
|
||||||
|
serverProperties,
|
||||||
|
formatters,
|
||||||
|
graphs,
|
||||||
|
tables,
|
||||||
|
accordions,
|
||||||
|
pluginsTabContentCreator
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -2,12 +2,12 @@ package com.djrapitops.plan.data.store.containers;
|
|||||||
|
|
||||||
import com.djrapitops.plan.data.store.CachingSupplier;
|
import com.djrapitops.plan.data.store.CachingSupplier;
|
||||||
import com.djrapitops.plan.data.store.Key;
|
import com.djrapitops.plan.data.store.Key;
|
||||||
import com.djrapitops.plan.data.store.mutators.formatting.Formatter;
|
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||||
import com.djrapitops.plugin.api.TimeAmount;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,7 +24,7 @@ public class DataContainer {
|
|||||||
private long timeToLive;
|
private long timeToLive;
|
||||||
|
|
||||||
public DataContainer() {
|
public DataContainer() {
|
||||||
this(TimeAmount.SECOND.ms() * 30L);
|
this(TimeUnit.SECONDS.toMillis(30L));
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataContainer(long timeToLive) {
|
public DataContainer(long timeToLive) {
|
||||||
|
@ -1,33 +1,35 @@
|
|||||||
package com.djrapitops.plan.data.store.containers;
|
package com.djrapitops.plan.data.store.containers;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanPlugin;
|
import com.djrapitops.plan.data.container.TPS;
|
||||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
|
||||||
import com.djrapitops.plan.data.store.Key;
|
import com.djrapitops.plan.data.store.Key;
|
||||||
import com.djrapitops.plan.data.store.keys.NetworkKeys;
|
import com.djrapitops.plan.data.store.keys.NetworkKeys;
|
||||||
import com.djrapitops.plan.data.store.keys.ServerKeys;
|
import com.djrapitops.plan.data.store.keys.ServerKeys;
|
||||||
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
|
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
|
||||||
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
||||||
import com.djrapitops.plan.data.store.mutators.formatting.Formatters;
|
|
||||||
import com.djrapitops.plan.data.store.mutators.health.NetworkHealthInformation;
|
import com.djrapitops.plan.data.store.mutators.health.NetworkHealthInformation;
|
||||||
import com.djrapitops.plan.system.database.databases.Database;
|
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.Settings;
|
||||||
|
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||||
import com.djrapitops.plan.system.settings.theme.ThemeVal;
|
import com.djrapitops.plan.system.settings.theme.ThemeVal;
|
||||||
import com.djrapitops.plan.utilities.MiscUtils;
|
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||||
import com.djrapitops.plan.utilities.html.graphs.ActivityStackGraph;
|
import com.djrapitops.plan.utilities.html.graphs.Graphs;
|
||||||
import com.djrapitops.plan.utilities.html.graphs.WorldMap;
|
import com.djrapitops.plan.utilities.html.graphs.bar.BarGraph;
|
||||||
import com.djrapitops.plan.utilities.html.graphs.bar.GeolocationBarGraph;
|
import com.djrapitops.plan.utilities.html.graphs.stack.StackGraph;
|
||||||
import com.djrapitops.plan.utilities.html.graphs.line.OnlineActivityGraph;
|
import com.djrapitops.plan.utilities.html.structure.NetworkServerBox;
|
||||||
import com.djrapitops.plan.utilities.html.graphs.pie.ActivityPie;
|
|
||||||
import com.djrapitops.plugin.api.Check;
|
import com.djrapitops.plugin.api.Check;
|
||||||
import com.djrapitops.plugin.api.TimeAmount;
|
import com.djrapitops.plugin.api.TimeAmount;
|
||||||
import com.djrapitops.plugin.api.utility.log.Log;
|
import dagger.Lazy;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DataContainer for the whole network.
|
* DataContainer for the whole network.
|
||||||
@ -40,94 +42,122 @@ public class NetworkContainer extends DataContainer {
|
|||||||
|
|
||||||
private final ServerContainer bungeeContainer;
|
private final ServerContainer bungeeContainer;
|
||||||
|
|
||||||
private final Map<UUID, AnalysisContainer> serverContainers;
|
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;
|
||||||
|
|
||||||
public NetworkContainer(ServerContainer bungeeContainer) {
|
public NetworkContainer(
|
||||||
|
ServerContainer bungeeContainer,
|
||||||
|
String version,
|
||||||
|
PlanConfig config,
|
||||||
|
Theme theme,
|
||||||
|
Database database,
|
||||||
|
ServerProperties serverProperties,
|
||||||
|
Formatters formatters,
|
||||||
|
Graphs graphs
|
||||||
|
) {
|
||||||
this.bungeeContainer = bungeeContainer;
|
this.bungeeContainer = bungeeContainer;
|
||||||
serverContainers = new HashMap<>();
|
this.version = version;
|
||||||
|
this.config = config;
|
||||||
|
this.theme = theme;
|
||||||
|
this.database = database;
|
||||||
|
this.serverProperties = serverProperties;
|
||||||
|
this.formatters = formatters;
|
||||||
|
this.graphs = graphs;
|
||||||
|
|
||||||
putCachingSupplier(NetworkKeys.PLAYERS_MUTATOR, () -> PlayersMutator.forContainer(bungeeContainer));
|
putCachingSupplier(NetworkKeys.PLAYERS_MUTATOR, () -> PlayersMutator.forContainer(bungeeContainer));
|
||||||
|
|
||||||
addConstants();
|
addConstants();
|
||||||
|
addServerBoxes();
|
||||||
addPlayerInformation();
|
addPlayerInformation();
|
||||||
addNetworkHealth();
|
addNetworkHealth();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addServerBoxes() {
|
||||||
|
putSupplier(NetworkKeys.NETWORK_PLAYER_ONLINE_DATA, () -> database.fetch().getPlayersOnlineForServers(
|
||||||
|
getValue(NetworkKeys.BUKKIT_SERVERS).orElse(new ArrayList<>()))
|
||||||
|
);
|
||||||
|
putSupplier(NetworkKeys.SERVERS_TAB, () -> {
|
||||||
|
StringBuilder serverBoxes = new StringBuilder();
|
||||||
|
Map<Integer, List<TPS>> playersOnlineData = getValue(NetworkKeys.NETWORK_PLAYER_ONLINE_DATA).orElse(new HashMap<>());
|
||||||
|
getValue(NetworkKeys.BUKKIT_SERVERS).orElse(new ArrayList<>())
|
||||||
|
.stream()
|
||||||
|
.sorted((one, two) -> String.CASE_INSENSITIVE_ORDER.compare(one.getName(), two.getName()))
|
||||||
|
.forEach(server -> {
|
||||||
|
TPSMutator tpsMutator = new TPSMutator(playersOnlineData.getOrDefault(server.getId(), new ArrayList<>()));
|
||||||
|
// TODO Add Registered players per server.
|
||||||
|
NetworkServerBox serverBox = new NetworkServerBox(server, 0, tpsMutator, graphs);
|
||||||
|
serverBoxes.append(serverBox.toHtml());
|
||||||
|
});
|
||||||
|
return serverBoxes.toString();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void addNetworkHealth() {
|
private void addNetworkHealth() {
|
||||||
Key<NetworkHealthInformation> healthInformation = new Key<>(NetworkHealthInformation.class, "HEALTH_INFORMATION");
|
Key<NetworkHealthInformation> healthInformation = new Key<>(NetworkHealthInformation.class, "HEALTH_INFORMATION");
|
||||||
putCachingSupplier(healthInformation, () -> new NetworkHealthInformation(this));
|
putCachingSupplier(healthInformation, () -> new NetworkHealthInformation(
|
||||||
|
this,
|
||||||
|
config.getNumber(Settings.ACTIVE_PLAY_THRESHOLD),
|
||||||
|
config.getNumber(Settings.ACTIVE_LOGIN_THRESHOLD),
|
||||||
|
formatters.timeAmount(), formatters.decimals(), formatters.percentage()
|
||||||
|
));
|
||||||
putCachingSupplier(NetworkKeys.HEALTH_INDEX, () -> getUnsafe(healthInformation).getServerHealth());
|
putCachingSupplier(NetworkKeys.HEALTH_INDEX, () -> getUnsafe(healthInformation).getServerHealth());
|
||||||
putCachingSupplier(NetworkKeys.HEALTH_NOTES, () -> getUnsafe(healthInformation).toHtml());
|
putCachingSupplier(NetworkKeys.HEALTH_NOTES, () -> getUnsafe(healthInformation).toHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void putAnalysisContainer(AnalysisContainer analysisContainer) {
|
|
||||||
serverContainers.put(analysisContainer.getServerContainer().getUnsafe(ServerKeys.SERVER_UUID), analysisContainer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<AnalysisContainer> getAnalysisContainer(UUID serverUUID) {
|
|
||||||
AnalysisContainer container = serverContainers.get(serverUUID);
|
|
||||||
if (container != null) {
|
|
||||||
return Optional.of(container);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
AnalysisContainer analysisContainer = new AnalysisContainer(Database.getActive().fetch().getServerContainer(serverUUID));
|
|
||||||
serverContainers.put(serverUUID, analysisContainer);
|
|
||||||
return Optional.of(analysisContainer);
|
|
||||||
} catch (DBOpException e) {
|
|
||||||
Log.toLog(this.getClass(), e);
|
|
||||||
}
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addConstants() {
|
private void addConstants() {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
putRawData(NetworkKeys.REFRESH_TIME, now);
|
putRawData(NetworkKeys.REFRESH_TIME, now);
|
||||||
putRawData(NetworkKeys.REFRESH_TIME_DAY_AGO, getUnsafe(NetworkKeys.REFRESH_TIME) - TimeAmount.DAY.ms());
|
putRawData(NetworkKeys.REFRESH_TIME_DAY_AGO, getUnsafe(NetworkKeys.REFRESH_TIME) - TimeUnit.DAYS.toMillis(1L));
|
||||||
putRawData(NetworkKeys.REFRESH_TIME_WEEK_AGO, getUnsafe(NetworkKeys.REFRESH_TIME) - TimeAmount.WEEK.ms());
|
putRawData(NetworkKeys.REFRESH_TIME_WEEK_AGO, getUnsafe(NetworkKeys.REFRESH_TIME) - TimeAmount.WEEK.toMillis(1L));
|
||||||
putRawData(NetworkKeys.REFRESH_TIME_MONTH_AGO, getUnsafe(NetworkKeys.REFRESH_TIME) - TimeAmount.MONTH.ms());
|
putRawData(NetworkKeys.REFRESH_TIME_MONTH_AGO, getUnsafe(NetworkKeys.REFRESH_TIME) - TimeAmount.MONTH.toMillis(1L));
|
||||||
putSupplier(NetworkKeys.REFRESH_TIME_F, () -> Formatters.second().apply(() -> getUnsafe(NetworkKeys.REFRESH_TIME)));
|
putSupplier(NetworkKeys.REFRESH_TIME_F, () -> formatters.secondLong().apply(getUnsafe(NetworkKeys.REFRESH_TIME)));
|
||||||
|
|
||||||
putRawData(NetworkKeys.VERSION, PlanPlugin.getInstance().getVersion());
|
putRawData(NetworkKeys.VERSION, version);
|
||||||
putSupplier(NetworkKeys.TIME_ZONE, MiscUtils::getTimeZoneOffsetHours);
|
putSupplier(NetworkKeys.TIME_ZONE, config::getTimeZoneOffsetHours);
|
||||||
|
|
||||||
putCachingSupplier(NetworkKeys.NETWORK_NAME, () ->
|
putCachingSupplier(NetworkKeys.NETWORK_NAME, () ->
|
||||||
Check.isBungeeAvailable() ?
|
Check.isBungeeAvailable() ?
|
||||||
Settings.BUNGEE_NETWORK_NAME.toString() :
|
config.getString(Settings.BUNGEE_NETWORK_NAME) :
|
||||||
bungeeContainer.getValue(ServerKeys.NAME).orElse("Plan")
|
bungeeContainer.getValue(ServerKeys.NAME).orElse("Plan")
|
||||||
);
|
);
|
||||||
putSupplier(NetworkKeys.PLAYERS_ONLINE, ServerInfo.getServerProperties()::getOnlinePlayers);
|
putSupplier(NetworkKeys.PLAYERS_ONLINE, serverProperties::getOnlinePlayers);
|
||||||
putRawData(NetworkKeys.WORLD_MAP_LOW_COLOR, Theme.getValue(ThemeVal.WORLD_MAP_LOW));
|
putRawData(NetworkKeys.WORLD_MAP_LOW_COLOR, theme.getValue(ThemeVal.WORLD_MAP_LOW));
|
||||||
putRawData(NetworkKeys.WORLD_MAP_HIGH_COLOR, Theme.getValue(ThemeVal.WORLD_MAP_HIGH));
|
putRawData(NetworkKeys.WORLD_MAP_HIGH_COLOR, theme.getValue(ThemeVal.WORLD_MAP_HIGH));
|
||||||
putRawData(NetworkKeys.PLAYERS_GRAPH_COLOR, Theme.getValue(ThemeVal.GRAPH_PLAYERS_ONLINE));
|
putRawData(NetworkKeys.PLAYERS_GRAPH_COLOR, theme.getValue(ThemeVal.GRAPH_PLAYERS_ONLINE));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addPlayerInformation() {
|
private void addPlayerInformation() {
|
||||||
putSupplier(NetworkKeys.PLAYERS_TOTAL, () -> getUnsafe(NetworkKeys.PLAYERS_MUTATOR).count());
|
putSupplier(NetworkKeys.PLAYERS_TOTAL, () -> getUnsafe(NetworkKeys.PLAYERS_MUTATOR).count());
|
||||||
putSupplier(NetworkKeys.WORLD_MAP_SERIES, () ->
|
putSupplier(NetworkKeys.WORLD_MAP_SERIES, () ->
|
||||||
new WorldMap(PlayersMutator.forContainer(bungeeContainer)).toHighChartsSeries()
|
graphs.special().worldMap(PlayersMutator.forContainer(bungeeContainer)).toHighChartsSeries()
|
||||||
);
|
);
|
||||||
Key<GeolocationBarGraph> geolocationBarChart = new Key<>(GeolocationBarGraph.class, "GEOLOCATION_BAR_CHART");
|
Key<BarGraph> geolocationBarChart = new Key<>(BarGraph.class, "GEOLOCATION_BAR_GRAPH");
|
||||||
putSupplier(geolocationBarChart, () -> new GeolocationBarGraph(getUnsafe(NetworkKeys.PLAYERS_MUTATOR)));
|
putSupplier(geolocationBarChart, () -> graphs.bar().geolocationBarGraph(getUnsafe(NetworkKeys.PLAYERS_MUTATOR)));
|
||||||
putSupplier(NetworkKeys.COUNTRY_CATEGORIES, () -> getUnsafe(geolocationBarChart).toHighChartsCategories());
|
putSupplier(NetworkKeys.COUNTRY_CATEGORIES, () -> getUnsafe(geolocationBarChart).toHighChartsCategories());
|
||||||
putSupplier(NetworkKeys.COUNTRY_SERIES, () -> getUnsafe(geolocationBarChart).toHighChartsSeries());
|
putSupplier(NetworkKeys.COUNTRY_SERIES, () -> getUnsafe(geolocationBarChart).toHighChartsSeries());
|
||||||
|
|
||||||
putSupplier(NetworkKeys.PLAYERS_ONLINE_SERIES, () ->
|
putSupplier(NetworkKeys.PLAYERS_ONLINE_SERIES, () ->
|
||||||
new OnlineActivityGraph(TPSMutator.forContainer(bungeeContainer)).toHighChartsSeries()
|
graphs.line().playersOnlineGraph(TPSMutator.forContainer(bungeeContainer)).toHighChartsSeries()
|
||||||
);
|
);
|
||||||
Key<ActivityStackGraph> activityStackGraph = new Key<>(ActivityStackGraph.class, "ACTIVITY_STACK_GRAPH");
|
Key<StackGraph> activityStackGraph = new Key<>(StackGraph.class, "ACTIVITY_STACK_GRAPH");
|
||||||
putSupplier(NetworkKeys.ACTIVITY_DATA, () -> getUnsafe(NetworkKeys.PLAYERS_MUTATOR).toActivityDataMap(getUnsafe(NetworkKeys.REFRESH_TIME)));
|
putSupplier(NetworkKeys.ACTIVITY_DATA, () -> getUnsafe(NetworkKeys.PLAYERS_MUTATOR).toActivityDataMap(getUnsafe(NetworkKeys.REFRESH_TIME), config.getNumber(Settings.ACTIVE_PLAY_THRESHOLD), config.getNumber(Settings.ACTIVE_LOGIN_THRESHOLD)));
|
||||||
putSupplier(activityStackGraph, () -> new ActivityStackGraph(getUnsafe(NetworkKeys.ACTIVITY_DATA)));
|
putSupplier(activityStackGraph, () -> graphs.stack().activityStackGraph(getUnsafe(NetworkKeys.ACTIVITY_DATA)));
|
||||||
putSupplier(NetworkKeys.ACTIVITY_STACK_CATEGORIES, () -> getUnsafe(activityStackGraph).toHighChartsLabels());
|
putSupplier(NetworkKeys.ACTIVITY_STACK_CATEGORIES, () -> getUnsafe(activityStackGraph).toHighChartsLabels());
|
||||||
putSupplier(NetworkKeys.ACTIVITY_STACK_SERIES, () -> getUnsafe(activityStackGraph).toHighChartsSeries());
|
putSupplier(NetworkKeys.ACTIVITY_STACK_SERIES, () -> getUnsafe(activityStackGraph).toHighChartsSeries());
|
||||||
putSupplier(NetworkKeys.ACTIVITY_PIE_SERIES, () ->
|
putSupplier(NetworkKeys.ACTIVITY_PIE_SERIES, () -> graphs.pie().activityPie(
|
||||||
new ActivityPie(getUnsafe(NetworkKeys.ACTIVITY_DATA).get(getUnsafe(NetworkKeys.REFRESH_TIME))).toHighChartsSeries()
|
getUnsafe(NetworkKeys.ACTIVITY_DATA).get(getUnsafe(NetworkKeys.REFRESH_TIME))).toHighChartsSeries()
|
||||||
);
|
);
|
||||||
|
|
||||||
putSupplier(NetworkKeys.ALL_TIME_PEAK_TIME_F, () ->
|
putSupplier(NetworkKeys.ALL_TIME_PEAK_TIME_F, () ->
|
||||||
bungeeContainer.getValue(ServerKeys.ALL_TIME_PEAK_PLAYERS).map(Formatters.year()::apply).orElse("No data")
|
bungeeContainer.getValue(ServerKeys.ALL_TIME_PEAK_PLAYERS).map(formatters.year()).orElse("No data")
|
||||||
);
|
);
|
||||||
putSupplier(NetworkKeys.RECENT_PEAK_TIME_F, () ->
|
putSupplier(NetworkKeys.RECENT_PEAK_TIME_F, () ->
|
||||||
bungeeContainer.getValue(ServerKeys.RECENT_PEAK_PLAYERS).map(Formatters.year()::apply).orElse("No data")
|
bungeeContainer.getValue(ServerKeys.RECENT_PEAK_PLAYERS).map(formatters.year()).orElse("No data")
|
||||||
);
|
);
|
||||||
putSupplier(NetworkKeys.PLAYERS_ALL_TIME_PEAK, () ->
|
putSupplier(NetworkKeys.PLAYERS_ALL_TIME_PEAK, () ->
|
||||||
bungeeContainer.getValue(ServerKeys.ALL_TIME_PEAK_PLAYERS).map(dateObj -> "" + dateObj.getValue()).orElse("-")
|
bungeeContainer.getValue(ServerKeys.ALL_TIME_PEAK_PLAYERS).map(dateObj -> "" + dateObj.getValue()).orElse("-")
|
||||||
@ -176,4 +206,49 @@ public class NetworkContainer extends DataContainer {
|
|||||||
public ServerContainer getBungeeContainer() {
|
public ServerContainer getBungeeContainer() {
|
||||||
return bungeeContainer;
|
return bungeeContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public static class Factory {
|
||||||
|
|
||||||
|
private final Lazy<String> version;
|
||||||
|
private final Lazy<PlanConfig> config;
|
||||||
|
private final Lazy<Theme> theme;
|
||||||
|
private final Lazy<Database> database;
|
||||||
|
private final Lazy<ServerProperties> serverProperties;
|
||||||
|
private final Lazy<Formatters> formatters;
|
||||||
|
private final Lazy<Graphs> graphs;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public Factory(
|
||||||
|
@Named("currentVersion") Lazy<String> version,
|
||||||
|
Lazy<PlanConfig> config,
|
||||||
|
Lazy<Theme> theme,
|
||||||
|
Lazy<Database> database,
|
||||||
|
Lazy<ServerProperties> serverProperties,
|
||||||
|
Lazy<Formatters> formatters,
|
||||||
|
Lazy<Graphs> graphs
|
||||||
|
) {
|
||||||
|
this.version = version;
|
||||||
|
this.config = config;
|
||||||
|
this.theme = theme;
|
||||||
|
this.database = database;
|
||||||
|
this.serverProperties = serverProperties;
|
||||||
|
this.formatters = formatters;
|
||||||
|
this.graphs = graphs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NetworkContainer forBungeeContainer(ServerContainer bungeeContainer) {
|
||||||
|
return new NetworkContainer(
|
||||||
|
bungeeContainer,
|
||||||
|
version.get(),
|
||||||
|
config.get(),
|
||||||
|
theme.get(),
|
||||||
|
database.get(),
|
||||||
|
serverProperties.get(),
|
||||||
|
formatters.get(),
|
||||||
|
graphs.get()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -22,8 +22,8 @@ public class PlayerContainer extends DataContainer {
|
|||||||
activityIndexCache = new HashMap<>();
|
activityIndexCache = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActivityIndex getActivityIndex(long date) {
|
public ActivityIndex getActivityIndex(long date, int minuteThreshold, int loginThreshold) {
|
||||||
return activityIndexCache.computeIfAbsent(date, time -> new ActivityIndex(this, time));
|
return activityIndexCache.computeIfAbsent(date, time -> new ActivityIndex(this, time, minuteThreshold, loginThreshold));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean playedBetween(long after, long before) {
|
public boolean playedBetween(long after, long before) {
|
||||||
|
@ -151,6 +151,7 @@ public class AnalysisKeys {
|
|||||||
public static final Key<Long> ANALYSIS_TIME_MONTH_AGO = new Key<>(Long.class, "ANALYSIS_TIME_MONTH_AGO");
|
public static final Key<Long> ANALYSIS_TIME_MONTH_AGO = new Key<>(Long.class, "ANALYSIS_TIME_MONTH_AGO");
|
||||||
public static final Key<Map<UUID, String>> PLAYER_NAMES = new Key<>(new Type<Map<UUID, String>>() {}, "PLAYER_NAMES");
|
public static final Key<Map<UUID, String>> PLAYER_NAMES = new Key<>(new Type<Map<UUID, String>>() {}, "PLAYER_NAMES");
|
||||||
public static final Key<TreeMap<Long, Map<String, Set<UUID>>>> ACTIVITY_DATA = CommonKeys.ACTIVITY_DATA;
|
public static final Key<TreeMap<Long, Map<String, Set<UUID>>>> ACTIVITY_DATA = CommonKeys.ACTIVITY_DATA;
|
||||||
|
@Deprecated
|
||||||
public static final Key<Set<UUID>> BAN_DATA = new Key<>(new Type<Set<UUID>>() {}, "BAN_DATA");
|
public static final Key<Set<UUID>> BAN_DATA = new Key<>(new Type<Set<UUID>>() {}, "BAN_DATA");
|
||||||
public static final Key<TreeMap<Long, Integer>> UNIQUE_PLAYERS_PER_DAY = new Key<>(new Type<TreeMap<Long, Integer>>() {}, "UNIQUE_PLAYERS_PER_DAY");
|
public static final Key<TreeMap<Long, Integer>> UNIQUE_PLAYERS_PER_DAY = new Key<>(new Type<TreeMap<Long, Integer>>() {}, "UNIQUE_PLAYERS_PER_DAY");
|
||||||
public static final Key<TreeMap<Long, Integer>> NEW_PLAYERS_PER_DAY = new Key<>(new Type<TreeMap<Long, Integer>>() {}, "NEW_PLAYERS_PER_DAY");
|
public static final Key<TreeMap<Long, Integer>> NEW_PLAYERS_PER_DAY = new Key<>(new Type<TreeMap<Long, Integer>>() {}, "NEW_PLAYERS_PER_DAY");
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.djrapitops.plan.data.store.keys;
|
package com.djrapitops.plan.data.store.keys;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.data.container.TPS;
|
||||||
import com.djrapitops.plan.data.store.Key;
|
import com.djrapitops.plan.data.store.Key;
|
||||||
import com.djrapitops.plan.data.store.PlaceholderKey;
|
import com.djrapitops.plan.data.store.PlaceholderKey;
|
||||||
import com.djrapitops.plan.data.store.Type;
|
import com.djrapitops.plan.data.store.Type;
|
||||||
@ -37,6 +38,7 @@ public class NetworkKeys {
|
|||||||
public static final PlaceholderKey<Integer> PLAYERS_NEW_WEEK = CommonPlaceholderKeys.PLAYERS_NEW_WEEK;
|
public static final PlaceholderKey<Integer> PLAYERS_NEW_WEEK = CommonPlaceholderKeys.PLAYERS_NEW_WEEK;
|
||||||
public static final PlaceholderKey<Integer> PLAYERS_NEW_MONTH = CommonPlaceholderKeys.PLAYERS_NEW_MONTH;
|
public static final PlaceholderKey<Integer> PLAYERS_NEW_MONTH = CommonPlaceholderKeys.PLAYERS_NEW_MONTH;
|
||||||
|
|
||||||
|
public static final PlaceholderKey<String> SERVERS_TAB = new PlaceholderKey<>(String.class, "tabContentServers");
|
||||||
public static final PlaceholderKey<String> WORLD_MAP_SERIES = CommonPlaceholderKeys.WORLD_MAP_SERIES;
|
public static final PlaceholderKey<String> WORLD_MAP_SERIES = CommonPlaceholderKeys.WORLD_MAP_SERIES;
|
||||||
public static final PlaceholderKey<String> PLAYERS_ONLINE_SERIES = CommonPlaceholderKeys.PLAYERS_ONLINE_SERIES;
|
public static final PlaceholderKey<String> PLAYERS_ONLINE_SERIES = CommonPlaceholderKeys.PLAYERS_ONLINE_SERIES;
|
||||||
public static final PlaceholderKey<String> ACTIVITY_STACK_SERIES = CommonPlaceholderKeys.ACTIVITY_STACK_SERIES;
|
public static final PlaceholderKey<String> ACTIVITY_STACK_SERIES = CommonPlaceholderKeys.ACTIVITY_STACK_SERIES;
|
||||||
@ -55,6 +57,7 @@ public class NetworkKeys {
|
|||||||
|
|
||||||
public static final Key<Collection<Server>> BUKKIT_SERVERS = new Key<>(new Type<Collection<Server>>() {}, "BUKKIT_SERVERS");
|
public static final Key<Collection<Server>> BUKKIT_SERVERS = new Key<>(new Type<Collection<Server>>() {}, "BUKKIT_SERVERS");
|
||||||
public static final Key<TreeMap<Long, Map<String, Set<UUID>>>> ACTIVITY_DATA = CommonKeys.ACTIVITY_DATA;
|
public static final Key<TreeMap<Long, Map<String, Set<UUID>>>> ACTIVITY_DATA = CommonKeys.ACTIVITY_DATA;
|
||||||
|
public static final Key<Map<Integer, List<TPS>>> NETWORK_PLAYER_ONLINE_DATA = new Key<>(new Type<Map<Integer, List<TPS>>>() {}, "NETWORK_PLAYER_ONLINE_DATA");
|
||||||
|
|
||||||
private NetworkKeys() {
|
private NetworkKeys() {
|
||||||
/* static variable class */
|
/* static variable class */
|
||||||
|
@ -32,6 +32,7 @@ public class SessionKeys {
|
|||||||
public static final Key<Integer> DEATH_COUNT = CommonKeys.DEATH_COUNT;
|
public static final Key<Integer> DEATH_COUNT = CommonKeys.DEATH_COUNT;
|
||||||
public static final Key<List<PlayerDeath>> PLAYER_DEATHS = CommonKeys.PLAYER_DEATHS;
|
public static final Key<List<PlayerDeath>> PLAYER_DEATHS = CommonKeys.PLAYER_DEATHS;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public static final Key<String> LONGEST_WORLD_PLAYED = new Key<>(String.class, "longest_world_played");
|
public static final Key<String> LONGEST_WORLD_PLAYED = new Key<>(String.class, "longest_world_played");
|
||||||
|
|
||||||
private SessionKeys() {
|
private SessionKeys() {
|
||||||
|
@ -3,18 +3,27 @@ package com.djrapitops.plan.data.store.mutators;
|
|||||||
import com.djrapitops.plan.data.container.Session;
|
import com.djrapitops.plan.data.container.Session;
|
||||||
import com.djrapitops.plan.data.store.containers.DataContainer;
|
import com.djrapitops.plan.data.store.containers.DataContainer;
|
||||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
||||||
import com.djrapitops.plan.system.settings.Settings;
|
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||||
import com.djrapitops.plan.utilities.FormatUtils;
|
|
||||||
import com.djrapitops.plugin.api.TimeAmount;
|
import com.djrapitops.plugin.api.TimeAmount;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class ActivityIndex {
|
public class ActivityIndex {
|
||||||
|
|
||||||
private final double value;
|
private final double value;
|
||||||
|
|
||||||
public ActivityIndex(DataContainer container, long date) {
|
private final int playThreshold;
|
||||||
|
private final int loginThreshold;
|
||||||
|
|
||||||
|
public ActivityIndex(
|
||||||
|
DataContainer container, long date,
|
||||||
|
int minuteThreshold, int loginThreshold
|
||||||
|
) {
|
||||||
|
this.playThreshold = minuteThreshold;
|
||||||
|
this.loginThreshold = loginThreshold;
|
||||||
|
|
||||||
value = calculate(container, date);
|
value = calculate(container, date);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,22 +31,14 @@ public class ActivityIndex {
|
|||||||
return new String[]{"Very Active", "Active", "Regular", "Irregular", "Inactive"};
|
return new String[]{"Very Active", "Active", "Regular", "Irregular", "Inactive"};
|
||||||
}
|
}
|
||||||
|
|
||||||
private long loadSetting(long value) {
|
|
||||||
return value <= 0 ? 1 : value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int loadSetting(int value) {
|
|
||||||
return value <= 0 ? 1 : value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private double calculate(DataContainer container, long date) {
|
private double calculate(DataContainer container, long date) {
|
||||||
long week = TimeAmount.WEEK.ms();
|
long week = TimeAmount.WEEK.toMillis(1L);
|
||||||
long weekAgo = date - week;
|
long weekAgo = date - week;
|
||||||
long twoWeeksAgo = date - 2L * week;
|
long twoWeeksAgo = date - 2L * week;
|
||||||
long threeWeeksAgo = date - 3L * week;
|
long threeWeeksAgo = date - 3L * week;
|
||||||
|
|
||||||
long activePlayThreshold = loadSetting(Settings.ACTIVE_PLAY_THRESHOLD.getNumber() * TimeAmount.MINUTE.ms());
|
long activePlayThreshold = TimeUnit.MINUTES.toMillis(playThreshold);
|
||||||
int activeLoginThreshold = loadSetting(Settings.ACTIVE_LOGIN_THRESHOLD.getNumber());
|
int activeLoginThreshold = loginThreshold;
|
||||||
|
|
||||||
Optional<List<Session>> sessionsValue = container.getValue(PlayerKeys.SESSIONS);
|
Optional<List<Session>> sessionsValue = container.getValue(PlayerKeys.SESSIONS);
|
||||||
if (!sessionsValue.isPresent()) {
|
if (!sessionsValue.isPresent()) {
|
||||||
@ -109,8 +110,8 @@ public class ActivityIndex {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFormattedValue() {
|
public String getFormattedValue(Formatter<Double> formatter) {
|
||||||
return FormatUtils.cutDecimals(value);
|
return formatter.apply(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getGroup() {
|
public String getGroup() {
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package com.djrapitops.plan.data.store.mutators;
|
package com.djrapitops.plan.data.store.mutators;
|
||||||
|
|
||||||
import com.djrapitops.plan.data.store.objects.DateHolder;
|
import com.djrapitops.plan.data.store.objects.DateHolder;
|
||||||
import com.djrapitops.plugin.api.TimeAmount;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class DateHoldersMutator<T extends DateHolder> {
|
public class DateHoldersMutator<T extends DateHolder> {
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ public class DateHoldersMutator<T extends DateHolder> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SortedMap<Long, List<T>> groupByStartOfMinute() {
|
public SortedMap<Long, List<T>> groupByStartOfMinute() {
|
||||||
return groupByStartOfSections(TimeAmount.MINUTE.ms());
|
return groupByStartOfSections(TimeUnit.MINUTES.toMillis(1L));
|
||||||
}
|
}
|
||||||
|
|
||||||
private SortedMap<Long, List<T>> groupByStartOfSections(long sectionLength) {
|
private SortedMap<Long, List<T>> groupByStartOfSections(long sectionLength) {
|
||||||
@ -39,7 +39,7 @@ public class DateHoldersMutator<T extends DateHolder> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SortedMap<Long, List<T>> groupByStartOfDay() {
|
public SortedMap<Long, List<T>> groupByStartOfDay() {
|
||||||
long twentyFourHours = 24L * TimeAmount.HOUR.ms();
|
long twentyFourHours = TimeUnit.DAYS.toMillis(1L);
|
||||||
SortedMap<Long, List<T>> map = groupByStartOfSections(twentyFourHours);
|
SortedMap<Long, List<T>> map = groupByStartOfSections(twentyFourHours);
|
||||||
|
|
||||||
// Empty map firstKey attempt causes NPE if not checked.
|
// Empty map firstKey attempt causes NPE if not checked.
|
||||||
|
@ -70,8 +70,8 @@ public class PlayersMutator {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayersMutator filterActive(long date, double limit) {
|
public PlayersMutator filterActive(long date, int minuteThreshold, int loginThreshold, double limit) {
|
||||||
return filterBy(player -> player.getActivityIndex(date).getValue() >= limit);
|
return filterBy(player -> player.getActivityIndex(date, minuteThreshold, loginThreshold).getValue() >= limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayersMutator filterPlayedOnServer(UUID serverUUID) {
|
public PlayersMutator filterPlayedOnServer(UUID serverUUID) {
|
||||||
@ -123,16 +123,16 @@ public class PlayersMutator {
|
|||||||
return pingPerCountry;
|
return pingPerCountry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TreeMap<Long, Map<String, Set<UUID>>> toActivityDataMap(long date) {
|
public TreeMap<Long, Map<String, Set<UUID>>> toActivityDataMap(long date, int minuteThreshold, int loginThreshold) {
|
||||||
TreeMap<Long, Map<String, Set<UUID>>> activityData = new TreeMap<>();
|
TreeMap<Long, Map<String, Set<UUID>>> activityData = new TreeMap<>();
|
||||||
for (long time = date; time >= date - TimeAmount.MONTH.ms() * 2L; time -= TimeAmount.WEEK.ms()) {
|
for (long time = date; time >= date - TimeAmount.MONTH.toMillis(2L); time -= TimeAmount.WEEK.toMillis(1L)) {
|
||||||
Map<String, Set<UUID>> map = activityData.getOrDefault(time, new HashMap<>());
|
Map<String, Set<UUID>> map = activityData.getOrDefault(time, new HashMap<>());
|
||||||
if (!players.isEmpty()) {
|
if (!players.isEmpty()) {
|
||||||
for (PlayerContainer player : players) {
|
for (PlayerContainer player : players) {
|
||||||
if (player.getValue(PlayerKeys.REGISTERED).orElse(0L) > time) {
|
if (player.getValue(PlayerKeys.REGISTERED).orElse(0L) > time) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ActivityIndex activityIndex = player.getActivityIndex(time);
|
ActivityIndex activityIndex = player.getActivityIndex(time, minuteThreshold, loginThreshold);
|
||||||
String activityGroup = activityIndex.getGroup();
|
String activityGroup = activityIndex.getGroup();
|
||||||
|
|
||||||
Set<UUID> uuids = map.getOrDefault(activityGroup, new HashSet<>());
|
Set<UUID> uuids = map.getOrDefault(activityGroup, new HashSet<>());
|
||||||
@ -175,9 +175,13 @@ public class PlayersMutator {
|
|||||||
* @return Mutator containing the players that are considered to be retained.
|
* @return Mutator containing the players that are considered to be retained.
|
||||||
* @throws IllegalStateException If all players are rejected due to dateLimit.
|
* @throws IllegalStateException If all players are rejected due to dateLimit.
|
||||||
*/
|
*/
|
||||||
public PlayersMutator compareAndFindThoseLikelyToBeRetained(Iterable<PlayerContainer> compareTo,
|
public PlayersMutator compareAndFindThoseLikelyToBeRetained(
|
||||||
long dateLimit,
|
Iterable<PlayerContainer> compareTo,
|
||||||
PlayersOnlineResolver onlineResolver) {
|
long dateLimit,
|
||||||
|
PlayersOnlineResolver onlineResolver,
|
||||||
|
int activityMinuteThreshold,
|
||||||
|
int activityLoginThreshold
|
||||||
|
) {
|
||||||
Collection<PlayerContainer> retainedAfterMonth = new ArrayList<>();
|
Collection<PlayerContainer> retainedAfterMonth = new ArrayList<>();
|
||||||
Collection<PlayerContainer> notRetainedAfterMonth = new ArrayList<>();
|
Collection<PlayerContainer> notRetainedAfterMonth = new ArrayList<>();
|
||||||
|
|
||||||
@ -189,8 +193,8 @@ public class PlayersMutator {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
long monthAfterRegister = registered + TimeAmount.MONTH.ms();
|
long monthAfterRegister = registered + TimeAmount.MONTH.toMillis(1L);
|
||||||
long half = registered + (TimeAmount.MONTH.ms() / 2L);
|
long half = registered + (TimeAmount.MONTH.toMillis(1L) / 2L);
|
||||||
if (player.playedBetween(registered, half) && player.playedBetween(half, monthAfterRegister)) {
|
if (player.playedBetween(registered, half) && player.playedBetween(half, monthAfterRegister)) {
|
||||||
retainedAfterMonth.add(player);
|
retainedAfterMonth.add(player);
|
||||||
} else {
|
} else {
|
||||||
@ -203,10 +207,10 @@ public class PlayersMutator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<RetentionData> retained = retainedAfterMonth.stream()
|
List<RetentionData> retained = retainedAfterMonth.stream()
|
||||||
.map(player -> new RetentionData(player, onlineResolver))
|
.map(player -> new RetentionData(player, onlineResolver, activityMinuteThreshold, activityLoginThreshold))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
List<RetentionData> notRetained = notRetainedAfterMonth.stream()
|
List<RetentionData> notRetained = notRetainedAfterMonth.stream()
|
||||||
.map(player -> new RetentionData(player, onlineResolver))
|
.map(player -> new RetentionData(player, onlineResolver, activityMinuteThreshold, activityLoginThreshold))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
RetentionData avgRetained = RetentionData.average(retained);
|
RetentionData avgRetained = RetentionData.average(retained);
|
||||||
@ -214,7 +218,7 @@ public class PlayersMutator {
|
|||||||
|
|
||||||
List<PlayerContainer> toBeRetained = new ArrayList<>();
|
List<PlayerContainer> toBeRetained = new ArrayList<>();
|
||||||
for (PlayerContainer player : compareTo) {
|
for (PlayerContainer player : compareTo) {
|
||||||
RetentionData retentionData = new RetentionData(player, onlineResolver);
|
RetentionData retentionData = new RetentionData(player, onlineResolver, activityMinuteThreshold, activityLoginThreshold);
|
||||||
if (retentionData.distance(avgRetained) < retentionData.distance(avgNotRetained)) {
|
if (retentionData.distance(avgRetained) < retentionData.distance(avgNotRetained)) {
|
||||||
toBeRetained.add(player);
|
toBeRetained.add(player);
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,11 @@ package com.djrapitops.plan.data.store.mutators;
|
|||||||
|
|
||||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
||||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
||||||
import com.djrapitops.plugin.api.TimeAmount;
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class for player retention calculations.
|
* Utility class for player retention calculations.
|
||||||
@ -45,10 +45,20 @@ public class RetentionData {
|
|||||||
this.onlineOnJoin = onlineOnJoin;
|
this.onlineOnJoin = onlineOnJoin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RetentionData(PlayerContainer player, PlayersOnlineResolver onlineOnJoin) {
|
public RetentionData(
|
||||||
|
PlayerContainer player,
|
||||||
|
PlayersOnlineResolver onlineOnJoin,
|
||||||
|
int activityMinuteThreshold,
|
||||||
|
int activityLoginThreshold
|
||||||
|
) {
|
||||||
Optional<Long> registeredValue = player.getValue(PlayerKeys.REGISTERED);
|
Optional<Long> registeredValue = player.getValue(PlayerKeys.REGISTERED);
|
||||||
activityIndex = registeredValue
|
activityIndex = registeredValue
|
||||||
.map(registered -> new ActivityIndex(player, registered + TimeAmount.DAY.ms()).getValue())
|
.map(registered -> new ActivityIndex(
|
||||||
|
player,
|
||||||
|
registered + TimeUnit.DAYS.toMillis(1L),
|
||||||
|
activityMinuteThreshold,
|
||||||
|
activityLoginThreshold
|
||||||
|
).getValue())
|
||||||
.orElse(0.0);
|
.orElse(0.0);
|
||||||
this.onlineOnJoin = registeredValue
|
this.onlineOnJoin = registeredValue
|
||||||
.map(registered -> onlineOnJoin.getOnlineOn(registered).orElse(-1))
|
.map(registered -> onlineOnJoin.getOnlineOn(registered).orElse(-1))
|
||||||
|
@ -3,14 +3,13 @@ package com.djrapitops.plan.data.store.mutators;
|
|||||||
import com.djrapitops.plan.data.container.TPS;
|
import com.djrapitops.plan.data.container.TPS;
|
||||||
import com.djrapitops.plan.data.store.containers.DataContainer;
|
import com.djrapitops.plan.data.store.containers.DataContainer;
|
||||||
import com.djrapitops.plan.data.store.keys.ServerKeys;
|
import com.djrapitops.plan.data.store.keys.ServerKeys;
|
||||||
import com.djrapitops.plan.system.settings.Settings;
|
|
||||||
import com.djrapitops.plan.utilities.comparators.TPSComparator;
|
import com.djrapitops.plan.utilities.comparators.TPSComparator;
|
||||||
import com.djrapitops.plan.utilities.html.graphs.line.Point;
|
import com.djrapitops.plan.utilities.html.graphs.line.Point;
|
||||||
import com.djrapitops.plugin.api.TimeAmount;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.OptionalDouble;
|
import java.util.OptionalDouble;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -99,7 +98,7 @@ public class TPSMutator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
long diff = date - lastDate;
|
long diff = date - lastDate;
|
||||||
if (diff > TimeAmount.MINUTE.ms() * 3L) {
|
if (diff > TimeUnit.MINUTES.toMillis(3L)) {
|
||||||
downTime += diff;
|
downTime += diff;
|
||||||
}
|
}
|
||||||
lastDate = date;
|
lastDate = date;
|
||||||
@ -134,13 +133,11 @@ public class TPSMutator {
|
|||||||
return idleTime;
|
return idleTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double percentageTPSAboveLowThreshold() {
|
public double percentageTPSAboveThreshold(int threshold) {
|
||||||
if (tpsData.isEmpty()) {
|
if (tpsData.isEmpty()) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int threshold = Settings.THEME_GRAPH_TPS_THRESHOLD_MED.getNumber();
|
|
||||||
|
|
||||||
long count = 0;
|
long count = 0;
|
||||||
for (TPS tps : tpsData) {
|
for (TPS tps : tpsData) {
|
||||||
if (tps.getTicksPerSecond() >= threshold) {
|
if (tps.getTicksPerSecond() >= threshold) {
|
||||||
@ -151,15 +148,13 @@ public class TPSMutator {
|
|||||||
return count * 1.0 / tpsData.size();
|
return count * 1.0 / tpsData.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int lowTpsSpikeCount() {
|
public int lowTpsSpikeCount(int threshold) {
|
||||||
int mediumThreshold = Settings.THEME_GRAPH_TPS_THRESHOLD_MED.getNumber();
|
|
||||||
|
|
||||||
boolean wasLow = false;
|
boolean wasLow = false;
|
||||||
int spikeCount = 0;
|
int spikeCount = 0;
|
||||||
|
|
||||||
for (TPS tpsObj : tpsData) {
|
for (TPS tpsObj : tpsData) {
|
||||||
double tps = tpsObj.getTicksPerSecond();
|
double tps = tpsObj.getTicksPerSecond();
|
||||||
if (tps < mediumThreshold) {
|
if (tps < threshold) {
|
||||||
if (!wasLow) {
|
if (!wasLow) {
|
||||||
spikeCount++;
|
spikeCount++;
|
||||||
wasLow = true;
|
wasLow = true;
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
package com.djrapitops.plan.data.store.mutators.combiners;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.data.store.containers.DataContainer;
|
|
||||||
import com.djrapitops.plan.data.store.containers.PerServerContainer;
|
|
||||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
|
||||||
import com.djrapitops.plan.data.store.keys.PerServerKeys;
|
|
||||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
|
||||||
import com.djrapitops.plan.data.store.keys.ServerKeys;
|
|
||||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class MultiBanCombiner {
|
|
||||||
|
|
||||||
private final DataContainer container;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* @param container DataContainer that supports {@link com.djrapitops.plan.data.store.keys.ServerKeys}.PLAYERS
|
|
||||||
*/
|
|
||||||
public MultiBanCombiner(DataContainer container) {
|
|
||||||
this.container = container;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void combine(Set<UUID> banned) {
|
|
||||||
combine(Collections.singletonMap(ServerInfo.getServerUUID(), banned));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void combine(Map<UUID, Set<UUID>> perServerBanned) {
|
|
||||||
List<PlayerContainer> playerContainers = container.getValue(ServerKeys.PLAYERS).orElse(new ArrayList<>());
|
|
||||||
|
|
||||||
for (Map.Entry<UUID, Set<UUID>> entry : perServerBanned.entrySet()) {
|
|
||||||
UUID serverUUID = entry.getKey();
|
|
||||||
Set<UUID> banned = entry.getValue();
|
|
||||||
for (PlayerContainer player : playerContainers) {
|
|
||||||
if (player.getValue(PlayerKeys.UUID).map(banned::contains).orElse(false)) {
|
|
||||||
PerServerContainer perServer = player.getValue(PlayerKeys.PER_SERVER)
|
|
||||||
.orElse(new PerServerContainer());
|
|
||||||
DataContainer perServerContainer = perServer.getOrDefault(serverUUID, new DataContainer());
|
|
||||||
|
|
||||||
perServerContainer.putRawData(PerServerKeys.BANNED, true);
|
|
||||||
|
|
||||||
perServer.put(serverUUID, perServerContainer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,94 +0,0 @@
|
|||||||
package com.djrapitops.plan.data.store.mutators.formatting;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.data.store.objects.DateHolder;
|
|
||||||
import com.djrapitops.plan.utilities.FormatUtils;
|
|
||||||
import com.djrapitops.plugin.api.TimeAmount;
|
|
||||||
import com.djrapitops.plugin.utilities.Format;
|
|
||||||
import org.apache.commons.text.TextStringBuilder;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class that holds static methods for getting new instances of different {@link Formatter}s.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
public class Formatters {
|
|
||||||
|
|
||||||
private Formatters() {
|
|
||||||
/* Static method class */
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Formatter<DateHolder> year() {
|
|
||||||
return dateHolder -> {
|
|
||||||
long date = dateHolder.getDate();
|
|
||||||
return date > 0 ? FormatUtils.formatTimeStampYear(date) : "-";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Formatter<Long> yearLongValue() {
|
|
||||||
return date -> date > 0 ? FormatUtils.formatTimeStampYear(date) : "-";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Formatter<DateHolder> day() {
|
|
||||||
return dateHolder -> {
|
|
||||||
long date = dateHolder.getDate();
|
|
||||||
return date > 0 ? FormatUtils.formatTimeStampDay(date) : "-";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Formatter<DateHolder> second() {
|
|
||||||
return dateHolder -> {
|
|
||||||
long date = dateHolder.getDate();
|
|
||||||
return date > 0 ? FormatUtils.formatTimeStampSecond(date) : "-";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Formatter<DateHolder> clock() {
|
|
||||||
return dateHolder -> {
|
|
||||||
long date = dateHolder.getDate();
|
|
||||||
return date > 0 ? FormatUtils.formatTimeStampClock(date) : "-";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Formatter<DateHolder> iso8601NoClock() {
|
|
||||||
return dateHolder -> FormatUtils.formatTimeStampISO8601NoClock(dateHolder.getDate());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Formatter<Long> timeAmount() {
|
|
||||||
return new TimeAmountFormatter();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Function<Long, Integer> dayOfYear() {
|
|
||||||
return date -> {
|
|
||||||
Calendar day = Calendar.getInstance();
|
|
||||||
day.setTimeInMillis(date);
|
|
||||||
return day.get(Calendar.DAY_OF_YEAR);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Formatter<Double> percentage() {
|
|
||||||
return value -> value >= 0 ? FormatUtils.cutDecimals(value * 100.0) + "%" : "-";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Formatter<Long> benchmark() {
|
|
||||||
return ns -> {
|
|
||||||
if (ns > TimeAmount.MILLISECOND.ns() * 5L) {
|
|
||||||
return (ns / TimeAmount.MILLISECOND.ns()) + "ms";
|
|
||||||
} else {
|
|
||||||
return 1.0 * ns / TimeAmount.MILLISECOND.ns() + "ms";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Formatter<String> itemName() {
|
|
||||||
return name -> {
|
|
||||||
String[] parts = name.split("_");
|
|
||||||
TextStringBuilder builder = new TextStringBuilder();
|
|
||||||
builder.appendWithSeparators(Arrays.stream(parts).map(part -> new Format(part).capitalize()).iterator(), " ");
|
|
||||||
return builder.toString();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,12 +3,11 @@ package com.djrapitops.plan.data.store.mutators.health;
|
|||||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
||||||
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
|
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
|
||||||
import com.djrapitops.plan.data.store.mutators.SessionsMutator;
|
import com.djrapitops.plan.data.store.mutators.SessionsMutator;
|
||||||
import com.djrapitops.plan.data.store.mutators.formatting.Formatters;
|
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||||
import com.djrapitops.plan.utilities.FormatUtils;
|
|
||||||
import com.djrapitops.plan.utilities.html.icon.Icons;
|
import com.djrapitops.plan.utilities.html.icon.Icons;
|
||||||
import com.djrapitops.plugin.api.TimeAmount;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public abstract class AbstractHealthInfo {
|
public abstract class AbstractHealthInfo {
|
||||||
|
|
||||||
@ -20,9 +19,27 @@ public abstract class AbstractHealthInfo {
|
|||||||
|
|
||||||
protected double serverHealth;
|
protected double serverHealth;
|
||||||
|
|
||||||
public AbstractHealthInfo(long now, long monthAgo) {
|
protected final int activeMinuteThreshold;
|
||||||
|
protected final int activeLoginThreshold;
|
||||||
|
protected final Formatter<Long> timeAmountFormatter;
|
||||||
|
protected final Formatter<Double> decimalFormatter;
|
||||||
|
protected final Formatter<Double> percentageFormatter;
|
||||||
|
|
||||||
|
public AbstractHealthInfo(
|
||||||
|
long now, long monthAgo,
|
||||||
|
int activeMinuteThreshold,
|
||||||
|
int activeLoginThreshold,
|
||||||
|
Formatter<Long> timeAmountFormatter,
|
||||||
|
Formatter<Double> decimalFormatter,
|
||||||
|
Formatter<Double> percentageFormatter
|
||||||
|
) {
|
||||||
this.now = now;
|
this.now = now;
|
||||||
this.monthAgo = monthAgo;
|
this.monthAgo = monthAgo;
|
||||||
|
this.activeMinuteThreshold = activeMinuteThreshold;
|
||||||
|
this.activeLoginThreshold = activeLoginThreshold;
|
||||||
|
this.timeAmountFormatter = timeAmountFormatter;
|
||||||
|
this.decimalFormatter = decimalFormatter;
|
||||||
|
this.percentageFormatter = percentageFormatter;
|
||||||
serverHealth = 100.0;
|
serverHealth = 100.0;
|
||||||
|
|
||||||
this.notes = new ArrayList<>();
|
this.notes = new ArrayList<>();
|
||||||
@ -63,7 +80,7 @@ public abstract class AbstractHealthInfo {
|
|||||||
regularRemainCompareSet.removeAll(veryActiveNow);
|
regularRemainCompareSet.removeAll(veryActiveNow);
|
||||||
int notRegularAnymore = regularRemainCompareSet.size();
|
int notRegularAnymore = regularRemainCompareSet.size();
|
||||||
int remain = activeFWAGNum - notRegularAnymore;
|
int remain = activeFWAGNum - notRegularAnymore;
|
||||||
double percRemain = activeFWAGNum != 0 ? remain * 100.0 / activeFWAGNum : 100.0;
|
double percRemain = activeFWAGNum != 0 ? remain / activeFWAGNum : 1.0;
|
||||||
|
|
||||||
int newActive = getNewActive(veryActiveNow, activeNow, regularNow, veryActiveFWAG, activeFWAG, regularFWAG);
|
int newActive = getNewActive(veryActiveNow, activeNow, regularNow, veryActiveFWAG, activeFWAG, regularFWAG);
|
||||||
|
|
||||||
@ -72,16 +89,16 @@ public abstract class AbstractHealthInfo {
|
|||||||
String remainNote = "";
|
String remainNote = "";
|
||||||
if (activeFWAGNum != 0) {
|
if (activeFWAGNum != 0) {
|
||||||
remainNote = "<br> ";
|
remainNote = "<br> ";
|
||||||
if (percRemain > 50) {
|
if (percRemain > 0.5) {
|
||||||
remainNote += Icons.GREEN_THUMB;
|
remainNote += Icons.GREEN_THUMB;
|
||||||
} else if (percRemain > 20) {
|
} else if (percRemain > 0.2) {
|
||||||
remainNote += Icons.YELLOW_FLAG;
|
remainNote += Icons.YELLOW_FLAG;
|
||||||
} else {
|
} else {
|
||||||
remainNote += Icons.RED_WARN;
|
remainNote += Icons.RED_WARN;
|
||||||
serverHealth -= 2.5;
|
serverHealth -= 2.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
remainNote += " " + FormatUtils.cutDecimals(percRemain) + "% of regular players have remained active ("
|
remainNote += " " + percentageFormatter.apply(percRemain) + " of regular players have remained active ("
|
||||||
+ remain + "/" + activeFWAGNum + ")";
|
+ remain + "/" + activeFWAGNum + ")";
|
||||||
}
|
}
|
||||||
if (change > 0) {
|
if (change > 0) {
|
||||||
@ -98,7 +115,7 @@ public abstract class AbstractHealthInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void activePlayerPlaytimeChange(PlayersMutator playersMutator) {
|
protected void activePlayerPlaytimeChange(PlayersMutator playersMutator) {
|
||||||
PlayersMutator currentlyActive = playersMutator.filterActive(now, 1.75);
|
PlayersMutator currentlyActive = playersMutator.filterActive(now, activeMinuteThreshold, activeLoginThreshold, 1.75);
|
||||||
long twoWeeksAgo = (now - (now - monthAgo)) / 2L;
|
long twoWeeksAgo = (now - (now - monthAgo)) / 2L;
|
||||||
|
|
||||||
long totalFourToTwoWeeks = 0;
|
long totalFourToTwoWeeks = 0;
|
||||||
@ -113,13 +130,13 @@ public abstract class AbstractHealthInfo {
|
|||||||
if (activeCount != 0) {
|
if (activeCount != 0) {
|
||||||
long avgFourToTwoWeeks = totalFourToTwoWeeks / (long) activeCount;
|
long avgFourToTwoWeeks = totalFourToTwoWeeks / (long) activeCount;
|
||||||
long avgLastTwoWeeks = totalLastTwoWeeks / (long) activeCount;
|
long avgLastTwoWeeks = totalLastTwoWeeks / (long) activeCount;
|
||||||
String avgLastTwoWeeksString = Formatters.timeAmount().apply(avgLastTwoWeeks);
|
String avgLastTwoWeeksString = timeAmountFormatter.apply(avgLastTwoWeeks);
|
||||||
String avgFourToTwoWeeksString = Formatters.timeAmount().apply(avgFourToTwoWeeks);
|
String avgFourToTwoWeeksString = timeAmountFormatter.apply(avgFourToTwoWeeks);
|
||||||
if (avgFourToTwoWeeks >= avgLastTwoWeeks) {
|
if (avgFourToTwoWeeks >= avgLastTwoWeeks) {
|
||||||
addNote(Icons.GREEN_THUMB + " Active players seem to have things to do (Played "
|
addNote(Icons.GREEN_THUMB + " Active players seem to have things to do (Played "
|
||||||
+ avgLastTwoWeeksString + " vs " + avgFourToTwoWeeksString
|
+ avgLastTwoWeeksString + " vs " + avgFourToTwoWeeksString
|
||||||
+ ", last two weeks vs weeks 2-4)");
|
+ ", last two weeks vs weeks 2-4)");
|
||||||
} else if (avgFourToTwoWeeks - avgLastTwoWeeks > TimeAmount.HOUR.ms() * 2L) {
|
} else if (avgFourToTwoWeeks - avgLastTwoWeeks > TimeUnit.HOURS.toMillis(2L)) {
|
||||||
addNote(Icons.RED_WARN + " Active players might be running out of things to do (Played "
|
addNote(Icons.RED_WARN + " Active players might be running out of things to do (Played "
|
||||||
+ avgLastTwoWeeksString + " vs " + avgFourToTwoWeeksString
|
+ avgLastTwoWeeksString + " vs " + avgFourToTwoWeeksString
|
||||||
+ ", last two weeks vs weeks 2-4)");
|
+ ", last two weeks vs weeks 2-4)");
|
||||||
|
@ -10,15 +10,13 @@ import com.djrapitops.plan.data.store.keys.AnalysisKeys;
|
|||||||
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
|
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
|
||||||
import com.djrapitops.plan.data.store.mutators.PlayersOnlineResolver;
|
import com.djrapitops.plan.data.store.mutators.PlayersOnlineResolver;
|
||||||
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
||||||
import com.djrapitops.plan.data.store.mutators.formatting.Formatter;
|
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||||
import com.djrapitops.plan.data.store.mutators.formatting.Formatters;
|
|
||||||
import com.djrapitops.plan.system.settings.Settings;
|
|
||||||
import com.djrapitops.plan.utilities.FormatUtils;
|
|
||||||
import com.djrapitops.plan.utilities.html.icon.Icons;
|
import com.djrapitops.plan.utilities.html.icon.Icons;
|
||||||
import com.djrapitops.plugin.api.TimeAmount;
|
import com.djrapitops.plugin.api.TimeAmount;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Server Health analysis mutator.
|
* Server Health analysis mutator.
|
||||||
@ -29,12 +27,23 @@ public class HealthInformation extends AbstractHealthInfo {
|
|||||||
|
|
||||||
private final AnalysisContainer analysisContainer;
|
private final AnalysisContainer analysisContainer;
|
||||||
|
|
||||||
public HealthInformation(AnalysisContainer analysisContainer) {
|
private final int lowTPSThreshold;
|
||||||
|
|
||||||
|
public HealthInformation(
|
||||||
|
AnalysisContainer analysisContainer,
|
||||||
|
int lowTPSThreshold, int activeMinuteThreshold,
|
||||||
|
int activeLoginThreshold,
|
||||||
|
Formatter<Long> timeAmountFormatter,
|
||||||
|
Formatter<Double> decimalFormatter,
|
||||||
|
Formatter<Double> percentageFormatter
|
||||||
|
) {
|
||||||
super(
|
super(
|
||||||
analysisContainer.getUnsafe(AnalysisKeys.ANALYSIS_TIME),
|
analysisContainer.getUnsafe(AnalysisKeys.ANALYSIS_TIME),
|
||||||
analysisContainer.getUnsafe(AnalysisKeys.ANALYSIS_TIME_MONTH_AGO)
|
analysisContainer.getUnsafe(AnalysisKeys.ANALYSIS_TIME_MONTH_AGO),
|
||||||
|
activeMinuteThreshold, activeLoginThreshold, timeAmountFormatter, decimalFormatter, percentageFormatter
|
||||||
);
|
);
|
||||||
this.analysisContainer = analysisContainer;
|
this.analysisContainer = analysisContainer;
|
||||||
|
this.lowTPSThreshold = lowTPSThreshold;
|
||||||
calculate();
|
calculate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,10 +76,10 @@ public class HealthInformation extends AbstractHealthInfo {
|
|||||||
.average().orElse(0);
|
.average().orElse(0);
|
||||||
if (avgOnlineOnRegister >= 1) {
|
if (avgOnlineOnRegister >= 1) {
|
||||||
addNote(Icons.GREEN_THUMB + " New Players have players to play with when they join ("
|
addNote(Icons.GREEN_THUMB + " New Players have players to play with when they join ("
|
||||||
+ FormatUtils.cutDecimals(avgOnlineOnRegister) + " on average)");
|
+ decimalFormatter.apply(avgOnlineOnRegister) + " on average)");
|
||||||
} else {
|
} else {
|
||||||
addNote(Icons.YELLOW_FLAG + " New Players may not have players to play with when they join ("
|
addNote(Icons.YELLOW_FLAG + " New Players may not have players to play with when they join ("
|
||||||
+ FormatUtils.cutDecimals(avgOnlineOnRegister) + " on average)");
|
+ decimalFormatter.apply(avgOnlineOnRegister) + " on average)");
|
||||||
serverHealth -= 5;
|
serverHealth -= 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,10 +89,10 @@ public class HealthInformation extends AbstractHealthInfo {
|
|||||||
if (playersNewMonth != 0) {
|
if (playersNewMonth != 0) {
|
||||||
double retainPercentage = playersRetainedMonth * 1.0 / playersNewMonth;
|
double retainPercentage = playersRetainedMonth * 1.0 / playersNewMonth;
|
||||||
if (retainPercentage >= 0.25) {
|
if (retainPercentage >= 0.25) {
|
||||||
addNote(Icons.GREEN_THUMB + " " + Formatters.percentage().apply(retainPercentage)
|
addNote(Icons.GREEN_THUMB + " " + percentageFormatter.apply(retainPercentage)
|
||||||
+ " of new players have stuck around (" + playersRetainedMonth + "/" + playersNewMonth + ")");
|
+ " of new players have stuck around (" + playersRetainedMonth + "/" + playersNewMonth + ")");
|
||||||
} else {
|
} else {
|
||||||
addNote(Icons.YELLOW_FLAG + " " + Formatters.percentage().apply(retainPercentage)
|
addNote(Icons.YELLOW_FLAG + " " + percentageFormatter.apply(retainPercentage)
|
||||||
+ " of new players have stuck around (" + playersRetainedMonth + "/" + playersNewMonth + ")");
|
+ " of new players have stuck around (" + playersRetainedMonth + "/" + playersNewMonth + ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,7 +102,8 @@ public class HealthInformation extends AbstractHealthInfo {
|
|||||||
Key<TPSMutator> tpsMonth = new Key<>(TPSMutator.class, "TPS_MONTH");
|
Key<TPSMutator> tpsMonth = new Key<>(TPSMutator.class, "TPS_MONTH");
|
||||||
TPSMutator tpsMutator = analysisContainer.getUnsafe(tpsMonth);
|
TPSMutator tpsMutator = analysisContainer.getUnsafe(tpsMonth);
|
||||||
long serverDownTime = tpsMutator.serverDownTime();
|
long serverDownTime = tpsMutator.serverDownTime();
|
||||||
double aboveThreshold = tpsMutator.percentageTPSAboveLowThreshold();
|
|
||||||
|
double aboveThreshold = tpsMutator.percentageTPSAboveThreshold(lowTPSThreshold);
|
||||||
long tpsSpikeMonth = analysisContainer.getValue(AnalysisKeys.TPS_SPIKE_MONTH).orElse(0);
|
long tpsSpikeMonth = analysisContainer.getValue(AnalysisKeys.TPS_SPIKE_MONTH).orElse(0);
|
||||||
|
|
||||||
String avgLowThresholdString = "<br> ";
|
String avgLowThresholdString = "<br> ";
|
||||||
@ -107,34 +117,36 @@ public class HealthInformation extends AbstractHealthInfo {
|
|||||||
serverHealth *= 0.6;
|
serverHealth *= 0.6;
|
||||||
}
|
}
|
||||||
avgLowThresholdString += " Average TPS was above Low Threshold "
|
avgLowThresholdString += " Average TPS was above Low Threshold "
|
||||||
+ FormatUtils.cutDecimals(aboveThreshold * 100.0) + "% of the time";
|
+ decimalFormatter.apply(aboveThreshold * 100.0) + "% of the time";
|
||||||
|
|
||||||
int threshold = Settings.THEME_GRAPH_TPS_THRESHOLD_MED.getNumber();
|
|
||||||
if (tpsSpikeMonth <= 5) {
|
if (tpsSpikeMonth <= 5) {
|
||||||
addNote(Icons.GREEN_THUMB + " Average TPS dropped below Low Threshold (" + threshold + ")" +
|
addNote(Icons.GREEN_THUMB + " Average TPS dropped below Low Threshold (" + lowTPSThreshold + ")" +
|
||||||
" " + tpsSpikeMonth + " times" +
|
" " + tpsSpikeMonth + " times" +
|
||||||
avgLowThresholdString);
|
avgLowThresholdString);
|
||||||
} else if (tpsSpikeMonth <= 25) {
|
} else if (tpsSpikeMonth <= 25) {
|
||||||
addNote(Icons.YELLOW_FLAG + " Average TPS dropped below Low Threshold (" + threshold + ")" +
|
addNote(Icons.YELLOW_FLAG + " Average TPS dropped below Low Threshold (" + lowTPSThreshold + ")" +
|
||||||
" " + tpsSpikeMonth + " times" +
|
" " + tpsSpikeMonth + " times" +
|
||||||
avgLowThresholdString);
|
avgLowThresholdString);
|
||||||
serverHealth *= 0.95;
|
serverHealth *= 0.95;
|
||||||
} else {
|
} else {
|
||||||
addNote(Icons.RED_WARN + " Average TPS dropped below Low Threshold (" + threshold + ")" +
|
addNote(Icons.RED_WARN + " Average TPS dropped below Low Threshold (" + lowTPSThreshold + ")" +
|
||||||
" " + tpsSpikeMonth + " times" +
|
" " + tpsSpikeMonth + " times" +
|
||||||
avgLowThresholdString);
|
avgLowThresholdString);
|
||||||
serverHealth *= 0.8;
|
serverHealth *= 0.8;
|
||||||
}
|
}
|
||||||
|
|
||||||
Formatter<Long> formatter = Formatters.timeAmount();
|
if (serverDownTime <= TimeUnit.DAYS.toMillis(1L)) {
|
||||||
if (serverDownTime <= TimeAmount.DAY.ms()) {
|
addNote(Icons.GREEN_THUMB + " Total Server downtime (No Data) was " + timeAmountFormatter.apply(serverDownTime));
|
||||||
addNote(Icons.GREEN_THUMB + " Total Server downtime (No Data) was " + formatter.apply(serverDownTime));
|
|
||||||
} else if (serverDownTime <= TimeAmount.WEEK.ms()) {
|
|
||||||
addNote(Icons.YELLOW_FLAG + " Total Server downtime (No Data) was " + formatter.apply(serverDownTime));
|
|
||||||
serverHealth *= (TimeAmount.WEEK.ms() - serverDownTime) * 1.0 / TimeAmount.WEEK.ms();
|
|
||||||
} else {
|
} else {
|
||||||
addNote(Icons.RED_WARN + " Total Server downtime (No Data) was " + formatter.apply(serverDownTime));
|
long weekMs = TimeAmount.WEEK.toMillis(1L);
|
||||||
serverHealth *= (TimeAmount.MONTH.ms() - serverDownTime) * 1.0 / TimeAmount.MONTH.ms();
|
if (serverDownTime <= weekMs) {
|
||||||
|
addNote(Icons.YELLOW_FLAG + " Total Server downtime (No Data) was " + timeAmountFormatter.apply(serverDownTime));
|
||||||
|
serverHealth *= (weekMs - serverDownTime) * 1.0 / weekMs;
|
||||||
|
} else {
|
||||||
|
addNote(Icons.RED_WARN + " Total Server downtime (No Data) was " + timeAmountFormatter.apply(serverDownTime));
|
||||||
|
long monthMs = TimeAmount.MONTH.toMillis(1L);
|
||||||
|
serverHealth *= (monthMs - serverDownTime) * 1.0 / monthMs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ import com.djrapitops.plan.data.store.keys.NetworkKeys;
|
|||||||
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
|
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
|
||||||
import com.djrapitops.plan.data.store.mutators.SessionsMutator;
|
import com.djrapitops.plan.data.store.mutators.SessionsMutator;
|
||||||
import com.djrapitops.plan.system.info.server.Server;
|
import com.djrapitops.plan.system.info.server.Server;
|
||||||
import com.djrapitops.plan.utilities.FormatUtils;
|
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||||
import com.djrapitops.plan.utilities.html.icon.Icon;
|
import com.djrapitops.plan.utilities.html.icon.Icon;
|
||||||
import com.djrapitops.plan.utilities.html.icon.Icons;
|
import com.djrapitops.plan.utilities.html.icon.Icons;
|
||||||
|
|
||||||
@ -18,10 +18,18 @@ public class NetworkHealthInformation extends AbstractHealthInfo {
|
|||||||
|
|
||||||
private final NetworkContainer container;
|
private final NetworkContainer container;
|
||||||
|
|
||||||
public NetworkHealthInformation(NetworkContainer container) {
|
public NetworkHealthInformation(
|
||||||
|
NetworkContainer container,
|
||||||
|
int activeMinuteThreshold,
|
||||||
|
int activeLoginThreshold,
|
||||||
|
Formatter<Long> timeAmountFormatter,
|
||||||
|
Formatter<Double> decimalFormatter,
|
||||||
|
Formatter<Double> percentageFormatter
|
||||||
|
) {
|
||||||
super(
|
super(
|
||||||
container.getUnsafe(NetworkKeys.REFRESH_TIME),
|
container.getUnsafe(NetworkKeys.REFRESH_TIME),
|
||||||
container.getUnsafe(NetworkKeys.REFRESH_TIME_MONTH_AGO)
|
container.getUnsafe(NetworkKeys.REFRESH_TIME_MONTH_AGO),
|
||||||
|
activeMinuteThreshold, activeLoginThreshold, timeAmountFormatter, decimalFormatter, percentageFormatter
|
||||||
);
|
);
|
||||||
this.container = container;
|
this.container = container;
|
||||||
calculate();
|
calculate();
|
||||||
@ -82,7 +90,7 @@ public class NetworkHealthInformation extends AbstractHealthInfo {
|
|||||||
return subNote + (playersPerMonth >= average && playersPerMonth > 0 ? Icons.GREEN_PLUS : Icons.RED_MINUS) + " " +
|
return subNote + (playersPerMonth >= average && playersPerMonth > 0 ? Icons.GREEN_PLUS : Icons.RED_MINUS) + " " +
|
||||||
server.getName() + ": " + playersPerMonth;
|
server.getName() + ": " + playersPerMonth;
|
||||||
}).forEach(subNotes::append);
|
}).forEach(subNotes::append);
|
||||||
addNote(icon + " " + FormatUtils.cutDecimals(average) + uniquePlayersNote + subNotes.toString());
|
addNote(icon + " " + decimalFormatter.apply(average) + uniquePlayersNote + subNotes.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void newPlayersNote(int serverCount, Key<Server> serverKey, List<DataContainer> perServerContainers) {
|
private void newPlayersNote(int serverCount, Key<Server> serverKey, List<DataContainer> perServerContainers) {
|
||||||
@ -109,7 +117,7 @@ public class NetworkHealthInformation extends AbstractHealthInfo {
|
|||||||
return subNote + (playersPerMonth >= average && playersPerMonth > 0 ? Icons.GREEN_PLUS : Icons.RED_MINUS) + " " +
|
return subNote + (playersPerMonth >= average && playersPerMonth > 0 ? Icons.GREEN_PLUS : Icons.RED_MINUS) + " " +
|
||||||
server.getName() + ": " + playersPerMonth;
|
server.getName() + ": " + playersPerMonth;
|
||||||
}).forEach(subNotes::append);
|
}).forEach(subNotes::append);
|
||||||
addNote(icon + " " + FormatUtils.cutDecimals(average) + newPlayersNote + subNotes.toString());
|
addNote(icon + " " + decimalFormatter.apply(average) + newPlayersNote + subNotes.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<DataContainer> getPerServerContainers(PlayersMutator playersMutator, Collection<Server> servers, Key<Server> serverKey) {
|
private List<DataContainer> getPerServerContainers(PlayersMutator playersMutator, Collection<Server> servers, Key<Server> serverKey) {
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
package com.djrapitops.plan.data.time;
|
package com.djrapitops.plan.data.time;
|
||||||
|
|
||||||
import com.djrapitops.plan.system.settings.WorldAliasSettings;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that tracks the time spent in each World based on GMTimes.
|
* Class that tracks the time spent in each World based on GMTimes.
|
||||||
@ -169,33 +166,4 @@ public class WorldTimes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Long> getPlaytimePerAlias() {
|
|
||||||
if (times.isEmpty()) {
|
|
||||||
return new HashMap<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, Long> playtimePerWorld = times.entrySet().stream() // WorldTimes Map<String, GMTimes>
|
|
||||||
.collect(Collectors.toMap(
|
|
||||||
Map.Entry::getKey,
|
|
||||||
entry -> entry.getValue().getTotal() // GMTimes.getTotal
|
|
||||||
));
|
|
||||||
|
|
||||||
Map<String, String> aliases = WorldAliasSettings.getAliases();
|
|
||||||
|
|
||||||
Map<String, Long> playtimePerAlias = new HashMap<>();
|
|
||||||
for (Map.Entry<String, Long> entry : playtimePerWorld.entrySet()) {
|
|
||||||
String worldName = entry.getKey();
|
|
||||||
long playtime = entry.getValue();
|
|
||||||
|
|
||||||
if (!aliases.containsKey(worldName)) {
|
|
||||||
aliases.put(worldName, worldName);
|
|
||||||
WorldAliasSettings.addWorld(worldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
String alias = aliases.get(worldName);
|
|
||||||
|
|
||||||
playtimePerAlias.put(alias, playtimePerAlias.getOrDefault(alias, 0L) + playtime);
|
|
||||||
}
|
|
||||||
return playtimePerAlias;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,73 @@
|
|||||||
|
package com.djrapitops.plan.modules;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.PlanPlugin;
|
||||||
|
import com.djrapitops.plugin.IPlugin;
|
||||||
|
import com.djrapitops.plugin.benchmarking.Timings;
|
||||||
|
import com.djrapitops.plugin.command.ColorScheme;
|
||||||
|
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||||
|
import com.djrapitops.plugin.logging.debug.DebugLogger;
|
||||||
|
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||||
|
import com.djrapitops.plugin.task.RunnableFactory;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dagger module for defining Abstract Plugin Framework utilities.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
@Module
|
||||||
|
public class APFModule {
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
IPlugin provideIPlugin(PlanPlugin plugin) {
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Named("currentVersion")
|
||||||
|
@Singleton
|
||||||
|
String provideCurrentVersion(IPlugin plugin) {
|
||||||
|
return plugin.getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ColorScheme provideColorScheme(PlanPlugin plugin) {
|
||||||
|
return plugin.getColorScheme();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
DebugLogger provideDebugLogger(IPlugin plugin) {
|
||||||
|
return plugin.getDebugLogger();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
PluginLogger providePluginLogger(IPlugin plugin) {
|
||||||
|
return plugin.getPluginLogger();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ErrorHandler provideErrorHandler(IPlugin plugin) {
|
||||||
|
return plugin.getErrorHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
Timings provideTimings(IPlugin plugin) {
|
||||||
|
return plugin.getTimings();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
RunnableFactory provideRunnableFactory(IPlugin plugin) {
|
||||||
|
return plugin.getRunnableFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.djrapitops.plan.modules;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.system.file.PlanFiles;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dagger Module for the Plan files.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
@Module
|
||||||
|
public class FilesModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Named("configFile")
|
||||||
|
@Singleton
|
||||||
|
File provideConfigFile(PlanFiles files) {
|
||||||
|
return files.getConfigFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.djrapitops.plan.modules;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.system.cache.DataCache;
|
||||||
|
import com.djrapitops.plan.system.cache.SessionCache;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module for binding instances of implementations to super classes.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
@Module
|
||||||
|
public class SuperClassBindingModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
SessionCache provideSessionCache(DataCache cache) {
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package com.djrapitops.plan.modules;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.data.plugin.PluginsConfigSection;
|
||||||
|
import com.djrapitops.plan.system.database.DBSystem;
|
||||||
|
import com.djrapitops.plan.system.database.databases.Database;
|
||||||
|
import com.djrapitops.plan.system.locale.Locale;
|
||||||
|
import com.djrapitops.plan.system.locale.LocaleSystem;
|
||||||
|
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module for binding object instances found inside other systems.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
@Module
|
||||||
|
public class SystemObjectBindingModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
Locale provideLocale(LocaleSystem localeSystem) {
|
||||||
|
return localeSystem.getLocale();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
Database provideDatabase(DBSystem dbSystem) {
|
||||||
|
return dbSystem.getActiveDatabase();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
PluginsConfigSection providePluginsConfigSection(PlanConfig config) {
|
||||||
|
return config.getPluginsConfigSection();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
package com.djrapitops.plan.modules.proxy;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.api.PlanAPI;
|
||||||
|
import com.djrapitops.plan.api.ProxyAPI;
|
||||||
|
import com.djrapitops.plan.system.cache.DataCache;
|
||||||
|
import com.djrapitops.plan.system.cache.ProxyDataCache;
|
||||||
|
import com.djrapitops.plan.system.database.DBSystem;
|
||||||
|
import com.djrapitops.plan.system.database.ProxyDBSystem;
|
||||||
|
import com.djrapitops.plan.system.importing.EmptyImportSystem;
|
||||||
|
import com.djrapitops.plan.system.importing.ImportSystem;
|
||||||
|
import com.djrapitops.plan.system.info.InfoSystem;
|
||||||
|
import com.djrapitops.plan.system.info.ProxyInfoSystem;
|
||||||
|
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||||
|
import com.djrapitops.plan.system.info.connection.ProxyConnectionSystem;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dagger module for binding proxy server classes to super classes.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
@Module
|
||||||
|
public class ProxySuperClassBindingModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
PlanAPI provideProxyPlanAPI(ProxyAPI proxyAPI) {
|
||||||
|
return proxyAPI;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
DBSystem provideProxyDatabaseSystem(ProxyDBSystem proxyDBSystem) {
|
||||||
|
return proxyDBSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
InfoSystem provideProxyInfoSystem(ProxyInfoSystem proxyInfoSystem) {
|
||||||
|
return proxyInfoSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ConnectionSystem provideProxyConnectionSystem(ProxyConnectionSystem proxyConnectionSystem) {
|
||||||
|
return proxyConnectionSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
DataCache provideProxyDataCache(ProxyDataCache proxyDataCache) {
|
||||||
|
return proxyDataCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ImportSystem provideImportSystem() {
|
||||||
|
return new EmptyImportSystem();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.djrapitops.plan.modules.proxy.bungee;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.PlanBungee;
|
||||||
|
import com.djrapitops.plan.system.info.server.properties.BungeeServerProperties;
|
||||||
|
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 dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dagger module for Bungee ServerProperties.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
@Module
|
||||||
|
public class BungeeServerPropertiesModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ServerProperties provideServerProperties(PlanBungee plugin, PlanConfig config) {
|
||||||
|
return new BungeeServerProperties(plugin.getProxy(), config.getString(Settings.BUNGEE_IP));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package com.djrapitops.plan.modules.proxy.bungee;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.system.info.server.BungeeServerInfo;
|
||||||
|
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||||
|
import com.djrapitops.plan.system.listeners.BungeeListenerSystem;
|
||||||
|
import com.djrapitops.plan.system.listeners.ListenerSystem;
|
||||||
|
import com.djrapitops.plan.system.settings.config.ConfigSystem;
|
||||||
|
import com.djrapitops.plan.system.settings.config.ProxyConfigSystem;
|
||||||
|
import com.djrapitops.plan.system.tasks.BungeeTaskSystem;
|
||||||
|
import com.djrapitops.plan.system.tasks.TaskSystem;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module for binding Bungee specific classes to the interface implementations.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
@Module
|
||||||
|
public class BungeeSuperClassBindingModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ServerInfo provideBungeeServerInfo(BungeeServerInfo bungeeServerInfo) {
|
||||||
|
return bungeeServerInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ConfigSystem provideBungeeConfigSystem(ProxyConfigSystem proxyConfigSystem) {
|
||||||
|
return proxyConfigSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
TaskSystem provideBungeeTaskSystem(BungeeTaskSystem bungeeTaskSystem) {
|
||||||
|
return bungeeTaskSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ListenerSystem provideBungeeListenerSystem(BungeeListenerSystem bungeeListenerSystem) {
|
||||||
|
return bungeeListenerSystem;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.djrapitops.plan.modules.proxy.velocity;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.PlanVelocity;
|
||||||
|
import com.djrapitops.plan.system.info.server.properties.ServerProperties;
|
||||||
|
import com.djrapitops.plan.system.info.server.properties.VelocityServerProperties;
|
||||||
|
import com.djrapitops.plan.system.settings.Settings;
|
||||||
|
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dagger module for Bungee ServerProperties.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
@Module
|
||||||
|
public class VelocityServerPropertiesModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ServerProperties provideServerProperties(PlanVelocity plugin, PlanConfig config) {
|
||||||
|
return new VelocityServerProperties(plugin.getProxy(), config.getString(Settings.BUNGEE_IP));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package com.djrapitops.plan.modules.proxy.velocity;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||||
|
import com.djrapitops.plan.system.info.server.VelocityServerInfo;
|
||||||
|
import com.djrapitops.plan.system.listeners.ListenerSystem;
|
||||||
|
import com.djrapitops.plan.system.listeners.VelocityListenerSystem;
|
||||||
|
import com.djrapitops.plan.system.settings.config.ConfigSystem;
|
||||||
|
import com.djrapitops.plan.system.settings.config.ProxyConfigSystem;
|
||||||
|
import com.djrapitops.plan.system.tasks.TaskSystem;
|
||||||
|
import com.djrapitops.plan.system.tasks.VelocityTaskSystem;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module for binding Velocity specific classes to the interface implementations.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
@Module
|
||||||
|
public class VelocitySuperClassBindingModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ServerInfo provideVelocityServerInfo(VelocityServerInfo velocityServerInfo) {
|
||||||
|
return velocityServerInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ConfigSystem provideVelocityConfigSystem(ProxyConfigSystem proxyConfigSystem) {
|
||||||
|
return proxyConfigSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
TaskSystem provideVelocityTaskSystem(VelocityTaskSystem velocityTaskSystem) {
|
||||||
|
return velocityTaskSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ListenerSystem provideVelocityListenerSystem(VelocityListenerSystem velocityListenerSystem) {
|
||||||
|
return velocityListenerSystem;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package com.djrapitops.plan.modules.server;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.api.PlanAPI;
|
||||||
|
import com.djrapitops.plan.api.ServerAPI;
|
||||||
|
import com.djrapitops.plan.system.info.InfoSystem;
|
||||||
|
import com.djrapitops.plan.system.info.ServerInfoSystem;
|
||||||
|
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||||
|
import com.djrapitops.plan.system.info.connection.ServerConnectionSystem;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module for binding Server specific classes to the interface implementations.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
@Module
|
||||||
|
public class ServerSuperClassBindingModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
PlanAPI provideServerPlanAPI(ServerAPI serverAPI) {
|
||||||
|
return serverAPI;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
InfoSystem provideServerInfoSystem(ServerInfoSystem serverInfoSystem) {
|
||||||
|
return serverInfoSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ConnectionSystem provideServerConnectionSystem(ServerConnectionSystem serverConnectionSystem) {
|
||||||
|
return serverConnectionSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.djrapitops.plan.modules.server.bukkit;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.Plan;
|
||||||
|
import com.djrapitops.plan.system.info.server.properties.BukkitServerProperties;
|
||||||
|
import com.djrapitops.plan.system.info.server.properties.ServerProperties;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dagger module for Bukkit ServerProperties.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
@Module
|
||||||
|
public class BukkitServerPropertiesModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ServerProperties provideServerProperties(Plan plugin) {
|
||||||
|
return new BukkitServerProperties(plugin.getServer());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
package com.djrapitops.plan.modules.server.bukkit;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.system.database.BukkitDBSystem;
|
||||||
|
import com.djrapitops.plan.system.database.DBSystem;
|
||||||
|
import com.djrapitops.plan.system.importing.BukkitImportSystem;
|
||||||
|
import com.djrapitops.plan.system.importing.ImportSystem;
|
||||||
|
import com.djrapitops.plan.system.info.server.BukkitServerInfo;
|
||||||
|
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||||
|
import com.djrapitops.plan.system.listeners.BukkitListenerSystem;
|
||||||
|
import com.djrapitops.plan.system.listeners.ListenerSystem;
|
||||||
|
import com.djrapitops.plan.system.settings.config.BukkitConfigSystem;
|
||||||
|
import com.djrapitops.plan.system.settings.config.ConfigSystem;
|
||||||
|
import com.djrapitops.plan.system.tasks.BukkitTaskSystem;
|
||||||
|
import com.djrapitops.plan.system.tasks.TaskSystem;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module for binding Bukkit specific classes to the interface implementations.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
@Module
|
||||||
|
public class BukkitSuperClassBindingModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ServerInfo provideBukkitServerInfo(BukkitServerInfo bukkitServerInfo) {
|
||||||
|
return bukkitServerInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
DBSystem provideBukkitDatabaseSystem(BukkitDBSystem dbSystem) {
|
||||||
|
return dbSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ConfigSystem provideBukkitConfigSystem(BukkitConfigSystem bukkitConfigSystem) {
|
||||||
|
return bukkitConfigSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
TaskSystem provideBukkitTaskSystem(BukkitTaskSystem bukkitTaskSystem) {
|
||||||
|
return bukkitTaskSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ListenerSystem provideBukkitListenerSystem(BukkitListenerSystem bukkitListenerSystem) {
|
||||||
|
return bukkitListenerSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ImportSystem provideImportSsytem(BukkitImportSystem bukkitImportSystem) {
|
||||||
|
return bukkitImportSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.djrapitops.plan.modules.server.sponge;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.system.info.server.properties.ServerProperties;
|
||||||
|
import com.djrapitops.plan.system.info.server.properties.SpongeServerProperties;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
import org.spongepowered.api.Sponge;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dagger module for Sponge ServerProperties.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
@Module
|
||||||
|
public class SpongeServerPropertiesModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ServerProperties provideServerProperties() {
|
||||||
|
return new SpongeServerProperties(Sponge.getGame());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
package com.djrapitops.plan.modules.server.sponge;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.system.database.DBSystem;
|
||||||
|
import com.djrapitops.plan.system.database.SpongeDBSystem;
|
||||||
|
import com.djrapitops.plan.system.importing.EmptyImportSystem;
|
||||||
|
import com.djrapitops.plan.system.importing.ImportSystem;
|
||||||
|
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||||
|
import com.djrapitops.plan.system.info.server.SpongeServerInfo;
|
||||||
|
import com.djrapitops.plan.system.listeners.ListenerSystem;
|
||||||
|
import com.djrapitops.plan.system.listeners.SpongeListenerSystem;
|
||||||
|
import com.djrapitops.plan.system.settings.config.ConfigSystem;
|
||||||
|
import com.djrapitops.plan.system.settings.config.SpongeConfigSystem;
|
||||||
|
import com.djrapitops.plan.system.tasks.SpongeTaskSystem;
|
||||||
|
import com.djrapitops.plan.system.tasks.TaskSystem;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module for binding Sponge specific classes to the interface implementations.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
@Module
|
||||||
|
public class SpongeSuperClassBindingModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ServerInfo provideSpongeServerInfo(SpongeServerInfo spongeServerInfo) {
|
||||||
|
return spongeServerInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
DBSystem provideSpongeDatabaseSystem(SpongeDBSystem dbSystem) {
|
||||||
|
return dbSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ConfigSystem provideSpongeConfigSystem(SpongeConfigSystem spongeConfigSystem) {
|
||||||
|
return spongeConfigSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
TaskSystem provideSpongeTaskSystem(SpongeTaskSystem spongeTaskSystem) {
|
||||||
|
return spongeTaskSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ListenerSystem provideSpongeListenerSystem(SpongeListenerSystem spongeListenerSystem) {
|
||||||
|
return spongeListenerSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ImportSystem provideImportSystem() {
|
||||||
|
return new EmptyImportSystem();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,68 +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.system;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.Plan;
|
|
||||||
import com.djrapitops.plan.ShutdownHook;
|
|
||||||
import com.djrapitops.plan.api.ServerAPI;
|
|
||||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
|
||||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
|
||||||
import com.djrapitops.plan.system.database.ServerDBSystem;
|
|
||||||
import com.djrapitops.plan.system.file.FileSystem;
|
|
||||||
import com.djrapitops.plan.system.info.ServerInfoSystem;
|
|
||||||
import com.djrapitops.plan.system.info.server.BukkitServerInfo;
|
|
||||||
import com.djrapitops.plan.system.listeners.BukkitListenerSystem;
|
|
||||||
import com.djrapitops.plan.system.locale.Locale;
|
|
||||||
import com.djrapitops.plan.system.settings.PlanErrorManager;
|
|
||||||
import com.djrapitops.plan.system.settings.config.ServerConfigSystem;
|
|
||||||
import com.djrapitops.plan.system.settings.network.NetworkSettings;
|
|
||||||
import com.djrapitops.plan.system.tasks.BukkitTaskSystem;
|
|
||||||
import com.djrapitops.plan.system.update.VersionCheckSystem;
|
|
||||||
import com.djrapitops.plugin.StaticHolder;
|
|
||||||
import com.djrapitops.plugin.api.utility.log.Log;
|
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents PlanSystem for Plan.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
public class BukkitSystem extends PlanSystem implements ServerSystem {
|
|
||||||
|
|
||||||
public BukkitSystem(Plan plugin) {
|
|
||||||
setTestSystem(this);
|
|
||||||
|
|
||||||
Log.setErrorManager(new PlanErrorManager());
|
|
||||||
|
|
||||||
Supplier<Locale> localeSupplier = () -> getLocaleSystem().getLocale();
|
|
||||||
|
|
||||||
versionCheckSystem = new VersionCheckSystem(plugin.getVersion(), localeSupplier);
|
|
||||||
fileSystem = new FileSystem(plugin);
|
|
||||||
configSystem = new ServerConfigSystem();
|
|
||||||
databaseSystem = new ServerDBSystem(localeSupplier);
|
|
||||||
listenerSystem = new BukkitListenerSystem(plugin);
|
|
||||||
taskSystem = new BukkitTaskSystem(plugin);
|
|
||||||
|
|
||||||
infoSystem = new ServerInfoSystem(localeSupplier);
|
|
||||||
serverInfo = new BukkitServerInfo(plugin);
|
|
||||||
|
|
||||||
hookHandler = new HookHandler();
|
|
||||||
planAPI = new ServerAPI(this);
|
|
||||||
|
|
||||||
StaticHolder.saveInstance(ShutdownHook.class, plugin.getClass());
|
|
||||||
new ShutdownHook().register();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BukkitSystem getInstance() {
|
|
||||||
return Plan.getInstance().getSystem();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void enable() throws EnableException {
|
|
||||||
super.enable();
|
|
||||||
NetworkSettings.loadSettingsFromDB();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,70 +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.system;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanBungee;
|
|
||||||
import com.djrapitops.plan.api.BungeeAPI;
|
|
||||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
|
||||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
|
||||||
import com.djrapitops.plan.system.cache.ProxyCacheSystem;
|
|
||||||
import com.djrapitops.plan.system.database.ProxyDBSystem;
|
|
||||||
import com.djrapitops.plan.system.database.DBSystem;
|
|
||||||
import com.djrapitops.plan.system.file.FileSystem;
|
|
||||||
import com.djrapitops.plan.system.info.ProxyInfoSystem;
|
|
||||||
import com.djrapitops.plan.system.info.server.BungeeServerInfo;
|
|
||||||
import com.djrapitops.plan.system.listeners.BungeeListenerSystem;
|
|
||||||
import com.djrapitops.plan.system.locale.Locale;
|
|
||||||
import com.djrapitops.plan.system.settings.PlanErrorManager;
|
|
||||||
import com.djrapitops.plan.system.settings.config.BungeeConfigSystem;
|
|
||||||
import com.djrapitops.plan.system.settings.network.NetworkSettings;
|
|
||||||
import com.djrapitops.plan.system.tasks.BungeeTaskSystem;
|
|
||||||
import com.djrapitops.plan.system.update.VersionCheckSystem;
|
|
||||||
import com.djrapitops.plugin.api.utility.log.Log;
|
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents PlanSystem for PlanBungee.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
public class BungeeSystem extends PlanSystem {
|
|
||||||
|
|
||||||
public BungeeSystem(PlanBungee plugin) {
|
|
||||||
setTestSystem(this);
|
|
||||||
|
|
||||||
Log.setErrorManager(new PlanErrorManager());
|
|
||||||
|
|
||||||
Supplier<Locale> localeSupplier = () -> getLocaleSystem().getLocale();
|
|
||||||
|
|
||||||
versionCheckSystem = new VersionCheckSystem(plugin.getVersion(), localeSupplier);
|
|
||||||
fileSystem = new FileSystem(plugin);
|
|
||||||
configSystem = new BungeeConfigSystem();
|
|
||||||
databaseSystem = new ProxyDBSystem(localeSupplier);
|
|
||||||
cacheSystem = new ProxyCacheSystem(this);
|
|
||||||
listenerSystem = new BungeeListenerSystem(plugin);
|
|
||||||
taskSystem = new BungeeTaskSystem(plugin);
|
|
||||||
|
|
||||||
infoSystem = new ProxyInfoSystem();
|
|
||||||
serverInfo = new BungeeServerInfo(plugin);
|
|
||||||
|
|
||||||
hookHandler = new HookHandler();
|
|
||||||
planAPI = new BungeeAPI(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BungeeSystem getInstance() {
|
|
||||||
return PlanBungee.getInstance().getSystem();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDatabaseSystem(DBSystem dbSystem) {
|
|
||||||
this.databaseSystem = dbSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void enable() throws EnableException {
|
|
||||||
super.enable();
|
|
||||||
NetworkSettings.placeSettingsToDB();
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.djrapitops.plan.system;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Identifiers for different Debug channels.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public class DebugChannels {
|
||||||
|
|
||||||
|
public static final String ANALYSIS = "Analysis";
|
||||||
|
public static final String INFO_REQUESTS = "InfoRequests";
|
||||||
|
public static final String CONNECTIONS = "Connections";
|
||||||
|
public static final String WEB_REQUESTS = "Web Requests";
|
||||||
|
public static final String IMPORTING = "Importing";
|
||||||
|
public static final String SQL = "SQL";
|
||||||
|
|
||||||
|
}
|
@ -9,22 +9,23 @@ import com.djrapitops.plan.api.exceptions.EnableException;
|
|||||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
import com.djrapitops.plan.data.plugin.HookHandler;
|
||||||
import com.djrapitops.plan.system.cache.CacheSystem;
|
import com.djrapitops.plan.system.cache.CacheSystem;
|
||||||
import com.djrapitops.plan.system.database.DBSystem;
|
import com.djrapitops.plan.system.database.DBSystem;
|
||||||
import com.djrapitops.plan.system.file.FileSystem;
|
import com.djrapitops.plan.system.export.ExportSystem;
|
||||||
|
import com.djrapitops.plan.system.file.PlanFiles;
|
||||||
|
import com.djrapitops.plan.system.importing.ImportSystem;
|
||||||
import com.djrapitops.plan.system.info.InfoSystem;
|
import com.djrapitops.plan.system.info.InfoSystem;
|
||||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||||
import com.djrapitops.plan.system.listeners.ListenerSystem;
|
import com.djrapitops.plan.system.listeners.ListenerSystem;
|
||||||
import com.djrapitops.plan.system.locale.Locale;
|
|
||||||
import com.djrapitops.plan.system.locale.LocaleSystem;
|
import com.djrapitops.plan.system.locale.LocaleSystem;
|
||||||
import com.djrapitops.plan.system.processing.Processing;
|
import com.djrapitops.plan.system.processing.Processing;
|
||||||
import com.djrapitops.plan.system.settings.config.ConfigSystem;
|
import com.djrapitops.plan.system.settings.config.ConfigSystem;
|
||||||
import com.djrapitops.plan.system.tasks.TaskSystem;
|
import com.djrapitops.plan.system.tasks.TaskSystem;
|
||||||
import com.djrapitops.plan.system.update.VersionCheckSystem;
|
import com.djrapitops.plan.system.update.VersionCheckSystem;
|
||||||
import com.djrapitops.plan.system.webserver.WebServerSystem;
|
import com.djrapitops.plan.system.webserver.WebServerSystem;
|
||||||
import com.djrapitops.plugin.api.Check;
|
import com.djrapitops.plugin.logging.L;
|
||||||
import com.djrapitops.plugin.api.utility.log.Log;
|
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlanSystem contains everything Plan needs to run.
|
* PlanSystem contains everything Plan needs to run.
|
||||||
@ -33,67 +34,77 @@ import java.util.function.Supplier;
|
|||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public abstract class PlanSystem implements SubSystem {
|
@Singleton
|
||||||
|
public class PlanSystem implements SubSystem {
|
||||||
|
|
||||||
protected static PlanSystem testSystem;
|
private final PlanFiles files;
|
||||||
|
private final ConfigSystem configSystem;
|
||||||
|
private final VersionCheckSystem versionCheckSystem;
|
||||||
|
private final LocaleSystem localeSystem;
|
||||||
|
private final DBSystem databaseSystem;
|
||||||
|
private final CacheSystem cacheSystem;
|
||||||
|
private final ListenerSystem listenerSystem;
|
||||||
|
private final TaskSystem taskSystem;
|
||||||
|
private final InfoSystem infoSystem;
|
||||||
|
private final ServerInfo serverInfo;
|
||||||
|
private final WebServerSystem webServerSystem;
|
||||||
|
|
||||||
// Initialized in this class
|
private final Processing processing;
|
||||||
private Processing processing;
|
|
||||||
protected final WebServerSystem webServerSystem;
|
|
||||||
protected final LocaleSystem localeSystem;
|
|
||||||
protected CacheSystem cacheSystem;
|
|
||||||
|
|
||||||
// These need to be initialized in the sub class.
|
private final ImportSystem importSystem;
|
||||||
protected VersionCheckSystem versionCheckSystem;
|
private final ExportSystem exportSystem;
|
||||||
protected FileSystem fileSystem;
|
private final HookHandler hookHandler;
|
||||||
protected ConfigSystem configSystem;
|
private final PlanAPI planAPI;
|
||||||
protected DBSystem databaseSystem;
|
private final ErrorHandler errorHandler;
|
||||||
protected InfoSystem infoSystem;
|
|
||||||
|
|
||||||
protected ListenerSystem listenerSystem;
|
@Inject
|
||||||
protected TaskSystem taskSystem;
|
public PlanSystem(
|
||||||
protected ServerInfo serverInfo;
|
PlanFiles files,
|
||||||
|
ConfigSystem configSystem,
|
||||||
protected HookHandler hookHandler;
|
VersionCheckSystem versionCheckSystem,
|
||||||
|
LocaleSystem localeSystem,
|
||||||
// Not a SubSystem.
|
DBSystem databaseSystem,
|
||||||
protected PlanAPI planAPI;
|
CacheSystem cacheSystem,
|
||||||
|
ListenerSystem listenerSystem,
|
||||||
public PlanSystem() {
|
TaskSystem taskSystem,
|
||||||
Supplier<Locale> localeSupplier = () -> getLocaleSystem().getLocale();
|
InfoSystem infoSystem,
|
||||||
|
ServerInfo serverInfo,
|
||||||
processing = new Processing(localeSupplier);
|
WebServerSystem webServerSystem,
|
||||||
webServerSystem = new WebServerSystem(localeSupplier);
|
Processing processing,
|
||||||
localeSystem = new LocaleSystem();
|
ImportSystem importSystem,
|
||||||
cacheSystem = new CacheSystem(this);
|
ExportSystem exportSystem,
|
||||||
}
|
HookHandler hookHandler,
|
||||||
|
PlanAPI planAPI,
|
||||||
public static PlanSystem getInstance() {
|
ErrorHandler errorHandler
|
||||||
boolean bukkitAvailable = Check.isBukkitAvailable();
|
) {
|
||||||
boolean bungeeAvailable = Check.isBungeeAvailable();
|
this.files = files;
|
||||||
boolean spongeAvailable = Check.isSpongeAvailable();
|
this.configSystem = configSystem;
|
||||||
if (bukkitAvailable && bungeeAvailable) {
|
this.versionCheckSystem = versionCheckSystem;
|
||||||
return testSystem;
|
this.localeSystem = localeSystem;
|
||||||
} else if (bungeeAvailable) {
|
this.databaseSystem = databaseSystem;
|
||||||
return BungeeSystem.getInstance();
|
this.cacheSystem = cacheSystem;
|
||||||
} else if (bukkitAvailable) {
|
this.listenerSystem = listenerSystem;
|
||||||
return BukkitSystem.getInstance();
|
this.taskSystem = taskSystem;
|
||||||
} else if (spongeAvailable) {
|
this.infoSystem = infoSystem;
|
||||||
return SpongeSystem.getInstance();
|
this.serverInfo = serverInfo;
|
||||||
}
|
this.webServerSystem = webServerSystem;
|
||||||
throw new IllegalAccessError("PlanSystem is not available on this platform.");
|
this.processing = processing;
|
||||||
|
this.importSystem = importSystem;
|
||||||
|
this.exportSystem = exportSystem;
|
||||||
|
this.hookHandler = hookHandler;
|
||||||
|
this.planAPI = planAPI;
|
||||||
|
this.errorHandler = errorHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enable() throws EnableException {
|
public void enable() throws EnableException {
|
||||||
checkSubSystemInitialization();
|
|
||||||
|
|
||||||
enableSystems(
|
enableSystems(
|
||||||
fileSystem,
|
files,
|
||||||
configSystem,
|
configSystem,
|
||||||
localeSystem,
|
localeSystem,
|
||||||
versionCheckSystem,
|
versionCheckSystem,
|
||||||
databaseSystem,
|
databaseSystem,
|
||||||
|
exportSystem,
|
||||||
webServerSystem,
|
webServerSystem,
|
||||||
processing,
|
processing,
|
||||||
serverInfo,
|
serverInfo,
|
||||||
@ -118,6 +129,7 @@ public abstract class PlanSystem implements SubSystem {
|
|||||||
hookHandler,
|
hookHandler,
|
||||||
cacheSystem,
|
cacheSystem,
|
||||||
listenerSystem,
|
listenerSystem,
|
||||||
|
exportSystem,
|
||||||
processing,
|
processing,
|
||||||
databaseSystem,
|
databaseSystem,
|
||||||
webServerSystem,
|
webServerSystem,
|
||||||
@ -125,7 +137,7 @@ public abstract class PlanSystem implements SubSystem {
|
|||||||
serverInfo,
|
serverInfo,
|
||||||
localeSystem,
|
localeSystem,
|
||||||
configSystem,
|
configSystem,
|
||||||
fileSystem,
|
files,
|
||||||
versionCheckSystem
|
versionCheckSystem
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -137,29 +149,11 @@ public abstract class PlanSystem implements SubSystem {
|
|||||||
system.disable();
|
system.disable();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.toLog(this.getClass(), e);
|
errorHandler.log(L.WARN, this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkSubSystemInitialization() throws EnableException {
|
|
||||||
try {
|
|
||||||
Verify.nullCheck(versionCheckSystem, () -> new IllegalStateException("Version Check system was not initialized."));
|
|
||||||
Verify.nullCheck(fileSystem, () -> new IllegalStateException("File system was not initialized."));
|
|
||||||
Verify.nullCheck(configSystem, () -> new IllegalStateException("Config system was not initialized."));
|
|
||||||
Verify.nullCheck(localeSystem, () -> new IllegalStateException("Locale system was not initialized."));
|
|
||||||
Verify.nullCheck(databaseSystem, () -> new IllegalStateException("Database system was not initialized."));
|
|
||||||
Verify.nullCheck(infoSystem, () -> new IllegalStateException("Info system was not initialized."));
|
|
||||||
Verify.nullCheck(serverInfo, () -> new IllegalStateException("ServerInfo was not initialized."));
|
|
||||||
Verify.nullCheck(listenerSystem, () -> new IllegalStateException("Listener system was not initialized."));
|
|
||||||
Verify.nullCheck(taskSystem, () -> new IllegalStateException("Task system was not initialized."));
|
|
||||||
Verify.nullCheck(hookHandler, () -> new IllegalStateException("Plugin Hooks were not initialized."));
|
|
||||||
Verify.nullCheck(planAPI, () -> new IllegalStateException("Plan API was not initialized."));
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new EnableException("One of the subsystems is not initialized on enable for " + this.getClass().getSimpleName() + ": " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Accessor methods.
|
// Accessor methods.
|
||||||
|
|
||||||
public VersionCheckSystem getVersionCheckSystem() {
|
public VersionCheckSystem getVersionCheckSystem() {
|
||||||
@ -170,8 +164,8 @@ public abstract class PlanSystem implements SubSystem {
|
|||||||
return configSystem;
|
return configSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileSystem getFileSystem() {
|
public PlanFiles getPlanFiles() {
|
||||||
return fileSystem;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DBSystem getDatabaseSystem() {
|
public DBSystem getDatabaseSystem() {
|
||||||
@ -190,6 +184,14 @@ public abstract class PlanSystem implements SubSystem {
|
|||||||
return webServerSystem;
|
return webServerSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ImportSystem getImportSystem() {
|
||||||
|
return importSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExportSystem getExportSystem() {
|
||||||
|
return exportSystem;
|
||||||
|
}
|
||||||
|
|
||||||
public ServerInfo getServerInfo() {
|
public ServerInfo getServerInfo() {
|
||||||
return serverInfo;
|
return serverInfo;
|
||||||
}
|
}
|
||||||
@ -214,10 +216,6 @@ public abstract class PlanSystem implements SubSystem {
|
|||||||
return processing;
|
return processing;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setTestSystem(PlanSystem testSystem) {
|
|
||||||
PlanSystem.testSystem = testSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocaleSystem getLocaleSystem() {
|
public LocaleSystem getLocaleSystem() {
|
||||||
return localeSystem;
|
return localeSystem;
|
||||||
}
|
}
|
||||||
|
@ -1,68 +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.system;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanSponge;
|
|
||||||
import com.djrapitops.plan.ShutdownHook;
|
|
||||||
import com.djrapitops.plan.api.ServerAPI;
|
|
||||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
|
||||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
|
||||||
import com.djrapitops.plan.system.database.ServerDBSystem;
|
|
||||||
import com.djrapitops.plan.system.file.FileSystem;
|
|
||||||
import com.djrapitops.plan.system.info.ServerInfoSystem;
|
|
||||||
import com.djrapitops.plan.system.info.server.SpongeServerInfo;
|
|
||||||
import com.djrapitops.plan.system.listeners.SpongeListenerSystem;
|
|
||||||
import com.djrapitops.plan.system.locale.Locale;
|
|
||||||
import com.djrapitops.plan.system.settings.PlanErrorManager;
|
|
||||||
import com.djrapitops.plan.system.settings.config.SpongeConfigSystem;
|
|
||||||
import com.djrapitops.plan.system.settings.network.NetworkSettings;
|
|
||||||
import com.djrapitops.plan.system.tasks.SpongeTaskSystem;
|
|
||||||
import com.djrapitops.plan.system.update.VersionCheckSystem;
|
|
||||||
import com.djrapitops.plugin.StaticHolder;
|
|
||||||
import com.djrapitops.plugin.api.utility.log.Log;
|
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents PlanSystem for PlanSponge.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
public class SpongeSystem extends PlanSystem implements ServerSystem {
|
|
||||||
|
|
||||||
public SpongeSystem(PlanSponge plugin) {
|
|
||||||
setTestSystem(this);
|
|
||||||
|
|
||||||
Supplier<Locale> localeSupplier = () -> getLocaleSystem().getLocale();
|
|
||||||
|
|
||||||
Log.setErrorManager(new PlanErrorManager());
|
|
||||||
|
|
||||||
versionCheckSystem = new VersionCheckSystem(plugin.getVersion(), localeSupplier);
|
|
||||||
fileSystem = new FileSystem(plugin);
|
|
||||||
configSystem = new SpongeConfigSystem();
|
|
||||||
databaseSystem = new ServerDBSystem(localeSupplier);
|
|
||||||
listenerSystem = new SpongeListenerSystem(plugin);
|
|
||||||
taskSystem = new SpongeTaskSystem(plugin);
|
|
||||||
|
|
||||||
infoSystem = new ServerInfoSystem(localeSupplier);
|
|
||||||
serverInfo = new SpongeServerInfo();
|
|
||||||
|
|
||||||
hookHandler = new HookHandler();
|
|
||||||
planAPI = new ServerAPI(this);
|
|
||||||
|
|
||||||
StaticHolder.saveInstance(ShutdownHook.class, plugin.getClass());
|
|
||||||
new ShutdownHook().register();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SpongeSystem getInstance() {
|
|
||||||
return PlanSponge.getInstance().getSystem();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void enable() throws EnableException {
|
|
||||||
super.enable();
|
|
||||||
NetworkSettings.loadSettingsFromDB();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,72 +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.system;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanVelocity;
|
|
||||||
import com.djrapitops.plan.api.VelocityAPI;
|
|
||||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
|
||||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
|
||||||
import com.djrapitops.plan.system.cache.ProxyCacheSystem;
|
|
||||||
import com.djrapitops.plan.system.database.DBSystem;
|
|
||||||
import com.djrapitops.plan.system.database.ProxyDBSystem;
|
|
||||||
import com.djrapitops.plan.system.file.FileSystem;
|
|
||||||
import com.djrapitops.plan.system.info.ProxyInfoSystem;
|
|
||||||
import com.djrapitops.plan.system.info.server.VelocityServerInfo;
|
|
||||||
import com.djrapitops.plan.system.listeners.VelocityListenerSystem;
|
|
||||||
import com.djrapitops.plan.system.locale.Locale;
|
|
||||||
import com.djrapitops.plan.system.settings.PlanErrorManager;
|
|
||||||
import com.djrapitops.plan.system.settings.config.BungeeConfigSystem;
|
|
||||||
import com.djrapitops.plan.system.settings.network.NetworkSettings;
|
|
||||||
import com.djrapitops.plan.system.tasks.VelocityTaskSystem;
|
|
||||||
import com.djrapitops.plan.system.update.VersionCheckSystem;
|
|
||||||
import com.djrapitops.plugin.api.utility.log.Log;
|
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents PlanSystem for PlanVelocity.
|
|
||||||
*
|
|
||||||
* Based on BungeeSystem
|
|
||||||
*
|
|
||||||
* @author MicleBrick
|
|
||||||
*/
|
|
||||||
public class VelocitySystem extends PlanSystem {
|
|
||||||
|
|
||||||
public VelocitySystem(PlanVelocity plugin) {
|
|
||||||
setTestSystem(this);
|
|
||||||
|
|
||||||
Log.setErrorManager(new PlanErrorManager());
|
|
||||||
|
|
||||||
Supplier<Locale> localeSupplier = () -> getLocaleSystem().getLocale();
|
|
||||||
|
|
||||||
versionCheckSystem = new VersionCheckSystem(plugin.getVersion(), localeSupplier);
|
|
||||||
fileSystem = new FileSystem(plugin);
|
|
||||||
configSystem = new BungeeConfigSystem(); // not sure if this needs to be different for velocity
|
|
||||||
databaseSystem = new ProxyDBSystem(localeSupplier);
|
|
||||||
cacheSystem = new ProxyCacheSystem(this);
|
|
||||||
listenerSystem = new VelocityListenerSystem(plugin);
|
|
||||||
taskSystem = new VelocityTaskSystem(plugin);
|
|
||||||
|
|
||||||
infoSystem = new ProxyInfoSystem();
|
|
||||||
serverInfo = new VelocityServerInfo(plugin);
|
|
||||||
|
|
||||||
hookHandler = new HookHandler();
|
|
||||||
planAPI = new VelocityAPI(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static VelocitySystem getInstance() {
|
|
||||||
return PlanVelocity.getInstance().getSystem();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDatabaseSystem(DBSystem dbSystem) {
|
|
||||||
this.databaseSystem = dbSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void enable() throws EnableException {
|
|
||||||
super.enable();
|
|
||||||
NetworkSettings.placeSettingsToDB();
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,9 +3,10 @@ package com.djrapitops.plan.system.afk;
|
|||||||
import com.djrapitops.plan.data.container.Session;
|
import com.djrapitops.plan.data.container.Session;
|
||||||
import com.djrapitops.plan.system.cache.SessionCache;
|
import com.djrapitops.plan.system.cache.SessionCache;
|
||||||
import com.djrapitops.plan.system.settings.Settings;
|
import com.djrapitops.plan.system.settings.Settings;
|
||||||
import com.djrapitops.plugin.api.TimeAmount;
|
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keeps track how long player has been afk during a session
|
* Keeps track how long player has been afk during a session
|
||||||
@ -18,10 +19,10 @@ public class AFKTracker {
|
|||||||
private final Map<UUID, Long> lastMovement;
|
private final Map<UUID, Long> lastMovement;
|
||||||
private final long afkThresholdMs;
|
private final long afkThresholdMs;
|
||||||
|
|
||||||
public AFKTracker() {
|
public AFKTracker(PlanConfig config) {
|
||||||
usedAFKCommand = new HashSet<>();
|
usedAFKCommand = new HashSet<>();
|
||||||
lastMovement = new HashMap<>();
|
lastMovement = new HashMap<>();
|
||||||
afkThresholdMs = Settings.AFK_THRESHOLD_MINUTES.getNumber() * TimeAmount.MINUTE.ms();
|
afkThresholdMs = TimeUnit.MINUTES.toMillis(config.getNumber(Settings.AFK_THRESHOLD_MINUTES));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hasIgnorePermission(UUID uuid) {
|
public void hasIgnorePermission(UUID uuid) {
|
||||||
|
@ -5,33 +5,26 @@
|
|||||||
package com.djrapitops.plan.system.cache;
|
package com.djrapitops.plan.system.cache;
|
||||||
|
|
||||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||||
import com.djrapitops.plan.system.PlanSystem;
|
|
||||||
import com.djrapitops.plan.system.SubSystem;
|
import com.djrapitops.plan.system.SubSystem;
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* System that holds data caches of the plugin.
|
* System that holds data caches of the plugin.
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class CacheSystem implements SubSystem {
|
public class CacheSystem implements SubSystem {
|
||||||
|
|
||||||
private final DataCache dataCache;
|
private final DataCache dataCache;
|
||||||
private final GeolocationCache geolocationCache;
|
private final GeolocationCache geolocationCache;
|
||||||
|
|
||||||
public CacheSystem(PlanSystem system) {
|
@Inject
|
||||||
this(new DataCache(system), system);
|
public CacheSystem(DataCache dataCache, GeolocationCache geolocationCache) {
|
||||||
}
|
|
||||||
|
|
||||||
protected CacheSystem(DataCache dataCache, PlanSystem system) {
|
|
||||||
this.dataCache = dataCache;
|
this.dataCache = dataCache;
|
||||||
geolocationCache = new GeolocationCache(() -> system.getLocaleSystem().getLocale());
|
this.geolocationCache = geolocationCache;
|
||||||
}
|
|
||||||
|
|
||||||
public static CacheSystem getInstance() {
|
|
||||||
CacheSystem cacheSystem = PlanSystem.getInstance().getCacheSystem();
|
|
||||||
Verify.nullCheck(cacheSystem, () -> new IllegalStateException("Cache System was not initialized."));
|
|
||||||
return cacheSystem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
package com.djrapitops.plan.system.cache;
|
package com.djrapitops.plan.system.cache;
|
||||||
|
|
||||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||||
import com.djrapitops.plan.system.PlanSystem;
|
|
||||||
import com.djrapitops.plan.system.SubSystem;
|
import com.djrapitops.plan.system.SubSystem;
|
||||||
import com.djrapitops.plan.system.database.databases.Database;
|
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.utilities.Verify;
|
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||||
|
|
||||||
import java.util.*;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This Class contains the Cache.
|
* This Class contains the Cache.
|
||||||
@ -22,24 +26,32 @@ import java.util.*;
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
* @since 4.0.0
|
* @since 4.0.0
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class DataCache extends SessionCache implements SubSystem {
|
public class DataCache extends SessionCache implements SubSystem {
|
||||||
|
|
||||||
private Database db;
|
private final ErrorHandler errorHandler;
|
||||||
|
private Database database;
|
||||||
|
|
||||||
private final Map<UUID, String> playerNames;
|
private final Map<UUID, String> playerNames;
|
||||||
private final Map<String, UUID> uuids;
|
private final Map<String, UUID> uuids;
|
||||||
private final Map<UUID, String> displayNames;
|
private final Map<UUID, String> displayNames;
|
||||||
|
|
||||||
public DataCache(PlanSystem system) {
|
@Inject
|
||||||
super(system);
|
public DataCache(
|
||||||
|
Database database,
|
||||||
|
ErrorHandler errorHandler
|
||||||
|
) {
|
||||||
|
super(database);
|
||||||
|
this.errorHandler = errorHandler;
|
||||||
playerNames = new HashMap<>();
|
playerNames = new HashMap<>();
|
||||||
displayNames = new HashMap<>();
|
displayNames = new HashMap<>();
|
||||||
uuids = new HashMap<>();
|
uuids = new HashMap<>();
|
||||||
|
|
||||||
|
this.database = database;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enable() {
|
public void enable() {
|
||||||
db = system.getDatabaseSystem().getActiveDatabase();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -49,12 +61,6 @@ public class DataCache extends SessionCache implements SubSystem {
|
|||||||
displayNames.clear();
|
displayNames.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DataCache getInstance() {
|
|
||||||
DataCache dataCache = CacheSystem.getInstance().getDataCache();
|
|
||||||
Verify.nullCheck(dataCache, () -> new IllegalStateException("Data Cache was not initialized."));
|
|
||||||
return dataCache;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to update PlayerName and DisplayName caches.
|
* Used to update PlayerName and DisplayName caches.
|
||||||
*
|
*
|
||||||
@ -87,10 +93,10 @@ public class DataCache extends SessionCache implements SubSystem {
|
|||||||
String name = playerNames.get(uuid);
|
String name = playerNames.get(uuid);
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
try {
|
try {
|
||||||
name = db.fetch().getPlayerName(uuid);
|
name = database.fetch().getPlayerName(uuid);
|
||||||
playerNames.put(uuid, name);
|
playerNames.put(uuid, name);
|
||||||
} catch (DBOpException e) {
|
} catch (DBOpException e) {
|
||||||
Log.toLog(this.getClass(), e);
|
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||||
name = "Error occurred";
|
name = "Error occurred";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -110,21 +116,17 @@ public class DataCache extends SessionCache implements SubSystem {
|
|||||||
if (cached == null) {
|
if (cached == null) {
|
||||||
List<String> nicknames;
|
List<String> nicknames;
|
||||||
try {
|
try {
|
||||||
nicknames = db.fetch().getNicknames(uuid);
|
nicknames = database.fetch().getNicknames(uuid);
|
||||||
if (!nicknames.isEmpty()) {
|
if (!nicknames.isEmpty()) {
|
||||||
return nicknames.get(nicknames.size() - 1);
|
return nicknames.get(nicknames.size() - 1);
|
||||||
}
|
}
|
||||||
} catch (DBOpException e) {
|
} catch (DBOpException e) {
|
||||||
Log.toLog(this.getClass(), e);
|
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<UUID> getUuids() {
|
|
||||||
return playerNames.keySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getUUIDof(String playerName) {
|
public UUID getUUIDof(String playerName) {
|
||||||
return uuids.get(playerName);
|
return uuids.get(playerName);
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,20 @@ package com.djrapitops.plan.system.cache;
|
|||||||
|
|
||||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||||
import com.djrapitops.plan.system.SubSystem;
|
import com.djrapitops.plan.system.SubSystem;
|
||||||
import com.djrapitops.plan.system.file.FileSystem;
|
import com.djrapitops.plan.system.file.PlanFiles;
|
||||||
import com.djrapitops.plan.system.locale.Locale;
|
import com.djrapitops.plan.system.locale.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.PluginLang;
|
import com.djrapitops.plan.system.locale.lang.PluginLang;
|
||||||
import com.djrapitops.plan.system.settings.Settings;
|
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.utilities.Verify;
|
import com.djrapitops.plugin.logging.L;
|
||||||
|
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||||
import com.maxmind.geoip2.DatabaseReader;
|
import com.maxmind.geoip2.DatabaseReader;
|
||||||
import com.maxmind.geoip2.exception.GeoIp2Exception;
|
import com.maxmind.geoip2.exception.GeoIp2Exception;
|
||||||
import com.maxmind.geoip2.model.CountryResponse;
|
import com.maxmind.geoip2.model.CountryResponse;
|
||||||
import com.maxmind.geoip2.record.Country;
|
import com.maxmind.geoip2.record.Country;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -24,7 +27,6 @@ import java.nio.channels.Channels;
|
|||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Supplier;
|
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,30 +37,45 @@ import java.util.zip.GZIPInputStream;
|
|||||||
* @author Fuzzlemann
|
* @author Fuzzlemann
|
||||||
* @since 3.5.5
|
* @since 3.5.5
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class GeolocationCache implements SubSystem {
|
public class GeolocationCache implements SubSystem {
|
||||||
|
|
||||||
private final Supplier<Locale> locale;
|
private final Locale locale;
|
||||||
|
private final PlanFiles files;
|
||||||
|
private final PlanConfig config;
|
||||||
|
private final PluginLogger logger;
|
||||||
private final Map<String, String> cached;
|
private final Map<String, String> cached;
|
||||||
|
|
||||||
private File geolocationDB;
|
private File geolocationDB;
|
||||||
|
|
||||||
public GeolocationCache(Supplier<Locale> locale) {
|
@Inject
|
||||||
|
public GeolocationCache(
|
||||||
|
Locale locale,
|
||||||
|
PlanFiles files,
|
||||||
|
PlanConfig config,
|
||||||
|
PluginLogger logger
|
||||||
|
) {
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
cached = new HashMap<>();
|
this.files = files;
|
||||||
|
this.config = config;
|
||||||
|
this.logger = logger;
|
||||||
|
|
||||||
|
this.cached = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enable() throws EnableException {
|
public void enable() throws EnableException {
|
||||||
geolocationDB = new File(FileSystem.getDataFolder(), "GeoIP.dat");
|
geolocationDB = files.getFileFromPluginFolder("GeoIP.dat");
|
||||||
if (Settings.DATA_GEOLOCATIONS.isTrue()) {
|
if (config.isTrue(Settings.DATA_GEOLOCATIONS)) {
|
||||||
try {
|
try {
|
||||||
GeolocationCache.checkDB();
|
checkDB();
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
Log.error(locale.get().getString(PluginLang.ENABLE_NOTIFY_GEOLOCATIONS_INTERNET_REQUIRED));
|
logger.error(locale.getString(PluginLang.ENABLE_NOTIFY_GEOLOCATIONS_INTERNET_REQUIRED));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new EnableException(locale.get().getString(PluginLang.ENABLE_FAIL_GEODB_WRITE), e);
|
throw new EnableException(locale.getString(PluginLang.ENABLE_FAIL_GEODB_WRITE), e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.infoColor("§e" + locale.get().getString(PluginLang.ENABLE_NOTIFY_GEOLOCATIONS_DISABLED));
|
logger.log(L.INFO_COLOR, "§e" + locale.getString(PluginLang.ENABLE_NOTIFY_GEOLOCATIONS_DISABLED));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,33 +91,27 @@ public class GeolocationCache implements SubSystem {
|
|||||||
* if that happens, "Not Known" will be returned.
|
* if that happens, "Not Known" will be returned.
|
||||||
* @see #getUnCachedCountry(String)
|
* @see #getUnCachedCountry(String)
|
||||||
*/
|
*/
|
||||||
public static String getCountry(String ipAddress) {
|
public String getCountry(String ipAddress) {
|
||||||
String country = getCachedCountry(ipAddress);
|
String country = getCachedCountry(ipAddress);
|
||||||
|
|
||||||
if (country != null) {
|
if (country != null) {
|
||||||
return country;
|
return country;
|
||||||
} else {
|
} else {
|
||||||
country = getUnCachedCountry(ipAddress);
|
country = getUnCachedCountry(ipAddress);
|
||||||
getInstance().cached.put(ipAddress, country);
|
cached.put(ipAddress, country);
|
||||||
|
|
||||||
return country;
|
return country;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static GeolocationCache getInstance() {
|
|
||||||
GeolocationCache geolocationCache = CacheSystem.getInstance().getGeolocationCache();
|
|
||||||
Verify.nullCheck(geolocationCache, () -> new IllegalStateException("GeolocationCache was not initialized."));
|
|
||||||
return geolocationCache;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the cached country
|
* Returns the cached country
|
||||||
*
|
*
|
||||||
* @param ipAddress The IP Address which is retrieved out of the cache
|
* @param ipAddress The IP Address which is retrieved out of the cache
|
||||||
* @return The cached country, {@code null} if the country is not cached
|
* @return The cached country, {@code null} if the country is not cached
|
||||||
*/
|
*/
|
||||||
private static String getCachedCountry(String ipAddress) {
|
private String getCachedCountry(String ipAddress) {
|
||||||
return getInstance().cached.get(ipAddress);
|
return cached.get(ipAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -117,14 +128,14 @@ public class GeolocationCache implements SubSystem {
|
|||||||
* @see <a href="http://maxmind.com">http://maxmind.com</a>
|
* @see <a href="http://maxmind.com">http://maxmind.com</a>
|
||||||
* @see #getCountry(String)
|
* @see #getCountry(String)
|
||||||
*/
|
*/
|
||||||
private static String getUnCachedCountry(String ipAddress) {
|
private String getUnCachedCountry(String ipAddress) {
|
||||||
if ("127.0.0.1".equals(ipAddress)) {
|
if ("127.0.0.1".equals(ipAddress)) {
|
||||||
return "Local Machine";
|
return "Local Machine";
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
checkDB();
|
checkDB();
|
||||||
|
|
||||||
try (DatabaseReader reader = new DatabaseReader.Builder(getInstance().geolocationDB).build()) {
|
try (DatabaseReader reader = new DatabaseReader.Builder(geolocationDB).build()) {
|
||||||
InetAddress inetAddress = InetAddress.getByName(ipAddress);
|
InetAddress inetAddress = InetAddress.getByName(ipAddress);
|
||||||
|
|
||||||
CountryResponse response = reader.country(inetAddress);
|
CountryResponse response = reader.country(inetAddress);
|
||||||
@ -143,8 +154,8 @@ public class GeolocationCache implements SubSystem {
|
|||||||
*
|
*
|
||||||
* @throws IOException when an error at download or saving the DB happens
|
* @throws IOException when an error at download or saving the DB happens
|
||||||
*/
|
*/
|
||||||
public static void checkDB() throws IOException {
|
private void checkDB() throws IOException {
|
||||||
if (getInstance().geolocationDB.exists()) {
|
if (geolocationDB.exists()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
URL downloadSite = new URL("http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz");
|
URL downloadSite = new URL("http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz");
|
||||||
@ -152,7 +163,7 @@ public class GeolocationCache implements SubSystem {
|
|||||||
InputStream in = downloadSite.openStream();
|
InputStream in = downloadSite.openStream();
|
||||||
GZIPInputStream gzipIn = new GZIPInputStream(in);
|
GZIPInputStream gzipIn = new GZIPInputStream(in);
|
||||||
ReadableByteChannel rbc = Channels.newChannel(gzipIn);
|
ReadableByteChannel rbc = Channels.newChannel(gzipIn);
|
||||||
FileOutputStream fos = new FileOutputStream(getInstance().geolocationDB.getAbsoluteFile())
|
FileOutputStream fos = new FileOutputStream(geolocationDB.getAbsoluteFile())
|
||||||
) {
|
) {
|
||||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||||
}
|
}
|
||||||
@ -164,8 +175,8 @@ public class GeolocationCache implements SubSystem {
|
|||||||
* @param ipAddress The IP Address which is checked
|
* @param ipAddress The IP Address which is checked
|
||||||
* @return true if the IP Address is cached
|
* @return true if the IP Address is cached
|
||||||
*/
|
*/
|
||||||
public static boolean isCached(String ipAddress) {
|
boolean isCached(String ipAddress) {
|
||||||
return getInstance().cached.containsKey(ipAddress);
|
return cached.containsKey(ipAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
package com.djrapitops.plan.system.cache;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.system.PlanSystem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CacheSystem for proxy servers.
|
|
||||||
* <p>
|
|
||||||
* Used for overriding {@link DataCache} with {@link ProxyDataCache}
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
public class ProxyCacheSystem extends CacheSystem {
|
|
||||||
|
|
||||||
public ProxyCacheSystem(PlanSystem system) {
|
|
||||||
super(new ProxyDataCache(system), system);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user