Apply suggestions from @kske 1
This commit is contained in:
parent
7468947728
commit
08ce7a9f86
@ -0,0 +1,39 @@
|
|||||||
|
package envoy.client.data.commands;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This interface defines an action that should be performed when a system
|
||||||
|
* command gets called.
|
||||||
|
*
|
||||||
|
* @author Leon Hofmeister
|
||||||
|
* @since Envoy Client v0.2-beta
|
||||||
|
*/
|
||||||
|
public interface Callable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs the instance specific action when a {@link SystemCommand} has been
|
||||||
|
* called.
|
||||||
|
*
|
||||||
|
* @param arguments the arguments that should be passed to the
|
||||||
|
* {@link SystemCommand}
|
||||||
|
* @since Envoy Client v0.2-beta
|
||||||
|
*/
|
||||||
|
void call(List<String> arguments);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs the instance specific action when a {@link SystemCommand} has been
|
||||||
|
* called and additionally enables the user to execute his own action once it
|
||||||
|
* has been called.
|
||||||
|
*
|
||||||
|
* @param arguments the arguments that should be passed to the
|
||||||
|
* {@link SystemCommand}
|
||||||
|
* @param additionalAction the action to perform when this system command has
|
||||||
|
* been called
|
||||||
|
* @since Envoy Client v0.2-beta
|
||||||
|
*/
|
||||||
|
default void call(List<String> arguments, Runnable additionalAction) {
|
||||||
|
call(arguments);
|
||||||
|
additionalAction.run();
|
||||||
|
}
|
||||||
|
}
|
@ -1,30 +0,0 @@
|
|||||||
package envoy.client.data.commands;
|
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This interface defines an action that should be performed when a system
|
|
||||||
* command gets called.
|
|
||||||
*
|
|
||||||
* @author Leon Hofmeister
|
|
||||||
* @since Envoy Client v0.2-beta
|
|
||||||
*/
|
|
||||||
public interface OnCall {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs class specific actions when a {@link SystemCommand} has been called.
|
|
||||||
*
|
|
||||||
* @since Envoy Client v0.2-beta
|
|
||||||
*/
|
|
||||||
void onCall();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs actions that can only be performed by classes that are not
|
|
||||||
* {@link SystemCommand}s when a SystemCommand has been called.
|
|
||||||
*
|
|
||||||
* @param consumer the action to perform when this {@link SystemCommand} has
|
|
||||||
* been called
|
|
||||||
* @since Envoy Client v0.2-beta
|
|
||||||
*/
|
|
||||||
void onCall(Supplier<Void> consumer);
|
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
package envoy.client.data.commands;
|
package envoy.client.data.commands;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.*;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is the base class of all {@code SystemCommands} and contains an
|
* This class is the base class of all {@code SystemCommands} and contains an
|
||||||
@ -17,7 +17,7 @@ import java.util.function.*;
|
|||||||
* @author Leon Hofmeister
|
* @author Leon Hofmeister
|
||||||
* @since Envoy Client v0.2-beta
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
public final class SystemCommand implements OnCall {
|
public final class SystemCommand implements Callable {
|
||||||
|
|
||||||
protected int relevance;
|
protected int relevance;
|
||||||
|
|
||||||
@ -55,12 +55,6 @@ public final class SystemCommand implements OnCall {
|
|||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the action that should be performed
|
|
||||||
* @since Envoy Client v0.2-beta
|
|
||||||
*/
|
|
||||||
public Consumer<List<String>> getAction() { return action; }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the argument count of the command
|
* @return the argument count of the command
|
||||||
* @since Envoy Client v0.2-beta
|
* @since Envoy Client v0.2-beta
|
||||||
@ -85,20 +79,10 @@ public final class SystemCommand implements OnCall {
|
|||||||
*/
|
*/
|
||||||
public void setRelevance(int relevance) { this.relevance = relevance; }
|
public void setRelevance(int relevance) { this.relevance = relevance; }
|
||||||
|
|
||||||
/**
|
|
||||||
* Increments the relevance of this {@code SystemCommand}.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void onCall() { relevance++; }
|
public void call(List<String> arguments) {
|
||||||
|
action.accept(arguments);
|
||||||
/**
|
++relevance;
|
||||||
* Increments the relevance of this {@code SystemCommand} and executes the
|
|
||||||
* supplier.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onCall(Supplier<Void> consumer) {
|
|
||||||
onCall();
|
|
||||||
consumer.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -155,14 +155,7 @@ public final class SystemCommandMap {
|
|||||||
final var arguments = extractArguments(input, systemCommand);
|
final var arguments = extractArguments(input, systemCommand);
|
||||||
// Executing the function
|
// Executing the function
|
||||||
try {
|
try {
|
||||||
systemCommand.getAction().accept(arguments);
|
systemCommand.call(arguments);
|
||||||
systemCommand.onCall();
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
logger.log(Level.SEVERE,
|
|
||||||
String.format(
|
|
||||||
"System command %s threw an IndexOutOfBoundsException. The most likely cause is a lower number of arguments than expected. It could also be a problem of the action performed: ",
|
|
||||||
command),
|
|
||||||
e);
|
|
||||||
} catch (final NumberFormatException e) {
|
} catch (final NumberFormatException e) {
|
||||||
logger.log(Level.INFO,
|
logger.log(Level.INFO,
|
||||||
String.format(
|
String.format(
|
||||||
|
Reference in New Issue
Block a user