🎨 Some codestyle fixes
This commit is contained in:
parent
9a35a873c0
commit
a6b98ca278
12 changed files with 76 additions and 28 deletions
|
|
@ -117,9 +117,6 @@ subprojects {
|
|||
maven(MavenPublication) {
|
||||
from components.java
|
||||
|
||||
artifact javadocJar
|
||||
artifact sourcesJar
|
||||
|
||||
pom {
|
||||
name = project.name
|
||||
url = 'https://github.com/Sauilitired/cloud'
|
||||
|
|
|
|||
|
|
@ -27,7 +27,14 @@ import cloud.commandframework.execution.preprocessor.CommandPreprocessingContext
|
|||
import cloud.commandframework.execution.preprocessor.CommandPreprocessor;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class BukkitCommandPreprocessor<C> implements CommandPreprocessor<C> {
|
||||
/**
|
||||
* Command preprocessor which decorates incoming {@link cloud.commandframework.context.CommandContext}
|
||||
* with Bukkit specific objects
|
||||
*
|
||||
* @param <C>
|
||||
*/
|
||||
final class BukkitCommandPreprocessor<C> implements CommandPreprocessor<C> {
|
||||
|
||||
private final BukkitCommandManager<C> mgr;
|
||||
|
||||
/**
|
||||
|
|
@ -35,7 +42,7 @@ public class BukkitCommandPreprocessor<C> implements CommandPreprocessor<C> {
|
|||
*
|
||||
* @param mgr The BukkitCommandManager
|
||||
*/
|
||||
public BukkitCommandPreprocessor(final BukkitCommandManager<C> mgr) {
|
||||
BukkitCommandPreprocessor(final @NonNull BukkitCommandManager<C> mgr) {
|
||||
this.mgr = mgr;
|
||||
}
|
||||
|
||||
|
|
@ -49,4 +56,5 @@ public class BukkitCommandPreprocessor<C> implements CommandPreprocessor<C> {
|
|||
context.getCommandContext().getSender()));
|
||||
context.getCommandContext().store("CloudBukkitCapabilities", mgr.queryCapabilities());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,26 +24,34 @@
|
|||
package cloud.commandframework.bukkit.arguments.selector;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A class to represent the result of parsing a Minecraft Entity/Target Selector argument
|
||||
*/
|
||||
public abstract class EntitySelector {
|
||||
|
||||
private final List<Entity> entities;
|
||||
|
||||
/**
|
||||
* @param entities The List of Bukkit {@link Entity}s to construct the {@link EntitySelector} from
|
||||
* Construct a new entity selector
|
||||
*
|
||||
* @param entities The List of Bukkit {@link Entity entities} to construct the {@link EntitySelector} from
|
||||
*/
|
||||
public EntitySelector(final List<Entity> entities) {
|
||||
public EntitySelector(final @NonNull List<@NonNull Entity> entities) {
|
||||
this.entities = entities;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The list of Entities resulting from parsing the entity selector
|
||||
* Get the resulting entities
|
||||
*
|
||||
* @return Immutable view of the list list of entities resulting from parsing the entity selector
|
||||
*/
|
||||
public final List<Entity> getEntities() {
|
||||
return entities;
|
||||
public @NonNull List<@NonNull Entity> getEntities() {
|
||||
return Collections.unmodifiableList(this.entities);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,14 +24,17 @@
|
|||
package cloud.commandframework.bukkit.arguments.selector;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MultipleEntitySelector extends EntitySelector {
|
||||
|
||||
/**
|
||||
* @param entities The List of Bukkit {@link Entity}s to construct the {@link EntitySelector} from
|
||||
*/
|
||||
public MultipleEntitySelector(final List<Entity> entities) {
|
||||
public MultipleEntitySelector(final @NonNull List<@NonNull Entity> entities) {
|
||||
super(entities);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,17 +26,22 @@ package cloud.commandframework.bukkit.arguments.selector;
|
|||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class MultiplePlayerSelector extends MultipleEntitySelector {
|
||||
|
||||
private final List<Player> players = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Construct a new selector
|
||||
*
|
||||
* @param entities The List of Bukkit {@link Entity}s to construct the {@link EntitySelector} from
|
||||
*/
|
||||
public MultiplePlayerSelector(final List<Entity> entities) {
|
||||
public MultiplePlayerSelector(final @NonNull List<@NonNull Entity> entities) {
|
||||
super(entities);
|
||||
entities.forEach(e -> {
|
||||
if (e.getType() != EntityType.PLAYER) {
|
||||
|
|
@ -48,9 +53,12 @@ public class MultiplePlayerSelector extends MultipleEntitySelector {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return The list of Bukkit Players parsed from the selector
|
||||
* Get the resulting players
|
||||
*
|
||||
* @return Immutable views of the list of Bukkit {@link Player players} parsed from the selector
|
||||
*/
|
||||
public final List<Player> getPlayers() {
|
||||
return players;
|
||||
public final @NonNull List<@NonNull Player> getPlayers() {
|
||||
return Collections.unmodifiableList(this.players);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,14 +24,18 @@
|
|||
package cloud.commandframework.bukkit.arguments.selector;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class SingleEntitySelector extends MultipleEntitySelector {
|
||||
|
||||
/**
|
||||
* @param entities The List of Bukkit {@link Entity}s to construct the {@link EntitySelector} from
|
||||
* Construct a new selector
|
||||
*
|
||||
* @param entities The List of Bukkit {@link Entity entities} to construct the {@link EntitySelector} from
|
||||
*/
|
||||
public SingleEntitySelector(final List<Entity> entities) {
|
||||
public SingleEntitySelector(final @NonNull List<@NonNull Entity> entities) {
|
||||
super(entities);
|
||||
if (entities.size() > 1) {
|
||||
throw new IllegalArgumentException("More than 1 entity selected in single entity selector.");
|
||||
|
|
@ -39,9 +43,12 @@ public final class SingleEntitySelector extends MultipleEntitySelector {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the selected entity
|
||||
*
|
||||
* @return Gets the single Bukkit Entity parsed by the selector
|
||||
*/
|
||||
public Entity getEntity() {
|
||||
public @NonNull Entity getEntity() {
|
||||
return this.getEntities().get(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,14 +25,18 @@ package cloud.commandframework.bukkit.arguments.selector;
|
|||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class SinglePlayerSelector extends MultiplePlayerSelector {
|
||||
|
||||
/**
|
||||
* @param entities The List of Bukkit {@link Entity}s to construct the {@link EntitySelector} from
|
||||
* Construct a new selector
|
||||
*
|
||||
* @param entities The List of Bukkit {@link Entity entities} to construct the {@link EntitySelector} from
|
||||
*/
|
||||
public SinglePlayerSelector(final List<Entity> entities) {
|
||||
public SinglePlayerSelector(final @NonNull List<@NonNull Entity> entities) {
|
||||
super(entities);
|
||||
if (getPlayers().size() > 1) {
|
||||
throw new IllegalArgumentException("More than 1 player selected in single player selector.");
|
||||
|
|
@ -40,9 +44,12 @@ public final class SinglePlayerSelector extends MultiplePlayerSelector {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the selected player
|
||||
*
|
||||
* @return Gets the single player parsed by the selector
|
||||
*/
|
||||
public Player getPlayer() {
|
||||
public @NonNull Player getPlayer() {
|
||||
return this.getPlayers().get(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ import java.util.Set;
|
|||
import java.util.function.BiFunction;
|
||||
|
||||
public final class MultipleEntitySelectorArgument<C> extends CommandArgument<C, MultipleEntitySelector> {
|
||||
|
||||
private MultipleEntitySelectorArgument(final boolean required,
|
||||
@NonNull final String name,
|
||||
@NonNull final String defaultValue,
|
||||
|
|
@ -56,7 +57,7 @@ public final class MultipleEntitySelectorArgument<C> extends CommandArgument<C,
|
|||
* @param <C> Command sender type
|
||||
* @return Created builder
|
||||
*/
|
||||
public static <C> MultipleEntitySelectorArgument.Builder<C> newBuilder(@NonNull final String name) {
|
||||
public static <C> MultipleEntitySelectorArgument.@NonNull Builder<C> newBuilder(@NonNull final String name) {
|
||||
return new MultipleEntitySelectorArgument.Builder<>(name);
|
||||
}
|
||||
|
||||
|
|
@ -121,7 +122,7 @@ public final class MultipleEntitySelectorArgument<C> extends CommandArgument<C,
|
|||
@Override
|
||||
public @NonNull ArgumentParseResult<MultipleEntitySelector> parse(@NonNull final CommandContext<C> commandContext,
|
||||
@NonNull final Queue<@NonNull String> inputQueue) {
|
||||
if (!((Set<CloudBukkitCapabilities>) commandContext.get("CloudBukkitCapabilities")).contains(
|
||||
if (!commandContext.<Set<CloudBukkitCapabilities>>get("CloudBukkitCapabilities").contains(
|
||||
CloudBukkitCapabilities.BRIGADIER)) {
|
||||
return ArgumentParseResult.failure(
|
||||
new IllegalArgumentException("Entity selector argument type not supported below Minecraft 1.13."));
|
||||
|
|
@ -142,4 +143,5 @@ public final class MultipleEntitySelectorArgument<C> extends CommandArgument<C,
|
|||
return ArgumentParseResult.success(new MultipleEntitySelector(entities));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ import java.util.Set;
|
|||
import java.util.function.BiFunction;
|
||||
|
||||
public final class MultiplePlayerSelectorArgument<C> extends CommandArgument<C, MultiplePlayerSelector> {
|
||||
|
||||
private MultiplePlayerSelectorArgument(final boolean required,
|
||||
@NonNull final String name,
|
||||
@NonNull final String defaultValue,
|
||||
|
|
@ -169,4 +170,5 @@ public final class MultiplePlayerSelectorArgument<C> extends CommandArgument<C,
|
|||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ import java.util.Set;
|
|||
import java.util.function.BiFunction;
|
||||
|
||||
public final class SingleEntitySelectorArgument<C> extends CommandArgument<C, SingleEntitySelector> {
|
||||
|
||||
private SingleEntitySelectorArgument(final boolean required,
|
||||
@NonNull final String name,
|
||||
@NonNull final String defaultValue,
|
||||
|
|
@ -55,7 +56,7 @@ public final class SingleEntitySelectorArgument<C> extends CommandArgument<C, Si
|
|||
* @param <C> Command sender type
|
||||
* @return Created builder
|
||||
*/
|
||||
public static <C> SingleEntitySelectorArgument.Builder<C> newBuilder(@NonNull final String name) {
|
||||
public static <C> SingleEntitySelectorArgument.@NonNull Builder<C> newBuilder(@NonNull final String name) {
|
||||
return new SingleEntitySelectorArgument.Builder<>(name);
|
||||
}
|
||||
|
||||
|
|
@ -146,4 +147,5 @@ public final class SingleEntitySelectorArgument<C> extends CommandArgument<C, Si
|
|||
return ArgumentParseResult.success(new SingleEntitySelector(entities));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ import java.util.Set;
|
|||
import java.util.function.BiFunction;
|
||||
|
||||
public final class SinglePlayerSelectorArgument<C> extends CommandArgument<C, SinglePlayerSelector> {
|
||||
|
||||
private SinglePlayerSelectorArgument(final boolean required,
|
||||
@NonNull final String name,
|
||||
@NonNull final String defaultValue,
|
||||
|
|
@ -59,7 +60,7 @@ public final class SinglePlayerSelectorArgument<C> extends CommandArgument<C, Si
|
|||
* @param <C> Command sender type
|
||||
* @return Created builder
|
||||
*/
|
||||
public static <C> SinglePlayerSelectorArgument.Builder<C> newBuilder(@NonNull final String name) {
|
||||
public static <C> SinglePlayerSelectorArgument.@NonNull Builder<C> newBuilder(@NonNull final String name) {
|
||||
return new SinglePlayerSelectorArgument.Builder<>(name);
|
||||
}
|
||||
|
||||
|
|
@ -132,6 +133,7 @@ public final class SinglePlayerSelectorArgument<C> extends CommandArgument<C, Si
|
|||
|
||||
if (!((Set<CloudBukkitCapabilities>) commandContext.get("CloudBukkitCapabilities")).contains(
|
||||
CloudBukkitCapabilities.BRIGADIER)) {
|
||||
@SuppressWarnings("deprecation")
|
||||
Player player = Bukkit.getPlayer(input);
|
||||
|
||||
if (player == null) {
|
||||
|
|
@ -172,4 +174,5 @@ public final class SinglePlayerSelectorArgument<C> extends CommandArgument<C, Si
|
|||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,13 +97,14 @@ class PaperBrigadierListener<C> implements Listener {
|
|||
* @param playersOnly Whether the selector is for players only (true), or for all entities (false)
|
||||
* @return The NMS ArgumentType
|
||||
*/
|
||||
private Supplier<ArgumentType<?>> getEntitySelectorArgument(final boolean single, final boolean playersOnly) {
|
||||
private Supplier<ArgumentType<?>> getEntitySelectorArgument(final boolean single,
|
||||
final boolean playersOnly) {
|
||||
return () -> {
|
||||
try {
|
||||
Constructor<?> constructor = this.getNMSArgument("Entity").getDeclaredConstructors()[0];
|
||||
final Constructor<?> constructor = this.getNMSArgument("Entity").getDeclaredConstructors()[0];
|
||||
constructor.setAccessible(true);
|
||||
return (ArgumentType<?>) constructor.newInstance(single, playersOnly);
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
this.paperCommandManager.getOwningPlugin().getLogger().log(Level.INFO, "Failed to retrieve Selector Argument", e);
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue