Fix nullpointer when command requires no permissions
- Add test to verify connections among the command initialization
This commit is contained in:
parent
7c652feac2
commit
d7513ecc7b
@ -108,12 +108,15 @@ public class FoundCommandResult {
|
|||||||
* @return True if the command sender has permission, false otherwise.
|
* @return True if the command sender has permission, false otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean hasPermission(CommandSender sender) {
|
public boolean hasPermission(CommandSender sender) {
|
||||||
// Make sure the command description is valid
|
if (commandDescription == null) {
|
||||||
if (this.commandDescription == null)
|
|
||||||
return false;
|
return false;
|
||||||
|
} else if (commandDescription.getCommandPermissions() == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Get and return the permission
|
// TODO: Move permissions check to the permission package; command package should not define permission-checking
|
||||||
return this.commandDescription.getCommandPermissions().hasPermission(sender);
|
// API
|
||||||
|
return commandDescription.getCommandPermissions().hasPermission(sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -65,6 +65,28 @@ public class CommandManagerTest {
|
|||||||
walkThroughCommands(manager.getCommandDescriptions(), descriptionTester);
|
walkThroughCommands(manager.getCommandDescriptions(), descriptionTester);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Ensure that all children of a command stored the parent. */
|
||||||
|
@Test
|
||||||
|
public void shouldHaveConnectionBetweenParentAndChild() {
|
||||||
|
// given
|
||||||
|
BiConsumer connectionTester = new BiConsumer() {
|
||||||
|
@Override
|
||||||
|
public void accept(CommandDescription command, int depth) {
|
||||||
|
if (command.hasChildren()) {
|
||||||
|
for (CommandDescription child : command.getChildren()) {
|
||||||
|
assertThat(command.equals(child.getParent()), equalTo(true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Checking that the parent has the current command as child is redundant as this is how we can traverse
|
||||||
|
// the "command tree" in the first place - if we're here, it's that the parent definitely has the
|
||||||
|
// command as child.
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// when/then
|
||||||
|
walkThroughCommands(manager.getCommandDescriptions(), connectionTester);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldNotDefineSameLabelTwice() {
|
public void shouldNotDefineSameLabelTwice() {
|
||||||
// given
|
// given
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user