Skip to content

Commit

Permalink
Clean up again
Browse files Browse the repository at this point in the history
  • Loading branch information
Mqzn committed Oct 4, 2024
1 parent 57693f8 commit da27553
Show file tree
Hide file tree
Showing 234 changed files with 13,751 additions and 13,752 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,54 @@
*/
@SuppressWarnings("unchecked")
public interface AdventureProvider<S> {
/**
* Obtains an {@link Audience} for the specified source.
*
* @param s the source from which the {@link Audience} is derived
* @return the {@link Audience} corresponding to the given source
*/
Audience audience(final S s);
/**
* Obtains an {@link Audience} for a given {@link Source} instance.
* This method delegates to {@link #audience(Object)} by retrieving the origin
* from the provided {@link Source}.
*
* @param source the {@link Source} instance from which the {@link Audience} is derived
* @return the {@link Audience} corresponding to the origin of the provided {@link Source}
*/
default Audience audience(final Source source) {
return this.audience((S) source.origin());
}
/**
* Sends a message to the {@link Audience} derived from the specified source.
*
* @param sender the source from which the {@link Audience} is derived
* @param component the message to be sent, represented by a {@link ComponentLike} instance
*/
default void send(final S sender, final ComponentLike component) {
this.audience(sender).sendMessage(component);
}
/**
* Sends a message to the {@link Audience} derived from the specified {@link Source} instance.
* This method delegates to {@link #send(Object, ComponentLike)} by retrieving the origin
* from the provided {@link Source}.
*
* @param source the {@link Source} instance from which the {@link Audience} is derived
* @param component the message to be sent, represented by a {@link ComponentLike} instance
*/
default void send(final Source source, final ComponentLike component) {
this.send((S) source.origin(), component);
}
/**
* Performs any necessary cleanup or resource management. By default, this method
* does nothing, but it can be overridden to provide specific close operations.
*/
default void close() {
}

/**
* Obtains an {@link Audience} for the specified source.
*
* @param s the source from which the {@link Audience} is derived
* @return the {@link Audience} corresponding to the given source
*/
Audience audience(final S s);

/**
* Obtains an {@link Audience} for a given {@link Source} instance.
* This method delegates to {@link #audience(Object)} by retrieving the origin
* from the provided {@link Source}.
*
* @param source the {@link Source} instance from which the {@link Audience} is derived
* @return the {@link Audience} corresponding to the origin of the provided {@link Source}
*/
default Audience audience(final Source source) {
return this.audience((S) source.origin());
}

/**
* Sends a message to the {@link Audience} derived from the specified source.
*
* @param sender the source from which the {@link Audience} is derived
* @param component the message to be sent, represented by a {@link ComponentLike} instance
*/
default void send(final S sender, final ComponentLike component) {
this.audience(sender).sendMessage(component);
}

/**
* Sends a message to the {@link Audience} derived from the specified {@link Source} instance.
* This method delegates to {@link #send(Object, ComponentLike)} by retrieving the origin
* from the provided {@link Source}.
*
* @param source the {@link Source} instance from which the {@link Audience} is derived
* @param component the message to be sent, represented by a {@link ComponentLike} instance
*/
default void send(final Source source, final ComponentLike component) {
this.send((S) source.origin(), component);
}

/**
* Performs any necessary cleanup or resource management. By default, this method
* does nothing, but it can be overridden to provide specific close operations.
*/
default void close() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import net.kyori.adventure.audience.Audience;

public class CastingAdventure<S> implements AdventureProvider<S> {
@Override
public final Audience audience(final S sender) {
return (Audience) sender;
}

@Override
public final Audience audience(final S sender) {
return (Audience) sender;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@
import net.kyori.adventure.text.ComponentLike;

public class EmptyAdventure<S> implements AdventureProvider<S> {
@Override
public Audience audience(final S sender) {
return null;
}
@Override
public Audience audience(final Source source) {
return null;
}
@Override
public void send(final S sender, final ComponentLike component) {
// do nothing
}
@Override
public void send(final Source source, final ComponentLike component) {
// do nothing
}

@Override
public Audience audience(final S sender) {
return null;
}

@Override
public Audience audience(final Source source) {
return null;
}

@Override
public void send(final S sender, final ComponentLike component) {
// do nothing
}

@Override
public void send(final Source source, final ComponentLike component) {
// do nothing
}

}
76 changes: 38 additions & 38 deletions brigadier/src/main/java/dev/velix/imperat/ArgumentTypeResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,42 @@
*/
@FunctionalInterface
public interface ArgumentTypeResolver {
/**
* Creates a {@link ArgumentTypeResolver} that will return the same
* argument type for all parameters that match a specific type
*
* @param type Type to check for
* @param argumentType The argument type to return
* @return The resolver factory
*/
static @NotNull ArgumentTypeResolver forType(Class<?> type, ArgumentType<?> argumentType) {
return parameter -> parameter.type() == type ? argumentType : null;
}
/**
* Creates a {@link ArgumentTypeResolver} that will return the same
* argument type for all parameters that match or extend a specific type
*
* @param type Type to check for
* @param argumentType The argument type to return
* @return The resolver factory
*/
static @NotNull ArgumentTypeResolver forHierarchyType(Class<?> type, ArgumentType<?> argumentType) {
return parameter -> {
var token = TypeWrap.of(parameter.type());
var token2 = TypeWrap.of(type);
return parameter.type() == type || token.isSupertypeOf(token2) ? argumentType : null;
};
}
/**
* Returns the argument type for the given parameter.
* If unknown, it returns null
*
* @param parameter Parameter to create for
* @return The argument type
*/
@Nullable
ArgumentType<?> resolveArgType(@NotNull CommandParameter<?> parameter);

/**
* Creates a {@link ArgumentTypeResolver} that will return the same
* argument type for all parameters that match a specific type
*
* @param type Type to check for
* @param argumentType The argument type to return
* @return The resolver factory
*/
static @NotNull ArgumentTypeResolver forType(Class<?> type, ArgumentType<?> argumentType) {
return parameter -> parameter.type() == type ? argumentType : null;
}

/**
* Creates a {@link ArgumentTypeResolver} that will return the same
* argument type for all parameters that match or extend a specific type
*
* @param type Type to check for
* @param argumentType The argument type to return
* @return The resolver factory
*/
static @NotNull ArgumentTypeResolver forHierarchyType(Class<?> type, ArgumentType<?> argumentType) {
return parameter -> {
var token = TypeWrap.of(parameter.type());
var token2 = TypeWrap.of(type);
return parameter.type() == type || token.isSupertypeOf(token2) ? argumentType : null;
};
}

/**
* Returns the argument type for the given parameter.
* If unknown, it returns null
*
* @param parameter Parameter to create for
* @return The argument type
*/
@Nullable
ArgumentType<?> resolveArgType(@NotNull CommandParameter<?> parameter);
}
Loading

0 comments on commit da27553

Please sign in to comment.