Package dev.jorel.commandapi
Class MockCommandAPI
java.lang.Object
dev.jorel.commandapi.MockCommandAPI
Additional logic that helps the CommandAPI run in a MockBukkit testing environment.
Does not rely on any version-specific Minecraft code to (ideally) support testing in any version.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic booleanA global toggle for whether the default logger returned byCommandAPIBukkit.getLogger()should print messages to the console. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMockCommandAPI(CommandAPIBukkit<MockCommandSource> commandAPIBukkit) -
Method Summary
Modifier and TypeMethodDescriptionstatic MockCommandAPIvoidonLoad()static <Target> voidSets a field inside a target object to the given value.
-
Field Details
-
ENABLE_LOGGING
public static boolean ENABLE_LOGGINGA global toggle for whether the default logger returned byCommandAPIBukkit.getLogger()should print messages to the console. This isfalseby default, so not messages will appear. If you don't provide your own logger usingCommandAPI.setLogger(CommandAPILogger)and set this totruebefore callingCommandAPI.onLoad(CommandAPIConfig), then the CommandAPI will write messages into the test log.
-
-
Constructor Details
-
MockCommandAPI
-
-
Method Details
-
getInstance
- Returns:
- The
MockCommandAPIinstance currently loaded.
-
getCommandAPIBukkit
- Returns:
- The implementation of
CommandAPIBukkitwhich is currently loaded. This is the same object as is returned byCommandAPIBukkit.get(), but explicitly using theMockCommandSourceclass.
-
setField
public static <Target> void setField(Class<? super Target> targetClass, String fieldName, Target target, Object value) Sets a field inside a target object to the given value. Ignores private access or final status.- Type Parameters:
Target- The type of the target object.- Parameters:
targetClass- TheClassthat contains the field.fieldName- The name of the field to change.target- The object whose field will be changed. If the field is static, this is ignored and can be null.value- The new value for the field.- Throws:
IllegalArgumentException- If the field cannot be set.
-
onLoad
public void onLoad() -
getCommandAPIHandlerSpy
- Returns:
- The
CommandAPIHandlerSpyobject intercepting calls toCommandAPIHandlermethods.
-
getCommandRegistrationStrategy
- Returns:
- The
MockCommandRegistrationStrategyhandling Brigadier command logic.
-