[WIP] Add dependency injection functionality, Closes #85 (#86)

* misc improvements (as suggested by intellij)

* first draft of the DI functionality (#85)

* address review

* reenabled disabled inspections

* overload registerDependency method

* inject fields of superclasses two and remove invalid sponge default dependency
This commit is contained in:
MiniDigger
2018-01-25 20:21:16 +01:00
committed by Daniel Ennis
parent 23e8858c67
commit cebe28ef6c
16 changed files with 232 additions and 23 deletions
@@ -74,7 +74,7 @@ public class ACFSpongeUtil {
}
public static List<Player> matchPlayer(String partialName) {
List<Player> matchedPlayers = new ArrayList<Player>();
List<Player> matchedPlayers = new ArrayList<>();
for (Player iterPlayer : Sponge.getServer().getOnlinePlayers()) {
String iterPlayerName = iterPlayer.getName();
@@ -58,13 +58,12 @@ public class SpongeCommandContexts extends CommandContexts<SpongeCommandExecutio
colours = colours.filter(colour -> finalFilter.equals(ACFUtil.simplifyString(colour.getName())));
}
Stream<TextColor> finalColours = colours;
TextColor match = Sponge.getRegistry().getType(TextColor.class, ACFUtil.simplifyString(first)).orElseThrow(() -> {
return Sponge.getRegistry().getType(TextColor.class, ACFUtil.simplifyString(first)).orElseThrow(() -> {
String valid = finalColours
.map(colour -> "<c2>" + ACFUtil.simplifyString(colour.getName()) + "</c2>")
.collect(Collectors.joining("<c1>,</c1> "));
return new InvalidCommandArgument(MessageKeys.PLEASE_SPECIFY_ONE_OF, "{valid}", valid);
});
return match;
});
registerContext(TextStyle.Base.class, c -> {
String first = c.popFirstArg();
@@ -76,13 +75,12 @@ public class SpongeCommandContexts extends CommandContexts<SpongeCommandExecutio
styles = styles.filter(style -> finalFilter.equals(ACFUtil.simplifyString(style.getName())));
}
Stream<TextStyle.Base> finalStyles = styles;
TextStyle.Base match = Sponge.getRegistry().getType(TextStyle.Base.class, ACFUtil.simplifyString(first)).orElseThrow(() -> {
return Sponge.getRegistry().getType(TextStyle.Base.class, ACFUtil.simplifyString(first)).orElseThrow(() -> {
String valid = finalStyles
.map(style -> "<c2>" + ACFUtil.simplifyString(style.getName()) + "</c2>")
.collect(Collectors.joining("<c1>,</c1> "));
return new InvalidCommandArgument(MessageKeys.PLEASE_SPECIFY_ONE_OF, "{valid}", valid);
});
return match;
});
registerIssuerAwareContext(CommandSource.class, SpongeCommandExecutionContext::getSource);
@@ -67,6 +67,9 @@ public class SpongeCommandManager extends CommandManager<
this.formatters.put(MessageType.INFO, new SpongeMessageFormatter(TextColors.BLUE, TextColors.DARK_GREEN, TextColors.GREEN));
this.formatters.put(MessageType.HELP, new SpongeMessageFormatter(TextColors.AQUA, TextColors.GREEN, TextColors.YELLOW));
getLocales(); // auto load locales
//TODO more default dependencies for sponge
registerDependency(plugin.getClass(), plugin);
}
public PluginContainer getPlugin() {