mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-10 22:01:00 +01:00
Moved some abstraction of ImporterSystem to Dagger
Removes 2 unnecessary classes
This commit is contained in:
parent
a6a606494d
commit
68ce65b4d5
@ -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);
|
||||
}
|
||||
}
|
@ -18,8 +18,11 @@ package com.djrapitops.plan.modules.bukkit;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
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.Module;
|
||||
import dagger.multibindings.IntoSet;
|
||||
|
||||
/**
|
||||
* Dagger module for binding Plan instance.
|
||||
@ -31,4 +34,8 @@ public interface BukkitPlanModule {
|
||||
|
||||
@Binds
|
||||
PlanPlugin bindPlanPlugin(Plan plugin);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
Importer bindOfflinePlayerImporter(OfflinePlayerImporter importer);
|
||||
}
|
@ -22,8 +22,6 @@ import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.gathering.BukkitSensor;
|
||||
import com.djrapitops.plan.gathering.ServerSensor;
|
||||
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.ListenerSystem;
|
||||
import com.djrapitops.plan.identification.ServerInfo;
|
||||
@ -59,9 +57,6 @@ public interface BukkitSuperClassBindingModule {
|
||||
@Binds
|
||||
ListenerSystem bindListenerSystem(BukkitListenerSystem listenerSystem);
|
||||
|
||||
@Binds
|
||||
ImportSystem bindImportSystem(BukkitImportSystem importSystem);
|
||||
|
||||
@Binds
|
||||
ServerShutdownSave bindServerShutdownSave(BukkitServerShutdownSave shutdownSave);
|
||||
|
||||
|
@ -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.
|
||||
}
|
||||
}
|
@ -20,30 +20,34 @@ import com.djrapitops.plan.SubSystem;
|
||||
import com.djrapitops.plan.gathering.importing.importers.Importer;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public abstract class ImportSystem implements SubSystem {
|
||||
@Singleton
|
||||
public class ImportSystem implements SubSystem {
|
||||
|
||||
protected final Map<String, Importer> importers;
|
||||
|
||||
protected ImportSystem() {
|
||||
importers = new HashMap<>();
|
||||
@Inject
|
||||
protected ImportSystem(Set<Importer> importers) {
|
||||
this.importers = new HashMap<>();
|
||||
for (Importer importer : importers) {
|
||||
this.importers.put(importer.getName(), importer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
registerImporters();
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
abstract void registerImporters();
|
||||
|
||||
public void registerImporter(Importer importer) {
|
||||
Verify.nullCheck(importer, () -> new IllegalArgumentException("Importer cannot be null"));
|
||||
|
||||
|
@ -17,8 +17,6 @@
|
||||
package com.djrapitops.plan.modules;
|
||||
|
||||
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.ProxyConfigSystem;
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
@ -40,9 +38,6 @@ public interface ProxySuperClassBindingModule {
|
||||
@Binds
|
||||
ConfigSystem bindConfigSystem(ProxyConfigSystem configSystem);
|
||||
|
||||
@Binds
|
||||
ImportSystem bindImportSystem(EmptyImportSystem emptyImportSystem);
|
||||
|
||||
@Binds
|
||||
ServerSensor<?> bindServerSensor(ServerSensor<Object> sensor);
|
||||
|
||||
|
@ -19,6 +19,7 @@ package com.djrapitops.plan.modules;
|
||||
import com.djrapitops.plan.DataService;
|
||||
import com.djrapitops.plan.DataSvc;
|
||||
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.PlanConfig;
|
||||
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 dagger.Module;
|
||||
import dagger.Provides;
|
||||
import dagger.multibindings.ElementsIntoSet;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
@ -42,6 +46,12 @@ import java.util.function.Predicate;
|
||||
@Module
|
||||
public class SystemObjectProvidingModule {
|
||||
|
||||
@Provides
|
||||
@ElementsIntoSet
|
||||
Set<Importer> emptyImporterSet() {
|
||||
return new HashSet<>();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
Locale provideLocale(LocaleSystem localeSystem) {
|
||||
|
@ -16,8 +16,6 @@
|
||||
*/
|
||||
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.ServerServerInfo;
|
||||
import com.djrapitops.plan.settings.BukkitConfigSystem;
|
||||
@ -33,9 +31,6 @@ import dagger.Module;
|
||||
@Module
|
||||
public interface PlanPluginModule {
|
||||
|
||||
@Binds
|
||||
ImportSystem bindImportSystem(EmptyImportSystem emptyImportSystem);
|
||||
|
||||
@Binds
|
||||
ConfigSystem bindBukkitConfigSystem(BukkitConfigSystem bukkitConfigSystem);
|
||||
|
||||
|
@ -23,8 +23,6 @@ import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.gathering.NukkitSensor;
|
||||
import com.djrapitops.plan.gathering.ServerSensor;
|
||||
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.NukkitListenerSystem;
|
||||
import com.djrapitops.plan.identification.ServerInfo;
|
||||
@ -59,9 +57,6 @@ public interface NukkitSuperClassBindingModule {
|
||||
@Binds
|
||||
ListenerSystem bindListenerSystem(NukkitListenerSystem listenerSystem);
|
||||
|
||||
@Binds
|
||||
ImportSystem bindImportSystem(EmptyImportSystem emptyImportSystem);
|
||||
|
||||
@Binds
|
||||
ServerShutdownSave bindServerShutdownSave(NukkitServerShutdownSave shutdownSave);
|
||||
|
||||
|
@ -22,8 +22,6 @@ import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.gathering.ServerSensor;
|
||||
import com.djrapitops.plan.gathering.ServerShutdownSave;
|
||||
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.SpongeListenerSystem;
|
||||
import com.djrapitops.plan.identification.ServerInfo;
|
||||
@ -64,9 +62,6 @@ public interface SpongeSuperClassBindingModule {
|
||||
@Binds
|
||||
ListenerSystem bindListenerSystem(SpongeListenerSystem listenerSystem);
|
||||
|
||||
@Binds
|
||||
ImportSystem bindImportSystem(EmptyImportSystem emptyImportSystem);
|
||||
|
||||
@Binds
|
||||
ServerShutdownSave bindServerShutdownSave(SpongeServerShutdownSave shutdownSave);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user