Moved some abstraction of ImporterSystem to Dagger

Removes 2 unnecessary classes
This commit is contained in:
Risto Lahtela 2020-11-19 17:05:44 +02:00
parent a6a606494d
commit 68ce65b4d5
10 changed files with 29 additions and 117 deletions

View File

@ -1,45 +0,0 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.gathering.importing;
import com.djrapitops.plan.gathering.importing.importers.OfflinePlayerImporter;
import javax.inject.Inject;
import javax.inject.Singleton;
/**
* ImportSystem implementation for Bukkit.
*
* @author Rsl1122
*/
@Singleton
public class BukkitImportSystem extends ImportSystem {
private final OfflinePlayerImporter offlinePlayerImporter;
@Inject
public BukkitImportSystem(
OfflinePlayerImporter offlinePlayerImporter
) {
this.offlinePlayerImporter = offlinePlayerImporter;
}
@Override
void registerImporters() {
registerImporter(offlinePlayerImporter);
}
}

View File

@ -18,8 +18,11 @@ package com.djrapitops.plan.modules.bukkit;
import com.djrapitops.plan.Plan; import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.gathering.importing.importers.Importer;
import com.djrapitops.plan.gathering.importing.importers.OfflinePlayerImporter;
import dagger.Binds; import dagger.Binds;
import dagger.Module; import dagger.Module;
import dagger.multibindings.IntoSet;
/** /**
* Dagger module for binding Plan instance. * Dagger module for binding Plan instance.
@ -31,4 +34,8 @@ public interface BukkitPlanModule {
@Binds @Binds
PlanPlugin bindPlanPlugin(Plan plugin); PlanPlugin bindPlanPlugin(Plan plugin);
@Binds
@IntoSet
Importer bindOfflinePlayerImporter(OfflinePlayerImporter importer);
} }

View File

@ -22,8 +22,6 @@ import com.djrapitops.plan.TaskSystem;
import com.djrapitops.plan.gathering.BukkitSensor; import com.djrapitops.plan.gathering.BukkitSensor;
import com.djrapitops.plan.gathering.ServerSensor; import com.djrapitops.plan.gathering.ServerSensor;
import com.djrapitops.plan.gathering.ServerShutdownSave; import com.djrapitops.plan.gathering.ServerShutdownSave;
import com.djrapitops.plan.gathering.importing.BukkitImportSystem;
import com.djrapitops.plan.gathering.importing.ImportSystem;
import com.djrapitops.plan.gathering.listeners.BukkitListenerSystem; import com.djrapitops.plan.gathering.listeners.BukkitListenerSystem;
import com.djrapitops.plan.gathering.listeners.ListenerSystem; import com.djrapitops.plan.gathering.listeners.ListenerSystem;
import com.djrapitops.plan.identification.ServerInfo; import com.djrapitops.plan.identification.ServerInfo;
@ -59,9 +57,6 @@ public interface BukkitSuperClassBindingModule {
@Binds @Binds
ListenerSystem bindListenerSystem(BukkitListenerSystem listenerSystem); ListenerSystem bindListenerSystem(BukkitListenerSystem listenerSystem);
@Binds
ImportSystem bindImportSystem(BukkitImportSystem importSystem);
@Binds @Binds
ServerShutdownSave bindServerShutdownSave(BukkitServerShutdownSave shutdownSave); ServerShutdownSave bindServerShutdownSave(BukkitServerShutdownSave shutdownSave);

View File

@ -1,39 +0,0 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.gathering.importing;
import javax.inject.Inject;
import javax.inject.Singleton;
/**
* Placeholder for a ImportSystem.
*
* @author Rsl1122
*/
@Singleton
public class EmptyImportSystem extends ImportSystem {
@Inject
public EmptyImportSystem() {
// Inject constructor required for dagger
}
@Override
void registerImporters() {
// No importers to register.
}
}

View File

