mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-08-21 20:22:45 +02: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>
|
||||
<groupId>com.djrapitops</groupId>
|
||||
<artifactId>Plan</artifactId>
|
||||
<version>4.3.0-SNAPSHOT</version>
|
||||
<version>4.5.0-SNAPSHOT</version>
|
||||
<build>
|
||||
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
|
||||
<testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
|
||||
|
@ -31,6 +31,13 @@
|
|||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>com.google.dagger</groupId>
|
||||
<artifactId>dagger-compiler</artifactId>
|
||||
<version>2.16</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
17
Plan/pom.xml
17
Plan/pom.xml
|
@ -4,7 +4,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.djrapitops</groupId>
|
||||
<artifactId>Plan</artifactId>
|
||||
<version>4.3.0-SNAPSHOT</version>
|
||||
<version>4.5.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<repositories>
|
||||
|
@ -45,7 +45,7 @@
|
|||
<dependency>
|
||||
<groupId>com.djrapitops</groupId>
|
||||
<artifactId>AbstractPluginFramework</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<version>3.3.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- SoftDepended Plugins -->
|
||||
<dependency>
|
||||
|
@ -192,6 +192,12 @@
|
|||
<version>1.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.dagger</groupId>
|
||||
<artifactId>dagger</artifactId>
|
||||
<version>2.16</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -221,6 +227,13 @@
|
|||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>com.google.dagger</groupId>
|
||||
<artifactId>dagger-compiler</artifactId>
|
||||
<version>2.16</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -21,24 +21,77 @@ package com.djrapitops.plan;
|
|||
|
||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.command.PlanCommand;
|
||||
import com.djrapitops.plan.system.BukkitSystem;
|
||||
import com.djrapitops.plan.modules.APFModule;
|
||||
import com.djrapitops.plan.modules.FilesModule;
|
||||
import com.djrapitops.plan.modules.SuperClassBindingModule;
|
||||
import com.djrapitops.plan.modules.SystemObjectBindingModule;
|
||||
import com.djrapitops.plan.modules.server.ServerSuperClassBindingModule;
|
||||
import com.djrapitops.plan.modules.server.bukkit.BukkitServerPropertiesModule;
|
||||
import com.djrapitops.plan.modules.server.bukkit.BukkitSuperClassBindingModule;
|
||||
import com.djrapitops.plan.system.PlanSystem;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.PluginLang;
|
||||
import com.djrapitops.plan.system.processing.importing.ImporterManager;
|
||||
import com.djrapitops.plan.system.processing.importing.importers.OfflinePlayerImporter;
|
||||
import com.djrapitops.plan.system.settings.theme.PlanColorScheme;
|
||||
import com.djrapitops.plan.utilities.metrics.BStatsBukkit;
|
||||
import com.djrapitops.plugin.BukkitPlugin;
|
||||
import com.djrapitops.plugin.StaticHolder;
|
||||
import com.djrapitops.plugin.api.Benchmark;
|
||||
import com.djrapitops.plugin.api.utility.log.DebugLog;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.settings.ColorScheme;
|
||||
import com.djrapitops.plugin.benchmarking.Benchmark;
|
||||
import com.djrapitops.plugin.command.ColorScheme;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import dagger.BindsInstance;
|
||||
import dagger.Component;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@Singleton
|
||||
@Component(modules = {
|
||||
BukkitPlanModule.class,
|
||||
SuperClassBindingModule.class,
|
||||
SystemObjectBindingModule.class,
|
||||
APFModule.class,
|
||||
FilesModule.class,
|
||||
BukkitServerPropertiesModule.class,
|
||||
ServerSuperClassBindingModule.class,
|
||||
BukkitSuperClassBindingModule.class
|
||||
})
|
||||
interface PlanComponent {
|
||||
|
||||
PlanCommand planCommand();
|
||||
|
||||
PlanSystem system();
|
||||
|
||||
@Component.Builder
|
||||
interface Builder {
|
||||
|
||||
@BindsInstance
|
||||
Builder plan(Plan plan);
|
||||
|
||||
PlanComponent build();
|
||||
}
|
||||
}
|
||||
|
||||
@Module
|
||||
class BukkitPlanModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
PlanPlugin providePlanPlugin(Plan plugin) {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("mainCommand")
|
||||
CommandNode provideMainCommand(PlanCommand command) {
|
||||
return command;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Main class for Bukkit that manages the plugin.
|
||||
*
|
||||
|
@ -47,55 +100,45 @@ import java.util.logging.Logger;
|
|||
*/
|
||||
public class Plan extends BukkitPlugin implements PlanPlugin {
|
||||
|
||||
private BukkitSystem system;
|
||||
private PlanSystem system;
|
||||
private Locale locale;
|
||||
|
||||
/**
|
||||
* Used to get the plugin-instance singleton.
|
||||
*
|
||||
* @return this object.
|
||||
*/
|
||||
public static Plan getInstance() {
|
||||
return (Plan) StaticHolder.getInstance(Plan.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
super.onEnable();
|
||||
PlanComponent component = DaggerPlanComponent.builder().plan(this).build();
|
||||
try {
|
||||
Benchmark.start("Enable");
|
||||
system = new BukkitSystem(this);
|
||||
timings.start("Enable");
|
||||
system = component.system();
|
||||
locale = system.getLocaleSystem().getLocale();
|
||||
system.enable();
|
||||
|
||||
ImporterManager.registerImporter(new OfflinePlayerImporter());
|
||||
|
||||
new BStatsBukkit(this).registerMetrics();
|
||||
|
||||
Log.debug("Verbose debug messages are enabled.");
|
||||
Benchmark.stop("Enable", "Enable");
|
||||
Log.logDebug("Enable");
|
||||
Log.info(locale.getString(PluginLang.ENABLED));
|
||||
logger.debug("Verbose debug messages are enabled.");
|
||||
String benchTime = " (" + timings.end("Enable").map(Benchmark::toDurationString).orElse("-") + ")";
|
||||
logger.info(locale.getString(PluginLang.ENABLED) + benchTime);
|
||||
} catch (AbstractMethodError e) {
|
||||
Log.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart.");
|
||||
logger.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart.");
|
||||
} catch (EnableException e) {
|
||||
Log.error("----------------------------------------");
|
||||
Log.error("Error: " + e.getMessage());
|
||||
Log.error("----------------------------------------");
|
||||
Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
|
||||
logger.error("----------------------------------------");
|
||||
logger.error("Error: " + e.getMessage());
|
||||
logger.error("----------------------------------------");
|
||||
logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
|
||||
onDisable();
|
||||
} catch (Exception e) {
|
||||
Logger.getGlobal().log(Level.SEVERE, this.getClass().getSimpleName() + "-v" + getVersion(), e);
|
||||
Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
|
||||
Log.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
|
||||
logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
|
||||
logger.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
|
||||
onDisable();
|
||||
}
|
||||
registerCommand("plan", new PlanCommand(this));
|
||||
PlanCommand command = component.planCommand();
|
||||
command.registerCommands();
|
||||
registerCommand("plan", command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColorScheme getColorScheme() {
|
||||
return PlanColorScheme.create();
|
||||
return PlanColorScheme.create(system.getConfigSystem().getConfig(), logger);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,11 +146,11 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
|
|||
*/
|
||||
@Override
|
||||
public void onDisable() {
|
||||
system.disable();
|
||||
if (system != null) {
|
||||
system.disable();
|
||||
}
|
||||
|
||||
Log.info(locale.getString(PluginLang.DISABLED));
|
||||
Benchmark.pluginDisabled(Plan.class);
|
||||
DebugLog.pluginDisabled(Plan.class);
|
||||
logger.info(locale != null ? locale.getString(PluginLang.DISABLED) : PluginLang.DISABLED.getDefault());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -162,7 +205,7 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BukkitSystem getSystem() {
|
||||
public PlanSystem getSystem() {
|
||||
return system;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,21 +6,74 @@ package com.djrapitops.plan;
|
|||
|
||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.command.PlanBungeeCommand;
|
||||
import com.djrapitops.plan.system.BungeeSystem;
|
||||
import com.djrapitops.plan.modules.APFModule;
|
||||
import com.djrapitops.plan.modules.FilesModule;
|
||||
import com.djrapitops.plan.modules.SuperClassBindingModule;
|
||||
import com.djrapitops.plan.modules.SystemObjectBindingModule;
|
||||
import com.djrapitops.plan.modules.proxy.ProxySuperClassBindingModule;
|
||||
import com.djrapitops.plan.modules.proxy.bungee.BungeeServerPropertiesModule;
|
||||
import com.djrapitops.plan.modules.proxy.bungee.BungeeSuperClassBindingModule;
|
||||
import com.djrapitops.plan.system.PlanSystem;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.PluginLang;
|
||||
import com.djrapitops.plan.system.settings.theme.PlanColorScheme;
|
||||
import com.djrapitops.plan.utilities.metrics.BStatsBungee;
|
||||
import com.djrapitops.plugin.BungeePlugin;
|
||||
import com.djrapitops.plugin.StaticHolder;
|
||||
import com.djrapitops.plugin.api.Benchmark;
|
||||
import com.djrapitops.plugin.api.utility.log.DebugLog;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.settings.ColorScheme;
|
||||
import com.djrapitops.plugin.command.ColorScheme;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import dagger.BindsInstance;
|
||||
import dagger.Component;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import java.io.InputStream;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@Singleton
|
||||
@Component(modules = {
|
||||
BungeePlanModule.class,
|
||||
SuperClassBindingModule.class,
|
||||
SystemObjectBindingModule.class,
|
||||
APFModule.class,
|
||||
FilesModule.class,
|
||||
ProxySuperClassBindingModule.class,
|
||||
BungeeSuperClassBindingModule.class,
|
||||
BungeeServerPropertiesModule.class
|
||||
})
|
||||
interface PlanBungeeComponent {
|
||||
|
||||
PlanBungeeCommand planCommand();
|
||||
|
||||
PlanSystem system();
|
||||
|
||||
@Component.Builder
|
||||
interface Builder {
|
||||
|
||||
@BindsInstance
|
||||
Builder plan(PlanBungee plan);
|
||||
|
||||
PlanBungeeComponent build();
|
||||
}
|
||||
}
|
||||
|
||||
@Module
|
||||
class BungeePlanModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
PlanPlugin providePlanPlugin(PlanBungee plugin) {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("mainCommand")
|
||||
CommandNode provideMainCommand(PlanBungeeCommand command) {
|
||||
return command;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bungee Main class.
|
||||
|
@ -29,48 +82,48 @@ import java.util.logging.Logger;
|
|||
*/
|
||||
public class PlanBungee extends BungeePlugin implements PlanPlugin {
|
||||
|
||||
private BungeeSystem system;
|
||||
private PlanSystem system;
|
||||
private Locale locale;
|
||||
|
||||
public static PlanBungee getInstance() {
|
||||
return (PlanBungee) StaticHolder.getInstance(PlanBungee.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
super.onEnable();
|
||||
PlanBungeeComponent component = DaggerPlanBungeeComponent.builder().plan(this).build();
|
||||
try {
|
||||
system = new BungeeSystem(this);
|
||||
system = component.system();
|
||||
locale = system.getLocaleSystem().getLocale();
|
||||
system.enable();
|
||||
|
||||
new BStatsBungee(this).registerMetrics();
|
||||
new BStatsBungee(
|
||||
this,
|
||||
system.getDatabaseSystem().getActiveDatabase(),
|
||||
system.getInfoSystem().getConnectionSystem()
|
||||
).registerMetrics();
|
||||
|
||||
Log.info(locale.getString(PluginLang.ENABLED));
|
||||
logger.info(locale.getString(PluginLang.ENABLED));
|
||||
} catch (AbstractMethodError e) {
|
||||
Log.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart.");
|
||||
logger.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart.");
|
||||
} catch (EnableException e) {
|
||||
Log.error("----------------------------------------");
|
||||
Log.error("Error: " + e.getMessage());
|
||||
Log.error("----------------------------------------");
|
||||
Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planbungee reload");
|
||||
logger.error("----------------------------------------");
|
||||
logger.error("Error: " + e.getMessage());
|
||||
logger.error("----------------------------------------");
|
||||
logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planbungee reload");
|
||||
onDisable();
|
||||
} catch (Exception e) {
|
||||
Logger.getGlobal().log(Level.SEVERE, this.getClass().getSimpleName() + "-v" + getVersion(), e);
|
||||
Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planbungee reload");
|
||||
Log.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
|
||||
errorHandler.log(L.CRITICAL, this.getClass(), e);
|
||||
logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planbungee reload");
|
||||
logger.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
|
||||
onDisable();
|
||||
}
|
||||
registerCommand("planbungee", new PlanBungeeCommand(this));
|
||||
PlanBungeeCommand command = component.planCommand();
|
||||
command.registerCommands();
|
||||
registerCommand("planbungee", command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
system.disable();
|
||||
|
||||
Log.info(locale.getString(PluginLang.DISABLED));
|
||||
Benchmark.pluginDisabled(PlanBungee.class);
|
||||
DebugLog.pluginDisabled(PlanBungee.class);
|
||||
logger.info(locale.getString(PluginLang.DISABLED));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -90,11 +143,11 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
|
|||
|
||||
@Override
|
||||
public ColorScheme getColorScheme() {
|
||||
return PlanColorScheme.create();
|
||||
return PlanColorScheme.create(system.getConfigSystem().getConfig(), logger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BungeeSystem getSystem() {
|
||||
public PlanSystem getSystem() {
|
||||
return system;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,7 @@ package com.djrapitops.plan;
|
|||
|
||||
import com.djrapitops.plan.system.PlanSystem;
|
||||
import com.djrapitops.plugin.IPlugin;
|
||||
import com.djrapitops.plugin.api.Check;
|
||||
import com.djrapitops.plugin.settings.ColorScheme;
|
||||
import com.djrapitops.plugin.command.ColorScheme;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
@ -18,39 +17,6 @@ import java.io.InputStream;
|
|||
* @author Rsl1122
|
||||
*/
|
||||
public interface PlanPlugin extends IPlugin {
|
||||
static PlanPlugin getInstance() {
|
||||
boolean bukkitAvailable = Check.isBukkitAvailable();
|
||||
boolean bungeeAvailable = Check.isBungeeAvailable();
|
||||
boolean spongeAvailable = Check.isSpongeAvailable();
|
||||
if (bukkitAvailable) {
|
||||
try {
|
||||
Plan instance = Plan.getInstance();
|
||||
if (instance != null) {
|
||||
return instance;
|
||||
}
|
||||
} catch (IllegalStateException ignored) {
|
||||
}
|
||||
}
|
||||
if (bungeeAvailable) {
|
||||
try {
|
||||
PlanBungee instance = PlanBungee.getInstance();
|
||||
if (instance != null) {
|
||||
return instance;
|
||||
}
|
||||
} catch (IllegalStateException ignored) {
|
||||
}
|
||||
}
|
||||
if (spongeAvailable) {
|
||||
try {
|
||||
PlanSponge instance = PlanSponge.getInstance();
|
||||
if (instance != null) {
|
||||
return instance;
|
||||
}
|
||||
} catch (IllegalStateException ignored) {
|
||||
}
|
||||
}
|
||||
throw new IllegalAccessError("Plugin instance not available");
|
||||
}
|
||||
|
||||
@Override
|
||||
File getDataFolder();
|
||||
|
|
|
@ -2,18 +2,26 @@ package com.djrapitops.plan;
|
|||
|
||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.command.PlanCommand;
|
||||
import com.djrapitops.plan.system.SpongeSystem;
|
||||
import com.djrapitops.plan.modules.APFModule;
|
||||
import com.djrapitops.plan.modules.FilesModule;
|
||||
import com.djrapitops.plan.modules.SuperClassBindingModule;
|
||||
import com.djrapitops.plan.modules.SystemObjectBindingModule;
|
||||
import com.djrapitops.plan.modules.server.ServerSuperClassBindingModule;
|
||||
import com.djrapitops.plan.modules.server.sponge.SpongeServerPropertiesModule;
|
||||
import com.djrapitops.plan.modules.server.sponge.SpongeSuperClassBindingModule;
|
||||
import com.djrapitops.plan.system.PlanSystem;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.PluginLang;
|
||||
import com.djrapitops.plan.system.settings.theme.PlanColorScheme;
|
||||
import com.djrapitops.plan.utilities.metrics.BStatsSponge;
|
||||
import com.djrapitops.plugin.SpongePlugin;
|
||||
import com.djrapitops.plugin.StaticHolder;
|
||||
import com.djrapitops.plugin.api.Benchmark;
|
||||
import com.djrapitops.plugin.api.utility.log.DebugLog;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.settings.ColorScheme;
|
||||
import com.google.inject.Inject;
|
||||
import com.djrapitops.plugin.command.ColorScheme;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import dagger.BindsInstance;
|
||||
import dagger.Component;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import org.bstats.sponge.Metrics;
|
||||
import org.slf4j.Logger;
|
||||
import org.spongepowered.api.config.ConfigDir;
|
||||
|
@ -23,9 +31,55 @@ import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
|
|||
import org.spongepowered.api.plugin.Dependency;
|
||||
import org.spongepowered.api.plugin.Plugin;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
@Singleton
|
||||
@Component(modules = {
|
||||
SpongePlanModule.class,
|
||||
SuperClassBindingModule.class,
|
||||
SystemObjectBindingModule.class,
|
||||
APFModule.class,
|
||||
FilesModule.class,
|
||||
ServerSuperClassBindingModule.class,
|
||||
SpongeSuperClassBindingModule.class,
|
||||
SpongeServerPropertiesModule.class
|
||||
})
|
||||
interface PlanSpongeComponent {
|
||||
|
||||
PlanCommand planCommand();
|
||||
|
||||
PlanSystem system();
|
||||
|
||||
@Component.Builder
|
||||
interface Builder {
|
||||
|
||||
@BindsInstance
|
||||
Builder plan(PlanSponge plan);
|
||||
|
||||
PlanSpongeComponent build();
|
||||
}
|
||||
}
|
||||
|
||||
@Module
|
||||
class SpongePlanModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
PlanPlugin providePlanPlugin(PlanSponge plugin) {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("mainCommand")
|
||||
CommandNode provideMainCommand(PlanCommand command) {
|
||||
return command;
|
||||
}
|
||||
}
|
||||
|
||||
@Plugin(
|
||||
id = "plan",
|
||||
name = "Plan",
|
||||
|
@ -39,16 +93,16 @@ import java.io.InputStream;
|
|||
)
|
||||
public class PlanSponge extends SpongePlugin implements PlanPlugin {
|
||||
|
||||
@Inject
|
||||
@com.google.inject.Inject
|
||||
private Metrics metrics;
|
||||
|
||||
@Inject
|
||||
private Logger logger;
|
||||
@com.google.inject.Inject
|
||||
private Logger slf4jLogger;
|
||||
|
||||
@Inject
|
||||
@com.google.inject.Inject
|
||||
@ConfigDir(sharedRoot = false)
|
||||
private File dataFolder;
|
||||
private SpongeSystem system;
|
||||
private PlanSystem system;
|
||||
private Locale locale;
|
||||
|
||||
@Listener
|
||||
|
@ -61,36 +115,37 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
|
|||
onDisable();
|
||||
}
|
||||
|
||||
public static PlanSponge getInstance() {
|
||||
return (PlanSponge) StaticHolder.getInstance(PlanSponge.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
super.onEnable();
|
||||
PlanSpongeComponent component = DaggerPlanSpongeComponent.builder().plan(this).build();
|
||||
try {
|
||||
system = new SpongeSystem(this);
|
||||
system = component.system();
|
||||
locale = system.getLocaleSystem().getLocale();
|
||||
system.enable();
|
||||
|
||||
new BStatsSponge(metrics).registerMetrics();
|
||||
new BStatsSponge(
|
||||
metrics,
|
||||
system.getDatabaseSystem().getActiveDatabase()
|
||||
).registerMetrics();
|
||||
|
||||
Log.info(locale.getString(PluginLang.ENABLED));
|
||||
slf4jLogger.info(locale.getString(PluginLang.ENABLED));
|
||||
} catch (AbstractMethodError e) {
|
||||
Log.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart.");
|
||||
slf4jLogger.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart.");
|
||||
} catch (EnableException e) {
|
||||
Log.error("----------------------------------------");
|
||||
Log.error("Error: " + e.getMessage());
|
||||
Log.error("----------------------------------------");
|
||||
Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
|
||||
slf4jLogger.error("----------------------------------------");
|
||||
slf4jLogger.error("Error: " + e.getMessage());
|
||||
slf4jLogger.error("----------------------------------------");
|
||||
slf4jLogger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
|
||||
onDisable();
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass().getSimpleName() + "-v" + getVersion(), e);
|
||||
Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
|
||||
Log.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
|
||||
errorHandler.log(L.CRITICAL, this.getClass(), e);
|
||||
slf4jLogger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
|
||||
slf4jLogger.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
|
||||
onDisable();
|
||||
}
|
||||
registerCommand("plan", new PlanCommand(this));
|
||||
PlanCommand command = component.planCommand();
|
||||
command.registerCommands();
|
||||
registerCommand("plan", command);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -99,9 +154,7 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
|
|||
system.disable();
|
||||
}
|
||||
|
||||
Log.info(locale.getString(PluginLang.DISABLED));
|
||||
Benchmark.pluginDisabled(PlanSponge.class);
|
||||
DebugLog.pluginDisabled(PlanSponge.class);
|
||||
logger.info(locale.getString(PluginLang.DISABLED));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -111,7 +164,7 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
|
|||
|
||||
@Override
|
||||
public ColorScheme getColorScheme() {
|
||||
return PlanColorScheme.create();
|
||||
return PlanColorScheme.create(system.getConfigSystem().getConfig(), logger);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -126,7 +179,7 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
|
|||
|
||||
@Override
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
return slf4jLogger;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -140,7 +193,7 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SpongeSystem getSystem() {
|
||||
public PlanSystem getSystem() {
|
||||
return system;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,29 +6,83 @@ package com.djrapitops.plan;
|
|||
|
||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.command.PlanVelocityCommand;
|
||||
import com.djrapitops.plan.system.VelocitySystem;
|
||||
import com.djrapitops.plan.modules.APFModule;
|
||||
import com.djrapitops.plan.modules.FilesModule;
|
||||
import com.djrapitops.plan.modules.SuperClassBindingModule;
|
||||
import com.djrapitops.plan.modules.SystemObjectBindingModule;
|
||||
import com.djrapitops.plan.modules.proxy.ProxySuperClassBindingModule;
|
||||
import com.djrapitops.plan.modules.proxy.velocity.VelocityServerPropertiesModule;
|
||||
import com.djrapitops.plan.modules.proxy.velocity.VelocitySuperClassBindingModule;
|
||||
import com.djrapitops.plan.system.PlanSystem;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.PluginLang;
|
||||
import com.djrapitops.plan.system.settings.theme.PlanColorScheme;
|
||||
import com.djrapitops.plugin.StaticHolder;
|
||||
import com.djrapitops.plugin.VelocityPlugin;
|
||||
import com.djrapitops.plugin.api.Benchmark;
|
||||
import com.djrapitops.plugin.api.utility.log.DebugLog;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.settings.ColorScheme;
|
||||
import com.google.inject.Inject;
|
||||
import com.djrapitops.plugin.command.ColorScheme;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import dagger.BindsInstance;
|
||||
import dagger.Component;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
|
||||
@Singleton
|
||||
@Component(modules = {
|
||||
VelocityPlanModule.class,
|
||||
SuperClassBindingModule.class,
|
||||
SystemObjectBindingModule.class,
|
||||
APFModule.class,
|
||||
FilesModule.class,
|
||||
ProxySuperClassBindingModule.class,
|
||||
VelocitySuperClassBindingModule.class,
|
||||
VelocityServerPropertiesModule.class
|
||||
})
|
||||
interface PlanVelocityComponent {
|
||||
|
||||
PlanVelocityCommand planCommand();
|
||||
|
||||
PlanSystem system();
|
||||
|
||||
@Component.Builder
|
||||
interface Builder {
|
||||
|
||||
@BindsInstance
|
||||
Builder plan(PlanVelocity plan);
|
||||
|
||||
PlanVelocityComponent build();
|
||||
}
|
||||
}
|
||||
|
||||
@Module
|
||||
class VelocityPlanModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
PlanPlugin providePlanPlugin(PlanVelocity plugin) {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("mainCommand")
|
||||
CommandNode provideMainCommand(PlanVelocityCommand command) {
|
||||
return command;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Velocity Main class.
|
||||
*
|
||||
* <p>
|
||||
* Based on the PlanBungee class
|
||||
*
|
||||
* @author MicleBrick
|
||||
|
@ -36,16 +90,16 @@ import java.nio.file.Path;
|
|||
@Plugin(id = "plan", name = "Plan", version = "4.4.6", description = "Player Analytics Plugin by Rsl1122", authors = {"Rsl1122"})
|
||||
public class PlanVelocity extends VelocityPlugin implements PlanPlugin {
|
||||
|
||||
private VelocitySystem system;
|
||||
private PlanSystem system;
|
||||
private Locale locale;
|
||||
|
||||
public static PlanVelocity getInstance() {
|
||||
return (PlanVelocity) StaticHolder.getInstance(PlanVelocity.class);
|
||||
}
|
||||
|
||||
@Inject
|
||||
@com.google.inject.Inject
|
||||
@DataDirectory
|
||||
private Path dataFolderPath;
|
||||
@com.google.inject.Inject
|
||||
private ProxyServer proxy;
|
||||
@com.google.inject.Inject
|
||||
private Logger slf4jLogger;
|
||||
|
||||
@Override
|
||||
public File getDataFolder() {
|
||||
|
@ -54,45 +108,39 @@ public class PlanVelocity extends VelocityPlugin implements PlanPlugin {
|
|||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
super.onEnable();
|
||||
PlanVelocityComponent component = DaggerPlanVelocityComponent.builder().plan(this).build();
|
||||
try {
|
||||
system = new VelocitySystem(this);
|
||||
system = component.system();
|
||||
locale = system.getLocaleSystem().getLocale();
|
||||
system.enable();
|
||||
|
||||
Log.info(locale.getString(PluginLang.ENABLED));
|
||||
logger.info(locale.getString(PluginLang.ENABLED));
|
||||
} catch (AbstractMethodError e) {
|
||||
Log.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart.");
|
||||
logger.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart.");
|
||||
} catch (EnableException e) {
|
||||
Log.error("----------------------------------------");
|
||||
Log.error("Error: " + e.getMessage());
|
||||
Log.error("----------------------------------------");
|
||||
Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planvelocity reload");
|
||||
logger.error("----------------------------------------");
|
||||
logger.error("Error: " + e.getMessage());
|
||||
logger.error("----------------------------------------");
|
||||
logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planbungee reload");
|
||||
onDisable();
|
||||
} catch (Exception e) {
|
||||
getLogger().error(this.getClass().getSimpleName() + "-v" + getVersion(), e);
|
||||
Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planvelocity reload");
|
||||
Log.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
|
||||
errorHandler.log(L.CRITICAL, this.getClass(), e);
|
||||
logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planbungee reload");
|
||||
logger.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
|
||||
onDisable();
|
||||
}
|
||||
registerCommand("planvelocity", new PlanVelocityCommand(this));
|
||||
PlanVelocityCommand command = component.planCommand();
|
||||
command.registerCommands();
|
||||
registerCommand("planvelocity", command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
system.disable();
|
||||
|
||||
Log.info(locale.getString(PluginLang.DISABLED));
|
||||
Benchmark.pluginDisabled(PlanVelocity.class);
|
||||
DebugLog.pluginDisabled(PlanVelocity.class);
|
||||
slf4jLogger.info(locale.getString(PluginLang.DISABLED));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return getClass().getAnnotation(Plugin.class).version();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onReload() {
|
||||
// Nothing to be done, systems are disabled
|
||||
|
@ -105,11 +153,11 @@ public class PlanVelocity extends VelocityPlugin implements PlanPlugin {
|
|||
|
||||
@Override
|
||||
public ColorScheme getColorScheme() {
|
||||
return PlanColorScheme.create();
|
||||
return PlanColorScheme.create(system.getConfigSystem().getConfig(), logger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VelocitySystem getSystem() {
|
||||
public PlanSystem getSystem() {
|
||||
return system;
|
||||
}
|
||||
|
||||
|
@ -118,19 +166,13 @@ public class PlanVelocity extends VelocityPlugin implements PlanPlugin {
|
|||
return reloading;
|
||||
}
|
||||
|
||||
@Inject
|
||||
private ProxyServer proxy;
|
||||
|
||||
@Override
|
||||
public ProxyServer getProxy() {
|
||||
return proxy;
|
||||
}
|
||||
|
||||
@Inject
|
||||
private Logger logger;
|
||||
|
||||
@Override
|
||||
protected Logger getLogger() {
|
||||
return logger;
|
||||
return slf4jLogger;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,8 +11,10 @@ import com.djrapitops.plan.data.container.Session;
|
|||
import com.djrapitops.plan.data.store.keys.SessionKeys;
|
||||
import com.djrapitops.plan.system.cache.SessionCache;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
@ -26,50 +28,57 @@ import java.util.UUID;
|
|||
*/
|
||||
public class ShutdownHook extends Thread {
|
||||
|
||||
private static boolean activated = false;
|
||||
private static ShutdownHook activated;
|
||||
private final Database database;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
@Inject
|
||||
public ShutdownHook(Database database, ErrorHandler errorHandler) {
|
||||
this.database = database;
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
private static boolean isActivated() {
|
||||
return activated;
|
||||
return activated != null;
|
||||
}
|
||||
|
||||
private static void activate(ShutdownHook hook) {
|
||||
activated = true;
|
||||
activated = hook;
|
||||
Runtime.getRuntime().addShutdownHook(hook);
|
||||
}
|
||||
|
||||
private static void deactivate() {
|
||||
Runtime.getRuntime().removeShutdownHook(activated);
|
||||
activated = null;
|
||||
}
|
||||
|
||||
public void register() {
|
||||
if (isActivated()) {
|
||||
return;
|
||||
deactivate();
|
||||
}
|
||||
activate(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Log.debug("Shutdown hook triggered.");
|
||||
|
||||
Database db = null;
|
||||
try {
|
||||
Map<UUID, Session> activeSessions = SessionCache.getActiveSessions();
|
||||
long now = System.currentTimeMillis();
|
||||
db = Database.getActive();
|
||||
saveActiveSessions(db, activeSessions, now);
|
||||
saveActiveSessions(activeSessions, now);
|
||||
} catch (IllegalStateException ignored) {
|
||||
/* Database is not initialized */
|
||||
} catch (DBInitException e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
} finally {
|
||||
if (db != null) {
|
||||
try {
|
||||
db.close();
|
||||
} catch (DBException e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
}
|
||||
try {
|
||||
database.close();
|
||||
} catch (DBException e) {
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void saveActiveSessions(Database db, Map<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()) {
|
||||
UUID uuid = entry.getKey();
|
||||
Session session = entry.getValue();
|
||||
|
@ -77,13 +86,13 @@ public class ShutdownHook extends Thread {
|
|||
if (!end.isPresent()) {
|
||||
session.endSession(now);
|
||||
}
|
||||
if (!db.isOpen()) {
|
||||
db.init();
|
||||
if (!database.isOpen()) {
|
||||
database.init();
|
||||
}
|
||||
try {
|
||||
db.save().session(uuid, session);
|
||||
database.save().session(uuid, session);
|
||||
} catch (DBOpException e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
}
|
||||
}
|
||||
activeSessions.clear();
|
||||
|
|
|
@ -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.utilities.uuid.UUIDUtility;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -19,6 +20,15 @@ import java.util.UUID;
|
|||
*/
|
||||
public abstract class CommonAPI implements PlanAPI {
|
||||
|
||||
private final UUIDUtility uuidUtility;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
CommonAPI(UUIDUtility uuidUtility, ErrorHandler errorHandler) {
|
||||
this.uuidUtility = uuidUtility;
|
||||
this.errorHandler = errorHandler;
|
||||
PlanAPIHolder.set(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerInspectPageLink(UUID uuid) {
|
||||
return getPlayerInspectPageLink(getPlayerName(uuid));
|
||||
|
@ -31,7 +41,7 @@ public abstract class CommonAPI implements PlanAPI {
|
|||
|
||||
@Override
|
||||
public UUID playerNameToUUID(String playerName) {
|
||||
return UUIDUtility.getUUIDOf(playerName);
|
||||
return uuidUtility.getUUIDOf(playerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,7 +49,7 @@ public abstract class CommonAPI implements PlanAPI {
|
|||
try {
|
||||
return fetchFromPlanDB().getPlayerNames();
|
||||
} catch (DBOpException e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
return new HashMap<>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
package com.djrapitops.plan.api;
|
||||
|
||||
import com.djrapitops.plan.data.plugin.PluginData;
|
||||
import com.djrapitops.plan.system.PlanSystem;
|
||||
import com.djrapitops.plan.system.database.databases.operation.FetchOperations;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
@ -19,7 +19,16 @@ import java.util.UUID;
|
|||
public interface PlanAPI {
|
||||
|
||||
static PlanAPI getInstance() {
|
||||
return PlanSystem.getInstance().getPlanAPI();
|
||||
return Optional.ofNullable(PlanAPIHolder.API)
|
||||
.orElseThrow(() -> new IllegalStateException("PlanAPI has not been initialised yet."));
|
||||
}
|
||||
|
||||
class PlanAPIHolder {
|
||||
static PlanAPI API;
|
||||
|
||||
static void set(PlanAPI api) {
|
||||
PlanAPIHolder.API = api;
|
||||
}
|
||||
}
|
||||
|
||||
void addPluginDataSource(PluginData pluginData);
|
||||
|
|
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;
|
||||
|
||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
||||
import com.djrapitops.plan.data.plugin.PluginData;
|
||||
import com.djrapitops.plan.system.ServerSystem;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.database.databases.operation.FetchOperations;
|
||||
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
@ -15,26 +20,36 @@ import java.util.UUID;
|
|||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class ServerAPI extends CommonAPI {
|
||||
|
||||
private final ServerSystem serverSystem;
|
||||
private final HookHandler hookHandler;
|
||||
private final Database database;
|
||||
|
||||
public ServerAPI(ServerSystem serverSystem) {
|
||||
this.serverSystem = serverSystem;
|
||||
@Inject
|
||||
public ServerAPI(
|
||||
UUIDUtility uuidUtility,
|
||||
HookHandler hookHandler,
|
||||
Database database,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super(uuidUtility, errorHandler);
|
||||
this.hookHandler = hookHandler;
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPluginDataSource(PluginData pluginData) {
|
||||
serverSystem.getHookHandler().addPluginDataSource(pluginData);
|
||||
hookHandler.addPluginDataSource(pluginData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerName(UUID uuid) {
|
||||
return serverSystem.getCacheSystem().getDataCache().getName(uuid);
|
||||
return database.fetch().getPlayerName(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchOperations fetchFromPlanDB() {
|
||||
return serverSystem.getDatabaseSystem().getActiveDatabase().fetch();
|
||||
return database.fetch();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.command.commands.*;
|
||||
import com.djrapitops.plan.command.commands.manage.ManageConDebugCommand;
|
||||
import com.djrapitops.plan.command.commands.manage.ManageRawDataCommand;
|
||||
|
@ -8,10 +7,14 @@ import com.djrapitops.plan.command.commands.manage.ManageUninstalledCommand;
|
|||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plugin.command.ColorScheme;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.TreeCmdNode;
|
||||
import com.djrapitops.plugin.command.defaultcmds.StatusCommand;
|
||||
import dagger.Lazy;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* TreeCommand for the /plan command, and all subcommands.
|
||||
|
@ -21,36 +24,85 @@ import com.djrapitops.plugin.command.defaultcmds.StatusCommand;
|
|||
* @author Rsl1122
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Singleton
|
||||
public class PlanBungeeCommand extends TreeCmdNode {
|
||||
|
||||
public PlanBungeeCommand(PlanPlugin plugin) {
|
||||
private final NetworkCommand networkCommand;
|
||||
private final ListServersCommand listServersCommand;
|
||||
private final ListPlayersCommand listPlayersCommand;
|
||||
private final RegisterCommand registerCommand;
|
||||
private final Lazy<WebUserCommand> 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.setColorScheme(plugin.getColorScheme());
|
||||
this.uninstalledCommand = uninstalledCommand;
|
||||
|
||||
Locale locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
commandsRegistered = false;
|
||||
|
||||
this.networkCommand = networkCommand;
|
||||
this.listServersCommand = listServersCommand;
|
||||
this.listPlayersCommand = listPlayersCommand;
|
||||
this.registerCommand = registerCommand;
|
||||
this.webUserCommand = webUserCommand;
|
||||
this.conDebugCommand = conDebugCommand;
|
||||
this.rawDataCommand = rawDataCommand;
|
||||
this.setupToggleCommand = setupToggleCommand;
|
||||
this.reloadCommand = reloadCommand;
|
||||
this.disableCommand = disableCommand;
|
||||
|
||||
setColorScheme(colorScheme);
|
||||
setInDepthHelp(locale.getArray(DeepHelpLang.PLAN));
|
||||
}
|
||||
|
||||
public void registerCommands() {
|
||||
if (commandsRegistered) {
|
||||
return;
|
||||
}
|
||||
|
||||
RegisterCommand registerCommand = new RegisterCommand(plugin);
|
||||
CommandNode[] analyticsGroup = {
|
||||
new NetworkCommand(plugin),
|
||||
new ListServersCommand(plugin),
|
||||
new ListPlayersCommand(plugin),
|
||||
networkCommand,
|
||||
listServersCommand,
|
||||
listPlayersCommand
|
||||
};
|
||||
CommandNode[] webGroup = {
|
||||
registerCommand,
|
||||
new WebUserCommand(plugin, registerCommand, this),
|
||||
webUserCommand.get()
|
||||
};
|
||||
CommandNode[] manageGroup = {
|
||||
new ManageConDebugCommand(plugin),
|
||||
new ManageRawDataCommand(plugin),
|
||||
new BungeeSetupToggleCommand(plugin),
|
||||
new ManageUninstalledCommand(plugin),
|
||||
new ReloadCommand(plugin),
|
||||
new DisableCommand(plugin),
|
||||
new StatusCommand<>(plugin, Permissions.MANAGE.getPermission(), plugin.getColorScheme()),
|
||||
// (Settings.ALLOW_UPDATE.isTrue() ? new UpdateCommand() : null)
|
||||
conDebugCommand,
|
||||
rawDataCommand,
|
||||
setupToggleCommand,
|
||||
uninstalledCommand,
|
||||
reloadCommand,
|
||||
disableCommand
|
||||
};
|
||||
setNodeGroups(analyticsGroup, webGroup, manageGroup);
|
||||
commandsRegistered = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
package com.djrapitops.plan.command;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.command.commands.*;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plugin.command.ColorScheme;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.TreeCmdNode;
|
||||
import com.djrapitops.plugin.command.defaultcmds.StatusCommand;
|
||||
import dagger.Lazy;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* TreeCommand for the /plan command, and all SubCommands.
|
||||
|
@ -19,39 +22,97 @@ import com.djrapitops.plugin.command.defaultcmds.StatusCommand;
|
|||
* @author Rsl1122
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Singleton
|
||||
public class PlanCommand extends TreeCmdNode {
|
||||
|
||||
public PlanCommand(PlanPlugin plugin) {
|
||||
private final PlanConfig config;
|
||||
private final InspectCommand inspectCommand;
|
||||
private final QInspectCommand qInspectCommand;
|
||||
private final SearchCommand searchCommand;
|
||||
private final ListPlayersCommand listPlayersCommand;
|
||||
private final AnalyzeCommand analyzeCommand;
|
||||
private final NetworkCommand networkCommand;
|
||||
private final ListServersCommand listServersCommand;
|
||||
private final Lazy<WebUserCommand> 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.setDefaultCommand("inspect");
|
||||
super.setColorScheme(plugin.getColorScheme());
|
||||
|
||||
Locale locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
commandsRegistered = false;
|
||||
|
||||
this.config = config;
|
||||
this.inspectCommand = inspectCommand;
|
||||
this.qInspectCommand = qInspectCommand;
|
||||
this.searchCommand = searchCommand;
|
||||
this.listPlayersCommand = listPlayersCommand;
|
||||
this.analyzeCommand = analyzeCommand;
|
||||
this.networkCommand = networkCommand;
|
||||
this.listServersCommand = listServersCommand;
|
||||
this.webUserCommand = webUserCommand;
|
||||
this.registerCommand = registerCommand;
|
||||
this.infoCommand = infoCommand;
|
||||
this.reloadCommand = reloadCommand;
|
||||
this.manageCommand = manageCommand;
|
||||
this.devCommand = devCommand;
|
||||
|
||||
setDefaultCommand("inspect");
|
||||
setColorScheme(colorScheme);
|
||||
setInDepthHelp(locale.getArray(DeepHelpLang.PLAN));
|
||||
}
|
||||
|
||||
public void registerCommands() {
|
||||
if (commandsRegistered) {
|
||||
return;
|
||||
}
|
||||
|
||||
RegisterCommand registerCommand = new RegisterCommand(plugin);
|
||||
CommandNode[] analyticsGroup = {
|
||||
new InspectCommand(plugin),
|
||||
new QInspectCommand(plugin),
|
||||
new SearchCommand(plugin),
|
||||
new ListPlayersCommand(plugin),
|
||||
new AnalyzeCommand(plugin),
|
||||
new NetworkCommand(plugin),
|
||||
new ListServersCommand(plugin)
|
||||
inspectCommand,
|
||||
qInspectCommand,
|
||||
searchCommand,
|
||||
listPlayersCommand,
|
||||
analyzeCommand,
|
||||
networkCommand,
|
||||
listServersCommand
|
||||
};
|
||||
CommandNode[] webGroup = {
|
||||
new WebUserCommand(plugin, registerCommand, this),
|
||||
webUserCommand.get(),
|
||||
registerCommand
|
||||
};
|
||||
CommandNode[] manageGroup = {
|
||||
new InfoCommand(plugin),
|
||||
new ReloadCommand(plugin),
|
||||
new ManageCommand(plugin, this),
|
||||
new StatusCommand<>(plugin, Permissions.MANAGE.getPermission(), plugin.getColorScheme()),
|
||||
(Settings.DEV_MODE.isTrue() ? new DevCommand(plugin) : null),
|
||||
// (Settings.ALLOW_UPDATE.isTrue() ? new UpdateCommand() : null)
|
||||
infoCommand,
|
||||
reloadCommand,
|
||||
manageCommand.get(),
|
||||
config.isTrue(Settings.DEV_MODE) ? devCommand : null
|
||||
};
|
||||
setNodeGroups(analyticsGroup, webGroup, manageGroup);
|
||||
commandsRegistered = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.djrapitops.plan.command;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.command.commands.*;
|
||||
import com.djrapitops.plan.command.commands.manage.ManageConDebugCommand;
|
||||
import com.djrapitops.plan.command.commands.manage.ManageRawDataCommand;
|
||||
|
@ -8,50 +7,102 @@ import com.djrapitops.plan.command.commands.manage.ManageUninstalledCommand;
|
|||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plugin.command.ColorScheme;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.TreeCmdNode;
|
||||
import com.djrapitops.plugin.command.defaultcmds.StatusCommand;
|
||||
import dagger.Lazy;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* TreeCommand for the /plan command, and all subcommands.
|
||||
* <p>
|
||||
* Uses the Abstract Plugin Framework for easier command management.
|
||||
*
|
||||
* Based on PlanBungeeCommand
|
||||
*
|
||||
* @author MicleBrick
|
||||
* @author Rsl1122
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Singleton
|
||||
public class PlanVelocityCommand extends TreeCmdNode {
|
||||
|
||||
public PlanVelocityCommand(PlanPlugin plugin) {
|
||||
private final NetworkCommand networkCommand;
|
||||
private final ListServersCommand listServersCommand;
|
||||
private final ListPlayersCommand listPlayersCommand;
|
||||
private final RegisterCommand registerCommand;
|
||||
private final Lazy<WebUserCommand> 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.setColorScheme(plugin.getColorScheme());
|
||||
this.uninstalledCommand = uninstalledCommand;
|
||||
|
||||
Locale locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
commandsRegistered = false;
|
||||
|
||||
this.networkCommand = networkCommand;
|
||||
this.listServersCommand = listServersCommand;
|
||||
this.listPlayersCommand = listPlayersCommand;
|
||||
this.registerCommand = registerCommand;
|
||||
this.webUserCommand = webUserCommand;
|
||||
this.conDebugCommand = conDebugCommand;
|
||||
this.rawDataCommand = rawDataCommand;
|
||||
this.setupToggleCommand = setupToggleCommand;
|
||||
this.reloadCommand = reloadCommand;
|
||||
this.disableCommand = disableCommand;
|
||||
|
||||
setColorScheme(colorScheme);
|
||||
setInDepthHelp(locale.getArray(DeepHelpLang.PLAN));
|
||||
}
|
||||
|
||||
public void registerCommands() {
|
||||
if (commandsRegistered) {
|
||||
return;
|
||||
}
|
||||
|
||||
RegisterCommand registerCommand = new RegisterCommand(plugin);
|
||||
CommandNode[] analyticsGroup = {
|
||||
new NetworkCommand(plugin),
|
||||
new ListServersCommand(plugin),
|
||||
new ListPlayersCommand(plugin),
|
||||
networkCommand,
|
||||
listServersCommand,
|
||||
listPlayersCommand
|
||||
};
|
||||
CommandNode[] webGroup = {
|
||||
registerCommand,
|
||||
new WebUserCommand(plugin, registerCommand, this),
|
||||
webUserCommand.get()
|
||||
};
|
||||
CommandNode[] manageGroup = {
|
||||
new ManageConDebugCommand(plugin),
|
||||
new ManageRawDataCommand(plugin),
|
||||
new BungeeSetupToggleCommand(plugin), // perhaps rename to ProxySetupToggleCommand ?
|
||||
new ManageUninstalledCommand(plugin),
|
||||
new ReloadCommand(plugin),
|
||||
new DisableCommand(plugin),
|
||||
new StatusCommand<>(plugin, Permissions.MANAGE.getPermission(), plugin.getColorScheme()),
|
||||
// (Settings.ALLOW_UPDATE.isTrue() ? new UpdateCommand() : null)
|
||||
conDebugCommand,
|
||||
rawDataCommand,
|
||||
setupToggleCommand,
|
||||
uninstalledCommand,
|
||||
reloadCommand,
|
||||
disableCommand
|
||||
};
|
||||
setNodeGroups(analyticsGroup, webGroup, manageGroup);
|
||||
commandsRegistered = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
|
@ -15,13 +14,16 @@ import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
|||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.webserver.WebServerSystem;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plan.system.webserver.WebServer;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.CommandUtils;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
@ -32,14 +34,38 @@ import java.util.UUID;
|
|||
* @author Rsl1122
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@Singleton
|
||||
public class AnalyzeCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final Processing processing;
|
||||
private final InfoSystem infoSystem;
|
||||
private final ServerInfo serverInfo;
|
||||
private final WebServer webServer;
|
||||
private final Database database;
|
||||
private final ConnectionSystem connectionSystem;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public AnalyzeCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public AnalyzeCommand(
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
InfoSystem infoSystem,
|
||||
ServerInfo serverInfo,
|
||||
WebServer webServer,
|
||||
Database database,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super("analyze|analyse|analysis|a", Permissions.ANALYZE.getPermission(), CommandType.CONSOLE);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
this.processing = processing;
|
||||
this.infoSystem = infoSystem;
|
||||
connectionSystem = infoSystem.getConnectionSystem();
|
||||
this.serverInfo = serverInfo;
|
||||
this.webServer = webServer;
|
||||
this.database = database;
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
setShortHelp(locale.getString(CmdHelpLang.ANALYZE));
|
||||
setInDepthHelp(locale.getArray(DeepHelpLang.ANALYZE));
|
||||
|
@ -47,27 +73,27 @@ public class AnalyzeCommand extends CommandNode {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
|
||||
|
||||
Processing.submitNonCritical(() -> {
|
||||
processing.submitNonCritical(() -> {
|
||||
try {
|
||||
Server server = getServer(args).orElseGet(ServerInfo::getServer);
|
||||
Server server = getServer(args).orElseGet(serverInfo::getServer);
|
||||
UUID serverUUID = server.getUuid();
|
||||
|
||||
InfoSystem.getInstance().generateAnalysisPage(serverUUID);
|
||||
infoSystem.generateAnalysisPage(serverUUID);
|
||||
sendWebUserNotificationIfNecessary(sender);
|
||||
sendLink(server, sender);
|
||||
} catch (DBOpException | WebException e) {
|
||||
sender.sendMessage("§cError occurred: " + e.toString());
|
||||
Log.toLog(this.getClass(), e);
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void sendLink(Server server, ISender sender) {
|
||||
private void sendLink(Server server, Sender sender) {
|
||||
String target = "/server/" + server.getName();
|
||||
String url = ConnectionSystem.getAddress() + target;
|
||||
String url = connectionSystem.getMainAddress() + target;
|
||||
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
|
||||
sender.sendMessage(locale.getString(CommandLang.HEADER_ANALYSIS));
|
||||
// Link
|
||||
|
@ -81,19 +107,17 @@ public class AnalyzeCommand extends CommandNode {
|
|||
sender.sendMessage(">");
|
||||
}
|
||||
|
||||
private void sendWebUserNotificationIfNecessary(ISender sender) {
|
||||
if (WebServerSystem.getInstance().getWebServer().isAuthRequired() && CommandUtils.isPlayer(sender)) {
|
||||
|
||||
boolean senderHasWebUser = Database.getActive().check().doesWebUserExists(sender.getName());
|
||||
if (!senderHasWebUser) {
|
||||
sender.sendMessage("§e" + locale.getString(CommandLang.NO_WEB_USER_NOTIFY));
|
||||
}
|
||||
private void sendWebUserNotificationIfNecessary(Sender sender) {
|
||||
if (webServer.isAuthRequired() &&
|
||||
CommandUtils.isPlayer(sender) &&
|
||||
!database.check().doesWebUserExists(sender.getName())) {
|
||||
sender.sendMessage("§e" + locale.getString(CommandLang.NO_WEB_USER_NOTIFY));
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<Server> getServer(String[] args) {
|
||||
if (args.length >= 1 && ConnectionSystem.getInstance().isServerAvailable()) {
|
||||
Map<UUID, Server> bukkitServers = Database.getActive().fetch().getBukkitServers();
|
||||
if (args.length >= 1 && connectionSystem.isServerAvailable()) {
|
||||
Map<UUID, Server> bukkitServers = database.fetch().getBukkitServers();
|
||||
String serverIdentifier = getGivenIdentifier(args);
|
||||
for (Map.Entry<UUID, Server> entry : bukkitServers.entrySet()) {
|
||||
Server server = entry.getValue();
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
*/
|
||||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||
|
@ -13,7 +12,9 @@ import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
|||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Command for Toggling whether or not BungeeCord accepts set up requests.
|
||||
|
@ -25,27 +26,28 @@ import com.djrapitops.plugin.command.ISender;
|
|||
public class BungeeSetupToggleCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final ConnectionSystem connectionSystem;
|
||||
|
||||
public BungeeSetupToggleCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public BungeeSetupToggleCommand(Locale locale, ConnectionSystem connectionSystem) {
|
||||
super("setup", Permissions.MANAGE.getPermission(), CommandType.ALL);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
this.connectionSystem = connectionSystem;
|
||||
|
||||
setShortHelp(locale.getString(CmdHelpLang.SETUP));
|
||||
setInDepthHelp(locale.getArray(DeepHelpLang.SETUP));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String s, String[] strings) {
|
||||
boolean setupAllowed = ConnectionSystem.isSetupAllowed();
|
||||
ConnectionSystem connectionSystem = ConnectionSystem.getInstance();
|
||||
|
||||
if (setupAllowed) {
|
||||
public void onCommand(Sender sender, String s, String[] strings) {
|
||||
if (connectionSystem.isSetupAllowed()) {
|
||||
connectionSystem.setSetupAllowed(false);
|
||||
} else {
|
||||
connectionSystem.setSetupAllowed(true);
|
||||
}
|
||||
String msg = locale.getString(!setupAllowed ? CommandLang.SETUP_ALLOWED : CommandLang.CONNECT_FORBIDDEN);
|
||||
|
||||
String msg = locale.getString(connectionSystem.isSetupAllowed() ? CommandLang.SETUP_ALLOWED : CommandLang.CONNECT_FORBIDDEN);
|
||||
sender.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,15 +4,15 @@
|
|||
*/
|
||||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
|
@ -24,17 +24,18 @@ public class DevCommand extends CommandNode {
|
|||
|
||||
private final Locale locale;
|
||||
|
||||
public DevCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public DevCommand(Locale locale) {
|
||||
super("dev", "plan.*", CommandType.PLAYER_OR_ARGS);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
|
||||
setShortHelp(locale.get(CmdHelpLang.DEV).toString());
|
||||
setArguments("<feature>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String cmd, String[] args) {
|
||||
public void onCommand(Sender sender, String cmd, String[] args) {
|
||||
Verify.isTrue(args.length >= 1,
|
||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
||||
|
||||
|
|
|
@ -7,24 +7,29 @@ import com.djrapitops.plan.system.locale.lang.CommandLang;
|
|||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class DisableCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final PlanPlugin plugin;
|
||||
|
||||
public DisableCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public DisableCommand(PlanPlugin plugin, Locale locale) {
|
||||
super("disable", "plan.reload", CommandType.ALL);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.plugin = plugin;
|
||||
this.locale = locale;
|
||||
|
||||
setShortHelp(locale.getString(CmdHelpLang.DISABLE));
|
||||
setInDepthHelp(locale.getArray(DeepHelpLang.DISABLE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
PlanPlugin.getInstance().onDisable();
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
plugin.onDisable();
|
||||
sender.sendMessage(locale.getString(CommandLang.DISABLE_DISABLED));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,9 @@ import com.djrapitops.plan.system.settings.Permissions;
|
|||
import com.djrapitops.plan.system.update.VersionCheckSystem;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* This SubCommand is used to view the version and the database type in use.
|
||||
|
@ -23,29 +25,42 @@ public class InfoCommand extends CommandNode {
|
|||
|
||||
private final PlanPlugin plugin;
|
||||
private final Locale locale;
|
||||
private final Database database;
|
||||
private final ConnectionSystem connectionSystem;
|
||||
private final VersionCheckSystem versionCheckSystem;
|
||||
|
||||
public InfoCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public InfoCommand(
|
||||
PlanPlugin plugin,
|
||||
Locale locale,
|
||||
Database database,
|
||||
ConnectionSystem connectionSystem,
|
||||
VersionCheckSystem versionCheckSystem
|
||||
) {
|
||||
super("info", Permissions.INFO.getPermission(), CommandType.CONSOLE);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.plugin = plugin;
|
||||
this.locale = locale;
|
||||
this.database = database;
|
||||
this.connectionSystem = connectionSystem;
|
||||
this.versionCheckSystem = versionCheckSystem;
|
||||
|
||||
setShortHelp(locale.get(CmdHelpLang.INFO).toString());
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
String yes = locale.getString(GenericLang.YES);
|
||||
String no = locale.getString(GenericLang.NO);
|
||||
|
||||
String updateAvailable = VersionCheckSystem.isNewVersionAvailable() ? yes : no;
|
||||
String connectedToBungee = ConnectionSystem.getInstance().isServerAvailable() ? yes : no;
|
||||
String updateAvailable = versionCheckSystem.isNewVersionAvailable() ? yes : no;
|
||||
String connectedToBungee = connectionSystem.isServerAvailable() ? yes : no;
|
||||
String[] messages = {
|
||||
locale.getString(CommandLang.HEADER_INFO),
|
||||
"",
|
||||
locale.getString(CommandLang.INFO_VERSION, plugin.getVersion()),
|
||||
locale.getString(CommandLang.INFO_UPDATE, updateAvailable),
|
||||
locale.getString(CommandLang.INFO_DATABASE, Database.getActive().getName()),
|
||||
locale.getString(CommandLang.INFO_DATABASE, database.getName()),
|
||||
locale.getString(CommandLang.INFO_BUNGEE_CONNECTION, connectedToBungee),
|
||||
"",
|
||||
">"
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.processing.processors.info.InspectCacheRequestProcessor;
|
||||
import com.djrapitops.plan.system.processing.processors.info.InfoProcessors;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.webserver.WebServer;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.CommandUtils;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
@ -32,19 +32,43 @@ import java.util.UUID;
|
|||
public class InspectCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final Database database;
|
||||
private final WebServer webServer;
|
||||
private final InfoProcessors processorFactory;
|
||||
private final Processing processing;
|
||||
private final ConnectionSystem connectionSystem;
|
||||
private final UUIDUtility uuidUtility;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public InspectCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public InspectCommand(
|
||||
Locale locale,
|
||||
InfoProcessors processorFactory,
|
||||
Processing processing,
|
||||
Database database,
|
||||
WebServer webServer,
|
||||
ConnectionSystem connectionSystem,
|
||||
UUIDUtility uuidUtility,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super("inspect", Permissions.INSPECT.getPermission(), CommandType.PLAYER_OR_ARGS);
|
||||
this.processorFactory = processorFactory;
|
||||
this.processing = processing;
|
||||
this.connectionSystem = connectionSystem;
|
||||
setArguments("<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));
|
||||
setInDepthHelp(locale.getArray(DeepHelpLang.INSPECT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
String playerName = MiscUtils.getPlayerName(args, sender);
|
||||
|
||||
if (playerName == null) {
|
||||
|
@ -54,42 +78,53 @@ public class InspectCommand extends CommandNode {
|
|||
runInspectTask(playerName, sender);
|
||||
}
|
||||
|
||||
private void runInspectTask(String playerName, ISender sender) {
|
||||
RunnableFactory.createNew(new AbsRunnable("InspectTask") {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
UUID uuid = UUIDUtility.getUUIDOf(playerName);
|
||||
if (uuid == null) {
|
||||
sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_VALID));
|
||||
return;
|
||||
}
|
||||
|
||||
Database activeDB = Database.getActive();
|
||||
if (!activeDB.check().isPlayerRegistered(uuid)) {
|
||||
sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_KNOWN));
|
||||
return;
|
||||
}
|
||||
|
||||
checkWebUserAndNotify(activeDB, sender);
|
||||
Processing.submit(new InspectCacheRequestProcessor(uuid, sender, playerName, locale));
|
||||
} catch (DBOpException e) {
|
||||
sender.sendMessage("§eDatabase exception occurred: " + e.getMessage());
|
||||
Log.toLog(this.getClass(), e);
|
||||
} finally {
|
||||
this.cancel();
|
||||
private void runInspectTask(String playerName, Sender sender) {
|
||||
processing.submitNonCritical(() -> {
|
||||
try {
|
||||
UUID uuid = uuidUtility.getUUIDOf(playerName);
|
||||
if (uuid == null) {
|
||||
sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_VALID));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!database.check().isPlayerRegistered(uuid)) {
|
||||
sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_KNOWN));
|
||||
return;
|
||||
}
|
||||
|
||||
checkWebUserAndNotify(sender);
|
||||
processing.submit(processorFactory.inspectCacheRequestProcessor(uuid, sender, playerName, this::sendInspectMsg));
|
||||
} catch (DBOpException e) {
|
||||
sender.sendMessage("§eDatabase exception occurred: " + e.getMessage());
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
});
|
||||
}
|
||||
|
||||
private void checkWebUserAndNotify(Database activeDB, ISender sender) {
|
||||
if (CommandUtils.isPlayer(sender) && WebServer.getInstance().isAuthRequired()) {
|
||||
boolean senderHasWebUser = activeDB.check().doesWebUserExists(sender.getName());
|
||||
private void checkWebUserAndNotify(Sender sender) {
|
||||
if (CommandUtils.isPlayer(sender) && webServer.isAuthRequired()) {
|
||||
boolean senderHasWebUser = database.check().doesWebUserExists(sender.getName());
|
||||
|
||||
if (!senderHasWebUser) {
|
||||
sender.sendMessage("§e" + locale.getString(CommandLang.NO_WEB_USER_NOTIFY));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void sendInspectMsg(Sender sender, String playerName) {
|
||||
sender.sendMessage(locale.getString(CommandLang.HEADER_INSPECT, playerName));
|
||||
|
||||
String url = connectionSystem.getMainAddress() + "/player/" + playerName;
|
||||
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
|
||||
|
||||
boolean console = !CommandUtils.isPlayer(sender);
|
||||
if (console) {
|
||||
sender.sendMessage(linkPrefix + url);
|
||||
} else {
|
||||
sender.sendMessage(linkPrefix);
|
||||
sender.sendLink(" ", locale.getString(CommandLang.LINK_CLICK_ME), url);
|
||||
}
|
||||
|
||||
sender.sendMessage(">");
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||
|
@ -10,7 +9,9 @@ import com.djrapitops.plan.system.settings.Permissions;
|
|||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.CommandUtils;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Command used to display url to the player list page.
|
||||
|
@ -21,26 +22,29 @@ import com.djrapitops.plugin.command.ISender;
|
|||
public class ListPlayersCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final ConnectionSystem connectionSystem;
|
||||
|
||||
public ListPlayersCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public ListPlayersCommand(Locale locale, ConnectionSystem connectionSystem) {
|
||||
super("players|pl|playerlist|list", Permissions.INSPECT_OTHER.getPermission(), CommandType.CONSOLE);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
this.connectionSystem = connectionSystem;
|
||||
|
||||
setShortHelp(locale.getString(CmdHelpLang.PLAYERS));
|
||||
setInDepthHelp(locale.getArray(DeepHelpLang.PLAYERS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
sendListMsg(sender);
|
||||
}
|
||||
|
||||
private void sendListMsg(ISender sender) {
|
||||
private void sendListMsg(Sender sender) {
|
||||
sender.sendMessage(locale.getString(CommandLang.HEADER_PLAYERS));
|
||||
|
||||
// Link
|
||||
String url = ConnectionSystem.getAddress() + "/players/";
|
||||
String url = connectionSystem.getMainAddress() + "/players/";
|
||||
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
|
||||
boolean console = !CommandUtils.isPlayer(sender);
|
||||
if (console) {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
|
@ -9,12 +8,15 @@ import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
|||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
import com.djrapitops.plugin.command.ColorScheme;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.settings.ColorScheme;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -24,35 +26,48 @@ import java.util.List;
|
|||
*/
|
||||
public class ListServersCommand extends CommandNode {
|
||||
|
||||
private final PlanPlugin plugin;
|
||||
private final Locale locale;
|
||||
private final ColorScheme colorScheme;
|
||||
private final Database database;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public ListServersCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public ListServersCommand(Locale locale, ColorScheme colorScheme, Database database, ErrorHandler errorHandler) {
|
||||
super("servers|serverlist|listservers|sl|ls", Permissions.MANAGE.getPermission(), CommandType.CONSOLE);
|
||||
this.plugin = plugin;
|
||||
|
||||
this.locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
this.colorScheme = colorScheme;
|
||||
this.database = database;
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
setShortHelp(locale.getString(CmdHelpLang.SERVERS));
|
||||
setInDepthHelp(locale.getArray(DeepHelpLang.SERVERS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
ColorScheme colorScheme = plugin.getColorScheme();
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
String sCol = colorScheme.getSecondaryColor();
|
||||
String tCol = colorScheme.getTertiaryColor();
|
||||
Formatter<Server> serverFormatter = serverLister(sCol, tCol);
|
||||
try {
|
||||
sender.sendMessage(locale.getString(CommandLang.HEADER_SERVERS));
|
||||
List<Server> servers = Database.getActive().fetch().getServers();
|
||||
for (Server server : servers) {
|
||||
sender.sendMessage(" " + tCol + server.getId() + sCol + " : " + server.getName() + " : " + server.getWebAddress());
|
||||
}
|
||||
sendServers(sender, serverFormatter);
|
||||
sender.sendMessage(">");
|
||||
} catch (DBOpException e) {
|
||||
sender.sendMessage("§cDatabase Exception occurred.");
|
||||
Log.toLog(this.getClass(), e);
|
||||
errorHandler.log(L.WARN, this.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendServers(Sender sender, Formatter<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;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.command.commands.manage.*;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plugin.command.ColorScheme;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.TreeCmdNode;
|
||||
import dagger.Lazy;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
/**
|
||||
* This SubCommand is used to manage the the plugin's database and components.
|
||||
|
@ -18,29 +22,43 @@ import com.djrapitops.plugin.command.TreeCmdNode;
|
|||
*/
|
||||
public class ManageCommand extends TreeCmdNode {
|
||||
|
||||
public ManageCommand(PlanPlugin plugin, CommandNode parent) {
|
||||
super("manage|m", Permissions.MANAGE.getPermission(), CommandType.CONSOLE, parent);
|
||||
|
||||
Locale locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
@Inject
|
||||
public ManageCommand(ColorScheme colorScheme, Locale locale, @Named("mainCommand") Lazy<CommandNode> parent,
|
||||
// Group 1
|
||||
ManageRawDataCommand rawDataCommand,
|
||||
ManageMoveCommand moveCommand,
|
||||
ManageBackupCommand backupCommand,
|
||||
ManageRemoveCommand removeCommand,
|
||||
ManageRestoreCommand restoreCommand,
|
||||
ManageHotSwapCommand hotSwapCommand,
|
||||
ManageClearCommand clearCommand,
|
||||
// Group 2
|
||||
ManageSetupCommand setupCommand,
|
||||
ManageConDebugCommand conDebugCommand,
|
||||
ManageImportCommand importCommand,
|
||||
ManageDisableCommand disableCommand,
|
||||
ManageUninstalledCommand uninstalledCommand
|
||||
) {
|
||||
super("manage|m", Permissions.MANAGE.getPermission(), CommandType.CONSOLE, parent.get());
|
||||
super.setColorScheme(colorScheme);
|
||||
|
||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE));
|
||||
setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE));
|
||||
super.setColorScheme(plugin.getColorScheme());
|
||||
CommandNode[] databaseGroup = {
|
||||
new ManageRawDataCommand(plugin),
|
||||
new ManageMoveCommand(plugin),
|
||||
new ManageBackupCommand(plugin),
|
||||
new ManageRestoreCommand(plugin),
|
||||
new ManageRemoveCommand(plugin),
|
||||
new ManageHotSwapCommand(plugin),
|
||||
new ManageClearCommand(plugin),
|
||||
rawDataCommand,
|
||||
moveCommand,
|
||||
backupCommand,
|
||||
restoreCommand,
|
||||
hotSwapCommand,
|
||||
removeCommand,
|
||||
clearCommand,
|
||||
};
|
||||
CommandNode[] pluginGroup = {
|
||||
new ManageSetupCommand(plugin),
|
||||
new ManageConDebugCommand(plugin),
|
||||
new ManageImportCommand(plugin),
|
||||
new ManageDisableCommand(plugin),
|
||||
new ManageUninstalledCommand(plugin)
|
||||
setupCommand,
|
||||
conDebugCommand,
|
||||
importCommand,
|
||||
disableCommand,
|
||||
uninstalledCommand
|
||||
};
|
||||
setNodeGroups(databaseGroup, pluginGroup);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||
|
@ -10,7 +9,9 @@ import com.djrapitops.plan.system.settings.Permissions;
|
|||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.CommandUtils;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Command used to display url to the network page.
|
||||
|
@ -20,26 +21,29 @@ import com.djrapitops.plugin.command.ISender;
|
|||
public class NetworkCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final ConnectionSystem connectionSystem;
|
||||
|
||||
public NetworkCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public NetworkCommand(Locale locale, ConnectionSystem connectionSystem) {
|
||||
super("network|n|netw", Permissions.ANALYZE.getPermission(), CommandType.CONSOLE);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
this.connectionSystem = connectionSystem;
|
||||
|
||||
setShortHelp(locale.getString(CmdHelpLang.NETWORK));
|
||||
setInDepthHelp(locale.getArray(DeepHelpLang.NETWORK));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
sendNetworkMsg(sender);
|
||||
}
|
||||
|
||||
private void sendNetworkMsg(ISender sender) {
|
||||
private void sendNetworkMsg(Sender sender) {
|
||||
sender.sendMessage(locale.getString(CommandLang.HEADER_NETWORK));
|
||||
|
||||
// Link
|
||||
String url = ConnectionSystem.getAddress() + "/network/";
|
||||
String url = connectionSystem.getMainAddress() + "/network/";
|
||||
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
|
||||
boolean console = !CommandUtils.isPlayer(sender);
|
||||
if (console) {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.data.container.GeoInfo;
|
||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
||||
|
@ -8,8 +7,6 @@ import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
|||
import com.djrapitops.plan.data.store.mutators.ActivityIndex;
|
||||
import com.djrapitops.plan.data.store.mutators.GeoInfoMutator;
|
||||
import com.djrapitops.plan.data.store.mutators.SessionsMutator;
|
||||
import com.djrapitops.plan.data.store.mutators.formatting.Formatter;
|
||||
import com.djrapitops.plan.data.store.mutators.formatting.Formatters;
|
||||
import com.djrapitops.plan.data.store.objects.DateHolder;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
|
@ -17,16 +14,22 @@ import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
|||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.GenericLang;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
@ -38,27 +41,44 @@ import java.util.UUID;
|
|||
* @author Rsl1122
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Singleton
|
||||
public class QInspectCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final Database database;
|
||||
private final PlanConfig config;
|
||||
private final Processing processing;
|
||||
private final Formatters formatters;
|
||||
private final UUIDUtility uuidUtility;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
*
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public QInspectCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public QInspectCommand(
|
||||
PlanConfig config,
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
Database database,
|
||||
UUIDUtility uuidUtility,
|
||||
Formatters formatters,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super("qinspect", Permissions.QUICK_INSPECT.getPermission(), CommandType.PLAYER_OR_ARGS);
|
||||
this.config = config;
|
||||
this.processing = processing;
|
||||
this.formatters = formatters;
|
||||
setArguments("<player>");
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
this.database = database;
|
||||
this.uuidUtility = uuidUtility;
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
setShortHelp(locale.getString(CmdHelpLang.QINSPECT));
|
||||
setInDepthHelp(locale.getArray(DeepHelpLang.QINSPECT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
String playerName = MiscUtils.getPlayerName(args, sender, Permissions.QUICK_INSPECT_OTHER);
|
||||
|
||||
if (playerName == null) {
|
||||
|
@ -69,43 +89,42 @@ public class QInspectCommand extends CommandNode {
|
|||
runInspectTask(playerName, sender);
|
||||
}
|
||||
|
||||
private void runInspectTask(String playerName, ISender sender) {
|
||||
RunnableFactory.createNew(new AbsRunnable("InspectTask") {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
UUID uuid = UUIDUtility.getUUIDOf(playerName);
|
||||
if (uuid == null) {
|
||||
sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_VALID));
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerContainer container = Database.getActive().fetch().getPlayerContainer(uuid);
|
||||
if (!container.getValue(PlayerKeys.REGISTERED).isPresent()) {
|
||||
sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_KNOWN));
|
||||
return;
|
||||
}
|
||||
|
||||
sendMessages(sender, container);
|
||||
} catch (DBOpException e) {
|
||||
sender.sendMessage("§eDatabase exception occurred: " + e.getMessage());
|
||||
Log.toLog(this.getClass(), e);
|
||||
} finally {
|
||||
this.cancel();
|
||||
private void runInspectTask(String playerName, Sender sender) {
|
||||
processing.submitNonCritical(() -> {
|
||||
try {
|
||||
UUID uuid = uuidUtility.getUUIDOf(playerName);
|
||||
if (uuid == null) {
|
||||
sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_VALID));
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerContainer container = database.fetch().getPlayerContainer(uuid);
|
||||
if (!container.getValue(PlayerKeys.REGISTERED).isPresent()) {
|
||||
sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_KNOWN));
|
||||
return;
|
||||
}
|
||||
|
||||
sendMessages(sender, container);
|
||||
} catch (DBOpException e) {
|
||||
sender.sendMessage("§eDatabase exception occurred: " + e.getMessage());
|
||||
errorHandler.log(L.WARN, this.getClass(), e);
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
});
|
||||
}
|
||||
|
||||
private void sendMessages(ISender sender, PlayerContainer player) {
|
||||
private void sendMessages(Sender sender, PlayerContainer player) {
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
Formatter<DateHolder> timestamp = Formatters.year();
|
||||
Formatter<Long> length = Formatters.timeAmount();
|
||||
Formatter<DateHolder> timestamp = formatters.year();
|
||||
Formatter<Long> length = formatters.timeAmount();
|
||||
|
||||
String playerName = player.getValue(PlayerKeys.NAME).orElse(locale.getString(GenericLang.UNKNOWN));
|
||||
|
||||
ActivityIndex activityIndex = player.getActivityIndex(now);
|
||||
ActivityIndex activityIndex = player.getActivityIndex(
|
||||
now,
|
||||
config.getNumber(Settings.ACTIVE_PLAY_THRESHOLD),
|
||||
config.getNumber(Settings.ACTIVE_LOGIN_THRESHOLD)
|
||||
);
|
||||
Long registered = player.getValue(PlayerKeys.REGISTERED).orElse(0L);
|
||||
Long lastSeen = player.getValue(PlayerKeys.LAST_SEEN).orElse(0L);
|
||||
List<GeoInfo> geoInfo = player.getValue(PlayerKeys.GEO_INFO).orElse(new ArrayList<>());
|
||||
|
@ -115,7 +134,7 @@ public class QInspectCommand extends CommandNode {
|
|||
|
||||
String[] messages = new String[]{
|
||||
locale.getString(CommandLang.HEADER_INSPECT, playerName),
|
||||
locale.getString(CommandLang.QINSPECT_ACTIVITY_INDEX, activityIndex.getFormattedValue(), activityIndex.getGroup()),
|
||||
locale.getString(CommandLang.QINSPECT_ACTIVITY_INDEX, activityIndex.getFormattedValue(formatters.decimals()), activityIndex.getGroup()),
|
||||
locale.getString(CommandLang.QINSPECT_REGISTERED, timestamp.apply(() -> registered)),
|
||||
locale.getString(CommandLang.QINSPECT_LAST_SEEN, timestamp.apply(() -> lastSeen)),
|
||||
locale.getString(CommandLang.QINSPECT_GEOLOCATION, geolocation),
|
||||
|
|
|
@ -1,24 +1,26 @@
|
|||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.data.WebUser;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.utilities.PassEncryptUtil;
|
||||
import com.djrapitops.plugin.api.Check;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.CommandUtils;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
|
@ -32,17 +34,31 @@ import java.util.Arrays;
|
|||
* @author Rsl1122
|
||||
* @since 3.5.2
|
||||
*/
|
||||
@Singleton
|
||||
public class RegisterCommand extends CommandNode {
|
||||
|
||||
private final String notEnoughArgsMsg;
|
||||
private final String hashErrorMsg;
|
||||
private final Locale locale;
|
||||
private final Processing processing;
|
||||
private final Database database;
|
||||
private final PluginLogger logger;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public RegisterCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public RegisterCommand(
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
Database database,
|
||||
PluginLogger logger,
|
||||
ErrorHandler errorHandler) {
|
||||
// No Permission Requirement
|
||||
super("register", "", CommandType.PLAYER_OR_ARGS);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
this.processing = processing;
|
||||
this.logger = logger;
|
||||
this.database = database;
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
setArguments("<password>", "[name]", "[lvl]");
|
||||
setShortHelp(locale.getString(CmdHelpLang.WEB_REGISTER));
|
||||
|
@ -52,11 +68,10 @@ public class RegisterCommand extends CommandNode {
|
|||
}
|
||||
|
||||
notEnoughArgsMsg = locale.getString(CommandLang.FAIL_REQ_ARGS, 3, Arrays.toString(getArguments()));
|
||||
hashErrorMsg = "§cPassword hash error.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
try {
|
||||
if (CommandUtils.isPlayer(sender)) {
|
||||
playerRegister(args, sender);
|
||||
|
@ -64,16 +79,16 @@ public class RegisterCommand extends CommandNode {
|
|||
consoleRegister(args, sender, notEnoughArgsMsg);
|
||||
}
|
||||
} catch (PassEncryptUtil.CannotPerformOperationException e) {
|
||||
Log.toLog(this.getClass().getSimpleName(), e);
|
||||
sender.sendMessage(hashErrorMsg);
|
||||
errorHandler.log(L.WARN, this.getClass(), e);
|
||||
sender.sendMessage("§cPassword hash error.");
|
||||
} catch (NumberFormatException e) {
|
||||
throw new NumberFormatException(args[2]);
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass().getSimpleName(), e);
|
||||
errorHandler.log(L.WARN, this.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void consoleRegister(String[] args, ISender sender, String notEnoughArgsMsg) throws PassEncryptUtil.CannotPerformOperationException {
|
||||
private void consoleRegister(String[] args, Sender sender, String notEnoughArgsMsg) throws PassEncryptUtil.CannotPerformOperationException {
|
||||
Verify.isTrue(args.length >= 3, () -> new IllegalArgumentException(notEnoughArgsMsg));
|
||||
|
||||
int permLevel;
|
||||
|
@ -82,7 +97,7 @@ public class RegisterCommand extends CommandNode {
|
|||
registerUser(new WebUser(args[1], passHash, permLevel), sender);
|
||||
}
|
||||
|
||||
private void playerRegister(String[] args, ISender sender) throws PassEncryptUtil.CannotPerformOperationException {
|
||||
private void playerRegister(String[] args, Sender sender) throws PassEncryptUtil.CannotPerformOperationException {
|
||||
boolean registerSenderAsUser = args.length == 1;
|
||||
if (registerSenderAsUser) {
|
||||
String user = sender.getName();
|
||||
|
@ -96,7 +111,7 @@ public class RegisterCommand extends CommandNode {
|
|||
}
|
||||
}
|
||||
|
||||
private int getPermissionLevel(ISender sender) {
|
||||
private int getPermissionLevel(Sender sender) {
|
||||
final String permAnalyze = Permissions.ANALYZE.getPerm();
|
||||
final String permInspectOther = Permissions.INSPECT_OTHER.getPerm();
|
||||
final String permInspect = Permissions.INSPECT.getPerm();
|
||||
|
@ -112,30 +127,22 @@ public class RegisterCommand extends CommandNode {
|
|||
return 100;
|
||||
}
|
||||
|
||||
private void registerUser(WebUser webUser, ISender sender) {
|
||||
RunnableFactory.createNew(new AbsRunnable("Register WebUser Task") {
|
||||
@Override
|
||||
public void run() {
|
||||
final String existsMsg = locale.getString(CommandLang.FAIL_WEB_USER_EXISTS);
|
||||
final String userName = webUser.getName();
|
||||
final String successMsg = locale.getString(CommandLang.WEB_USER_REGISTER_SUCCESS);
|
||||
try {
|
||||
Database database = Database.getActive();
|
||||
boolean userExists = database.check().doesWebUserExists(userName);
|
||||
if (userExists) {
|
||||
sender.sendMessage(existsMsg);
|
||||
return;
|
||||
}
|
||||
database.save().webUser(webUser);
|
||||
sender.sendMessage(successMsg);
|
||||
Log.info(locale.getString(CommandLang.WEB_USER_REGISTER_NOTIFY, userName, webUser.getPermLevel()));
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
} finally {
|
||||
this.cancel();
|
||||
private void registerUser(WebUser webUser, Sender sender) {
|
||||
processing.submitCritical(() -> {
|
||||
String userName = webUser.getName();
|
||||
try {
|
||||
boolean userExists = database.check().doesWebUserExists(userName);
|
||||
if (userExists) {
|
||||
sender.sendMessage(locale.getString(CommandLang.FAIL_WEB_USER_EXISTS));
|
||||
return;
|
||||
}
|
||||
database.save().webUser(webUser);
|
||||
sender.sendMessage(locale.getString(CommandLang.WEB_USER_REGISTER_SUCCESS));
|
||||
logger.info(locale.getString(CommandLang.WEB_USER_REGISTER_NOTIFY, userName, webUser.getPermLevel()));
|
||||
} catch (Exception e) {
|
||||
errorHandler.log(L.WARN, this.getClass(), e);
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,13 +6,16 @@ import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
|||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* This SubCommand is used to reload the plugin.
|
||||
*
|
||||
|
@ -23,26 +26,31 @@ public class ReloadCommand extends CommandNode {
|
|||
|
||||
private final PlanPlugin plugin;
|
||||
private final Locale locale;
|
||||
private final ErrorHandler errorHandler;
|
||||
private final RunnableFactory runnableFactory;
|
||||
|
||||
public ReloadCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public ReloadCommand(PlanPlugin plugin, Locale locale, RunnableFactory runnableFactory, ErrorHandler errorHandler) {
|
||||
super("reload", Permissions.RELOAD.getPermission(), CommandType.CONSOLE);
|
||||
this.plugin = plugin;
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.plugin = plugin;
|
||||
this.locale = locale;
|
||||
this.runnableFactory = runnableFactory;
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
setShortHelp(locale.getString(CmdHelpLang.RELOAD));
|
||||
setInDepthHelp(locale.getArray(DeepHelpLang.RELOAD));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
RunnableFactory.createNew("Reload task", new AbsRunnable() {
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
runnableFactory.create("Reload task", new AbsRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
plugin.reloadPlugin(true);
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
errorHandler.log(L.CRITICAL, this.getClass(), e);
|
||||
sender.sendMessage(locale.getString(CommandLang.RELOAD_FAILED));
|
||||
}
|
||||
sender.sendMessage(locale.getString(CommandLang.RELOAD_COMPLETE));
|
||||
|
|
|
@ -1,24 +1,25 @@
|
|||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import com.djrapitops.plugin.utilities.FormatUtils;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -27,14 +28,26 @@ import java.util.List;
|
|||
* @author Rsl1122
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@Singleton
|
||||
public class SearchCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final Processing processing;
|
||||
private final Database database;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public SearchCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public SearchCommand(
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
Database database,
|
||||
ErrorHandler errorHandler) {
|
||||
super("search", Permissions.SEARCH.getPermission(), CommandType.PLAYER_OR_ARGS);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
this.processing = processing;
|
||||
this.database = database;
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
setArguments("<text>");
|
||||
setShortHelp(locale.getString(CmdHelpLang.SEARCH));
|
||||
|
@ -42,7 +55,7 @@ public class SearchCommand extends CommandNode {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
Verify.isTrue(args.length >= 1,
|
||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
||||
|
||||
|
@ -51,30 +64,26 @@ public class SearchCommand extends CommandNode {
|
|||
runSearchTask(args, sender);
|
||||
}
|
||||
|
||||
private void runSearchTask(String[] args, ISender sender) {
|
||||
RunnableFactory.createNew(new AbsRunnable("SearchTask: " + Arrays.toString(args)) {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String searchTerm = args[0];
|
||||
List<String> names = MiscUtils.getMatchingPlayerNames(searchTerm);
|
||||
private void runSearchTask(String[] args, Sender sender) {
|
||||
processing.submitNonCritical(() -> {
|
||||
try {
|
||||
String searchTerm = args[0];
|
||||
List<String> names = database.search().matchingPlayers(searchTerm);
|
||||
Collections.sort(names);
|
||||
boolean empty = Verify.isEmpty(names);
|
||||
|
||||
boolean empty = Verify.isEmpty(names);
|
||||
|
||||
sender.sendMessage(locale.getString(CommandLang.HEADER_SEARCH, empty ? 0 : names.size(), searchTerm));
|
||||
// Results
|
||||
if (!empty) {
|
||||
sender.sendMessage(FormatUtils.collectionToStringNoBrackets(names));
|
||||
}
|
||||
|
||||
sender.sendMessage(">");
|
||||
} catch (DBOpException e) {
|
||||
sender.sendMessage("§cDatabase error occurred: " + e.getMessage());
|
||||
Log.toLog(this.getClass(), e);
|
||||
} finally {
|
||||
this.cancel();
|
||||
sender.sendMessage(locale.getString(CommandLang.HEADER_SEARCH, empty ? 0 : names.size(), searchTerm));
|
||||
// Results
|
||||
if (!empty) {
|
||||
String message = names.toString();
|
||||
sender.sendMessage(message.substring(1, message.length() - 1));
|
||||
}
|
||||
|
||||
sender.sendMessage(">");
|
||||
} catch (DBOpException e) {
|
||||
sender.sendMessage("§cDatabase error occurred: " + e.getMessage());
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.command.commands.webuser.WebCheckCommand;
|
||||
import com.djrapitops.plan.command.commands.webuser.WebDeleteCommand;
|
||||
import com.djrapitops.plan.command.commands.webuser.WebLevelCommand;
|
||||
|
@ -9,9 +8,14 @@ import com.djrapitops.plan.system.locale.Locale;
|
|||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plugin.command.ColorScheme;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.TreeCmdNode;
|
||||
import dagger.Lazy;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
/**
|
||||
* Web subcommand used to manage Web users.
|
||||
|
@ -21,20 +25,25 @@ import com.djrapitops.plugin.command.TreeCmdNode;
|
|||
*/
|
||||
public class WebUserCommand extends TreeCmdNode {
|
||||
|
||||
public WebUserCommand(PlanPlugin plugin, RegisterCommand register, CommandNode parent) {
|
||||
super("webuser|web", Permissions.MANAGE_WEB.getPerm(), CommandType.CONSOLE, parent);
|
||||
super.setColorScheme(plugin.getColorScheme());
|
||||
|
||||
Locale locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
@Inject
|
||||
public WebUserCommand(ColorScheme colorScheme, Locale locale, @Named("mainCommand") Lazy<CommandNode> parent,
|
||||
RegisterCommand registerCommand,
|
||||
WebLevelCommand levelCommand,
|
||||
WebListUsersCommand listUsersCommand,
|
||||
WebCheckCommand checkCommand,
|
||||
WebDeleteCommand deleteCommand
|
||||
) {
|
||||
super("webuser|web", Permissions.MANAGE_WEB.getPerm(), CommandType.CONSOLE, parent.get());
|
||||
super.setColorScheme(colorScheme);
|
||||
|
||||
setShortHelp(locale.getString(CmdHelpLang.WEB));
|
||||
setInDepthHelp(locale.getArray(DeepHelpLang.WEB));
|
||||
CommandNode[] webGroup = {
|
||||
register,
|
||||
new WebLevelCommand(plugin),
|
||||
new WebListUsersCommand(plugin),
|
||||
new WebCheckCommand(plugin),
|
||||
new WebDeleteCommand(plugin)
|
||||
registerCommand,
|
||||
levelCommand,
|
||||
listUsersCommand,
|
||||
checkCommand,
|
||||
deleteCommand
|
||||
};
|
||||
setNodeGroups(webGroup);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBInitException;
|
||||
import com.djrapitops.plan.data.store.mutators.formatting.Formatters;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.database.databases.sql.SQLiteDB;
|
||||
|
@ -12,15 +10,19 @@ import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
|||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
|
@ -31,14 +33,35 @@ import java.util.UUID;
|
|||
* @author Rsl1122
|
||||
* @since 2.3.0
|
||||
*/
|
||||
@Singleton
|
||||
public class ManageBackupCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final Processing processing;
|
||||
private final DBSystem dbSystem;
|
||||
private final SQLiteDB.Factory sqliteFactory;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public ManageBackupCommand(PlanPlugin plugin) {
|
||||
private final Formatter<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);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
this.processing = processing;
|
||||
this.dbSystem = dbSystem;
|
||||
this.sqliteFactory = sqliteFactory;
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
this.iso8601LongFormatter = formatters.iso8601NoClockLong();
|
||||
|
||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE_BACKUP));
|
||||
setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE_BACKUP));
|
||||
|
@ -47,7 +70,7 @@ public class ManageBackupCommand extends CommandNode {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
try {
|
||||
Verify.isTrue(args.length >= 1,
|
||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
||||
|
@ -58,7 +81,8 @@ public class ManageBackupCommand extends CommandNode {
|
|||
Verify.isTrue(isCorrectDB,
|
||||
() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_INCORRECT_DB, dbName)));
|
||||
|
||||
Database database = DBSystem.getActiveDatabaseByName(dbName);
|
||||
Database database = dbSystem.getActiveDatabaseByName(dbName);
|
||||
database.init();
|
||||
|
||||
runBackupTask(sender, args, database);
|
||||
} catch (DBInitException e) {
|
||||
|
@ -66,24 +90,17 @@ public class ManageBackupCommand extends CommandNode {
|
|||
}
|
||||
}
|
||||
|
||||
private void runBackupTask(ISender sender, String[] args, Database database) {
|
||||
RunnableFactory.createNew(new AbsRunnable("BackupTask") {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Log.debug("Backup", "Start");
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
|
||||
createNewBackup(args[0], database);
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
|
||||
} catch (Exception e) {
|
||||
Log.toLog(ManageBackupCommand.class, e);
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||
} finally {
|
||||
Log.logDebug("Backup");
|
||||
this.cancel();
|
||||
}
|
||||
private void runBackupTask(Sender sender, String[] args, Database database) {
|
||||
processing.submitCritical(() -> {
|
||||
try {
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
|
||||
createNewBackup(args[0], database);
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
|
||||
} catch (Exception e) {
|
||||
errorHandler.log(L.ERROR, ManageBackupCommand.class, e);
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -95,9 +112,9 @@ public class ManageBackupCommand extends CommandNode {
|
|||
private void createNewBackup(String dbName, Database copyFromDB) {
|
||||
SQLiteDB backupDB = null;
|
||||
try {
|
||||
String timeStamp = Formatters.iso8601NoClock().apply(System::currentTimeMillis);
|
||||
String timeStamp = iso8601LongFormatter.apply(System.currentTimeMillis());
|
||||
String fileName = dbName + "-backup-" + timeStamp;
|
||||
backupDB = new SQLiteDB(fileName, () -> locale);
|
||||
backupDB = sqliteFactory.usingFileCalled(fileName);
|
||||
Collection<UUID> uuids = copyFromDB.fetch().getSavedUUIDs();
|
||||
if (uuids.isEmpty()) {
|
||||
return;
|
||||
|
@ -105,7 +122,7 @@ public class ManageBackupCommand extends CommandNode {
|
|||
backupDB.init();
|
||||
copyFromDB.backup().backup(backupDB);
|
||||
} catch (DBException e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
} finally {
|
||||
if (backupDB != null) {
|
||||
backupDB.close();
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBInitException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
|
@ -10,15 +9,17 @@ import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
|||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
|
@ -27,14 +28,27 @@ import java.util.Arrays;
|
|||
* @author Rsl1122
|
||||
* @since 2.3.0
|
||||
*/
|
||||
@Singleton
|
||||
public class ManageClearCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final Processing processing;
|
||||
private final DBSystem dbSystem;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public ManageClearCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public ManageClearCommand(
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
DBSystem dbSystem,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super("clear", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
this.processing = processing;
|
||||
this.dbSystem = dbSystem;
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
setArguments("<DB>", "[-a]");
|
||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE_CLEAR));
|
||||
|
@ -42,7 +56,7 @@ public class ManageClearCommand extends CommandNode {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
Verify.isTrue(args.length >= 1,
|
||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
||||
|
||||
|
@ -58,30 +72,26 @@ public class ManageClearCommand extends CommandNode {
|
|||
}
|
||||
|
||||
try {
|
||||
Database database = DBSystem.getActiveDatabaseByName(dbName);
|
||||
Database database = dbSystem.getActiveDatabaseByName(dbName);
|
||||
database.init();
|
||||
runClearTask(sender, database);
|
||||
} catch (DBInitException e) {
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
private void runClearTask(ISender sender, Database database) {
|
||||
RunnableFactory.createNew(new AbsRunnable("DBClearTask") {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
|
||||
private void runClearTask(Sender sender, Database database) {
|
||||
processing.submitCritical(() -> {
|
||||
try {
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
|
||||
|
||||
database.remove().everything();
|
||||
database.remove().everything();
|
||||
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
|
||||
} catch (DBOpException e) {
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||
Log.toLog(this.getClass(), e);
|
||||
} finally {
|
||||
this.cancel();
|
||||
}
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
|
||||
} catch (DBOpException e) {
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.connection.*;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.InfoSystem;
|
||||
import com.djrapitops.plan.system.info.request.CheckConnectionRequest;
|
||||
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||
import com.djrapitops.plan.system.info.request.InfoRequestFactory;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
|
@ -14,13 +13,15 @@ import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
|||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.webserver.WebServerSystem;
|
||||
import com.djrapitops.plan.system.webserver.WebServer;
|
||||
import com.djrapitops.plugin.api.Check;
|
||||
import com.djrapitops.plugin.command.ColorScheme;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.settings.ColorScheme;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -30,20 +31,45 @@ import java.util.UUID;
|
|||
* @author Rsl1122
|
||||
* @since 2.3.0
|
||||
*/
|
||||
@Singleton
|
||||
public class ManageConDebugCommand extends CommandNode {
|
||||
|
||||
private final ColorScheme colorScheme;
|
||||
private final Locale locale;
|
||||
private final Processing processing;
|
||||
private final ServerInfo serverInfo;
|
||||
private final ConnectionSystem connectionSystem;
|
||||
private final InfoRequestFactory infoRequestFactory;
|
||||
private final WebServer webServer;
|
||||
private final Database database;
|
||||
|
||||
public ManageConDebugCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public ManageConDebugCommand(
|
||||
ColorScheme colorScheme,
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
ServerInfo serverInfo,
|
||||
ConnectionSystem connectionSystem,
|
||||
InfoRequestFactory infoRequestFactory,
|
||||
WebServer webServer,
|
||||
Database database
|
||||
) {
|
||||
super("con", Permissions.MANAGE.getPermission(), CommandType.ALL);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.colorScheme = colorScheme;
|
||||
this.locale = locale;
|
||||
this.processing = processing;
|
||||
this.serverInfo = serverInfo;
|
||||
this.connectionSystem = connectionSystem;
|
||||
this.infoRequestFactory = infoRequestFactory;
|
||||
this.webServer = webServer;
|
||||
this.database = database;
|
||||
|
||||
setShortHelp(locale.getString(Check.isBungeeAvailable() ? CmdHelpLang.CON : CmdHelpLang.MANAGE_CON));
|
||||
setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE_CON));
|
||||
}
|
||||
|
||||
public static boolean testServer(ISender sender, String accessAddress, Server server, Locale locale) {
|
||||
private void testServer(Sender sender, String accessAddress, Server server, Locale locale) {
|
||||
String address = server.getWebAddress().toLowerCase();
|
||||
boolean usingHttps = address.startsWith("https");
|
||||
boolean local = address.contains("localhost")
|
||||
|
@ -52,11 +78,8 @@ public class ManageConDebugCommand extends CommandNode {
|
|||
|| address.contains("127.0.0.1");
|
||||
|
||||
try {
|
||||
|
||||
InfoSystem.getInstance().getConnectionSystem().sendInfoRequest(new CheckConnectionRequest(accessAddress), server);
|
||||
connectionSystem.sendInfoRequest(infoRequestFactory.checkConnectionRequest(address), server);
|
||||
sender.sendMessage(getMsgFor(address, usingHttps, local, true, true));
|
||||
return true;
|
||||
|
||||
} catch (ForbiddenException | BadRequestException | InternalErrorException e) {
|
||||
sender.sendMessage(getMsgFor(address, usingHttps, local, false, false));
|
||||
sender.sendMessage(locale.getString(ManageLang.CON_EXCEPTION, e.getClass().getSimpleName()));
|
||||
|
@ -78,28 +101,27 @@ public class ManageConDebugCommand extends CommandNode {
|
|||
sender.sendMessage(getMsgFor(address, usingHttps, local, false, false));
|
||||
sender.sendMessage(locale.getString(ManageLang.CON_EXCEPTION, e.getClass().getSimpleName()));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!WebServerSystem.isWebServerEnabled()) {
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
if (!webServer.isEnabled()) {
|
||||
sender.sendMessage(locale.getString(CommandLang.CONNECT_WEBSERVER_NOT_ENABLED));
|
||||
return;
|
||||
}
|
||||
|
||||
Processing.submitNonCritical(() -> testServers(sender));
|
||||
processing.submitNonCritical(() -> testServers(sender));
|
||||
}
|
||||
|
||||
private void testServers(ISender sender) {
|
||||
List<Server> servers = Database.getActive().fetch().getServers();
|
||||
private void testServers(Sender sender) {
|
||||
List<Server> servers = database.fetch().getServers();
|
||||
|
||||
if (servers.isEmpty()) {
|
||||
sender.sendMessage(locale.getString(ManageLang.CON_NO_SERVERS));
|
||||
}
|
||||
|
||||
String accessAddress = WebServerSystem.getInstance().getWebServer().getAccessAddress();
|
||||
UUID thisServer = ServerInfo.getServerUUID();
|
||||
String accessAddress = webServer.getAccessAddress();
|
||||
UUID thisServer = serverInfo.getServerUUID();
|
||||
for (Server server : servers) {
|
||||
if (thisServer.equals(server.getUuid())) {
|
||||
continue;
|
||||
|
@ -108,10 +130,9 @@ public class ManageConDebugCommand extends CommandNode {
|
|||
}
|
||||
}
|
||||
|
||||
private static String getMsgFor(String address, boolean usingHttps, boolean local, boolean successTo, boolean successFrom) {
|
||||
ColorScheme cs = PlanPlugin.getInstance().getColorScheme();
|
||||
String tCol = cs.getTertiaryColor();
|
||||
String sCol = cs.getSecondaryColor();
|
||||
private String getMsgFor(String address, boolean usingHttps, boolean local, boolean successTo, boolean successFrom) {
|
||||
String tCol = colorScheme.getTertiaryColor();
|
||||
String sCol = colorScheme.getSecondaryColor();
|
||||
return tCol + address + sCol + ": "
|
||||
+ (usingHttps ? "HTTPS" : "HTTP") + " : "
|
||||
+ (local ? "Local" : "External") + " : "
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.system.listeners.bukkit.PlayerOnlineListener;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||
|
@ -9,9 +8,10 @@ import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
|||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
|
@ -24,10 +24,11 @@ public class ManageDisableCommand extends CommandNode {
|
|||
|
||||
private final Locale locale;
|
||||
|
||||
public ManageDisableCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public ManageDisableCommand(Locale locale) {
|
||||
super("disable", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
|
||||
setArguments("<feature>");
|
||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE_DISABLE));
|
||||
|
@ -35,7 +36,7 @@ public class ManageDisableCommand extends CommandNode {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
Verify.isTrue(args.length >= 1,
|
||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
||||
|
||||
|
|
|
@ -9,12 +9,16 @@ import com.djrapitops.plan.system.locale.lang.CommandLang;
|
|||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
|
@ -28,19 +32,26 @@ public class ManageHotSwapCommand extends CommandNode {
|
|||
|
||||
private final PlanPlugin plugin;
|
||||
private final Locale locale;
|
||||
private final DBSystem dbSystem;
|
||||
private final PlanConfig config;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public ManageHotSwapCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public ManageHotSwapCommand(PlanPlugin plugin, Locale locale, DBSystem dbSystem, PlanConfig config, ErrorHandler errorHandler) {
|
||||
super("hotswap", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
|
||||
this.plugin = plugin;
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.plugin = plugin;
|
||||
this.locale = locale;
|
||||
this.dbSystem = dbSystem;
|
||||
this.config = config;
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
setArguments("<DB>");
|
||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE_HOTSWAP));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
Verify.isTrue(args.length >= 1,
|
||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
||||
|
||||
|
@ -50,24 +61,29 @@ public class ManageHotSwapCommand extends CommandNode {
|
|||
Verify.isTrue(isCorrectDB,
|
||||
() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_INCORRECT_DB, dbName)));
|
||||
|
||||
Verify.isFalse(dbName.equals(Database.getActive().getConfigName()),
|
||||
Verify.isFalse(dbName.equals(dbSystem.getActiveDatabase().getConfigName()),
|
||||
() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_SAME_DB)));
|
||||
|
||||
try {
|
||||
Database database = DBSystem.getActiveDatabaseByName(dbName);
|
||||
Database database = dbSystem.getActiveDatabaseByName(dbName);
|
||||
database.init();
|
||||
|
||||
if (!database.isOpen()) {
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||
return;
|
||||
}
|
||||
|
||||
Settings.DB_TYPE.set(dbName);
|
||||
|
||||
Settings.save();
|
||||
try {
|
||||
config.set(Settings.DB_TYPE, dbName);
|
||||
config.save();
|
||||
} catch (IOException e) {
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
return;
|
||||
}
|
||||
plugin.reloadPlugin(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,23 @@
|
|||
package com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.system.importing.ImportSystem;
|
||||
import com.djrapitops.plan.system.importing.importers.Importer;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
||||
import com.djrapitops.plan.system.processing.importing.ImporterManager;
|
||||
import com.djrapitops.plan.system.processing.importing.importers.Importer;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* This manage SubCommand is used to import data from 3rd party plugins.
|
||||
|
@ -24,14 +25,24 @@ import java.util.Arrays;
|
|||
* @author Rsl1122
|
||||
* @since 2.3.0
|
||||
*/
|
||||
@Singleton
|
||||
public class ManageImportCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final Processing processing;
|
||||
private final ImportSystem importSystem;
|
||||
|
||||
public ManageImportCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public ManageImportCommand(
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
ImportSystem importSystem
|
||||
) {
|
||||
super("import", Permissions.MANAGE.getPermission(), CommandType.CONSOLE);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
this.processing = processing;
|
||||
this.importSystem = importSystem;
|
||||
|
||||
setArguments("<plugin>/list", "[import args]");
|
||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE_IMPORT));
|
||||
|
@ -39,7 +50,7 @@ public class ManageImportCommand extends CommandNode {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
Verify.isTrue(args.length >= 1,
|
||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ARGS, "1+", Arrays.toString(this.getArguments()))));
|
||||
|
||||
|
@ -47,28 +58,20 @@ public class ManageImportCommand extends CommandNode {
|
|||
|
||||
if (importArg.equals("list")) {
|
||||
sender.sendMessage(locale.getString(ManageLang.IMPORTERS));
|
||||
ImporterManager.getImporters().stream()
|
||||
.map(Importer::getNames)
|
||||
.map(list -> list.get(0))
|
||||
.forEach(name -> sender.sendMessage("- " + name));
|
||||
importSystem.getImporterNames().forEach(name -> sender.sendMessage("- " + name));
|
||||
return;
|
||||
}
|
||||
|
||||
Importer importer = ImporterManager.getImporter(importArg);
|
||||
if (importer == null) {
|
||||
findImporter(sender, importArg);
|
||||
}
|
||||
|
||||
private void findImporter(Sender sender, String importArg) {
|
||||
Optional<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));
|
||||
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;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
|
@ -8,15 +7,17 @@ import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
|||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
|
@ -27,14 +28,27 @@ import java.util.Arrays;
|
|||
* @author Rsl1122
|
||||
* @since 2.3.0
|
||||
*/
|
||||
@Singleton
|
||||
public class ManageMoveCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final Processing processing;
|
||||
private final DBSystem dbSystem;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public ManageMoveCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public ManageMoveCommand(
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
DBSystem dbSystem,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super("move", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
this.processing = processing;
|
||||
this.dbSystem = dbSystem;
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
setArguments("<fromDB>", "<toDB>", "[-a]");
|
||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE_MOVE));
|
||||
|
@ -42,7 +56,7 @@ public class ManageMoveCommand extends CommandNode {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
Verify.isTrue(args.length >= 2,
|
||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ARGS, 2, Arrays.toString(this.getArguments()))));
|
||||
|
||||
|
@ -65,8 +79,10 @@ public class ManageMoveCommand extends CommandNode {
|
|||
}
|
||||
|
||||
try {
|
||||
final Database fromDatabase = DBSystem.getActiveDatabaseByName(fromDB);
|
||||
final Database toDatabase = DBSystem.getActiveDatabaseByName(toDB);
|
||||
final Database fromDatabase = dbSystem.getActiveDatabaseByName(fromDB);
|
||||
final Database toDatabase = dbSystem.getActiveDatabaseByName(toDB);
|
||||
fromDatabase.init();
|
||||
toDatabase.init();
|
||||
|
||||
runMoveTask(fromDatabase, toDatabase, sender);
|
||||
} catch (Exception e) {
|
||||
|
@ -74,28 +90,23 @@ public class ManageMoveCommand extends CommandNode {
|
|||
}
|
||||
}
|
||||
|
||||
private void runMoveTask(final Database fromDatabase, final Database toDatabase, ISender sender) {
|
||||
RunnableFactory.createNew(new AbsRunnable("DBMoveTask") {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
|
||||
private void runMoveTask(final Database fromDatabase, final Database toDatabase, Sender sender) {
|
||||
processing.submitCritical(() -> {
|
||||
try {
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
|
||||
|
||||
fromDatabase.backup().backup(toDatabase);
|
||||
fromDatabase.backup().backup(toDatabase);
|
||||
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
|
||||
|
||||
boolean movingToCurrentDB = toDatabase.getConfigName().equalsIgnoreCase(Database.getActive().getConfigName());
|
||||
if (movingToCurrentDB) {
|
||||
sender.sendMessage(locale.getString(ManageLang.HOTSWAP_REMINDER, toDatabase.getConfigName()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||
} finally {
|
||||
this.cancel();
|
||||
boolean movingToCurrentDB = toDatabase.getConfigName().equalsIgnoreCase(dbSystem.getActiveDatabase().getConfigName());
|
||||
if (movingToCurrentDB) {
|
||||
sender.sendMessage(locale.getString(ManageLang.HOTSWAP_REMINDER, toDatabase.getConfigName()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||
|
@ -11,9 +10,10 @@ import com.djrapitops.plan.utilities.MiscUtils;
|
|||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.CommandUtils;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
|
@ -25,11 +25,14 @@ import java.util.Arrays;
|
|||
public class ManageRawDataCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final ConnectionSystem connectionSystem;
|
||||
|
||||
public ManageRawDataCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public ManageRawDataCommand(Locale locale, ConnectionSystem connectionSystem) {
|
||||
super("raw", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
this.connectionSystem = connectionSystem;
|
||||
|
||||
setArguments("<player>");
|
||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE_RAW_DATA));
|
||||
|
@ -37,7 +40,7 @@ public class ManageRawDataCommand extends CommandNode {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
Verify.isTrue(args.length >= 1,
|
||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
||||
|
||||
|
@ -45,7 +48,7 @@ public class ManageRawDataCommand extends CommandNode {
|
|||
|
||||
sender.sendMessage(locale.getString(CommandLang.HEADER_INSPECT, playerName));
|
||||
// Link
|
||||
String url = ConnectionSystem.getInstance().getMainAddress() + "/player/" + playerName + "/raw";
|
||||
String url = connectionSystem.getMainAddress() + "/player/" + playerName + "/raw";
|
||||
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
|
||||
boolean console = !CommandUtils.isPlayer(sender);
|
||||
if (console) {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
|
@ -8,17 +7,19 @@ import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
|||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -28,14 +29,30 @@ import java.util.UUID;
|
|||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class ManageRemoveCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final Processing processing;
|
||||
private final Database database;
|
||||
private final UUIDUtility uuidUtility;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public ManageRemoveCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public ManageRemoveCommand(
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
Database database,
|
||||
UUIDUtility uuidUtility,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super("remove|delete", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
this.processing = processing;
|
||||
this.database = database;
|
||||
this.uuidUtility = uuidUtility;
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
setArguments("<player>", "[-a]");
|
||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE_REMOVE));
|
||||
|
@ -43,7 +60,7 @@ public class ManageRemoveCommand extends CommandNode {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
Verify.isTrue(args.length >= 1,
|
||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
||||
|
||||
|
@ -57,41 +74,35 @@ public class ManageRemoveCommand extends CommandNode {
|
|||
runRemoveTask(playerName, sender, args);
|
||||
}
|
||||
|
||||
private void runRemoveTask(String playerName, ISender sender, String[] args) {
|
||||
RunnableFactory.createNew(new AbsRunnable("DBRemoveTask " + playerName) {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
UUID uuid = UUIDUtility.getUUIDOf(playerName);
|
||||
private void runRemoveTask(String playerName, Sender sender, String[] args) {
|
||||
processing.submitCritical(() -> {
|
||||
try {
|
||||
UUID uuid = uuidUtility.getUUIDOf(playerName);
|
||||
|
||||
if (uuid == null) {
|
||||
sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_VALID));
|
||||
return;
|
||||
}
|
||||
|
||||
Database database = Database.getActive();
|
||||
if (!database.check().isPlayerRegistered(uuid)) {
|
||||
sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_KNOWN));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Verify.contains("-a", args)) {
|
||||
sender.sendMessage(locale.getString(ManageLang.CONFIRMATION, locale.getString(ManageLang.CONFIRM_REMOVAL, database.getName())));
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
|
||||
|
||||
database.remove().player(uuid);
|
||||
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
|
||||
} catch (DBOpException e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||
} finally {
|
||||
this.cancel();
|
||||
if (uuid == null) {
|
||||
sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_VALID));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!database.check().isPlayerRegistered(uuid)) {
|
||||
sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_KNOWN));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Verify.contains("-a", args)) {
|
||||
sender.sendMessage(locale.getString(ManageLang.CONFIRMATION, locale.getString(ManageLang.CONFIRM_REMOVAL, database.getName())));
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
|
||||
|
||||
database.remove().player(uuid);
|
||||
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
|
||||
} catch (DBOpException e) {
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,24 @@
|
|||
package com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.database.databases.sql.SQLiteDB;
|
||||
import com.djrapitops.plan.system.file.PlanFiles;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
|
||||
|
@ -29,14 +30,30 @@ import java.util.Arrays;
|
|||
*/
|
||||
public class ManageRestoreCommand extends CommandNode {
|
||||
|
||||
private final PlanPlugin plugin;
|
||||
private final Locale locale;
|
||||
private final Processing processing;
|
||||
private final DBSystem dbSystem;
|
||||
private final ErrorHandler errorHandler;
|
||||
private final SQLiteDB.Factory sqliteFactory;
|
||||
private final PlanFiles files;
|
||||
|
||||
public ManageRestoreCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public ManageRestoreCommand(
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
DBSystem dbSystem,
|
||||
SQLiteDB.Factory sqliteFactory,
|
||||
PlanFiles files,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super("restore", Permissions.MANAGE.getPermission(), CommandType.CONSOLE);
|
||||
this.plugin = plugin;
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
this.processing = processing;
|
||||
this.dbSystem = dbSystem;
|
||||
this.sqliteFactory = sqliteFactory;
|
||||
this.files = files;
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
setArguments("<Filename.db>", "<dbTo>", "[-a]");
|
||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE_RESTORE));
|
||||
|
@ -44,7 +61,7 @@ public class ManageRestoreCommand extends CommandNode {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
Verify.isTrue(args.length >= 2,
|
||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ARGS, 2, Arrays.toString(this.getArguments()))));
|
||||
|
||||
|
@ -56,9 +73,11 @@ public class ManageRestoreCommand extends CommandNode {
|
|||
() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_INCORRECT_DB, dbName)));
|
||||
|
||||
try {
|
||||
Database database = DBSystem.getActiveDatabaseByName(dbName);
|
||||
Database database = dbSystem.getActiveDatabaseByName(dbName);
|
||||
|
||||
Verify.isFalse(backupDbName.contains("database") && database instanceof SQLiteDB,
|
||||
() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_SAME_DB)));
|
||||
database.init();
|
||||
|
||||
if (!Verify.contains("-a", args)) {
|
||||
sender.sendMessage(locale.getString(ManageLang.CONFIRMATION, locale.getString(ManageLang.CONFIRM_OVERWRITE, database.getName())));
|
||||
|
@ -71,40 +90,35 @@ public class ManageRestoreCommand extends CommandNode {
|
|||
}
|
||||
}
|
||||
|
||||
private void runRestoreTask(String backupDbName, ISender sender, final Database database) {
|
||||
RunnableFactory.createNew(new AbsRunnable("RestoreTask") {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String backupDBName = backupDbName;
|
||||
boolean containsDBFileExtension = backupDBName.endsWith(".db");
|
||||
private void runRestoreTask(String backupDbName, Sender sender, Database database) {
|
||||
processing.submitCritical(() -> {
|
||||
try {
|
||||
String backupDBName = backupDbName;
|
||||
boolean containsDBFileExtension = backupDBName.endsWith(".db");
|
||||
|
||||
File backupDBFile = new File(plugin.getDataFolder(), backupDBName + (containsDBFileExtension ? "" : ".db"));
|
||||
File backupDBFile = files.getFileFromPluginFolder(backupDBName + (containsDBFileExtension ? "" : ".db"));
|
||||
|
||||
if (!backupDBFile.exists()) {
|
||||
sender.sendMessage(locale.getString(ManageLang.FAIL_FILE_NOT_FOUND, backupDBFile.getAbsolutePath()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (containsDBFileExtension) {
|
||||
backupDBName = backupDBName.substring(0, backupDBName.length() - 3);
|
||||
}
|
||||
|
||||
SQLiteDB backupDB = new SQLiteDB(backupDBName, () -> locale);
|
||||
backupDB.init();
|
||||
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
|
||||
|
||||
database.backup().restore(backupDB);
|
||||
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||
} finally {
|
||||
this.cancel();
|
||||
if (!backupDBFile.exists()) {
|
||||
sender.sendMessage(locale.getString(ManageLang.FAIL_FILE_NOT_FOUND, backupDBFile.getAbsolutePath()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (containsDBFileExtension) {
|
||||
backupDBName = backupDBName.substring(0, backupDBName.length() - 3);
|
||||
}
|
||||
|
||||
SQLiteDB backupDB = sqliteFactory.usingFile(backupDBFile);
|
||||
backupDB.init();
|
||||
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
|
||||
|
||||
database.backup().restore(backupDB);
|
||||
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
|
||||
} catch (Exception e) {
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.connection.*;
|
||||
import com.djrapitops.plan.system.info.InfoSystem;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
|
@ -10,13 +9,17 @@ import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
|||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.webserver.WebServerSystem;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.system.webserver.WebServer;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
|
@ -25,14 +28,33 @@ import java.util.Arrays;
|
|||
* @author Rsl1122
|
||||
* @since 2.3.0
|
||||
*/
|
||||
@Singleton
|
||||
public class ManageSetupCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final PlanConfig config;
|
||||
private final Processing processing;
|
||||
private final InfoSystem infoSystem;
|
||||
private final WebServer webServer;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public ManageSetupCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public ManageSetupCommand(
|
||||
Locale locale,
|
||||
PlanConfig config,
|
||||
Processing processing,
|
||||
InfoSystem infoSystem,
|
||||
WebServer webServer,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super("setup", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
this.config = config;
|
||||
this.processing = processing;
|
||||
this.infoSystem = infoSystem;
|
||||
this.webServer = webServer;
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
setArguments("<BungeeAddress>");
|
||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE_SETUP));
|
||||
|
@ -40,11 +62,11 @@ public class ManageSetupCommand extends CommandNode {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
Verify.isTrue(args.length >= 1,
|
||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
||||
|
||||
if (!WebServerSystem.isWebServerEnabled()) {
|
||||
if (!webServer.isEnabled()) {
|
||||
sender.sendMessage(locale.getString(CommandLang.CONNECT_WEBSERVER_NOT_ENABLED));
|
||||
return;
|
||||
}
|
||||
|
@ -60,13 +82,13 @@ public class ManageSetupCommand extends CommandNode {
|
|||
requestSetup(sender, address);
|
||||
}
|
||||
|
||||
private void requestSetup(ISender sender, String address) {
|
||||
Processing.submitNonCritical(() -> {
|
||||
private void requestSetup(Sender sender, String address) {
|
||||
processing.submitNonCritical(() -> {
|
||||
try {
|
||||
Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.set(false);
|
||||
Settings.BUNGEE_COPY_CONFIG.set(true);
|
||||
config.set(Settings.BUNGEE_OVERRIDE_STANDALONE_MODE, false);
|
||||
config.set(Settings.BUNGEE_COPY_CONFIG, true);
|
||||
|
||||
InfoSystem.getInstance().requestSetUp(address);
|
||||
infoSystem.requestSetUp(address);
|
||||
|
||||
sender.sendMessage(locale.getString(CommandLang.CONNECT_SUCCESS));
|
||||
} catch (ForbiddenException e) {
|
||||
|
@ -82,7 +104,7 @@ public class ManageSetupCommand extends CommandNode {
|
|||
} catch (GatewayException e) {
|
||||
sender.sendMessage(locale.getString(CommandLang.CONNECT_GATEWAY));
|
||||
} catch (WebException e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
errorHandler.log(L.WARN, this.getClass(), e);
|
||||
sender.sendMessage(locale.getString(CommandLang.CONNECT_FAIL, e.toString()));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
|
@ -11,11 +10,14 @@ import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
|||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
@ -26,14 +28,30 @@ import java.util.UUID;
|
|||
* @author Rsl1122
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@Singleton
|
||||
public class ManageUninstalledCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final Processing processing;
|
||||
private final Database database;
|
||||
private final ErrorHandler errorHandler;
|
||||
private final ServerInfo serverInfo;
|
||||
|
||||
public ManageUninstalledCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public ManageUninstalledCommand(
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
Database database,
|
||||
ServerInfo serverInfo,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super("uninstalled", Permissions.MANAGE.getPermission(), CommandType.ALL_WITH_ARGS);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
this.processing = processing;
|
||||
this.database = database;
|
||||
this.serverInfo = serverInfo;
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE_UNINSTALLED));
|
||||
setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE_UNINSTALLED));
|
||||
|
@ -41,10 +59,10 @@ public class ManageUninstalledCommand extends CommandNode {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
|
||||
|
||||
Processing.submitNonCritical(() -> {
|
||||
processing.submitNonCritical(() -> {
|
||||
try {
|
||||
Optional<Server> serverOptional = getServer(args);
|
||||
if (!serverOptional.isPresent()) {
|
||||
|
@ -53,23 +71,23 @@ public class ManageUninstalledCommand extends CommandNode {
|
|||
}
|
||||
Server server = serverOptional.get();
|
||||
UUID serverUUID = server.getUuid();
|
||||
if (ServerInfo.getServerUUID().equals(serverUUID)) {
|
||||
if (serverInfo.getServerUUID().equals(serverUUID)) {
|
||||
sender.sendMessage(locale.getString(ManageLang.UNINSTALLING_SAME_SERVER));
|
||||
return;
|
||||
}
|
||||
|
||||
Database.getActive().save().setAsUninstalled(serverUUID);
|
||||
database.save().setAsUninstalled(serverUUID);
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
|
||||
} catch (DBOpException e) {
|
||||
sender.sendMessage("§cError occurred: " + e.toString());
|
||||
Log.toLog(this.getClass(), e);
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Optional<Server> getServer(String[] args) {
|
||||
if (args.length >= 1) {
|
||||
Map<UUID, Server> bukkitServers = Database.getActive().fetch().getBukkitServers();
|
||||
Map<UUID, Server> bukkitServers = database.fetch().getBukkitServers();
|
||||
String serverIdentifier = getGivenIdentifier(args);
|
||||
for (Map.Entry<UUID, Server> entry : bukkitServers.entrySet()) {
|
||||
Server server = entry.getValue();
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
package com.djrapitops.plan.command.commands.webuser;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.data.WebUser;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
|
@ -24,45 +25,51 @@ import java.util.Arrays;
|
|||
* @author Rsl1122
|
||||
* @since 3.5.2
|
||||
*/
|
||||
@Singleton
|
||||
public class WebCheckCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final Processing processing;
|
||||
private final Database database;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public WebCheckCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public WebCheckCommand(
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
Database database,
|
||||
ErrorHandler errorHandler) {
|
||||
super("check", Permissions.MANAGE_WEB.getPerm(), CommandType.PLAYER_OR_ARGS);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
this.processing = processing;
|
||||
this.database = database;
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
setShortHelp(locale.getString(CmdHelpLang.WEB_CHECK));
|
||||
setArguments("<username>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
Verify.isTrue(args.length >= 1,
|
||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
||||
|
||||
Database database = Database.getActive();
|
||||
String user = args[0];
|
||||
|
||||
RunnableFactory.createNew(new AbsRunnable("Webuser Check Task: " + user) {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (!database.check().doesWebUserExists(user)) {
|
||||
sender.sendMessage(locale.getString(CommandLang.FAIL_WEB_USER_NOT_EXISTS));
|
||||
return;
|
||||
}
|
||||
WebUser info = database.fetch().getWebUser(user);
|
||||
sender.sendMessage(locale.getString(CommandLang.WEB_USER_LIST, info.getName(), info.getPermLevel()));
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||
} finally {
|
||||
this.cancel();
|
||||
processing.submitNonCritical(() -> {
|
||||
try {
|
||||
if (!database.check().doesWebUserExists(user)) {
|
||||
sender.sendMessage(locale.getString(CommandLang.FAIL_WEB_USER_NOT_EXISTS));
|
||||
return;
|
||||
}
|
||||
WebUser info = database.fetch().getWebUser(user);
|
||||
sender.sendMessage(locale.getString(CommandLang.WEB_USER_LIST, info.getName(), info.getPermLevel()));
|
||||
} catch (Exception e) {
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
package com.djrapitops.plan.command.commands.webuser;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
|
@ -23,45 +24,52 @@ import java.util.Arrays;
|
|||
* @author Rsl1122
|
||||
* @since 3.5.2
|
||||
*/
|
||||
@Singleton
|
||||
public class WebDeleteCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final Processing processing;
|
||||
private final Database database;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public WebDeleteCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public WebDeleteCommand(
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
Database database,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super("delete|remove", Permissions.MANAGE_WEB.getPerm(), CommandType.PLAYER_OR_ARGS);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
this.processing = processing;
|
||||
this.database = database;
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
setShortHelp(locale.getString(CmdHelpLang.WEB_DELETE));
|
||||
setArguments("<username>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
Verify.isTrue(args.length >= 1,
|
||||
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
|
||||
|
||||
Database database = Database.getActive();
|
||||
String user = args[0];
|
||||
|
||||
RunnableFactory.createNew("Webuser Delete Task: " + user, new AbsRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (!database.check().doesWebUserExists(user)) {
|
||||
sender.sendMessage("§c[Plan] User Doesn't exist.");
|
||||
return;
|
||||
}
|
||||
database.remove().webUser(user);
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||
} finally {
|
||||
this.cancel();
|
||||
processing.submitNonCritical(() -> {
|
||||
try {
|
||||
if (!database.check().doesWebUserExists(user)) {
|
||||
sender.sendMessage("§c[Plan] User Doesn't exist.");
|
||||
return;
|
||||
}
|
||||
database.remove().webUser(user);
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
|
||||
} catch (Exception e) {
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
package com.djrapitops.plan.command.commands.webuser;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Subcommand for info about permission levels.
|
||||
|
@ -19,16 +20,17 @@ public class WebLevelCommand extends CommandNode {
|
|||
|
||||
private final Locale locale;
|
||||
|
||||
public WebLevelCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public WebLevelCommand(Locale locale) {
|
||||
super("level", Permissions.MANAGE_WEB.getPerm(), CommandType.CONSOLE);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
|
||||
setShortHelp(locale.getString(CmdHelpLang.WEB_LEVEL));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
sender.sendMessage(locale.getArray(CommandLang.WEB_PERMISSION_LEVELS));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
package com.djrapitops.plan.command.commands.webuser;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.data.WebUser;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.utilities.comparators.WebUserComparator;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import com.djrapitops.plugin.command.Sender;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -24,39 +25,47 @@ import java.util.List;
|
|||
* @author Rsl1122
|
||||
* @since 3.5.2
|
||||
*/
|
||||
@Singleton
|
||||
public class WebListUsersCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final Processing processing;
|
||||
private final Database database;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public WebListUsersCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public WebListUsersCommand(
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
Database database,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super("list", Permissions.MANAGE_WEB.getPerm(), CommandType.CONSOLE);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
this.processing = processing;
|
||||
this.database = database;
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
setShortHelp(locale.getString(CmdHelpLang.WEB_LIST));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
RunnableFactory.createNew(new AbsRunnable("Web user List Task") {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
List<WebUser> users = Database.getActive().fetch().getWebUsers();
|
||||
users.sort(new WebUserComparator());
|
||||
sender.sendMessage(locale.getString(CommandLang.HEADER_WEB_USERS, users.size()));
|
||||
for (WebUser user : users) {
|
||||
sender.sendMessage(locale.getString(CommandLang.WEB_USER_LIST, user.getName(), user.getPermLevel()));
|
||||
}
|
||||
sender.sendMessage(">");
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||
} finally {
|
||||
this.cancel();
|
||||
public void onCommand(Sender sender, String commandLabel, String[] args) {
|
||||
processing.submitNonCritical(() -> {
|
||||
try {
|
||||
List<WebUser> users = database.fetch().getWebUsers();
|
||||
users.sort(new WebUserComparator());
|
||||
sender.sendMessage(locale.getString(CommandLang.HEADER_WEB_USERS, users.size()));
|
||||
for (WebUser user : users) {
|
||||
sender.sendMessage(locale.getString(CommandLang.WEB_USER_LIST, user.getName(), user.getPermLevel()));
|
||||
}
|
||||
sender.sendMessage(">");
|
||||
} catch (Exception e) {
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,11 +6,11 @@ package com.djrapitops.plan.data.container;
|
|||
|
||||
import com.djrapitops.plan.data.store.objects.DateHolder;
|
||||
import com.djrapitops.plan.data.store.objects.DateMap;
|
||||
import com.djrapitops.plan.utilities.FormatUtils;
|
||||
import com.djrapitops.plan.utilities.SHA256Hash;
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
|
@ -26,9 +26,8 @@ public class GeoInfo implements DateHolder, Serializable {
|
|||
private final String ipHash;
|
||||
private final long date;
|
||||
|
||||
public GeoInfo(InetAddress address, String geolocation, long lastUsed)
|
||||
throws NoSuchAlgorithmException {
|
||||
this(FormatUtils.formatIP(address), geolocation, lastUsed, new SHA256Hash(address.getHostAddress()).create());
|
||||
public GeoInfo(InetAddress address, String geolocation, long lastUsed) throws NoSuchAlgorithmException {
|
||||
this(formatIP(address), geolocation, lastUsed, new SHA256Hash(address.getHostAddress()).create());
|
||||
}
|
||||
|
||||
public GeoInfo(String ip, String geolocation, long date, String ipHash) {
|
||||
|
@ -46,6 +45,42 @@ public class GeoInfo implements DateHolder, Serializable {
|
|||
return map;
|
||||
}
|
||||
|
||||
static String formatIP(InetAddress address) {
|
||||
String ip = address.getHostAddress();
|
||||
if ("localhost".equals(ip)) {
|
||||
return ip;
|
||||
}
|
||||
if (address instanceof Inet6Address) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
int i = 0;
|
||||
for (String part : ip.split(":")) {
|
||||
if (i >= 3) {
|
||||
break;
|
||||
}
|
||||
|
||||
b.append(part).append(':');
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return b.append("xx..").toString();
|
||||
} else {
|
||||
StringBuilder b = new StringBuilder();
|
||||
int i = 0;
|
||||
for (String part : ip.split("\\.")) {
|
||||
if (i >= 2) {
|
||||
break;
|
||||
}
|
||||
|
||||
b.append(part).append('.');
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return b.append("xx.xx").toString();
|
||||
}
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
|
|
@ -7,11 +7,13 @@ import java.util.UUID;
|
|||
public class PlayerDeath implements DateHolder {
|
||||
|
||||
private final UUID killer;
|
||||
private final String killerName;
|
||||
private final long date;
|
||||
private final String weapon;
|
||||
|
||||
public PlayerDeath(UUID killer, String weapon, long date) {
|
||||
public PlayerDeath(UUID killer, String killerName, String weapon, long date) {
|
||||
this.killer = killer;
|
||||
this.killerName = killerName;
|
||||
this.date = date;
|
||||
this.weapon = weapon;
|
||||
}
|
||||
|
@ -20,6 +22,10 @@ public class PlayerDeath implements DateHolder {
|
|||
return killer;
|
||||
}
|
||||
|
||||
public String getKillerName() {
|
||||
return killerName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDate() {
|
||||
return date;
|
||||
|
|
|
@ -2,8 +2,8 @@ package com.djrapitops.plan.data.container;
|
|||
|
||||
import com.djrapitops.plan.data.store.objects.DateHolder;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
@ -12,11 +12,13 @@ import java.util.UUID;
|
|||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class PlayerKill implements DateHolder, Serializable {
|
||||
public class PlayerKill implements DateHolder {
|
||||
|
||||
private final UUID victim;
|
||||
private final long date;
|
||||
private final String weapon;
|
||||
private final long date;
|
||||
|
||||
private String victimName;
|
||||
|
||||
/**
|
||||
* Creates a PlayerKill object with given parameters.
|
||||
|
@ -31,6 +33,13 @@ public class PlayerKill implements DateHolder, Serializable {
|
|||
this.date = date;
|
||||
}
|
||||
|
||||
public PlayerKill(UUID victim, String weapon, long date, String victimName) {
|
||||
this.victim = victim;
|
||||
this.date = date;
|
||||
this.weapon = weapon;
|
||||
this.victimName = victimName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the victim's UUID.
|
||||
*
|
||||
|
@ -40,6 +49,10 @@ public class PlayerKill implements DateHolder, Serializable {
|
|||
return victim;
|
||||
}
|
||||
|
||||
public Optional<String> getVictimName() {
|
||||
return Optional.ofNullable(victimName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDate() {
|
||||
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.keys.SessionKeys;
|
||||
import com.djrapitops.plan.data.store.mutators.formatting.Formatters;
|
||||
import com.djrapitops.plan.data.store.objects.DateHolder;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.settings.WorldAliasSettings;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
@ -30,11 +27,12 @@ public class Session extends DataContainer implements DateHolder {
|
|||
* Creates a new session.
|
||||
*
|
||||
* @param uuid UUID of the Player.
|
||||
* @param serverUUID UUID of the server.
|
||||
* @param sessionStart Epoch ms the session started.
|
||||
* @param world Starting world.
|
||||
* @param gm Starting GameMode.
|
||||
*/
|
||||
public Session(UUID uuid, long sessionStart, String world, String gm) {
|
||||
public Session(UUID uuid, UUID serverUUID, long sessionStart, String world, String gm) {
|
||||
this.sessionStart = sessionStart;
|
||||
worldTimes = new WorldTimes(world, gm, sessionStart);
|
||||
playerKills = new ArrayList<>();
|
||||
|
@ -44,6 +42,7 @@ public class Session extends DataContainer implements DateHolder {
|
|||
afkTime = 0;
|
||||
|
||||
putRawData(SessionKeys.UUID, uuid);
|
||||
putRawData(SessionKeys.SERVER_UUID, serverUUID);
|
||||
putSupplier(SessionKeys.START, this::getSessionStart);
|
||||
putSupplier(SessionKeys.WORLD_TIMES, this::getWorldTimes);
|
||||
putSupplier(SessionKeys.PLAYER_KILLS, this::getPlayerKills);
|
||||
|
@ -56,9 +55,8 @@ public class Session extends DataContainer implements DateHolder {
|
|||
putSupplier(SessionKeys.LENGTH, () ->
|
||||
getValue(SessionKeys.END).orElse(System.currentTimeMillis()) - getUnsafe(SessionKeys.START));
|
||||
putSupplier(SessionKeys.ACTIVE_TIME, () -> getUnsafe(SessionKeys.LENGTH) - getUnsafe(SessionKeys.AFK_TIME));
|
||||
putSupplier(SessionKeys.SERVER_UUID, ServerInfo::getServerUUID);
|
||||
|
||||
putSupplier(SessionKeys.LONGEST_WORLD_PLAYED, this::getLongestWorldPlayed);
|
||||
putRawData(SessionKeys.LONGEST_WORLD_PLAYED, "Key is Deprecated, use WorldAliasSettings#getLongestWorldPlayed(Session) instead.");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,7 +99,7 @@ public class Session extends DataContainer implements DateHolder {
|
|||
getValue(SessionKeys.END).orElse(System.currentTimeMillis()) - getUnsafe(SessionKeys.START));
|
||||
putSupplier(SessionKeys.ACTIVE_TIME, () -> getUnsafe(SessionKeys.LENGTH) - getUnsafe(SessionKeys.AFK_TIME));
|
||||
|
||||
putSupplier(SessionKeys.LONGEST_WORLD_PLAYED, this::getLongestWorldPlayed);
|
||||
putRawData(SessionKeys.LONGEST_WORLD_PLAYED, "Key is Deprecated, use WorldAliasSettings#getLongestWorldPlayed(Session) instead.");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -157,8 +155,17 @@ public class Session extends DataContainer implements DateHolder {
|
|||
this.worldTimes = worldTimes;
|
||||
}
|
||||
|
||||
public void setPlayerKills(List<PlayerKill> playerKills) {
|
||||
this.playerKills = playerKills;
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Session session = (Session) o;
|
||||
return getUnsafe(SessionKeys.START).equals(session.getUnsafe(SessionKeys.START)) &&
|
||||
getValue(SessionKeys.END).orElse(-1L).equals(session.getValue(SessionKeys.END).orElse(-1L)) &&
|
||||
mobKills == session.mobKills &&
|
||||
deaths == session.deaths &&
|
||||
Objects.equals(playerKills, session.playerKills) &&
|
||||
Objects.equals(worldTimes, session.worldTimes);
|
||||
}
|
||||
|
||||
public boolean isFetchedFromDB() {
|
||||
|
@ -173,17 +180,8 @@ public class Session extends DataContainer implements DateHolder {
|
|||
putRawData(SessionKeys.DB_ID, sessionID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Session session = (Session) o;
|
||||
return getUnsafe(SessionKeys.START).equals(session.getUnsafe(SessionKeys.START)) &&
|
||||
getValue(SessionKeys.END).orElse(-1L).equals(session.getValue(SessionKeys.END).orElse(-1L)) &&
|
||||
mobKills == session.mobKills &&
|
||||
deaths == session.deaths &&
|
||||
Objects.equals(playerKills, session.playerKills) &&
|
||||
Objects.equals(worldTimes, session.worldTimes);
|
||||
public List<PlayerKill> getPlayerKills() {
|
||||
return playerKills;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -199,8 +197,8 @@ public class Session extends DataContainer implements DateHolder {
|
|||
return worldTimes;
|
||||
}
|
||||
|
||||
public List<PlayerKill> getPlayerKills() {
|
||||
return playerKills;
|
||||
public void setPlayerKills(List<PlayerKill> playerKills) {
|
||||
this.playerKills = playerKills;
|
||||
}
|
||||
|
||||
private int getMobKills() {
|
||||
|
@ -214,48 +212,4 @@ public class Session extends DataContainer implements DateHolder {
|
|||
private long getAfkTime() {
|
||||
return afkTime;
|
||||
}
|
||||
|
||||
private String getLongestWorldPlayed() {
|
||||
Map<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;
|
||||
|
||||
import com.djrapitops.plan.data.store.mutators.formatting.Formatter;
|
||||
import com.djrapitops.plan.utilities.FormatUtils;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
import com.djrapitops.plan.utilities.html.Html;
|
||||
import com.djrapitops.plan.utilities.html.icon.Icon;
|
||||
import com.djrapitops.plugin.utilities.ArrayUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
@ -40,10 +40,9 @@ public class TableContainer {
|
|||
}
|
||||
|
||||
public TableContainer(boolean players, String... header) {
|
||||
this(FormatUtils.mergeArrays(
|
||||
new String[]{Icon.called("user").build() + " Player"},
|
||||
header
|
||||
));
|
||||
this(
|
||||
ArrayUtil.merge(new String[]{Icon.called("user").build() + " Player"}, header)
|
||||
);
|
||||
}
|
||||
|
||||
public final void addRow(Serializable... values) {
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
package com.djrapitops.plan.data.plugin;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.data.element.InspectContainer;
|
||||
import com.djrapitops.plan.system.PlanSystem;
|
||||
import com.djrapitops.plan.system.SubSystem;
|
||||
import com.djrapitops.plugin.StaticHolder;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import com.djrapitops.pluginbridge.plan.Bridge;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -19,29 +18,30 @@ import java.util.stream.Collectors;
|
|||
* @author Rsl1122
|
||||
* @since 2.6.0
|
||||
*/
|
||||
@Singleton
|
||||
public class HookHandler implements SubSystem {
|
||||
|
||||
private final List<PluginData> additionalDataSources;
|
||||
private PluginsConfigSection configHandler;
|
||||
private final PluginLogger logger;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
@Inject
|
||||
public HookHandler(PluginsConfigSection configHandler, PluginLogger logger, ErrorHandler errorHandler) {
|
||||
this.configHandler = configHandler;
|
||||
this.logger = logger;
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
public HookHandler() {
|
||||
additionalDataSources = new ArrayList<>();
|
||||
}
|
||||
|
||||
public static HookHandler getInstance() {
|
||||
HookHandler hookHandler = PlanSystem.getInstance().getHookHandler();
|
||||
Verify.nullCheck(hookHandler, () -> new IllegalStateException("Plugin Hooks were not initialized."));
|
||||
return hookHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
configHandler = new PluginsConfigSection();
|
||||
try {
|
||||
Bridge.hook(this);
|
||||
// Bridge.hook(this);
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
Log.error("Plan Plugin Bridge not included in the plugin jar.");
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
logger.error("Plan Plugin Bridge not included in the plugin jar.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,17 +65,16 @@ public class HookHandler implements SubSystem {
|
|||
return;
|
||||
}
|
||||
try {
|
||||
StaticHolder.saveInstance(dataSource.getClass(), PlanPlugin.getInstance().getClass());
|
||||
if (!configHandler.hasSection(dataSource)) {
|
||||
configHandler.createSection(dataSource);
|
||||
}
|
||||
if (configHandler.isEnabled(dataSource)) {
|
||||
Log.debug("Registered a new datasource: " + dataSource.getSourcePlugin());
|
||||
logger.debug("Registered a new datasource: " + dataSource.getSourcePlugin());
|
||||
additionalDataSources.add(dataSource);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
Log.error("Attempting to register PluginDataSource caused an exception.");
|
||||
errorHandler.log(L.WARN, this.getClass(), e);
|
||||
logger.error("Attempting to register PluginDataSource caused an exception.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,8 +106,8 @@ public class HookHandler implements SubSystem {
|
|||
}
|
||||
} catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError e) {
|
||||
String sourcePlugin = pluginData.getSourcePlugin();
|
||||
Log.error("PluginData caused exception: " + sourcePlugin);
|
||||
Log.toLog(this.getClass().getName() + " " + sourcePlugin, e);
|
||||
logger.error("PluginData caused exception: " + sourcePlugin);
|
||||
errorHandler.log(L.WARN, pluginData.getClass(), e);
|
||||
}
|
||||
}
|
||||
return containers;
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package com.djrapitops.plan.data.plugin;
|
||||
|
||||
import com.djrapitops.plan.system.settings.config.ConfigSystem;
|
||||
import com.djrapitops.plugin.api.config.ConfigNode;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plugin.config.ConfigNode;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -15,6 +14,14 @@ import java.io.IOException;
|
|||
*/
|
||||
public class PluginsConfigSection {
|
||||
|
||||
private final PlanConfig config;
|
||||
|
||||
public PluginsConfigSection(
|
||||
PlanConfig config
|
||||
) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public boolean hasSection(PluginData dataSource) {
|
||||
ConfigNode section = getPluginsSection();
|
||||
String pluginName = dataSource.getSourcePlugin();
|
||||
|
@ -23,20 +30,16 @@ public class PluginsConfigSection {
|
|||
}
|
||||
|
||||
private ConfigNode getPluginsSection() {
|
||||
return ConfigSystem.getConfig().getConfigNode("Plugins");
|
||||
return config.getConfigNode("Plugins");
|
||||
}
|
||||
|
||||
public void createSection(PluginData dataSource) {
|
||||
public void createSection(PluginData dataSource) throws IOException {
|
||||
ConfigNode section = getPluginsSection();
|
||||
String pluginName = dataSource.getSourcePlugin();
|
||||
|
||||
section.set(pluginName + ".Enabled", true);
|
||||
try {
|
||||
section.sort();
|
||||
section.save();
|
||||
} catch (IOException e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
}
|
||||
section.sort();
|
||||
section.save();
|
||||
}
|
||||
|
||||
public boolean isEnabled(PluginData dataSource) {
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package com.djrapitops.plan.data.store;
|
||||
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Caching layer between Supplier and caller.
|
||||
*
|
||||
* <p>
|
||||
* Refreshes the value if 30 seconds have passed since the last call.
|
||||
*
|
||||
* @author Rsl1122
|
||||
|
@ -19,7 +18,7 @@ public class CachingSupplier<T> implements Supplier<T> {
|
|||
private long timeToLive;
|
||||
|
||||
public CachingSupplier(Supplier<T> original) {
|
||||
this(original, TimeAmount.SECOND.ms() * 30L);
|
||||
this(original, TimeUnit.SECONDS.toMillis(30L));
|
||||
}
|
||||
|
||||
public CachingSupplier(Supplier<T> original, long timeToLive) {
|
||||
|
|
|
@ -1,42 +1,37 @@
|
|||
package com.djrapitops.plan.data.store.containers;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.data.store.Key;
|
||||
import com.djrapitops.plan.data.store.Type;
|
||||
import com.djrapitops.plan.data.store.keys.AnalysisKeys;
|
||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
||||
import com.djrapitops.plan.data.store.keys.ServerKeys;
|
||||
import com.djrapitops.plan.data.store.mutators.*;
|
||||
import com.djrapitops.plan.data.store.mutators.combiners.MultiBanCombiner;
|
||||
import com.djrapitops.plan.data.store.mutators.formatting.Formatters;
|
||||
import com.djrapitops.plan.data.store.mutators.health.HealthInformation;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.info.server.properties.ServerProperties;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.system.settings.theme.ThemeVal;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plan.utilities.analysis.ServerBanDataReader;
|
||||
import com.djrapitops.plan.utilities.html.graphs.ActivityStackGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.PunchCardGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.WorldMap;
|
||||
import com.djrapitops.plan.utilities.html.graphs.bar.GeolocationBarGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.calendar.ServerCalendar;
|
||||
import com.djrapitops.plan.utilities.html.graphs.line.*;
|
||||
import com.djrapitops.plan.utilities.html.graphs.pie.ActivityPie;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
import com.djrapitops.plan.utilities.html.graphs.Graphs;
|
||||
import com.djrapitops.plan.utilities.html.graphs.bar.BarGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.line.PingGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.pie.WorldPie;
|
||||
import com.djrapitops.plan.utilities.html.graphs.stack.StackGraph;
|
||||
import com.djrapitops.plan.utilities.html.structure.Accordions;
|
||||
import com.djrapitops.plan.utilities.html.structure.AnalysisPluginsTabContentCreator;
|
||||
import com.djrapitops.plan.utilities.html.structure.RecentLoginList;
|
||||
import com.djrapitops.plan.utilities.html.structure.SessionAccordion;
|
||||
import com.djrapitops.plan.utilities.html.tables.CommandUseTable;
|
||||
import com.djrapitops.plan.utilities.html.tables.PingTable;
|
||||
import com.djrapitops.plan.utilities.html.tables.PlayersTable;
|
||||
import com.djrapitops.plan.utilities.html.tables.ServerSessionTable;
|
||||
import com.djrapitops.plan.utilities.html.tables.HtmlTables;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
@ -50,10 +45,43 @@ public class AnalysisContainer extends DataContainer {
|
|||
|
||||
private final ServerContainer serverContainer;
|
||||
|
||||
private final String version;
|
||||
private final PlanConfig config;
|
||||
private final Theme theme;
|
||||
private final Database database;
|
||||
private final ServerProperties serverProperties;
|
||||
private final Formatters formatters;
|
||||
private final Graphs graphs;
|
||||
private final HtmlTables tables;
|
||||
private final Accordions accordions;
|
||||
private final AnalysisPluginsTabContentCreator pluginsTabContentCreator;
|
||||
|
||||
private static final Key<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.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();
|
||||
}
|
||||
|
||||
|
@ -74,27 +102,21 @@ public class AnalysisContainer extends DataContainer {
|
|||
addCommandSuppliers();
|
||||
addServerHealth();
|
||||
addPluginSuppliers();
|
||||
|
||||
runCombiners();
|
||||
}
|
||||
|
||||
private void runCombiners() {
|
||||
new MultiBanCombiner(this.serverContainer).combine(getUnsafe(AnalysisKeys.BAN_DATA));
|
||||
}
|
||||
|
||||
private void addConstants() {
|
||||
long now = System.currentTimeMillis();
|
||||
putRawData(AnalysisKeys.ANALYSIS_TIME, now);
|
||||
putRawData(AnalysisKeys.ANALYSIS_TIME_DAY_AGO, now - TimeAmount.DAY.ms());
|
||||
putRawData(AnalysisKeys.ANALYSIS_TIME_WEEK_AGO, now - TimeAmount.WEEK.ms());
|
||||
putRawData(AnalysisKeys.ANALYSIS_TIME_MONTH_AGO, now - TimeAmount.MONTH.ms());
|
||||
putSupplier(AnalysisKeys.REFRESH_TIME_F, () -> Formatters.second().apply(() -> getUnsafe(AnalysisKeys.ANALYSIS_TIME)));
|
||||
putRawData(AnalysisKeys.ANALYSIS_TIME_DAY_AGO, now - TimeUnit.DAYS.toMillis(1L));
|
||||
putRawData(AnalysisKeys.ANALYSIS_TIME_WEEK_AGO, now - TimeAmount.WEEK.toMillis(1L));
|
||||
putRawData(AnalysisKeys.ANALYSIS_TIME_MONTH_AGO, now - TimeAmount.MONTH.toMillis(1L));
|
||||
putSupplier(AnalysisKeys.REFRESH_TIME_F, () -> formatters.secondLong().apply(getUnsafe(AnalysisKeys.ANALYSIS_TIME)));
|
||||
|
||||
putRawData(AnalysisKeys.VERSION, PlanPlugin.getInstance().getVersion());
|
||||
putSupplier(AnalysisKeys.TIME_ZONE, MiscUtils::getTimeZoneOffsetHours);
|
||||
putRawData(AnalysisKeys.VERSION, version);
|
||||
putSupplier(AnalysisKeys.TIME_ZONE, config::getTimeZoneOffsetHours);
|
||||
putRawData(AnalysisKeys.FIRST_DAY, 1);
|
||||
putRawData(AnalysisKeys.TPS_MEDIUM, Settings.THEME_GRAPH_TPS_THRESHOLD_MED.getNumber());
|
||||
putRawData(AnalysisKeys.TPS_HIGH, Settings.THEME_GRAPH_TPS_THRESHOLD_HIGH.getNumber());
|
||||
putRawData(AnalysisKeys.TPS_MEDIUM, config.getNumber(Settings.THEME_GRAPH_TPS_THRESHOLD_MED));
|
||||
putRawData(AnalysisKeys.TPS_HIGH, config.getNumber(Settings.THEME_GRAPH_TPS_THRESHOLD_HIGH));
|
||||
|
||||
addServerProperties();
|
||||
addThemeColors();
|
||||
|
@ -105,24 +127,23 @@ public class AnalysisContainer extends DataContainer {
|
|||
getUnsafe(serverNames).getOrDefault(serverContainer.getUnsafe(ServerKeys.SERVER_UUID), "Plan")
|
||||
);
|
||||
|
||||
ServerProperties serverProperties = ServerInfo.getServerProperties();
|
||||
putRawData(AnalysisKeys.PLAYERS_MAX, serverProperties.getMaxPlayers());
|
||||
putRawData(AnalysisKeys.PLAYERS_ONLINE, serverProperties.getOnlinePlayers());
|
||||
}
|
||||
|
||||
private void addThemeColors() {
|
||||
putRawData(AnalysisKeys.ACTIVITY_PIE_COLORS, Theme.getValue(ThemeVal.GRAPH_ACTIVITY_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.TPS_LOW_COLOR, Theme.getValue(ThemeVal.GRAPH_TPS_LOW));
|
||||
putRawData(AnalysisKeys.TPS_MEDIUM_COLOR, Theme.getValue(ThemeVal.GRAPH_TPS_MED));
|
||||
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_HIGH_COLOR, Theme.getValue(ThemeVal.WORLD_MAP_HIGH));
|
||||
putRawData(AnalysisKeys.WORLD_PIE_COLORS, Theme.getValue(ThemeVal.GRAPH_WORLD_PIE));
|
||||
putRawData(AnalysisKeys.AVG_PING_COLOR, Theme.getValue(ThemeVal.GRAPH_AVG_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.ACTIVITY_PIE_COLORS, theme.getValue(ThemeVal.GRAPH_ACTIVITY_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.TPS_LOW_COLOR, theme.getValue(ThemeVal.GRAPH_TPS_LOW));
|
||||
putRawData(AnalysisKeys.TPS_MEDIUM_COLOR, theme.getValue(ThemeVal.GRAPH_TPS_MED));
|
||||
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_HIGH_COLOR, theme.getValue(ThemeVal.WORLD_MAP_HIGH));
|
||||
putRawData(AnalysisKeys.WORLD_PIE_COLORS, theme.getValue(ThemeVal.GRAPH_WORLD_PIE));
|
||||
putRawData(AnalysisKeys.AVG_PING_COLOR, theme.getValue(ThemeVal.GRAPH_AVG_PING));
|
||||
putRawData(AnalysisKeys.MAX_PING_COLOR, theme.getValue(ThemeVal.GRAPH_MAX_PING));
|
||||
putRawData(AnalysisKeys.MIN_PING_COLOR, theme.getValue(ThemeVal.GRAPH_MIN_PING));
|
||||
}
|
||||
|
||||
private void addPlayerSuppliers() {
|
||||
|
@ -142,18 +163,18 @@ public class AnalysisContainer extends DataContainer {
|
|||
);
|
||||
putSupplier(AnalysisKeys.LAST_PEAK_TIME_F, () ->
|
||||
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, () ->
|
||||
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.PLAYERS_TABLE, () ->
|
||||
PlayersTable.forServerPage(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).all()).parseHtml()
|
||||
tables.playerTableForServerPage(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).all()).parseHtml()
|
||||
);
|
||||
putSupplier(AnalysisKeys.PING_TABLE, () ->
|
||||
new PingTable(
|
||||
tables.pingTable(
|
||||
getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)
|
||||
.getPingPerCountry(serverContainer.getUnsafe(ServerKeys.SERVER_UUID))
|
||||
).parseHtml()
|
||||
|
@ -201,20 +222,20 @@ public class AnalysisContainer extends DataContainer {
|
|||
|
||||
putSupplier(AnalysisKeys.UNIQUE_PLAYERS_PER_DAY, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).uniqueJoinsPerDay());
|
||||
putSupplier(AnalysisKeys.NEW_PLAYERS_PER_DAY, () -> getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).newPerDay());
|
||||
putSupplier(AnalysisKeys.UNIQUE_PLAYERS_SERIES, () -> new AbstractLineGraph(
|
||||
MutatorFunctions.toPoints(getUnsafe(AnalysisKeys.UNIQUE_PLAYERS_PER_DAY))
|
||||
).toHighChartsSeries()
|
||||
putSupplier(AnalysisKeys.UNIQUE_PLAYERS_SERIES, () -> graphs.line().lineGraph(
|
||||
MutatorFunctions.toPoints(getUnsafe(AnalysisKeys.UNIQUE_PLAYERS_PER_DAY))).toHighChartsSeries()
|
||||
);
|
||||
putSupplier(AnalysisKeys.NEW_PLAYERS_SERIES, () -> new AbstractLineGraph(
|
||||
MutatorFunctions.toPoints(getUnsafe(AnalysisKeys.NEW_PLAYERS_PER_DAY))
|
||||
).toHighChartsSeries()
|
||||
putSupplier(AnalysisKeys.NEW_PLAYERS_SERIES, () -> graphs.line().lineGraph(
|
||||
MutatorFunctions.toPoints(getUnsafe(AnalysisKeys.NEW_PLAYERS_PER_DAY))).toHighChartsSeries()
|
||||
);
|
||||
|
||||
Key<Integer> retentionDay = new Key<>(Integer.class, "RETENTION_DAY");
|
||||
// compareAndFindThoseLikelyToBeRetained can throw exception.
|
||||
putCachingSupplier(retentionDay, () -> getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).compareAndFindThoseLikelyToBeRetained(
|
||||
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()
|
||||
);
|
||||
putSupplier(AnalysisKeys.PLAYERS_RETAINED_DAY, () -> {
|
||||
|
@ -239,29 +260,31 @@ public class AnalysisContainer extends DataContainer {
|
|||
putSupplier(AnalysisKeys.PLAYERS_RETAINED_DAY_PERC, () -> {
|
||||
try {
|
||||
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) {
|
||||
return "Not enough data";
|
||||
}
|
||||
});
|
||||
putSupplier(AnalysisKeys.PLAYERS_RETAINED_WEEK_PERC, () -> {
|
||||
Integer playersNewWeek = getUnsafe(AnalysisKeys.PLAYERS_NEW_WEEK);
|
||||
return playersNewWeek != 0 ? Formatters.percentage().apply(
|
||||
1.0 * getUnsafe(AnalysisKeys.PLAYERS_RETAINED_WEEK) / playersNewWeek) : "-";
|
||||
return playersNewWeek != 0 ? formatters.percentage().apply(1.0 * getUnsafe(AnalysisKeys.PLAYERS_RETAINED_WEEK) / playersNewWeek) : "-";
|
||||
}
|
||||
);
|
||||
putSupplier(AnalysisKeys.PLAYERS_RETAINED_MONTH_PERC, () -> {
|
||||
Integer playersNewMonth = getUnsafe(AnalysisKeys.PLAYERS_NEW_MONTH);
|
||||
return playersNewMonth != 0 ? Formatters.percentage().apply(
|
||||
1.0 * getUnsafe(AnalysisKeys.PLAYERS_RETAINED_MONTH) / playersNewMonth) : "-";
|
||||
return playersNewMonth != 0
|
||||
? formatters.percentage().apply(1.0 * getUnsafe(AnalysisKeys.PLAYERS_RETAINED_MONTH) / playersNewMonth)
|
||||
: "-";
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private void addSessionSuppliers() {
|
||||
Key<SessionAccordion> sessionAccordion = new Key<>(SessionAccordion.class, "SESSION_ACCORDION");
|
||||
putCachingSupplier(serverNames, () -> Database.getActive().fetch().getServerNames());
|
||||
putCachingSupplier(sessionAccordion, () -> SessionAccordion.forServer(
|
||||
putCachingSupplier(serverNames, () -> database.fetch().getServerNames());
|
||||
putCachingSupplier(sessionAccordion, () -> accordions.serverSessionAccordion(
|
||||
getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).all(),
|
||||
getSupplier(serverNames),
|
||||
() -> getUnsafe(AnalysisKeys.PLAYER_NAMES)
|
||||
|
@ -270,32 +293,33 @@ public class AnalysisContainer extends DataContainer {
|
|||
putSupplier(AnalysisKeys.SESSION_ACCORDION_FUNCTIONS, () -> getUnsafe(sessionAccordion).toViewScript());
|
||||
|
||||
putSupplier(AnalysisKeys.RECENT_LOGINS, () -> new RecentLoginList(
|
||||
serverContainer.getValue(ServerKeys.PLAYERS).orElse(new ArrayList<>())
|
||||
).toHtml()
|
||||
serverContainer.getValue(ServerKeys.PLAYERS).orElse(new ArrayList<>()),
|
||||
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()
|
||||
);
|
||||
|
||||
putSupplier(AnalysisKeys.AVERAGE_SESSION_LENGTH_F, () -> Formatters.timeAmount()
|
||||
.apply(getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toAverageSessionLength())
|
||||
putSupplier(AnalysisKeys.AVERAGE_SESSION_LENGTH_F,
|
||||
() -> formatters.timeAmount().apply(getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toAverageSessionLength())
|
||||
);
|
||||
putSupplier(AnalysisKeys.SESSION_COUNT, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).count());
|
||||
putSupplier(AnalysisKeys.PLAYTIME_TOTAL, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toPlaytime());
|
||||
putSupplier(AnalysisKeys.DEATHS, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toDeathCount());
|
||||
putSupplier(AnalysisKeys.MOB_KILL_COUNT, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toMobKillCount());
|
||||
putSupplier(AnalysisKeys.PLAYER_KILL_COUNT, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toPlayerKillCount());
|
||||
putSupplier(AnalysisKeys.PLAYTIME_F, () -> Formatters.timeAmount()
|
||||
.apply(getUnsafe(AnalysisKeys.PLAYTIME_TOTAL))
|
||||
putSupplier(AnalysisKeys.PLAYTIME_F,
|
||||
() -> formatters.timeAmount().apply(getUnsafe(AnalysisKeys.PLAYTIME_TOTAL))
|
||||
);
|
||||
putSupplier(AnalysisKeys.AVERAGE_PLAYTIME_F, () -> {
|
||||
long players = getUnsafe(AnalysisKeys.PLAYERS_TOTAL);
|
||||
return players != 0 ? Formatters.timeAmount()
|
||||
.apply(getUnsafe(AnalysisKeys.PLAYTIME_TOTAL) / players) : "-";
|
||||
return players != 0
|
||||
? formatters.timeAmount().apply(getUnsafe(AnalysisKeys.PLAYTIME_TOTAL) / players)
|
||||
: "-";
|
||||
}
|
||||
);
|
||||
putSupplier(AnalysisKeys.AVERAGE_SESSION_LENGTH_F, () -> Formatters.timeAmount()
|
||||
.apply(getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toAverageSessionLength())
|
||||
putSupplier(AnalysisKeys.AVERAGE_SESSION_LENGTH_F,
|
||||
() -> formatters.timeAmount().apply(getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toAverageSessionLength())
|
||||
);
|
||||
|
||||
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))
|
||||
);
|
||||
|
||||
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_DAY, () -> getUnsafe(sessionsDay).toAverageUniqueJoinsPerDay());
|
||||
putSupplier(AnalysisKeys.AVG_PLAYERS_WEEK, () -> getUnsafe(sessionsWeek).toAverageUniqueJoinsPerDay());
|
||||
|
@ -320,46 +344,48 @@ public class AnalysisContainer extends DataContainer {
|
|||
|
||||
private void addGraphSuppliers() {
|
||||
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.GM_PIE_SERIES, () -> getUnsafe(worldPie).toHighChartsDrilldown());
|
||||
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.CPU_SERIES, () -> new CPUGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
||||
putSupplier(AnalysisKeys.RAM_SERIES, () -> new RamGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
||||
putSupplier(AnalysisKeys.ENTITY_SERIES, () -> new EntityGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
||||
putSupplier(AnalysisKeys.CHUNK_SERIES, () -> new ChunkGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
||||
putSupplier(AnalysisKeys.TPS_SERIES, () -> graphs.line().tpsGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
||||
putSupplier(AnalysisKeys.CPU_SERIES, () -> graphs.line().cpuGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
||||
putSupplier(AnalysisKeys.RAM_SERIES, () -> graphs.line().ramGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
||||
putSupplier(AnalysisKeys.ENTITY_SERIES, () -> graphs.line().entityGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
||||
putSupplier(AnalysisKeys.CHUNK_SERIES, () -> graphs.line().cpuGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
||||
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");
|
||||
putCachingSupplier(geolocationBarChart, () -> new GeolocationBarGraph(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)));
|
||||
Key<BarGraph> geolocationBarChart = new Key<>(BarGraph.class, "GEOLOCATION_BAR_GRAPH");
|
||||
putCachingSupplier(geolocationBarChart, () -> graphs.bar().geolocationBarGraph(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)));
|
||||
putSupplier(AnalysisKeys.COUNTRY_CATEGORIES, () -> getUnsafe(geolocationBarChart).toHighChartsCategories());
|
||||
putSupplier(AnalysisKeys.COUNTRY_SERIES, () -> getUnsafe(geolocationBarChart).toHighChartsSeries());
|
||||
|
||||
Key<PingGraph> pingGraph = new Key<>(PingGraph.class, "PING_GRAPH");
|
||||
putCachingSupplier(pingGraph, () -> new PingGraph(
|
||||
PingMutator.forContainer(serverContainer).mutateToByMinutePings().all()
|
||||
));
|
||||
putCachingSupplier(pingGraph, () ->
|
||||
graphs.line().pingGraph(PingMutator.forContainer(serverContainer).mutateToByMinutePings().all())
|
||||
);
|
||||
putSupplier(AnalysisKeys.AVG_PING_SERIES, () -> getUnsafe(pingGraph).toAvgSeries());
|
||||
putSupplier(AnalysisKeys.MAX_PING_SERIES, () -> getUnsafe(pingGraph).toMaxSeries());
|
||||
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.UNIQUE_PLAYERS_PER_DAY),
|
||||
getUnsafe(AnalysisKeys.NEW_PLAYERS_PER_DAY)
|
||||
).toCalendarSeries());
|
||||
|
||||
putCachingSupplier(AnalysisKeys.ACTIVITY_DATA, () -> getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).toActivityDataMap(getUnsafe(AnalysisKeys.ANALYSIS_TIME)));
|
||||
Key<ActivityStackGraph> activityStackGraph = new Key<>(ActivityStackGraph.class, "ACTIVITY_STACK_GRAPH");
|
||||
putCachingSupplier(activityStackGraph, () -> new ActivityStackGraph(getUnsafe(AnalysisKeys.ACTIVITY_DATA)));
|
||||
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<StackGraph> activityStackGraph = new Key<>(StackGraph.class, "ACTIVITY_STACK_GRAPH");
|
||||
putCachingSupplier(activityStackGraph, () -> graphs.stack().activityStackGraph(getUnsafe(AnalysisKeys.ACTIVITY_DATA)));
|
||||
putSupplier(AnalysisKeys.ACTIVITY_STACK_CATEGORIES, () -> getUnsafe(activityStackGraph).toHighChartsLabels());
|
||||
putSupplier(AnalysisKeys.ACTIVITY_STACK_SERIES, () -> getUnsafe(activityStackGraph).toHighChartsSeries());
|
||||
putSupplier(AnalysisKeys.ACTIVITY_PIE_SERIES, () ->
|
||||
new ActivityPie(getUnsafe(AnalysisKeys.ACTIVITY_DATA).get(getUnsafe(AnalysisKeys.ANALYSIS_TIME))).toHighChartsSeries()
|
||||
putSupplier(AnalysisKeys.ACTIVITY_PIE_SERIES, () -> graphs.pie().activityPie(
|
||||
getUnsafe(AnalysisKeys.ACTIVITY_DATA).get(getUnsafe(AnalysisKeys.ANALYSIS_TIME))).toHighChartsSeries()
|
||||
);
|
||||
putSupplier(AnalysisKeys.PLAYERS_REGULAR, () -> {
|
||||
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)));
|
||||
|
||||
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_CPU_MONTH, () -> getUnsafe(tpsMonth).averageCPU());
|
||||
putSupplier(AnalysisKeys.AVG_RAM_MONTH, () -> getUnsafe(tpsMonth).averageRAM());
|
||||
putSupplier(AnalysisKeys.AVG_ENTITY_MONTH, () -> getUnsafe(tpsMonth).averageEntities());
|
||||
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_CPU_WEEK, () -> getUnsafe(tpsWeek).averageCPU());
|
||||
putSupplier(AnalysisKeys.AVG_RAM_WEEK, () -> getUnsafe(tpsWeek).averageRAM());
|
||||
putSupplier(AnalysisKeys.AVG_ENTITY_WEEK, () -> getUnsafe(tpsWeek).averageEntities());
|
||||
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_CPU_DAY, () -> getUnsafe(tpsDay).averageCPU());
|
||||
putSupplier(AnalysisKeys.AVG_RAM_DAY, () -> getUnsafe(tpsDay).averageRAM());
|
||||
|
@ -409,14 +437,20 @@ public class AnalysisContainer extends DataContainer {
|
|||
}
|
||||
|
||||
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, () -> CommandUseMutator.forContainer(serverContainer).commandUsageCount());
|
||||
}
|
||||
|
||||
private void addServerHealth() {
|
||||
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_NOTES, () -> getUnsafe(healthInformation).toHtml());
|
||||
}
|
||||
|
@ -424,14 +458,66 @@ public class AnalysisContainer extends DataContainer {
|
|||
private void addPluginSuppliers() {
|
||||
// TODO Refactor into a system that supports running the analysis on Bungee
|
||||
Key<String[]> navAndTabs = new Key<>(new Type<String[]>() {}, "NAV_AND_TABS");
|
||||
putCachingSupplier(navAndTabs, () ->
|
||||
AnalysisPluginsTabContentCreator.createContent(
|
||||
getUnsafe(AnalysisKeys.PLAYERS_MUTATOR),
|
||||
this
|
||||
)
|
||||
);
|
||||
putCachingSupplier(AnalysisKeys.BAN_DATA, () -> new ServerBanDataReader().readBanDataForContainer(this));
|
||||
putCachingSupplier(navAndTabs, () -> pluginsTabContentCreator.createContent(
|
||||
this, getValue(AnalysisKeys.PLAYERS_MUTATOR).orElse(new PlayersMutator(new ArrayList<>()))
|
||||
));
|
||||
putSupplier(AnalysisKeys.PLUGINS_TAB_NAV, () -> getUnsafe(navAndTabs)[0]);
|
||||
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.Key;
|
||||
import com.djrapitops.plan.data.store.mutators.formatting.Formatter;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
|
@ -24,7 +24,7 @@ public class DataContainer {
|
|||
private long timeToLive;
|
||||
|
||||
public DataContainer() {
|
||||
this(TimeAmount.SECOND.ms() * 30L);
|
||||
this(TimeUnit.SECONDS.toMillis(30L));
|
||||
}
|
||||
|
||||
public DataContainer(long timeToLive) {
|
||||
|
|
|
@ -1,33 +1,35 @@
|
|||
package com.djrapitops.plan.data.store.containers;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.data.container.TPS;
|
||||
import com.djrapitops.plan.data.store.Key;
|
||||
import com.djrapitops.plan.data.store.keys.NetworkKeys;
|
||||
import com.djrapitops.plan.data.store.keys.ServerKeys;
|
||||
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
|
||||
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.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.info.server.properties.ServerProperties;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.system.settings.theme.ThemeVal;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plan.utilities.html.graphs.ActivityStackGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.WorldMap;
|
||||
import com.djrapitops.plan.utilities.html.graphs.bar.GeolocationBarGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.line.OnlineActivityGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.pie.ActivityPie;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
import com.djrapitops.plan.utilities.html.graphs.Graphs;
|
||||
import com.djrapitops.plan.utilities.html.graphs.bar.BarGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.stack.StackGraph;
|
||||
import com.djrapitops.plan.utilities.html.structure.NetworkServerBox;
|
||||
import com.djrapitops.plugin.api.Check;
|
||||
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.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* DataContainer for the whole network.
|
||||
|
@ -40,94 +42,122 @@ public class NetworkContainer extends DataContainer {
|
|||
|
||||
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;
|
||||
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));
|
||||
|
||||
addConstants();
|
||||
addServerBoxes();
|
||||
addPlayerInformation();
|
||||
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() {
|
||||
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_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() {
|
||||
long now = System.currentTimeMillis();
|
||||
putRawData(NetworkKeys.REFRESH_TIME, now);
|
||||
putRawData(NetworkKeys.REFRESH_TIME_DAY_AGO, getUnsafe(NetworkKeys.REFRESH_TIME) - TimeAmount.DAY.ms());
|
||||
putRawData(NetworkKeys.REFRESH_TIME_WEEK_AGO, getUnsafe(NetworkKeys.REFRESH_TIME) - TimeAmount.WEEK.ms());
|
||||
putRawData(NetworkKeys.REFRESH_TIME_MONTH_AGO, getUnsafe(NetworkKeys.REFRESH_TIME) - TimeAmount.MONTH.ms());
|
||||
putSupplier(NetworkKeys.REFRESH_TIME_F, () -> Formatters.second().apply(() -> getUnsafe(NetworkKeys.REFRESH_TIME)));
|
||||
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.toMillis(1L));
|
||||
putRawData(NetworkKeys.REFRESH_TIME_MONTH_AGO, getUnsafe(NetworkKeys.REFRESH_TIME) - TimeAmount.MONTH.toMillis(1L));
|
||||
putSupplier(NetworkKeys.REFRESH_TIME_F, () -> formatters.secondLong().apply(getUnsafe(NetworkKeys.REFRESH_TIME)));
|
||||
|
||||
putRawData(NetworkKeys.VERSION, PlanPlugin.getInstance().getVersion());
|
||||
putSupplier(NetworkKeys.TIME_ZONE, MiscUtils::getTimeZoneOffsetHours);
|
||||
putRawData(NetworkKeys.VERSION, version);
|
||||
putSupplier(NetworkKeys.TIME_ZONE, config::getTimeZoneOffsetHours);
|
||||
|
||||
putCachingSupplier(NetworkKeys.NETWORK_NAME, () ->
|
||||
Check.isBungeeAvailable() ?
|
||||
Settings.BUNGEE_NETWORK_NAME.toString() :
|
||||
config.getString(Settings.BUNGEE_NETWORK_NAME) :
|
||||
bungeeContainer.getValue(ServerKeys.NAME).orElse("Plan")
|
||||
);
|
||||
putSupplier(NetworkKeys.PLAYERS_ONLINE, ServerInfo.getServerProperties()::getOnlinePlayers);
|
||||
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.PLAYERS_GRAPH_COLOR, Theme.getValue(ThemeVal.GRAPH_PLAYERS_ONLINE));
|
||||
putSupplier(NetworkKeys.PLAYERS_ONLINE, serverProperties::getOnlinePlayers);
|
||||
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.PLAYERS_GRAPH_COLOR, theme.getValue(ThemeVal.GRAPH_PLAYERS_ONLINE));
|
||||
}
|
||||
|
||||
private void addPlayerInformation() {
|
||||
putSupplier(NetworkKeys.PLAYERS_TOTAL, () -> getUnsafe(NetworkKeys.PLAYERS_MUTATOR).count());
|
||||
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");
|
||||
putSupplier(geolocationBarChart, () -> new GeolocationBarGraph(getUnsafe(NetworkKeys.PLAYERS_MUTATOR)));
|
||||
Key<BarGraph> geolocationBarChart = new Key<>(BarGraph.class, "GEOLOCATION_BAR_GRAPH");
|
||||
putSupplier(geolocationBarChart, () -> graphs.bar().geolocationBarGraph(getUnsafe(NetworkKeys.PLAYERS_MUTATOR)));
|
||||
putSupplier(NetworkKeys.COUNTRY_CATEGORIES, () -> getUnsafe(geolocationBarChart).toHighChartsCategories());
|
||||
putSupplier(NetworkKeys.COUNTRY_SERIES, () -> getUnsafe(geolocationBarChart).toHighChartsSeries());
|
||||
|
||||
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");
|
||||
putSupplier(NetworkKeys.ACTIVITY_DATA, () -> getUnsafe(NetworkKeys.PLAYERS_MUTATOR).toActivityDataMap(getUnsafe(NetworkKeys.REFRESH_TIME)));
|
||||
putSupplier(activityStackGraph, () -> new ActivityStackGraph(getUnsafe(NetworkKeys.ACTIVITY_DATA)));
|
||||
Key<StackGraph> activityStackGraph = new Key<>(StackGraph.class, "ACTIVITY_STACK_GRAPH");
|
||||
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, () -> graphs.stack().activityStackGraph(getUnsafe(NetworkKeys.ACTIVITY_DATA)));
|
||||
putSupplier(NetworkKeys.ACTIVITY_STACK_CATEGORIES, () -> getUnsafe(activityStackGraph).toHighChartsLabels());
|
||||
putSupplier(NetworkKeys.ACTIVITY_STACK_SERIES, () -> getUnsafe(activityStackGraph).toHighChartsSeries());
|
||||
putSupplier(NetworkKeys.ACTIVITY_PIE_SERIES, () ->
|
||||
new ActivityPie(getUnsafe(NetworkKeys.ACTIVITY_DATA).get(getUnsafe(NetworkKeys.REFRESH_TIME))).toHighChartsSeries()
|
||||
putSupplier(NetworkKeys.ACTIVITY_PIE_SERIES, () -> graphs.pie().activityPie(
|
||||
getUnsafe(NetworkKeys.ACTIVITY_DATA).get(getUnsafe(NetworkKeys.REFRESH_TIME))).toHighChartsSeries()
|
||||
);
|
||||
|
||||
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, () ->
|
||||
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, () ->
|
||||
bungeeContainer.getValue(ServerKeys.ALL_TIME_PEAK_PLAYERS).map(dateObj -> "" + dateObj.getValue()).orElse("-")
|
||||
|
@ -176,4 +206,49 @@ public class NetworkContainer extends DataContainer {
|
|||
public ServerContainer getBungeeContainer() {
|
||||
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<>();
|
||||
}
|
||||
|
||||
public ActivityIndex getActivityIndex(long date) {
|
||||
return activityIndexCache.computeIfAbsent(date, time -> new ActivityIndex(this, time));
|
||||
public ActivityIndex getActivityIndex(long date, int minuteThreshold, int loginThreshold) {
|
||||
return activityIndexCache.computeIfAbsent(date, time -> new ActivityIndex(this, time, minuteThreshold, loginThreshold));
|
||||
}
|
||||
|
||||
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<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;
|
||||
@Deprecated
|
||||
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>> 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;
|
||||
|
||||
import com.djrapitops.plan.data.container.TPS;
|
||||
import com.djrapitops.plan.data.store.Key;
|
||||
import com.djrapitops.plan.data.store.PlaceholderKey;
|
||||
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_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> PLAYERS_ONLINE_SERIES = CommonPlaceholderKeys.PLAYERS_ONLINE_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<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() {
|
||||
/* static variable class */
|
||||
|
|
|
@ -32,6 +32,7 @@ public class SessionKeys {
|
|||
public static final Key<Integer> DEATH_COUNT = CommonKeys.DEATH_COUNT;
|
||||
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");
|
||||
|
||||
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.store.containers.DataContainer;
|
||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.utilities.FormatUtils;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ActivityIndex {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -22,22 +31,14 @@ public class ActivityIndex {
|
|||
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) {
|
||||
long week = TimeAmount.WEEK.ms();
|
||||
long week = TimeAmount.WEEK.toMillis(1L);
|
||||
long weekAgo = date - week;
|
||||
long twoWeeksAgo = date - 2L * week;
|
||||
long threeWeeksAgo = date - 3L * week;
|
||||
|
||||
long activePlayThreshold = loadSetting(Settings.ACTIVE_PLAY_THRESHOLD.getNumber() * TimeAmount.MINUTE.ms());
|
||||
int activeLoginThreshold = loadSetting(Settings.ACTIVE_LOGIN_THRESHOLD.getNumber());
|
||||
long activePlayThreshold = TimeUnit.MINUTES.toMillis(playThreshold);
|
||||
int activeLoginThreshold = loginThreshold;
|
||||
|
||||
Optional<List<Session>> sessionsValue = container.getValue(PlayerKeys.SESSIONS);
|
||||
if (!sessionsValue.isPresent()) {
|
||||
|
@ -109,8 +110,8 @@ public class ActivityIndex {
|
|||
return value;
|
||||
}
|
||||
|
||||
public String getFormattedValue() {
|
||||
return FormatUtils.cutDecimals(value);
|
||||
public String getFormattedValue(Formatter<Double> formatter) {
|
||||
return formatter.apply(value);
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package com.djrapitops.plan.data.store.mutators;
|
||||
|
||||
import com.djrapitops.plan.data.store.objects.DateHolder;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class DateHoldersMutator<T extends DateHolder> {
|
||||
|
||||
|
@ -17,7 +17,7 @@ public class DateHoldersMutator<T extends DateHolder> {
|
|||
}
|
||||
|
||||
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) {
|
||||
|
@ -39,7 +39,7 @@ public class DateHoldersMutator<T extends DateHolder> {
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
// Empty map firstKey attempt causes NPE if not checked.
|
||||
|
|
|
@ -70,8 +70,8 @@ public class PlayersMutator {
|
|||
);
|
||||
}
|
||||
|
||||
public PlayersMutator filterActive(long date, double limit) {
|
||||
return filterBy(player -> player.getActivityIndex(date).getValue() >= limit);
|
||||
public PlayersMutator filterActive(long date, int minuteThreshold, int loginThreshold, double limit) {
|
||||
return filterBy(player -> player.getActivityIndex(date, minuteThreshold, loginThreshold).getValue() >= limit);
|
||||
}
|
||||
|
||||
public PlayersMutator filterPlayedOnServer(UUID serverUUID) {
|
||||
|
@ -123,16 +123,16 @@ public class PlayersMutator {
|
|||
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<>();
|
||||
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<>());
|
||||
if (!players.isEmpty()) {
|
||||
for (PlayerContainer player : players) {
|
||||
if (player.getValue(PlayerKeys.REGISTERED).orElse(0L) > time) {
|
||||
continue;
|
||||
}
|
||||
ActivityIndex activityIndex = player.getActivityIndex(time);
|
||||
ActivityIndex activityIndex = player.getActivityIndex(time, minuteThreshold, loginThreshold);
|
||||
String activityGroup = activityIndex.getGroup();
|
||||
|
||||
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.
|
||||
* @throws IllegalStateException If all players are rejected due to dateLimit.
|
||||
*/
|
||||
public PlayersMutator compareAndFindThoseLikelyToBeRetained(Iterable<PlayerContainer> compareTo,
|
||||
long dateLimit,
|
||||
PlayersOnlineResolver onlineResolver) {
|
||||
public PlayersMutator compareAndFindThoseLikelyToBeRetained(
|
||||
Iterable<PlayerContainer> compareTo,
|
||||
long dateLimit,
|
||||
PlayersOnlineResolver onlineResolver,
|
||||
int activityMinuteThreshold,
|
||||
int activityLoginThreshold
|
||||
) {
|
||||
Collection<PlayerContainer> retainedAfterMonth = new ArrayList<>();
|
||||
Collection<PlayerContainer> notRetainedAfterMonth = new ArrayList<>();
|
||||
|
||||
|
@ -189,8 +193,8 @@ public class PlayersMutator {
|
|||
continue;
|
||||
}
|
||||
|
||||
long monthAfterRegister = registered + TimeAmount.MONTH.ms();
|
||||
long half = registered + (TimeAmount.MONTH.ms() / 2L);
|
||||
long monthAfterRegister = registered + TimeAmount.MONTH.toMillis(1L);
|
||||
long half = registered + (TimeAmount.MONTH.toMillis(1L) / 2L);
|
||||
if (player.playedBetween(registered, half) && player.playedBetween(half, monthAfterRegister)) {
|
||||
retainedAfterMonth.add(player);
|
||||
} else {
|
||||
|
@ -203,10 +207,10 @@ public class PlayersMutator {
|
|||
}
|
||||
|
||||
List<RetentionData> retained = retainedAfterMonth.stream()
|
||||
.map(player -> new RetentionData(player, onlineResolver))
|
||||
.map(player -> new RetentionData(player, onlineResolver, activityMinuteThreshold, activityLoginThreshold))
|
||||
.collect(Collectors.toList());
|
||||
List<RetentionData> notRetained = notRetainedAfterMonth.stream()
|
||||
.map(player -> new RetentionData(player, onlineResolver))
|
||||
.map(player -> new RetentionData(player, onlineResolver, activityMinuteThreshold, activityLoginThreshold))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
RetentionData avgRetained = RetentionData.average(retained);
|
||||
|
@ -214,7 +218,7 @@ public class PlayersMutator {
|
|||
|
||||
List<PlayerContainer> toBeRetained = new ArrayList<>();
|
||||
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)) {
|
||||
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.keys.PlayerKeys;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Utility class for player retention calculations.
|
||||
|
@ -45,10 +45,20 @@ public class RetentionData {
|
|||
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);
|
||||
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);
|
||||
this.onlineOnJoin = registeredValue
|
||||
.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.store.containers.DataContainer;
|
||||
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.html.graphs.line.Point;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.OptionalDouble;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -99,7 +98,7 @@ public class TPSMutator {
|
|||
}
|
||||
|
||||
long diff = date - lastDate;
|
||||
if (diff > TimeAmount.MINUTE.ms() * 3L) {
|
||||
if (diff > TimeUnit.MINUTES.toMillis(3L)) {
|
||||
downTime += diff;
|
||||
}
|
||||
lastDate = date;
|
||||
|
@ -134,13 +133,11 @@ public class TPSMutator {
|
|||
return idleTime;
|
||||
}
|
||||
|
||||
public double percentageTPSAboveLowThreshold() {
|
||||
public double percentageTPSAboveThreshold(int threshold) {
|
||||
if (tpsData.isEmpty()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int threshold = Settings.THEME_GRAPH_TPS_THRESHOLD_MED.getNumber();
|
||||
|
||||
long count = 0;
|
||||
for (TPS tps : tpsData) {
|
||||
if (tps.getTicksPerSecond() >= threshold) {
|
||||
|
@ -151,15 +148,13 @@ public class TPSMutator {
|
|||
return count * 1.0 / tpsData.size();
|
||||
}
|
||||
|
||||
public int lowTpsSpikeCount() {
|
||||
int mediumThreshold = Settings.THEME_GRAPH_TPS_THRESHOLD_MED.getNumber();
|
||||
|
||||
public int lowTpsSpikeCount(int threshold) {
|
||||
boolean wasLow = false;
|
||||
int spikeCount = 0;
|
||||
|
||||
for (TPS tpsObj : tpsData) {
|
||||
double tps = tpsObj.getTicksPerSecond();
|
||||
if (tps < mediumThreshold) {
|
||||
if (tps < threshold) {
|
||||
if (!wasLow) {
|
||||
spikeCount++;
|
||||
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.mutators.PlayersMutator;
|
||||
import com.djrapitops.plan.data.store.mutators.SessionsMutator;
|
||||
import com.djrapitops.plan.data.store.mutators.formatting.Formatters;
|
||||
import com.djrapitops.plan.utilities.FormatUtils;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
import com.djrapitops.plan.utilities.html.icon.Icons;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public abstract class AbstractHealthInfo {
|
||||
|
||||
|
@ -20,9 +19,27 @@ public abstract class AbstractHealthInfo {
|
|||
|
||||
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.monthAgo = monthAgo;
|
||||
this.activeMinuteThreshold = activeMinuteThreshold;
|
||||
this.activeLoginThreshold = activeLoginThreshold;
|
||||
this.timeAmountFormatter = timeAmountFormatter;
|
||||
this.decimalFormatter = decimalFormatter;
|
||||
this.percentageFormatter = percentageFormatter;
|
||||
serverHealth = 100.0;
|
||||
|
||||
this.notes = new ArrayList<>();
|
||||
|
@ -63,7 +80,7 @@ public abstract class AbstractHealthInfo {
|
|||
regularRemainCompareSet.removeAll(veryActiveNow);
|
||||
int notRegularAnymore = regularRemainCompareSet.size();
|
||||
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);
|
||||
|
||||
|
@ -72,16 +89,16 @@ public abstract class AbstractHealthInfo {
|
|||
String remainNote = "";
|
||||
if (activeFWAGNum != 0) {
|
||||
remainNote = "<br> ";
|
||||
if (percRemain > 50) {
|
||||
if (percRemain > 0.5) {
|
||||
remainNote += Icons.GREEN_THUMB;
|
||||
} else if (percRemain > 20) {
|
||||
} else if (percRemain > 0.2) {
|
||||
remainNote += Icons.YELLOW_FLAG;
|
||||
} else {
|
||||
remainNote += Icons.RED_WARN;
|
||||
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 + ")";
|
||||
}
|
||||
if (change > 0) {
|
||||
|
@ -98,7 +115,7 @@ public abstract class AbstractHealthInfo {
|
|||
}
|
||||
|
||||
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 totalFourToTwoWeeks = 0;
|
||||
|
@ -113,13 +130,13 @@ public abstract class AbstractHealthInfo {
|
|||
if (activeCount != 0) {
|
||||
long avgFourToTwoWeeks = totalFourToTwoWeeks / (long) activeCount;
|
||||
long avgLastTwoWeeks = totalLastTwoWeeks / (long) activeCount;
|
||||
String avgLastTwoWeeksString = Formatters.timeAmount().apply(avgLastTwoWeeks);
|
||||
String avgFourToTwoWeeksString = Formatters.timeAmount().apply(avgFourToTwoWeeks);
|
||||
String avgLastTwoWeeksString = timeAmountFormatter.apply(avgLastTwoWeeks);
|
||||
String avgFourToTwoWeeksString = timeAmountFormatter.apply(avgFourToTwoWeeks);
|
||||
if (avgFourToTwoWeeks >= avgLastTwoWeeks) {
|
||||
addNote(Icons.GREEN_THUMB + " Active players seem to have things to do (Played "
|
||||
+ avgLastTwoWeeksString + " vs " + avgFourToTwoWeeksString
|
||||
+ ", 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 "
|
||||
+ avgLastTwoWeeksString + " vs " + avgFourToTwoWeeksString
|
||||
+ ", 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.PlayersOnlineResolver;
|
||||
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
||||
import com.djrapitops.plan.data.store.mutators.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.formatting.Formatter;
|
||||
import com.djrapitops.plan.utilities.html.icon.Icons;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Server Health analysis mutator.
|
||||
|
@ -29,12 +27,23 @@ public class HealthInformation extends AbstractHealthInfo {
|
|||
|
||||
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(
|
||||
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.lowTPSThreshold = lowTPSThreshold;
|
||||
calculate();
|
||||
}
|
||||
|
||||
|
@ -67,10 +76,10 @@ public class HealthInformation extends AbstractHealthInfo {
|
|||
.average().orElse(0);
|
||||
if (avgOnlineOnRegister >= 1) {
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -80,10 +89,10 @@ public class HealthInformation extends AbstractHealthInfo {
|
|||
if (playersNewMonth != 0) {
|
||||
double retainPercentage = playersRetainedMonth * 1.0 / playersNewMonth;
|
||||
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 + ")");
|
||||
} else {
|
||||
addNote(Icons.YELLOW_FLAG + " " + Formatters.percentage().apply(retainPercentage)
|
||||
addNote(Icons.YELLOW_FLAG + " " + percentageFormatter.apply(retainPercentage)
|
||||
+ " 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");
|
||||
TPSMutator tpsMutator = analysisContainer.getUnsafe(tpsMonth);
|
||||
long serverDownTime = tpsMutator.serverDownTime();
|
||||
double aboveThreshold = tpsMutator.percentageTPSAboveLowThreshold();
|
||||
|
||||
double aboveThreshold = tpsMutator.percentageTPSAboveThreshold(lowTPSThreshold);
|
||||
long tpsSpikeMonth = analysisContainer.getValue(AnalysisKeys.TPS_SPIKE_MONTH).orElse(0);
|
||||
|
||||
String avgLowThresholdString = "<br> ";
|
||||
|
@ -107,34 +117,36 @@ public class HealthInformation extends AbstractHealthInfo {
|
|||
serverHealth *= 0.6;
|
||||
}
|
||||
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) {
|
||||
addNote(Icons.GREEN_THUMB + " Average TPS dropped below Low Threshold (" + threshold + ")" +
|
||||
addNote(Icons.GREEN_THUMB + " Average TPS dropped below Low Threshold (" + lowTPSThreshold + ")" +
|
||||
" " + tpsSpikeMonth + " times" +
|
||||
avgLowThresholdString);
|
||||
} 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" +
|
||||
avgLowThresholdString);
|
||||
serverHealth *= 0.95;
|
||||
} 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" +
|
||||
avgLowThresholdString);
|
||||
serverHealth *= 0.8;
|
||||
}
|
||||
|
||||
Formatter<Long> formatter = Formatters.timeAmount();
|
||||
if (serverDownTime <= TimeAmount.DAY.ms()) {
|
||||
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();
|
||||
if (serverDownTime <= TimeUnit.DAYS.toMillis(1L)) {
|
||||
addNote(Icons.GREEN_THUMB + " Total Server downtime (No Data) was " + timeAmountFormatter.apply(serverDownTime));
|
||||
} else {
|
||||
addNote(Icons.RED_WARN + " Total Server downtime (No Data) was " + formatter.apply(serverDownTime));
|
||||
serverHealth *= (TimeAmount.MONTH.ms() - serverDownTime) * 1.0 / TimeAmount.MONTH.ms();
|
||||
long weekMs = TimeAmount.WEEK.toMillis(1L);
|
||||
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.SessionsMutator;
|
||||
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.Icons;
|
||||
|
||||
|
@ -18,10 +18,18 @@ public class NetworkHealthInformation extends AbstractHealthInfo {
|
|||
|
||||
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(
|
||||
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;
|
||||
calculate();
|
||||
|
@ -82,7 +90,7 @@ public class NetworkHealthInformation extends AbstractHealthInfo {
|
|||
return subNote + (playersPerMonth >= average && playersPerMonth > 0 ? Icons.GREEN_PLUS : Icons.RED_MINUS) + " " +
|
||||
server.getName() + ": " + playersPerMonth;
|
||||
}).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) {
|
||||
|
@ -109,7 +117,7 @@ public class NetworkHealthInformation extends AbstractHealthInfo {
|
|||
return subNote + (playersPerMonth >= average && playersPerMonth > 0 ? Icons.GREEN_PLUS : Icons.RED_MINUS) + " " +
|
||||
server.getName() + ": " + playersPerMonth;
|
||||
}).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) {
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
package com.djrapitops.plan.data.time;
|
||||
|
||||
import com.djrapitops.plan.system.settings.WorldAliasSettings;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 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.system.cache.CacheSystem;
|
||||
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.server.ServerInfo;
|
||||
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.processing.Processing;
|
||||
import com.djrapitops.plan.system.settings.config.ConfigSystem;
|
||||
import com.djrapitops.plan.system.tasks.TaskSystem;
|
||||
import com.djrapitops.plan.system.update.VersionCheckSystem;
|
||||
import com.djrapitops.plan.system.webserver.WebServerSystem;
|
||||
import com.djrapitops.plugin.api.Check;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* PlanSystem contains everything Plan needs to run.
|
||||
|
@ -33,67 +34,77 @@ import java.util.function.Supplier;
|
|||
*
|
||||
* @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 Processing processing;
|
||||
protected final WebServerSystem webServerSystem;
|
||||
protected final LocaleSystem localeSystem;
|
||||
protected CacheSystem cacheSystem;
|
||||
private final Processing processing;
|
||||
|
||||
// These need to be initialized in the sub class.
|
||||
protected VersionCheckSystem versionCheckSystem;
|
||||
protected FileSystem fileSystem;
|
||||
protected ConfigSystem configSystem;
|
||||
protected DBSystem databaseSystem;
|
||||
protected InfoSystem infoSystem;
|
||||
private final ImportSystem importSystem;
|
||||
private final ExportSystem exportSystem;
|
||||
private final HookHandler hookHandler;
|
||||
private final PlanAPI planAPI;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
protected ListenerSystem listenerSystem;
|
||||
protected TaskSystem taskSystem;
|
||||
protected ServerInfo serverInfo;
|
||||
|
||||
protected HookHandler hookHandler;
|
||||
|
||||
// Not a SubSystem.
|
||||
protected PlanAPI planAPI;
|
||||
|
||||
public PlanSystem() {
|
||||
Supplier<Locale> localeSupplier = () -> getLocaleSystem().getLocale();
|
||||
|
||||
processing = new Processing(localeSupplier);
|
||||
webServerSystem = new WebServerSystem(localeSupplier);
|
||||
localeSystem = new LocaleSystem();
|
||||
cacheSystem = new CacheSystem(this);
|
||||
}
|
||||
|
||||
public static PlanSystem getInstance() {
|
||||
boolean bukkitAvailable = Check.isBukkitAvailable();
|
||||
boolean bungeeAvailable = Check.isBungeeAvailable();
|
||||
boolean spongeAvailable = Check.isSpongeAvailable();
|
||||
if (bukkitAvailable && bungeeAvailable) {
|
||||
return testSystem;
|
||||
} else if (bungeeAvailable) {
|
||||
return BungeeSystem.getInstance();
|
||||
} else if (bukkitAvailable) {
|
||||
return BukkitSystem.getInstance();
|
||||
} else if (spongeAvailable) {
|
||||
return SpongeSystem.getInstance();
|
||||
}
|
||||
throw new IllegalAccessError("PlanSystem is not available on this platform.");
|
||||
@Inject
|
||||
public PlanSystem(
|
||||
PlanFiles files,
|
||||
ConfigSystem configSystem,
|
||||
VersionCheckSystem versionCheckSystem,
|
||||
LocaleSystem localeSystem,
|
||||
DBSystem databaseSystem,
|
||||
CacheSystem cacheSystem,
|
||||
ListenerSystem listenerSystem,
|
||||
TaskSystem taskSystem,
|
||||
InfoSystem infoSystem,
|
||||
ServerInfo serverInfo,
|
||||
WebServerSystem webServerSystem,
|
||||
Processing processing,
|
||||
ImportSystem importSystem,
|
||||
ExportSystem exportSystem,
|
||||
HookHandler hookHandler,
|
||||
PlanAPI planAPI,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
this.files = files;
|
||||
this.configSystem = configSystem;
|
||||
this.versionCheckSystem = versionCheckSystem;
|
||||
this.localeSystem = localeSystem;
|
||||
this.databaseSystem = databaseSystem;
|
||||
this.cacheSystem = cacheSystem;
|
||||
this.listenerSystem = listenerSystem;
|
||||
this.taskSystem = taskSystem;
|
||||
this.infoSystem = infoSystem;
|
||||
this.serverInfo = serverInfo;
|
||||
this.webServerSystem = webServerSystem;
|
||||
this.processing = processing;
|
||||
this.importSystem = importSystem;
|
||||
this.exportSystem = exportSystem;
|
||||
this.hookHandler = hookHandler;
|
||||
this.planAPI = planAPI;
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() throws EnableException {
|
||||
checkSubSystemInitialization();
|
||||
|
||||
enableSystems(
|
||||
fileSystem,
|
||||
files,
|
||||
configSystem,
|
||||
localeSystem,
|
||||
versionCheckSystem,
|
||||
databaseSystem,
|
||||
exportSystem,
|
||||
webServerSystem,
|
||||
processing,
|
||||
serverInfo,
|
||||
|
@ -118,6 +129,7 @@ public abstract class PlanSystem implements SubSystem {
|
|||
hookHandler,
|
||||
cacheSystem,
|
||||
listenerSystem,
|
||||
exportSystem,
|
||||
processing,
|
||||
databaseSystem,
|
||||
webServerSystem,
|
||||
|
@ -125,7 +137,7 @@ public abstract class PlanSystem implements SubSystem {
|
|||
serverInfo,
|
||||
localeSystem,
|
||||
configSystem,
|
||||
fileSystem,
|
||||
files,
|
||||
versionCheckSystem
|
||||
);
|
||||
}
|
||||
|
@ -137,29 +149,11 @@ public abstract class PlanSystem implements SubSystem {
|
|||
system.disable();
|
||||
}
|
||||
} 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.
|
||||
|
||||
public VersionCheckSystem getVersionCheckSystem() {
|
||||
|
@ -170,8 +164,8 @@ public abstract class PlanSystem implements SubSystem {
|
|||
return configSystem;
|
||||
}
|
||||
|
||||
public FileSystem getFileSystem() {
|
||||
return fileSystem;
|
||||
public PlanFiles getPlanFiles() {
|
||||
return files;
|
||||
}
|
||||
|
||||
public DBSystem getDatabaseSystem() {
|
||||
|
@ -190,6 +184,14 @@ public abstract class PlanSystem implements SubSystem {
|
|||
return webServerSystem;
|
||||
}
|
||||
|
||||
public ImportSystem getImportSystem() {
|
||||
return importSystem;
|
||||
}
|
||||
|
||||
public ExportSystem getExportSystem() {
|
||||
return exportSystem;
|
||||
}
|
||||
|
||||
public ServerInfo getServerInfo() {
|
||||
return serverInfo;
|
||||
}
|
||||
|
@ -214,11 +216,7 @@ public abstract class PlanSystem implements SubSystem {
|
|||
return processing;
|
||||
}
|
||||
|
||||
static void setTestSystem(PlanSystem testSystem) {
|
||||
PlanSystem.testSystem = testSystem;
|
||||
}
|
||||
|
||||
public LocaleSystem getLocaleSystem() {
|
||||
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.system.cache.SessionCache;
|
||||
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.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 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 long afkThresholdMs;
|
||||
|
||||
public AFKTracker() {
|
||||
public AFKTracker(PlanConfig config) {
|
||||
usedAFKCommand = new HashSet<>();
|
||||
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) {
|
||||
|
|
|
@ -5,33 +5,26 @@
|
|||
package com.djrapitops.plan.system.cache;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.system.PlanSystem;
|
||||
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.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class CacheSystem implements SubSystem {
|
||||
|
||||
private final DataCache dataCache;
|
||||
private final GeolocationCache geolocationCache;
|
||||
|
||||
public CacheSystem(PlanSystem system) {
|
||||
this(new DataCache(system), system);
|
||||
}
|
||||
|
||||
protected CacheSystem(DataCache dataCache, PlanSystem system) {
|
||||
@Inject
|
||||
public CacheSystem(DataCache dataCache, GeolocationCache geolocationCache) {
|
||||
this.dataCache = dataCache;
|
||||
geolocationCache = new GeolocationCache(() -> system.getLocaleSystem().getLocale());
|
||||
}
|
||||
|
||||
public static CacheSystem getInstance() {
|
||||
CacheSystem cacheSystem = PlanSystem.getInstance().getCacheSystem();
|
||||
Verify.nullCheck(cacheSystem, () -> new IllegalStateException("Cache System was not initialized."));
|
||||
return cacheSystem;
|
||||
this.geolocationCache = geolocationCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
package com.djrapitops.plan.system.cache;
|
||||
|
||||
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.database.databases.Database;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
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.
|
||||
|
@ -22,24 +26,32 @@ import java.util.*;
|
|||
* @author Rsl1122
|
||||
* @since 4.0.0
|
||||
*/
|
||||
@Singleton
|
||||
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<String, UUID> uuids;
|
||||
private final Map<UUID, String> displayNames;
|
||||
|
||||
public DataCache(PlanSystem system) {
|
||||
super(system);
|
||||
|
||||
@Inject
|
||||
public DataCache(
|
||||
Database database,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super(database);
|
||||
this.errorHandler = errorHandler;
|
||||
playerNames = new HashMap<>();
|
||||
displayNames = new HashMap<>();
|
||||
uuids = new HashMap<>();
|
||||
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
db = system.getDatabaseSystem().getActiveDatabase();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,12 +61,6 @@ public class DataCache extends SessionCache implements SubSystem {
|
|||
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.
|
||||
*
|
||||
|
@ -87,10 +93,10 @@ public class DataCache extends SessionCache implements SubSystem {
|
|||
String name = playerNames.get(uuid);
|
||||
if (name == null) {
|
||||
try {
|
||||
name = db.fetch().getPlayerName(uuid);
|
||||
name = database.fetch().getPlayerName(uuid);
|
||||
playerNames.put(uuid, name);
|
||||
} catch (DBOpException e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
name = "Error occurred";
|
||||
}
|
||||
}
|
||||
|
@ -110,21 +116,17 @@ public class DataCache extends SessionCache implements SubSystem {
|
|||
if (cached == null) {
|
||||
List<String> nicknames;
|
||||
try {
|
||||
nicknames = db.fetch().getNicknames(uuid);
|
||||
nicknames = database.fetch().getNicknames(uuid);
|
||||
if (!nicknames.isEmpty()) {
|
||||
return nicknames.get(nicknames.size() - 1);
|
||||
}
|
||||
} catch (DBOpException e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
}
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
|
||||
public Set<UUID> getUuids() {
|
||||
return playerNames.keySet();
|
||||
}
|
||||
|
||||
public UUID getUUIDof(String 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.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.lang.PluginLang;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.maxmind.geoip2.DatabaseReader;
|
||||
import com.maxmind.geoip2.exception.GeoIp2Exception;
|
||||
import com.maxmind.geoip2.model.CountryResponse;
|
||||
import com.maxmind.geoip2.record.Country;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -24,7 +27,6 @@ import java.nio.channels.Channels;
|
|||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
/**
|
||||
|
@ -35,30 +37,45 @@ import java.util.zip.GZIPInputStream;
|
|||
* @author Fuzzlemann
|
||||
* @since 3.5.5
|
||||
*/
|
||||
@Singleton
|
||||
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 File geolocationDB;
|
||||
|
||||
public GeolocationCache(Supplier<Locale> locale) {
|
||||
@Inject
|
||||
public GeolocationCache(
|
||||
Locale locale,
|
||||
PlanFiles files,
|
||||
PlanConfig config,
|
||||
PluginLogger logger
|
||||
) {
|
||||
this.locale = locale;
|
||||
cached = new HashMap<>();
|
||||
this.files = files;
|
||||
this.config = config;
|
||||
this.logger = logger;
|
||||
|
||||
this.cached = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() throws EnableException {
|
||||
geolocationDB = new File(FileSystem.getDataFolder(), "GeoIP.dat");
|
||||
if (Settings.DATA_GEOLOCATIONS.isTrue()) {
|
||||
geolocationDB = files.getFileFromPluginFolder("GeoIP.dat");
|
||||
if (config.isTrue(Settings.DATA_GEOLOCATIONS)) {
|
||||
try {
|
||||
GeolocationCache.checkDB();
|
||||
checkDB();
|
||||
} 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) {
|
||||
throw new EnableException(locale.get().getString(PluginLang.ENABLE_FAIL_GEODB_WRITE), e);
|
||||
throw new EnableException(locale.getString(PluginLang.ENABLE_FAIL_GEODB_WRITE), e);
|
||||
}
|
||||
} 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.
|
||||
* @see #getUnCachedCountry(String)
|
||||
*/
|
||||
public static String getCountry(String ipAddress) {
|
||||
public String getCountry(String ipAddress) {
|
||||
String country = getCachedCountry(ipAddress);
|
||||
|
||||
if (country != null) {
|
||||
return country;
|
||||
} else {
|
||||
country = getUnCachedCountry(ipAddress);
|
||||
getInstance().cached.put(ipAddress, country);
|
||||
cached.put(ipAddress, 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
|
||||
*
|
||||
* @param ipAddress The IP Address which is retrieved out of the cache
|
||||
* @return The cached country, {@code null} if the country is not cached
|
||||
*/
|
||||
private static String getCachedCountry(String ipAddress) {
|
||||
return getInstance().cached.get(ipAddress);
|
||||
private String getCachedCountry(String 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 #getCountry(String)
|
||||
*/
|
||||
private static String getUnCachedCountry(String ipAddress) {
|
||||
private String getUnCachedCountry(String ipAddress) {
|
||||
if ("127.0.0.1".equals(ipAddress)) {
|
||||
return "Local Machine";
|
||||
}
|
||||
try {
|
||||
checkDB();
|
||||
|
||||
try (DatabaseReader reader = new DatabaseReader.Builder(getInstance().geolocationDB).build()) {
|
||||
try (DatabaseReader reader = new DatabaseReader.Builder(geolocationDB).build()) {
|
||||
InetAddress inetAddress = InetAddress.getByName(ipAddress);
|
||||
|
||||
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
|
||||
*/
|
||||
public static void checkDB() throws IOException {
|
||||
if (getInstance().geolocationDB.exists()) {
|
||||
private void checkDB() throws IOException {
|
||||
if (geolocationDB.exists()) {
|
||||
return;
|
||||
}
|
||||
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();
|
||||
GZIPInputStream gzipIn = new GZIPInputStream(in);
|
||||
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);
|
||||
}
|
||||
|
@ -164,8 +175,8 @@ public class GeolocationCache implements SubSystem {
|
|||
* @param ipAddress The IP Address which is checked
|
||||
* @return true if the IP Address is cached
|
||||
*/
|
||||
public static boolean isCached(String ipAddress) {
|
||||
return getInstance().cached.containsKey(ipAddress);
|
||||
boolean isCached(String ipAddress) {
|
||||
return cached.containsKey(ipAddress);
|
||||
}
|
||||
|
||||
@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