mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-21 05:50:18 +08:00
parent
b87f715492
commit
e100068e78
@ -2,7 +2,7 @@ dependencies {
|
||||
compile project(path: ":api")
|
||||
compile 'com.djrapitops:Extension-AAC:4.0.11-R0.1'
|
||||
compile 'com.djrapitops:Extension-AdvancedAchievements:1.1-R0.3'
|
||||
compile 'com.djrapitops:Extension-AdvancedBan:2.1.5-R0.6'
|
||||
compile 'com.djrapitops:Extension-AdvancedBan:2.1.5-R0.7'
|
||||
compile 'com.djrapitops:Extension-ASkyBlock:3.0.9.4-R0.4'
|
||||
compile 'com.djrapitops:Extension-BanManager:5.15.0-R0.5'
|
||||
compile 'com.djrapitops:Extension-CoreProtect:2.16.0-R0.3'
|
||||
|
@ -17,6 +17,7 @@
|
||||
package com.djrapitops.plan.extension.implementation;
|
||||
|
||||
import com.djrapitops.extension.*;
|
||||
import com.djrapitops.plan.extension.Caller;
|
||||
import com.djrapitops.plan.extension.DataExtension;
|
||||
import com.djrapitops.plan.extension.ExtensionService;
|
||||
import com.djrapitops.plan.extension.extractor.ExtensionExtractor;
|
||||
@ -25,7 +26,8 @@ import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* In charge of registering built in {@link com.djrapitops.plan.extension.DataExtension} implementations.
|
||||
@ -37,6 +39,7 @@ public class ExtensionRegister {
|
||||
|
||||
private IllegalStateException registerException;
|
||||
private Set<String> disabledExtensions;
|
||||
private ExtensionService extensionService;
|
||||
|
||||
@Inject
|
||||
public ExtensionRegister() {
|
||||
@ -45,68 +48,83 @@ public class ExtensionRegister {
|
||||
|
||||
public void registerBuiltInExtensions(Set<String> disabledExtensions) {
|
||||
this.disabledExtensions = disabledExtensions;
|
||||
// No need to catch exceptions here,
|
||||
// registerBuiltInExtensions method will not be called unless Plan has enabled properly
|
||||
ExtensionService extensionService = ExtensionService.getInstance();
|
||||
extensionService = ExtensionService.getInstance();
|
||||
|
||||
register(new AACExtensionFactory()::createExtension, AACExtensionFactory.class);
|
||||
register(new AdvancedAchievementsExtensionFactory()::createExtension, AdvancedAchievementsExtensionFactory.class);
|
||||
register(new AdvancedBanExtensionFactory()::createExtension, AdvancedBanExtensionFactory.class);
|
||||
register(new ASkyBlockExtensionFactory()::createExtension, ASkyBlockExtensionFactory.class);
|
||||
register(new BanManagerExtensionFactory()::createExtension, BanManagerExtensionFactory.class);
|
||||
register(new CoreProtectExtensionFactory()::createExtension, CoreProtectExtensionFactory.class);
|
||||
register(new DiscordSRVExtensionFactory()::createExtension, DiscordSRVExtensionFactory.class);
|
||||
registerEssentialsExtension(extensionService);
|
||||
register(new GriefPreventionExtensionFactory()::createExtension, GriefPreventionExtensionFactory.class);
|
||||
register(new GriefPreventionSpongeExtensionFactory()::createExtension, GriefPreventionSpongeExtensionFactory.class);
|
||||
register(new GriefPreventionPlusExtensionFactory()::createExtension, GriefPreventionPlusExtensionFactory.class);
|
||||
register(new McMMOExtensionFactory()::createExtension, McMMOExtensionFactory.class);
|
||||
registerMinigameLibExtensions(extensionService);
|
||||
register(new NucleusExtensionFactory()::createExtension, NucleusExtensionFactory.class);
|
||||
register(new NuVotifierExtensionFactory()::createExtension, NuVotifierExtensionFactory.class);
|
||||
register(new ProtocolSupportExtensionFactory()::createExtension, ProtocolSupportExtensionFactory.class);
|
||||
register(new RedProtectExtensionFactory()::createExtension, RedProtectExtensionFactory.class);
|
||||
register(new SpongeEconomyExtensionFactory()::createExtension, SpongeEconomyExtensionFactory.class);
|
||||
register(new SuperbVoteExtensionFactory()::createExtension, SuperbVoteExtensionFactory.class);
|
||||
register(new VaultExtensionFactory()::createExtension, VaultExtensionFactory.class);
|
||||
register(new ViaVersionExtensionFactory()::createExtension, ViaVersionExtensionFactory.class);
|
||||
register(new AACExtensionFactory(), AACExtensionFactory::createExtension);
|
||||
register(new AdvancedAchievementsExtensionFactory(), AdvancedAchievementsExtensionFactory::createExtension);
|
||||
register(new AdvancedBanExtensionFactory(), AdvancedBanExtensionFactory::createExtension, AdvancedBanExtensionFactory::registerListener);
|
||||
register(new ASkyBlockExtensionFactory(), ASkyBlockExtensionFactory::createExtension);
|
||||
register(new BanManagerExtensionFactory(), BanManagerExtensionFactory::createExtension);
|
||||
register(new CoreProtectExtensionFactory(), CoreProtectExtensionFactory::createExtension);
|
||||
register(new DiscordSRVExtensionFactory(), DiscordSRVExtensionFactory::createExtension);
|
||||
register(new EssentialsExtensionFactory(), EssentialsExtensionFactory::createExtension, EssentialsExtensionFactory::registerUpdateListeners);
|
||||
register(new GriefPreventionExtensionFactory(), GriefPreventionExtensionFactory::createExtension);
|
||||
register(new GriefPreventionSpongeExtensionFactory(), GriefPreventionSpongeExtensionFactory::createExtension);
|
||||
register(new GriefPreventionPlusExtensionFactory(), GriefPreventionPlusExtensionFactory::createExtension);
|
||||
register(new McMMOExtensionFactory(), McMMOExtensionFactory::createExtension);
|
||||
registerMinigameLibExtensions();
|
||||
register(new NucleusExtensionFactory(), NucleusExtensionFactory::createExtension);
|
||||
register(new NuVotifierExtensionFactory(), NuVotifierExtensionFactory::createExtension);
|
||||
register(new ProtocolSupportExtensionFactory(), ProtocolSupportExtensionFactory::createExtension);
|
||||
register(new RedProtectExtensionFactory(), RedProtectExtensionFactory::createExtension);
|
||||
register(new SpongeEconomyExtensionFactory(), SpongeEconomyExtensionFactory::createExtension);
|
||||
register(new SuperbVoteExtensionFactory(), SuperbVoteExtensionFactory::createExtension);
|
||||
register(new VaultExtensionFactory(), VaultExtensionFactory::createExtension);
|
||||
register(new ViaVersionExtensionFactory(), ViaVersionExtensionFactory::createExtension);
|
||||
|
||||
if (registerException != null) throw registerException;
|
||||
}
|
||||
|
||||
private void registerEssentialsExtension(ExtensionService extensionService) {
|
||||
EssentialsExtensionFactory essentials = new EssentialsExtensionFactory();
|
||||
essentials.createExtension()
|
||||
.flatMap(extensionService::register) // If the extension was registered this is present.
|
||||
.ifPresent(essentials::registerUpdateListeners);
|
||||
}
|
||||
|
||||
private void registerMinigameLibExtensions(ExtensionService extensionService) {
|
||||
private void registerMinigameLibExtensions() {
|
||||
for (DataExtension minigame : new MinigameLibExtensionFactory().createExtensions()) {
|
||||
extensionService.register(minigame);
|
||||
register(minigame);
|
||||
}
|
||||
}
|
||||
|
||||
private void register(Supplier<Optional<DataExtension>> extension, Class factory) {
|
||||
ExtensionService extensionService = ExtensionService.getInstance();
|
||||
private void suppressException(Class factory, Throwable e) {
|
||||
// Places all exceptions to one exception with plugin information so that they can be reported.
|
||||
if (registerException == null) {
|
||||
registerException = new IllegalStateException("One or more extensions failed to register:");
|
||||
registerException.setStackTrace(new StackTraceElement[0]);
|
||||
}
|
||||
IllegalStateException info = new IllegalStateException(factory.getSimpleName() + " ran into exception when creating Extension", e);
|
||||
info.setStackTrace(new StackTraceElement[0]);
|
||||
registerException.addSuppressed(info);
|
||||
}
|
||||
|
||||
private <T> void register(
|
||||
T factory,
|
||||
Function<T, Optional<DataExtension>> createExtension
|
||||
) {
|
||||
try {
|
||||
Optional<DataExtension> optional = extension.get();
|
||||
if (!optional.isPresent()) return;
|
||||
DataExtension dataExtension = optional.get();
|
||||
|
||||
String extensionName = ExtensionExtractor.getPluginName(dataExtension.getClass());
|
||||
if (disabledExtensions.contains(extensionName)) return;
|
||||
|
||||
extensionService.register(dataExtension);
|
||||
// Creates the extension with factory and registers it
|
||||
createExtension.apply(factory).flatMap(this::register);
|
||||
} catch (IllegalStateException | NoClassDefFoundError | IncompatibleClassChangeError e) {
|
||||
// Places all exceptions to one exception with plugin information so that they can be reported.
|
||||
if (registerException == null) {
|
||||
registerException = new IllegalStateException("One or more extensions failed to register:");
|
||||
registerException.setStackTrace(new StackTraceElement[0]);
|
||||
}
|
||||
IllegalStateException info = new IllegalStateException(factory.getSimpleName() + " ran into exception when creating Extension", e);
|
||||
info.setStackTrace(new StackTraceElement[0]);
|
||||
registerException.addSuppressed(info);
|
||||
suppressException(factory.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private <T> void register(
|
||||
T factory,
|
||||
Function<T, Optional<DataExtension>> createExtension,
|
||||
BiConsumer<T, Caller> registerListener
|
||||
) {
|
||||
try {
|
||||
// Creates the extension with factory and registers it, then registers listener
|
||||
createExtension.apply(factory)
|
||||
.flatMap(this::register)
|
||||
.ifPresent(caller -> registerListener.accept(factory, caller));
|
||||
} catch (IllegalStateException | NoClassDefFoundError | IncompatibleClassChangeError e) {
|
||||
// Places all exceptions to one exception with plugin information so that they can be reported.
|
||||
suppressException(factory.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<Caller> register(DataExtension dataExtension) {
|
||||
String extensionName = ExtensionExtractor.getPluginName(dataExtension.getClass());
|
||||
if (disabledExtensions.contains(extensionName)) return Optional.empty();
|
||||
|
||||
return extensionService.register(dataExtension);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user