Large changes: (Still compiles, does not function)

- Made all Command related things be initialized by Dagger
- Removed Update stuff since it is incompatible with ConnectionSystem removal
- Deprecated a lot of static methods
This commit is contained in:
Rsl1122 2018-08-19 13:22:54 +03:00
parent 0b56576bb8
commit b48eb26f74
132 changed files with 1154 additions and 1149 deletions

View File

@ -22,11 +22,8 @@ package com.djrapitops.plan;
import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.command.PlanCommand; import com.djrapitops.plan.command.PlanCommand;
import com.djrapitops.plan.modules.APFModule; import com.djrapitops.plan.modules.APFModule;
import com.djrapitops.plan.modules.common.ExportModule; import com.djrapitops.plan.modules.common.*;
import com.djrapitops.plan.modules.common.FileSystemModule; import com.djrapitops.plan.modules.server.*;
import com.djrapitops.plan.modules.common.LocaleModule;
import com.djrapitops.plan.modules.common.VersionCheckModule;
import com.djrapitops.plan.modules.server.ServerCommandModule;
import com.djrapitops.plan.system.BukkitSystem; import com.djrapitops.plan.system.BukkitSystem;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.PluginLang; import com.djrapitops.plan.system.locale.lang.PluginLang;
@ -40,22 +37,33 @@ import com.djrapitops.plugin.StaticHolder;
import com.djrapitops.plugin.api.utility.log.DebugLog; import com.djrapitops.plugin.api.utility.log.DebugLog;
import com.djrapitops.plugin.benchmarking.Benchmark; import com.djrapitops.plugin.benchmarking.Benchmark;
import com.djrapitops.plugin.command.ColorScheme; import com.djrapitops.plugin.command.ColorScheme;
import com.djrapitops.plugin.command.CommandNode;
import dagger.BindsInstance; import dagger.BindsInstance;
import dagger.Component; import dagger.Component;
import dagger.Module;
import dagger.Provides;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@Singleton @Singleton
@Component(modules = { @Component(modules = {
BukkitPlanModule.class,
APFModule.class, APFModule.class,
ServerCommandModule.class,
ExportModule.class, ExportModule.class,
VersionCheckModule.class, VersionCheckModule.class,
FileSystemModule.class, FileSystemModule.class,
LocaleModule.class ServerConfigModule.class,
LocaleModule.class,
ServerDatabaseModule.class,
ServerDataCacheModule.class,
WebServerSystemModule.class,
ServerInfoSystemModule.class,
PluginHookModule.class,
ServerAPIModule.class
}) })
interface PlanComponent { interface PlanComponent {
@ -73,6 +81,21 @@ interface PlanComponent {
} }
} }
@Module
class BukkitPlanModule {
@Provides
PlanPlugin providePlanPlugin(Plan plan) {
return plan;
}
@Provides
@Named("mainCommand")
CommandNode provideMainCommand(PlanCommand command) {
return command;
}
}
/** /**
* Main class for Bukkit that manages the plugin. * Main class for Bukkit that manages the plugin.
* *

View File

@ -6,6 +6,11 @@ package com.djrapitops.plan;
import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.command.PlanBungeeCommand; import com.djrapitops.plan.command.PlanBungeeCommand;
import com.djrapitops.plan.modules.APFModule;
import com.djrapitops.plan.modules.common.*;
import com.djrapitops.plan.modules.server.ServerConfigModule;
import com.djrapitops.plan.modules.server.ServerDatabaseModule;
import com.djrapitops.plan.modules.server.ServerInfoSystemModule;
import com.djrapitops.plan.system.BungeeSystem; import com.djrapitops.plan.system.BungeeSystem;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.PluginLang; import com.djrapitops.plan.system.locale.lang.PluginLang;
@ -15,12 +20,62 @@ import com.djrapitops.plugin.BungeePlugin;
import com.djrapitops.plugin.StaticHolder; import com.djrapitops.plugin.StaticHolder;
import com.djrapitops.plugin.api.Benchmark; import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.utility.log.DebugLog; import com.djrapitops.plugin.api.utility.log.DebugLog;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.ColorScheme; import com.djrapitops.plugin.command.ColorScheme;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.logging.L;
import dagger.BindsInstance;
import dagger.Component;
import dagger.Module;
import dagger.Provides;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.InputStream; import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger; @Singleton
@Component(modules = {
BungeePlanModule.class,
APFModule.class,
ExportModule.class,
VersionCheckModule.class,
FileSystemModule.class,
ServerConfigModule.class,
LocaleModule.class,
ServerDatabaseModule.class,
WebServerSystemModule.class,
ServerInfoSystemModule.class,
PluginHookModule.class
})
interface PlanBungeeComponent {
PlanBungeeCommand planCommand();
BungeeSystem system();
@Component.Builder
interface Builder {
@BindsInstance
Builder plan(PlanBungee plan);
PlanBungeeComponent build();
}
}
@Module
class BungeePlanModule {
@Provides
PlanPlugin providePlanPlugin(PlanBungee plan) {
return plan;
}
@Provides
@Named("mainCommand")
CommandNode provideMainCommand(PlanBungeeCommand command) {
return command;
}
}
/** /**
* Bungee Main class. * Bungee Main class.
@ -39,36 +94,37 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
super.onEnable(); super.onEnable();
PlanBungeeComponent component = DaggerPlanBungeeComponent.builder().plan(this).build();
try { try {
system = new BungeeSystem(this); system = component.system();
locale = system.getLocaleSystem().getLocale(); locale = system.getLocaleSystem().getLocale();
system.enable(); system.enable();
new BStatsBungee(this).registerMetrics(); new BStatsBungee(this).registerMetrics();
Log.info(locale.getString(PluginLang.ENABLED)); logger.info(locale.getString(PluginLang.ENABLED));
} catch (AbstractMethodError e) { } catch (AbstractMethodError e) {
Log.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart."); logger.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart.");
} catch (EnableException e) { } catch (EnableException e) {
Log.error("----------------------------------------"); logger.error("----------------------------------------");
Log.error("Error: " + e.getMessage()); logger.error("Error: " + e.getMessage());
Log.error("----------------------------------------"); logger.error("----------------------------------------");
Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planbungee reload"); logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planbungee reload");
onDisable(); onDisable();
} catch (Exception e) { } catch (Exception e) {
Logger.getGlobal().log(Level.SEVERE, this.getClass().getSimpleName() + "-v" + getVersion(), e); errorHandler.log(L.CRITICAL, this.getClass(), e);
Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planbungee reload"); logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /planbungee reload");
Log.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues"); logger.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
onDisable(); onDisable();
} }
registerCommand("planbungee", new PlanBungeeCommand(this)); registerCommand("planbungee", component.planCommand());
} }
@Override @Override
public void onDisable() { public void onDisable() {
system.disable(); system.disable();
Log.info(locale.getString(PluginLang.DISABLED)); logger.info(locale.getString(PluginLang.DISABLED));
Benchmark.pluginDisabled(PlanBungee.class); Benchmark.pluginDisabled(PlanBungee.class);
DebugLog.pluginDisabled(PlanBungee.class); DebugLog.pluginDisabled(PlanBungee.class);
} }

View File

@ -2,6 +2,9 @@ package com.djrapitops.plan;
import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.command.PlanCommand; import com.djrapitops.plan.command.PlanCommand;
import com.djrapitops.plan.modules.APFModule;
import com.djrapitops.plan.modules.common.*;
import com.djrapitops.plan.modules.server.*;
import com.djrapitops.plan.system.SpongeSystem; import com.djrapitops.plan.system.SpongeSystem;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.PluginLang; import com.djrapitops.plan.system.locale.lang.PluginLang;
@ -13,7 +16,13 @@ import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.utility.log.DebugLog; import com.djrapitops.plugin.api.utility.log.DebugLog;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.ColorScheme; import com.djrapitops.plugin.command.ColorScheme;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.logging.L;
import com.google.inject.Inject; import com.google.inject.Inject;
import dagger.BindsInstance;
import dagger.Component;
import dagger.Module;
import dagger.Provides;
import org.bstats.sponge.Metrics; import org.bstats.sponge.Metrics;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.spongepowered.api.config.ConfigDir; import org.spongepowered.api.config.ConfigDir;
@ -22,9 +31,58 @@ import org.spongepowered.api.event.game.state.GameStartedServerEvent;
import org.spongepowered.api.event.game.state.GameStoppingServerEvent; import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
import org.spongepowered.api.plugin.Plugin; import org.spongepowered.api.plugin.Plugin;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.File; import java.io.File;
import java.io.InputStream; import java.io.InputStream;
@Singleton
@Component(modules = {
SpongePlanModule.class,
APFModule.class,
ExportModule.class,
VersionCheckModule.class,
FileSystemModule.class,
ServerConfigModule.class,
LocaleModule.class,
ServerDatabaseModule.class,
ServerDataCacheModule.class,
WebServerSystemModule.class,
ServerInfoSystemModule.class,
PluginHookModule.class,
ServerAPIModule.class,
})
interface PlanSpongeComponent {
PlanCommand planCommand();
SpongeSystem system();
@Component.Builder
interface Builder {
@BindsInstance
Builder plan(PlanSponge plan);
PlanSpongeComponent build();
}
}
@Module
class SpongePlanModule {
@Provides
PlanPlugin providePlanPlugin(PlanSponge plan) {
return plan;
}
@Provides
@Named("mainCommand")
CommandNode provideMainCommand(PlanCommand command) {
return command;
}
}
@Plugin(id = "plan", name = "Plan", version = "4.4.3", description = "Player Analytics Plugin by Rsl1122", authors = {"Rsl1122"}) @Plugin(id = "plan", name = "Plan", version = "4.4.3", description = "Player Analytics Plugin by Rsl1122", authors = {"Rsl1122"})
public class PlanSponge extends SpongePlugin implements PlanPlugin { public class PlanSponge extends SpongePlugin implements PlanPlugin {
@ -57,29 +115,30 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
super.onEnable(); super.onEnable();
PlanSpongeComponent component = DaggerPlanSpongeComponent.builder().plan(this).build();
try { try {
system = new SpongeSystem(this); system = component.system();
locale = system.getLocaleSystem().getLocale(); locale = system.getLocaleSystem().getLocale();
system.enable(); system.enable();
new BStatsSponge(metrics).registerMetrics(); new BStatsSponge(metrics).registerMetrics();
Log.info(locale.getString(PluginLang.ENABLED)); logger.info(locale.getString(PluginLang.ENABLED));
} catch (AbstractMethodError e) { } catch (AbstractMethodError e) {
Log.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart."); logger.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart.");
} catch (EnableException e) { } catch (EnableException e) {
Log.error("----------------------------------------"); logger.error("----------------------------------------");
Log.error("Error: " + e.getMessage()); logger.error("Error: " + e.getMessage());
Log.error("----------------------------------------"); logger.error("----------------------------------------");
Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload"); logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
onDisable(); onDisable();
} catch (Exception e) { } catch (Exception e) {
Log.toLog(this.getClass().getSimpleName() + "-v" + getVersion(), e); errorHandler.log(L.CRITICAL, this.getClass(), e);
Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload"); logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
Log.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues"); logger.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
onDisable(); onDisable();
} }
registerCommand("plan", new PlanCommand(this)); registerCommand("plan", component.planCommand());
} }
@Override @Override

View File

@ -1,16 +1,18 @@
package com.djrapitops.plan.command; package com.djrapitops.plan.command;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.command.commands.*; import com.djrapitops.plan.command.commands.*;
import com.djrapitops.plan.command.commands.manage.ManageConDebugCommand; import com.djrapitops.plan.command.commands.manage.ManageConDebugCommand;
import com.djrapitops.plan.command.commands.manage.ManageRawDataCommand; import com.djrapitops.plan.command.commands.manage.ManageRawDataCommand;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang; import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plugin.command.ColorScheme;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.TreeCmdNode; import com.djrapitops.plugin.command.TreeCmdNode;
import javax.inject.Inject;
/** /**
* TreeCommand for the /plan command, and all subcommands. * TreeCommand for the /plan command, and all subcommands.
* <p> * <p>
@ -21,31 +23,42 @@ import com.djrapitops.plugin.command.TreeCmdNode;
*/ */
public class PlanBungeeCommand extends TreeCmdNode { public class PlanBungeeCommand extends TreeCmdNode {
public PlanBungeeCommand(PlanPlugin plugin) { @Inject
public PlanBungeeCommand(ColorScheme colorScheme, Locale locale,
// Group 1
NetworkCommand networkCommand,
ListServersCommand listServersCommand,
ListPlayersCommand listPlayersCommand,
// Group 2
RegisterCommand registerCommand,
WebUserCommand webUserCommand,
// Group 3
ManageConDebugCommand conDebugCommand,
ManageRawDataCommand rawDataCommand,
BungeeSetupToggleCommand setupToggleCommand,
ReloadCommand reloadCommand,
DisableCommand disableCommand
) {
super("planbungee", Permissions.MANAGE.getPermission(), CommandType.CONSOLE, null); super("planbungee", Permissions.MANAGE.getPermission(), CommandType.CONSOLE, null);
super.setColorScheme(plugin.getColorScheme()); super.setColorScheme(colorScheme);
Locale locale = plugin.getSystem().getLocaleSystem().getLocale();
setInDepthHelp(locale.getArray(DeepHelpLang.PLAN)); setInDepthHelp(locale.getArray(DeepHelpLang.PLAN));
RegisterCommand registerCommand = new RegisterCommand(plugin);
CommandNode[] analyticsGroup = { CommandNode[] analyticsGroup = {
new NetworkCommand(plugin), networkCommand,
new ListServersCommand(plugin), listServersCommand,
new ListPlayersCommand(plugin), listPlayersCommand
}; };
CommandNode[] webGroup = { CommandNode[] webGroup = {
registerCommand, registerCommand,
new WebUserCommand(plugin, registerCommand, this), webUserCommand
}; };
CommandNode[] manageGroup = { CommandNode[] manageGroup = {
new ManageConDebugCommand(plugin), conDebugCommand,
new ManageRawDataCommand(plugin), rawDataCommand,
new BungeeSetupToggleCommand(plugin), setupToggleCommand,
new ReloadCommand(plugin), reloadCommand,
new DisableCommand(plugin), disableCommand
// (Settings.ALLOW_UPDATE.isTrue() ? new UpdateCommand() : null)
}; };
setNodeGroups(analyticsGroup, webGroup, manageGroup); setNodeGroups(analyticsGroup, webGroup, manageGroup);
} }

View File

@ -1,14 +1,17 @@
package com.djrapitops.plan.command; package com.djrapitops.plan.command;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.command.commands.*; import com.djrapitops.plan.command.commands.*;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang; import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.settings.config.PlanConfig;
import com.djrapitops.plugin.command.ColorScheme;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.TreeCmdNode; import com.djrapitops.plugin.command.TreeCmdNode;
import javax.inject.Inject;
/** /**
* TreeCommand for the /plan command, and all SubCommands. * TreeCommand for the /plan command, and all SubCommands.
* <p> * <p>
@ -19,35 +22,49 @@ import com.djrapitops.plugin.command.TreeCmdNode;
*/ */
public class PlanCommand extends TreeCmdNode { public class PlanCommand extends TreeCmdNode {
public PlanCommand(PlanPlugin plugin) { @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
WebUserCommand webUserCommand,
RegisterCommand registerCommand,
// Group 3
InfoCommand infoCommand,
ReloadCommand reloadCommand,
ManageCommand manageCommand,
DevCommand devCommand
) {
super("plan", "", CommandType.CONSOLE, null); super("plan", "", CommandType.CONSOLE, null);
super.setDefaultCommand("inspect"); super.setDefaultCommand("inspect");
super.setColorScheme(plugin.getColorScheme()); super.setColorScheme(colorScheme);
Locale locale = plugin.getSystem().getLocaleSystem().getLocale();
setInDepthHelp(locale.getArray(DeepHelpLang.PLAN)); setInDepthHelp(locale.getArray(DeepHelpLang.PLAN));
RegisterCommand registerCommand = new RegisterCommand(plugin);
CommandNode[] analyticsGroup = { CommandNode[] analyticsGroup = {
new InspectCommand(plugin), inspectCommand,
new QInspectCommand(plugin), qInspectCommand,
new SearchCommand(plugin), searchCommand,
new ListPlayersCommand(plugin), listPlayersCommand,
new AnalyzeCommand(plugin), analyzeCommand,
new NetworkCommand(plugin), networkCommand,
new ListServersCommand(plugin) listServersCommand
}; };
CommandNode[] webGroup = { CommandNode[] webGroup = {
new WebUserCommand(plugin, registerCommand, this), webUserCommand,
registerCommand registerCommand
}; };
CommandNode[] manageGroup = { CommandNode[] manageGroup = {
new InfoCommand(plugin), infoCommand,
new ReloadCommand(plugin), reloadCommand,
new ManageCommand(plugin, this), manageCommand,
(Settings.DEV_MODE.isTrue() ? new DevCommand(plugin) : null), config.isTrue(Settings.DEV_MODE) ? devCommand : null
// (Settings.ALLOW_UPDATE.isTrue() ? new UpdateCommand() : null)
}; };
setNodeGroups(analyticsGroup, webGroup, manageGroup); setNodeGroups(analyticsGroup, webGroup, manageGroup);
} }

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands; package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
@ -15,13 +14,15 @@ import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.locale.lang.ManageLang; import com.djrapitops.plan.system.locale.lang.ManageLang;
import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.webserver.WebServerSystem; import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.CommandUtils; import com.djrapitops.plugin.command.CommandUtils;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import javax.inject.Inject;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
@ -35,11 +36,22 @@ import java.util.UUID;
public class AnalyzeCommand extends CommandNode { public class AnalyzeCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final InfoSystem infoSystem;
private final WebServer webServer;
private final Database database;
private final ConnectionSystem connectionSystem;
private final ErrorHandler errorHandler;
public AnalyzeCommand(PlanPlugin plugin) { @Inject
public AnalyzeCommand(Locale locale, InfoSystem infoSystem, WebServer webServer, Database database, ErrorHandler errorHandler) {
super("analyze|analyse|analysis|a", Permissions.ANALYZE.getPermission(), CommandType.CONSOLE); super("analyze|analyse|analysis|a", Permissions.ANALYZE.getPermission(), CommandType.CONSOLE);
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.locale = locale;
this.infoSystem = infoSystem;
connectionSystem = infoSystem.getConnectionSystem();
this.webServer = webServer;
this.database = database;
this.errorHandler = errorHandler;
setShortHelp(locale.getString(CmdHelpLang.ANALYZE)); setShortHelp(locale.getString(CmdHelpLang.ANALYZE));
setInDepthHelp(locale.getArray(DeepHelpLang.ANALYZE)); setInDepthHelp(locale.getArray(DeepHelpLang.ANALYZE));
@ -52,22 +64,22 @@ public class AnalyzeCommand extends CommandNode {
Processing.submitNonCritical(() -> { Processing.submitNonCritical(() -> {
try { try {
Server server = getServer(args).orElseGet(ServerInfo::getServer); Server server = getServer(args).orElseGet(ServerInfo::getServer_Old);
UUID serverUUID = server.getUuid(); UUID serverUUID = server.getUuid();
InfoSystem.getInstance().generateAnalysisPage(serverUUID); infoSystem.generateAnalysisPage(serverUUID);
sendWebUserNotificationIfNecessary(sender); sendWebUserNotificationIfNecessary(sender);
sendLink(server, sender); sendLink(server, sender);
} catch (DBOpException | WebException e) { } catch (DBOpException | WebException e) {
sender.sendMessage("§cError occurred: " + e.toString()); sender.sendMessage("§cError occurred: " + e.toString());
Log.toLog(this.getClass(), e); errorHandler.log(L.ERROR, this.getClass(), e);
} }
}); });
} }
private void sendLink(Server server, ISender sender) { private void sendLink(Server server, ISender sender) {
String target = "/server/" + server.getName(); String target = "/server/" + server.getName();
String url = ConnectionSystem.getAddress() + target; String url = connectionSystem.getMainAddress() + target;
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX); String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
sender.sendMessage(locale.getString(CommandLang.HEADER_ANALYSIS)); sender.sendMessage(locale.getString(CommandLang.HEADER_ANALYSIS));
// Link // Link
@ -82,18 +94,16 @@ public class AnalyzeCommand extends CommandNode {
} }
private void sendWebUserNotificationIfNecessary(ISender sender) { private void sendWebUserNotificationIfNecessary(ISender sender) {
if (WebServerSystem.getInstance().getWebServer().isAuthRequired() && CommandUtils.isPlayer(sender)) { if (webServer.isAuthRequired() &&
CommandUtils.isPlayer(sender) &&
boolean senderHasWebUser = Database.getActive().check().doesWebUserExists(sender.getName()); !database.check().doesWebUserExists(sender.getName())) {
if (!senderHasWebUser) { sender.sendMessage("§e" + locale.getString(CommandLang.NO_WEB_USER_NOTIFY));
sender.sendMessage("§e" + locale.getString(CommandLang.NO_WEB_USER_NOTIFY));
}
} }
} }
private Optional<Server> getServer(String[] args) { private Optional<Server> getServer(String[] args) {
if (args.length >= 1 && ConnectionSystem.getInstance().isServerAvailable()) { if (args.length >= 1 && connectionSystem.isServerAvailable()) {
Map<UUID, Server> bukkitServers = Database.getActive().fetch().getBukkitServers(); Map<UUID, Server> bukkitServers = database.fetch().getBukkitServers();
String serverIdentifier = getGivenIdentifier(args); String serverIdentifier = getGivenIdentifier(args);
for (Map.Entry<UUID, Server> entry : bukkitServers.entrySet()) { for (Map.Entry<UUID, Server> entry : bukkitServers.entrySet()) {
Server server = entry.getValue(); Server server = entry.getValue();

View File

@ -4,7 +4,6 @@
*/ */
package com.djrapitops.plan.command.commands; package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.info.connection.ConnectionSystem; import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang; import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
@ -15,6 +14,8 @@ import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import javax.inject.Inject;
/** /**
* Command for Toggling whether or not BungeeCord accepts set up requests. * Command for Toggling whether or not BungeeCord accepts set up requests.
* <p> * <p>
@ -25,11 +26,14 @@ import com.djrapitops.plugin.command.ISender;
public class BungeeSetupToggleCommand extends CommandNode { public class BungeeSetupToggleCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final ConnectionSystem connectionSystem;
public BungeeSetupToggleCommand(PlanPlugin plugin) { @Inject
public BungeeSetupToggleCommand(Locale locale, ConnectionSystem connectionSystem) {
super("setup", Permissions.MANAGE.getPermission(), CommandType.ALL); super("setup", Permissions.MANAGE.getPermission(), CommandType.ALL);
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.locale = locale;
this.connectionSystem = connectionSystem;
setShortHelp(locale.getString(CmdHelpLang.SETUP)); setShortHelp(locale.getString(CmdHelpLang.SETUP));
setInDepthHelp(locale.getArray(DeepHelpLang.SETUP)); setInDepthHelp(locale.getArray(DeepHelpLang.SETUP));
@ -37,15 +41,13 @@ public class BungeeSetupToggleCommand extends CommandNode {
@Override @Override
public void onCommand(ISender sender, String s, String[] strings) { public void onCommand(ISender sender, String s, String[] strings) {
boolean setupAllowed = ConnectionSystem.isSetupAllowed(); if (connectionSystem.isSetupAllowed()) {
ConnectionSystem connectionSystem = ConnectionSystem.getInstance();
if (setupAllowed) {
connectionSystem.setSetupAllowed(false); connectionSystem.setSetupAllowed(false);
} else { } else {
connectionSystem.setSetupAllowed(true); connectionSystem.setSetupAllowed(true);
} }
String msg = locale.getString(!setupAllowed ? CommandLang.SETUP_ALLOWED : CommandLang.CONNECT_FORBIDDEN);
String msg = locale.getString(connectionSystem.isSetupAllowed() ? CommandLang.SETUP_ALLOWED : CommandLang.CONNECT_FORBIDDEN);
sender.sendMessage(msg); sender.sendMessage(msg);
} }
} }

View File

@ -4,7 +4,6 @@
*/ */
package com.djrapitops.plan.command.commands; package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang; import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang; import com.djrapitops.plan.system.locale.lang.CommandLang;
@ -13,6 +12,7 @@ import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import javax.inject.Inject;
import java.util.Arrays; import java.util.Arrays;
/** /**
@ -24,10 +24,11 @@ public class DevCommand extends CommandNode {
private final Locale locale; private final Locale locale;
public DevCommand(PlanPlugin plugin) { @Inject
public DevCommand(Locale locale) {
super("dev", "plan.*", CommandType.PLAYER_OR_ARGS); super("dev", "plan.*", CommandType.PLAYER_OR_ARGS);
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.locale = locale;
setShortHelp(locale.get(CmdHelpLang.DEV).toString()); setShortHelp(locale.get(CmdHelpLang.DEV).toString());
setArguments("<feature>"); setArguments("<feature>");

View File

@ -9,14 +9,19 @@ import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import javax.inject.Inject;
public class DisableCommand extends CommandNode { public class DisableCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final PlanPlugin plugin;
public DisableCommand(PlanPlugin plugin) { @Inject
public DisableCommand(PlanPlugin plugin, Locale locale) {
super("disable", "plan.reload", CommandType.ALL); super("disable", "plan.reload", CommandType.ALL);
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.plugin = plugin;
this.locale = locale;
setShortHelp(locale.getString(CmdHelpLang.DISABLE)); setShortHelp(locale.getString(CmdHelpLang.DISABLE));
setInDepthHelp(locale.getArray(DeepHelpLang.DISABLE)); setInDepthHelp(locale.getArray(DeepHelpLang.DISABLE));
@ -24,7 +29,7 @@ public class DisableCommand extends CommandNode {
@Override @Override
public void onCommand(ISender sender, String commandLabel, String[] args) { public void onCommand(ISender sender, String commandLabel, String[] args) {
PlanPlugin.getInstance().onDisable(); plugin.onDisable();
sender.sendMessage(locale.getString(CommandLang.DISABLE_DISABLED)); sender.sendMessage(locale.getString(CommandLang.DISABLE_DISABLED));
} }
} }

View File

@ -13,6 +13,8 @@ import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import javax.inject.Inject;
/** /**
* This SubCommand is used to view the version and the database type in use. * This SubCommand is used to view the version and the database type in use.
* *
@ -23,14 +25,19 @@ public class InfoCommand extends CommandNode {
private final PlanPlugin plugin; private final PlanPlugin plugin;
private final Locale locale; private final Locale locale;
private final ConnectionSystem connectionSystem;
private final VersionCheckSystem versionCheckSystem;
public InfoCommand(PlanPlugin plugin) { @Inject
public InfoCommand(PlanPlugin plugin, Locale locale, ConnectionSystem connectionSystem, VersionCheckSystem versionCheckSystem) {
super("info", Permissions.INFO.getPermission(), CommandType.CONSOLE); super("info", Permissions.INFO.getPermission(), CommandType.CONSOLE);
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.plugin = plugin;
this.locale = locale;
this.connectionSystem = connectionSystem;
this.versionCheckSystem = versionCheckSystem;
setShortHelp(locale.get(CmdHelpLang.INFO).toString()); setShortHelp(locale.get(CmdHelpLang.INFO).toString());
this.plugin = plugin;
} }
@Override @Override
@ -38,8 +45,8 @@ public class InfoCommand extends CommandNode {
String yes = locale.getString(GenericLang.YES); String yes = locale.getString(GenericLang.YES);
String no = locale.getString(GenericLang.NO); String no = locale.getString(GenericLang.NO);
String updateAvailable = VersionCheckSystem.isNewVersionAvailable() ? yes : no; String updateAvailable = versionCheckSystem.isNewVersionAvailable() ? yes : no;
String connectedToBungee = ConnectionSystem.getInstance().isServerAvailable() ? yes : no; String connectedToBungee = connectionSystem.isServerAvailable() ? yes : no;
String[] messages = { String[] messages = {
locale.getString(CommandLang.HEADER_INFO), locale.getString(CommandLang.HEADER_INFO),
"", "",

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands; package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
@ -13,12 +12,14 @@ import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.webserver.WebServer; import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plan.utilities.MiscUtils; import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plan.utilities.uuid.UUIDUtility; import com.djrapitops.plan.utilities.uuid.UUIDUtility;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.CommandUtils; import com.djrapitops.plugin.command.CommandUtils;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import javax.inject.Inject;
import java.util.UUID; import java.util.UUID;
/** /**
@ -30,12 +31,19 @@ import java.util.UUID;
public class InspectCommand extends CommandNode { public class InspectCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final Database database;
private final WebServer webServer;
private final ErrorHandler errorHandler;
public InspectCommand(PlanPlugin plugin) { @Inject
public InspectCommand(Locale locale, Database database, WebServer webServer, ErrorHandler errorHandler) {
super("inspect", Permissions.INSPECT.getPermission(), CommandType.PLAYER_OR_ARGS); super("inspect", Permissions.INSPECT.getPermission(), CommandType.PLAYER_OR_ARGS);
setArguments("<player>"); setArguments("<player>");
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.locale = locale;
this.database = database;
this.webServer = webServer;
this.errorHandler = errorHandler;
setShortHelp(locale.getString(CmdHelpLang.INSPECT)); setShortHelp(locale.getString(CmdHelpLang.INSPECT));
setInDepthHelp(locale.getArray(DeepHelpLang.INSPECT)); setInDepthHelp(locale.getArray(DeepHelpLang.INSPECT));
@ -61,24 +69,23 @@ public class InspectCommand extends CommandNode {
return; return;
} }
Database activeDB = Database.getActive(); if (!database.check().isPlayerRegistered(uuid)) {
if (!activeDB.check().isPlayerRegistered(uuid)) {
sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_KNOWN)); sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_KNOWN));
return; return;
} }
checkWebUserAndNotify(activeDB, sender); checkWebUserAndNotify(sender);
Processing.submit(new InspectCacheRequestProcessor(uuid, sender, playerName, locale)); Processing.submit(new InspectCacheRequestProcessor(uuid, sender, playerName, locale));
} catch (DBOpException e) { } catch (DBOpException e) {
sender.sendMessage("§eDatabase exception occurred: " + e.getMessage()); sender.sendMessage("§eDatabase exception occurred: " + e.getMessage());
Log.toLog(this.getClass(), e); errorHandler.log(L.ERROR, this.getClass(), e);
} }
}); });
} }
private void checkWebUserAndNotify(Database activeDB, ISender sender) { private void checkWebUserAndNotify(ISender sender) {
if (CommandUtils.isPlayer(sender) && WebServer.getInstance().isAuthRequired()) { if (CommandUtils.isPlayer(sender) && webServer.isAuthRequired()) {
boolean senderHasWebUser = activeDB.check().doesWebUserExists(sender.getName()); boolean senderHasWebUser = database.check().doesWebUserExists(sender.getName());
if (!senderHasWebUser) { if (!senderHasWebUser) {
sender.sendMessage("§e" + locale.getString(CommandLang.NO_WEB_USER_NOTIFY)); sender.sendMessage("§e" + locale.getString(CommandLang.NO_WEB_USER_NOTIFY));

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands; package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.info.connection.ConnectionSystem; import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang; import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
@ -12,6 +11,8 @@ import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.CommandUtils; import com.djrapitops.plugin.command.CommandUtils;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import javax.inject.Inject;
/** /**
* Command used to display url to the player list page. * Command used to display url to the player list page.
* *
@ -21,11 +22,14 @@ import com.djrapitops.plugin.command.ISender;
public class ListPlayersCommand extends CommandNode { public class ListPlayersCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final ConnectionSystem connectionSystem;
public ListPlayersCommand(PlanPlugin plugin) { @Inject
public ListPlayersCommand(Locale locale, ConnectionSystem connectionSystem) {
super("players|pl|playerlist|list", Permissions.INSPECT_OTHER.getPermission(), CommandType.CONSOLE); super("players|pl|playerlist|list", Permissions.INSPECT_OTHER.getPermission(), CommandType.CONSOLE);
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.locale = locale;
this.connectionSystem = connectionSystem;
setShortHelp(locale.getString(CmdHelpLang.PLAYERS)); setShortHelp(locale.getString(CmdHelpLang.PLAYERS));
setInDepthHelp(locale.getArray(DeepHelpLang.PLAYERS)); setInDepthHelp(locale.getArray(DeepHelpLang.PLAYERS));
@ -40,7 +44,7 @@ public class ListPlayersCommand extends CommandNode {
sender.sendMessage(locale.getString(CommandLang.HEADER_PLAYERS)); sender.sendMessage(locale.getString(CommandLang.HEADER_PLAYERS));
// Link // Link
String url = ConnectionSystem.getAddress() + "/players/"; String url = connectionSystem.getMainAddress() + "/players/";
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX); String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
boolean console = !CommandUtils.isPlayer(sender); boolean console = !CommandUtils.isPlayer(sender);
if (console) { if (console) {

View File

@ -1,7 +1,7 @@
package com.djrapitops.plan.command.commands; package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.data.store.mutators.formatting.Formatter;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.info.server.Server; import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
@ -9,12 +9,14 @@ import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang; import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang; import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.ColorScheme; import com.djrapitops.plugin.command.ColorScheme;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import javax.inject.Inject;
import java.util.List; import java.util.List;
/** /**
@ -24,14 +26,19 @@ import java.util.List;
*/ */
public class ListServersCommand extends CommandNode { public class ListServersCommand extends CommandNode {
private final PlanPlugin plugin;
private final Locale locale; private final Locale locale;
private final ColorScheme colorScheme;
private final Database database;
private final ErrorHandler errorHandler;
public ListServersCommand(PlanPlugin plugin) { @Inject
public ListServersCommand(Locale locale, ColorScheme colorScheme, Database database, ErrorHandler errorHandler) {
super("servers|serverlist|listservers|sl|ls", Permissions.MANAGE.getPermission(), CommandType.CONSOLE); super("servers|serverlist|listservers|sl|ls", Permissions.MANAGE.getPermission(), CommandType.CONSOLE);
this.plugin = plugin;
this.locale = plugin.getSystem().getLocaleSystem().getLocale(); this.locale = locale;
this.colorScheme = colorScheme;
this.database = database;
this.errorHandler = errorHandler;
setShortHelp(locale.getString(CmdHelpLang.SERVERS)); setShortHelp(locale.getString(CmdHelpLang.SERVERS));
setInDepthHelp(locale.getArray(DeepHelpLang.SERVERS)); setInDepthHelp(locale.getArray(DeepHelpLang.SERVERS));
@ -39,20 +46,28 @@ public class ListServersCommand extends CommandNode {
@Override @Override
public void onCommand(ISender sender, String commandLabel, String[] args) { public void onCommand(ISender sender, String commandLabel, String[] args) {
ColorScheme colorScheme = plugin.getColorScheme();
String sCol = colorScheme.getSecondaryColor(); String sCol = colorScheme.getSecondaryColor();
String tCol = colorScheme.getTertiaryColor(); String tCol = colorScheme.getTertiaryColor();
Formatter<Server> serverFormatter = serverLister(sCol, tCol);
try { try {
sender.sendMessage(locale.getString(CommandLang.HEADER_SERVERS)); sender.sendMessage(locale.getString(CommandLang.HEADER_SERVERS));
List<Server> servers = Database.getActive().fetch().getServers(); sendServers(sender, serverFormatter);
for (Server server : servers) {
sender.sendMessage(" " + tCol + server.getId() + sCol + " : " + server.getName() + " : " + server.getWebAddress());
}
sender.sendMessage(">"); sender.sendMessage(">");
} catch (DBOpException e) { } catch (DBOpException e) {
sender.sendMessage("§cDatabase Exception occurred."); sender.sendMessage("§cDatabase Exception occurred.");
Log.toLog(this.getClass(), e); errorHandler.log(L.WARN, this.getClass(), e);
} }
} }
private void sendServers(ISender sender, Formatter<Server> serverFormatter) {
List<Server> servers = database.fetch().getServers();
for (Server server : servers) {
sender.sendMessage(serverFormatter.apply(server));
}
}
private Formatter<Server> serverLister(String tertiaryColor, String secondaryColor) {
return server -> " " + tertiaryColor + server.getId() + secondaryColor + " : " + server.getName() + " : " + server.getWebAddress();
}
} }

View File

@ -1,14 +1,18 @@
package com.djrapitops.plan.command.commands; package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.command.commands.manage.*; import com.djrapitops.plan.command.commands.manage.*;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang; import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang; import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plugin.command.ColorScheme;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.TreeCmdNode; import com.djrapitops.plugin.command.TreeCmdNode;
import dagger.Lazy;
import javax.inject.Inject;
import javax.inject.Named;
/** /**
* This SubCommand is used to manage the the plugin's database and components. * This SubCommand is used to manage the the plugin's database and components.
@ -18,29 +22,43 @@ import com.djrapitops.plugin.command.TreeCmdNode;
*/ */
public class ManageCommand extends TreeCmdNode { public class ManageCommand extends TreeCmdNode {
public ManageCommand(PlanPlugin plugin, CommandNode parent) { @Inject
super("manage|m", Permissions.MANAGE.getPermission(), CommandType.CONSOLE, parent); public ManageCommand(ColorScheme colorScheme, Locale locale, @Named("mainCommand") Lazy<CommandNode> parent,
// Group 1
Locale locale = plugin.getSystem().getLocaleSystem().getLocale(); ManageRawDataCommand rawDataCommand,
ManageMoveCommand moveCommand,
ManageBackupCommand backupCommand,
ManageRemoveCommand removeCommand,
ManageRestoreCommand restoreCommand,
ManageHotSwapCommand hotSwapCommand,
ManageClearCommand clearCommand,
// Group 2
ManageSetupCommand setupCommand,
ManageConDebugCommand conDebugCommand,
ManageImportCommand importCommand,
ManageDisableCommand disableCommand,
ManageUninstalledCommand uninstalledCommand
) {
super("manage|m", Permissions.MANAGE.getPermission(), CommandType.CONSOLE, parent.get());
super.setColorScheme(colorScheme);
setShortHelp(locale.getString(CmdHelpLang.MANAGE)); setShortHelp(locale.getString(CmdHelpLang.MANAGE));
setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE)); setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE));
super.setColorScheme(plugin.getColorScheme());
CommandNode[] databaseGroup = { CommandNode[] databaseGroup = {
new ManageRawDataCommand(plugin), rawDataCommand,
new ManageMoveCommand(plugin), moveCommand,
new ManageBackupCommand(plugin), backupCommand,
new ManageRestoreCommand(plugin), restoreCommand,
new ManageRemoveCommand(plugin), hotSwapCommand,
new ManageHotSwapCommand(plugin), removeCommand,
new ManageClearCommand(plugin), clearCommand,
}; };
CommandNode[] pluginGroup = { CommandNode[] pluginGroup = {
new ManageSetupCommand(plugin), setupCommand,
new ManageConDebugCommand(plugin), conDebugCommand,
new ManageImportCommand(plugin), importCommand,
new ManageDisableCommand(plugin), disableCommand,
new ManageUninstalledCommand(plugin) uninstalledCommand
}; };
setNodeGroups(databaseGroup, pluginGroup); setNodeGroups(databaseGroup, pluginGroup);
} }

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands; package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.info.connection.ConnectionSystem; import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang; import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
@ -12,6 +11,8 @@ import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.CommandUtils; import com.djrapitops.plugin.command.CommandUtils;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import javax.inject.Inject;
/** /**
* Command used to display url to the network page. * Command used to display url to the network page.
* *
@ -20,11 +21,14 @@ import com.djrapitops.plugin.command.ISender;
public class NetworkCommand extends CommandNode { public class NetworkCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final ConnectionSystem connectionSystem;
public NetworkCommand(PlanPlugin plugin) { @Inject
public NetworkCommand(Locale locale, ConnectionSystem connectionSystem) {
super("network|n|netw", Permissions.ANALYZE.getPermission(), CommandType.CONSOLE); super("network|n|netw", Permissions.ANALYZE.getPermission(), CommandType.CONSOLE);
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.locale = locale;
this.connectionSystem = connectionSystem;
setShortHelp(locale.getString(CmdHelpLang.NETWORK)); setShortHelp(locale.getString(CmdHelpLang.NETWORK));
setInDepthHelp(locale.getArray(DeepHelpLang.NETWORK)); setInDepthHelp(locale.getArray(DeepHelpLang.NETWORK));
@ -39,7 +43,7 @@ public class NetworkCommand extends CommandNode {
sender.sendMessage(locale.getString(CommandLang.HEADER_NETWORK)); sender.sendMessage(locale.getString(CommandLang.HEADER_NETWORK));
// Link // Link
String url = ConnectionSystem.getAddress() + "/network/"; String url = connectionSystem.getMainAddress() + "/network/";
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX); String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
boolean console = !CommandUtils.isPlayer(sender); boolean console = !CommandUtils.isPlayer(sender);
if (console) { if (console) {

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands; package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.data.container.GeoInfo; import com.djrapitops.plan.data.container.GeoInfo;
import com.djrapitops.plan.data.store.containers.PlayerContainer; import com.djrapitops.plan.data.store.containers.PlayerContainer;
@ -21,11 +20,13 @@ import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.utilities.MiscUtils; import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plan.utilities.uuid.UUIDUtility; import com.djrapitops.plan.utilities.uuid.UUIDUtility;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import javax.inject.Inject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -40,17 +41,17 @@ import java.util.UUID;
public class QInspectCommand extends CommandNode { public class QInspectCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final Database database;
private final ErrorHandler errorHandler;
/** @Inject
* Class Constructor. public QInspectCommand(Locale locale, Database database, ErrorHandler errorHandler) {
*
* @param plugin Current instance of Plan
*/
public QInspectCommand(PlanPlugin plugin) {
super("qinspect", Permissions.QUICK_INSPECT.getPermission(), CommandType.PLAYER_OR_ARGS); super("qinspect", Permissions.QUICK_INSPECT.getPermission(), CommandType.PLAYER_OR_ARGS);
setArguments("<player>"); setArguments("<player>");
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.locale = locale;
this.database = database;
this.errorHandler = errorHandler;
setShortHelp(locale.getString(CmdHelpLang.QINSPECT)); setShortHelp(locale.getString(CmdHelpLang.QINSPECT));
setInDepthHelp(locale.getArray(DeepHelpLang.QINSPECT)); setInDepthHelp(locale.getArray(DeepHelpLang.QINSPECT));
@ -77,7 +78,7 @@ public class QInspectCommand extends CommandNode {
return; return;
} }
PlayerContainer container = Database.getActive().fetch().getPlayerContainer(uuid); PlayerContainer container = database.fetch().getPlayerContainer(uuid);
if (!container.getValue(PlayerKeys.REGISTERED).isPresent()) { if (!container.getValue(PlayerKeys.REGISTERED).isPresent()) {
sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_KNOWN)); sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_KNOWN));
return; return;
@ -86,7 +87,7 @@ public class QInspectCommand extends CommandNode {
sendMessages(sender, container); sendMessages(sender, container);
} catch (DBOpException e) { } catch (DBOpException e) {
sender.sendMessage("§eDatabase exception occurred: " + e.getMessage()); sender.sendMessage("§eDatabase exception occurred: " + e.getMessage());
Log.toLog(this.getClass(), e); errorHandler.log(L.WARN, this.getClass(), e);
} }
}); });
} }

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands; package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.data.WebUser; import com.djrapitops.plan.data.WebUser;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
@ -11,13 +10,16 @@ import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.utilities.PassEncryptUtil; import com.djrapitops.plan.utilities.PassEncryptUtil;
import com.djrapitops.plugin.api.Check; import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.CommandUtils; import com.djrapitops.plugin.command.CommandUtils;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
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 com.djrapitops.plugin.utilities.Verify;
import javax.inject.Inject;
import java.util.Arrays; import java.util.Arrays;
/** /**
@ -34,14 +36,20 @@ import java.util.Arrays;
public class RegisterCommand extends CommandNode { public class RegisterCommand extends CommandNode {
private final String notEnoughArgsMsg; private final String notEnoughArgsMsg;
private final String hashErrorMsg;
private final Locale locale; private final Locale locale;
private final PluginLogger logger;
private final Database database;
private final ErrorHandler errorHandler;
public RegisterCommand(PlanPlugin plugin) { @Inject
public RegisterCommand(Locale locale, PluginLogger logger, Database database, ErrorHandler errorHandler) {
// No Permission Requirement // No Permission Requirement
super("register", "", CommandType.PLAYER_OR_ARGS); super("register", "", CommandType.PLAYER_OR_ARGS);
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.locale = locale;
this.logger = logger;
this.database = database;
this.errorHandler = errorHandler;
setArguments("<password>", "[name]", "[lvl]"); setArguments("<password>", "[name]", "[lvl]");
setShortHelp(locale.getString(CmdHelpLang.WEB_REGISTER)); setShortHelp(locale.getString(CmdHelpLang.WEB_REGISTER));
@ -51,7 +59,6 @@ public class RegisterCommand extends CommandNode {
} }
notEnoughArgsMsg = locale.getString(CommandLang.FAIL_REQ_ARGS, 3, Arrays.toString(getArguments())); notEnoughArgsMsg = locale.getString(CommandLang.FAIL_REQ_ARGS, 3, Arrays.toString(getArguments()));
hashErrorMsg = "§cPassword hash error.";
} }
@Override @Override
@ -63,12 +70,12 @@ public class RegisterCommand extends CommandNode {
consoleRegister(args, sender, notEnoughArgsMsg); consoleRegister(args, sender, notEnoughArgsMsg);
} }
} catch (PassEncryptUtil.CannotPerformOperationException e) { } catch (PassEncryptUtil.CannotPerformOperationException e) {
Log.toLog(this.getClass().getSimpleName(), e); errorHandler.log(L.WARN, this.getClass(), e);
sender.sendMessage(hashErrorMsg); sender.sendMessage("§cPassword hash error.");
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new NumberFormatException(args[2]); throw new NumberFormatException(args[2]);
} catch (Exception e) { } catch (Exception e) {
Log.toLog(this.getClass().getSimpleName(), e); errorHandler.log(L.WARN, this.getClass(), e);
} }
} }
@ -115,7 +122,6 @@ public class RegisterCommand extends CommandNode {
Processing.submitCritical(() -> { Processing.submitCritical(() -> {
String userName = webUser.getName(); String userName = webUser.getName();
try { try {
Database database = Database.getActive();
boolean userExists = database.check().doesWebUserExists(userName); boolean userExists = database.check().doesWebUserExists(userName);
if (userExists) { if (userExists) {
sender.sendMessage(locale.getString(CommandLang.FAIL_WEB_USER_EXISTS)); sender.sendMessage(locale.getString(CommandLang.FAIL_WEB_USER_EXISTS));
@ -123,9 +129,9 @@ public class RegisterCommand extends CommandNode {
} }
database.save().webUser(webUser); database.save().webUser(webUser);
sender.sendMessage(locale.getString(CommandLang.WEB_USER_REGISTER_SUCCESS)); sender.sendMessage(locale.getString(CommandLang.WEB_USER_REGISTER_SUCCESS));
Log.info(locale.getString(CommandLang.WEB_USER_REGISTER_NOTIFY, userName, webUser.getPermLevel())); logger.info(locale.getString(CommandLang.WEB_USER_REGISTER_NOTIFY, userName, webUser.getPermLevel()));
} catch (Exception e) { } catch (Exception e) {
Log.toLog(this.getClass(), e); errorHandler.log(L.WARN, this.getClass(), e);
} }
}); });
} }

View File

@ -6,13 +6,16 @@ import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang; import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang; import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.task.AbsRunnable; import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory; import com.djrapitops.plugin.task.RunnableFactory;
import javax.inject.Inject;
/** /**
* This SubCommand is used to reload the plugin. * This SubCommand is used to reload the plugin.
* *
@ -23,12 +26,17 @@ public class ReloadCommand extends CommandNode {
private final PlanPlugin plugin; private final PlanPlugin plugin;
private final Locale locale; private final Locale locale;
private final ErrorHandler errorHandler;
private final RunnableFactory runnableFactory;
public ReloadCommand(PlanPlugin plugin) { @Inject
public ReloadCommand(PlanPlugin plugin, Locale locale, RunnableFactory runnableFactory, ErrorHandler errorHandler) {
super("reload", Permissions.RELOAD.getPermission(), CommandType.CONSOLE); super("reload", Permissions.RELOAD.getPermission(), CommandType.CONSOLE);
this.plugin = plugin;
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.plugin = plugin;
this.locale = locale;
this.runnableFactory = runnableFactory;
this.errorHandler = errorHandler;
setShortHelp(locale.getString(CmdHelpLang.RELOAD)); setShortHelp(locale.getString(CmdHelpLang.RELOAD));
setInDepthHelp(locale.getArray(DeepHelpLang.RELOAD)); setInDepthHelp(locale.getArray(DeepHelpLang.RELOAD));
@ -36,13 +44,13 @@ public class ReloadCommand extends CommandNode {
@Override @Override
public void onCommand(ISender sender, String commandLabel, String[] args) { public void onCommand(ISender sender, String commandLabel, String[] args) {
RunnableFactory.createNew("Reload task", new AbsRunnable() { runnableFactory.create("Reload task", new AbsRunnable() {
@Override @Override
public void run() { public void run() {
try { try {
plugin.reloadPlugin(true); plugin.reloadPlugin(true);
} catch (Exception e) { } catch (Exception e) {
Log.toLog(this.getClass(), e); errorHandler.log(L.CRITICAL, this.getClass(), e);
sender.sendMessage(locale.getString(CommandLang.RELOAD_FAILED)); sender.sendMessage(locale.getString(CommandLang.RELOAD_FAILED));
} }
sender.sendMessage(locale.getString(CommandLang.RELOAD_COMPLETE)); sender.sendMessage(locale.getString(CommandLang.RELOAD_COMPLETE));

View File

@ -1,7 +1,7 @@
package com.djrapitops.plan.command.commands; package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang; import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang; import com.djrapitops.plan.system.locale.lang.CommandLang;
@ -9,15 +9,16 @@ import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.locale.lang.ManageLang; import com.djrapitops.plan.system.locale.lang.ManageLang;
import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.utilities.FormatUtils; import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import javax.inject.Inject;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
@ -29,11 +30,16 @@ import java.util.List;
public class SearchCommand extends CommandNode { public class SearchCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final Database database;
private final ErrorHandler errorHandler;
public SearchCommand(PlanPlugin plugin) { @Inject
public SearchCommand(Locale locale, Database database, ErrorHandler errorHandler) {
super("search", Permissions.SEARCH.getPermission(), CommandType.PLAYER_OR_ARGS); super("search", Permissions.SEARCH.getPermission(), CommandType.PLAYER_OR_ARGS);
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.locale = locale;
this.database = database;
this.errorHandler = errorHandler;
setArguments("<text>"); setArguments("<text>");
setShortHelp(locale.getString(CmdHelpLang.SEARCH)); setShortHelp(locale.getString(CmdHelpLang.SEARCH));
@ -54,20 +60,21 @@ public class SearchCommand extends CommandNode {
Processing.submitNonCritical(() -> { Processing.submitNonCritical(() -> {
try { try {
String searchTerm = args[0]; String searchTerm = args[0];
List<String> names = MiscUtils.getMatchingPlayerNames(searchTerm); List<String> names = database.search().matchingPlayers(searchTerm);
Collections.sort(names);
boolean empty = Verify.isEmpty(names); boolean empty = Verify.isEmpty(names);
sender.sendMessage(locale.getString(CommandLang.HEADER_SEARCH, empty ? 0 : names.size(), searchTerm)); sender.sendMessage(locale.getString(CommandLang.HEADER_SEARCH, empty ? 0 : names.size(), searchTerm));
// Results // Results
if (!empty) { if (!empty) {
sender.sendMessage(FormatUtils.collectionToStringNoBrackets(names)); String message = names.toString();
sender.sendMessage(message.substring(1, message.length() - 1));
} }
sender.sendMessage(">"); sender.sendMessage(">");
} catch (DBOpException e) { } catch (DBOpException e) {
sender.sendMessage("§cDatabase error occurred: " + e.getMessage()); sender.sendMessage("§cDatabase error occurred: " + e.getMessage());
Log.toLog(this.getClass(), e); errorHandler.log(L.ERROR, this.getClass(), e);
} }
}); });
} }

View File

@ -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;
}
}
}

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands; package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.command.commands.webuser.WebCheckCommand; import com.djrapitops.plan.command.commands.webuser.WebCheckCommand;
import com.djrapitops.plan.command.commands.webuser.WebDeleteCommand; import com.djrapitops.plan.command.commands.webuser.WebDeleteCommand;
import com.djrapitops.plan.command.commands.webuser.WebLevelCommand; import com.djrapitops.plan.command.commands.webuser.WebLevelCommand;
@ -9,9 +8,14 @@ import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang; import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang; import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plugin.command.ColorScheme;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.TreeCmdNode; import com.djrapitops.plugin.command.TreeCmdNode;
import dagger.Lazy;
import javax.inject.Inject;
import javax.inject.Named;
/** /**
* Web subcommand used to manage Web users. * Web subcommand used to manage Web users.
@ -21,20 +25,25 @@ import com.djrapitops.plugin.command.TreeCmdNode;
*/ */
public class WebUserCommand extends TreeCmdNode { public class WebUserCommand extends TreeCmdNode {
public WebUserCommand(PlanPlugin plugin, RegisterCommand register, CommandNode parent) { @Inject
super("webuser|web", Permissions.MANAGE_WEB.getPerm(), CommandType.CONSOLE, parent); public WebUserCommand(ColorScheme colorScheme, Locale locale, @Named("mainCommand") Lazy<CommandNode> parent,
super.setColorScheme(plugin.getColorScheme()); RegisterCommand registerCommand,
WebLevelCommand levelCommand,
Locale locale = plugin.getSystem().getLocaleSystem().getLocale(); WebListUsersCommand listUsersCommand,
WebCheckCommand checkCommand,
WebDeleteCommand deleteCommand
) {
super("webuser|web", Permissions.MANAGE_WEB.getPerm(), CommandType.CONSOLE, parent.get());
super.setColorScheme(colorScheme);
setShortHelp(locale.getString(CmdHelpLang.WEB)); setShortHelp(locale.getString(CmdHelpLang.WEB));
setInDepthHelp(locale.getArray(DeepHelpLang.WEB)); setInDepthHelp(locale.getArray(DeepHelpLang.WEB));
CommandNode[] webGroup = { CommandNode[] webGroup = {
register, registerCommand,
new WebLevelCommand(plugin), levelCommand,
new WebListUsersCommand(plugin), listUsersCommand,
new WebCheckCommand(plugin), checkCommand,
new WebDeleteCommand(plugin) deleteCommand
}; };
setNodeGroups(webGroup); setNodeGroups(webGroup);
} }

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands.manage; package com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.database.DBException; import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.api.exceptions.database.DBInitException; import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.data.store.mutators.formatting.Formatters; import com.djrapitops.plan.data.store.mutators.formatting.Formatters;
@ -18,8 +17,11 @@ import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import javax.inject.Inject;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.UUID; import java.util.UUID;
@ -33,11 +35,16 @@ import java.util.UUID;
public class ManageBackupCommand extends CommandNode { public class ManageBackupCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final DBSystem dbSystem;
private final ErrorHandler errorHandler;
public ManageBackupCommand(PlanPlugin plugin) { @Inject
public ManageBackupCommand(Locale locale, DBSystem dbSystem, ErrorHandler errorHandler) {
super("backup", Permissions.MANAGE.getPermission(), CommandType.CONSOLE); super("backup", Permissions.MANAGE.getPermission(), CommandType.CONSOLE);
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.locale = locale;
this.dbSystem = dbSystem;
this.errorHandler = errorHandler;
setShortHelp(locale.getString(CmdHelpLang.MANAGE_BACKUP)); setShortHelp(locale.getString(CmdHelpLang.MANAGE_BACKUP));
setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE_BACKUP)); setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE_BACKUP));
@ -57,7 +64,7 @@ public class ManageBackupCommand extends CommandNode {
Verify.isTrue(isCorrectDB, Verify.isTrue(isCorrectDB,
() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_INCORRECT_DB, dbName))); () -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_INCORRECT_DB, dbName)));
Database database = DBSystem.getActiveDatabaseByName(dbName); Database database = dbSystem.getActiveDatabaseByName(dbName);
runBackupTask(sender, args, database); runBackupTask(sender, args, database);
} catch (DBInitException e) { } catch (DBInitException e) {
@ -73,7 +80,7 @@ public class ManageBackupCommand extends CommandNode {
createNewBackup(args[0], database); createNewBackup(args[0], database);
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS)); sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
} catch (Exception e) { } catch (Exception e) {
Log.toLog(ManageBackupCommand.class, e); errorHandler.log(L.ERROR, ManageBackupCommand.class, e);
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage())); sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
} }
}); });
@ -98,7 +105,7 @@ public class ManageBackupCommand extends CommandNode {
backupDB.init(); backupDB.init();
copyFromDB.backup().backup(backupDB); copyFromDB.backup().backup(backupDB);
} catch (DBException e) { } catch (DBException e) {
Log.toLog(this.getClass(), e); errorHandler.log(L.ERROR, this.getClass(), e);
} finally { } finally {
if (backupDB != null) { if (backupDB != null) {
backupDB.close(); backupDB.close();

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands.manage; package com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.database.DBInitException; import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.DBSystem;
@ -12,12 +11,14 @@ import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.locale.lang.ManageLang; import com.djrapitops.plan.system.locale.lang.ManageLang;
import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import javax.inject.Inject;
import java.util.Arrays; import java.util.Arrays;
/** /**
@ -29,11 +30,16 @@ import java.util.Arrays;
public class ManageClearCommand extends CommandNode { public class ManageClearCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final DBSystem dbSystem;
private final ErrorHandler errorHandler;
public ManageClearCommand(PlanPlugin plugin) { @Inject
public ManageClearCommand(Locale locale, DBSystem dbSystem, ErrorHandler errorHandler) {
super("clear", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS); super("clear", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.locale = locale;
this.dbSystem = dbSystem;
this.errorHandler = errorHandler;
setArguments("<DB>", "[-a]"); setArguments("<DB>", "[-a]");
setShortHelp(locale.getString(CmdHelpLang.MANAGE_CLEAR)); setShortHelp(locale.getString(CmdHelpLang.MANAGE_CLEAR));
@ -57,7 +63,7 @@ public class ManageClearCommand extends CommandNode {
} }
try { try {
Database database = DBSystem.getActiveDatabaseByName(dbName); Database database = dbSystem.getActiveDatabaseByName(dbName);
runClearTask(sender, database); runClearTask(sender, database);
} catch (DBInitException e) { } catch (DBInitException e) {
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage())); sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
@ -74,7 +80,7 @@ public class ManageClearCommand extends CommandNode {
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS)); sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
} catch (DBOpException e) { } catch (DBOpException e) {
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage())); sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
Log.toLog(this.getClass(), e); errorHandler.log(L.ERROR, this.getClass(), e);
} }
}); });
} }

View File

@ -1,9 +1,8 @@
package com.djrapitops.plan.command.commands.manage; package com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.connection.*; import com.djrapitops.plan.api.exceptions.connection.*;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.info.InfoSystem; import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.info.request.CheckConnectionRequest; import com.djrapitops.plan.system.info.request.CheckConnectionRequest;
import com.djrapitops.plan.system.info.server.Server; import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.info.server.ServerInfo;
@ -14,6 +13,7 @@ import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.locale.lang.ManageLang; import com.djrapitops.plan.system.locale.lang.ManageLang;
import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plan.system.webserver.WebServerSystem; import com.djrapitops.plan.system.webserver.WebServerSystem;
import com.djrapitops.plugin.api.Check; import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.command.ColorScheme; import com.djrapitops.plugin.command.ColorScheme;
@ -21,6 +21,7 @@ import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import javax.inject.Inject;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -33,17 +34,26 @@ import java.util.UUID;
public class ManageConDebugCommand extends CommandNode { public class ManageConDebugCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final ConnectionSystem connectionSystem;
private final WebServer webServer;
private final Database database;
private final ColorScheme colorScheme;
public ManageConDebugCommand(PlanPlugin plugin) { @Inject
public ManageConDebugCommand(ColorScheme colorScheme, Locale locale, ConnectionSystem connectionSystem, WebServer webServer, Database database) {
super("con", Permissions.MANAGE.getPermission(), CommandType.ALL); super("con", Permissions.MANAGE.getPermission(), CommandType.ALL);
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.colorScheme = colorScheme;
this.locale = locale;
this.connectionSystem = connectionSystem;
this.webServer = webServer;
this.database = database;
setShortHelp(locale.getString(Check.isBungeeAvailable() ? CmdHelpLang.CON : CmdHelpLang.MANAGE_CON)); setShortHelp(locale.getString(Check.isBungeeAvailable() ? CmdHelpLang.CON : CmdHelpLang.MANAGE_CON));
setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE_CON)); setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE_CON));
} }
public static boolean testServer(ISender sender, String accessAddress, Server server, Locale locale) { private void testServer(ISender sender, String accessAddress, Server server, Locale locale) {
String address = server.getWebAddress().toLowerCase(); String address = server.getWebAddress().toLowerCase();
boolean usingHttps = address.startsWith("https"); boolean usingHttps = address.startsWith("https");
boolean local = address.contains("localhost") boolean local = address.contains("localhost")
@ -52,11 +62,8 @@ public class ManageConDebugCommand extends CommandNode {
|| address.contains("127.0.0.1"); || address.contains("127.0.0.1");
try { try {
connectionSystem.sendInfoRequest(new CheckConnectionRequest(accessAddress), server);
InfoSystem.getInstance().getConnectionSystem().sendInfoRequest(new CheckConnectionRequest(accessAddress), server);
sender.sendMessage(getMsgFor(address, usingHttps, local, true, true)); sender.sendMessage(getMsgFor(address, usingHttps, local, true, true));
return true;
} catch (ForbiddenException | BadRequestException | InternalErrorException e) { } catch (ForbiddenException | BadRequestException | InternalErrorException e) {
sender.sendMessage(getMsgFor(address, usingHttps, local, false, false)); sender.sendMessage(getMsgFor(address, usingHttps, local, false, false));
sender.sendMessage(locale.getString(ManageLang.CON_EXCEPTION, e.getClass().getSimpleName())); sender.sendMessage(locale.getString(ManageLang.CON_EXCEPTION, e.getClass().getSimpleName()));
@ -78,7 +85,6 @@ public class ManageConDebugCommand extends CommandNode {
sender.sendMessage(getMsgFor(address, usingHttps, local, false, false)); sender.sendMessage(getMsgFor(address, usingHttps, local, false, false));
sender.sendMessage(locale.getString(ManageLang.CON_EXCEPTION, e.getClass().getSimpleName())); sender.sendMessage(locale.getString(ManageLang.CON_EXCEPTION, e.getClass().getSimpleName()));
} }
return false;
} }
@Override @Override
@ -92,14 +98,14 @@ public class ManageConDebugCommand extends CommandNode {
} }
private void testServers(ISender sender) { private void testServers(ISender sender) {
List<Server> servers = Database.getActive().fetch().getServers(); List<Server> servers = database.fetch().getServers();
if (servers.isEmpty()) { if (servers.isEmpty()) {
sender.sendMessage(locale.getString(ManageLang.CON_NO_SERVERS)); sender.sendMessage(locale.getString(ManageLang.CON_NO_SERVERS));
} }
String accessAddress = WebServerSystem.getInstance().getWebServer().getAccessAddress(); String accessAddress = webServer.getAccessAddress();
UUID thisServer = ServerInfo.getServerUUID(); UUID thisServer = ServerInfo.getServerUUID_Old();
for (Server server : servers) { for (Server server : servers) {
if (thisServer.equals(server.getUuid())) { if (thisServer.equals(server.getUuid())) {
continue; continue;
@ -108,10 +114,9 @@ public class ManageConDebugCommand extends CommandNode {
} }
} }
private static String getMsgFor(String address, boolean usingHttps, boolean local, boolean successTo, boolean successFrom) { private String getMsgFor(String address, boolean usingHttps, boolean local, boolean successTo, boolean successFrom) {
ColorScheme cs = PlanPlugin.getInstance().getColorScheme(); String tCol = colorScheme.getTertiaryColor();
String tCol = cs.getTertiaryColor(); String sCol = colorScheme.getSecondaryColor();
String sCol = cs.getSecondaryColor();
return tCol + address + sCol + ": " return tCol + address + sCol + ": "
+ (usingHttps ? "HTTPS" : "HTTP") + " : " + (usingHttps ? "HTTPS" : "HTTP") + " : "
+ (local ? "Local" : "External") + " : " + (local ? "Local" : "External") + " : "

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands.manage; package com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.listeners.bukkit.PlayerOnlineListener; import com.djrapitops.plan.system.listeners.bukkit.PlayerOnlineListener;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang; import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
@ -12,6 +11,7 @@ import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import javax.inject.Inject;
import java.util.Arrays; import java.util.Arrays;
/** /**
@ -24,10 +24,11 @@ public class ManageDisableCommand extends CommandNode {
private final Locale locale; private final Locale locale;
public ManageDisableCommand(PlanPlugin plugin) { @Inject
public ManageDisableCommand(Locale locale) {
super("disable", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS); super("disable", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.locale = locale;
setArguments("<feature>"); setArguments("<feature>");
setShortHelp(locale.getString(CmdHelpLang.MANAGE_DISABLE)); setShortHelp(locale.getString(CmdHelpLang.MANAGE_DISABLE));

View File

@ -9,12 +9,16 @@ import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.ManageLang; import com.djrapitops.plan.system.locale.lang.ManageLang;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plan.system.settings.config.PlanConfig;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import javax.inject.Inject;
import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
/** /**
@ -28,12 +32,19 @@ public class ManageHotSwapCommand extends CommandNode {
private final PlanPlugin plugin; private final PlanPlugin plugin;
private final Locale locale; private final Locale locale;
private final DBSystem dbSystem;
private final PlanConfig config;
private final ErrorHandler errorHandler;
public ManageHotSwapCommand(PlanPlugin plugin) { @Inject
public ManageHotSwapCommand(PlanPlugin plugin, Locale locale, DBSystem dbSystem, PlanConfig config, ErrorHandler errorHandler) {
super("hotswap", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS); super("hotswap", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
this.plugin = plugin;
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.plugin = plugin;
this.locale = locale;
this.dbSystem = dbSystem;
this.config = config;
this.errorHandler = errorHandler;
setArguments("<DB>"); setArguments("<DB>");
setShortHelp(locale.getString(CmdHelpLang.MANAGE_HOTSWAP)); setShortHelp(locale.getString(CmdHelpLang.MANAGE_HOTSWAP));
@ -50,24 +61,28 @@ public class ManageHotSwapCommand extends CommandNode {
Verify.isTrue(isCorrectDB, Verify.isTrue(isCorrectDB,
() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_INCORRECT_DB, dbName))); () -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_INCORRECT_DB, dbName)));
Verify.isFalse(dbName.equals(Database.getActive().getConfigName()), Verify.isFalse(dbName.equals(dbSystem.getActiveDatabase().getConfigName()),
() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_SAME_DB))); () -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_SAME_DB)));
try { try {
Database database = DBSystem.getActiveDatabaseByName(dbName); Database database = dbSystem.getActiveDatabaseByName(dbName);
if (!database.isOpen()) { if (!database.isOpen()) {
return; return;
} }
} catch (Exception e) { } catch (Exception e) {
Log.toLog(this.getClass(), e); errorHandler.log(L.ERROR, this.getClass(), e);
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage())); sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
return; return;
} }
Settings.DB_TYPE.set(dbName); try {
config.set(Settings.DB_TYPE, dbName);
Settings.save(); config.save();
} catch (IOException e) {
errorHandler.log(L.ERROR, this.getClass(), e);
return;
}
plugin.reloadPlugin(true); plugin.reloadPlugin(true);
} }
} }

View File

@ -1,21 +1,20 @@
package com.djrapitops.plan.command.commands.manage; package com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang; import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang; import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang; import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.locale.lang.ManageLang; import com.djrapitops.plan.system.locale.lang.ManageLang;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.processing.importing.ImporterManager; import com.djrapitops.plan.system.processing.importing.ImporterManager;
import com.djrapitops.plan.system.processing.importing.importers.Importer; import com.djrapitops.plan.system.processing.importing.importers.Importer;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import javax.inject.Inject;
import java.util.Arrays; import java.util.Arrays;
/** /**
@ -28,10 +27,11 @@ public class ManageImportCommand extends CommandNode {
private final Locale locale; private final Locale locale;
public ManageImportCommand(PlanPlugin plugin) { @Inject
public ManageImportCommand(Locale locale) {
super("import", Permissions.MANAGE.getPermission(), CommandType.CONSOLE); super("import", Permissions.MANAGE.getPermission(), CommandType.CONSOLE);
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.locale = locale;
setArguments("<plugin>/list", "[import args]"); setArguments("<plugin>/list", "[import args]");
setShortHelp(locale.getString(CmdHelpLang.MANAGE_IMPORT)); setShortHelp(locale.getString(CmdHelpLang.MANAGE_IMPORT));
@ -60,15 +60,6 @@ public class ManageImportCommand extends CommandNode {
return; return;
} }
RunnableFactory.createNew("Import:" + importArg, new AbsRunnable() { Processing.submitNonCritical(importer::processImport);
@Override
public void run() {
try {
importer.processImport();
} finally {
cancel();
}
}
}).runTaskAsynchronously();
} }
} }

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands.manage; package com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
@ -10,12 +9,14 @@ import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.locale.lang.ManageLang; import com.djrapitops.plan.system.locale.lang.ManageLang;
import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import javax.inject.Inject;
import java.util.Arrays; import java.util.Arrays;
/** /**
@ -29,11 +30,16 @@ import java.util.Arrays;
public class ManageMoveCommand extends CommandNode { public class ManageMoveCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final DBSystem dbSystem;
private final ErrorHandler errorHandler;
public ManageMoveCommand(PlanPlugin plugin) { @Inject
public ManageMoveCommand(Locale locale, DBSystem dbSystem, ErrorHandler errorHandler) {
super("move", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS); super("move", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.locale = locale;
this.dbSystem = dbSystem;
this.errorHandler = errorHandler;
setArguments("<fromDB>", "<toDB>", "[-a]"); setArguments("<fromDB>", "<toDB>", "[-a]");
setShortHelp(locale.getString(CmdHelpLang.MANAGE_MOVE)); setShortHelp(locale.getString(CmdHelpLang.MANAGE_MOVE));
@ -64,8 +70,8 @@ public class ManageMoveCommand extends CommandNode {
} }
try { try {
final Database fromDatabase = DBSystem.getActiveDatabaseByName(fromDB); final Database fromDatabase = dbSystem.getActiveDatabaseByName(fromDB);
final Database toDatabase = DBSystem.getActiveDatabaseByName(toDB); final Database toDatabase = dbSystem.getActiveDatabaseByName(toDB);
runMoveTask(fromDatabase, toDatabase, sender); runMoveTask(fromDatabase, toDatabase, sender);
} catch (Exception e) { } catch (Exception e) {
@ -82,12 +88,12 @@ public class ManageMoveCommand extends CommandNode {
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS)); sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
boolean movingToCurrentDB = toDatabase.getConfigName().equalsIgnoreCase(Database.getActive().getConfigName()); boolean movingToCurrentDB = toDatabase.getConfigName().equalsIgnoreCase(dbSystem.getActiveDatabase().getConfigName());
if (movingToCurrentDB) { if (movingToCurrentDB) {
sender.sendMessage(locale.getString(ManageLang.HOTSWAP_REMINDER, toDatabase.getConfigName())); sender.sendMessage(locale.getString(ManageLang.HOTSWAP_REMINDER, toDatabase.getConfigName()));
} }
} catch (Exception e) { } catch (Exception e) {
Log.toLog(this.getClass(), e); errorHandler.log(L.ERROR, this.getClass(), e);
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage())); sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
} }
}); });

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands.manage; package com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.info.connection.ConnectionSystem; import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang; import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
@ -14,6 +13,7 @@ import com.djrapitops.plugin.command.CommandUtils;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import javax.inject.Inject;
import java.util.Arrays; import java.util.Arrays;
/** /**
@ -25,11 +25,14 @@ import java.util.Arrays;
public class ManageRawDataCommand extends CommandNode { public class ManageRawDataCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final ConnectionSystem connectionSystem;
public ManageRawDataCommand(PlanPlugin plugin) { @Inject
public ManageRawDataCommand(Locale locale, ConnectionSystem connectionSystem) {
super("raw", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS); super("raw", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.locale = locale;
this.connectionSystem = connectionSystem;
setArguments("<player>"); setArguments("<player>");
setShortHelp(locale.getString(CmdHelpLang.MANAGE_RAW_DATA)); setShortHelp(locale.getString(CmdHelpLang.MANAGE_RAW_DATA));
@ -45,7 +48,7 @@ public class ManageRawDataCommand extends CommandNode {
sender.sendMessage(locale.getString(CommandLang.HEADER_INSPECT, playerName)); sender.sendMessage(locale.getString(CommandLang.HEADER_INSPECT, playerName));
// Link // Link
String url = ConnectionSystem.getInstance().getMainAddress() + "/player/" + playerName + "/raw"; String url = connectionSystem.getMainAddress() + "/player/" + playerName + "/raw";
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX); String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
boolean console = !CommandUtils.isPlayer(sender); boolean console = !CommandUtils.isPlayer(sender);
if (console) { if (console) {

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands.manage; package com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
@ -12,12 +11,14 @@ import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.utilities.MiscUtils; import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plan.utilities.uuid.UUIDUtility; import com.djrapitops.plan.utilities.uuid.UUIDUtility;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import javax.inject.Inject;
import java.util.Arrays; import java.util.Arrays;
import java.util.UUID; import java.util.UUID;
@ -30,11 +31,16 @@ import java.util.UUID;
public class ManageRemoveCommand extends CommandNode { public class ManageRemoveCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final Database database;
private final ErrorHandler errorHandler;
public ManageRemoveCommand(PlanPlugin plugin) { @Inject
public ManageRemoveCommand(Locale locale, Database database, ErrorHandler errorHandler) {
super("remove|delete", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS); super("remove|delete", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.locale = locale;
this.database = database;
this.errorHandler = errorHandler;
setArguments("<player>", "[-a]"); setArguments("<player>", "[-a]");
setShortHelp(locale.getString(CmdHelpLang.MANAGE_REMOVE)); setShortHelp(locale.getString(CmdHelpLang.MANAGE_REMOVE));
@ -66,7 +72,6 @@ public class ManageRemoveCommand extends CommandNode {
return; return;
} }
Database database = Database.getActive();
if (!database.check().isPlayerRegistered(uuid)) { if (!database.check().isPlayerRegistered(uuid)) {
sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_KNOWN)); sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_KNOWN));
return; return;
@ -83,7 +88,7 @@ public class ManageRemoveCommand extends CommandNode {
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS)); sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
} catch (DBOpException e) { } catch (DBOpException e) {
Log.toLog(this.getClass(), e); errorHandler.log(L.ERROR, this.getClass(), e);
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage())); sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
} }
}); });

View File

@ -1,9 +1,9 @@
package com.djrapitops.plan.command.commands.manage; package com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.database.databases.sql.SQLiteDB; import com.djrapitops.plan.system.database.databases.sql.SQLiteDB;
import com.djrapitops.plan.system.file.FileSystem;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang; import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang; import com.djrapitops.plan.system.locale.lang.CommandLang;
@ -11,12 +11,14 @@ import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.locale.lang.ManageLang; import com.djrapitops.plan.system.locale.lang.ManageLang;
import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import javax.inject.Inject;
import java.io.File; import java.io.File;
import java.util.Arrays; import java.util.Arrays;
@ -28,14 +30,19 @@ import java.util.Arrays;
*/ */
public class ManageRestoreCommand extends CommandNode { public class ManageRestoreCommand extends CommandNode {
private final PlanPlugin plugin;
private final Locale locale; private final Locale locale;
private final DBSystem dbSystem;
private final ErrorHandler errorHandler;
private final FileSystem fileSystem;
public ManageRestoreCommand(PlanPlugin plugin) { @Inject
public ManageRestoreCommand(Locale locale, DBSystem dbSystem, FileSystem fileSystem, ErrorHandler errorHandler) {
super("restore", Permissions.MANAGE.getPermission(), CommandType.CONSOLE); super("restore", Permissions.MANAGE.getPermission(), CommandType.CONSOLE);
this.plugin = plugin;
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.locale = locale;
this.dbSystem = dbSystem;
this.fileSystem = fileSystem;
this.errorHandler = errorHandler;
setArguments("<Filename.db>", "<dbTo>", "[-a]"); setArguments("<Filename.db>", "<dbTo>", "[-a]");
setShortHelp(locale.getString(CmdHelpLang.MANAGE_RESTORE)); setShortHelp(locale.getString(CmdHelpLang.MANAGE_RESTORE));
@ -55,7 +62,7 @@ public class ManageRestoreCommand extends CommandNode {
() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_INCORRECT_DB, dbName))); () -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_INCORRECT_DB, dbName)));
try { try {
Database database = DBSystem.getActiveDatabaseByName(dbName); Database database = dbSystem.getActiveDatabaseByName(dbName);
Verify.isFalse(backupDbName.contains("database") && database instanceof SQLiteDB, Verify.isFalse(backupDbName.contains("database") && database instanceof SQLiteDB,
() -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_SAME_DB))); () -> new IllegalArgumentException(locale.getString(ManageLang.FAIL_SAME_DB)));
@ -70,13 +77,13 @@ public class ManageRestoreCommand extends CommandNode {
} }
} }
private void runRestoreTask(String backupDbName, ISender sender, final Database database) { private void runRestoreTask(String backupDbName, ISender sender, Database database) {
Processing.submitCritical(() -> { Processing.submitCritical(() -> {
try { try {
String backupDBName = backupDbName; String backupDBName = backupDbName;
boolean containsDBFileExtension = backupDBName.endsWith(".db"); boolean containsDBFileExtension = backupDBName.endsWith(".db");
File backupDBFile = new File(plugin.getDataFolder(), backupDBName + (containsDBFileExtension ? "" : ".db")); File backupDBFile = fileSystem.getFileFromPluginFolder(backupDBName + (containsDBFileExtension ? "" : ".db"));
if (!backupDBFile.exists()) { if (!backupDBFile.exists()) {
sender.sendMessage(locale.getString(ManageLang.FAIL_FILE_NOT_FOUND, backupDBFile.getAbsolutePath())); sender.sendMessage(locale.getString(ManageLang.FAIL_FILE_NOT_FOUND, backupDBFile.getAbsolutePath()));
@ -96,7 +103,7 @@ public class ManageRestoreCommand extends CommandNode {
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS)); sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
} catch (Exception e) { } catch (Exception e) {
Log.toLog(this.getClass(), e); errorHandler.log(L.ERROR, this.getClass(), e);
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage())); sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
} }
}); });

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands.manage; package com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.connection.*; import com.djrapitops.plan.api.exceptions.connection.*;
import com.djrapitops.plan.system.info.InfoSystem; import com.djrapitops.plan.system.info.InfoSystem;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
@ -10,13 +9,16 @@ import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.webserver.WebServerSystem; import com.djrapitops.plan.system.settings.config.PlanConfig;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import javax.inject.Inject;
import java.util.Arrays; import java.util.Arrays;
/** /**
@ -28,11 +30,20 @@ import java.util.Arrays;
public class ManageSetupCommand extends CommandNode { public class ManageSetupCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final PlanConfig config;
private final InfoSystem infoSystem;
private final WebServer webServer;
private final ErrorHandler errorHandler;
public ManageSetupCommand(PlanPlugin plugin) { @Inject
public ManageSetupCommand(Locale locale, PlanConfig config, InfoSystem infoSystem, WebServer webServer, ErrorHandler errorHandler) {
super("setup", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS); super("setup", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.locale = locale;
this.config = config;
this.infoSystem = infoSystem;
this.webServer = webServer;
this.errorHandler = errorHandler;
setArguments("<BungeeAddress>"); setArguments("<BungeeAddress>");
setShortHelp(locale.getString(CmdHelpLang.MANAGE_SETUP)); setShortHelp(locale.getString(CmdHelpLang.MANAGE_SETUP));
@ -44,7 +55,7 @@ public class ManageSetupCommand extends CommandNode {
Verify.isTrue(args.length >= 1, Verify.isTrue(args.length >= 1,
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments())))); () -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
if (!WebServerSystem.isWebServerEnabled()) { if (!webServer.isEnabled()) {
sender.sendMessage(locale.getString(CommandLang.CONNECT_WEBSERVER_NOT_ENABLED)); sender.sendMessage(locale.getString(CommandLang.CONNECT_WEBSERVER_NOT_ENABLED));
return; return;
} }
@ -63,10 +74,10 @@ public class ManageSetupCommand extends CommandNode {
private void requestSetup(ISender sender, String address) { private void requestSetup(ISender sender, String address) {
Processing.submitNonCritical(() -> { Processing.submitNonCritical(() -> {
try { try {
Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.set(false); config.set(Settings.BUNGEE_OVERRIDE_STANDALONE_MODE, false);
Settings.BUNGEE_COPY_CONFIG.set(true); config.set(Settings.BUNGEE_COPY_CONFIG, true);
InfoSystem.getInstance().requestSetUp(address); infoSystem.requestSetUp(address);
sender.sendMessage(locale.getString(CommandLang.CONNECT_SUCCESS)); sender.sendMessage(locale.getString(CommandLang.CONNECT_SUCCESS));
} catch (ForbiddenException e) { } catch (ForbiddenException e) {
@ -82,7 +93,7 @@ public class ManageSetupCommand extends CommandNode {
} catch (GatewayException e) { } catch (GatewayException e) {
sender.sendMessage(locale.getString(CommandLang.CONNECT_GATEWAY)); sender.sendMessage(locale.getString(CommandLang.CONNECT_GATEWAY));
} catch (WebException e) { } catch (WebException e) {
Log.toLog(this.getClass(), e); errorHandler.log(L.WARN, this.getClass(), e);
sender.sendMessage(locale.getString(CommandLang.CONNECT_FAIL, e.toString())); sender.sendMessage(locale.getString(CommandLang.CONNECT_FAIL, e.toString()));
} }
}); });

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands.manage; package com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.info.connection.ConnectionSystem; import com.djrapitops.plan.system.info.connection.ConnectionSystem;
@ -12,11 +11,13 @@ import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.locale.lang.ManageLang; import com.djrapitops.plan.system.locale.lang.ManageLang;
import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import javax.inject.Inject;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
@ -30,11 +31,18 @@ import java.util.UUID;
public class ManageUninstalledCommand extends CommandNode { public class ManageUninstalledCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final Database database;
private final ErrorHandler errorHandler;
private final ConnectionSystem connectionSystem;
public ManageUninstalledCommand(PlanPlugin plugin) { @Inject
public ManageUninstalledCommand(Locale locale, Database database, ConnectionSystem connectionSystem, ErrorHandler errorHandler) {
super("uninstalled", Permissions.MANAGE.getPermission(), CommandType.ALL_WITH_ARGS); super("uninstalled", Permissions.MANAGE.getPermission(), CommandType.ALL_WITH_ARGS);
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.locale = locale;
this.database = database;
this.connectionSystem = connectionSystem;
this.errorHandler = errorHandler;
setShortHelp(locale.getString(CmdHelpLang.MANAGE_UNINSTALLED)); setShortHelp(locale.getString(CmdHelpLang.MANAGE_UNINSTALLED));
setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE_UNINSTALLED)); setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE_UNINSTALLED));
@ -54,23 +62,23 @@ public class ManageUninstalledCommand extends CommandNode {
} }
Server server = serverOptional.get(); Server server = serverOptional.get();
UUID serverUUID = server.getUuid(); UUID serverUUID = server.getUuid();
if (ServerInfo.getServerUUID().equals(serverUUID)) { if (ServerInfo.getServerUUID_Old().equals(serverUUID)) {
sender.sendMessage(locale.getString(ManageLang.UNINSTALLING_SAME_SERVER)); sender.sendMessage(locale.getString(ManageLang.UNINSTALLING_SAME_SERVER));
return; return;
} }
Database.getActive().save().setAsUninstalled(serverUUID); database.save().setAsUninstalled(serverUUID);
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS)); sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
} catch (DBOpException e) { } catch (DBOpException e) {
sender.sendMessage("§cError occurred: " + e.toString()); sender.sendMessage("§cError occurred: " + e.toString());
Log.toLog(this.getClass(), e); errorHandler.log(L.ERROR, this.getClass(), e);
} }
}); });
} }
private Optional<Server> getServer(String[] args) { private Optional<Server> getServer(String[] args) {
if (args.length >= 1 && ConnectionSystem.getInstance().isServerAvailable()) { if (args.length >= 1 && connectionSystem.isServerAvailable()) {
Map<UUID, Server> bukkitServers = Database.getActive().fetch().getBukkitServers(); Map<UUID, Server> bukkitServers = database.fetch().getBukkitServers();
String serverIdentifier = getGivenIdentifier(args); String serverIdentifier = getGivenIdentifier(args);
for (Map.Entry<UUID, Server> entry : bukkitServers.entrySet()) { for (Map.Entry<UUID, Server> entry : bukkitServers.entrySet()) {
Server server = entry.getValue(); Server server = entry.getValue();

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands.webuser; package com.djrapitops.plan.command.commands.webuser;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.data.WebUser; import com.djrapitops.plan.data.WebUser;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
@ -9,12 +8,14 @@ import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.ManageLang; import com.djrapitops.plan.system.locale.lang.ManageLang;
import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import javax.inject.Inject;
import java.util.Arrays; import java.util.Arrays;
/** /**
@ -26,11 +27,16 @@ import java.util.Arrays;
public class WebCheckCommand extends CommandNode { public class WebCheckCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final Database database;
private final ErrorHandler errorHandler;
public WebCheckCommand(PlanPlugin plugin) { @Inject
public WebCheckCommand(Locale locale, Database database, ErrorHandler errorHandler) {
super("check", Permissions.MANAGE_WEB.getPerm(), CommandType.PLAYER_OR_ARGS); super("check", Permissions.MANAGE_WEB.getPerm(), CommandType.PLAYER_OR_ARGS);
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.locale = locale;
this.database = database;
this.errorHandler = errorHandler;
setShortHelp(locale.getString(CmdHelpLang.WEB_CHECK)); setShortHelp(locale.getString(CmdHelpLang.WEB_CHECK));
setArguments("<username>"); setArguments("<username>");
@ -41,7 +47,6 @@ public class WebCheckCommand extends CommandNode {
Verify.isTrue(args.length >= 1, Verify.isTrue(args.length >= 1,
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments())))); () -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
Database database = Database.getActive();
String user = args[0]; String user = args[0];
Processing.submitNonCritical(() -> { Processing.submitNonCritical(() -> {
@ -53,7 +58,7 @@ public class WebCheckCommand extends CommandNode {
WebUser info = database.fetch().getWebUser(user); WebUser info = database.fetch().getWebUser(user);
sender.sendMessage(locale.getString(CommandLang.WEB_USER_LIST, info.getName(), info.getPermLevel())); sender.sendMessage(locale.getString(CommandLang.WEB_USER_LIST, info.getName(), info.getPermLevel()));
} catch (Exception e) { } catch (Exception e) {
Log.toLog(this.getClass(), e); errorHandler.log(L.ERROR, this.getClass(), e);
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage())); sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
} }
}); });

View File

@ -1,20 +1,20 @@
package com.djrapitops.plan.command.commands.webuser; package com.djrapitops.plan.command.commands.webuser;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang; import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang; import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.ManageLang; import com.djrapitops.plan.system.locale.lang.ManageLang;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.task.AbsRunnable; import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.task.RunnableFactory; import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import javax.inject.Inject;
import java.util.Arrays; import java.util.Arrays;
/** /**
@ -26,11 +26,16 @@ import java.util.Arrays;
public class WebDeleteCommand extends CommandNode { public class WebDeleteCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final Database database;
private final ErrorHandler errorHandler;
public WebDeleteCommand(PlanPlugin plugin) { @Inject
public WebDeleteCommand(Locale locale, Database database, ErrorHandler errorHandler) {
super("delete|remove", Permissions.MANAGE_WEB.getPerm(), CommandType.PLAYER_OR_ARGS); super("delete|remove", Permissions.MANAGE_WEB.getPerm(), CommandType.PLAYER_OR_ARGS);
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.locale = locale;
this.database = database;
this.errorHandler = errorHandler;
setShortHelp(locale.getString(CmdHelpLang.WEB_DELETE)); setShortHelp(locale.getString(CmdHelpLang.WEB_DELETE));
setArguments("<username>"); setArguments("<username>");
@ -41,27 +46,21 @@ public class WebDeleteCommand extends CommandNode {
Verify.isTrue(args.length >= 1, Verify.isTrue(args.length >= 1,
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments())))); () -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
Database database = Database.getActive();
String user = args[0]; String user = args[0];
RunnableFactory.createNew("Webuser Delete Task: " + user, new AbsRunnable() { Processing.submitNonCritical(() -> {
@Override try {
public void run() { if (!database.check().doesWebUserExists(user)) {
try { sender.sendMessage("§c[Plan] User Doesn't exist.");
if (!database.check().doesWebUserExists(user)) { return;
sender.sendMessage("§c[Plan] User Doesn't exist.");
return;
}
database.remove().webUser(user);
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
} catch (Exception e) {
Log.toLog(this.getClass(), e);
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
} finally {
this.cancel();
} }
database.remove().webUser(user);
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
} catch (Exception e) {
errorHandler.log(L.ERROR, this.getClass(), e);
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
} }
}).runTaskAsynchronously(); });
} }
} }

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands.webuser; package com.djrapitops.plan.command.commands.webuser;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang; import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang; import com.djrapitops.plan.system.locale.lang.CommandLang;
@ -9,6 +8,8 @@ import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import javax.inject.Inject;
/** /**
* Subcommand for info about permission levels. * Subcommand for info about permission levels.
* *
@ -19,10 +20,11 @@ public class WebLevelCommand extends CommandNode {
private final Locale locale; private final Locale locale;
public WebLevelCommand(PlanPlugin plugin) { @Inject
public WebLevelCommand(Locale locale) {
super("level", Permissions.MANAGE_WEB.getPerm(), CommandType.CONSOLE); super("level", Permissions.MANAGE_WEB.getPerm(), CommandType.CONSOLE);
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.locale = locale;
setShortHelp(locale.getString(CmdHelpLang.WEB_LEVEL)); setShortHelp(locale.getString(CmdHelpLang.WEB_LEVEL));
} }

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.command.commands.webuser; package com.djrapitops.plan.command.commands.webuser;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.data.WebUser; import com.djrapitops.plan.data.WebUser;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
@ -10,11 +9,13 @@ import com.djrapitops.plan.system.locale.lang.ManageLang;
import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.utilities.comparators.WebUserComparator; import com.djrapitops.plan.utilities.comparators.WebUserComparator;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import javax.inject.Inject;
import java.util.List; import java.util.List;
/** /**
@ -26,11 +27,16 @@ import java.util.List;
public class WebListUsersCommand extends CommandNode { public class WebListUsersCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final Database database;
private final ErrorHandler errorHandler;
public WebListUsersCommand(PlanPlugin plugin) { @Inject
public WebListUsersCommand(Locale locale, Database database, ErrorHandler errorHandler) {
super("list", Permissions.MANAGE_WEB.getPerm(), CommandType.CONSOLE); super("list", Permissions.MANAGE_WEB.getPerm(), CommandType.CONSOLE);
locale = plugin.getSystem().getLocaleSystem().getLocale(); this.locale = locale;
this.database = database;
this.errorHandler = errorHandler;
setShortHelp(locale.getString(CmdHelpLang.WEB_LIST)); setShortHelp(locale.getString(CmdHelpLang.WEB_LIST));
} }
@ -39,7 +45,7 @@ public class WebListUsersCommand extends CommandNode {
public void onCommand(ISender sender, String commandLabel, String[] args) { public void onCommand(ISender sender, String commandLabel, String[] args) {
Processing.submitNonCritical(() -> { Processing.submitNonCritical(() -> {
try { try {
List<WebUser> users = Database.getActive().fetch().getWebUsers(); List<WebUser> users = database.fetch().getWebUsers();
users.sort(new WebUserComparator()); users.sort(new WebUserComparator());
sender.sendMessage(locale.getString(CommandLang.HEADER_WEB_USERS, users.size())); sender.sendMessage(locale.getString(CommandLang.HEADER_WEB_USERS, users.size()));
for (WebUser user : users) { for (WebUser user : users) {
@ -47,7 +53,7 @@ public class WebListUsersCommand extends CommandNode {
} }
sender.sendMessage(">"); sender.sendMessage(">");
} catch (Exception e) { } catch (Exception e) {
Log.toLog(this.getClass(), e); errorHandler.log(L.ERROR, this.getClass(), e);
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage())); sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
} }
}); });

View File

@ -56,7 +56,7 @@ public class Session extends DataContainer implements DateHolder {
putSupplier(SessionKeys.LENGTH, () -> putSupplier(SessionKeys.LENGTH, () ->
getValue(SessionKeys.END).orElse(System.currentTimeMillis()) - getUnsafe(SessionKeys.START)); getValue(SessionKeys.END).orElse(System.currentTimeMillis()) - getUnsafe(SessionKeys.START));
putSupplier(SessionKeys.ACTIVE_TIME, () -> getUnsafe(SessionKeys.LENGTH) - getUnsafe(SessionKeys.AFK_TIME)); putSupplier(SessionKeys.ACTIVE_TIME, () -> getUnsafe(SessionKeys.LENGTH) - getUnsafe(SessionKeys.AFK_TIME));
putSupplier(SessionKeys.SERVER_UUID, ServerInfo::getServerUUID); putSupplier(SessionKeys.SERVER_UUID, ServerInfo::getServerUUID_Old);
putSupplier(SessionKeys.LONGEST_WORLD_PLAYED, this::getLongestWorldPlayed); putSupplier(SessionKeys.LONGEST_WORLD_PLAYED, this::getLongestWorldPlayed);
} }

View File

@ -105,7 +105,7 @@ public class AnalysisContainer extends DataContainer {
getUnsafe(serverNames).getOrDefault(serverContainer.getUnsafe(ServerKeys.SERVER_UUID), "Plan") getUnsafe(serverNames).getOrDefault(serverContainer.getUnsafe(ServerKeys.SERVER_UUID), "Plan")
); );
ServerProperties serverProperties = ServerInfo.getServerProperties(); ServerProperties serverProperties = ServerInfo.getServerProperties_Old();
putRawData(AnalysisKeys.PLAYERS_MAX, serverProperties.getMaxPlayers()); putRawData(AnalysisKeys.PLAYERS_MAX, serverProperties.getMaxPlayers());
putRawData(AnalysisKeys.PLAYERS_ONLINE, serverProperties.getOnlinePlayers()); putRawData(AnalysisKeys.PLAYERS_ONLINE, serverProperties.getOnlinePlayers());
} }

View File

@ -95,7 +95,7 @@ public class NetworkContainer extends DataContainer {
Settings.BUNGEE_NETWORK_NAME.toString() : Settings.BUNGEE_NETWORK_NAME.toString() :
bungeeContainer.getValue(ServerKeys.NAME).orElse("Plan") bungeeContainer.getValue(ServerKeys.NAME).orElse("Plan")
); );
putSupplier(NetworkKeys.PLAYERS_ONLINE, ServerInfo.getServerProperties()::getOnlinePlayers); putSupplier(NetworkKeys.PLAYERS_ONLINE, ServerInfo.getServerProperties_Old()::getOnlinePlayers);
putRawData(NetworkKeys.WORLD_MAP_LOW_COLOR, Theme.getValue(ThemeVal.WORLD_MAP_LOW)); putRawData(NetworkKeys.WORLD_MAP_LOW_COLOR, Theme.getValue(ThemeVal.WORLD_MAP_LOW));
putRawData(NetworkKeys.WORLD_MAP_HIGH_COLOR, Theme.getValue(ThemeVal.WORLD_MAP_HIGH)); putRawData(NetworkKeys.WORLD_MAP_HIGH_COLOR, Theme.getValue(ThemeVal.WORLD_MAP_HIGH));
putRawData(NetworkKeys.PLAYERS_GRAPH_COLOR, Theme.getValue(ThemeVal.GRAPH_PLAYERS_ONLINE)); putRawData(NetworkKeys.PLAYERS_GRAPH_COLOR, Theme.getValue(ThemeVal.GRAPH_PLAYERS_ONLINE));

View File

@ -24,7 +24,7 @@ public class MultiBanCombiner {
} }
public void combine(Set<UUID> banned) { public void combine(Set<UUID> banned) {
combine(Collections.singletonMap(ServerInfo.getServerUUID(), banned)); combine(Collections.singletonMap(ServerInfo.getServerUUID_Old(), banned));
} }
public void combine(Map<UUID, Set<UUID>> perServerBanned) { public void combine(Map<UUID, Set<UUID>> perServerBanned) {

View File

@ -1,7 +1,9 @@
package com.djrapitops.plan.modules; package com.djrapitops.plan.modules;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plugin.IPlugin; import com.djrapitops.plugin.IPlugin;
import com.djrapitops.plugin.benchmarking.Timings; import com.djrapitops.plugin.benchmarking.Timings;
import com.djrapitops.plugin.command.ColorScheme;
import com.djrapitops.plugin.logging.console.PluginLogger; import com.djrapitops.plugin.logging.console.PluginLogger;
import com.djrapitops.plugin.logging.debug.DebugLogger; import com.djrapitops.plugin.logging.debug.DebugLogger;
import com.djrapitops.plugin.logging.error.ErrorHandler; import com.djrapitops.plugin.logging.error.ErrorHandler;
@ -16,6 +18,15 @@ import dagger.Provides;
*/ */
@Module @Module
public class APFModule { public class APFModule {
@Provides
IPlugin provideIPlugin(PlanPlugin plugin) {
return plugin;
}
@Provides
ColorScheme provideColorScheme(PlanPlugin plugin) {
return plugin.getColorScheme();
}
@Provides @Provides
DebugLogger provideDebugLogger(IPlugin plugin) { DebugLogger provideDebugLogger(IPlugin plugin) {

View File

@ -0,0 +1,27 @@
package com.djrapitops.plan.modules.common;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plan.system.webserver.WebServerSystem;
import dagger.Module;
import dagger.Provides;
/**
* Dagger module for WebServerSystem.
*
* @author Rsl1122
*/
@Module
public class WebServerSystemModule {
@Provides
WebServerSystem provideWebServerSystem(Locale locale) {
return new WebServerSystem(() -> locale);
}
@Provides
WebServer provideWebServer(WebServerSystem webServerSystem) {
return webServerSystem.getWebServer();
}
}

View File

@ -1,21 +0,0 @@
package com.djrapitops.plan.modules.server;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.command.PlanCommand;
import dagger.Module;
import dagger.Provides;
/**
* Dagger module for Server Command /plan.
*
* @author Rsl1122
*/
@Module
public class ServerCommandModule {
@Provides
PlanCommand providePlanCommand(PlanPlugin plugin) {
return new PlanCommand(plugin);
}
}

View File

@ -1,9 +1,9 @@
package com.djrapitops.plan.modules.server.bukkit; package com.djrapitops.plan.modules.server;
import com.djrapitops.plan.system.settings.config.ConfigSystem; import com.djrapitops.plan.system.settings.config.ConfigSystem;
import com.djrapitops.plan.system.settings.config.PlanConfig;
import com.djrapitops.plan.system.settings.config.ServerConfigSystem; import com.djrapitops.plan.system.settings.config.ServerConfigSystem;
import com.djrapitops.plan.system.settings.theme.Theme; import com.djrapitops.plan.system.settings.theme.Theme;
import com.djrapitops.plugin.config.Config;
import dagger.Module; import dagger.Module;
import dagger.Provides; import dagger.Provides;
@ -13,7 +13,7 @@ import dagger.Provides;
* @author Rsl1122 * @author Rsl1122
*/ */
@Module @Module
public class BukkitConfigModule { public class ServerConfigModule {
@Provides @Provides
ConfigSystem provideConfigSystem() { ConfigSystem provideConfigSystem() {
@ -21,7 +21,7 @@ public class BukkitConfigModule {
} }
@Provides @Provides
Config provideConfig(ConfigSystem configSystem) { PlanConfig provideConfig(ConfigSystem configSystem) {
return configSystem.getConfig(); return configSystem.getConfig();
} }

View File

@ -0,0 +1,21 @@
package com.djrapitops.plan.modules.server;
import com.djrapitops.plan.system.cache.DataCache;
import com.djrapitops.plan.system.cache.SessionCache;
import dagger.Module;
import dagger.Provides;
/**
* Dagger module for Server CacheSystem.
*
* @author Rsl1122
*/
@Module
public class ServerDataCacheModule {
@Provides
SessionCache provideSessionCache(DataCache cache) {
return cache;
}
}

View File

@ -2,6 +2,7 @@ package com.djrapitops.plan.modules.server;
import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.database.ServerDBSystem; import com.djrapitops.plan.system.database.ServerDBSystem;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import dagger.Module; import dagger.Module;
import dagger.Provides; import dagger.Provides;
@ -19,4 +20,9 @@ public class ServerDatabaseModule {
return new ServerDBSystem(() -> locale); return new ServerDBSystem(() -> locale);
} }
@Provides
Database provideDatabase(DBSystem dbSystem) {
return dbSystem.getActiveDatabase();
}
} }

View File

@ -6,19 +6,18 @@ package com.djrapitops.plan.system;
import com.djrapitops.plan.Plan; import com.djrapitops.plan.Plan;
import com.djrapitops.plan.ShutdownHook; import com.djrapitops.plan.ShutdownHook;
import com.djrapitops.plan.api.ServerAPI; import com.djrapitops.plan.api.PlanAPI;
import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.data.plugin.HookHandler; import com.djrapitops.plan.data.plugin.HookHandler;
import com.djrapitops.plan.system.database.ServerDBSystem; import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.export.ExportSystem; import com.djrapitops.plan.system.export.ExportSystem;
import com.djrapitops.plan.system.file.FileSystem; import com.djrapitops.plan.system.file.FileSystem;
import com.djrapitops.plan.system.info.ServerInfoSystem; import com.djrapitops.plan.system.info.InfoSystem;
import com.djrapitops.plan.system.info.connection.ServerConnectionSystem;
import com.djrapitops.plan.system.info.server.BukkitServerInfo; import com.djrapitops.plan.system.info.server.BukkitServerInfo;
import com.djrapitops.plan.system.listeners.BukkitListenerSystem; import com.djrapitops.plan.system.listeners.BukkitListenerSystem;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.settings.PlanErrorManager; import com.djrapitops.plan.system.settings.PlanErrorManager;
import com.djrapitops.plan.system.settings.config.ServerConfigSystem; import com.djrapitops.plan.system.settings.config.ConfigSystem;
import com.djrapitops.plan.system.settings.network.NetworkSettings; import com.djrapitops.plan.system.settings.network.NetworkSettings;
import com.djrapitops.plan.system.tasks.BukkitTaskSystem; import com.djrapitops.plan.system.tasks.BukkitTaskSystem;
import com.djrapitops.plan.system.update.VersionCheckSystem; import com.djrapitops.plan.system.update.VersionCheckSystem;
@ -36,26 +35,35 @@ import java.util.function.Supplier;
public class BukkitSystem extends PlanSystem implements ServerSystem { public class BukkitSystem extends PlanSystem implements ServerSystem {
@Inject @Inject
public BukkitSystem(Plan plugin) { public BukkitSystem(Plan plugin,
VersionCheckSystem versionCheckSystem,
FileSystem fileSystem,
ConfigSystem serverConfigSystem,
InfoSystem serverInfoSystem,
HookHandler hookHandler,
PlanAPI planAPI,
ExportSystem exportSystem,
DBSystem serverDBSystem
) {
setTestSystem(this); setTestSystem(this);
Log.setErrorManager(new PlanErrorManager()); Log.setErrorManager(new PlanErrorManager());
Supplier<Locale> localeSupplier = () -> getLocaleSystem().getLocale(); Supplier<Locale> localeSupplier = () -> getLocaleSystem().getLocale();
versionCheckSystem = new VersionCheckSystem(plugin.getVersion(), localeSupplier); this.versionCheckSystem = versionCheckSystem;
fileSystem = new FileSystem(plugin); this.fileSystem = fileSystem;
configSystem = new ServerConfigSystem(); this.configSystem = serverConfigSystem;
exportSystem = new ExportSystem(plugin); this.exportSystem = exportSystem;
databaseSystem = new ServerDBSystem(localeSupplier); this.databaseSystem = serverDBSystem;
listenerSystem = new BukkitListenerSystem(plugin); listenerSystem = new BukkitListenerSystem(plugin);
taskSystem = new BukkitTaskSystem(plugin); taskSystem = new BukkitTaskSystem(plugin);
infoSystem = new ServerInfoSystem(new ServerConnectionSystem(localeSupplier)); infoSystem = serverInfoSystem;
serverInfo = new BukkitServerInfo(plugin); serverInfo = new BukkitServerInfo(plugin);
hookHandler = new HookHandler(); this.hookHandler = hookHandler;
planAPI = new ServerAPI(hookHandler, databaseSystem.getActiveDatabase(), cacheSystem.getDataCache()); this.planAPI = planAPI;
StaticHolder.saveInstance(ShutdownHook.class, plugin.getClass()); StaticHolder.saveInstance(ShutdownHook.class, plugin.getClass());
new ShutdownHook().register(); new ShutdownHook().register();

View File

@ -24,6 +24,7 @@ import com.djrapitops.plan.system.tasks.BungeeTaskSystem;
import com.djrapitops.plan.system.update.VersionCheckSystem; import com.djrapitops.plan.system.update.VersionCheckSystem;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
import javax.inject.Inject;
import java.util.function.Supplier; import java.util.function.Supplier;
/** /**
@ -33,26 +34,32 @@ import java.util.function.Supplier;
*/ */
public class BungeeSystem extends PlanSystem { public class BungeeSystem extends PlanSystem {
public BungeeSystem(PlanBungee plugin) { @Inject
public BungeeSystem(PlanBungee plugin,
VersionCheckSystem versionCheckSystem,
FileSystem fileSystem,
BungeeCacheSystem bungeeCacheSystem,
HookHandler hookHandler
) {
setTestSystem(this); setTestSystem(this);
Log.setErrorManager(new PlanErrorManager()); Log.setErrorManager(new PlanErrorManager());
Supplier<Locale> localeSupplier = () -> getLocaleSystem().getLocale(); Supplier<Locale> localeSupplier = () -> getLocaleSystem().getLocale();
versionCheckSystem = new VersionCheckSystem(plugin.getVersion(), localeSupplier); this.versionCheckSystem = versionCheckSystem;
fileSystem = new FileSystem(plugin); this.fileSystem = fileSystem;
configSystem = new BungeeConfigSystem(); configSystem = new BungeeConfigSystem();
exportSystem = new ExportSystem(plugin); exportSystem = new ExportSystem(plugin);
databaseSystem = new BungeeDBSystem(localeSupplier); databaseSystem = new BungeeDBSystem(localeSupplier);
cacheSystem = new BungeeCacheSystem(this); cacheSystem = bungeeCacheSystem;
listenerSystem = new BungeeListenerSystem(plugin); listenerSystem = new BungeeListenerSystem(plugin);
taskSystem = new BungeeTaskSystem(plugin.getRunnableFactory()); taskSystem = new BungeeTaskSystem(plugin.getRunnableFactory());
infoSystem = new BungeeInfoSystem(); infoSystem = new BungeeInfoSystem();
serverInfo = new BungeeServerInfo(plugin); serverInfo = new BungeeServerInfo(plugin);
hookHandler = new HookHandler(); this.hookHandler = hookHandler;
planAPI = new BungeeAPI(this); planAPI = new BungeeAPI(this);
} }

View File

@ -67,7 +67,6 @@ public abstract class PlanSystem implements SubSystem {
processing = new Processing(localeSupplier); processing = new Processing(localeSupplier);
webServerSystem = new WebServerSystem(localeSupplier); webServerSystem = new WebServerSystem(localeSupplier);
localeSystem = new LocaleSystem(); localeSystem = new LocaleSystem();
cacheSystem = new CacheSystem(this);
} }
public static PlanSystem getInstance() { public static PlanSystem getInstance() {

View File

@ -6,24 +6,23 @@ package com.djrapitops.plan.system;
import com.djrapitops.plan.PlanSponge; import com.djrapitops.plan.PlanSponge;
import com.djrapitops.plan.ShutdownHook; import com.djrapitops.plan.ShutdownHook;
import com.djrapitops.plan.api.ServerAPI; import com.djrapitops.plan.api.PlanAPI;
import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.data.plugin.HookHandler; import com.djrapitops.plan.data.plugin.HookHandler;
import com.djrapitops.plan.system.database.ServerDBSystem; import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.export.ExportSystem; import com.djrapitops.plan.system.export.ExportSystem;
import com.djrapitops.plan.system.file.FileSystem; import com.djrapitops.plan.system.file.FileSystem;
import com.djrapitops.plan.system.info.ServerInfoSystem; import com.djrapitops.plan.system.info.InfoSystem;
import com.djrapitops.plan.system.info.server.SpongeServerInfo; import com.djrapitops.plan.system.info.server.SpongeServerInfo;
import com.djrapitops.plan.system.listeners.SpongeListenerSystem; import com.djrapitops.plan.system.listeners.SpongeListenerSystem;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.settings.PlanErrorManager; import com.djrapitops.plan.system.settings.config.ConfigSystem;
import com.djrapitops.plan.system.settings.config.SpongeConfigSystem;
import com.djrapitops.plan.system.settings.network.NetworkSettings; import com.djrapitops.plan.system.settings.network.NetworkSettings;
import com.djrapitops.plan.system.tasks.SpongeTaskSystem; import com.djrapitops.plan.system.tasks.SpongeTaskSystem;
import com.djrapitops.plan.system.update.VersionCheckSystem; import com.djrapitops.plan.system.update.VersionCheckSystem;
import com.djrapitops.plugin.StaticHolder; import com.djrapitops.plugin.StaticHolder;
import com.djrapitops.plugin.api.utility.log.Log;
import javax.inject.Inject;
import java.util.function.Supplier; import java.util.function.Supplier;
/** /**
@ -33,26 +32,34 @@ import java.util.function.Supplier;
*/ */
public class SpongeSystem extends PlanSystem implements ServerSystem { public class SpongeSystem extends PlanSystem implements ServerSystem {
public SpongeSystem(PlanSponge plugin) { @Inject
public SpongeSystem(PlanSponge plugin,
VersionCheckSystem versionCheckSystem,
FileSystem fileSystem,
ConfigSystem serverConfigSystem,
InfoSystem serverInfoSystem,
HookHandler hookHandler,
PlanAPI planAPI,
ExportSystem exportSystem,
DBSystem serverDBSystem
) {
setTestSystem(this); setTestSystem(this);
Supplier<Locale> localeSupplier = () -> getLocaleSystem().getLocale(); Supplier<Locale> localeSupplier = () -> getLocaleSystem().getLocale();
Log.setErrorManager(new PlanErrorManager()); this.versionCheckSystem = versionCheckSystem;
this.fileSystem = fileSystem;
versionCheckSystem = new VersionCheckSystem(plugin.getVersion(), localeSupplier); this.configSystem = serverConfigSystem;
fileSystem = new FileSystem(plugin); this.exportSystem = exportSystem;
configSystem = new SpongeConfigSystem(); this.databaseSystem = serverDBSystem;
exportSystem = new ExportSystem(plugin);
databaseSystem = new ServerDBSystem(localeSupplier);
listenerSystem = new SpongeListenerSystem(plugin); listenerSystem = new SpongeListenerSystem(plugin);
taskSystem = new SpongeTaskSystem(plugin); taskSystem = new SpongeTaskSystem(plugin);
infoSystem = new ServerInfoSystem(localeSupplier); infoSystem = serverInfoSystem;
serverInfo = new SpongeServerInfo(); serverInfo = new SpongeServerInfo();
hookHandler = new HookHandler(); this.hookHandler = hookHandler;
planAPI = new ServerAPI(this); this.planAPI = planAPI;
StaticHolder.saveInstance(ShutdownHook.class, plugin.getClass()); StaticHolder.saveInstance(ShutdownHook.class, plugin.getClass());
new ShutdownHook().register(); new ShutdownHook().register();

View File

@ -1,6 +1,6 @@
package com.djrapitops.plan.system.cache; package com.djrapitops.plan.system.cache;
import com.djrapitops.plan.system.PlanSystem; import javax.inject.Inject;
/** /**
* CacheSystem for Bungee. * CacheSystem for Bungee.
@ -11,8 +11,9 @@ import com.djrapitops.plan.system.PlanSystem;
*/ */
public class BungeeCacheSystem extends CacheSystem { public class BungeeCacheSystem extends CacheSystem {
public BungeeCacheSystem(PlanSystem system) { @Inject
super(new BungeeDataCache(system), system); public BungeeCacheSystem(BungeeDataCache dataCache, GeolocationCache geolocationCache) {
super(dataCache, geolocationCache);
} }
} }

View File

@ -1,7 +1,8 @@
package com.djrapitops.plan.system.cache; package com.djrapitops.plan.system.cache;
import com.djrapitops.plan.system.PlanSystem; import com.djrapitops.plan.system.database.databases.Database;
import javax.inject.Inject;
import java.util.UUID; import java.util.UUID;
/** /**
@ -13,8 +14,9 @@ import java.util.UUID;
*/ */
public class BungeeDataCache extends DataCache { public class BungeeDataCache extends DataCache {
public BungeeDataCache(PlanSystem system) { @Inject
super(system); public BungeeDataCache(Database database) {
super(database);
} }
@Override @Override

View File

@ -9,6 +9,8 @@ import com.djrapitops.plan.system.PlanSystem;
import com.djrapitops.plan.system.SubSystem; import com.djrapitops.plan.system.SubSystem;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import javax.inject.Inject;
/** /**
* System that holds data caches of the plugin. * System that holds data caches of the plugin.
* *
@ -19,13 +21,10 @@ public class CacheSystem implements SubSystem {
private final DataCache dataCache; private final DataCache dataCache;
private final GeolocationCache geolocationCache; private final GeolocationCache geolocationCache;
public CacheSystem(PlanSystem system) { @Inject
this(new DataCache(system), system); public CacheSystem(DataCache dataCache, GeolocationCache geolocationCache) {
}
protected CacheSystem(DataCache dataCache, PlanSystem system) {
this.dataCache = dataCache; this.dataCache = dataCache;
geolocationCache = new GeolocationCache(() -> system.getLocaleSystem().getLocale()); this.geolocationCache = geolocationCache;
} }
public static CacheSystem getInstance() { public static CacheSystem getInstance() {

View File

@ -1,12 +1,12 @@
package com.djrapitops.plan.system.cache; package com.djrapitops.plan.system.cache;
import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.system.PlanSystem;
import com.djrapitops.plan.system.SubSystem; import com.djrapitops.plan.system.SubSystem;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import javax.inject.Inject;
import java.util.*; import java.util.*;
/** /**
@ -24,22 +24,22 @@ import java.util.*;
*/ */
public class DataCache extends SessionCache implements SubSystem { public class DataCache extends SessionCache implements SubSystem {
private Database db; private Database database;
private final Map<UUID, String> playerNames; private final Map<UUID, String> playerNames;
private final Map<String, UUID> uuids; private final Map<String, UUID> uuids;
private final Map<UUID, String> displayNames; private final Map<UUID, String> displayNames;
public DataCache(PlanSystem system) { @Inject
super(system); public DataCache(Database database) {
playerNames = new HashMap<>(); playerNames = new HashMap<>();
displayNames = new HashMap<>(); displayNames = new HashMap<>();
uuids = new HashMap<>(); uuids = new HashMap<>();
this.database = database;
} }
@Override @Override
public void enable() { public void enable() {
db = system.getDatabaseSystem().getActiveDatabase();
} }
@Override @Override
@ -87,7 +87,7 @@ public class DataCache extends SessionCache implements SubSystem {
String name = playerNames.get(uuid); String name = playerNames.get(uuid);
if (name == null) { if (name == null) {
try { try {
name = db.fetch().getPlayerName(uuid); name = database.fetch().getPlayerName(uuid);
playerNames.put(uuid, name); playerNames.put(uuid, name);
} catch (DBOpException e) { } catch (DBOpException e) {
Log.toLog(this.getClass(), e); Log.toLog(this.getClass(), e);
@ -110,7 +110,7 @@ public class DataCache extends SessionCache implements SubSystem {
if (cached == null) { if (cached == null) {
List<String> nicknames; List<String> nicknames;
try { try {
nicknames = db.fetch().getNicknames(uuid); nicknames = database.fetch().getNicknames(uuid);
if (!nicknames.isEmpty()) { if (!nicknames.isEmpty()) {
return nicknames.get(nicknames.size() - 1); return nicknames.get(nicknames.size() - 1);
} }

View File

@ -13,6 +13,7 @@ import com.maxmind.geoip2.exception.GeoIp2Exception;
import com.maxmind.geoip2.model.CountryResponse; import com.maxmind.geoip2.model.CountryResponse;
import com.maxmind.geoip2.record.Country; import com.maxmind.geoip2.record.Country;
import javax.inject.Inject;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -23,7 +24,6 @@ import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel; import java.nio.channels.ReadableByteChannel;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.function.Supplier;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
/** /**
@ -36,28 +36,29 @@ import java.util.zip.GZIPInputStream;
*/ */
public class GeolocationCache implements SubSystem { public class GeolocationCache implements SubSystem {
private final Supplier<Locale> locale; private final Locale locale;
private final Map<String, String> cached; private final Map<String, String> cached;
private File geolocationDB; private File geolocationDB;
public GeolocationCache(Supplier<Locale> locale) { @Inject
public GeolocationCache(Locale locale) {
this.locale = locale; this.locale = locale;
cached = new HashMap<>(); cached = new HashMap<>();
} }
@Override @Override
public void enable() throws EnableException { public void enable() throws EnableException {
geolocationDB = new File(FileSystem.getDataFolder(), "GeoIP.dat"); geolocationDB = new File(FileSystem.getDataFolder_Old(), "GeoIP.dat");
if (Settings.DATA_GEOLOCATIONS.isTrue()) { if (Settings.DATA_GEOLOCATIONS.isTrue()) {
try { try {
GeolocationCache.checkDB(); GeolocationCache.checkDB();
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
Log.error(locale.get().getString(PluginLang.ENABLE_NOTIFY_GEOLOCATIONS_INTERNET_REQUIRED)); Log.error(locale.getString(PluginLang.ENABLE_NOTIFY_GEOLOCATIONS_INTERNET_REQUIRED));
} catch (IOException e) { } catch (IOException e) {
throw new EnableException(locale.get().getString(PluginLang.ENABLE_FAIL_GEODB_WRITE), e); throw new EnableException(locale.getString(PluginLang.ENABLE_FAIL_GEODB_WRITE), e);
} }
} else { } else {
Log.infoColor("§e" + locale.get().getString(PluginLang.ENABLE_NOTIFY_GEOLOCATIONS_DISABLED)); Log.infoColor("§e" + locale.getString(PluginLang.ENABLE_NOTIFY_GEOLOCATIONS_DISABLED));
} }
} }

View File

@ -3,7 +3,6 @@ package com.djrapitops.plan.system.cache;
import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.data.store.keys.SessionKeys; import com.djrapitops.plan.data.store.keys.SessionKeys;
import com.djrapitops.plan.system.PlanSystem;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
@ -22,11 +21,6 @@ import java.util.UUID;
public class SessionCache { public class SessionCache {
private static final Map<UUID, Session> activeSessions = new HashMap<>(); private static final Map<UUID, Session> activeSessions = new HashMap<>();
protected final PlanSystem system;
public SessionCache(PlanSystem system) {
this.system = system;
}
public static SessionCache getInstance() { public static SessionCache getInstance() {
SessionCache dataCache = CacheSystem.getInstance().getDataCache(); SessionCache dataCache = CacheSystem.getInstance().getDataCache();

View File

@ -37,22 +37,27 @@ public abstract class DBSystem implements SubSystem {
databases = new HashSet<>(); databases = new HashSet<>();
} }
@Deprecated
public static DBSystem getInstance() { public static DBSystem getInstance() {
DBSystem dbSystem = PlanSystem.getInstance().getDatabaseSystem(); DBSystem dbSystem = PlanSystem.getInstance().getDatabaseSystem();
Verify.nullCheck(dbSystem, () -> new IllegalStateException("Database system was not initialized.")); Verify.nullCheck(dbSystem, () -> new IllegalStateException("Database system was not initialized."));
return dbSystem; return dbSystem;
} }
public static Database getActiveDatabaseByName(String dbName) throws DBInitException { @Deprecated
DBSystem system = getInstance(); public static Database getActiveDatabaseByName_Old(String dbName) throws DBInitException {
for (Database database : system.getDatabases()) { return getInstance().getActiveDatabaseByName(dbName);
}
public Database getActiveDatabaseByName(String dbName) throws DBInitException {
for (Database database : getDatabases()) {
String dbConfigName = database.getConfigName(); String dbConfigName = database.getConfigName();
if (Verify.equalsIgnoreCase(dbName, dbConfigName)) { if (Verify.equalsIgnoreCase(dbName, dbConfigName)) {
database.init(); database.init();
return database; return database;
} }
} }
throw new DBInitException(system.locale.get().getString(PluginLang.ENABLE_FAIL_WRONG_DB, dbName)); throw new DBInitException(locale.get().getString(PluginLang.ENABLE_FAIL_WRONG_DB, dbName));
} }
protected abstract void initDatabase() throws DBInitException; protected abstract void initDatabase() throws DBInitException;

View File

@ -31,6 +31,6 @@ public class ServerDBSystem extends DBSystem {
databases.add(new SQLiteDB(locale)); databases.add(new SQLiteDB(locale));
String dbType = Settings.DB_TYPE.toString().toLowerCase().trim(); String dbType = Settings.DB_TYPE.toString().toLowerCase().trim();
db = getActiveDatabaseByName(dbType); db = getActiveDatabaseByName_Old(dbType);
} }
} }

View File

@ -18,6 +18,7 @@ public abstract class Database {
protected boolean open = false; protected boolean open = false;
@Deprecated
public static Database getActive() { public static Database getActive() {
Database database = DBSystem.getInstance().getActiveDatabase(); Database database = DBSystem.getInstance().getActiveDatabase();
Verify.nullCheck(database, () -> new IllegalStateException("Database was not initialized.")); Verify.nullCheck(database, () -> new IllegalStateException("Database was not initialized."));

View File

@ -13,7 +13,7 @@ public interface CheckOperations {
boolean doesWebUserExists(String username); boolean doesWebUserExists(String username);
default boolean isPlayerRegisteredOnThisServer(UUID player) { default boolean isPlayerRegisteredOnThisServer(UUID player) {
return isPlayerRegistered(player, ServerInfo.getServerUUID()); return isPlayerRegistered(player, ServerInfo.getServerUUID_Old());
} }
boolean isServerInDatabase(UUID serverUUID); boolean isServerInDatabase(UUID serverUUID);

View File

@ -29,7 +29,7 @@ public class SQLCheckOps extends SQLOps implements CheckOperations {
@Override @Override
public boolean isPlayerRegisteredOnThisServer(UUID player) { public boolean isPlayerRegisteredOnThisServer(UUID player) {
return isPlayerRegistered(player, ServerInfo.getServerUUID()); return isPlayerRegistered(player, ServerInfo.getServerUUID_Old());
} }
@Override @Override

View File

@ -25,7 +25,7 @@ public class Version10Patch extends Patch {
@Override @Override
public void apply() { public void apply() {
try { try {
Optional<Integer> fetchedServerID = db.getServerTable().getServerID(ServerInfo.getServerUUID()); Optional<Integer> fetchedServerID = db.getServerTable().getServerID(ServerInfo.getServerUUID_Old());
if (!fetchedServerID.isPresent()) { if (!fetchedServerID.isPresent()) {
throw new IllegalStateException("Server UUID was not registered, try rebooting the plugin."); throw new IllegalStateException("Server UUID was not registered, try rebooting the plugin.");
} }

View File

@ -94,7 +94,7 @@ public class CommandUseTable extends Table {
* @return command - times used Map * @return command - times used Map
*/ */
public Map<String, Integer> getCommandUse() { public Map<String, Integer> getCommandUse() {
return getCommandUse(ServerInfo.getServerUUID()); return getCommandUse(ServerInfo.getServerUUID_Old());
} }
public void commandUsed(String command) { public void commandUsed(String command) {
@ -110,7 +110,7 @@ public class CommandUseTable extends Table {
boolean updated = execute(new ExecStatement(sql) { boolean updated = execute(new ExecStatement(sql) {
@Override @Override
public void prepare(PreparedStatement statement) throws SQLException { public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, ServerInfo.getServerUUID().toString()); statement.setString(1, ServerInfo.getServerUUID_Old().toString());
statement.setString(2, command); statement.setString(2, command);
} }
}); });
@ -144,7 +144,7 @@ public class CommandUseTable extends Table {
public void prepare(PreparedStatement statement) throws SQLException { public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, command); statement.setString(1, command);
statement.setInt(2, 1); statement.setInt(2, 1);
statement.setString(3, ServerInfo.getServerUUID().toString()); statement.setString(3, ServerInfo.getServerUUID_Old().toString());
} }
}); });
} }

View File

@ -179,7 +179,7 @@ public class KillsTable extends UserIDTable {
statement.setString(1, uuid.toString()); statement.setString(1, uuid.toString());
statement.setString(2, victim.toString()); statement.setString(2, victim.toString());
statement.setString(3, ServerInfo.getServerUUID().toString()); statement.setString(3, ServerInfo.getServerUUID_Old().toString());
statement.setInt(4, sessionID); statement.setInt(4, sessionID);
statement.setLong(5, date); statement.setLong(5, date);
statement.setString(6, weapon); statement.setString(6, weapon);

View File

@ -111,7 +111,7 @@ public class NicknamesTable extends UserIDTable {
* @return The nicknames of the User * @return The nicknames of the User
*/ */
public List<String> getNicknames(UUID uuid) { public List<String> getNicknames(UUID uuid) {
return getNicknames(uuid, ServerInfo.getServerUUID()); return getNicknames(uuid, ServerInfo.getServerUUID_Old());
} }
public Map<UUID, Map<UUID, List<Nickname>>> getAllNicknames() { public Map<UUID, Map<UUID, List<Nickname>>> getAllNicknames() {
@ -167,7 +167,7 @@ public class NicknamesTable extends UserIDTable {
statement.setLong(1, name.getDate()); statement.setLong(1, name.getDate());
statement.setString(2, name.getName()); statement.setString(2, name.getName());
statement.setString(3, uuid.toString()); statement.setString(3, uuid.toString());
statement.setString(4, ServerInfo.getServerUUID().toString()); statement.setString(4, ServerInfo.getServerUUID_Old().toString());
} }
}); });
} }
@ -177,7 +177,7 @@ public class NicknamesTable extends UserIDTable {
@Override @Override
public void prepare(PreparedStatement statement) throws SQLException { public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, uuid.toString()); statement.setString(1, uuid.toString());
statement.setString(2, ServerInfo.getServerUUID().toString()); statement.setString(2, ServerInfo.getServerUUID_Old().toString());
statement.setString(3, name.getName()); statement.setString(3, name.getName());
statement.setLong(4, name.getDate()); statement.setLong(4, name.getDate());
} }

View File

@ -73,7 +73,7 @@ public class PingTable extends UserIDTable {
@Override @Override
public void prepare(PreparedStatement statement) throws SQLException { public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, uuid.toString()); statement.setString(1, uuid.toString());
statement.setString(2, ServerInfo.getServerUUID().toString()); statement.setString(2, ServerInfo.getServerUUID_Old().toString());
statement.setLong(3, ping.getDate()); statement.setLong(3, ping.getDate());
statement.setInt(4, ping.getMin()); statement.setInt(4, ping.getMin());
statement.setInt(5, ping.getMax()); statement.setInt(5, ping.getMax());

View File

@ -134,7 +134,7 @@ public class SessionsTable extends UserIDTable {
statement.setInt(4, session.getUnsafe(SessionKeys.DEATH_COUNT)); statement.setInt(4, session.getUnsafe(SessionKeys.DEATH_COUNT));
statement.setInt(5, session.getUnsafe(SessionKeys.MOB_KILL_COUNT)); statement.setInt(5, session.getUnsafe(SessionKeys.MOB_KILL_COUNT));
statement.setLong(6, session.getUnsafe(SessionKeys.AFK_TIME)); statement.setLong(6, session.getUnsafe(SessionKeys.AFK_TIME));
statement.setString(7, ServerInfo.getServerUUID().toString()); statement.setString(7, ServerInfo.getServerUUID_Old().toString());
} }
}); });
} }
@ -239,7 +239,7 @@ public class SessionsTable extends UserIDTable {
* @return Milliseconds played on THIS server. 0 if player or server not found. * @return Milliseconds played on THIS server. 0 if player or server not found.
*/ */
public long getPlaytime(UUID uuid) { public long getPlaytime(UUID uuid) {
return getPlaytime(uuid, ServerInfo.getServerUUID()); return getPlaytime(uuid, ServerInfo.getServerUUID_Old());
} }
/** /**
@ -250,7 +250,7 @@ public class SessionsTable extends UserIDTable {
* @return Milliseconds played on THIS server. 0 if player or server not found. * @return Milliseconds played on THIS server. 0 if player or server not found.
*/ */
public long getPlaytime(UUID uuid, long afterDate) { public long getPlaytime(UUID uuid, long afterDate) {
return getPlaytime(uuid, ServerInfo.getServerUUID(), afterDate); return getPlaytime(uuid, ServerInfo.getServerUUID_Old(), afterDate);
} }
/** /**
@ -357,7 +357,7 @@ public class SessionsTable extends UserIDTable {
* @return How many sessions player has. 0 if player or server not found. * @return How many sessions player has. 0 if player or server not found.
*/ */
public int getSessionCount(UUID uuid, long afterDate) { public int getSessionCount(UUID uuid, long afterDate) {
return getSessionCount(uuid, ServerInfo.getServerUUID(), afterDate); return getSessionCount(uuid, ServerInfo.getServerUUID_Old(), afterDate);
} }
public Map<UUID, List<Session>> getSessionInfoOfServer(UUID serverUUID) { public Map<UUID, List<Session>> getSessionInfoOfServer(UUID serverUUID) {
@ -404,7 +404,7 @@ public class SessionsTable extends UserIDTable {
} }
public Map<UUID, List<Session>> getSessionInfoOfServer() { public Map<UUID, List<Session>> getSessionInfoOfServer() {
return getSessionInfoOfServer(ServerInfo.getServerUUID()); return getSessionInfoOfServer(ServerInfo.getServerUUID_Old());
} }
public Map<UUID, Long> getLastSeenForAllPlayers() { public Map<UUID, Long> getLastSeenForAllPlayers() {

View File

@ -105,7 +105,7 @@ public class TPSTable extends Table {
* @return @throws SQLException * @return @throws SQLException
*/ */
public List<TPS> getTPSData() { public List<TPS> getTPSData() {
return getTPSData(ServerInfo.getServerUUID()); return getTPSData(ServerInfo.getServerUUID_Old());
} }
/** /**
@ -138,7 +138,7 @@ public class TPSTable extends Table {
execute(new ExecStatement(insertStatement) { execute(new ExecStatement(insertStatement) {
@Override @Override
public void prepare(PreparedStatement statement) throws SQLException { public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, ServerInfo.getServerUUID().toString()); statement.setString(1, ServerInfo.getServerUUID_Old().toString());
statement.setLong(2, tps.getDate()); statement.setLong(2, tps.getDate());
statement.setDouble(3, tps.getTicksPerSecond()); statement.setDouble(3, tps.getTicksPerSecond());
statement.setInt(4, tps.getPlayers()); statement.setInt(4, tps.getPlayers());
@ -194,7 +194,7 @@ public class TPSTable extends Table {
} }
public Optional<TPS> getPeakPlayerCount(long afterDate) { public Optional<TPS> getPeakPlayerCount(long afterDate) {
return getPeakPlayerCount(ServerInfo.getServerUUID(), afterDate); return getPeakPlayerCount(ServerInfo.getServerUUID_Old(), afterDate);
} }
public Map<UUID, List<TPS>> getAllTPS() { public Map<UUID, List<TPS>> getAllTPS() {

View File

@ -90,7 +90,7 @@ public class TransferTable extends Table {
execute(new ExecStatement(sql) { execute(new ExecStatement(sql) {
@Override @Override
public void prepare(PreparedStatement statement) throws SQLException { public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, ServerInfo.getServerUUID().toString()); statement.setString(1, ServerInfo.getServerUUID_Old().toString());
statement.setString(2, "onlineStatus"); statement.setString(2, "onlineStatus");
} }
}); });
@ -100,7 +100,7 @@ public class TransferTable extends Table {
execute(new ExecStatement(insertStatementNoParts) { execute(new ExecStatement(insertStatementNoParts) {
@Override @Override
public void prepare(PreparedStatement statement) throws SQLException { public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, ServerInfo.getServerUUID().toString()); statement.setString(1, ServerInfo.getServerUUID_Old().toString());
statement.setLong(2, System.currentTimeMillis() + TimeAmount.HOUR.ms()); statement.setLong(2, System.currentTimeMillis() + TimeAmount.HOUR.ms());
statement.setString(3, "configSettings"); statement.setString(3, "configSettings");
statement.setString(4, null); statement.setString(4, null);

View File

@ -69,7 +69,7 @@ public class UserInfoTable extends UserIDTable {
public void prepare(PreparedStatement statement) throws SQLException { public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, uuid.toString()); statement.setString(1, uuid.toString());
statement.setLong(2, registered); statement.setLong(2, registered);
statement.setString(3, ServerInfo.getServerUUID().toString()); statement.setString(3, ServerInfo.getServerUUID_Old().toString());
} }
}); });
} }
@ -95,7 +95,7 @@ public class UserInfoTable extends UserIDTable {
} }
public boolean isRegistered(UUID uuid) { public boolean isRegistered(UUID uuid) {
return isRegistered(uuid, ServerInfo.getServerUUID()); return isRegistered(uuid, ServerInfo.getServerUUID_Old());
} }
public void updateOpStatus(UUID uuid, boolean op) { public void updateOpStatus(UUID uuid, boolean op) {
@ -166,7 +166,7 @@ public class UserInfoTable extends UserIDTable {
} }
public UserInfo getUserInfo(UUID uuid) { public UserInfo getUserInfo(UUID uuid) {
return getAllUserInfo(uuid).get(ServerInfo.getServerUUID()); return getAllUserInfo(uuid).get(ServerInfo.getServerUUID_Old());
} }
public List<UserInfo> getServerUserInfo(UUID serverUUID) { public List<UserInfo> getServerUserInfo(UUID serverUUID) {
@ -213,7 +213,7 @@ public class UserInfoTable extends UserIDTable {
* @return List of UserInfo objects. * @return List of UserInfo objects.
*/ */
public List<UserInfo> getServerUserInfo() { public List<UserInfo> getServerUserInfo() {
return getServerUserInfo(ServerInfo.getServerUUID()); return getServerUserInfo(ServerInfo.getServerUUID_Old());
} }
public Map<UUID, List<UserInfo>> getAllUserInfo() { public Map<UUID, List<UserInfo>> getAllUserInfo() {

View File

@ -73,7 +73,7 @@ public class WorldTable extends Table {
} }
public List<String> getWorlds() { public List<String> getWorlds() {
return getWorlds(ServerInfo.getServerUUID()); return getWorlds(ServerInfo.getServerUUID_Old());
} }
public List<String> getWorlds(UUID serverUUID) { public List<String> getWorlds(UUID serverUUID) {
@ -100,7 +100,7 @@ public class WorldTable extends Table {
} }
public void saveWorlds(Collection<String> worlds) { public void saveWorlds(Collection<String> worlds) {
saveWorlds(worlds, ServerInfo.getServerUUID()); saveWorlds(worlds, ServerInfo.getServerUUID_Old());
} }
/** /**

View File

@ -143,7 +143,7 @@ public class WorldTimesTable extends UserIDTable {
GMTimes gmTimes = entry.getValue(); GMTimes gmTimes = entry.getValue();
statement.setString(1, uuid.toString()); statement.setString(1, uuid.toString());
statement.setString(2, worldName); statement.setString(2, worldName);
String serverUUID = ServerInfo.getServerUUID().toString(); String serverUUID = ServerInfo.getServerUUID_Old().toString();
statement.setString(3, serverUUID); statement.setString(3, serverUUID);
statement.setString(4, serverUUID); statement.setString(4, serverUUID);
statement.setInt(5, sessionID); statement.setInt(5, sessionID);

View File

@ -15,6 +15,8 @@ import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.task.RunnableFactory; import com.djrapitops.plugin.task.RunnableFactory;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@ -29,38 +31,55 @@ public class FileSystem implements SubSystem {
private final File dataFolder; private final File dataFolder;
private File configFile; private File configFile;
@Deprecated @Inject
public FileSystem(PlanPlugin plugin) { public FileSystem(@Named("dataFolder") File dataFolder) {
this(plugin.getDataFolder());
}
public FileSystem(File dataFolder) {
this.dataFolder = dataFolder; this.dataFolder = dataFolder;
configFile = new File(dataFolder, "config.yml"); configFile = new File(dataFolder, "config.yml");
} }
@Deprecated
public static FileSystem getInstance() { public static FileSystem getInstance() {
FileSystem fileSystem = PlanSystem.getInstance().getFileSystem(); FileSystem fileSystem = PlanSystem.getInstance().getFileSystem();
Verify.nullCheck(fileSystem, () -> new IllegalStateException("File system was not initialized.")); Verify.nullCheck(fileSystem, () -> new IllegalStateException("File system was not initialized."));
return fileSystem; return fileSystem;
} }
public static File getDataFolder() { @Deprecated
public static File getDataFolder_Old() {
return getInstance().dataFolder; return getInstance().dataFolder;
} }
public static File getConfigFile() { @Deprecated
public static File getConfigFile_Old() {
return getInstance().configFile; return getInstance().configFile;
} }
public static File getLocaleFile() { @Deprecated
return new File(getInstance().dataFolder, "locale.txt"); public static File getLocaleFile_Old() {
return getInstance().getLocaleFile();
} }
@Deprecated
public static List<String> readFromResource(String fileName) throws IOException { public static List<String> readFromResource(String fileName) throws IOException {
return FileUtil.lines(PlanPlugin.getInstance(), fileName); return FileUtil.lines(PlanPlugin.getInstance(), fileName);
} }
public File getDataFolder() {
return dataFolder;
}
public File getConfigFile() {
return configFile;
}
public File getLocaleFile() {
return getFileFromPluginFolder("locale.txt");
}
public File getFileFromPluginFolder(String name) {
return new File(dataFolder, name);
}
@Override @Override
public void enable() throws EnableException { public void enable() throws EnableException {
Verify.isTrue((dataFolder.exists() && dataFolder.isDirectory()) || dataFolder.mkdirs(), Verify.isTrue((dataFolder.exists() && dataFolder.isDirectory()) || dataFolder.mkdirs(),

View File

@ -41,7 +41,7 @@ public class BungeeInfoSystem extends InfoSystem {
@Override @Override
public void updateNetworkPage() { public void updateNetworkPage() {
ResponseCache.cacheResponse(PageId.SERVER.of(ServerInfo.getServerUUID()), () -> { ResponseCache.cacheResponse(PageId.SERVER.of(ServerInfo.getServerUUID_Old()), () -> {
try { try {
return new NetworkPageResponse(); return new NetworkPageResponse();
} catch (ParseException e) { } catch (ParseException e) {

View File

@ -75,7 +75,7 @@ public abstract class InfoSystem implements SubSystem {
*/ */
public void generateAnalysisPage(UUID serverUUID) throws WebException { public void generateAnalysisPage(UUID serverUUID) throws WebException {
GenerateAnalysisPageRequest request = new GenerateAnalysisPageRequest(serverUUID); GenerateAnalysisPageRequest request = new GenerateAnalysisPageRequest(serverUUID);
if (ServerInfo.getServerUUID().equals(serverUUID)) { if (ServerInfo.getServerUUID_Old().equals(serverUUID)) {
runLocally(request); runLocally(request);
} else { } else {
sendRequest(request); sendRequest(request);

View File

@ -37,6 +37,6 @@ public class ServerInfoSystem extends InfoSystem {
@Override @Override
public void updateNetworkPage() throws WebException { public void updateNetworkPage() throws WebException {
String html = HtmlStructure.createServerContainer(); String html = HtmlStructure.createServerContainer();
sendRequest(new CacheNetworkPageContentRequest(ServerInfo.getServerUUID(), html)); sendRequest(new CacheNetworkPageContentRequest(ServerInfo.getServerUUID_Old(), html));
} }
} }

View File

@ -46,7 +46,7 @@ public class BungeeConnectionSystem extends ConnectionSystem {
Server server = null; Server server = null;
if (infoRequest instanceof CacheRequest || infoRequest instanceof GenerateInspectPageRequest) { if (infoRequest instanceof CacheRequest || infoRequest instanceof GenerateInspectPageRequest) {
// Run locally // Run locally
return ServerInfo.getServer(); return ServerInfo.getServer_Old();
} else if (infoRequest instanceof GenerateAnalysisPageRequest) { } else if (infoRequest instanceof GenerateAnalysisPageRequest) {
UUID serverUUID = ((GenerateAnalysisPageRequest) infoRequest).getServerUUID(); UUID serverUUID = ((GenerateAnalysisPageRequest) infoRequest).getServerUUID();
server = bukkitServers.get(serverUUID); server = bukkitServers.get(serverUUID);

View File

@ -47,7 +47,7 @@ public class ConnectionIn {
Log.debug("ConnectionIn: " + infoRequest.getClass().getSimpleName()); Log.debug("ConnectionIn: " + infoRequest.getClass().getSimpleName());
if (infoRequest instanceof SetupRequest) { if (infoRequest instanceof SetupRequest) {
if (!ConnectionSystem.isSetupAllowed()) { if (!ConnectionSystem.isSetupAllowed_Old()) {
throw new ForbiddenException("Setup not enabled on this server, use commands to enable."); throw new ForbiddenException("Setup not enabled on this server, use commands to enable.");
} }
} else { } else {

View File

@ -36,16 +36,23 @@ public abstract class ConnectionSystem implements SubSystem {
connectionLog = new ConnectionLog(); connectionLog = new ConnectionLog();
} }
@Deprecated
public static ConnectionSystem getInstance() { public static ConnectionSystem getInstance() {
ConnectionSystem connectionSystem = InfoSystem.getInstance().getConnectionSystem(); ConnectionSystem connectionSystem = InfoSystem.getInstance().getConnectionSystem();
Verify.nullCheck(connectionSystem, () -> new IllegalStateException("Connection System was not initialized")); Verify.nullCheck(connectionSystem, () -> new IllegalStateException("Connection System was not initialized"));
return connectionSystem; return connectionSystem;
} }
public static boolean isSetupAllowed() { @Deprecated
public static boolean isSetupAllowed_Old() {
return getInstance().setupAllowed; return getInstance().setupAllowed;
} }
@Deprecated
public static String getAddress() {
return getInstance().getMainAddress();
}
public InfoRequest getInfoRequest(String name) { public InfoRequest getInfoRequest(String name) {
return dataRequests.get(name.toLowerCase()); return dataRequests.get(name.toLowerCase());
} }
@ -60,8 +67,8 @@ public abstract class ConnectionSystem implements SubSystem {
protected abstract Server selectServerForRequest(InfoRequest infoRequest) throws NoServersException; protected abstract Server selectServerForRequest(InfoRequest infoRequest) throws NoServersException;
public static String getAddress() { public boolean isSetupAllowed() {
return getInstance().getMainAddress(); return setupAllowed;
} }
public void sendInfoRequest(InfoRequest infoRequest) throws WebException { public void sendInfoRequest(InfoRequest infoRequest) throws WebException {
@ -70,10 +77,10 @@ public abstract class ConnectionSystem implements SubSystem {
} }
public void sendInfoRequest(InfoRequest infoRequest, Server toServer) throws WebException { public void sendInfoRequest(InfoRequest infoRequest, Server toServer) throws WebException {
if (ServerInfo.getServerUUID().equals(toServer.getUuid())) { if (ServerInfo.getServerUUID_Old().equals(toServer.getUuid())) {
InfoSystem.getInstance().runLocally(infoRequest); InfoSystem.getInstance().runLocally(infoRequest);
} else { } else {
new ConnectionOut(toServer, ServerInfo.getServerUUID(), infoRequest).sendRequest(); new ConnectionOut(toServer, ServerInfo.getServerUUID_Old(), infoRequest).sendRequest();
} }
} }
@ -103,8 +110,6 @@ public abstract class ConnectionSystem implements SubSystem {
putRequest(requests, SendDBSettingsRequest.createHandler()); putRequest(requests, SendDBSettingsRequest.createHandler());
putRequest(requests, CheckConnectionRequest.createHandler()); putRequest(requests, CheckConnectionRequest.createHandler());
// putRequest(requests, UpdateRequest.createHandler());
// putRequest(requests, UpdateCancelRequest.createHandler());
return requests; return requests;
} }

View File

@ -99,7 +99,7 @@ public class ServerConnectionSystem extends ConnectionSystem {
@Override @Override
public String getMainAddress() { public String getMainAddress() {
return isServerAvailable() ? mainServer.getWebAddress() : ServerInfo.getServer().getWebAddress(); return isServerAvailable() ? mainServer.getWebAddress() : ServerInfo.getServer_Old().getWebAddress();
} }
@ -110,7 +110,7 @@ public class ServerConnectionSystem extends ConnectionSystem {
boolean usingBungeeWebServer = ConnectionSystem.getInstance().isServerAvailable(); boolean usingBungeeWebServer = ConnectionSystem.getInstance().isServerAvailable();
boolean usingAlternativeIP = Settings.SHOW_ALTERNATIVE_IP.isTrue(); boolean usingAlternativeIP = Settings.SHOW_ALTERNATIVE_IP.isTrue();
if (!usingAlternativeIP && ServerInfo.getServerProperties().getIp().isEmpty()) { if (!usingAlternativeIP && ServerInfo.getServerProperties_Old().getIp().isEmpty()) {
Log.infoColor("§e" + locale.get().getString(PluginLang.ENABLE_NOTIFY_EMPTY_IP)); Log.infoColor("§e" + locale.get().getString(PluginLang.ENABLE_NOTIFY_EMPTY_IP));
} }
if (usingBungeeWebServer && usingAlternativeIP) { if (usingBungeeWebServer && usingAlternativeIP) {

View File

@ -61,7 +61,7 @@ public class CacheInspectPageRequest extends InfoRequestWithVariables implements
String html = variables.get("html"); String html = variables.get("html");
Verify.nullCheck(html, () -> new BadRequestException("HTML 'html' variable not supplied in the request")); Verify.nullCheck(html, () -> new BadRequestException("HTML 'html' variable not supplied in the request"));
Map<String, String> replace = Collections.singletonMap("networkName", ServerInfo.getServerName()); Map<String, String> replace = Collections.singletonMap("networkName", ServerInfo.getServerName_Old());
boolean export = Settings.ANALYSIS_EXPORT.isTrue(); boolean export = Settings.ANALYSIS_EXPORT.isTrue();
cache(export, uuid, StringSubstitutor.replace(Base64Util.decode(html), replace)); cache(export, uuid, StringSubstitutor.replace(Base64Util.decode(html), replace));

View File

@ -72,6 +72,6 @@ public class CacheInspectPluginsTabRequest extends InfoRequestWithVariables impl
@Override @Override
public void runLocally() { public void runLocally() {
getPluginsTab(player).addTab(ServerInfo.getServerUUID(), variables.get("nav"), html); getPluginsTab(player).addTab(ServerInfo.getServerUUID_Old(), variables.get("nav"), html);
} }
} }

View File

@ -31,7 +31,7 @@ public class CacheNetworkPageContentRequest extends InfoRequestWithVariables imp
public CacheNetworkPageContentRequest(UUID serverUUID, String html) { public CacheNetworkPageContentRequest(UUID serverUUID, String html) {
Verify.nullCheck(serverUUID, html); Verify.nullCheck(serverUUID, html);
variables.put("serverName", ServerInfo.getServerName()); variables.put("serverName", ServerInfo.getServerName_Old());
variables.put("html", Base64Util.encode(html)); variables.put("html", Base64Util.encode(html));
this.html = html; this.html = html;
} }
@ -52,7 +52,7 @@ public class CacheNetworkPageContentRequest extends InfoRequestWithVariables imp
NetworkPageContent serversTab = getNetworkPageContent(); NetworkPageContent serversTab = getNetworkPageContent();
serversTab.addElement(serverName, Base64Util.decode(html)); serversTab.addElement(serverName, Base64Util.decode(html));
ResponseCache.clearResponse(PageId.SERVER.of(ServerInfo.getServerUUID())); ResponseCache.clearResponse(PageId.SERVER.of(ServerInfo.getServerUUID_Old()));
return DefaultResponses.SUCCESS.get(); return DefaultResponses.SUCCESS.get();
} }
@ -63,7 +63,7 @@ public class CacheNetworkPageContentRequest extends InfoRequestWithVariables imp
@Override @Override
public void runLocally() { public void runLocally() {
getNetworkPageContent().addElement(ServerInfo.getServerName(), html); getNetworkPageContent().addElement(ServerInfo.getServerName_Old(), html);
} }
public static CacheNetworkPageContentRequest createHandler() { public static CacheNetworkPageContentRequest createHandler() {

View File

@ -50,7 +50,7 @@ public class GenerateAnalysisPageRequest extends InfoRequestWithVariables implem
Verify.nullCheck(server, () -> new BadRequestException("Server UUID 'server' variable not supplied in the request.")); Verify.nullCheck(server, () -> new BadRequestException("Server UUID 'server' variable not supplied in the request."));
UUID serverUUID = UUID.fromString(server); UUID serverUUID = UUID.fromString(server);
if (!ServerInfo.getServerUUID().equals(serverUUID)) { if (!ServerInfo.getServerUUID_Old().equals(serverUUID)) {
throw new BadRequestException("Requested Analysis page from wrong server."); throw new BadRequestException("Requested Analysis page from wrong server.");
} }
@ -78,7 +78,7 @@ public class GenerateAnalysisPageRequest extends InfoRequestWithVariables implem
private String analyseAndGetHtml() throws InternalErrorException { private String analyseAndGetHtml() throws InternalErrorException {
try { try {
runningAnalysis = true; runningAnalysis = true;
UUID serverUUID = ServerInfo.getServerUUID(); UUID serverUUID = ServerInfo.getServerUUID_Old();
AnalysisContainer analysisContainer = new AnalysisContainer(Database.getActive().fetch().getServerContainer(serverUUID)); AnalysisContainer analysisContainer = new AnalysisContainer(Database.getActive().fetch().getServerContainer(serverUUID));
return new AnalysisPage(analysisContainer).toHtml(); return new AnalysisPage(analysisContainer).toHtml();
} catch (DBOpException e) { } catch (DBOpException e) {

View File

@ -1,37 +0,0 @@
/*
* License is provided in the jar as LICENSE also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/LICENSE
*/
package com.djrapitops.plan.system.info.request;
import com.djrapitops.plan.system.update.ShutdownUpdateHook;
import com.djrapitops.plan.system.webserver.response.DefaultResponses;
import com.djrapitops.plan.system.webserver.response.Response;
import java.util.Map;
/**
* InfoRequest used for Updating the plugin on a network.
*
* @author Rsl1122
*/
public class UpdateCancelRequest implements InfoRequest {
public UpdateCancelRequest() {
}
public static UpdateCancelRequest createHandler() {
return new UpdateCancelRequest();
}
@Override
public void runLocally() {
ShutdownUpdateHook.deActivate();
}
@Override
public Response handleRequest(Map<String, String> variables) {
ShutdownUpdateHook.deActivate();
return DefaultResponses.SUCCESS.get();
}
}

View File

@ -1,43 +0,0 @@
/*
* License is provided in the jar as LICENSE also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/LICENSE
*/
package com.djrapitops.plan.system.info.request;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.update.ShutdownUpdateHook;
import com.djrapitops.plan.system.webserver.response.DefaultResponses;
import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.response.errors.BadRequestResponse;
import java.util.Map;
/**
* InfoRequest used for Updating the plugin on a network.
*
* @author Rsl1122
*/
public class UpdateRequest implements InfoRequest {
public UpdateRequest() {
}
public static UpdateRequest createHandler() {
return new UpdateRequest();
}
@Override
public void runLocally() {
new ShutdownUpdateHook().register();
}
@Override
public Response handleRequest(Map<String, String> variables) {
if (Settings.ALLOW_UPDATE.isTrue()) {
new ShutdownUpdateHook().register();
return DefaultResponses.SUCCESS.get();
} else {
return new BadRequestResponse("Update not allowed on this server");
}
}
}

View File

@ -43,7 +43,7 @@ public class BukkitServerInfo extends ServerInfo {
database = Database.getActive(); database = Database.getActive();
try { try {
serverInfoFile = new ServerInfoFile(FileSystem.getDataFolder()); serverInfoFile = new ServerInfoFile(FileSystem.getDataFolder_Old());
} catch (IOException e) { } catch (IOException e) {
throw new EnableException("Failed to read ServerInfoFile.yml", e); throw new EnableException("Failed to read ServerInfoFile.yml", e);
} }
@ -87,7 +87,7 @@ public class BukkitServerInfo extends ServerInfo {
private Server registerServer(UUID serverUUID) throws IOException { private Server registerServer(UUID serverUUID) throws IOException {
String webAddress = WebServerSystem.getInstance().getWebServer().getAccessAddress(); String webAddress = WebServerSystem.getInstance().getWebServer().getAccessAddress();
String name = Settings.SERVER_NAME.toString().replaceAll("[^a-zA-Z0-9_\\s]", "_"); String name = Settings.SERVER_NAME.toString().replaceAll("[^a-zA-Z0-9_\\s]", "_");
int maxPlayers = ServerInfo.getServerProperties().getMaxPlayers(); int maxPlayers = ServerInfo.getServerProperties_Old().getMaxPlayers();
Server server = new Server(-1, serverUUID, name, webAddress, maxPlayers); Server server = new Server(-1, serverUUID, name, webAddress, maxPlayers);
database.save().serverInfoForThisServer(server); database.save().serverInfoForThisServer(server);

View File

@ -55,7 +55,7 @@ public class BungeeServerInfo extends ServerInfo {
} }
private void checkIfDefaultIP() throws EnableException { private void checkIfDefaultIP() throws EnableException {
String ip = ServerInfo.getServerProperties().getIp(); String ip = ServerInfo.getServerProperties_Old().getIp();
if ("0.0.0.0".equals(ip)) { if ("0.0.0.0".equals(ip)) {
Log.error("IP setting still 0.0.0.0 - Configure AlternativeIP/IP that connects to the Proxy server."); Log.error("IP setting still 0.0.0.0 - Configure AlternativeIP/IP that connects to the Proxy server.");
Log.info("Player Analytics partially enabled (Use /planbungee to reload config)"); Log.info("Player Analytics partially enabled (Use /planbungee to reload config)");
@ -64,7 +64,7 @@ public class BungeeServerInfo extends ServerInfo {
} }
private Server registerBungeeInfo(Database db) throws EnableException { private Server registerBungeeInfo(Database db) throws EnableException {
ServerProperties properties = ServerInfo.getServerProperties(); ServerProperties properties = ServerInfo.getServerProperties_Old();
UUID serverUUID = generateNewUUID(properties); UUID serverUUID = generateNewUUID(properties);
String accessAddress = WebServerSystem.getInstance().getWebServer().getAccessAddress(); String accessAddress = WebServerSystem.getInstance().getWebServer().getAccessAddress();

View File

@ -28,30 +28,48 @@ public abstract class ServerInfo implements SubSystem {
this.serverProperties = serverProperties; this.serverProperties = serverProperties;
} }
@Deprecated
public static ServerInfo getInstance() { public static ServerInfo getInstance() {
ServerInfo serverInfo = PlanSystem.getInstance().getServerInfo(); ServerInfo serverInfo = PlanSystem.getInstance().getServerInfo();
Verify.nullCheck(serverInfo, () -> new IllegalStateException("ServerInfo was not initialized.")); Verify.nullCheck(serverInfo, () -> new IllegalStateException("ServerInfo was not initialized."));
return serverInfo; return serverInfo;
} }
public static Server getServer() { @Deprecated
public static Server getServer_Old() {
return getInstance().server; return getInstance().server;
} }
public static ServerProperties getServerProperties() { @Deprecated
public static ServerProperties getServerProperties_Old() {
return getInstance().serverProperties; return getInstance().serverProperties;
} }
public static UUID getServerUUID() { @Deprecated
public static UUID getServerUUID_Old() {
return getServer_Old().getUuid();
}
@Deprecated
public static String getServerName_Old() {
return getServer_Old().getName();
}
@Deprecated
public static int getServerID_Old() {
return getServer_Old().getId();
}
public Server getServer() {
return server;
}
public UUID getServerUUID() {
return getServer().getUuid(); return getServer().getUuid();
} }
public static String getServerName() { public ServerProperties getServerProperties() {
return getServer().getName(); return serverProperties;
}
public static int getServerID() {
return getServer().getId();
} }
@Override @Override

View File

@ -46,7 +46,7 @@ public class PlayerOnlineListener implements Listener {
new IPUpdateProcessor(uuid, address, now)) new IPUpdateProcessor(uuid, address, now))
); );
Processing.submit(new PlayerPageUpdateProcessor(uuid)); Processing.submit(new PlayerPageUpdateProcessor(uuid));
ResponseCache.clearResponse(PageId.SERVER.of(ServerInfo.getServerUUID())); ResponseCache.clearResponse(PageId.SERVER.of(ServerInfo.getServerUUID_Old()));
} catch (Exception e) { } catch (Exception e) {
Log.toLog(this.getClass(), e); Log.toLog(this.getClass(), e);
} }
@ -60,7 +60,7 @@ public class PlayerOnlineListener implements Listener {
SessionCache.getInstance().endSession(uuid, System.currentTimeMillis()); SessionCache.getInstance().endSession(uuid, System.currentTimeMillis());
Processing.submit(new PlayerPageUpdateProcessor(uuid)); Processing.submit(new PlayerPageUpdateProcessor(uuid));
ResponseCache.clearResponse(PageId.SERVER.of(ServerInfo.getServerUUID())); ResponseCache.clearResponse(PageId.SERVER.of(ServerInfo.getServerUUID_Old()));
} catch (Exception e) { } catch (Exception e) {
Log.toLog(this.getClass(), e); Log.toLog(this.getClass(), e);
} }

View File

@ -51,7 +51,7 @@ public class LocaleSystem implements SubSystem {
@Override @Override
public void enable() throws EnableException { public void enable() throws EnableException {
File localeFile = FileSystem.getLocaleFile(); File localeFile = FileSystem.getLocaleFile_Old();
if (Settings.WRITE_NEW_LOCALE.isTrue()) { if (Settings.WRITE_NEW_LOCALE.isTrue()) {
writeNewDefaultLocale(localeFile); writeNewDefaultLocale(localeFile);

View File

@ -23,7 +23,6 @@ public enum CmdHelpLang implements Lang {
SETUP("Command Help - /planbungee setup", "Toggle set-up mode"), SETUP("Command Help - /planbungee setup", "Toggle set-up mode"),
CON("Command Help - /planbungee con", "Debug Bungee-Server connections"), CON("Command Help - /planbungee con", "Debug Bungee-Server connections"),
DISABLE("Command Help - /planbungee disable", "Disable the plugin temporarily"), DISABLE("Command Help - /planbungee disable", "Disable the plugin temporarily"),
UPDATE("Command Help - /plan update", "Get change log link or update plugin"),
MANAGE_MOVE("Command Help - /plan manage move", "Move data between Databases"), MANAGE_MOVE("Command Help - /plan manage move", "Move data between Databases"),
MANAGE_BACKUP("Command Help - /plan manage backup", "Backup a Database"), MANAGE_BACKUP("Command Help - /plan manage backup", "Backup a Database"),

View File

@ -67,17 +67,6 @@ public enum CommandLang implements Lang {
DISABLE_DISABLED("Cmd Disable - Disabled", "§aPlan systems are now disabled. You can still use /planbungee reload to restart the plugin."), DISABLE_DISABLED("Cmd Disable - Disabled", "§aPlan systems are now disabled. You can still use /planbungee reload to restart the plugin."),
UPDATE_WRONG_URL("Cmd Update - Url mismatch", "§cVersion download url did not start with ${0} and might not be trusted. You can download this version manually here (Direct download):"),
UPDATE_CHANGE_LOG("Cmd Update - Change log", "Change Log v${0}:"),
UPDATE_CANCEL_SUCCESS("Cmd Update - Cancel Success", "§aCancel operation performed."),
UPDATE_NOTIFY_CANCEL("Cmd Update - Notify Cancel", "§aYou can cancel the update on servers that haven't rebooted yet with /plan update cancel."),
UPDATE_ONLINE_CHECK("Cmd Update - Online Check", "Checking that all servers are online.."),
UPDATE_FAIL_NOT_ONLINE("Cmd Update - Fail Not Online", "§cNot all servers were online or accessible, you can still update available servers using /plan update -u -force"),
UPDATE_SCHEDULED("Cmd Update - Scheduled", "§a${0} scheduled for update."),
UPDATE_FAIL_FORCED("Cmd Update - Fail Force Notify", "§e${0} failed to update, -force specified, continuing update."),
UPDATE_FAIL_CANCEL("Cmd Update - Fail Cacnel", "§cUpdate failed on a server, cancelling update on all servers.."),
UPDATE_CANCELLED("Cmd Update - Cancelled", "§cUpdate cancelled."),
RELOAD_COMPLETE("Cmd Info - Reload Complete", "§aReload Complete"), RELOAD_COMPLETE("Cmd Info - Reload Complete", "§aReload Complete"),
RELOAD_FAILED("Cmd Info - Reload Failed", "§cSomething went wrong during reload of the plugin, a restart is recommended."); RELOAD_FAILED("Cmd Info - Reload Failed", "§cSomething went wrong during reload of the plugin, a restart is recommended.");

View File

@ -18,7 +18,6 @@ public enum DeepHelpLang implements Lang {
QINSPECT("In Depth Help - /plan qinspect ?", "> §2Quick Inspect Command\\ Displays some information about the player in game."), QINSPECT("In Depth Help - /plan qinspect ?", "> §2Quick Inspect Command\\ Displays some information about the player in game."),
RELOAD("In Depth Help - /plan reload ?", "> §2Reload Command\\ Restarts the plugin using onDisable and onEnable.\\ §bDoes not support swapping jar on the fly"), RELOAD("In Depth Help - /plan reload ?", "> §2Reload Command\\ Restarts the plugin using onDisable and onEnable.\\ §bDoes not support swapping jar on the fly"),
SEARCH("In Depth Help - /plan search ?", "> §2Search Command\\ Get a list of Player names that match the given argument.\\§7 Example: /plan search 123 - Finds all users with 123 in their name."), SEARCH("In Depth Help - /plan search ?", "> §2Search Command\\ Get a list of Player names that match the given argument.\\§7 Example: /plan search 123 - Finds all users with 123 in their name."),
UPDATE("In Depth Help - /plan update ?", "> §2Update Command\\ Used to update the plugin on the next shutdown\\ /plan update - Changelog link\\ /plan update -u - Schedule update to happen on all network servers that are online, next time they reboot.\\ /plan update cancel - Cancel scheduled update on servers that haven't rebooted yet."),
WEB("In Depth Help - /plan web ?", "< §2Web User Manage Command.\\ §2/plan web §fList subcommands\\ §2/plan web <subcommand> ? §fIn Depth help"), WEB("In Depth Help - /plan web ?", "< §2Web User Manage Command.\\ §2/plan web §fList subcommands\\ §2/plan web <subcommand> ? §fIn Depth help"),
MANAGE_BACKUP("In Depth Help - /plan manage backup ?", "> §2Backup Subcommand\\ Creates a new SQLite database (.db file) with contents of currently active database in the Plan plugin folder."), MANAGE_BACKUP("In Depth Help - /plan manage backup ?", "> §2Backup Subcommand\\ Creates a new SQLite database (.db file) with contents of currently active database in the Plan plugin folder."),

View File

@ -197,7 +197,7 @@ public class UserImportData {
public UserImportDataBuilder nicknames(String... nicknames) { public UserImportDataBuilder nicknames(String... nicknames) {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
UUID serverUUID = ServerInfo.getServerUUID(); UUID serverUUID = ServerInfo.getServerUUID_Old();
Arrays.stream(nicknames) Arrays.stream(nicknames)
.map(nick -> new Nickname(nick, time, serverUUID)) .map(nick -> new Nickname(nick, time, serverUUID))

View File

@ -93,7 +93,7 @@ public abstract class Importer {
return; return;
} }
UUID uuid = ServerInfo.getServerUUID(); UUID uuid = ServerInfo.getServerUUID_Old();
Database db = Database.getActive(); Database db = Database.getActive();
ExecutorService service = Executors.newCachedThreadPool(); ExecutorService service = Executors.newCachedThreadPool();
@ -137,7 +137,7 @@ public abstract class Importer {
UserImportRefiner userImportRefiner = new UserImportRefiner(Plan.getInstance(), userImportData); UserImportRefiner userImportRefiner = new UserImportRefiner(Plan.getInstance(), userImportData);
userImportData = userImportRefiner.refineData(); userImportData = userImportRefiner.refineData();
UUID serverUUID = ServerInfo.getServerUUID(); UUID serverUUID = ServerInfo.getServerUUID_Old();
Database db = Database.getActive(); Database db = Database.getActive();
Set<UUID> existingUUIDs = db.fetch().getSavedUUIDs(); Set<UUID> existingUUIDs = db.fetch().getSavedUUIDs();
@ -216,7 +216,7 @@ public abstract class Importer {
int mobKills = userImportData.getMobKills(); int mobKills = userImportData.getMobKills();
int deaths = userImportData.getDeaths(); int deaths = userImportData.getDeaths();
Session session = new Session(0, userImportData.getUuid(), ServerInfo.getServerUUID(), 0L, 0L, mobKills, deaths, 0); Session session = new Session(0, userImportData.getUuid(), ServerInfo.getServerUUID_Old(), 0L, 0L, mobKills, deaths, 0);
session.setPlayerKills(userImportData.getKills()); session.setPlayerKills(userImportData.getKills());
session.setWorldTimes(new WorldTimes(userImportData.getWorldTimes())); session.setWorldTimes(new WorldTimes(userImportData.getWorldTimes()));

View File

@ -27,7 +27,7 @@ public class NameProcessor implements CriticalRunnable {
public NameProcessor(UUID uuid, String playerName, String displayName) { public NameProcessor(UUID uuid, String playerName, String displayName) {
this.uuid = uuid; this.uuid = uuid;
this.playerName = playerName; this.playerName = playerName;
this.nickname = new Nickname(displayName, System.currentTimeMillis(), ServerInfo.getServerUUID()); this.nickname = new Nickname(displayName, System.currentTimeMillis(), ServerInfo.getServerUUID_Old());
} }
@Override @Override

View File

@ -56,7 +56,7 @@ public class PingInsertProcessor implements CriticalRunnable {
int maxValue = max.getAsInt(); int maxValue = max.getAsInt();
Ping ping = new Ping(lastDate, ServerInfo.getServerUUID(), Ping ping = new Ping(lastDate, ServerInfo.getServerUUID_Old(),
minValue, minValue,
maxValue, maxValue,
avgValue); avgValue);

View File

@ -1,6 +1,7 @@
package com.djrapitops.plan.system.settings; package com.djrapitops.plan.system.settings;
import com.djrapitops.plan.system.settings.config.ConfigSystem; import com.djrapitops.plan.system.settings.config.ConfigSystem;
import com.djrapitops.plan.system.settings.config.Setting;
import com.djrapitops.plugin.api.Check; import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.config.Config; import com.djrapitops.plugin.config.Config;
@ -16,7 +17,7 @@ import java.util.List;
* @author Rsl1122 * @author Rsl1122
* @since 2.3.2 * @since 2.3.2
*/ */
public enum Settings { public enum Settings implements Setting {
// Boolean // Boolean
BUNGEE_COPY_CONFIG("Plugin.Bungee-Override.CopyBungeeConfig"), BUNGEE_COPY_CONFIG("Plugin.Bungee-Override.CopyBungeeConfig"),
BUNGEE_OVERRIDE_STANDALONE_MODE("Plugin.Bungee-Override.StandaloneMode"), BUNGEE_OVERRIDE_STANDALONE_MODE("Plugin.Bungee-Override.StandaloneMode"),
@ -37,7 +38,6 @@ public enum Settings {
DISPLAY_PLAYER_IPS("Customization.Display.PlayerIPs"), DISPLAY_PLAYER_IPS("Customization.Display.PlayerIPs"),
DISPLAY_GAPS_IN_GRAPH_DATA("Customization.Display.GapsInGraphData"), DISPLAY_GAPS_IN_GRAPH_DATA("Customization.Display.GapsInGraphData"),
DATA_GEOLOCATIONS("Data.Geolocations"), DATA_GEOLOCATIONS("Data.Geolocations"),
ALLOW_UPDATE("Plugin.Allow-Update-Command"),
NOTIFY_ABOUT_DEV_RELEASES("Plugin.Notify-About-DEV-Releases"), NOTIFY_ABOUT_DEV_RELEASES("Plugin.Notify-About-DEV-Releases"),
// Integer // Integer
@ -117,6 +117,7 @@ public enum Settings {
this.configPath = path; this.configPath = path;
} }
@Deprecated
public static ServerSpecificSettings serverSpecific() { public static ServerSpecificSettings serverSpecific() {
if (!Check.isBungeeAvailable()) { if (!Check.isBungeeAvailable()) {
throw new IllegalStateException("Not supposed to call this method on Bukkit"); throw new IllegalStateException("Not supposed to call this method on Bukkit");
@ -125,22 +126,7 @@ public enum Settings {
return serverSpecificSettings; return serverSpecificSettings;
} }
/** @Deprecated
* If the settings is a boolean, this method should be used.
*
* @return Boolean value of the config setting, false if not boolean.
*/
public boolean isTrue() {
if (tempValue != null) {
return (Boolean) tempValue;
}
return getConfig().getBoolean(configPath);
}
public boolean isFalse() {
return !isTrue();
}
public static void save() { public static void save() {
try { try {
ConfigSystem.getConfig_Old().save(); ConfigSystem.getConfig_Old().save();
@ -149,12 +135,31 @@ public enum Settings {
} }
} }
/**
* If the settings is a boolean, this method should be used.
*
* @return Boolean value of the config setting, false if not boolean.
*/
@Deprecated
public boolean isTrue() {
if (tempValue != null) {
return (Boolean) tempValue;
}
return getConfig().getBoolean(configPath);
}
@Deprecated
public boolean isFalse() {
return !isTrue();
}
/** /**
* If the settings is a String, this method should be used. * If the settings is a String, this method should be used.
* *
* @return String value of the config setting. * @return String value of the config setting.
*/ */
@Override @Override
@Deprecated
public String toString() { public String toString() {
if (tempValue != null) { if (tempValue != null) {
return String.valueOf(tempValue); return String.valueOf(tempValue);
@ -167,6 +172,7 @@ public enum Settings {
* *
* @return Integer value of the config setting * @return Integer value of the config setting
*/ */
@Deprecated
public int getNumber() { public int getNumber() {
if (tempValue != null) { if (tempValue != null) {
return (Integer) tempValue; return (Integer) tempValue;

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