mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-08-26 22:49:51 +02:00
Refactored ImportManager into ImportSystem that is not static.
Moved Import data objects to system.importing.data Moved Importer classes to system.importing.importers Bound ImportSystem instances in SuperClassBindingModules Added ImportSystem as injected parameter to PlanSystem Injected ImportSystem to ManageImportCommand Removed old references to ImporterManager and removed the class Moved ImportBuilderTest to system.importing.data
This commit is contained in:
parent
d9cb158e3c
commit
db69d07100
|
@ -124,9 +124,6 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
|
|||
locale = system.getLocaleSystem().getLocale();
|
||||
system.enable();
|
||||
|
||||
// TODO Refactor into ImportSystem
|
||||
// ImporterManager.registerImporter(new OfflinePlayerImporter());
|
||||
|
||||
new BStatsBukkit(this).registerMetrics();
|
||||
|
||||
logger.debug("Verbose debug messages are enabled.");
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.plan.system.importing.ImportSystem;
|
||||
import com.djrapitops.plan.system.importing.importers.Importer;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.ManageLang;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.processing.importing.ImporterManager;
|
||||
import com.djrapitops.plan.system.processing.importing.importers.Importer;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
|
@ -17,6 +17,7 @@ import com.djrapitops.plugin.utilities.Verify;
|
|||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* This manage SubCommand is used to import data from 3rd party plugins.
|
||||
|
@ -29,16 +30,19 @@ public class ManageImportCommand extends CommandNode {
|
|||
|
||||
private final Locale locale;
|
||||
private final Processing processing;
|
||||
private final ImportSystem importSystem;
|
||||
|
||||
@Inject
|
||||
public ManageImportCommand(
|
||||
Locale locale,
|
||||
Processing processing
|
||||
Processing processing,
|
||||
ImportSystem importSystem
|
||||
) {
|
||||
super("import", Permissions.MANAGE.getPermission(), CommandType.CONSOLE);
|
||||
|
||||
this.locale = locale;
|
||||
this.processing = processing;
|
||||
this.importSystem = importSystem;
|
||||
|
||||
setArguments("<plugin>/list", "[import args]");
|
||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE_IMPORT));
|
||||
|
@ -54,19 +58,20 @@ public class ManageImportCommand extends CommandNode {
|
|||
|
||||
if (importArg.equals("list")) {
|
||||
sender.sendMessage(locale.getString(ManageLang.IMPORTERS));
|
||||
ImporterManager.getImporters().stream()
|
||||
.map(Importer::getNames)
|
||||
.map(list -> list.get(0))
|
||||
.forEach(name -> sender.sendMessage("- " + name));
|
||||
importSystem.getImporterNames().forEach(name -> sender.sendMessage("- " + name));
|
||||
return;
|
||||
}
|
||||
|
||||
Importer importer = ImporterManager.getImporter(importArg);
|
||||
if (importer == null) {
|
||||
findImporter(sender, importArg);
|
||||
}
|
||||
|
||||
private void findImporter(ISender sender, String importArg) {
|
||||
Optional<Importer> foundImporter = importSystem.getImporter(importArg);
|
||||
if (foundImporter.isPresent()) {
|
||||
Importer importer = foundImporter.get();
|
||||
processing.submitNonCritical(importer::processImport);
|
||||
} else {
|
||||
sender.sendMessage(locale.getString(ManageLang.FAIL_IMPORTER_NOT_FOUND, importArg));
|
||||
return;
|
||||
}
|
||||
|
||||
processing.submitNonCritical(importer::processImport);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import com.djrapitops.plan.api.BungeeAPI;
|
|||
import com.djrapitops.plan.api.PlanAPI;
|
||||
import com.djrapitops.plan.system.database.BungeeDBSystem;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.importing.EmptyImportSystem;
|
||||
import com.djrapitops.plan.system.importing.ImportSystem;
|
||||
import com.djrapitops.plan.system.info.BungeeInfoSystem;
|
||||
import com.djrapitops.plan.system.info.InfoSystem;
|
||||
import com.djrapitops.plan.system.info.connection.BungeeConnectionSystem;
|
||||
|
@ -69,4 +71,10 @@ public class BungeeSuperClassBindingModule {
|
|||
return bungeeListenerSystem;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
ImportSystem provideImportSystem() {
|
||||
return new EmptyImportSystem();
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,8 @@ package com.djrapitops.plan.modules.server.bukkit;
|
|||
|
||||
import com.djrapitops.plan.system.database.BukkitDBSystem;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.importing.BukkitImportSystem;
|
||||
import com.djrapitops.plan.system.importing.ImportSystem;
|
||||
import com.djrapitops.plan.system.listeners.BukkitListenerSystem;
|
||||
import com.djrapitops.plan.system.listeners.ListenerSystem;
|
||||
import com.djrapitops.plan.system.settings.config.BukkitConfigSystem;
|
||||
|
@ -45,4 +47,10 @@ public class BukkitSuperClassBindingModule {
|
|||
return bukkitListenerSystem;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
ImportSystem provideImportSsytem(BukkitImportSystem bukkitImportSystem) {
|
||||
return bukkitImportSystem;
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,8 @@ package com.djrapitops.plan.modules.server.sponge;
|
|||
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.database.SpongeDBSystem;
|
||||
import com.djrapitops.plan.system.importing.EmptyImportSystem;
|
||||
import com.djrapitops.plan.system.importing.ImportSystem;
|
||||
import com.djrapitops.plan.system.listeners.ListenerSystem;
|
||||
import com.djrapitops.plan.system.listeners.SpongeListenerSystem;
|
||||
import com.djrapitops.plan.system.settings.config.ConfigSystem;
|
||||
|
@ -45,4 +47,10 @@ public class SpongeSuperClassBindingModule {
|
|||
return spongeListenerSystem;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
ImportSystem provideImportSystem() {
|
||||
return new EmptyImportSystem();
|
||||
}
|
||||
|
||||
}
|
|
@ -12,6 +12,7 @@ import com.djrapitops.plan.system.cache.CacheSystem;
|
|||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.export.ExportSystem;
|
||||
import com.djrapitops.plan.system.file.FileSystem;
|
||||
import com.djrapitops.plan.system.importing.ImportSystem;
|
||||
import com.djrapitops.plan.system.info.InfoSystem;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.listeners.ListenerSystem;
|
||||
|
@ -50,6 +51,7 @@ public class PlanSystem implements SubSystem {
|
|||
|
||||
private final Processing processing;
|
||||
|
||||
private final ImportSystem importSystem;
|
||||
private final ExportSystem exportSystem;
|
||||
private final HookHandler hookHandler;
|
||||
private final PlanAPI planAPI;
|
||||
|
@ -68,6 +70,7 @@ public class PlanSystem implements SubSystem {
|
|||
ServerInfo serverInfo,
|
||||
WebServerSystem webServerSystem,
|
||||
Processing processing,
|
||||
ImportSystem importSystem,
|
||||
ExportSystem exportSystem,
|
||||
HookHandler hookHandler,
|
||||
PlanAPI planAPI
|
||||
|
@ -84,6 +87,7 @@ public class PlanSystem implements SubSystem {
|
|||
this.serverInfo = serverInfo;
|
||||
this.webServerSystem = webServerSystem;
|
||||
this.processing = processing;
|
||||
this.importSystem = importSystem;
|
||||
this.exportSystem = exportSystem;
|
||||
this.hookHandler = hookHandler;
|
||||
this.planAPI = planAPI;
|
||||
|
@ -182,6 +186,14 @@ public class PlanSystem implements SubSystem {
|
|||
return webServerSystem;
|
||||
}
|
||||
|
||||
public ImportSystem getImportSystem() {
|
||||
return importSystem;
|
||||
}
|
||||
|
||||
public ExportSystem getExportSystem() {
|
||||
return exportSystem;
|
||||
}
|
||||
|
||||
public ServerInfo getServerInfo() {
|
||||
return serverInfo;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package com.djrapitops.plan.system.importing;
|
||||
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.importing.importers.OfflinePlayerImporter;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* ImportSystem implementation for Bukkit.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class BukkitImportSystem extends ImportSystem {
|
||||
|
||||
private final Database database;
|
||||
private final ServerInfo serverInfo;
|
||||
|
||||
@Inject
|
||||
public BukkitImportSystem(
|
||||
Database database,
|
||||
ServerInfo serverInfo
|
||||
) {
|
||||
this.database = database;
|
||||
this.serverInfo = serverInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
void registerImporters() {
|
||||
registerImporter(new OfflinePlayerImporter(database, serverInfo));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.djrapitops.plan.system.importing;
|
||||
|
||||
/**
|
||||
* Placeholder for a ImportSystem.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class EmptyImportSystem extends ImportSystem {
|
||||
|
||||
@Override
|
||||
void registerImporters() {
|
||||
// No importers to register.
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package com.djrapitops.plan.system.importing;
|
||||
|
||||
import com.djrapitops.plan.system.SubSystem;
|
||||
import com.djrapitops.plan.system.importing.importers.Importer;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Abstract representation of an ImportSystem.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public abstract class ImportSystem implements SubSystem {
|
||||
|
||||
protected Map<String, Importer> importers;
|
||||
|
||||
public ImportSystem() {
|
||||
importers = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
registerImporters();
|
||||
}
|
||||
|
||||
abstract void registerImporters();
|
||||
|
||||
public void registerImporter(Importer importer) {
|
||||
Verify.nullCheck(importer, () -> new IllegalArgumentException("Importer cannot be null"));
|
||||
|
||||
importers.put(importer.getName(), importer);
|
||||
}
|
||||
|
||||
public Optional<Importer> getImporter(String name) {
|
||||
return Optional.ofNullable(importers.get(name));
|
||||
}
|
||||
|
||||
public List<String> getImporterNames() {
|
||||
List<String> names = new ArrayList<>(importers.keySet());
|
||||
Collections.sort(names);
|
||||
return names;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
importers.clear();
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
* 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.processing.importing;
|
||||
package com.djrapitops.plan.system.importing.data;
|
||||
|
||||
import com.djrapitops.plan.data.container.TPS;
|
||||
import com.djrapitops.plan.data.container.builders.TPSBuilder;
|
|
@ -2,7 +2,7 @@
|
|||
* 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.processing.importing;
|
||||
package com.djrapitops.plan.system.importing.data;
|
||||
|
||||
import com.djrapitops.plan.data.container.PlayerKill;
|
||||
import com.djrapitops.plan.data.store.objects.Nickname;
|
|
@ -2,7 +2,7 @@
|
|||
* 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.processing.importing;
|
||||
package com.djrapitops.plan.system.importing.data;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plugin.api.Benchmark;
|
|
@ -2,7 +2,7 @@
|
|||
* 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.processing.importing.importers;
|
||||
package com.djrapitops.plan.system.importing.importers;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBException;
|
||||
|
@ -15,10 +15,10 @@ import com.djrapitops.plan.data.time.WorldTimes;
|
|||
import com.djrapitops.plan.system.cache.GeolocationCache;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.database.databases.operation.SaveOperations;
|
||||
import com.djrapitops.plan.system.importing.data.ServerImportData;
|
||||
import com.djrapitops.plan.system.importing.data.UserImportData;
|
||||
import com.djrapitops.plan.system.importing.data.UserImportRefiner;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.processing.importing.ServerImportData;
|
||||
import com.djrapitops.plan.system.processing.importing.UserImportData;
|
||||
import com.djrapitops.plan.system.processing.importing.UserImportRefiner;
|
||||
import com.djrapitops.plan.utilities.SHA256Hash;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
@ -40,12 +40,23 @@ public abstract class Importer {
|
|||
private final Database database;
|
||||
private final UUID serverUUID;
|
||||
|
||||
protected Importer(Database database, ServerInfo serverInfo) {
|
||||
private final String name;
|
||||
|
||||
protected Importer(Database database, ServerInfo serverInfo, String name) {
|
||||
this.database = database;
|
||||
this.serverUUID = serverInfo.getServerUUID();
|
||||
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public abstract List<String> getNames();
|
||||
@Deprecated
|
||||
public List<String> getNames() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public abstract ServerImportData getServerImportData();
|
||||
|
|
@ -2,12 +2,12 @@
|
|||
* 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.processing.importing.importers;
|
||||
package com.djrapitops.plan.system.importing.importers;
|
||||
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.importing.data.ServerImportData;
|
||||
import com.djrapitops.plan.system.importing.data.UserImportData;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.processing.importing.ServerImportData;
|
||||
import com.djrapitops.plan.system.processing.importing.UserImportData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
|
@ -30,12 +30,7 @@ public class OfflinePlayerImporter extends Importer {
|
|||
Database database,
|
||||
ServerInfo serverInfo
|
||||
) {
|
||||
super(database, serverInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNames() {
|
||||
return Arrays.asList("offline", "offlineplayer");
|
||||
super(database, serverInfo, "offline");
|
||||
}
|
||||
|
||||
@Override
|
|
@ -1,58 +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.processing.importing;
|
||||
|
||||
import com.djrapitops.plan.system.processing.importing.importers.Importer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Fuzzlemann
|
||||
*/
|
||||
public class ImporterManager {
|
||||
|
||||
private static final List<Importer> registry = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Constructor used to hide the public constructor
|
||||
*/
|
||||
private ImporterManager() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
public static void registerImporter(Importer importer) {
|
||||
if (importer == null) {
|
||||
throw new NullPointerException("Importer cannot be null");
|
||||
}
|
||||
|
||||
String firstName = importer.getNames().get(0);
|
||||
|
||||
if (firstName == null) {
|
||||
throw new IllegalArgumentException("No Importer name given");
|
||||
}
|
||||
|
||||
if (getImporter(firstName) != null) {
|
||||
removeImporter(firstName);
|
||||
}
|
||||
|
||||
registry.add(importer);
|
||||
}
|
||||
|
||||
public static List<Importer> getImporters() {
|
||||
return registry;
|
||||
}
|
||||
|
||||
public static Importer getImporter(String name) {
|
||||
return registry.stream()
|
||||
.filter(importer -> importer.getNames().contains(name))
|
||||
.findAny()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public static void removeImporter(String name) {
|
||||
registry.removeIf(importer -> importer.getNames().contains(name));
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
* 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.data.additional.importer;
|
||||
package com.djrapitops.plan.system.importing.data;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.data.container.PlayerKill;
|
||||
|
@ -11,8 +11,6 @@ import com.djrapitops.plan.data.store.objects.Nickname;
|
|||
import com.djrapitops.plan.data.time.GMTimes;
|
||||
import com.djrapitops.plan.system.database.databases.SQLiteTest;
|
||||
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
|
||||
import com.djrapitops.plan.system.processing.importing.ServerImportData;
|
||||
import com.djrapitops.plan.system.processing.importing.UserImportData;
|
||||
import com.djrapitops.plugin.StaticHolder;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.google.common.collect.ImmutableMap;
|
Loading…
Reference in New Issue
Block a user