@ -20,30 +20,34 @@ import com.djrapitops.plan.SubSystem;
import com.djrapitops.plan.gathering.importing.importers.Importer; import com.djrapitops.plan.gathering.importing.importers.Importer;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.*; import java.util.*;
/** /**
* Abstract representation of an ImportSystem. * Abstract representation of an ImportSystem.
* <p>
* TODO it is possible to remove the abstract part of this class by binding Importers to a Map with Dagger
* *
* @author Rsl1122 * @author Rsl1122
*/ */
public abstract class ImportSystem implements SubSystem { @Singleton
public class ImportSystem implements SubSystem {
protected final Map<String, Importer> importers; protected final Map<String, Importer> importers;
protected ImportSystem() { @Inject
importers = new HashMap<>(); protected ImportSystem(Set<Importer> importers) {
this.importers = new HashMap<>();
for (Importer importer : importers) {
this.importers.put(importer.getName(), importer);
}
} }
@Override @Override
public void enable() { public void enable() {
registerImporters(); // Nothing to do
} }
abstract void registerImporters();
public void registerImporter(Importer importer) { public void registerImporter(Importer importer) {
Verify.nullCheck(importer, () -> new IllegalArgumentException("Importer cannot be null")); Verify.nullCheck(importer, () -> new IllegalArgumentException("Importer cannot be null"));

View File

@ -17,8 +17,6 @@
package com.djrapitops.plan.modules; package com.djrapitops.plan.modules;
import com.djrapitops.plan.gathering.ServerSensor; import com.djrapitops.plan.gathering.ServerSensor;
import com.djrapitops.plan.gathering.importing.EmptyImportSystem;
import com.djrapitops.plan.gathering.importing.ImportSystem;
import com.djrapitops.plan.settings.ConfigSystem; import com.djrapitops.plan.settings.ConfigSystem;
import com.djrapitops.plan.settings.ProxyConfigSystem; import com.djrapitops.plan.settings.ProxyConfigSystem;
import com.djrapitops.plan.storage.database.DBSystem; import com.djrapitops.plan.storage.database.DBSystem;
@ -40,9 +38,6 @@ public interface ProxySuperClassBindingModule {
@Binds @Binds
ConfigSystem bindConfigSystem(ProxyConfigSystem configSystem); ConfigSystem bindConfigSystem(ProxyConfigSystem configSystem);
@Binds
ImportSystem bindImportSystem(EmptyImportSystem emptyImportSystem);
@Binds @Binds
ServerSensor<?> bindServerSensor(ServerSensor<Object> sensor); ServerSensor<?> bindServerSensor(ServerSensor<Object> sensor);

View File

@ -19,6 +19,7 @@ package com.djrapitops.plan.modules;
import com.djrapitops.plan.DataService; import com.djrapitops.plan.DataService;
import com.djrapitops.plan.DataSvc; import com.djrapitops.plan.DataSvc;
import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.gathering.importing.importers.Importer;
import com.djrapitops.plan.settings.config.ExtensionSettings; import com.djrapitops.plan.settings.config.ExtensionSettings;
import com.djrapitops.plan.settings.config.PlanConfig; import com.djrapitops.plan.settings.config.PlanConfig;
import com.djrapitops.plan.settings.locale.Locale; import com.djrapitops.plan.settings.locale.Locale;
@ -28,10 +29,13 @@ import com.djrapitops.plan.utilities.logging.ErrorLogger;
import com.djrapitops.plan.utilities.logging.PluginErrorLogger; import com.djrapitops.plan.utilities.logging.PluginErrorLogger;
import dagger.Module; import dagger.Module;
import dagger.Provides; import dagger.Provides;
import dagger.multibindings.ElementsIntoSet;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import java.io.File; import java.io.File;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Predicate; import java.util.function.Predicate;
/** /**
@ -42,6 +46,12 @@ import java.util.function.Predicate;
@Module @Module
public class SystemObjectProvidingModule { public class SystemObjectProvidingModule {
@Provides
@ElementsIntoSet
Set<Importer> emptyImporterSet() {
return new HashSet<>();
}
@Provides @Provides
@Singleton @Singleton
Locale provideLocale(LocaleSystem localeSystem) { Locale provideLocale(LocaleSystem localeSystem) {

View File

@ -16,8 +16,6 @@
*/ */
package utilities.dagger; package utilities.dagger;
import com.djrapitops.plan.gathering.importing.EmptyImportSystem;
import com.djrapitops.plan.gathering.importing.ImportSystem;
import com.djrapitops.plan.identification.ServerInfo; import com.djrapitops.plan.identification.ServerInfo;
import com.djrapitops.plan.identification.ServerServerInfo; import com.djrapitops.plan.identification.ServerServerInfo;
import com.djrapitops.plan.settings.BukkitConfigSystem; import com.djrapitops.plan.settings.BukkitConfigSystem;
@ -33,9 +31,6 @@ import dagger.Module;
@Module @Module
public interface PlanPluginModule { public interface PlanPluginModule {
@Binds
ImportSystem bindImportSystem(EmptyImportSystem emptyImportSystem);
@Binds @Binds
ConfigSystem bindBukkitConfigSystem(BukkitConfigSystem bukkitConfigSystem); ConfigSystem bindBukkitConfigSystem(BukkitConfigSystem bukkitConfigSystem);

View File

@ -23,8 +23,6 @@ import com.djrapitops.plan.TaskSystem;
import com.djrapitops.plan.gathering.NukkitSensor; import com.djrapitops.plan.gathering.NukkitSensor;
import com.djrapitops.plan.gathering.ServerSensor; import com.djrapitops.plan.gathering.ServerSensor;
import com.djrapitops.plan.gathering.ServerShutdownSave; import com.djrapitops.plan.gathering.ServerShutdownSave;
import com.djrapitops.plan.gathering.importing.EmptyImportSystem;
import com.djrapitops.plan.gathering.importing.ImportSystem;
import com.djrapitops.plan.gathering.listeners.ListenerSystem; import com.djrapitops.plan.gathering.listeners.ListenerSystem;
import com.djrapitops.plan.gathering.listeners.NukkitListenerSystem; import com.djrapitops.plan.gathering.listeners.NukkitListenerSystem;
import com.djrapitops.plan.identification.ServerInfo; import com.djrapitops.plan.identification.ServerInfo;
@ -59,9 +57,6 @@ public interface NukkitSuperClassBindingModule {
@Binds @Binds
ListenerSystem bindListenerSystem(NukkitListenerSystem listenerSystem); ListenerSystem bindListenerSystem(NukkitListenerSystem listenerSystem);
@Binds
ImportSystem bindImportSystem(EmptyImportSystem emptyImportSystem);
@Binds @Binds
ServerShutdownSave bindServerShutdownSave(NukkitServerShutdownSave shutdownSave); ServerShutdownSave bindServerShutdownSave(NukkitServerShutdownSave shutdownSave);

View File

@ -22,8 +22,6 @@ import com.djrapitops.plan.TaskSystem;
import com.djrapitops.plan.gathering.ServerSensor; import com.djrapitops.plan.gathering.ServerSensor;
import com.djrapitops.plan.gathering.ServerShutdownSave; import com.djrapitops.plan.gathering.ServerShutdownSave;
import com.djrapitops.plan.gathering.SpongeSensor; import com.djrapitops.plan.gathering.SpongeSensor;
import com.djrapitops.plan.gathering.importing.EmptyImportSystem;
import com.djrapitops.plan.gathering.importing.ImportSystem;
import com.djrapitops.plan.gathering.listeners.ListenerSystem; import com.djrapitops.plan.gathering.listeners.ListenerSystem;
import com.djrapitops.plan.gathering.listeners.SpongeListenerSystem; import com.djrapitops.plan.gathering.listeners.SpongeListenerSystem;
import com.djrapitops.plan.identification.ServerInfo; import com.djrapitops.plan.identification.ServerInfo;
@ -64,9 +62,6 @@ public interface SpongeSuperClassBindingModule {
@Binds @Binds
ListenerSystem bindListenerSystem(SpongeListenerSystem listenerSystem); ListenerSystem bindListenerSystem(SpongeListenerSystem listenerSystem);
@Binds
ImportSystem bindImportSystem(EmptyImportSystem emptyImportSystem);
@Binds @Binds
ServerShutdownSave bindServerShutdownSave(SpongeServerShutdownSave shutdownSave); ServerShutdownSave bindServerShutdownSave(SpongeServerShutdownSave shutdownSave);