Get rid of some annoying warnings

This commit is contained in:
Alexander Söderberg 2020-10-05 16:27:26 +02:00
parent a4544a8550
commit ec233fcc20
No known key found for this signature in database
GPG key ID: FACEA5B0F4C1BF80
4 changed files with 29 additions and 9 deletions

View file

@ -34,6 +34,7 @@ import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Set;
public final class CommandHelpHandler<C> {
@ -73,7 +74,7 @@ public final class CommandHelpHandler<C> {
public @NonNull List<@NonNull String> getLongestSharedChains() {
final List<String> chains = new ArrayList<>();
this.commandManager.getCommandTree().getRootNodes().forEach(node ->
chains.add(node.getValue()
chains.add(Objects.requireNonNull(node.getValue())
.getName() + this.commandManager.getCommandSyntaxFormatter()
.apply(Collections
.emptyList(),
@ -216,7 +217,11 @@ public final class CommandHelpHandler<C> {
if (index < queryFragments.length) {
/* We might still be able to match an argument */
for (final CommandTree.Node<CommandArgument<C, ?>> child : head.getChildren()) {
@SuppressWarnings("unchecked")
final StaticArgument<C> childArgument = (StaticArgument<C>) child.getValue();
if (childArgument == null) {
continue;
}
for (final String childAlias : childArgument.getAliases()) {
if (childAlias.equalsIgnoreCase(queryFragments[index])) {
head = child;
@ -253,6 +258,7 @@ public final class CommandHelpHandler<C> {
*
* @param <C> Command sender type
*/
@SuppressWarnings("unused")
public interface HelpTopic<C> {
}

View file

@ -73,7 +73,6 @@ import java.util.function.Function;
*
* @param <C> Command sender type
*/
@SuppressWarnings("unused")
public abstract class CommandManager<C> {
private final Map<Class<? extends Exception>, BiConsumer<C, ? extends Exception>> exceptionHandlers = new HashMap<>();
@ -371,7 +370,7 @@ public abstract class CommandManager<C> {
* @return Flag builder
*/
public CommandFlag.@NonNull Builder<Void> flagBuilder(final @NonNull String name) {
return CommandFlag.<C>newBuilder(name);
return CommandFlag.newBuilder(name);
}
/**
@ -580,6 +579,7 @@ public abstract class CommandManager<C> {
* @param setting Setting to set
* @param value Value
*/
@SuppressWarnings("unused")
public void setSetting(final @NonNull ManagerSettings setting,
final boolean value) {
if (value) {

View file

@ -85,8 +85,6 @@ import java.util.stream.Collectors;
*/
public final class CommandTree<C> {
private static final @Nullable Exception NULL_EXCEPTION = null;
private final Object commandLock = new Object();
private final Node<CommandArgument<C, ?>> internalTree = new Node<>(null);
@ -144,6 +142,7 @@ public final class CommandTree<C> {
commandContext.getSender(),
this.getChain(root)
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())));
}
@ -169,6 +168,7 @@ public final class CommandTree<C> {
.apply(parsedArguments, root),
commandContext.getSender(), this.getChain(root)
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())));
}
@ -179,6 +179,7 @@ public final class CommandTree<C> {
.apply(parsedArguments, root),
commandContext.getSender(), this.getChain(root)
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())));
}
@ -219,6 +220,7 @@ public final class CommandTree<C> {
commandContext.getSender(),
this.getChain(root)
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())));
}
@ -230,6 +232,7 @@ public final class CommandTree<C> {
.apply(parsedArguments, root),
commandContext.getSender(), this.getChain(root)
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())));
}
@ -252,6 +255,7 @@ public final class CommandTree<C> {
commandContext.getSender(),
this.getChain(child)
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(
Collectors.toList())));
@ -273,6 +277,7 @@ public final class CommandTree<C> {
commandContext.getSender(),
this.getChain(root)
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())));
}
@ -287,6 +292,7 @@ public final class CommandTree<C> {
.getArguments(), child),
commandContext.getSender(), this.getChain(root)
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(
Collectors.toList())));
@ -301,6 +307,7 @@ public final class CommandTree<C> {
commandContext.getSender(),
this.getChain(root)
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())));
}
@ -312,6 +319,7 @@ public final class CommandTree<C> {
.apply(parsedArguments, root),
commandContext.getSender(), this.getChain(root)
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())));
}
@ -336,6 +344,7 @@ public final class CommandTree<C> {
.apply(parsedArguments, child),
commandContext.getSender(), this.getChain(root)
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(
Collectors.toList())));
@ -349,6 +358,7 @@ public final class CommandTree<C> {
result.getFailure().get(), commandContext.getSender(),
this.getChain(child)
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())));
}
@ -429,7 +439,8 @@ public final class CommandTree<C> {
commandContext.store(child.getValue().getName(), result.getParsedValue().get());
return this.getSuggestions(commandContext, commandQueue, child);
} else if (result.getFailure().isPresent()) {
return child.getValue().getSuggestionsProvider().apply(commandContext, commandQueue.peek());
final String value = commandQueue.peek() == null ? "" : commandQueue.peek();
return child.getValue().getSuggestionsProvider().apply(commandContext, value);
}
}
}
@ -606,7 +617,10 @@ public final class CommandTree<C> {
if (child.getValue() != null && !child.getValue().isRequired() && size > 1) {
throw new AmbiguousNodeException(node.getValue(),
child.getValue(),
node.getChildren().stream().map(Node::getValue).collect(Collectors.toList()));
node.getChildren()
.stream()
.filter(n -> n.getValue() != null)
.map(Node::getValue).collect(Collectors.toList()));
}
}
node.children.forEach(this::checkAmbiguity);

View file

@ -60,7 +60,7 @@ class PaperBrigadierListener<C> implements Listener {
private final PaperCommandManager<C> paperCommandManager;
private final String nmsVersion;
PaperBrigadierListener(@Nonnull final PaperCommandManager<C> paperCommandManager) throws Exception {
PaperBrigadierListener(@Nonnull final PaperCommandManager<C> paperCommandManager) {
this.paperCommandManager = paperCommandManager;
this.brigadierManager = new CloudBrigadierManager<>(this.paperCommandManager,
() -> new CommandContext<>(