[Merge] Version 4.5.0
This commit is contained in:
commit
d7694a0f1c
|
@ -3,7 +3,7 @@ sudo: false
|
|||
install: true
|
||||
before_install:
|
||||
- cd PlanPluginBridge
|
||||
- mvn install:install-file -Dfile=./PlanPluginBridge-4.4.0.jar -DpomFile=./pom.xml
|
||||
- mvn install:install-file -Dfile=./PlanPluginBridge-4.5.0.jar -DpomFile=./pom.xml
|
||||
- cd ../Plan
|
||||
install:
|
||||
- mvn clean
|
||||
|
|
|
@ -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>
|
||||
|
@ -20,6 +20,7 @@
|
|||
<include>**/*.js</include>
|
||||
<include>**/*.css</include>
|
||||
<include>locale/*.txt</include>
|
||||
<include>**/*.ico</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
|
@ -31,6 +32,23 @@
|
|||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>com.google.dagger</groupId>
|
||||
<artifactId>dagger-compiler</artifactId>
|
||||
<version>2.17</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>com.velocitypowered</groupId>
|
||||
<artifactId>velocity-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
<artifactId>spongeapi</artifactId>
|
||||
<version>7.1.0</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
@ -58,6 +76,7 @@
|
|||
<exclude>org.mockito:*</exclude>
|
||||
<exclude>org.easymock:*</exclude>
|
||||
<exclude>junit:*</exclude>
|
||||
<exclued>org.slf4j:*</exclued>
|
||||
</excludes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
|
@ -80,10 +99,6 @@
|
|||
<pattern>com.zaxxer</pattern>
|
||||
<shadedPattern>plan.com.zaxxer</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.slf4j</pattern>
|
||||
<shadedPattern>plan.org.slf4j</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>com.djrapitops.plan.utilities.metrics</shadedPattern>
|
||||
|
@ -147,9 +162,13 @@
|
|||
<url>https://repo.spongepowered.org/maven</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>md_5-snapshots</id>
|
||||
<url>http://repo.md-5.net/content/repositories/snapshots/</url>
|
||||
<id>velocity-repo</id>
|
||||
<url>https://repo.velocitypowered.com/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>md_5-snapshots</id>
|
||||
<url>http://repo.md-5.net/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>bstats-repo</id>
|
||||
<url>http://repo.bstats.org/content/repositories/releases/</url>
|
||||
|
@ -293,71 +312,109 @@
|
|||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
<artifactId>spongeapi</artifactId>
|
||||
<version>7.0.0</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>error_prone_annotations</artifactId>
|
||||
<groupId>com.google.errorprone</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>guice</artifactId>
|
||||
<groupId>com.google.inject</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>guava</artifactId>
|
||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>plugin-meta</artifactId>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>configurate-hocon</artifactId>
|
||||
<groupId>ninja.leaping.configurate</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>configurate-gson</artifactId>
|
||||
<groupId>ninja.leaping.configurate</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>configurate-yaml</artifactId>
|
||||
<groupId>ninja.leaping.configurate</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>flow-math</artifactId>
|
||||
<groupId>com.flowpowered</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>flow-noise</artifactId>
|
||||
<groupId>com.flowpowered</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>jsr305</artifactId>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>asm</artifactId>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>gson</artifactId>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>guava</artifactId>
|
||||
<groupId>com.google.guava</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<groupId>com.velocitypowered</groupId>
|
||||
<artifactId>velocity-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>text</artifactId>
|
||||
<groupId>net.kyori</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>toml4j</artifactId>
|
||||
<groupId>com.moandjiezana.toml</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>guice</artifactId>
|
||||
<groupId>com.google.inject</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>checker-qual</artifactId>
|
||||
<groupId>org.checkerframework</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>gson</artifactId>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>guava</artifactId>
|
||||
<groupId>com.google.guava</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
<artifactId>spongeapi</artifactId>
|
||||
<version>7.1.0</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>error_prone_annotations</artifactId>
|
||||
<groupId>com.google.errorprone</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>guava</artifactId>
|
||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>plugin-meta</artifactId>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>configurate-hocon</artifactId>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>configurate-gson</artifactId>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>configurate-yaml</artifactId>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>flow-math</artifactId>
|
||||
<groupId>com.flowpowered</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>flow-noise</artifactId>
|
||||
<groupId>com.flowpowered</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>jsr305</artifactId>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>guice</artifactId>
|
||||
<groupId>com.google.inject</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>asm</artifactId>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>gson</artifactId>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>guava</artifactId>
|
||||
<groupId>com.google.guava</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.imaginarycode.minecraft</groupId>
|
||||
<artifactId>RedisBungee</artifactId>
|
||||
<version>0.3.8-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-nop</artifactId>
|
||||
<version>1.7.25</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
|
|
60
Plan/pom.xml
60
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>
|
||||
|
@ -24,6 +24,10 @@
|
|||
<id>sponge-repo</id>
|
||||
<url>https://repo.spongepowered.org/maven</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>velocity-repo</id>
|
||||
<url>https://repo.velocitypowered.com/snapshots/</url>
|
||||
</repository>
|
||||
<!-- RedisBungee Repository -->
|
||||
<repository>
|
||||
<id>md_5-snapshots</id>
|
||||
|
@ -41,13 +45,13 @@
|
|||
<dependency>
|
||||
<groupId>com.djrapitops</groupId>
|
||||
<artifactId>AbstractPluginFramework</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<version>3.3.1</version>
|
||||
</dependency>
|
||||
<!-- SoftDepended Plugins -->
|
||||
<dependency>
|
||||
<groupId>com.djrapitops</groupId>
|
||||
<artifactId>PlanPluginBridge</artifactId>
|
||||
<version>4.3.0-SNAPSHOT</version>
|
||||
<version>4.5.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Paper API -->
|
||||
|
@ -79,11 +83,19 @@
|
|||
<type>jar</type>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Velocity -->
|
||||
<dependency>
|
||||
<groupId>com.velocitypowered</groupId>
|
||||
<artifactId>velocity-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- SpongePowered -->
|
||||
<dependency>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
<artifactId>spongeapi</artifactId>
|
||||
<version>7.0.0</version>
|
||||
<version>7.1.0</version>
|
||||
<type>jar</type>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
@ -114,6 +126,12 @@
|
|||
<artifactId>HikariCP</artifactId>
|
||||
<version>3.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-nop</artifactId>
|
||||
<version>1.7.25</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Geo IP -->
|
||||
<dependency>
|
||||
|
@ -180,6 +198,12 @@
|
|||
<version>1.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.dagger</groupId>
|
||||
<artifactId>dagger</artifactId>
|
||||
<version>2.17</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -199,6 +223,7 @@
|
|||
<include>**/*.js</include>
|
||||
<include>**/*.css</include>
|
||||
<include>locale/*.txt</include>
|
||||
<include>**/*.ico</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
|
@ -209,6 +234,23 @@
|
|||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>com.google.dagger</groupId>
|
||||
<artifactId>dagger-compiler</artifactId>
|
||||
<version>2.17</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>com.velocitypowered</groupId>
|
||||
<artifactId>velocity-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
<artifactId>spongeapi</artifactId>
|
||||
<version>7.1.0</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
@ -237,7 +279,7 @@
|
|||
<exclude>org.mockito:*</exclude>
|
||||
<exclude>org.easymock:*</exclude>
|
||||
<exclude>junit:*</exclude>
|
||||
<!--<exclued>org.slf4j:*</exclued>-->
|
||||
<exclued>org.slf4j:*</exclued>
|
||||
</excludes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
|
@ -260,10 +302,10 @@
|
|||
<pattern>com.zaxxer</pattern>
|
||||
<shadedPattern>plan.com.zaxxer</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.slf4j</pattern>
|
||||
<shadedPattern>plan.org.slf4j</shadedPattern>
|
||||
</relocation>
|
||||
<!--<relocation>-->
|
||||
<!--<pattern>org.slf4j</pattern>-->
|
||||
<!--<shadedPattern>plan.org.slf4j</shadedPattern>-->
|
||||
<!--</relocation>-->
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>com.djrapitops.plan.utilities.metrics</shadedPattern>
|
||||
|
|
|
@ -21,19 +21,14 @@ 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.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 org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
@ -47,55 +42,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();
|
||||
PlanBukkitComponent component = DaggerPlanBukkitComponent.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 +88,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 +147,7 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BukkitSystem getSystem() {
|
||||
public PlanSystem getSystem() {
|
||||
return system;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plan.command.PlanCommand;
|
||||
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.plugin.BukkitPlanModule;
|
||||
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.pluginbridge.plan.PluginBridgeModule;
|
||||
import dagger.BindsInstance;
|
||||
import dagger.Component;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Dagger Component that constructs the plugin systems running on Bukkit.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
@Component(modules = {
|
||||
BukkitPlanModule.class,
|
||||
SuperClassBindingModule.class,
|
||||
SystemObjectBindingModule.class,
|
||||
APFModule.class,
|
||||
FilesModule.class,
|
||||
BukkitServerPropertiesModule.class,
|
||||
ServerSuperClassBindingModule.class,
|
||||
BukkitSuperClassBindingModule.class,
|
||||
PluginBridgeModule.Bukkit.class
|
||||
})
|
||||
public interface PlanBukkitComponent {
|
||||
|
||||
PlanCommand planCommand();
|
||||
|
||||
PlanSystem system();
|
||||
|
||||
@Component.Builder
|
||||
interface Builder {
|
||||
|
||||
@BindsInstance
|
||||
Builder plan(Plan plan);
|
||||
|
||||
PlanBukkitComponent build();
|
||||
}
|
||||
}
|
|
@ -6,21 +6,16 @@ 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.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.logging.L;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Bungee Main class.
|
||||
|
@ -29,48 +24,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().getDatabase(),
|
||||
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 +85,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;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plan.command.PlanBungeeCommand;
|
||||
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.plugin.BungeePlanModule;
|
||||
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.pluginbridge.plan.PluginBridgeModule;
|
||||
import dagger.BindsInstance;
|
||||
import dagger.Component;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Dagger Component that constructs the plugin systems running on Bungee.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
@Component(modules = {
|
||||
BungeePlanModule.class,
|
||||
SuperClassBindingModule.class,
|
||||
SystemObjectBindingModule.class,
|
||||
APFModule.class,
|
||||
FilesModule.class,
|
||||
ProxySuperClassBindingModule.class,
|
||||
BungeeSuperClassBindingModule.class,
|
||||
BungeeServerPropertiesModule.class,
|
||||
PluginBridgeModule.Bungee.class
|
||||
})
|
||||
public interface PlanBungeeComponent {
|
||||
|
||||
PlanBungeeCommand planCommand();
|
||||
|
||||
PlanSystem system();
|
||||
|
||||
@Component.Builder
|
||||
interface Builder {
|
||||
|
||||
@BindsInstance
|
||||
Builder plan(PlanBungee plan);
|
||||
|
||||
PlanBungeeComponent build();
|
||||
}
|
||||
}
|
|
@ -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,20 +2,18 @@ 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.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.logging.L;
|
||||
import org.bstats.sponge.Metrics;
|
||||
import org.slf4j.Logger;
|
||||
import org.spongepowered.api.Game;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.config.ConfigDir;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
|
||||
|
@ -29,7 +27,7 @@ import java.io.InputStream;
|
|||
@Plugin(
|
||||
id = "plan",
|
||||
name = "Plan",
|
||||
version = "4.4.7",
|
||||
version = "4.5.0",
|
||||
description = "Player Analytics Plugin by Rsl1122",
|
||||
authors = {"Rsl1122"},
|
||||
dependencies = {
|
||||
|
@ -39,16 +37,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 +59,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().getDatabase()
|
||||
).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 +98,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 +108,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 +123,7 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
|
|||
|
||||
@Override
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
return slf4jLogger;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -140,7 +137,11 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SpongeSystem getSystem() {
|
||||
public PlanSystem getSystem() {
|
||||
return system;
|
||||
}
|
||||
|
||||
public Game getGame() {
|
||||
return Sponge.getGame();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plan.command.PlanCommand;
|
||||
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.plugin.SpongePlanModule;
|
||||
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.pluginbridge.plan.PluginBridgeModule;
|
||||
import dagger.BindsInstance;
|
||||
import dagger.Component;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Dagger Component that constructs the plugin systems running on Sponge.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
@Component(modules = {
|
||||
SpongePlanModule.class,
|
||||
SuperClassBindingModule.class,
|
||||
SystemObjectBindingModule.class,
|
||||
APFModule.class,
|
||||
FilesModule.class,
|
||||
ServerSuperClassBindingModule.class,
|
||||
SpongeSuperClassBindingModule.class,
|
||||
SpongeServerPropertiesModule.class,
|
||||
PluginBridgeModule.Sponge.class
|
||||
})
|
||||
public interface PlanSpongeComponent {
|
||||
|
||||
PlanCommand planCommand();
|
||||
|
||||
PlanSystem system();
|
||||
|
||||
@Component.Builder
|
||||
interface Builder {
|
||||
|
||||
@BindsInstance
|
||||
Builder plan(PlanSponge plan);
|
||||
|
||||
PlanSpongeComponent build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.command.PlanVelocityCommand;
|
||||
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.VelocityPlugin;
|
||||
import com.djrapitops.plugin.command.ColorScheme;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* Velocity Main class.
|
||||
* <p>
|
||||
* Based on the PlanBungee class
|
||||
*
|
||||
* @author MicleBrick
|
||||
*/
|
||||
@Plugin(
|
||||
id = "plan",
|
||||
name = "Plan",
|
||||
version = "4.5.0",
|
||||
description = "Player Analytics Plugin by Rsl1122",
|
||||
authors = {"Rsl1122"}
|
||||
)
|
||||
public class PlanVelocity extends VelocityPlugin implements PlanPlugin {
|
||||
|
||||
private PlanSystem system;
|
||||
private Locale locale;
|
||||
|
||||
@com.google.inject.Inject
|
||||
public PlanVelocity(ProxyServer proxy, Logger slf4jLogger, @DataDirectory Path dataFolderPath) {
|
||||
super(proxy, slf4jLogger, dataFolderPath);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProxyStart(ProxyInitializeEvent event) {
|
||||
onEnable();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProxyShutdown(ProxyShutdownEvent event) {
|
||||
onDisable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
PlanVelocityComponent component = DaggerPlanVelocityComponent.builder().plan(this).build();
|
||||
try {
|
||||
system = component.system();
|
||||
locale = system.getLocaleSystem().getLocale();
|
||||
system.enable();
|
||||
|
||||
logger.info(locale.getString(PluginLang.ENABLED));
|
||||
} catch (AbstractMethodError e) {
|
||||
logger.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart.");
|
||||
} catch (EnableException e) {
|
||||
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 /planvelocity reload");
|
||||
onDisable();
|
||||
} catch (Exception e) {
|
||||
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 /planvelocity reload");
|
||||
logger.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
|
||||
onDisable();
|
||||
}
|
||||
PlanVelocityCommand command = component.planCommand();
|
||||
command.registerCommands();
|
||||
registerCommand("planvelocity", command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
system.disable();
|
||||
|
||||
logger.info(locale.getString(PluginLang.DISABLED));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReload() {
|
||||
// Nothing to be done, systems are disabled
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResource(String resource) {
|
||||
return getClass().getResourceAsStream("/" + resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColorScheme getColorScheme() {
|
||||
return PlanColorScheme.create(system.getConfigSystem().getConfig(), logger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlanSystem getSystem() {
|
||||
return system;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReloading() {
|
||||
return reloading;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plan.command.PlanVelocityCommand;
|
||||
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.plugin.VelocityPlanModule;
|
||||
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.pluginbridge.plan.PluginBridgeModule;
|
||||
import dagger.BindsInstance;
|
||||
import dagger.Component;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Dagger Component that constructs the plugin systems running on Velocity.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
@Component(modules = {
|
||||
VelocityPlanModule.class,
|
||||
SuperClassBindingModule.class,
|
||||
SystemObjectBindingModule.class,
|
||||
APFModule.class,
|
||||
FilesModule.class,
|
||||
ProxySuperClassBindingModule.class,
|
||||
VelocitySuperClassBindingModule.class,
|
||||
VelocityServerPropertiesModule.class,
|
||||
PluginBridgeModule.Velocity.class
|
||||
})
|
||||
public interface PlanVelocityComponent {
|
||||
|
||||
PlanVelocityCommand planCommand();
|
||||
|
||||
PlanSystem system();
|
||||
|
||||
@Component.Builder
|
||||
interface Builder {
|
||||
|
||||
@BindsInstance
|
||||
Builder plan(PlanVelocity plan);
|
||||
|
||||
PlanVelocityComponent build();
|
||||
}
|
||||
}
|
|
@ -10,9 +10,12 @@ import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
|||
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.DBSystem;
|
||||
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 +29,57 @@ import java.util.UUID;
|
|||
*/
|
||||
public class ShutdownHook extends Thread {
|
||||
|
||||
private static boolean activated = false;
|
||||
private static ShutdownHook activated;
|
||||
private final DBSystem dbSystem;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
@Inject
|
||||
public ShutdownHook(DBSystem dbSystem, ErrorHandler errorHandler) {
|
||||
this.dbSystem = dbSystem;
|
||||
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 {
|
||||
dbSystem.getDatabase().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 +87,14 @@ public class ShutdownHook extends Thread {
|
|||
if (!end.isPresent()) {
|
||||
session.endSession(now);
|
||||
}
|
||||
if (!db.isOpen()) {
|
||||
db.init();
|
||||
Database database = dbSystem.getDatabase();
|
||||
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);
|
||||
|
|
|
@ -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.DBSystem;
|
||||
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 DBSystem dbSystem;
|
||||
|
||||
@Inject
|
||||
public ProxyAPI(
|
||||
UUIDUtility uuidUtility,
|
||||
DBSystem dbSystem,
|
||||
HookHandler hookHandler,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super(uuidUtility, errorHandler);
|
||||
|
||||
this.dbSystem = dbSystem;
|
||||
this.hookHandler = hookHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPluginDataSource(PluginData pluginData) {
|
||||
hookHandler.addPluginDataSource(pluginData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerName(UUID uuid) {
|
||||
return dbSystem.getDatabase().fetch().getPlayerName(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchOperations fetchFromPlanDB() {
|
||||
return dbSystem.getDatabase().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.DBSystem;
|
||||
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 DBSystem dbSystem;
|
||||
|
||||
public ServerAPI(ServerSystem serverSystem) {
|
||||
this.serverSystem = serverSystem;
|
||||
@Inject
|
||||
public ServerAPI(
|
||||
UUIDUtility uuidUtility,
|
||||
HookHandler hookHandler,
|
||||
DBSystem dbSystem,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super(uuidUtility, errorHandler);
|
||||
this.hookHandler = hookHandler;
|
||||
this.dbSystem = dbSystem;
|
||||
}
|
||||
|
||||
@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 dbSystem.getDatabase().fetch().getPlayerName(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchOperations fetchFromPlanDB() {
|
||||
return serverSystem.getDatabaseSystem().getActiveDatabase().fetch();
|
||||
return dbSystem.getDatabase().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,86 @@ 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;
|
||||
|
||||
getHelpCommand().setPermission(Permissions.MANAGE.getPermission());
|
||||
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,19 @@
|
|||
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 +23,98 @@ 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;
|
||||
|
||||
getHelpCommand().setPermission(Permissions.HELP.getPermission());
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
package com.djrapitops.plan.command;
|
||||
|
||||
import com.djrapitops.plan.command.commands.*;
|
||||
import com.djrapitops.plan.command.commands.manage.ManageConDebugCommand;
|
||||
import com.djrapitops.plan.command.commands.manage.ManageRawDataCommand;
|
||||
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 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.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Singleton
|
||||
public class PlanVelocityCommand extends TreeCmdNode {
|
||||
|
||||
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);
|
||||
this.uninstalledCommand = uninstalledCommand;
|
||||
|
||||
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;
|
||||
|
||||
getHelpCommand().setPermission(Permissions.MANAGE.getPermission());
|
||||
setColorScheme(colorScheme);
|
||||
setInDepthHelp(locale.getArray(DeepHelpLang.PLAN));
|
||||
}
|
||||
|
||||
public void registerCommands() {
|
||||
if (commandsRegistered) {
|
||||
return;
|
||||
}
|
||||
|
||||
CommandNode[] analyticsGroup = {
|
||||
networkCommand,
|
||||
listServersCommand,
|
||||
listPlayersCommand
|
||||
};
|
||||
CommandNode[] webGroup = {
|
||||
registerCommand,
|
||||
webUserCommand.get()
|
||||
};
|
||||
CommandNode[] manageGroup = {
|
||||
conDebugCommand,
|
||||
rawDataCommand,
|
||||
setupToggleCommand,
|
||||
uninstalledCommand,
|
||||
reloadCommand,
|
||||
disableCommand
|
||||
};
|
||||
setNodeGroups(analyticsGroup, webGroup, manageGroup);
|
||||
commandsRegistered = true;
|
||||
}
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
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;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.info.InfoSystem;
|
||||
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
|
@ -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 DBSystem dbSystem;
|
||||
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,
|
||||
DBSystem dbSystem,
|
||||
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.dbSystem = dbSystem;
|
||||
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) &&
|
||||
!dbSystem.getDatabase().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 = dbSystem.getDatabase().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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||
|
@ -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 DBSystem dbSystem;
|
||||
private final ConnectionSystem connectionSystem;
|
||||
private final VersionCheckSystem versionCheckSystem;
|
||||
|
||||
public InfoCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public InfoCommand(
|
||||
PlanPlugin plugin,
|
||||
Locale locale,
|
||||
DBSystem dbSystem,
|
||||
ConnectionSystem connectionSystem,
|
||||
VersionCheckSystem versionCheckSystem
|
||||
) {
|
||||
super("info", Permissions.INFO.getPermission(), CommandType.CONSOLE);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.plugin = plugin;
|
||||
this.locale = locale;
|
||||
this.dbSystem = dbSystem;
|
||||
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, dbSystem.getDatabase().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.database.DBSystem;
|
||||
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 DBSystem dbSystem;
|
||||
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,
|
||||
DBSystem dbSystem,
|
||||
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.dbSystem = dbSystem;
|
||||
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 (!dbSystem.getDatabase().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 = dbSystem.getDatabase().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,20 +1,22 @@
|
|||
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.database.DBSystem;
|
||||
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.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,53 @@ import java.util.List;
|
|||
*/
|
||||
public class ListServersCommand extends CommandNode {
|
||||
|
||||
private final PlanPlugin plugin;
|
||||
private final Locale locale;
|
||||
private final ColorScheme colorScheme;
|
||||
private final DBSystem dbSystem;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public ListServersCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public ListServersCommand(
|
||||
Locale locale,
|
||||
ColorScheme colorScheme,
|
||||
DBSystem dbSystem,
|
||||
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.dbSystem = dbSystem;
|
||||
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 = dbSystem.getDatabase().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,25 +7,29 @@ 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.database.DBSystem;
|
||||
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.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 DBSystem dbSystem;
|
||||
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,
|
||||
DBSystem dbSystem,
|
||||
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.dbSystem = dbSystem;
|
||||
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 = dbSystem.getDatabase().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,27 @@
|
|||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.data.WebUser;
|
||||
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.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 +35,32 @@ 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 DBSystem dbSystem;
|
||||
private final PluginLogger logger;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public RegisterCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public RegisterCommand(
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
DBSystem dbSystem,
|
||||
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.dbSystem = dbSystem;
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
setArguments("<password>", "[name]", "[lvl]");
|
||||
setShortHelp(locale.getString(CmdHelpLang.WEB_REGISTER));
|
||||
|
@ -52,11 +70,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 +81,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 +99,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 +113,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 +129,23 @@ 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 {
|
||||
Database database = dbSystem.getDatabase();
|
||||
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.DBSystem;
|
||||
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 DBSystem dbSystem;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public SearchCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public SearchCommand(
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
DBSystem dbSystem,
|
||||
ErrorHandler errorHandler) {
|
||||
super("search", Permissions.SEARCH.getPermission(), CommandType.PLAYER_OR_ARGS);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
this.processing = processing;
|
||||
this.dbSystem = dbSystem;
|
||||
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 = dbSystem.getDatabase().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.database.DBSystem;
|
||||
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 DBSystem dbSystem;
|
||||
|
||||
public ManageConDebugCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public ManageConDebugCommand(
|
||||
ColorScheme colorScheme,
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
ServerInfo serverInfo,
|
||||
ConnectionSystem connectionSystem,
|
||||
InfoRequestFactory infoRequestFactory,
|
||||
WebServer webServer,
|
||||
DBSystem dbSystem
|
||||
) {
|
||||
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.dbSystem = dbSystem;
|
||||
|
||||
setShortHelp(locale.getString(Check.isBungeeAvailable() ? CmdHelpLang.CON : CmdHelpLang.MANAGE_CON));
|
||||
setShortHelp(locale.getString(Check.isBungeeAvailable() || Check.isVelocityAvailable() ? 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 = dbSystem.getDatabase().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.getDatabase().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.getDatabase().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,41 +1,59 @@
|
|||
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.DBSystem;
|
||||
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.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;
|
||||
|
||||
/**
|
||||
* This manage subcommand is used to remove a single player's data from the
|
||||
* database.
|
||||
* dbSystem.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class ManageRemoveCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final Processing processing;
|
||||
private final DBSystem dbSystem;
|
||||
private final UUIDUtility uuidUtility;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public ManageRemoveCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public ManageRemoveCommand(
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
DBSystem dbSystem,
|
||||
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.dbSystem = dbSystem;
|
||||
this.uuidUtility = uuidUtility;
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
setArguments("<player>", "[-a]");
|
||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE_REMOVE));
|
||||
|
@ -43,7 +61,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 +75,40 @@ 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;
|
||||
}
|
||||
|
||||
Database db = dbSystem.getDatabase();
|
||||
if (!db.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, db.getName())
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
|
||||
|
||||
db.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,8 +1,7 @@
|
|||
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.database.DBSystem;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
|
@ -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 DBSystem dbSystem;
|
||||
private final ErrorHandler errorHandler;
|
||||
private final ServerInfo serverInfo;
|
||||
|
||||
public ManageUninstalledCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public ManageUninstalledCommand(
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
DBSystem dbSystem,
|
||||
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.dbSystem = dbSystem;
|
||||
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);
|
||||
dbSystem.getDatabase().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 = dbSystem.getDatabase().fetch().getBukkitServers();
|
||||
String serverIdentifier = getGivenIdentifier(args);
|
||||
for (Map.Entry<UUID, Server> entry : bukkitServers.entrySet()) {
|
||||
Server server = entry.getValue();
|
||||
|
|
|
@ -1,21 +1,23 @@
|
|||
package com.djrapitops.plan.command.commands.webuser;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.data.WebUser;
|
||||
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.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 +26,53 @@ 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 DBSystem dbSystem;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public WebCheckCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public WebCheckCommand(
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
DBSystem dbSystem,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super("check", Permissions.MANAGE_WEB.getPerm(), CommandType.PLAYER_OR_ARGS);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
this.processing = processing;
|
||||
this.dbSystem = dbSystem;
|
||||
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 {
|
||||
Database db = dbSystem.getDatabase();
|
||||
if (!db.check().doesWebUserExists(user)) {
|
||||
sender.sendMessage(locale.getString(CommandLang.FAIL_WEB_USER_NOT_EXISTS));
|
||||
return;
|
||||
}
|
||||
WebUser info = db.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,22 @@
|
|||
package com.djrapitops.plan.command.commands.webuser;
|
||||
|
||||
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;
|
||||
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 +25,53 @@ 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 DBSystem dbSystem;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public WebDeleteCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public WebDeleteCommand(
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
DBSystem dbSystem,
|
||||
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.dbSystem = dbSystem;
|
||||
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 {
|
||||
Database db = dbSystem.getDatabase();
|
||||
if (!db.check().doesWebUserExists(user)) {
|
||||
sender.sendMessage("§c[Plan] User Doesn't exist.");
|
||||
return;
|
||||
}
|
||||
db.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.database.DBSystem;
|
||||
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 DBSystem dbSystem;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public WebListUsersCommand(PlanPlugin plugin) {
|
||||
@Inject
|
||||
public WebListUsersCommand(
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
DBSystem dbSystem,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super("list", Permissions.MANAGE_WEB.getPerm(), CommandType.CONSOLE);
|
||||
|
||||
locale = plugin.getSystem().getLocaleSystem().getLocale();
|
||||
this.locale = locale;
|
||||
this.processing = processing;
|
||||
this.dbSystem = dbSystem;
|
||||
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 = dbSystem.getDatabase().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 +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ public class TPS implements DateHolder {
|
|||
private final long usedMemory;
|
||||
private final int entityCount;
|
||||
private final int chunksLoaded;
|
||||
private final long freeDiskSpace;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
@ -32,11 +33,21 @@ public class TPS implements DateHolder {
|
|||
* @param ticksPerSecond average ticksPerSecond for the last minute.
|
||||
* @param players players for the minute.
|
||||
* @param cpuUsage CPU usage for the minute
|
||||
* @param usedMemory used memory at the time of fetching
|
||||
* @param usedMemory used memory (megabytes) at the time of fetching
|
||||
* @param entityCount amount of entities at the time of fetching
|
||||
* @param chunksLoaded amount of chunks loaded at the time of fetching
|
||||
* @param freeDiskSpace free megabytes in the partition the server is running in.
|
||||
*/
|
||||
public TPS(long date, double ticksPerSecond, int players, double cpuUsage, long usedMemory, int entityCount, int chunksLoaded) {
|
||||
public TPS(
|
||||
long date,
|
||||
double ticksPerSecond,
|
||||
int players,
|
||||
double cpuUsage,
|
||||
long usedMemory,
|
||||
int entityCount,
|
||||
int chunksLoaded,
|
||||
long freeDiskSpace
|
||||
) {
|
||||
this.date = date;
|
||||
this.ticksPerSecond = ticksPerSecond;
|
||||
this.players = players;
|
||||
|
@ -44,6 +55,7 @@ public class TPS implements DateHolder {
|
|||
this.usedMemory = usedMemory;
|
||||
this.entityCount = entityCount;
|
||||
this.chunksLoaded = chunksLoaded;
|
||||
this.freeDiskSpace = freeDiskSpace;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -105,6 +117,15 @@ public class TPS implements DateHolder {
|
|||
return chunksLoaded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get free megabytes of disk space on the server disk.
|
||||
*
|
||||
* @return Amount of megabytes in use.
|
||||
*/
|
||||
public long getFreeDiskSpace() {
|
||||
return freeDiskSpace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
@ -116,12 +137,13 @@ public class TPS implements DateHolder {
|
|||
Double.compare(tps.cpuUsage, cpuUsage) == 0 &&
|
||||
usedMemory == tps.usedMemory &&
|
||||
entityCount == tps.entityCount &&
|
||||
chunksLoaded == tps.chunksLoaded;
|
||||
chunksLoaded == tps.chunksLoaded &&
|
||||
freeDiskSpace == tps.freeDiskSpace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(date, ticksPerSecond, players, cpuUsage, usedMemory, entityCount, chunksLoaded);
|
||||
return Objects.hash(date, ticksPerSecond, players, cpuUsage, usedMemory, entityCount, chunksLoaded, freeDiskSpace);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -133,6 +155,7 @@ public class TPS implements DateHolder {
|
|||
"cpuUsage=" + cpuUsage + ", " +
|
||||
"usedMemory=" + usedMemory + ", " +
|
||||
"entityCount=" + entityCount + ", " +
|
||||
"chunksLoaded=" + chunksLoaded + '}';
|
||||
"chunksLoaded=" + chunksLoaded + ", " +
|
||||
"freeDiskSpace=" + freeDiskSpace + '}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ public class TPSBuilder {
|
|||
protected long usedMemory = -1;
|
||||
protected int entityCount = -1;
|
||||
protected int chunksLoaded = -1;
|
||||
protected long freeDiskSpace = -1;
|
||||
|
||||
/**
|
||||
* Hides constructor.
|
||||
|
@ -28,11 +29,11 @@ public class TPSBuilder {
|
|||
}
|
||||
|
||||
public static TPSBuilder.Date get() {
|
||||
return new TPSBuilder.Chunks();
|
||||
return new TPSBuilder.DiskSpace();
|
||||
}
|
||||
|
||||
public TPS toTPS() {
|
||||
return new TPS(date, ticksPerSecond, players, cpuUsage, usedMemory, entityCount, chunksLoaded);
|
||||
return new TPS(date, ticksPerSecond, players, cpuUsage, usedMemory, entityCount, chunksLoaded, freeDiskSpace);
|
||||
}
|
||||
|
||||
public static class Date extends TPSBuilder {
|
||||
|
@ -89,8 +90,15 @@ public class TPSBuilder {
|
|||
|
||||
public static class Chunks extends Entities {
|
||||
|
||||
public TPSBuilder chunksLoaded(int chunksLoaded) {
|
||||
public DiskSpace chunksLoaded(int chunksLoaded) {
|
||||
this.chunksLoaded = chunksLoaded;
|
||||
return (DiskSpace) this;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DiskSpace extends Chunks {
|
||||
public TPSBuilder freeDiskSpace(long freeDiskSpace) {
|
||||
this.freeDiskSpace = freeDiskSpace;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,14 @@
|
|||
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.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import com.djrapitops.pluginbridge.plan.Bridge;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -19,29 +19,38 @@ import java.util.stream.Collectors;
|
|||
* @author Rsl1122
|
||||
* @since 2.6.0
|
||||
*/
|
||||
@Singleton
|
||||
public class HookHandler implements SubSystem {
|
||||
|
||||
private final List<PluginData> additionalDataSources;
|
||||
|
||||
private final Bridge bridge;
|
||||
private PluginsConfigSection configHandler;
|
||||
private final PluginLogger logger;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
@Inject
|
||||
public HookHandler(
|
||||
Bridge bridge,
|
||||
PluginsConfigSection configHandler,
|
||||
PluginLogger logger,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
this.bridge = bridge;
|
||||
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 +74,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 +115,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,38 @@
|
|||
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.database.DBSystem;
|
||||
import com.djrapitops.plan.system.info.server.properties.ServerProperties;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
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 +46,46 @@ public class AnalysisContainer extends DataContainer {
|
|||
|
||||
private final ServerContainer serverContainer;
|
||||
|
||||
private final String version;
|
||||
private final Locale locale;
|
||||
private final PlanConfig config;
|
||||
private final Theme theme;
|
||||
private final DBSystem dbSystem;
|
||||
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,
|
||||
Locale locale,
|
||||
PlanConfig config,
|
||||
Theme theme,
|
||||
DBSystem dbSystem,
|
||||
ServerProperties serverProperties,
|
||||
Formatters formatters,
|
||||
Graphs graphs,
|
||||
HtmlTables tables,
|
||||
Accordions accordions,
|
||||
AnalysisPluginsTabContentCreator pluginsTabContentCreator
|
||||
) {
|
||||
this.serverContainer = serverContainer;
|
||||
this.version = version;
|
||||
this.locale = locale;
|
||||
this.config = config;
|
||||
this.theme = theme;
|
||||
this.dbSystem = dbSystem;
|
||||
this.serverProperties = serverProperties;
|
||||
this.formatters = formatters;
|
||||
this.graphs = graphs;
|
||||
this.tables = tables;
|
||||
this.accordions = accordions;
|
||||
this.pluginsTabContentCreator = pluginsTabContentCreator;
|
||||
addAnalysisSuppliers();
|
||||
}
|
||||
|
||||
|
@ -74,27 +106,24 @@ 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.clockLong().apply(getUnsafe(AnalysisKeys.ANALYSIS_TIME)));
|
||||
putSupplier(AnalysisKeys.REFRESH_TIME_FULL_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));
|
||||
putRawData(AnalysisKeys.DISK_MEDIUM, config.getNumber(Settings.THEME_GRAPH_DISK_THRESHOLD_MED));
|
||||
putRawData(AnalysisKeys.DISK_HIGH, config.getNumber(Settings.THEME_GRAPH_DISK_THRESHOLD_HIGH));
|
||||
|
||||
addServerProperties();
|
||||
addThemeColors();
|
||||
|
@ -105,24 +134,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 +170,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 +229,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 +267,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, () -> dbSystem.getDatabase().fetch().getServerNames());
|
||||
putCachingSupplier(sessionAccordion, () -> accordions.serverSessionAccordion(
|
||||
getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).all(),
|
||||
getSupplier(serverNames),
|
||||
() -> getUnsafe(AnalysisKeys.PLAYER_NAMES)
|
||||
|
@ -270,32 +300,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 +342,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 +351,49 @@ 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.DISK_SERIES, () -> graphs.line().diskGraph(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 +422,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 +445,21 @@ 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,
|
||||
locale,
|
||||
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 +467,70 @@ 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 Locale locale;
|
||||
private final Theme theme;
|
||||
private final DBSystem dbSystem;
|
||||
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,
|
||||
Locale locale,
|
||||
Theme theme,
|
||||
DBSystem dbSystem,
|
||||
ServerProperties serverProperties,
|
||||
Formatters formatters,
|
||||
Graphs graphs,
|
||||
HtmlTables tables,
|
||||
Accordions accordions,
|
||||
AnalysisPluginsTabContentCreator pluginsTabContentCreator
|
||||
) {
|
||||
this.version = version;
|
||||
this.config = config;
|
||||
this.locale = locale;
|
||||
this.theme = theme;
|
||||
this.dbSystem = dbSystem;
|
||||
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,
|
||||
locale,
|
||||
config,
|
||||
theme,
|
||||
dbSystem,
|
||||
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,36 @@
|
|||
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.database.DBSystem;
|
||||
import com.djrapitops.plan.system.info.server.properties.ServerProperties;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
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 +43,131 @@ 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 Locale locale;
|
||||
private final Theme theme;
|
||||
private final DBSystem dbSystem;
|
||||
private final ServerProperties serverProperties;
|
||||
private final Formatters formatters;
|
||||
private final Graphs graphs;
|
||||
|
||||
public NetworkContainer(ServerContainer bungeeContainer) {
|
||||
public NetworkContainer(
|
||||
ServerContainer bungeeContainer,
|
||||
String version,
|
||||
PlanConfig config,
|
||||
Locale locale,
|
||||
Theme theme,
|
||||
DBSystem dbSystem,
|
||||
ServerProperties serverProperties,
|
||||
Formatters formatters,
|
||||
Graphs graphs
|
||||
) {
|
||||
this.bungeeContainer = bungeeContainer;
|
||||
serverContainers = new HashMap<>();
|
||||
this.version = version;
|
||||
this.config = config;
|
||||
this.locale = locale;
|
||||
this.theme = theme;
|
||||
this.dbSystem = dbSystem;
|
||||
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, () -> dbSystem.getDatabase().fetch().getPlayersOnlineForServers(
|
||||
getValue(NetworkKeys.BUKKIT_SERVERS).orElse(new ArrayList<>()))
|
||||
);
|
||||
putSupplier(NetworkKeys.SERVER_REGISTER_DATA, () -> dbSystem.getDatabase().fetch().getPlayersRegisteredForServers(
|
||||
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<>());
|
||||
Map<Integer, Integer> registerData = getValue(NetworkKeys.SERVER_REGISTER_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 -> {
|
||||
int serverId = server.getId();
|
||||
TPSMutator tpsMutator = new TPSMutator(playersOnlineData.getOrDefault(serverId, new ArrayList<>()));
|
||||
int registered = registerData.getOrDefault(serverId, 0);
|
||||
NetworkServerBox serverBox = new NetworkServerBox(server, registered, 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,
|
||||
locale,
|
||||
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() :
|
||||
Check.isBungeeAvailable() || Check.isVelocityAvailable() ?
|
||||
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 +216,53 @@ 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<Locale> locale;
|
||||
private final Lazy<Theme> theme;
|
||||
private final Lazy<DBSystem> dbSystem;
|
||||
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<Locale> locale,
|
||||
Lazy<Theme> theme,
|
||||
Lazy<DBSystem> dbSystem,
|
||||
Lazy<ServerProperties> serverProperties,
|
||||
Lazy<Formatters> formatters,
|
||||
Lazy<Graphs> graphs
|
||||
) {
|
||||
this.version = version;
|
||||
this.config = config;
|
||||
this.locale = locale;
|
||||
this.theme = theme;
|
||||
this.dbSystem = dbSystem;
|
||||
this.serverProperties = serverProperties;
|
||||
this.formatters = formatters;
|
||||
this.graphs = graphs;
|
||||
}
|
||||
|
||||
public NetworkContainer forBungeeContainer(ServerContainer bungeeContainer) {
|
||||
return new NetworkContainer(
|
||||
bungeeContainer,
|
||||
version.get(),
|
||||
config.get(),
|
||||
locale.get(),
|
||||
theme.get(),
|
||||
dbSystem.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) {
|
||||
|
|
|
@ -30,6 +30,8 @@ public class AnalysisKeys {
|
|||
public static final PlaceholderKey<Integer> FIRST_DAY = new PlaceholderKey<>(Integer.class, "firstDay");
|
||||
public static final PlaceholderKey<Integer> TPS_MEDIUM = new PlaceholderKey<>(Integer.class, "tpsMedium");
|
||||
public static final PlaceholderKey<Integer> TPS_HIGH = new PlaceholderKey<>(Integer.class, "tpsHigh");
|
||||
public static final PlaceholderKey<Integer> DISK_MEDIUM = new PlaceholderKey<>(Integer.class, "diskMedium");
|
||||
public static final PlaceholderKey<Integer> DISK_HIGH = new PlaceholderKey<>(Integer.class, "diskHigh");
|
||||
public static final PlaceholderKey<Integer> PLAYERS_MAX = new PlaceholderKey<>(Integer.class, "playersMax");
|
||||
public static final PlaceholderKey<Integer> PLAYERS_ONLINE = CommonPlaceholderKeys.PLAYERS_ONLINE;
|
||||
public static final PlaceholderKey<Integer> PLAYERS_TOTAL = CommonPlaceholderKeys.PLAYERS_TOTAL;
|
||||
|
@ -60,6 +62,7 @@ public class AnalysisKeys {
|
|||
public static final PlaceholderKey<String> PLUGINS_TAB_NAV = new PlaceholderKey<>(String.class, "navPluginsTabs");
|
||||
// Formatted time values
|
||||
public static final PlaceholderKey<String> REFRESH_TIME_F = CommonPlaceholderKeys.REFRESH_TIME_F;
|
||||
public static final PlaceholderKey<String> REFRESH_TIME_FULL_F = CommonPlaceholderKeys.REFRESH_TIME_FULL_F;
|
||||
public static final PlaceholderKey<String> LAST_PEAK_TIME_F = CommonPlaceholderKeys.LAST_PEAK_TIME_F;
|
||||
public static final PlaceholderKey<String> ALL_TIME_PEAK_TIME_F = CommonPlaceholderKeys.ALL_TIME_PEAK_TIME_F;
|
||||
public static final PlaceholderKey<String> AVERAGE_SESSION_LENGTH_F = new PlaceholderKey<>(String.class, "sessionAverage");
|
||||
|
@ -126,6 +129,7 @@ public class AnalysisKeys {
|
|||
public static final PlaceholderKey<String> RAM_SERIES = new PlaceholderKey<>(String.class, "ramSeries");
|
||||
public static final PlaceholderKey<String> ENTITY_SERIES = new PlaceholderKey<>(String.class, "entitySeries");
|
||||
public static final PlaceholderKey<String> CHUNK_SERIES = new PlaceholderKey<>(String.class, "chunkSeries");
|
||||
public static final PlaceholderKey<String> DISK_SERIES = new PlaceholderKey<>(String.class, "diskSeries");
|
||||
public static final PlaceholderKey<String> PUNCHCARD_SERIES = new PlaceholderKey<>(String.class, "punchCardSeries");
|
||||
public static final PlaceholderKey<String> WORLD_MAP_SERIES = CommonPlaceholderKeys.WORLD_MAP_SERIES;
|
||||
public static final PlaceholderKey<String> ACTIVITY_STACK_SERIES = CommonPlaceholderKeys.ACTIVITY_STACK_SERIES;
|
||||
|
@ -151,6 +155,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");
|
||||
|
|
|
@ -22,8 +22,8 @@ class CommonPlaceholderKeys {
|
|||
static final PlaceholderKey<String> ACTIVITY_STACK_SERIES = new PlaceholderKey<>(String.class, "activityStackSeries");
|
||||
static final PlaceholderKey<String> ACTIVITY_STACK_CATEGORIES = new PlaceholderKey<>(String.class, "activityStackCategories");
|
||||
static final PlaceholderKey<String> ACTIVITY_PIE_SERIES = new PlaceholderKey<>(String.class, "activityPieSeries");
|
||||
public static final PlaceholderKey<String> COUNTRY_CATEGORIES = new PlaceholderKey<>(String.class, "countryCategories");
|
||||
public static final PlaceholderKey<String> COUNTRY_SERIES = new PlaceholderKey<>(String.class, "countrySeries");
|
||||
static final PlaceholderKey<String> COUNTRY_CATEGORIES = new PlaceholderKey<>(String.class, "countryCategories");
|
||||
static final PlaceholderKey<String> COUNTRY_SERIES = new PlaceholderKey<>(String.class, "countrySeries");
|
||||
|
||||
static final PlaceholderKey<String> HEALTH_NOTES = new PlaceholderKey<>(String.class, "healthNotes");
|
||||
static final PlaceholderKey<Double> HEALTH_INDEX = new PlaceholderKey<>(Double.class, "healthIndex");
|
||||
|
@ -36,6 +36,7 @@ class CommonPlaceholderKeys {
|
|||
static final PlaceholderKey<Integer> PLAYERS_NEW_MONTH = new PlaceholderKey<>(Integer.class, "playersNewMonth");
|
||||
|
||||
static final PlaceholderKey<String> REFRESH_TIME_F = new PlaceholderKey<>(String.class, "refresh");
|
||||
static final PlaceholderKey<String> REFRESH_TIME_FULL_F = new PlaceholderKey<>(String.class, "refreshFull");
|
||||
static final PlaceholderKey<String> LAST_PEAK_TIME_F = new PlaceholderKey<>(String.class, "lastPeakTime");
|
||||
static final PlaceholderKey<String> ALL_TIME_PEAK_TIME_F = new PlaceholderKey<>(String.class, "bestPeakTime");
|
||||
static final PlaceholderKey<String> PLAYERS_LAST_PEAK = new PlaceholderKey<>(String.class, "playersLastPeak");
|
||||
|
|
|
@ -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,8 @@ 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");
|
||||
public static final Key<Map<Integer, Integer>> SERVER_REGISTER_DATA = new Key<>(new Type<Map<Integer, Integer>>() {}, "SERVER_REGISTER_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;
|
||||
|
||||
|
@ -66,6 +65,7 @@ public class TPSMutator {
|
|||
public List<Point> cpuPoints() {
|
||||
return tpsData.stream()
|
||||
.map(tps -> new Point(tps.getDate(), tps.getCPUUsage()))
|
||||
.filter(point -> point.getY() != -1)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
@ -87,6 +87,13 @@ public class TPSMutator {
|
|||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<Point> freeDiskPoints() {
|
||||
return tpsData.stream()
|
||||
.map(tps -> new Point(tps.getDate(), tps.getFreeDiskSpace()))
|
||||
.filter(point -> point.getY() != -1)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public long serverDownTime() {
|
||||
long lastDate = -1;
|
||||
long downTime = 0;
|
||||
|
@ -99,7 +106,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 +141,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 +156,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,13 @@ 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.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.HealthInfoLang;
|
||||
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 +21,29 @@ public abstract class AbstractHealthInfo {
|
|||
|
||||
protected double serverHealth;
|
||||
|
||||
public AbstractHealthInfo(long now, long monthAgo) {
|
||||
protected final Locale locale;
|
||||
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,
|
||||
Locale locale, int activeMinuteThreshold,
|
||||
int activeLoginThreshold,
|
||||
Formatter<Long> timeAmountFormatter,
|
||||
Formatter<Double> decimalFormatter,
|
||||
Formatter<Double> percentageFormatter
|
||||
) {
|
||||
this.now = now;
|
||||
this.monthAgo = monthAgo;
|
||||
this.locale = locale;
|
||||
this.activeMinuteThreshold = activeMinuteThreshold;
|
||||
this.activeLoginThreshold = activeLoginThreshold;
|
||||
this.timeAmountFormatter = timeAmountFormatter;
|
||||
this.decimalFormatter = decimalFormatter;
|
||||
this.percentageFormatter = percentageFormatter;
|
||||
serverHealth = 100.0;
|
||||
|
||||
this.notes = new ArrayList<>();
|
||||
|
@ -63,43 +84,47 @@ 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 * 1.0 / activeFWAGNum : 1.0;
|
||||
|
||||
int newActive = getNewActive(veryActiveNow, activeNow, regularNow, veryActiveFWAG, activeFWAG, regularFWAG);
|
||||
|
||||
int change = newActive - notRegularAnymore;
|
||||
|
||||
String remainNote = "";
|
||||
StringBuilder remainNote = new StringBuilder();
|
||||
if (activeFWAGNum != 0) {
|
||||
remainNote = "<br> ";
|
||||
if (percRemain > 50) {
|
||||
remainNote += Icons.GREEN_THUMB;
|
||||
} else if (percRemain > 20) {
|
||||
remainNote += Icons.YELLOW_FLAG;
|
||||
remainNote.append(subNote);
|
||||
if (percRemain > 0.5) {
|
||||
remainNote.append(Icons.GREEN_THUMB);
|
||||
} else if (percRemain > 0.2) {
|
||||
remainNote.append(Icons.YELLOW_FLAG);
|
||||
} else {
|
||||
remainNote += Icons.RED_WARN;
|
||||
remainNote.append(Icons.RED_WARN);
|
||||
serverHealth -= 2.5;
|
||||
}
|
||||
|
||||
remainNote += " " + FormatUtils.cutDecimals(percRemain) + "% of regular players have remained active ("
|
||||
+ remain + "/" + activeFWAGNum + ")";
|
||||
remainNote.append(locale.getString(HealthInfoLang.REGULAR_ACTIVITY_REMAIN,
|
||||
percentageFormatter.apply(percRemain),
|
||||
remain, activeFWAGNum
|
||||
));
|
||||
}
|
||||
|
||||
String sentenceStart = locale.getString(HealthInfoLang.REGULAR_CHANGE);
|
||||
if (change > 0) {
|
||||
addNote(Icons.GREEN_THUMB + " Number of regular players has increased (+" + change + ")" + remainNote);
|
||||
addNote(Icons.GREEN_THUMB + sentenceStart + locale.getString(HealthInfoLang.REGULAR_CHANGE_INCREASE, change) + remainNote);
|
||||
} else if (change == 0) {
|
||||
addNote(Icons.GREEN_THUMB + " Number of regular players has stayed the same (+" + change + ")" + remainNote);
|
||||
addNote(Icons.GREEN_THUMB + sentenceStart + locale.getString(HealthInfoLang.REGULAR_CHANGE_ZERO, change) + remainNote);
|
||||
} else if (change > -20) {
|
||||
addNote(Icons.YELLOW_FLAG + " Number of regular players has decreased (" + change + ")" + remainNote);
|
||||
addNote(Icons.YELLOW_FLAG + sentenceStart + locale.getString(HealthInfoLang.REGULAR_CHANGE_DECREASE, change) + remainNote);
|
||||
serverHealth -= 5;
|
||||
} else {
|
||||
addNote(Icons.RED_WARN + " Number of regular players has decreased (" + change + ")" + remainNote);
|
||||
addNote(Icons.RED_WARN + sentenceStart + locale.getString(HealthInfoLang.REGULAR_CHANGE_DECREASE, change) + remainNote);
|
||||
serverHealth -= 10;
|
||||
}
|
||||
}
|
||||
|
||||
protected void activePlayerPlaytimeChange(PlayersMutator playersMutator) {
|
||||
PlayersMutator currentlyActive = playersMutator.filterActive(now, 1.75);
|
||||
long twoWeeksAgo = (now - (now - monthAgo)) / 2L;
|
||||
PlayersMutator currentlyActive = playersMutator.filterActive(now, activeMinuteThreshold, activeLoginThreshold, 1.75);
|
||||
long twoWeeksAgo = now - ((now - monthAgo) / 2L);
|
||||
|
||||
long totalFourToTwoWeeks = 0;
|
||||
long totalLastTwoWeeks = 0;
|
||||
|
@ -113,21 +138,18 @@ 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) {
|
||||
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)");
|
||||
addNote(Icons.GREEN_THUMB + locale.getString(HealthInfoLang.ACTIVE_PLAY_COMPARISON_INCREASE,
|
||||
avgLastTwoWeeksString, avgFourToTwoWeeksString));
|
||||
} else if (avgFourToTwoWeeks - avgLastTwoWeeks > TimeUnit.HOURS.toMillis(2L)) {
|
||||
addNote(Icons.RED_WARN + locale.getString(HealthInfoLang.ACTIVE_PLAY_COMPARISON_DECREASE,
|
||||
avgLastTwoWeeksString, avgFourToTwoWeeksString));
|
||||
serverHealth -= 5;
|
||||
} else {
|
||||
addNote(Icons.YELLOW_FLAG + " Active players might be running out of things to do (Played "
|
||||
+ avgLastTwoWeeksString + " vs " + avgFourToTwoWeeksString
|
||||
+ ", last two weeks vs weeks 2-4)");
|
||||
addNote(Icons.YELLOW_FLAG + locale.getString(HealthInfoLang.ACTIVE_PLAY_COMPARISON_DECREASE,
|
||||
avgLastTwoWeeksString, avgFourToTwoWeeksString));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,15 +10,15 @@ 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.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.HealthInfoLang;
|
||||
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 +29,27 @@ public class HealthInformation extends AbstractHealthInfo {
|
|||
|
||||
private final AnalysisContainer analysisContainer;
|
||||
|
||||
public HealthInformation(AnalysisContainer analysisContainer) {
|
||||
private final int lowTPSThreshold;
|
||||
|
||||
public HealthInformation(
|
||||
AnalysisContainer analysisContainer,
|
||||
Locale locale,
|
||||
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),
|
||||
locale,
|
||||
activeMinuteThreshold, activeLoginThreshold,
|
||||
timeAmountFormatter, decimalFormatter, percentageFormatter
|
||||
);
|
||||
this.analysisContainer = analysisContainer;
|
||||
this.lowTPSThreshold = lowTPSThreshold;
|
||||
calculate();
|
||||
}
|
||||
|
||||
|
@ -66,11 +81,11 @@ public class HealthInformation extends AbstractHealthInfo {
|
|||
.mapToInt(Optional::get)
|
||||
.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)");
|
||||
addNote(Icons.GREEN_THUMB + locale.getString(HealthInfoLang.NEW_PLAYER_JOIN_PLAYERS_GOOD,
|
||||
decimalFormatter.apply(avgOnlineOnRegister)));
|
||||
} else {
|
||||
addNote(Icons.YELLOW_FLAG + " New Players may not have players to play with when they join ("
|
||||
+ FormatUtils.cutDecimals(avgOnlineOnRegister) + " on average)");
|
||||
addNote(Icons.YELLOW_FLAG + locale.getString(HealthInfoLang.NEW_PLAYER_JOIN_PLAYERS_BAD,
|
||||
decimalFormatter.apply(avgOnlineOnRegister)));
|
||||
serverHealth -= 5;
|
||||
}
|
||||
|
||||
|
@ -79,12 +94,12 @@ public class HealthInformation extends AbstractHealthInfo {
|
|||
|
||||
if (playersNewMonth != 0) {
|
||||
double retainPercentage = playersRetainedMonth * 1.0 / playersNewMonth;
|
||||
String stickinessSentence = locale.getString(HealthInfoLang.NEW_PLAYER_STICKINESS,
|
||||
percentageFormatter.apply(retainPercentage), playersRetainedMonth, playersNewMonth);
|
||||
if (retainPercentage >= 0.25) {
|
||||
addNote(Icons.GREEN_THUMB + " " + Formatters.percentage().apply(retainPercentage)
|
||||
+ " of new players have stuck around (" + playersRetainedMonth + "/" + playersNewMonth + ")");
|
||||
addNote(Icons.GREEN_THUMB + stickinessSentence);
|
||||
} else {
|
||||
addNote(Icons.YELLOW_FLAG + " " + Formatters.percentage().apply(retainPercentage)
|
||||
+ " of new players have stuck around (" + playersRetainedMonth + "/" + playersNewMonth + ")");
|
||||
addNote(Icons.YELLOW_FLAG + stickinessSentence);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -93,48 +108,46 @@ 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> ";
|
||||
StringBuilder avgLowThresholdString = new StringBuilder(subNote);
|
||||
if (aboveThreshold >= 0.96) {
|
||||
avgLowThresholdString += Icons.GREEN_THUMB;
|
||||
avgLowThresholdString.append(Icons.GREEN_THUMB);
|
||||
} else if (aboveThreshold >= 0.9) {
|
||||
avgLowThresholdString += Icons.YELLOW_FLAG;
|
||||
avgLowThresholdString.append(Icons.YELLOW_FLAG);
|
||||
serverHealth *= 0.9;
|
||||
} else {
|
||||
avgLowThresholdString += Icons.RED_WARN;
|
||||
avgLowThresholdString.append(Icons.RED_WARN);
|
||||
serverHealth *= 0.6;
|
||||
}
|
||||
avgLowThresholdString += " Average TPS was above Low Threshold "
|
||||
+ FormatUtils.cutDecimals(aboveThreshold * 100.0) + "% of the time";
|
||||
avgLowThresholdString.append(locale.getString(HealthInfoLang.TPS_ABOVE_LOW_THERSHOLD, percentageFormatter.apply(aboveThreshold)));
|
||||
|
||||
int threshold = Settings.THEME_GRAPH_TPS_THRESHOLD_MED.getNumber();
|
||||
String tpsDipSentence = locale.getString(HealthInfoLang.TPS_LOW_DIPS, lowTPSThreshold, tpsSpikeMonth);
|
||||
if (tpsSpikeMonth <= 5) {
|
||||
addNote(Icons.GREEN_THUMB + " Average TPS dropped below Low Threshold (" + threshold + ")" +
|
||||
" " + tpsSpikeMonth + " times" +
|
||||
avgLowThresholdString);
|
||||
addNote(Icons.GREEN_THUMB + tpsDipSentence + avgLowThresholdString);
|
||||
} else if (tpsSpikeMonth <= 25) {
|
||||
addNote(Icons.YELLOW_FLAG + " Average TPS dropped below Low Threshold (" + threshold + ")" +
|
||||
" " + tpsSpikeMonth + " times" +
|
||||
avgLowThresholdString);
|
||||
addNote(Icons.YELLOW_FLAG + tpsDipSentence + avgLowThresholdString);
|
||||
serverHealth *= 0.95;
|
||||
} else {
|
||||
addNote(Icons.RED_WARN + " Average TPS dropped below Low Threshold (" + threshold + ")" +
|
||||
" " + tpsSpikeMonth + " times" +
|
||||
avgLowThresholdString);
|
||||
addNote(Icons.RED_WARN + tpsDipSentence + 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();
|
||||
String downtimeSentence = locale.getString(HealthInfoLang.DOWNTIME, timeAmountFormatter.apply(serverDownTime));
|
||||
if (serverDownTime <= TimeUnit.DAYS.toMillis(1L)) {
|
||||
addNote(Icons.GREEN_THUMB + downtimeSentence);
|
||||
} 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 + downtimeSentence);
|
||||
serverHealth *= (weekMs - serverDownTime) * 1.0 / weekMs;
|
||||
} else {
|
||||
addNote(Icons.RED_WARN + downtimeSentence);
|
||||
long monthMs = TimeAmount.MONTH.toMillis(1L);
|
||||
serverHealth *= (monthMs - serverDownTime) * 1.0 / monthMs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,9 @@ 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.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.HealthInfoLang;
|
||||
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 +20,21 @@ public class NetworkHealthInformation extends AbstractHealthInfo {
|
|||
|
||||
private final NetworkContainer container;
|
||||
|
||||
public NetworkHealthInformation(NetworkContainer container) {
|
||||
public NetworkHealthInformation(
|
||||
NetworkContainer container,
|
||||
Locale locale,
|
||||
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),
|
||||
locale,
|
||||
activeMinuteThreshold, activeLoginThreshold,
|
||||
timeAmountFormatter, decimalFormatter, percentageFormatter
|
||||
);
|
||||
this.container = container;
|
||||
calculate();
|
||||
|
@ -40,12 +53,12 @@ public class NetworkHealthInformation extends AbstractHealthInfo {
|
|||
.orElse(Collections.emptyList());
|
||||
|
||||
if (servers.isEmpty()) {
|
||||
addNote(Icons.HELP_RING + " No Bukkit/Sponge servers to gather session data - These measures are inaccurate.");
|
||||
addNote(Icons.HELP_RING + locale.getString(HealthInfoLang.NO_SERVERS_INACCURACY));
|
||||
return;
|
||||
}
|
||||
int serverCount = servers.size();
|
||||
if (serverCount == 1) {
|
||||
addNote(Icons.HELP_RING + " Single Bukkit/Sponge server to gather session data.");
|
||||
addNote(Icons.HELP_RING + locale.getString(HealthInfoLang.SINGLE_SERVER_INACCURACY));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -60,7 +73,7 @@ public class NetworkHealthInformation extends AbstractHealthInfo {
|
|||
|
||||
private void uniquePlayersNote(int serverCount, Key<Server> serverKey, List<DataContainer> perServerContainers) {
|
||||
Icon icon;
|
||||
String uniquePlayersNote = " players visit on servers per day/server on average.";
|
||||
String uniquePlayersNote = locale.getString(HealthInfoLang.PLAYER_VISIT_PER_SERVER);
|
||||
double average = perServerContainers.stream()
|
||||
.mapToInt(c -> c.getUnsafe(AnalysisKeys.AVG_PLAYERS_MONTH))
|
||||
.average().orElse(0.0);
|
||||
|
@ -82,12 +95,12 @@ 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) {
|
||||
Icon icon;
|
||||
String newPlayersNote = " players register on servers per day/server on average.";
|
||||
String newPlayersNote = locale.getString(HealthInfoLang.PLAYER_REGISTER_PER_SERVER);
|
||||
double average = perServerContainers.stream()
|
||||
.mapToInt(c -> c.getUnsafe(AnalysisKeys.AVG_PLAYERS_NEW_MONTH))
|
||||
.average().orElse(0.0);
|
||||
|
@ -109,7 +122,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) {
|
||||
|
@ -139,7 +152,7 @@ public class NetworkHealthInformation extends AbstractHealthInfo {
|
|||
|
||||
private void playersNote(Key<Server> serverKey, List<DataContainer> perServerContainers) {
|
||||
Icon icon = Icons.HELP_RING;
|
||||
String uniquePlayersNote = "${playersMonth} players played on the network:";
|
||||
String uniquePlayersNote = "${playersMonth}" + locale.getString(HealthInfoLang.PLAYER_PLAY_ON_NETWORK);
|
||||
StringBuilder subNotes = new StringBuilder();
|
||||
perServerContainers.stream()
|
||||
.sorted(Comparator.comparingInt(c -> 0 - c.getUnsafe(AnalysisKeys.PLAYERS_MONTH)))
|
||||
|
|
|
@ -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,32 @@
|
|||
package com.djrapitops.plan.modules;
|
||||
|
||||
import com.djrapitops.plan.data.plugin.PluginsConfigSection;
|
||||
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
|
||||
PluginsConfigSection providePluginsConfigSection(PlanConfig config) {
|
||||
return config.getPluginsConfigSection();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.djrapitops.plan.modules.plugin;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.command.PlanCommand;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Dagger module for binding Plan instance.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Module
|
||||
public class BukkitPlanModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
PlanPlugin providePlanPlugin(Plan plugin) {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("mainCommand")
|
||||
CommandNode provideMainCommand(PlanCommand command) {
|
||||
return command;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.djrapitops.plan.modules.plugin;
|
||||
|
||||
import com.djrapitops.plan.PlanBungee;
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.command.PlanBungeeCommand;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Dagger module for binding PlanBungee instance.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Module
|
||||
public class BungeePlanModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
PlanPlugin providePlanPlugin(PlanBungee plugin) {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("mainCommand")
|
||||
CommandNode provideMainCommand(PlanBungeeCommand command) {
|
||||
return command;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.djrapitops.plan.modules.plugin;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.PlanSponge;
|
||||
import com.djrapitops.plan.command.PlanCommand;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Dagger module for binding PlanSponge instance.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Module
|
||||
public class SpongePlanModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
PlanPlugin providePlanPlugin(PlanSponge plugin) {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("mainCommand")
|
||||
CommandNode provideMainCommand(PlanCommand command) {
|
||||
return command;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.djrapitops.plan.modules.plugin;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.PlanVelocity;
|
||||
import com.djrapitops.plan.command.PlanVelocityCommand;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Dagger module for binding PlanVelocity instance.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Module
|
||||
public class VelocityPlanModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
PlanPlugin providePlanPlugin(PlanVelocity plugin) {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("mainCommand")
|
||||
CommandNode provideMainCommand(PlanVelocityCommand command) {
|
||||
return command;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
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 com.djrapitops.plan.system.settings.config.ConfigSystem;
|
||||
import com.djrapitops.plan.system.settings.config.ProxyConfigSystem;
|
||||
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
|
||||
ConfigSystem provideProxyConfigSystem(ProxyConfigSystem proxyConfigSystem) {
|
||||
return proxyConfigSystem;
|
||||
}
|
||||
|
||||
@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,39 @@
|
|||
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.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
|
||||
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,39 @@
|
|||
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.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
|
||||
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.PlanSponge;
|
||||
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 javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Dagger module for Sponge ServerProperties.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Module
|
||||
public class SpongeServerPropertiesModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
ServerProperties provideServerProperties(PlanSponge plugin) {
|
||||
return new SpongeServerProperties(plugin.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();
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue