♻️ Reformat + Update .editorconfig

This commit is contained in:
Alexander Söderberg 2020-10-06 22:48:30 +02:00 committed by Alexander Söderberg
parent 8bdec87a74
commit 2aac3980d5
169 changed files with 4261 additions and 2448 deletions

View file

@ -1,55 +1,85 @@
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
max_line_length = 120
max_line_length = 130
tab_width = 4
ij_continuation_indent_size = 8
ij_formatter_off_tag = @formatter:off
ij_formatter_on_tag = @formatter:on
ij_formatter_tags_enabled = true
ij_formatter_tags_enabled = false
ij_smart_tabs = false
ij_visual_guides = 130
ij_wrap_on_typing = false
ij_wrap_on_typing = true
[*.conf]
indent_size = 2
tab_width = 2
ij_continuation_indent_size = 2
ij_hocon_keep_blank_lines_before_right_brace = 2
ij_hocon_keep_indents_on_empty_lines = false
ij_hocon_keep_line_breaks = true
ij_hocon_space_after_colon = true
ij_hocon_space_after_comma = true
ij_hocon_space_before_colon = true
ij_hocon_space_before_comma = false
ij_hocon_spaces_within_braces = false
ij_hocon_spaces_within_brackets = false
ij_hocon_spaces_within_method_call_parentheses = false
[*.css]
ij_css_align_closing_brace_with_properties = false
ij_css_blank_lines_around_nested_selector = 1
ij_css_blank_lines_between_blocks = 1
ij_css_brace_placement = end_of_line
ij_css_enforce_quotes_on_format = false
ij_css_hex_color_long_format = false
ij_css_hex_color_lower_case = false
ij_css_hex_color_short_format = false
ij_css_hex_color_upper_case = false
ij_css_keep_blank_lines_in_code = 2
ij_css_keep_indents_on_empty_lines = false
ij_css_keep_single_line_blocks = false
ij_css_properties_order = font, font-family, font-size, font-weight, font-style, font-variant, font-size-adjust, font-stretch, line-height, position, z-index, top, right, bottom, left, display, visibility, float, clear, overflow, overflow-x, overflow-y, clip, zoom, align-content, align-items, align-self, flex, flex-flow, flex-basis, flex-direction, flex-grow, flex-shrink, flex-wrap, justify-content, order, box-sizing, width, min-width, max-width, height, min-height, max-height, margin, margin-top, margin-right, margin-bottom, margin-left, padding, padding-top, padding-right, padding-bottom, padding-left, table-layout, empty-cells, caption-side, border-spacing, border-collapse, list-style, list-style-position, list-style-type, list-style-image, content, quotes, counter-reset, counter-increment, resize, cursor, user-select, nav-index, nav-up, nav-right, nav-down, nav-left, transition, transition-delay, transition-timing-function, transition-duration, transition-property, transform, transform-origin, animation, animation-name, animation-duration, animation-play-state, animation-timing-function, animation-delay, animation-iteration-count, animation-direction, text-align, text-align-last, vertical-align, white-space, text-decoration, text-emphasis, text-emphasis-color, text-emphasis-style, text-emphasis-position, text-indent, text-justify, letter-spacing, word-spacing, text-outline, text-transform, text-wrap, text-overflow, text-overflow-ellipsis, text-overflow-mode, word-wrap, word-break, tab-size, hyphens, pointer-events, opacity, color, border, border-width, border-style, border-color, border-top, border-top-width, border-top-style, border-top-color, border-right, border-right-width, border-right-style, border-right-color, border-bottom, border-bottom-width, border-bottom-style, border-bottom-color, border-left, border-left-width, border-left-style, border-left-color, border-radius, border-top-left-radius, border-top-right-radius, border-bottom-right-radius, border-bottom-left-radius, border-image, border-image-source, border-image-slice, border-image-width, border-image-outset, border-image-repeat, outline, outline-width, outline-style, outline-color, outline-offset, background, background-color, background-image, background-repeat, background-attachment, background-position, background-position-x, background-position-y, background-clip, background-origin, background-size, box-decoration-break, box-shadow, text-shadow
ij_css_space_after_colon = true
ij_css_space_before_opening_brace = true
ij_css_use_double_quotes = true
ij_css_value_alignment = do_not_align
[*.java]
max_line_length = 130
ij_java_align_consecutive_assignments = false
ij_java_align_consecutive_variable_declarations = false
ij_java_align_group_field_declarations = false
ij_java_align_multiline_annotation_parameters = true
ij_java_align_multiline_array_initializer_expression = true
ij_java_align_multiline_annotation_parameters = false
ij_java_align_multiline_array_initializer_expression = false
ij_java_align_multiline_assignment = false
ij_java_align_multiline_binary_operation = false
ij_java_align_multiline_chained_methods = true
ij_java_align_multiline_chained_methods = false
ij_java_align_multiline_extends_list = false
ij_java_align_multiline_for = true
ij_java_align_multiline_method_parentheses = false
ij_java_align_multiline_parameters = true
ij_java_align_multiline_parameters_in_calls = true
ij_java_align_multiline_parameters_in_calls = false
ij_java_align_multiline_parenthesized_expression = false
ij_java_align_multiline_records = true
ij_java_align_multiline_resources = true
ij_java_align_multiline_ternary_operation = true
ij_java_align_multiline_ternary_operation = false
ij_java_align_multiline_text_blocks = false
ij_java_align_multiline_throws_list = false
ij_java_align_subsequent_simple_methods = false
ij_java_align_throws_keyword = false
ij_java_annotation_parameter_wrap = off
ij_java_array_initializer_new_line_after_left_brace = true
ij_java_array_initializer_right_brace_on_new_line = true
ij_java_array_initializer_wrap = on_every_item
ij_java_array_initializer_new_line_after_left_brace = false
ij_java_array_initializer_right_brace_on_new_line = false
ij_java_array_initializer_wrap = off
ij_java_assert_statement_colon_on_next_line = false
ij_java_assert_statement_wrap = off
ij_java_assignment_wrap = off
ij_java_binary_operation_sign_on_next_line = false
ij_java_binary_operation_wrap = off
ij_java_blank_lines_after_anonymous_class_header = 0
ij_java_blank_lines_after_class_header = 0
ij_java_blank_lines_after_class_header = 1
ij_java_blank_lines_after_imports = 1
ij_java_blank_lines_after_package = 1
ij_java_blank_lines_around_class = 1
@ -58,23 +88,23 @@ ij_java_blank_lines_around_field_in_interface = 0
ij_java_blank_lines_around_initializer = 1
ij_java_blank_lines_around_method = 1
ij_java_blank_lines_around_method_in_interface = 1
ij_java_blank_lines_before_class_end = 0
ij_java_blank_lines_before_class_end = 1
ij_java_blank_lines_before_imports = 1
ij_java_blank_lines_before_method_body = 0
ij_java_blank_lines_before_package = 0
ij_java_block_brace_style = end_of_line
ij_java_block_comment_at_first_column = true
ij_java_call_parameters_new_line_after_left_paren = false
ij_java_call_parameters_right_paren_on_new_line = false
ij_java_call_parameters_wrap = normal
ij_java_call_parameters_new_line_after_left_paren = true
ij_java_call_parameters_right_paren_on_new_line = true
ij_java_call_parameters_wrap = on_every_item
ij_java_case_statement_on_separate_line = true
ij_java_catch_on_new_line = false
ij_java_class_annotation_wrap = split_into_lines
ij_java_class_brace_style = end_of_line
ij_java_class_count_to_use_import_on_demand = 9999999
ij_java_class_count_to_use_import_on_demand = 100000
ij_java_class_names_in_javadoc = 1
ij_java_do_not_indent_top_level_class_members = false
ij_java_do_not_wrap_after_single_annotation = true
ij_java_do_not_wrap_after_single_annotation = false
ij_java_do_while_brace_force = always
ij_java_doc_add_blank_line_after_description = true
ij_java_doc_add_blank_line_after_param_comments = false
@ -85,12 +115,12 @@ ij_java_doc_align_param_comments = true
ij_java_doc_do_not_wrap_if_one_line = false
ij_java_doc_enable_formatting = true
ij_java_doc_enable_leading_asterisks = true
ij_java_doc_indent_on_continuation = false
ij_java_doc_indent_on_continuation = true
ij_java_doc_keep_empty_lines = true
ij_java_doc_keep_empty_parameter_tag = true
ij_java_doc_keep_empty_return_tag = true
ij_java_doc_keep_empty_throws_tag = true
ij_java_doc_keep_invalid_tags = true
ij_java_doc_keep_invalid_tags = false
ij_java_doc_param_description_on_new_line = false
ij_java_doc_preserve_line_breaks = false
ij_java_doc_use_throws_not_exception_tag = true
@ -133,18 +163,18 @@ ij_java_line_comment_at_first_column = true
ij_java_method_annotation_wrap = split_into_lines
ij_java_method_brace_style = end_of_line
ij_java_method_call_chain_wrap = on_every_item
ij_java_method_parameters_new_line_after_left_paren = false
ij_java_method_parameters_right_paren_on_new_line = false
ij_java_method_parameters_new_line_after_left_paren = true
ij_java_method_parameters_right_paren_on_new_line = true
ij_java_method_parameters_wrap = on_every_item
ij_java_modifier_list_wrap = false
ij_java_names_count_to_use_import_on_demand = 9999999
ij_java_names_count_to_use_import_on_demand = 100000
ij_java_new_line_after_lparen_in_record_header = false
ij_java_parameter_annotation_wrap = on_every_item
ij_java_parameter_annotation_wrap = off
ij_java_parentheses_expression_new_line_after_left_paren = false
ij_java_parentheses_expression_right_paren_on_new_line = false
ij_java_place_assignment_sign_on_next_line = false
ij_java_prefer_longer_names = true
ij_java_prefer_parameters_wrap = false
ij_java_prefer_longer_names = false
ij_java_prefer_parameters_wrap = true
ij_java_record_components_wrap = normal
ij_java_repeat_synchronized = true
ij_java_replace_instanceof_and_cast = false
@ -230,7 +260,7 @@ ij_java_spaces_within_try_parentheses = false
ij_java_spaces_within_while_parentheses = false
ij_java_special_else_if_treatment = true
ij_java_subclass_name_suffix = Impl
ij_java_ternary_operation_signs_on_next_line = false
ij_java_ternary_operation_signs_on_next_line = true
ij_java_ternary_operation_wrap = on_every_item
ij_java_test_name_suffix = Test
ij_java_throws_keyword_wrap = off
@ -239,10 +269,745 @@ ij_java_use_external_annotations = false
ij_java_use_fq_class_names = false
ij_java_use_relative_indents = false
ij_java_use_single_class_imports = true
ij_java_variable_annotation_wrap = on_every_item
ij_java_variable_annotation_wrap = off
ij_java_visibility = public
ij_java_while_brace_force = always
ij_java_while_on_new_line = false
ij_java_wrap_comments = false
ij_java_wrap_first_method_in_call_chain = false
ij_java_wrap_first_method_in_call_chain = true
ij_java_wrap_long_lines = false
[*.nbtt]
max_line_length = 150
ij_continuation_indent_size = 4
ij_nbtt_keep_indents_on_empty_lines = false
ij_nbtt_space_after_colon = true
ij_nbtt_space_after_comma = true
ij_nbtt_space_before_colon = true
ij_nbtt_space_before_comma = false
ij_nbtt_spaces_within_brackets = false
ij_nbtt_spaces_within_parentheses = false
[*.properties]
ij_properties_align_group_field_declarations = false
ij_properties_keep_blank_lines = false
ij_properties_key_value_delimiter = equals
ij_properties_spaces_around_key_value_delimiter = false
[*.sass]
indent_size = 2
ij_sass_align_closing_brace_with_properties = false
ij_sass_blank_lines_around_nested_selector = 1
ij_sass_blank_lines_between_blocks = 1
ij_sass_brace_placement = 0
ij_sass_enforce_quotes_on_format = false
ij_sass_hex_color_long_format = false
ij_sass_hex_color_lower_case = false
ij_sass_hex_color_short_format = false
ij_sass_hex_color_upper_case = false
ij_sass_keep_blank_lines_in_code = 2
ij_sass_keep_indents_on_empty_lines = false
ij_sass_keep_single_line_blocks = false
ij_sass_properties_order = font, font-family, font-size, font-weight, font-style, font-variant, font-size-adjust, font-stretch, line-height, position, z-index, top, right, bottom, left, display, visibility, float, clear, overflow, overflow-x, overflow-y, clip, zoom, align-content, align-items, align-self, flex, flex-flow, flex-basis, flex-direction, flex-grow, flex-shrink, flex-wrap, justify-content, order, box-sizing, width, min-width, max-width, height, min-height, max-height, margin, margin-top, margin-right, margin-bottom, margin-left, padding, padding-top, padding-right, padding-bottom, padding-left, table-layout, empty-cells, caption-side, border-spacing, border-collapse, list-style, list-style-position, list-style-type, list-style-image, content, quotes, counter-reset, counter-increment, resize, cursor, user-select, nav-index, nav-up, nav-right, nav-down, nav-left, transition, transition-delay, transition-timing-function, transition-duration, transition-property, transform, transform-origin, animation, animation-name, animation-duration, animation-play-state, animation-timing-function, animation-delay, animation-iteration-count, animation-direction, text-align, text-align-last, vertical-align, white-space, text-decoration, text-emphasis, text-emphasis-color, text-emphasis-style, text-emphasis-position, text-indent, text-justify, letter-spacing, word-spacing, text-outline, text-transform, text-wrap, text-overflow, text-overflow-ellipsis, text-overflow-mode, word-wrap, word-break, tab-size, hyphens, pointer-events, opacity, color, border, border-width, border-style, border-color, border-top, border-top-width, border-top-style, border-top-color, border-right, border-right-width, border-right-style, border-right-color, border-bottom, border-bottom-width, border-bottom-style, border-bottom-color, border-left, border-left-width, border-left-style, border-left-color, border-radius, border-top-left-radius, border-top-right-radius, border-bottom-right-radius, border-bottom-left-radius, border-image, border-image-source, border-image-slice, border-image-width, border-image-outset, border-image-repeat, outline, outline-width, outline-style, outline-color, outline-offset, background, background-color, background-image, background-repeat, background-attachment, background-position, background-position-x, background-position-y, background-clip, background-origin, background-size, box-decoration-break, box-shadow, text-shadow
ij_sass_space_after_colon = true
ij_sass_space_before_opening_brace = true
ij_sass_use_double_quotes = true
ij_sass_value_alignment = 0
[*.scss]
indent_size = 2
ij_scss_align_closing_brace_with_properties = false
ij_scss_blank_lines_around_nested_selector = 1
ij_scss_blank_lines_between_blocks = 1
ij_scss_brace_placement = 0
ij_scss_enforce_quotes_on_format = false
ij_scss_hex_color_long_format = false
ij_scss_hex_color_lower_case = false
ij_scss_hex_color_short_format = false
ij_scss_hex_color_upper_case = false
ij_scss_keep_blank_lines_in_code = 2
ij_scss_keep_indents_on_empty_lines = false
ij_scss_keep_single_line_blocks = false
ij_scss_properties_order = font, font-family, font-size, font-weight, font-style, font-variant, font-size-adjust, font-stretch, line-height, position, z-index, top, right, bottom, left, display, visibility, float, clear, overflow, overflow-x, overflow-y, clip, zoom, align-content, align-items, align-self, flex, flex-flow, flex-basis, flex-direction, flex-grow, flex-shrink, flex-wrap, justify-content, order, box-sizing, width, min-width, max-width, height, min-height, max-height, margin, margin-top, margin-right, margin-bottom, margin-left, padding, padding-top, padding-right, padding-bottom, padding-left, table-layout, empty-cells, caption-side, border-spacing, border-collapse, list-style, list-style-position, list-style-type, list-style-image, content, quotes, counter-reset, counter-increment, resize, cursor, user-select, nav-index, nav-up, nav-right, nav-down, nav-left, transition, transition-delay, transition-timing-function, transition-duration, transition-property, transform, transform-origin, animation, animation-name, animation-duration, animation-play-state, animation-timing-function, animation-delay, animation-iteration-count, animation-direction, text-align, text-align-last, vertical-align, white-space, text-decoration, text-emphasis, text-emphasis-color, text-emphasis-style, text-emphasis-position, text-indent, text-justify, letter-spacing, word-spacing, text-outline, text-transform, text-wrap, text-overflow, text-overflow-ellipsis, text-overflow-mode, word-wrap, word-break, tab-size, hyphens, pointer-events, opacity, color, border, border-width, border-style, border-color, border-top, border-top-width, border-top-style, border-top-color, border-right, border-right-width, border-right-style, border-right-color, border-bottom, border-bottom-width, border-bottom-style, border-bottom-color, border-left, border-left-width, border-left-style, border-left-color, border-radius, border-top-left-radius, border-top-right-radius, border-bottom-right-radius, border-bottom-left-radius, border-image, border-image-source, border-image-slice, border-image-width, border-image-outset, border-image-repeat, outline, outline-width, outline-style, outline-color, outline-offset, background, background-color, background-image, background-repeat, background-attachment, background-position, background-position-x, background-position-y, background-clip, background-origin, background-size, box-decoration-break, box-shadow, text-shadow
ij_scss_space_after_colon = true
ij_scss_space_before_opening_brace = true
ij_scss_use_double_quotes = true
ij_scss_value_alignment = 0
[.editorconfig]
ij_editorconfig_align_group_field_declarations = false
ij_editorconfig_space_after_colon = false
ij_editorconfig_space_after_comma = true
ij_editorconfig_space_before_colon = false
ij_editorconfig_space_before_comma = false
ij_editorconfig_spaces_around_assignment_operators = true
[{*.ant, *.fxml, *.jhm, *.jnlp, *.jrxml, *.pom, *.rng, *.tld, *.wsdl, *.xml, *.xsd, *.xsl, *.xslt, *.xul}]
ij_xml_align_attributes = true
ij_xml_align_text = false
ij_xml_attribute_wrap = normal
ij_xml_block_comment_at_first_column = true
ij_xml_keep_blank_lines = 2
ij_xml_keep_indents_on_empty_lines = false
ij_xml_keep_line_breaks = true
ij_xml_keep_line_breaks_in_text = true
ij_xml_keep_whitespaces = false
ij_xml_keep_whitespaces_around_cdata = preserve
ij_xml_keep_whitespaces_inside_cdata = false
ij_xml_line_comment_at_first_column = true
ij_xml_space_after_tag_name = false
ij_xml_space_around_equals_in_attribute = false
ij_xml_space_inside_empty_tag = false
ij_xml_text_wrap = normal
[{*.ats, *.ts}]
ij_continuation_indent_size = 4
ij_typescript_align_imports = false
ij_typescript_align_multiline_array_initializer_expression = false
ij_typescript_align_multiline_binary_operation = false
ij_typescript_align_multiline_chained_methods = false
ij_typescript_align_multiline_extends_list = false
ij_typescript_align_multiline_for = true
ij_typescript_align_multiline_parameters = true
ij_typescript_align_multiline_parameters_in_calls = false
ij_typescript_align_multiline_ternary_operation = false
ij_typescript_align_object_properties = 0
ij_typescript_align_union_types = false
ij_typescript_align_var_statements = 0
ij_typescript_array_initializer_new_line_after_left_brace = false
ij_typescript_array_initializer_right_brace_on_new_line = false
ij_typescript_array_initializer_wrap = off
ij_typescript_assignment_wrap = off
ij_typescript_binary_operation_sign_on_next_line = false
ij_typescript_binary_operation_wrap = off
ij_typescript_blacklist_imports = rxjs/Rx, node_modules/**, **/node_modules/**, @angular/material, @angular/material/typings/**
ij_typescript_blank_lines_after_imports = 1
ij_typescript_blank_lines_around_class = 1
ij_typescript_blank_lines_around_field = 0
ij_typescript_blank_lines_around_field_in_interface = 0
ij_typescript_blank_lines_around_function = 1
ij_typescript_blank_lines_around_method = 1
ij_typescript_blank_lines_around_method_in_interface = 1
ij_typescript_block_brace_style = end_of_line
ij_typescript_call_parameters_new_line_after_left_paren = false
ij_typescript_call_parameters_right_paren_on_new_line = false
ij_typescript_call_parameters_wrap = off
ij_typescript_catch_on_new_line = false
ij_typescript_chained_call_dot_on_new_line = true
ij_typescript_class_brace_style = end_of_line
ij_typescript_comma_on_new_line = false
ij_typescript_do_while_brace_force = never
ij_typescript_else_on_new_line = false
ij_typescript_enforce_trailing_comma = keep
ij_typescript_extends_keyword_wrap = off
ij_typescript_extends_list_wrap = off
ij_typescript_field_prefix = _
ij_typescript_file_name_style = relaxed
ij_typescript_finally_on_new_line = false
ij_typescript_for_brace_force = never
ij_typescript_for_statement_new_line_after_left_paren = false
ij_typescript_for_statement_right_paren_on_new_line = false
ij_typescript_for_statement_wrap = off
ij_typescript_force_quote_style = false
ij_typescript_force_semicolon_style = false
ij_typescript_function_expression_brace_style = end_of_line
ij_typescript_if_brace_force = never
ij_typescript_import_merge_members = global
ij_typescript_import_prefer_absolute_path = global
ij_typescript_import_sort_members = true
ij_typescript_import_sort_module_name = false
ij_typescript_import_use_node_resolution = true
ij_typescript_imports_wrap = on_every_item
ij_typescript_indent_case_from_switch = true
ij_typescript_indent_chained_calls = true
ij_typescript_indent_package_children = 0
ij_typescript_jsdoc_include_types = false
ij_typescript_jsx_attribute_value = braces
ij_typescript_keep_blank_lines_in_code = 2
ij_typescript_keep_first_column_comment = true
ij_typescript_keep_indents_on_empty_lines = false
ij_typescript_keep_line_breaks = true
ij_typescript_keep_simple_blocks_in_one_line = false
ij_typescript_keep_simple_methods_in_one_line = false
ij_typescript_line_comment_add_space = true
ij_typescript_line_comment_at_first_column = false
ij_typescript_method_brace_style = end_of_line
ij_typescript_method_call_chain_wrap = off
ij_typescript_method_parameters_new_line_after_left_paren = false
ij_typescript_method_parameters_right_paren_on_new_line = false
ij_typescript_method_parameters_wrap = off
ij_typescript_object_literal_wrap = on_every_item
ij_typescript_parentheses_expression_new_line_after_left_paren = false
ij_typescript_parentheses_expression_right_paren_on_new_line = false
ij_typescript_place_assignment_sign_on_next_line = false
ij_typescript_prefer_as_type_cast = false
ij_typescript_prefer_explicit_types_function_expression_returns = false
ij_typescript_prefer_explicit_types_function_returns = false
ij_typescript_prefer_explicit_types_vars_fields = false
ij_typescript_prefer_parameters_wrap = false
ij_typescript_reformat_c_style_comments = false
ij_typescript_space_after_colon = true
ij_typescript_space_after_comma = true
ij_typescript_space_after_dots_in_rest_parameter = false
ij_typescript_space_after_generator_mult = true
ij_typescript_space_after_property_colon = true
ij_typescript_space_after_quest = true
ij_typescript_space_after_type_colon = true
ij_typescript_space_after_unary_not = false
ij_typescript_space_before_async_arrow_lparen = true
ij_typescript_space_before_catch_keyword = true
ij_typescript_space_before_catch_left_brace = true
ij_typescript_space_before_catch_parentheses = true
ij_typescript_space_before_class_lbrace = true
ij_typescript_space_before_class_left_brace = true
ij_typescript_space_before_colon = true
ij_typescript_space_before_comma = false
ij_typescript_space_before_do_left_brace = true
ij_typescript_space_before_else_keyword = true
ij_typescript_space_before_else_left_brace = true
ij_typescript_space_before_finally_keyword = true
ij_typescript_space_before_finally_left_brace = true
ij_typescript_space_before_for_left_brace = true
ij_typescript_space_before_for_parentheses = true
ij_typescript_space_before_for_semicolon = false
ij_typescript_space_before_function_left_parenth = true
ij_typescript_space_before_generator_mult = false
ij_typescript_space_before_if_left_brace = true
ij_typescript_space_before_if_parentheses = true
ij_typescript_space_before_method_call_parentheses = false
ij_typescript_space_before_method_left_brace = true
ij_typescript_space_before_method_parentheses = false
ij_typescript_space_before_property_colon = false
ij_typescript_space_before_quest = true
ij_typescript_space_before_switch_left_brace = true
ij_typescript_space_before_switch_parentheses = true
ij_typescript_space_before_try_left_brace = true
ij_typescript_space_before_type_colon = false
ij_typescript_space_before_unary_not = false
ij_typescript_space_before_while_keyword = true
ij_typescript_space_before_while_left_brace = true
ij_typescript_space_before_while_parentheses = true
ij_typescript_spaces_around_additive_operators = true
ij_typescript_spaces_around_arrow_function_operator = true
ij_typescript_spaces_around_assignment_operators = true
ij_typescript_spaces_around_bitwise_operators = true
ij_typescript_spaces_around_equality_operators = true
ij_typescript_spaces_around_logical_operators = true
ij_typescript_spaces_around_multiplicative_operators = true
ij_typescript_spaces_around_relational_operators = true
ij_typescript_spaces_around_shift_operators = true
ij_typescript_spaces_around_unary_operator = false
ij_typescript_spaces_within_array_initializer_brackets = false
ij_typescript_spaces_within_brackets = false
ij_typescript_spaces_within_catch_parentheses = false
ij_typescript_spaces_within_for_parentheses = false
ij_typescript_spaces_within_if_parentheses = false
ij_typescript_spaces_within_imports = false
ij_typescript_spaces_within_interpolation_expressions = false
ij_typescript_spaces_within_method_call_parentheses = false
ij_typescript_spaces_within_method_parentheses = false
ij_typescript_spaces_within_object_literal_braces = false
ij_typescript_spaces_within_object_type_braces = true
ij_typescript_spaces_within_parentheses = false
ij_typescript_spaces_within_switch_parentheses = false
ij_typescript_spaces_within_type_assertion = false
ij_typescript_spaces_within_union_types = true
ij_typescript_spaces_within_while_parentheses = false
ij_typescript_special_else_if_treatment = true
ij_typescript_ternary_operation_signs_on_next_line = false
ij_typescript_ternary_operation_wrap = off
ij_typescript_union_types_wrap = on_every_item
ij_typescript_use_chained_calls_group_indents = false
ij_typescript_use_double_quotes = true
ij_typescript_use_explicit_js_extension = global
ij_typescript_use_path_mapping = always
ij_typescript_use_public_modifier = false
ij_typescript_use_semicolon_after_statement = true
ij_typescript_var_declaration_wrap = normal
ij_typescript_while_brace_force = never
ij_typescript_while_on_new_line = false
ij_typescript_wrap_comments = false
[{*.bash, *.sh, *.zsh}]
indent_size = 2
tab_width = 2
ij_shell_binary_ops_start_line = false
ij_shell_keep_column_alignment_padding = false
ij_shell_minify_program = false
ij_shell_redirect_followed_by_space = false
ij_shell_switch_cases_indented = false
[{*.cjs, *.js}]
ij_continuation_indent_size = 4
ij_javascript_align_imports = false
ij_javascript_align_multiline_array_initializer_expression = false
ij_javascript_align_multiline_binary_operation = false
ij_javascript_align_multiline_chained_methods = false
ij_javascript_align_multiline_extends_list = false
ij_javascript_align_multiline_for = true
ij_javascript_align_multiline_parameters = true
ij_javascript_align_multiline_parameters_in_calls = false
ij_javascript_align_multiline_ternary_operation = false
ij_javascript_align_object_properties = 0
ij_javascript_align_union_types = false
ij_javascript_align_var_statements = 0
ij_javascript_array_initializer_new_line_after_left_brace = false
ij_javascript_array_initializer_right_brace_on_new_line = false
ij_javascript_array_initializer_wrap = off
ij_javascript_assignment_wrap = off
ij_javascript_binary_operation_sign_on_next_line = false
ij_javascript_binary_operation_wrap = off
ij_javascript_blacklist_imports = rxjs/Rx, node_modules/**, **/node_modules/**, @angular/material, @angular/material/typings/**
ij_javascript_blank_lines_after_imports = 1
ij_javascript_blank_lines_around_class = 1
ij_javascript_blank_lines_around_field = 0
ij_javascript_blank_lines_around_function = 1
ij_javascript_blank_lines_around_method = 1
ij_javascript_block_brace_style = end_of_line
ij_javascript_call_parameters_new_line_after_left_paren = false
ij_javascript_call_parameters_right_paren_on_new_line = false
ij_javascript_call_parameters_wrap = off
ij_javascript_catch_on_new_line = false
ij_javascript_chained_call_dot_on_new_line = true
ij_javascript_class_brace_style = end_of_line
ij_javascript_comma_on_new_line = false
ij_javascript_do_while_brace_force = never
ij_javascript_else_on_new_line = false
ij_javascript_enforce_trailing_comma = keep
ij_javascript_extends_keyword_wrap = off
ij_javascript_extends_list_wrap = off
ij_javascript_field_prefix = _
ij_javascript_file_name_style = relaxed
ij_javascript_finally_on_new_line = false
ij_javascript_for_brace_force = never
ij_javascript_for_statement_new_line_after_left_paren = false
ij_javascript_for_statement_right_paren_on_new_line = false
ij_javascript_for_statement_wrap = off
ij_javascript_force_quote_style = false
ij_javascript_force_semicolon_style = false
ij_javascript_function_expression_brace_style = end_of_line
ij_javascript_if_brace_force = never
ij_javascript_import_merge_members = global
ij_javascript_import_prefer_absolute_path = global
ij_javascript_import_sort_members = true
ij_javascript_import_sort_module_name = false
ij_javascript_import_use_node_resolution = true
ij_javascript_imports_wrap = on_every_item
ij_javascript_indent_case_from_switch = true
ij_javascript_indent_chained_calls = true
ij_javascript_indent_package_children = 0
ij_javascript_jsx_attribute_value = braces
ij_javascript_keep_blank_lines_in_code = 2
ij_javascript_keep_first_column_comment = true
ij_javascript_keep_indents_on_empty_lines = false
ij_javascript_keep_line_breaks = true
ij_javascript_keep_simple_blocks_in_one_line = false
ij_javascript_keep_simple_methods_in_one_line = false
ij_javascript_line_comment_add_space = true
ij_javascript_line_comment_at_first_column = false
ij_javascript_method_brace_style = end_of_line
ij_javascript_method_call_chain_wrap = off
ij_javascript_method_parameters_new_line_after_left_paren = false
ij_javascript_method_parameters_right_paren_on_new_line = false
ij_javascript_method_parameters_wrap = off
ij_javascript_object_literal_wrap = on_every_item
ij_javascript_parentheses_expression_new_line_after_left_paren = false
ij_javascript_parentheses_expression_right_paren_on_new_line = false
ij_javascript_place_assignment_sign_on_next_line = false
ij_javascript_prefer_as_type_cast = false
ij_javascript_prefer_explicit_types_function_expression_returns = false
ij_javascript_prefer_explicit_types_function_returns = false
ij_javascript_prefer_explicit_types_vars_fields = false
ij_javascript_prefer_parameters_wrap = false
ij_javascript_reformat_c_style_comments = false
ij_javascript_space_after_colon = true
ij_javascript_space_after_comma = true
ij_javascript_space_after_dots_in_rest_parameter = false
ij_javascript_space_after_generator_mult = true
ij_javascript_space_after_property_colon = true
ij_javascript_space_after_quest = true
ij_javascript_space_after_type_colon = true
ij_javascript_space_after_unary_not = false
ij_javascript_space_before_async_arrow_lparen = true
ij_javascript_space_before_catch_keyword = true
ij_javascript_space_before_catch_left_brace = true
ij_javascript_space_before_catch_parentheses = true
ij_javascript_space_before_class_lbrace = true
ij_javascript_space_before_class_left_brace = true
ij_javascript_space_before_colon = true
ij_javascript_space_before_comma = false
ij_javascript_space_before_do_left_brace = true
ij_javascript_space_before_else_keyword = true
ij_javascript_space_before_else_left_brace = true
ij_javascript_space_before_finally_keyword = true
ij_javascript_space_before_finally_left_brace = true
ij_javascript_space_before_for_left_brace = true
ij_javascript_space_before_for_parentheses = true
ij_javascript_space_before_for_semicolon = false
ij_javascript_space_before_function_left_parenth = true
ij_javascript_space_before_generator_mult = false
ij_javascript_space_before_if_left_brace = true
ij_javascript_space_before_if_parentheses = true
ij_javascript_space_before_method_call_parentheses = false
ij_javascript_space_before_method_left_brace = true
ij_javascript_space_before_method_parentheses = false
ij_javascript_space_before_property_colon = false
ij_javascript_space_before_quest = true
ij_javascript_space_before_switch_left_brace = true
ij_javascript_space_before_switch_parentheses = true
ij_javascript_space_before_try_left_brace = true
ij_javascript_space_before_type_colon = false
ij_javascript_space_before_unary_not = false
ij_javascript_space_before_while_keyword = true
ij_javascript_space_before_while_left_brace = true
ij_javascript_space_before_while_parentheses = true
ij_javascript_spaces_around_additive_operators = true
ij_javascript_spaces_around_arrow_function_operator = true
ij_javascript_spaces_around_assignment_operators = true
ij_javascript_spaces_around_bitwise_operators = true
ij_javascript_spaces_around_equality_operators = true
ij_javascript_spaces_around_logical_operators = true
ij_javascript_spaces_around_multiplicative_operators = true
ij_javascript_spaces_around_relational_operators = true
ij_javascript_spaces_around_shift_operators = true
ij_javascript_spaces_around_unary_operator = false
ij_javascript_spaces_within_array_initializer_brackets = false
ij_javascript_spaces_within_brackets = false
ij_javascript_spaces_within_catch_parentheses = false
ij_javascript_spaces_within_for_parentheses = false
ij_javascript_spaces_within_if_parentheses = false
ij_javascript_spaces_within_imports = false
ij_javascript_spaces_within_interpolation_expressions = false
ij_javascript_spaces_within_method_call_parentheses = false
ij_javascript_spaces_within_method_parentheses = false
ij_javascript_spaces_within_object_literal_braces = false
ij_javascript_spaces_within_object_type_braces = true
ij_javascript_spaces_within_parentheses = false
ij_javascript_spaces_within_switch_parentheses = false
ij_javascript_spaces_within_type_assertion = false
ij_javascript_spaces_within_union_types = true
ij_javascript_spaces_within_while_parentheses = false
ij_javascript_special_else_if_treatment = true
ij_javascript_ternary_operation_signs_on_next_line = false
ij_javascript_ternary_operation_wrap = off
ij_javascript_union_types_wrap = on_every_item
ij_javascript_use_chained_calls_group_indents = false
ij_javascript_use_double_quotes = true
ij_javascript_use_explicit_js_extension = global
ij_javascript_use_path_mapping = always
ij_javascript_use_public_modifier = false
ij_javascript_use_semicolon_after_statement = true
ij_javascript_var_declaration_wrap = normal
ij_javascript_while_brace_force = never
ij_javascript_while_on_new_line = false
ij_javascript_wrap_comments = false
[{*.ft, *.vm, *.vsl}]
ij_vtl_keep_indents_on_empty_lines = false
[{*.gant, *.gradle, *.groovy, *.gy}]
ij_groovy_align_group_field_declarations = false
ij_groovy_align_multiline_array_initializer_expression = false
ij_groovy_align_multiline_assignment = false
ij_groovy_align_multiline_binary_operation = false
ij_groovy_align_multiline_chained_methods = false
ij_groovy_align_multiline_extends_list = false
ij_groovy_align_multiline_for = true
ij_groovy_align_multiline_list_or_map = true
ij_groovy_align_multiline_method_parentheses = false
ij_groovy_align_multiline_parameters = true
ij_groovy_align_multiline_parameters_in_calls = false
ij_groovy_align_multiline_resources = true
ij_groovy_align_multiline_ternary_operation = false
ij_groovy_align_multiline_throws_list = false
ij_groovy_align_named_args_in_map = true
ij_groovy_align_throws_keyword = false
ij_groovy_array_initializer_new_line_after_left_brace = false
ij_groovy_array_initializer_right_brace_on_new_line = false
ij_groovy_array_initializer_wrap = off
ij_groovy_assert_statement_wrap = off
ij_groovy_assignment_wrap = off
ij_groovy_binary_operation_wrap = off
ij_groovy_blank_lines_after_class_header = 0
ij_groovy_blank_lines_after_imports = 1
ij_groovy_blank_lines_after_package = 1
ij_groovy_blank_lines_around_class = 1
ij_groovy_blank_lines_around_field = 0
ij_groovy_blank_lines_around_field_in_interface = 0
ij_groovy_blank_lines_around_method = 1
ij_groovy_blank_lines_around_method_in_interface = 1
ij_groovy_blank_lines_before_imports = 1
ij_groovy_blank_lines_before_method_body = 0
ij_groovy_blank_lines_before_package = 0
ij_groovy_block_brace_style = end_of_line
ij_groovy_block_comment_at_first_column = true
ij_groovy_call_parameters_new_line_after_left_paren = false
ij_groovy_call_parameters_right_paren_on_new_line = false
ij_groovy_call_parameters_wrap = off
ij_groovy_catch_on_new_line = false
ij_groovy_class_annotation_wrap = split_into_lines
ij_groovy_class_brace_style = end_of_line
ij_groovy_class_count_to_use_import_on_demand = 5
ij_groovy_do_while_brace_force = never
ij_groovy_else_on_new_line = false
ij_groovy_enum_constants_wrap = off
ij_groovy_extends_keyword_wrap = off
ij_groovy_extends_list_wrap = off
ij_groovy_field_annotation_wrap = split_into_lines
ij_groovy_finally_on_new_line = false
ij_groovy_for_brace_force = never
ij_groovy_for_statement_new_line_after_left_paren = false
ij_groovy_for_statement_right_paren_on_new_line = false
ij_groovy_for_statement_wrap = off
ij_groovy_if_brace_force = never
ij_groovy_import_annotation_wrap = 2
ij_groovy_imports_layout = *, |, javax.**, java.**, |, $*
ij_groovy_indent_case_from_switch = true
ij_groovy_indent_label_blocks = true
ij_groovy_insert_inner_class_imports = false
ij_groovy_keep_blank_lines_before_right_brace = 2
ij_groovy_keep_blank_lines_in_code = 2
ij_groovy_keep_blank_lines_in_declarations = 2
ij_groovy_keep_control_statement_in_one_line = true
ij_groovy_keep_first_column_comment = true
ij_groovy_keep_indents_on_empty_lines = false
ij_groovy_keep_line_breaks = true
ij_groovy_keep_multiple_expressions_in_one_line = false
ij_groovy_keep_simple_blocks_in_one_line = false
ij_groovy_keep_simple_classes_in_one_line = true
ij_groovy_keep_simple_lambdas_in_one_line = true
ij_groovy_keep_simple_methods_in_one_line = true
ij_groovy_label_indent_absolute = false
ij_groovy_label_indent_size = 0
ij_groovy_lambda_brace_style = end_of_line
ij_groovy_layout_static_imports_separately = true
ij_groovy_line_comment_add_space = false
ij_groovy_line_comment_at_first_column = true
ij_groovy_method_annotation_wrap = split_into_lines
ij_groovy_method_brace_style = end_of_line
ij_groovy_method_call_chain_wrap = off
ij_groovy_method_parameters_new_line_after_left_paren = false
ij_groovy_method_parameters_right_paren_on_new_line = false
ij_groovy_method_parameters_wrap = off
ij_groovy_modifier_list_wrap = false
ij_groovy_names_count_to_use_import_on_demand = 3
ij_groovy_parameter_annotation_wrap = off
ij_groovy_parentheses_expression_new_line_after_left_paren = false
ij_groovy_parentheses_expression_right_paren_on_new_line = false
ij_groovy_prefer_parameters_wrap = false
ij_groovy_resource_list_new_line_after_left_paren = false
ij_groovy_resource_list_right_paren_on_new_line = false
ij_groovy_resource_list_wrap = off
ij_groovy_space_after_assert_separator = true
ij_groovy_space_after_colon = true
ij_groovy_space_after_comma = true
ij_groovy_space_after_comma_in_type_arguments = true
ij_groovy_space_after_for_semicolon = true
ij_groovy_space_after_quest = true
ij_groovy_space_after_type_cast = true
ij_groovy_space_before_annotation_parameter_list = false
ij_groovy_space_before_array_initializer_left_brace = false
ij_groovy_space_before_assert_separator = false
ij_groovy_space_before_catch_keyword = true
ij_groovy_space_before_catch_left_brace = true
ij_groovy_space_before_catch_parentheses = true
ij_groovy_space_before_class_left_brace = true
ij_groovy_space_before_closure_left_brace = true
ij_groovy_space_before_colon = true
ij_groovy_space_before_comma = false
ij_groovy_space_before_do_left_brace = true
ij_groovy_space_before_else_keyword = true
ij_groovy_space_before_else_left_brace = true
ij_groovy_space_before_finally_keyword = true
ij_groovy_space_before_finally_left_brace = true
ij_groovy_space_before_for_left_brace = true
ij_groovy_space_before_for_parentheses = true
ij_groovy_space_before_for_semicolon = false
ij_groovy_space_before_if_left_brace = true
ij_groovy_space_before_if_parentheses = true
ij_groovy_space_before_method_call_parentheses = false
ij_groovy_space_before_method_left_brace = true
ij_groovy_space_before_method_parentheses = false
ij_groovy_space_before_quest = true
ij_groovy_space_before_switch_left_brace = true
ij_groovy_space_before_switch_parentheses = true
ij_groovy_space_before_synchronized_left_brace = true
ij_groovy_space_before_synchronized_parentheses = true
ij_groovy_space_before_try_left_brace = true
ij_groovy_space_before_try_parentheses = true
ij_groovy_space_before_while_keyword = true
ij_groovy_space_before_while_left_brace = true
ij_groovy_space_before_while_parentheses = true
ij_groovy_space_in_named_argument = true
ij_groovy_space_in_named_argument_before_colon = false
ij_groovy_space_within_empty_array_initializer_braces = false
ij_groovy_space_within_empty_method_call_parentheses = false
ij_groovy_spaces_around_additive_operators = true
ij_groovy_spaces_around_assignment_operators = true
ij_groovy_spaces_around_bitwise_operators = true
ij_groovy_spaces_around_equality_operators = true
ij_groovy_spaces_around_lambda_arrow = true
ij_groovy_spaces_around_logical_operators = true
ij_groovy_spaces_around_multiplicative_operators = true
ij_groovy_spaces_around_regex_operators = true
ij_groovy_spaces_around_relational_operators = true
ij_groovy_spaces_around_shift_operators = true
ij_groovy_spaces_within_annotation_parentheses = false
ij_groovy_spaces_within_array_initializer_braces = false
ij_groovy_spaces_within_braces = true
ij_groovy_spaces_within_brackets = false
ij_groovy_spaces_within_cast_parentheses = false
ij_groovy_spaces_within_catch_parentheses = false
ij_groovy_spaces_within_for_parentheses = false
ij_groovy_spaces_within_gstring_injection_braces = false
ij_groovy_spaces_within_if_parentheses = false
ij_groovy_spaces_within_list_or_map = false
ij_groovy_spaces_within_method_call_parentheses = false
ij_groovy_spaces_within_method_parentheses = false
ij_groovy_spaces_within_parentheses = false
ij_groovy_spaces_within_switch_parentheses = false
ij_groovy_spaces_within_synchronized_parentheses = false
ij_groovy_spaces_within_try_parentheses = false
ij_groovy_spaces_within_tuple_expression = false
ij_groovy_spaces_within_while_parentheses = false
ij_groovy_special_else_if_treatment = true
ij_groovy_ternary_operation_wrap = off
ij_groovy_throws_keyword_wrap = off
ij_groovy_throws_list_wrap = off
ij_groovy_use_flying_geese_braces = false
ij_groovy_use_fq_class_names = false
ij_groovy_use_fq_class_names_in_javadoc = true
ij_groovy_use_relative_indents = false
ij_groovy_use_single_class_imports = true
ij_groovy_variable_annotation_wrap = off
ij_groovy_while_brace_force = never
ij_groovy_while_on_new_line = false
ij_groovy_wrap_long_lines = false
[{*.gradle.kts, *.kt, *.kts, *.main.kts}]
ij_kotlin_align_in_columns_case_branch = false
ij_kotlin_align_multiline_binary_operation = false
ij_kotlin_align_multiline_extends_list = false
ij_kotlin_align_multiline_method_parentheses = false
ij_kotlin_align_multiline_parameters = true
ij_kotlin_align_multiline_parameters_in_calls = false
ij_kotlin_allow_trailing_comma = false
ij_kotlin_allow_trailing_comma_on_call_site = false
ij_kotlin_assignment_wrap = off
ij_kotlin_blank_lines_after_class_header = 0
ij_kotlin_blank_lines_around_block_when_branches = 0
ij_kotlin_blank_lines_before_declaration_with_comment_or_annotation_on_separate_line = 1
ij_kotlin_block_comment_at_first_column = true
ij_kotlin_call_parameters_new_line_after_left_paren = false
ij_kotlin_call_parameters_right_paren_on_new_line = false
ij_kotlin_call_parameters_wrap = off
ij_kotlin_catch_on_new_line = false
ij_kotlin_class_annotation_wrap = split_into_lines
ij_kotlin_continuation_indent_for_chained_calls = true
ij_kotlin_continuation_indent_for_expression_bodies = true
ij_kotlin_continuation_indent_in_argument_lists = true
ij_kotlin_continuation_indent_in_elvis = true
ij_kotlin_continuation_indent_in_if_conditions = true
ij_kotlin_continuation_indent_in_parameter_lists = true
ij_kotlin_continuation_indent_in_supertype_lists = true
ij_kotlin_else_on_new_line = false
ij_kotlin_enum_constants_wrap = off
ij_kotlin_extends_list_wrap = off
ij_kotlin_field_annotation_wrap = split_into_lines
ij_kotlin_finally_on_new_line = false
ij_kotlin_if_rparen_on_new_line = false
ij_kotlin_import_nested_classes = false
ij_kotlin_insert_whitespaces_in_simple_one_line_method = true
ij_kotlin_keep_blank_lines_before_right_brace = 2
ij_kotlin_keep_blank_lines_in_code = 2
ij_kotlin_keep_blank_lines_in_declarations = 2
ij_kotlin_keep_first_column_comment = true
ij_kotlin_keep_indents_on_empty_lines = false
ij_kotlin_keep_line_breaks = true
ij_kotlin_lbrace_on_next_line = false
ij_kotlin_line_comment_add_space = false
ij_kotlin_line_comment_at_first_column = true
ij_kotlin_method_annotation_wrap = split_into_lines
ij_kotlin_method_call_chain_wrap = off
ij_kotlin_method_parameters_new_line_after_left_paren = false
ij_kotlin_method_parameters_right_paren_on_new_line = false
ij_kotlin_method_parameters_wrap = off
ij_kotlin_name_count_to_use_star_import = 5
ij_kotlin_name_count_to_use_star_import_for_members = 3
ij_kotlin_parameter_annotation_wrap = off
ij_kotlin_space_after_comma = true
ij_kotlin_space_after_extend_colon = true
ij_kotlin_space_after_type_colon = true
ij_kotlin_space_before_catch_parentheses = true
ij_kotlin_space_before_comma = false
ij_kotlin_space_before_extend_colon = true
ij_kotlin_space_before_for_parentheses = true
ij_kotlin_space_before_if_parentheses = true
ij_kotlin_space_before_lambda_arrow = true
ij_kotlin_space_before_type_colon = false
ij_kotlin_space_before_when_parentheses = true
ij_kotlin_space_before_while_parentheses = true
ij_kotlin_spaces_around_additive_operators = true
ij_kotlin_spaces_around_assignment_operators = true
ij_kotlin_spaces_around_equality_operators = true
ij_kotlin_spaces_around_function_type_arrow = true
ij_kotlin_spaces_around_logical_operators = true
ij_kotlin_spaces_around_multiplicative_operators = true
ij_kotlin_spaces_around_range = false
ij_kotlin_spaces_around_relational_operators = true
ij_kotlin_spaces_around_unary_operator = false
ij_kotlin_spaces_around_when_arrow = true
ij_kotlin_variable_annotation_wrap = off
ij_kotlin_while_on_new_line = false
ij_kotlin_wrap_elvis_expressions = 1
ij_kotlin_wrap_expression_body_functions = 0
ij_kotlin_wrap_first_method_in_call_chain = false
[{*.har, *.jsb2, *.jsb3, *.json, .babelrc, .eslintrc, .stylelintrc, bowerrc, jest.config, mcmod.info}]
indent_size = 2
ij_json_keep_blank_lines_in_code = 0
ij_json_keep_indents_on_empty_lines = false
ij_json_keep_line_breaks = true
ij_json_space_after_colon = true
ij_json_space_after_comma = true
ij_json_space_before_colon = true
ij_json_space_before_comma = false
ij_json_spaces_within_braces = false
ij_json_spaces_within_brackets = false
ij_json_wrap_long_lines = false
[{*.htm, *.html, *.sht, *.shtm, *.shtml}]
ij_html_add_new_line_before_tags = body, div, p, form, h1, h2, h3
ij_html_align_attributes = true
ij_html_align_text = false
ij_html_attribute_wrap = normal
ij_html_block_comment_at_first_column = true
ij_html_do_not_align_children_of_min_lines = 0
ij_html_do_not_break_if_inline_tags = title, h1, h2, h3, h4, h5, h6, p
ij_html_do_not_indent_children_of_tags = html, body, thead, tbody, tfoot
ij_html_enforce_quotes = false
ij_html_inline_tags = a, abbr, acronym, b, basefont, bdo, big, br, cite, cite, code, dfn, em, font, i, img, input, kbd, label, q, s, samp, select, small, span, strike, strong, sub, sup, textarea, tt, u, var
ij_html_keep_blank_lines = 2
ij_html_keep_indents_on_empty_lines = false
ij_html_keep_line_breaks = true
ij_html_keep_line_breaks_in_text = true
ij_html_keep_whitespaces = false
ij_html_keep_whitespaces_inside = span, pre, textarea
ij_html_line_comment_at_first_column = true
ij_html_new_line_after_last_attribute = never
ij_html_new_line_before_first_attribute = never
ij_html_quote_style = double
ij_html_remove_new_line_before_tags = br
ij_html_space_after_tag_name = false
ij_html_space_around_equality_in_attribute = false
ij_html_space_inside_empty_tag = false
ij_html_text_wrap = normal
ij_html_uniform_ident = false
[{*.yaml, *.yml}]
indent_size = 2
ij_yaml_keep_indents_on_empty_lines = false
ij_yaml_keep_line_breaks = true
ij_yaml_space_before_colon = true
ij_yaml_spaces_within_braces = true
ij_yaml_spaces_within_brackets = true

2
.github/FUNDING.yml vendored
View file

@ -9,4 +9,4 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: ['https://paypal.me/Sauilitired']# Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
custom: [ 'https://paypal.me/Sauilitired' ]# Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

View file

@ -5,7 +5,7 @@
version: 2
updates:
- package-ecosystem: "maven" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"
- package-ecosystem: "maven" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"

View file

@ -4,21 +4,21 @@
name: Java CI with Maven
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Gradle
run: ./gradlew clean build
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Gradle
run: ./gradlew clean build

View file

@ -171,9 +171,11 @@ subprojects {
}
signing {
required { project.hasProperty('signing.keyId') && (gradle.taskGraph.hasTask(':publish')
|| gradle.taskGraph.hasTask(':publishToSonatype')
|| gradle.taskGraph.hasTask(':publishToMavenLocal')) }
required {
project.hasProperty('signing.keyId') && (gradle.taskGraph.hasTask(':publish')
|| gradle.taskGraph.hasTask(':publishToSonatype')
|| gradle.taskGraph.hasTask(':publishToMavenLocal'))
}
sign publishing.publications.mavenJava
}

View file

@ -30,13 +30,13 @@ import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.arguments.flags.CommandFlag;
import cloud.commandframework.arguments.parser.ArgumentParser;
import cloud.commandframework.arguments.parser.ParserParameter;
import cloud.commandframework.arguments.parser.ParserParameters;
import cloud.commandframework.arguments.parser.StandardParameters;
import cloud.commandframework.execution.CommandExecutionHandler;
import cloud.commandframework.extra.confirmation.CommandConfirmationManager;
import cloud.commandframework.meta.CommandMeta;
import cloud.commandframework.meta.SimpleCommandMeta;
import io.leangen.geantyref.TypeToken;
import cloud.commandframework.arguments.parser.ParserParameters;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@ -77,9 +77,11 @@ public final class AnnotationParser<C> {
* {@link ParserParameter}. Mappers for the
* parser parameters can be registered using {@link #registerAnnotationMapper(Class, Function)}
*/
public AnnotationParser(final @NonNull CommandManager<C> manager,
final @NonNull Class<C> commandSenderClass,
final @NonNull Function<@NonNull ParserParameters, @NonNull CommandMeta> metaMapper) {
public AnnotationParser(
final @NonNull CommandManager<C> manager,
final @NonNull Class<C> commandSenderClass,
final @NonNull Function<@NonNull ParserParameters, @NonNull CommandMeta> metaMapper
) {
this.commandSenderClass = commandSenderClass;
this.manager = manager;
this.metaFactory = new MetaFactory(this, metaMapper);
@ -96,9 +98,11 @@ public final class AnnotationParser<C> {
* @param mapper Mapping function
* @param <A> Annotation type
*/
public <A extends Annotation> void registerAnnotationMapper(final @NonNull Class<A> annotation,
final @NonNull Function<@NonNull A,
@NonNull ParserParameters> mapper) {
public <A extends Annotation> void registerAnnotationMapper(
final @NonNull Class<A> annotation,
final @NonNull Function<@NonNull A,
@NonNull ParserParameters> mapper
) {
this.annotationMappers.put(annotation, mapper);
}
@ -122,8 +126,10 @@ public final class AnnotationParser<C> {
method.setAccessible(true);
}
if (method.getReturnType() != Void.TYPE) {
throw new IllegalArgumentException(String.format("@CommandMethod annotated method '%s' has non-void return type",
method.getName()));
throw new IllegalArgumentException(String.format(
"@CommandMethod annotated method '%s' has non-void return type",
method.getName()
));
}
commandMethodPairs.add(new CommandMethodPair(method, commandMethod));
}
@ -139,7 +145,8 @@ public final class AnnotationParser<C> {
@SuppressWarnings("unchecked")
private @NonNull Collection<@NonNull Command<C>> construct(
final @NonNull Object instance,
final @NonNull Collection<@NonNull CommandMethodPair> methodPairs) {
final @NonNull Collection<@NonNull CommandMethodPair> methodPairs
) {
final Collection<Command<C>> commands = new ArrayList<>();
for (final CommandMethodPair commandMethodPair : methodPairs) {
final CommandMethod commandMethod = commandMethodPair.getCommandMethod();
@ -149,24 +156,28 @@ public final class AnnotationParser<C> {
final String commandToken = commandMethod.value().split(" ")[0].split("\\|")[0];
@SuppressWarnings("ALL") final CommandManager manager = this.manager;
final SimpleCommandMeta.Builder metaBuilder = SimpleCommandMeta.builder()
.with(this.metaFactory.apply(method.getAnnotations()));
.with(this.metaFactory.apply(method.getAnnotations()));
if (method.isAnnotationPresent(Confirmation.class)) {
metaBuilder.with(CommandConfirmationManager.CONFIRMATION_REQUIRED_META, "true");
}
@SuppressWarnings("ALL")
Command.Builder builder = manager.commandBuilder(commandToken,
tokens.get(commandToken).getMinor(),
metaBuilder.build());
Command.Builder builder = manager.commandBuilder(
commandToken,
tokens.get(commandToken).getMinor(),
metaBuilder.build()
);
final Collection<ArgumentParameterPair> arguments = this.argumentExtractor.apply(method);
final Collection<CommandFlag<?>> flags = this.flagExtractor.apply(method);
final Map<String, CommandArgument<C, ?>> commandArguments = new HashMap<>();
final Map<CommandArgument<C, ?>, String> argumentDescriptions = new HashMap<>();
/* Go through all annotated parameters and build up the argument tree */
for (final ArgumentParameterPair argumentPair : arguments) {
final CommandArgument<C, ?> argument = this.buildArgument(method,
tokens.get(argumentPair.getArgument().value()),
argumentPair);
final CommandArgument<C, ?> argument = this.buildArgument(
method,
tokens.get(argumentPair.getArgument().value()),
argumentPair
);
commandArguments.put(argument.getName(), argument);
argumentDescriptions.put(argument, argumentPair.getArgument().description());
}
@ -209,9 +220,9 @@ public final class AnnotationParser<C> {
}
if (commandMethod.requiredSender() != Object.class) {
builder = builder.withSenderType(commandMethod.requiredSender());
builder = builder.senderType(commandMethod.requiredSender());
} else if (senderType != null) {
builder = builder.withSenderType(senderType);
builder = builder.senderType(senderType);
}
try {
/* Construct the handler */
@ -240,7 +251,7 @@ public final class AnnotationParser<C> {
throw new IllegalArgumentException("@ProxiedBy proxies may only contain single literals");
}
Command.Builder<C> proxyBuilder = manager.commandBuilder(proxy, builtCommand.getCommandMeta())
.proxies(builtCommand);
.proxies(builtCommand);
if (proxyAnnotation.hidden()) {
proxyBuilder = proxyBuilder.hidden();
}
@ -251,34 +262,38 @@ public final class AnnotationParser<C> {
}
@SuppressWarnings("unchecked")
private @NonNull CommandArgument<C, ?> buildArgument(final @NonNull Method method,
final @Nullable SyntaxFragment syntaxFragment,
final @NonNull ArgumentParameterPair argumentPair) {
private @NonNull CommandArgument<C, ?> buildArgument(
final @NonNull Method method,
final @Nullable SyntaxFragment syntaxFragment,
final @NonNull ArgumentParameterPair argumentPair
) {
final Parameter parameter = argumentPair.getParameter();
final Collection<Annotation> annotations = Arrays.asList(parameter.getAnnotations());
final TypeToken<?> token = TypeToken.get(parameter.getParameterizedType());
final ParserParameters parameters = this.manager.getParserRegistry()
.parseAnnotations(token, annotations);
.parseAnnotations(token, annotations);
final ArgumentParser<C, ?> parser;
if (argumentPair.getArgument().parserName().isEmpty()) {
parser = this.manager.getParserRegistry()
.createParser(token, parameters)
.orElseThrow(() -> new IllegalArgumentException(
String.format("Parameter '%s' in method '%s' "
+ "has parser '%s' but no parser exists "
+ "for that type",
parameter.getName(), method.getName(),
token.toString())));
.createParser(token, parameters)
.orElseThrow(() -> new IllegalArgumentException(
String.format("Parameter '%s' in method '%s' "
+ "has parser '%s' but no parser exists "
+ "for that type",
parameter.getName(), method.getName(),
token.toString()
)));
} else {
parser = this.manager.getParserRegistry()
.createParser(argumentPair.getArgument().parserName(), parameters)
.orElseThrow(() -> new IllegalArgumentException(
String.format("Parameter '%s' in method '%s' "
+ "has parser '%s' but no parser exists "
+ "for that type",
parameter.getName(), method.getName(),
token.toString())));
.createParser(argumentPair.getArgument().parserName(), parameters)
.orElseThrow(() -> new IllegalArgumentException(
String.format("Parameter '%s' in method '%s' "
+ "has parser '%s' but no parser exists "
+ "for that type",
parameter.getName(), method.getName(),
token.toString()
)));
}
if (syntaxFragment == null || syntaxFragment.getArgumentMode() == ArgumentMode.LITERAL) {
@ -287,8 +302,10 @@ public final class AnnotationParser<C> {
+ "Missing syntax mapping", argumentPair.getArgument().value(), method.getName()));
}
final Argument argument = argumentPair.getArgument();
@SuppressWarnings("ALL") final CommandArgument.Builder argumentBuilder = CommandArgument.ofType(parameter.getType(),
argument.value());
@SuppressWarnings("ALL") final CommandArgument.Builder argumentBuilder = CommandArgument.ofType(
parameter.getType(),
argument.value()
);
if (syntaxFragment.getArgumentMode() == ArgumentMode.OPTIONAL) {
if (argument.defaultValue().isEmpty()) {
argumentBuilder.asOptional();

View file

@ -32,8 +32,10 @@ final class ArgumentParameterPair {
private final Parameter parameter;
private final Argument argument;
ArgumentParameterPair(final @NonNull Parameter parameter,
final @NonNull Argument argument) {
ArgumentParameterPair(
final @NonNull Parameter parameter,
final @NonNull Argument argument
) {
this.parameter = parameter;
this.argument = argument;
}

View file

@ -32,8 +32,10 @@ final class CommandMethodPair {
private final Method method;
private final CommandMethod commandMethod;
CommandMethodPair(final @NonNull Method method,
final @NonNull CommandMethod commandMethod) {
CommandMethodPair(
final @NonNull Method method,
final @NonNull CommandMethod commandMethod
) {
this.method = method;
this.commandMethod = commandMethod;
}

View file

@ -34,4 +34,5 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Confirmation {
}

View file

@ -55,8 +55,10 @@ final class FlagExtractor implements Function<@NonNull Method, Collection<@NonNu
continue;
}
final Flag flag = parameter.getAnnotation(Flag.class);
final CommandFlag.Builder<Void> builder = this.commandManager.flagBuilder(flag.value())
.withDescription(Description.of(flag.description())).withAliases(flag.aliases());
final CommandFlag.Builder<Void> builder = this.commandManager
.flagBuilder(flag.value())
.withDescription(Description.of(flag.description()))
.withAliases(flag.aliases());
if (parameter.getType().equals(boolean.class)) {
flags.add(builder.build());
} else {
@ -72,15 +74,17 @@ final class FlagExtractor implements Function<@NonNull Method, Collection<@NonNu
if (parser == null) {
throw new IllegalArgumentException(
String.format("Cannot find parser for type '%s' for flag '%s' in method '%s'",
parameter.getType().getCanonicalName(), flag.value(), method.getName()));
parameter.getType().getCanonicalName(), flag.value(), method.getName()
));
}
@SuppressWarnings("ALL")
final CommandArgument.Builder argumentBuilder = CommandArgument.ofType(parameter.getType(), flag.value());
@SuppressWarnings("ALL")
final CommandArgument argument = argumentBuilder.asRequired()
.manager(this.commandManager)
.withParser(parser)
.build();
@SuppressWarnings("ALL") final CommandArgument.Builder argumentBuilder = CommandArgument.ofType(
parameter.getType(),
flag.value()
);
@SuppressWarnings("ALL") final CommandArgument argument = argumentBuilder.asRequired()
.manager(this.commandManager)
.withParser(parser)
.build();
// noinspection unchecked
flags.add(builder.withArgument(argument).build());
}

View file

@ -36,4 +36,5 @@ import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Hidden {
}

View file

@ -35,8 +35,10 @@ class MetaFactory implements Function<@NonNull Annotation @NonNull [], @NonNull
private final AnnotationParser<?> annotationParser;
private final Function<ParserParameters, CommandMeta> metaMapper;
MetaFactory(final @NonNull AnnotationParser<?> annotationParser,
final @NonNull Function<@NonNull ParserParameters, @NonNull CommandMeta> metaMapper) {
MetaFactory(
final @NonNull AnnotationParser<?> annotationParser,
final @NonNull Function<@NonNull ParserParameters, @NonNull CommandMeta> metaMapper
) {
this.annotationParser = annotationParser;
this.metaMapper = metaMapper;
}
@ -46,7 +48,7 @@ class MetaFactory implements Function<@NonNull Annotation @NonNull [], @NonNull
final ParserParameters parameters = ParserParameters.empty();
for (final Annotation annotation : annotations) {
@SuppressWarnings("ALL") final Function function = this.annotationParser.getAnnotationMappers()
.get(annotation.annotationType());
.get(annotation.annotationType());
if (function == null) {
continue;
}

View file

@ -43,10 +43,12 @@ class MethodCommandExecutionHandler<C> implements CommandExecutionHandler<C> {
private final MethodHandle methodHandle;
private final Map<String, CommandArgument<C, ?>> commandArguments;
MethodCommandExecutionHandler(final @NonNull Object instance,
final @NonNull Map<@NonNull String,
@NonNull CommandArgument<@NonNull C, @NonNull ?>> commandArguments,
@NonNull final Method method) throws Exception {
MethodCommandExecutionHandler(
final @NonNull Object instance,
final @NonNull Map<@NonNull String,
@NonNull CommandArgument<@NonNull C, @NonNull ?>> commandArguments,
@NonNull final Method method
) throws Exception {
this.commandArguments = commandArguments;
method.setAccessible(true);
this.methodHandle = MethodHandles.lookup().unreflect(method).bindTo(instance);

View file

@ -33,9 +33,11 @@ final class SyntaxFragment {
private final List<String> minor;
private final ArgumentMode argumentMode;
SyntaxFragment(final @NonNull String major,
final @NonNull List<@NonNull String> minor,
final @NonNull ArgumentMode argumentMode) {
SyntaxFragment(
final @NonNull String major,
final @NonNull List<@NonNull String> minor,
final @NonNull ArgumentMode argumentMode
) {
this.major = major;
this.minor = minor;
this.argumentMode = argumentMode;

View file

@ -40,11 +40,11 @@ import java.util.regex.Pattern;
final class SyntaxParser implements Function<@NonNull String, @NonNull LinkedHashMap<@NonNull String, @NonNull SyntaxFragment>> {
private static final Predicate<String> PATTERN_ARGUMENT_LITERAL = Pattern.compile("([A-Za-z0-9]+)(|([A-Za-z0-9]+))*")
.asPredicate();
.asPredicate();
private static final Predicate<String> PATTERN_ARGUMENT_REQUIRED = Pattern.compile("<([A-Za-z0-9]+)>")
.asPredicate();
.asPredicate();
private static final Predicate<String> PATTERN_ARGUMENT_OPTIONAL = Pattern.compile("\\[([A-Za-z0-9]+)]")
.asPredicate();
.asPredicate();
@Override
public @NonNull LinkedHashMap<@NonNull String, @NonNull SyntaxFragment> apply(final @NonNull String syntax) {

View file

@ -64,17 +64,20 @@ class AnnotationParserTest {
@ProxiedBy("proxycommand")
@CommandMethod("test|t literal <int> [string]")
public void testCommand(final TestCommandSender sender,
@Argument("int") @Range(max = "100") final int argument,
@Argument(value = "string", defaultValue = "potato", parserName = "potato")
final String string) {
public void testCommand(
final TestCommandSender sender,
@Argument("int") @Range(max = "100") final int argument,
@Argument(value = "string", defaultValue = "potato", parserName = "potato") final String string
) {
System.out.printf("Received int: %d and string '%s'\n", argument, string);
}
@CommandMethod("flagcommand")
public void testFlags(final TestCommandSender sender,
@Flag(value = "print", aliases = "p") boolean print,
@Flag(value = "word", aliases = "w") String word) {
public void testFlags(
final TestCommandSender sender,
@Flag(value = "print", aliases = "p") boolean print,
@Flag(value = "word", aliases = "w") String word
) {
if (print) {
System.out.println(word);
}

View file

@ -40,8 +40,10 @@ public class TestCommandManager extends CommandManager<TestCommandSender> {
}
@Override
public final boolean hasPermission(final TestCommandSender sender,
final String permission) {
public final boolean hasPermission(
final TestCommandSender sender,
final String permission
) {
return !permission.equalsIgnoreCase("no");
}

View file

@ -73,11 +73,13 @@ public class Command<C> {
* @param commandPermission Command permission
* @param commandMeta Command meta instance
*/
public Command(final @NonNull Map<@NonNull CommandArgument<C, ?>, @NonNull Description> commandArguments,
final @NonNull CommandExecutionHandler<@NonNull C> commandExecutionHandler,
final @Nullable Class<? extends C> senderType,
final @NonNull CommandPermission commandPermission,
final @NonNull CommandMeta commandMeta) {
public Command(
final @NonNull Map<@NonNull CommandArgument<C, ?>, @NonNull Description> commandArguments,
final @NonNull CommandExecutionHandler<@NonNull C> commandExecutionHandler,
final @Nullable Class<? extends C> senderType,
final @NonNull CommandPermission commandPermission,
final @NonNull CommandMeta commandMeta
) {
this.arguments = Objects.requireNonNull(commandArguments, "Command arguments may not be null");
if (this.arguments.size() == 0) {
throw new IllegalArgumentException("At least one command argument is required");
@ -90,8 +92,10 @@ public class Command<C> {
}
if (foundOptional && argument.isRequired()) {
throw new IllegalArgumentException(
String.format("Command argument '%s' cannot be placed after an optional argument",
argument.getName()));
String.format(
"Command argument '%s' cannot be placed after an optional argument",
argument.getName()
));
} else if (!argument.isRequired()) {
foundOptional = true;
}
@ -110,10 +114,12 @@ public class Command<C> {
* @param senderType Required sender type. May be {@code null}
* @param commandMeta Command meta instance
*/
public Command(final @NonNull Map<@NonNull CommandArgument<C, ?>, @NonNull Description> commandArguments,
final @NonNull CommandExecutionHandler<@NonNull C> commandExecutionHandler,
final @Nullable Class<? extends C> senderType,
final @NonNull CommandMeta commandMeta) {
public Command(
final @NonNull Map<@NonNull CommandArgument<C, ?>, @NonNull Description> commandArguments,
final @NonNull CommandExecutionHandler<@NonNull C> commandExecutionHandler,
final @Nullable Class<? extends C> senderType,
final @NonNull CommandMeta commandMeta
) {
this(commandArguments, commandExecutionHandler, senderType, Permission.empty(), commandMeta);
}
@ -125,10 +131,12 @@ public class Command<C> {
* @param commandPermission Command permission
* @param commandMeta Command meta instance
*/
public Command(final @NonNull Map<@NonNull CommandArgument<C, ?>, @NonNull Description> commandArguments,
final @NonNull CommandExecutionHandler<@NonNull C> commandExecutionHandler,
final @NonNull CommandPermission commandPermission,
final @NonNull CommandMeta commandMeta) {
public Command(
final @NonNull Map<@NonNull CommandArgument<C, ?>, @NonNull Description> commandArguments,
final @NonNull CommandExecutionHandler<@NonNull C> commandExecutionHandler,
final @NonNull CommandPermission commandPermission,
final @NonNull CommandMeta commandMeta
) {
this(commandArguments, commandExecutionHandler, null, commandPermission, commandMeta);
}
@ -143,19 +151,23 @@ public class Command<C> {
* @param <C> Command sender type
* @return Command builder
*/
public static <C> @NonNull Builder<C> newBuilder(final @NonNull String commandName,
final @NonNull CommandMeta commandMeta,
final @NonNull Description description,
final @NonNull String... aliases) {
public static <C> @NonNull Builder<C> newBuilder(
final @NonNull String commandName,
final @NonNull CommandMeta commandMeta,
final @NonNull Description description,
final @NonNull String... aliases
) {
final Map<@NonNull CommandArgument<C, ?>, @NonNull Description> map = new LinkedHashMap<>();
map.put(StaticArgument.of(commandName, aliases), description);
return new Builder<>(null,
commandMeta,
null,
map,
new CommandExecutionHandler.NullCommandExecutionHandler<>(),
Permission.empty(),
Collections.emptyList());
return new Builder<>(
null,
commandMeta,
null,
map,
new CommandExecutionHandler.NullCommandExecutionHandler<>(),
Permission.empty(),
Collections.emptyList()
);
}
/**
@ -168,18 +180,22 @@ public class Command<C> {
* @param <C> Command sender type
* @return Command builder
*/
public static <C> @NonNull Builder<C> newBuilder(final @NonNull String commandName,
final @NonNull CommandMeta commandMeta,
final @NonNull String... aliases) {
public static <C> @NonNull Builder<C> newBuilder(
final @NonNull String commandName,
final @NonNull CommandMeta commandMeta,
final @NonNull String... aliases
) {
final Map<CommandArgument<C, ?>, Description> map = new LinkedHashMap<>();
map.put(StaticArgument.of(commandName, aliases), Description.empty());
return new Builder<>(null,
commandMeta,
null,
map,
new CommandExecutionHandler.NullCommandExecutionHandler<>(),
Permission.empty(),
Collections.emptyList());
return new Builder<>(
null,
commandMeta,
null,
map,
new CommandExecutionHandler.NullCommandExecutionHandler<>(),
Permission.empty(),
Collections.emptyList()
);
}
/**
@ -273,13 +289,15 @@ public class Command<C> {
private final CommandManager<C> commandManager;
private final Collection<CommandFlag<?>> flags;
private Builder(final @Nullable CommandManager<C> commandManager,
final @NonNull CommandMeta commandMeta,
final @Nullable Class<? extends C> senderType,
final @NonNull Map<@NonNull CommandArgument<C, ?>, @NonNull Description> commandArguments,
final @NonNull CommandExecutionHandler<@NonNull C> commandExecutionHandler,
final @NonNull CommandPermission commandPermission,
final @NonNull Collection<CommandFlag<?>> flags) {
private Builder(
final @Nullable CommandManager<C> commandManager,
final @NonNull CommandMeta commandMeta,
final @Nullable Class<? extends C> senderType,
final @NonNull Map<@NonNull CommandArgument<C, ?>, @NonNull Description> commandArguments,
final @NonNull CommandExecutionHandler<@NonNull C> commandExecutionHandler,
final @NonNull CommandPermission commandPermission,
final @NonNull Collection<CommandFlag<?>> flags
) {
this.commandManager = commandManager;
this.senderType = senderType;
this.commandArguments = Objects.requireNonNull(commandArguments, "Arguments may not be null");
@ -298,13 +316,15 @@ public class Command<C> {
*/
public @NonNull Builder<C> meta(final @NonNull String key, final @NonNull String value) {
final CommandMeta commandMeta = SimpleCommandMeta.builder().with(this.commandMeta).with(key, value).build();
return new Builder<>(this.commandManager,
commandMeta,
this.senderType,
this.commandArguments,
this.commandExecutionHandler,
this.commandPermission,
this.flags);
return new Builder<>(
this.commandManager,
commandMeta,
this.senderType,
this.commandArguments,
this.commandExecutionHandler,
this.commandPermission,
this.flags
);
}
/**
@ -316,13 +336,15 @@ public class Command<C> {
* @return New builder instance using the provided command manager
*/
public @NonNull Builder<C> manager(final @Nullable CommandManager<C> commandManager) {
return new Builder<>(commandManager,
this.commandMeta,
this.senderType,
this.commandArguments,
this.commandExecutionHandler,
this.commandPermission,
this.flags);
return new Builder<>(
commandManager,
this.commandMeta,
this.senderType,
this.commandArguments,
this.commandExecutionHandler,
this.commandPermission,
this.flags
);
}
/**
@ -332,8 +354,10 @@ public class Command<C> {
* @param aliases Argument aliases
* @return New builder instance with the modified command chain
*/
public @NonNull Builder<C> literal(final @NonNull String main,
final @NonNull String... aliases) {
public @NonNull Builder<C> literal(
final @NonNull String main,
final @NonNull String... aliases
) {
return this.argument(StaticArgument.of(main, aliases));
}
@ -345,9 +369,11 @@ public class Command<C> {
* @param aliases Argument aliases
* @return New builder instance with the modified command chain
*/
public @NonNull Builder<C> literal(final @NonNull String main,
final @NonNull Description description,
final @NonNull String... aliases) {
public @NonNull Builder<C> literal(
final @NonNull String main,
final @NonNull Description description,
final @NonNull String... aliases
) {
return this.argument(StaticArgument.of(main, aliases), description);
}
@ -382,22 +408,26 @@ public class Command<C> {
* @param <T> Argument type
* @return New builder instance with the command argument inserted into the argument list
*/
public <T> @NonNull Builder<C> argument(final @NonNull CommandArgument<C, T> argument,
final @NonNull Description description) {
public <T> @NonNull Builder<C> argument(
final @NonNull CommandArgument<C, T> argument,
final @NonNull Description description
) {
if (argument.isArgumentRegistered()) {
throw new IllegalArgumentException("The provided argument has already been associated with a command."
+ " Use CommandArgument#copy to create a copy of the argument.");
+ " Use CommandArgument#copy to create a copy of the argument.");
}
argument.setArgumentRegistered();
final Map<CommandArgument<C, ?>, Description> commandArgumentMap = new LinkedHashMap<>(this.commandArguments);
commandArgumentMap.put(argument, description);
return new Builder<>(this.commandManager,
this.commandMeta,
this.senderType,
commandArgumentMap,
this.commandExecutionHandler,
this.commandPermission,
this.flags);
return new Builder<>(
this.commandManager,
this.commandMeta,
this.senderType,
commandArgumentMap,
this.commandExecutionHandler,
this.commandPermission,
this.flags
);
}
/**
@ -409,17 +439,21 @@ public class Command<C> {
* @param <T> Argument type
* @return New builder instance with the command argument inserted into the argument list
*/
public <T> @NonNull Builder<C> argument(final CommandArgument.@NonNull Builder<C, T> builder,
final @NonNull Description description) {
public <T> @NonNull Builder<C> argument(
final CommandArgument.@NonNull Builder<C, T> builder,
final @NonNull Description description
) {
final Map<CommandArgument<C, ?>, Description> commandArgumentMap = new LinkedHashMap<>(this.commandArguments);
commandArgumentMap.put(builder.build(), description);
return new Builder<>(this.commandManager,
this.commandMeta,
this.senderType,
commandArgumentMap,
this.commandExecutionHandler,
this.commandPermission,
this.flags);
return new Builder<>(
this.commandManager,
this.commandMeta,
this.senderType,
commandArgumentMap,
this.commandExecutionHandler,
this.commandPermission,
this.flags
);
}
/**
@ -431,9 +465,11 @@ public class Command<C> {
* @param <T> Argument type
* @return New builder instance with the command argument inserted into the argument list
*/
public <T> @NonNull Builder<C> argument(final @NonNull Class<T> clazz,
final @NonNull String name,
final @NonNull Consumer<CommandArgument.Builder<C, T>> builderConsumer) {
public <T> @NonNull Builder<C> argument(
final @NonNull Class<T> clazz,
final @NonNull String name,
final @NonNull Consumer<CommandArgument.Builder<C, T>> builderConsumer
) {
final CommandArgument.Builder<C, T> builder = CommandArgument.ofType(clazz, name);
if (this.commandManager != null) {
builder.manager(this.commandManager);
@ -461,10 +497,12 @@ public class Command<C> {
* @param <V> Second type
* @return Builder instance with the argument inserted
*/
public <U, V> @NonNull Builder<C> argumentPair(final @NonNull String name,
final @NonNull Pair<@NonNull String, @NonNull String> names,
final @NonNull Pair<@NonNull Class<U>, @NonNull Class<V>> parserPair,
final @NonNull Description description) {
public <U, V> @NonNull Builder<C> argumentPair(
final @NonNull String name,
final @NonNull Pair<@NonNull String, @NonNull String> names,
final @NonNull Pair<@NonNull Class<U>, @NonNull Class<V>> parserPair,
final @NonNull Description description
) {
if (this.commandManager == null) {
throw new IllegalStateException("This cannot be called from a command that has no command manager attached");
}
@ -491,18 +529,21 @@ public class Command<C> {
* @param <O> Output type
* @return Builder instance with the argument inserted
*/
public <U, V, O> @NonNull Builder<C> argumentPair(final @NonNull String name,
final @NonNull TypeToken<O> outputType,
final @NonNull Pair<String, String> names,
final @NonNull Pair<Class<U>, Class<V>> parserPair,
final @NonNull BiFunction<C, Pair<U, V>, O> mapper,
final @NonNull Description description) {
public <U, V, O> @NonNull Builder<C> argumentPair(
final @NonNull String name,
final @NonNull TypeToken<O> outputType,
final @NonNull Pair<String, String> names,
final @NonNull Pair<Class<U>, Class<V>> parserPair,
final @NonNull BiFunction<C, Pair<U, V>, O> mapper,
final @NonNull Description description
) {
if (this.commandManager == null) {
throw new IllegalStateException("This cannot be called from a command that has no command manager attached");
}
return this.argument(
ArgumentPair.of(this.commandManager, name, names, parserPair).withMapper(outputType, mapper),
description);
description
);
}
/**
@ -523,10 +564,12 @@ public class Command<C> {
* @param <W> Third type
* @return Builder instance with the argument inserted
*/
public <U, V, W> @NonNull Builder<C> argumentTriplet(final @NonNull String name,
final @NonNull Triplet<String, String, String> names,
final @NonNull Triplet<Class<U>, Class<V>, Class<W>> parserTriplet,
final @NonNull Description description) {
public <U, V, W> @NonNull Builder<C> argumentTriplet(
final @NonNull String name,
final @NonNull Triplet<String, String, String> names,
final @NonNull Triplet<Class<U>, Class<V>, Class<W>> parserTriplet,
final @NonNull Description description
) {
if (this.commandManager == null) {
throw new IllegalStateException("This cannot be called from a command that has no command manager attached");
}
@ -554,19 +597,22 @@ public class Command<C> {
* @param <O> Output type
* @return Builder instance with the argument inserted
*/
public <U, V, W, O> @NonNull Builder<C> argumentTriplet(final @NonNull String name,
final @NonNull TypeToken<O> outputType,
final @NonNull Triplet<String, String, String> names,
final @NonNull Triplet<Class<U>, Class<V>,
Class<W>> parserTriplet,
final @NonNull BiFunction<C, Triplet<U, V, W>, O> mapper,
final @NonNull Description description) {
public <U, V, W, O> @NonNull Builder<C> argumentTriplet(
final @NonNull String name,
final @NonNull TypeToken<O> outputType,
final @NonNull Triplet<String, String, String> names,
final @NonNull Triplet<Class<U>, Class<V>,
Class<W>> parserTriplet,
final @NonNull BiFunction<C, Triplet<U, V, W>, O> mapper,
final @NonNull Description description
) {
if (this.commandManager == null) {
throw new IllegalStateException("This cannot be called from a command that has no command manager attached");
}
return this.argument(
ArgumentTriplet.of(this.commandManager, name, names, parserTriplet).withMapper(outputType, mapper),
description);
description
);
}
// End of compound helper methods
@ -578,13 +624,15 @@ public class Command<C> {
* @return New builder instance using the command execution handler
*/
public @NonNull Builder<C> handler(final @NonNull CommandExecutionHandler<C> commandExecutionHandler) {
return new Builder<>(this.commandManager,
this.commandMeta,
this.senderType,
this.commandArguments,
commandExecutionHandler,
this.commandPermission,
this.flags);
return new Builder<>(
this.commandManager,
this.commandMeta,
this.senderType,
this.commandArguments,
commandExecutionHandler,
this.commandPermission,
this.flags
);
}
/**
@ -593,14 +641,16 @@ public class Command<C> {
* @param senderType Required sender type
* @return New builder instance using the command execution handler
*/
public @NonNull Builder<C> withSenderType(final @NonNull Class<? extends C> senderType) {
return new Builder<>(this.commandManager,
this.commandMeta,
senderType,
this.commandArguments,
this.commandExecutionHandler,
this.commandPermission,
this.flags);
public @NonNull Builder<C> senderType(final @NonNull Class<? extends C> senderType) {
return new Builder<>(
this.commandManager,
this.commandMeta,
senderType,
this.commandArguments,
this.commandExecutionHandler,
this.commandPermission,
this.flags
);
}
/**
@ -610,13 +660,15 @@ public class Command<C> {
* @return New builder instance using the command permission
*/
public @NonNull Builder<C> withPermission(final @NonNull CommandPermission permission) {
return new Builder<>(this.commandManager,
this.commandMeta,
this.senderType,
this.commandArguments,
this.commandExecutionHandler,
permission,
this.flags);
return new Builder<>(
this.commandManager,
this.commandMeta,
this.senderType,
this.commandArguments,
this.commandExecutionHandler,
permission,
this.flags
);
}
/**
@ -626,13 +678,15 @@ public class Command<C> {
* @return New builder instance using the command permission
*/
public @NonNull Builder<C> withPermission(final @NonNull String permission) {
return new Builder<>(this.commandManager,
this.commandMeta,
this.senderType,
this.commandArguments,
this.commandExecutionHandler,
Permission.of(permission),
this.flags);
return new Builder<>(
this.commandManager,
this.commandMeta,
this.senderType,
this.commandArguments,
this.commandExecutionHandler,
Permission.of(permission),
this.flags
);
}
/**
@ -681,13 +735,15 @@ public class Command<C> {
public @NonNull <T> Builder<C> flag(final @NonNull CommandFlag<T> flag) {
final List<CommandFlag<?>> flags = new ArrayList<>(this.flags);
flags.add(flag);
return new Builder<>(this.commandManager,
this.commandMeta,
this.senderType,
this.commandArguments,
this.commandExecutionHandler,
this.commandPermission,
Collections.unmodifiableList(flags));
return new Builder<>(
this.commandManager,
this.commandMeta,
this.senderType,
this.commandArguments,
this.commandExecutionHandler,
this.commandPermission,
Collections.unmodifiableList(flags)
);
}
/**
@ -713,11 +769,13 @@ public class Command<C> {
final FlagArgument<C> flagArgument = new FlagArgument<>(this.flags);
commandArguments.put(flagArgument, Description.of("Command flags"));
}
return new Command<>(Collections.unmodifiableMap(commandArguments),
this.commandExecutionHandler,
this.senderType,
this.commandPermission,
this.commandMeta);
return new Command<>(
Collections.unmodifiableMap(commandArguments),
this.commandExecutionHandler,
this.senderType,
this.commandPermission,
this.commandMeta
);
}
}

View file

@ -56,10 +56,12 @@ public final class CommandHelpHandler<C> {
for (final Command<C> command : this.commandManager.getCommands()) {
final List<CommandArgument<C, ?>> arguments = command.getArguments();
final String description = command.getCommandMeta().getOrDefault("description", "");
syntaxHints.add(new VerboseHelpEntry<>(command,
this.commandManager.getCommandSyntaxFormatter()
.apply(arguments, null),
description));
syntaxHints.add(new VerboseHelpEntry<>(
command,
this.commandManager.getCommandSyntaxFormatter()
.apply(arguments, null),
description
));
}
syntaxHints.sort(Comparator.comparing(VerboseHelpEntry::getSyntaxString));
return syntaxHints;
@ -75,58 +77,18 @@ public final class CommandHelpHandler<C> {
public @NonNull List<@NonNull String> getLongestSharedChains() {
final List<String> chains = new ArrayList<>();
this.commandManager.getCommandTree().getRootNodes().forEach(node ->
chains.add(Objects.requireNonNull(node.getValue())
.getName() + this.commandManager.getCommandSyntaxFormatter()
.apply(Collections
.emptyList(),
node)));
chains.add(Objects.requireNonNull(node.getValue())
.getName() + this.commandManager
.getCommandSyntaxFormatter()
.apply(
Collections
.emptyList(),
node
)));
chains.sort(String::compareTo);
return chains;
}
public static final class VerboseHelpEntry<C> {
private final Command<C> command;
private final String syntaxString;
private final String description;
private VerboseHelpEntry(final @NonNull Command<C> command,
final @NonNull String syntaxString,
final @NonNull String description) {
this.command = command;
this.syntaxString = syntaxString;
this.description = description;
}
/**
* Get the command
*
* @return Command
*/
public @NonNull Command<C> getCommand() {
return this.command;
}
/**
* Get the syntax string
*
* @return Syntax string
*/
public @NonNull String getSyntaxString() {
return this.syntaxString;
}
/**
* Get the command description
*
* @return Command description
*/
public @NonNull String getDescription() {
return this.description;
}
}
/**
* Query for help
*
@ -144,12 +106,15 @@ public final class CommandHelpHandler<C> {
* @param query Query string
* @return Help topic, will return an empty {@link IndexHelpTopic} if no results were found
*/
public @NonNull HelpTopic<C> queryHelp(final @Nullable C recipient,
final @NonNull String query) {
public @NonNull HelpTopic<C> queryHelp(
final @Nullable C recipient,
final @NonNull String query
) {
final List<VerboseHelpEntry<C>> commands = this.getAllCommands();
commands.removeIf(command -> recipient != null && !this.commandManager.hasPermission(recipient,
command.getCommand()
.getCommandPermission()));
commands.removeIf(command -> recipient != null && !this.commandManager.hasPermission(
recipient,
command.getCommand().getCommandPermission()
));
if (query.replace(" ", "").isEmpty()) {
return new IndexHelpTopic<>(commands);
}
@ -166,7 +131,7 @@ public final class CommandHelpHandler<C> {
for (final VerboseHelpEntry<C> entry : commands) {
final Command<C> command = entry.getCommand();
@SuppressWarnings("unchecked") final StaticArgument<C> staticArgument = (StaticArgument<C>) command.getArguments()
.get(0);
.get(0);
for (final String alias : staticArgument.getAliases()) {
if (alias.toLowerCase(Locale.ENGLISH).startsWith(rootFragment.toLowerCase(Locale.ENGLISH))) {
availableCommands.add(command);
@ -199,10 +164,12 @@ public final class CommandHelpHandler<C> {
for (final Command<C> command : availableCommands) {
final List<CommandArgument<C, ?>> arguments = command.getArguments();
final String description = command.getCommandMeta().getOrDefault("description", "");
syntaxHints.add(new VerboseHelpEntry<>(command,
this.commandManager.getCommandSyntaxFormatter()
.apply(arguments, null),
description));
syntaxHints.add(new VerboseHelpEntry<>(
command,
this.commandManager.getCommandSyntaxFormatter()
.apply(arguments, null),
description
));
}
syntaxHints.sort(Comparator.comparing(VerboseHelpEntry::getSyntaxString));
syntaxHints.removeIf(command -> recipient != null
@ -212,22 +179,23 @@ public final class CommandHelpHandler<C> {
/* Traverse command to find the most specific help topic */
final CommandTree.Node<CommandArgument<C, ?>> node = this.commandManager.getCommandTree()
.getNamedNode(availableCommandLabels.iterator()
.next());
.getNamedNode(availableCommandLabels.iterator()
.next());
final List<CommandArgument<C, ?>> traversedNodes = new LinkedList<>();
CommandTree.Node<CommandArgument<C, ?>> head = node;
int index = 0;
outer: while (head != null) {
outer:
while (head != null) {
++index;
traversedNodes.add(head.getValue());
if (head.getValue() != null && head.getValue().getOwningCommand() != null) {
if (head.isLeaf() || index == queryFragments.length) {
if (recipient == null || this.commandManager.hasPermission(recipient, head.getValue()
.getOwningCommand()
.getCommandPermission())) {
.getOwningCommand()
.getCommandPermission())) {
return new VerboseHelpTopic<>(head.getValue().getOwningCommand());
}
}
@ -239,8 +207,8 @@ public final class CommandHelpHandler<C> {
if (index < queryFragments.length) {
/* We might still be able to match an argument */
for (final CommandTree.Node<CommandArgument<C, ?>> child : head.getChildren()) {
@SuppressWarnings("unchecked")
final StaticArgument<C> childArgument = (StaticArgument<C>) child.getValue();
@SuppressWarnings("unchecked") final StaticArgument<C> childArgument = (StaticArgument<C>) child
.getValue();
if (childArgument == null) {
continue;
}
@ -260,8 +228,10 @@ public final class CommandHelpHandler<C> {
if (recipient == null
|| child.getValue() == null
|| child.getValue().getOwningCommand() == null
|| this.commandManager.hasPermission(recipient,
child.getValue().getOwningCommand().getCommandPermission())) {
|| this.commandManager.hasPermission(
recipient,
child.getValue().getOwningCommand().getCommandPermission()
)) {
traversedNodesSub.add(child.getValue());
childSuggestions.add(this.commandManager.getCommandSyntaxFormatter().apply(traversedNodesSub, child));
}
@ -273,7 +243,6 @@ public final class CommandHelpHandler<C> {
return new IndexHelpTopic<>(Collections.emptyList());
}
/**
* Something that can be returned as the result of a help query
* <p>
@ -287,8 +256,53 @@ public final class CommandHelpHandler<C> {
* @param <C> Command sender type
*/
public interface HelpTopic<C> {
}
public static final class VerboseHelpEntry<C> {
private final Command<C> command;
private final String syntaxString;
private final String description;
private VerboseHelpEntry(
final @NonNull Command<C> command,
final @NonNull String syntaxString,
final @NonNull String description
) {
this.command = command;
this.syntaxString = syntaxString;
this.description = description;
}
/**
* Get the command
*
* @return Command
*/
public @NonNull Command<C> getCommand() {
return this.command;
}
/**
* Get the syntax string
*
* @return Syntax string
*/
public @NonNull String getSyntaxString() {
return this.syntaxString;
}
/**
* Get the command description
*
* @return Command description
*/
public @NonNull String getDescription() {
return this.description;
}
}
/**
* Index of available commands
@ -371,8 +385,10 @@ public final class CommandHelpHandler<C> {
private final String longestPath;
private final List<String> childSuggestions;
private MultiHelpTopic(final @NonNull String longestPath,
final @NonNull List<@NonNull String> childSuggestions) {
private MultiHelpTopic(
final @NonNull String longestPath,
final @NonNull List<@NonNull String> childSuggestions
) {
this.longestPath = longestPath;
this.childSuggestions = childSuggestions;
}

View file

@ -45,13 +45,13 @@ import cloud.commandframework.execution.preprocessor.AcceptingCommandPreprocesso
import cloud.commandframework.execution.preprocessor.CommandPreprocessingContext;
import cloud.commandframework.execution.preprocessor.CommandPreprocessor;
import cloud.commandframework.internal.CommandRegistrationHandler;
import io.leangen.geantyref.TypeToken;
import cloud.commandframework.meta.CommandMeta;
import cloud.commandframework.permission.CommandPermission;
import cloud.commandframework.permission.OrPermission;
import cloud.commandframework.permission.Permission;
import cloud.commandframework.services.ServicePipeline;
import cloud.commandframework.services.State;
import io.leangen.geantyref.TypeToken;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@ -76,7 +76,8 @@ import java.util.function.Function;
public abstract class CommandManager<C> {
private final Map<Class<? extends Exception>, BiConsumer<C, ? extends Exception>> exceptionHandlers = new HashMap<>();
private final EnumSet<ManagerSettings> managerSettings = EnumSet.of(ManagerSettings.ENFORCE_INTERMEDIARY_PERMISSIONS);
private final EnumSet<ManagerSettings> managerSettings = EnumSet.of(
ManagerSettings.ENFORCE_INTERMEDIARY_PERMISSIONS);
private final CommandContextFactory<C> commandContextFactory = new StandardCommandContextFactory<>();
private final ServicePipeline servicePipeline = ServicePipeline.builder().build();
@ -97,7 +98,8 @@ public abstract class CommandManager<C> {
*/
public CommandManager(
final @NonNull Function<@NonNull CommandTree<C>, @NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator,
final @NonNull CommandRegistrationHandler commandRegistrationHandler) {
final @NonNull CommandRegistrationHandler commandRegistrationHandler
) {
this.commandTree = CommandTree.newTree(this);
this.commandExecutionCoordinator = commandExecutionCoordinator.apply(commandTree);
this.commandRegistrationHandler = commandRegistrationHandler;
@ -132,8 +134,10 @@ public abstract class CommandManager<C> {
* @param input Input provided by the sender
* @return Command result
*/
public @NonNull CompletableFuture<CommandResult<C>> executeCommand(final @NonNull C commandSender,
final @NonNull String input) {
public @NonNull CompletableFuture<CommandResult<C>> executeCommand(
final @NonNull C commandSender,
final @NonNull String input
) {
final CommandContext<C> context = this.commandContextFactory.create(false, commandSender);
final LinkedList<String> inputQueue = tokenize(input);
try {
@ -157,14 +161,18 @@ public abstract class CommandManager<C> {
* @param input Input provided by the sender
* @return List of suggestions
*/
public @NonNull List<@NonNull String> suggest(final @NonNull C commandSender,
final @NonNull String input) {
public @NonNull List<@NonNull String> suggest(
final @NonNull C commandSender,
final @NonNull String input
) {
final CommandContext<C> context = this.commandContextFactory.create(true, commandSender);
final LinkedList<String> inputQueue = tokenize(input);
if (this.preprocessContext(context, inputQueue) == State.ACCEPTED) {
return this.commandSuggestionProcessor.apply(new CommandPreprocessingContext<>(context, inputQueue),
this.commandTree.getSuggestions(
context, inputQueue));
return this.commandSuggestionProcessor.apply(
new CommandPreprocessingContext<>(context, inputQueue),
this.commandTree.getSuggestions(
context, inputQueue)
);
} else {
return Collections.emptyList();
}
@ -231,8 +239,10 @@ public abstract class CommandManager<C> {
* @param permission Permission node
* @return {@code true} if the sender has the permission, else {@code false}
*/
public boolean hasPermission(final @NonNull C sender,
final @NonNull CommandPermission permission) {
public boolean hasPermission(
final @NonNull C sender,
final @NonNull CommandPermission permission
) {
if (permission.toString().isEmpty()) {
return true;
}
@ -269,10 +279,12 @@ public abstract class CommandManager<C> {
* @param meta Command meta
* @return Builder instance
*/
public Command.@NonNull Builder<C> commandBuilder(final @NonNull String name,
final @NonNull Collection<String> aliases,
final @NonNull Description description,
final @NonNull CommandMeta meta) {
public Command.@NonNull Builder<C> commandBuilder(
final @NonNull String name,
final @NonNull Collection<String> aliases,
final @NonNull Description description,
final @NonNull CommandMeta meta
) {
return Command.newBuilder(name, meta, description, aliases.toArray(new String[0]));
}
@ -284,9 +296,11 @@ public abstract class CommandManager<C> {
* @param meta Command meta
* @return Builder instance
*/
public Command.@NonNull Builder<C> commandBuilder(final @NonNull String name,
final @NonNull Collection<String> aliases,
final @NonNull CommandMeta meta) {
public Command.@NonNull Builder<C> commandBuilder(
final @NonNull String name,
final @NonNull Collection<String> aliases,
final @NonNull CommandMeta meta
) {
return Command.newBuilder(name, meta, Description.empty(), aliases.toArray(new String[0]));
}
@ -299,10 +313,12 @@ public abstract class CommandManager<C> {
* @param aliases Command aliases
* @return Builder instance
*/
public Command.@NonNull Builder<C> commandBuilder(final @NonNull String name,
final @NonNull CommandMeta meta,
final @NonNull Description description,
final @NonNull String... aliases) {
public Command.@NonNull Builder<C> commandBuilder(
final @NonNull String name,
final @NonNull CommandMeta meta,
final @NonNull Description description,
final @NonNull String... aliases
) {
return Command.newBuilder(name, meta, description, aliases);
}
@ -314,9 +330,11 @@ public abstract class CommandManager<C> {
* @param aliases Command aliases
* @return Builder instance
*/
public Command.@NonNull Builder<C> commandBuilder(final @NonNull String name,
final @NonNull CommandMeta meta,
final @NonNull String... aliases) {
public Command.@NonNull Builder<C> commandBuilder(
final @NonNull String name,
final @NonNull CommandMeta meta,
final @NonNull String... aliases
) {
return Command.newBuilder(name, meta, Description.empty(), aliases);
}
@ -330,23 +348,27 @@ public abstract class CommandManager<C> {
* @throws UnsupportedOperationException If the command manager does not support default command meta creation
* @see #createDefaultCommandMeta() Default command meta creation
*/
public Command.@NonNull Builder<C> commandBuilder(final @NonNull String name,
final @NonNull Description description,
final @NonNull String... aliases) {
public Command.@NonNull Builder<C> commandBuilder(
final @NonNull String name,
final @NonNull Description description,
final @NonNull String... aliases
) {
return Command.<C>newBuilder(name, this.createDefaultCommandMeta(), description, aliases).manager(this);
}
/**
* Create a new command builder using a default command meta instance.
*
* @param name Command name
* @param aliases Command aliases
* @param name Command name
* @param aliases Command aliases
* @return Builder instance
* @throws UnsupportedOperationException If the command manager does not support default command meta creation
* @see #createDefaultCommandMeta() Default command meta creation
*/
public Command.@NonNull Builder<C> commandBuilder(final @NonNull String name,
final @NonNull String... aliases) {
public Command.@NonNull Builder<C> commandBuilder(
final @NonNull String name,
final @NonNull String... aliases
) {
return Command.<C>newBuilder(name, this.createDefaultCommandMeta(), Description.empty(), aliases).manager(this);
}
@ -358,8 +380,10 @@ public abstract class CommandManager<C> {
* @param <T> Generic argument name
* @return Argument builder
*/
public <T> CommandArgument.@NonNull Builder<C, T> argumentBuilder(final @NonNull Class<T> type,
final @NonNull String name) {
public <T> CommandArgument.@NonNull Builder<C, T> argumentBuilder(
final @NonNull Class<T> type,
final @NonNull String name
) {
return CommandArgument.<C, T>ofType(type, name).manager(this);
}
@ -401,7 +425,8 @@ public abstract class CommandManager<C> {
public void registerCommandPreProcessor(final @NonNull CommandPreprocessor<C> processor) {
this.servicePipeline.registerServiceImplementation(new TypeToken<CommandPreprocessor<C>>() {
}, processor,
Collections.emptyList());
Collections.emptyList()
);
}
/**
@ -414,7 +439,8 @@ public abstract class CommandManager<C> {
public void registerCommandPostProcessor(final @NonNull CommandPostprocessor<C> processor) {
this.servicePipeline.registerServiceImplementation(new TypeToken<CommandPostprocessor<C>>() {
}, processor,
Collections.emptyList());
Collections.emptyList()
);
}
/**
@ -425,15 +451,17 @@ public abstract class CommandManager<C> {
* @return {@link State#ACCEPTED} if the command should be parsed and executed, else {@link State#REJECTED}
* @see #registerCommandPreProcessor(CommandPreprocessor) Register a command preprocessor
*/
public State preprocessContext(final @NonNull CommandContext<C> context,
final @NonNull LinkedList<@NonNull String> inputQueue) {
public State preprocessContext(
final @NonNull CommandContext<C> context,
final @NonNull LinkedList<@NonNull String> inputQueue
) {
this.servicePipeline.pump(new CommandPreprocessingContext<>(context, inputQueue))
.through(new TypeToken<CommandPreprocessor<C>>() {
})
.getResult();
.through(new TypeToken<CommandPreprocessor<C>>() {
})
.getResult();
return context.<String>getOptional(AcceptingCommandPreprocessor.PROCESSED_INDICATOR_KEY).orElse("").isEmpty()
? State.REJECTED
: State.ACCEPTED;
? State.REJECTED
: State.ACCEPTED;
}
/**
@ -444,15 +472,17 @@ public abstract class CommandManager<C> {
* @return {@link State#ACCEPTED} if the command should be parsed and executed, else {@link State#REJECTED}
* @see #registerCommandPostProcessor(CommandPostprocessor) Register a command postprocessor
*/
public State postprocessContext(final @NonNull CommandContext<C> context,
final @NonNull Command<C> command) {
public State postprocessContext(
final @NonNull CommandContext<C> context,
final @NonNull Command<C> command
) {
this.servicePipeline.pump(new CommandPostprocessingContext<>(context, command))
.through(new TypeToken<CommandPostprocessor<C>>() {
})
.getResult();
.through(new TypeToken<CommandPostprocessor<C>>() {
})
.getResult();
return context.<String>getOptional(AcceptingCommandPostprocessor.PROCESSED_INDICATOR_KEY).orElse("").isEmpty()
? State.REJECTED
: State.ACCEPTED;
? State.REJECTED
: State.ACCEPTED;
}
/**
@ -520,8 +550,10 @@ public abstract class CommandManager<C> {
* @param handler Exception handler
* @param <E> Exception type
*/
public final <E extends Exception> void registerExceptionHandler(final @NonNull Class<E> clazz,
final @NonNull BiConsumer<@NonNull C, @NonNull E> handler) {
public final <E extends Exception> void registerExceptionHandler(
final @NonNull Class<E> clazz,
final @NonNull BiConsumer<@NonNull C, @NonNull E> handler
) {
this.exceptionHandlers.put(clazz, handler);
}
@ -536,10 +568,12 @@ public abstract class CommandManager<C> {
* handler stored for the exception type
* @param <E> Exception type
*/
public final <E extends Exception> void handleException(final @NonNull C sender,
final @NonNull Class<E> clazz,
final @NonNull E exception,
final @NonNull BiConsumer<C, E> defaultHandler) {
public final <E extends Exception> void handleException(
final @NonNull C sender,
final @NonNull Class<E> clazz,
final @NonNull E exception,
final @NonNull BiConsumer<C, E> defaultHandler
) {
Optional.ofNullable(this.getExceptionHandler(clazz)).orElse(defaultHandler).accept(sender, exception);
}
@ -557,7 +591,7 @@ public abstract class CommandManager<C> {
* of command help menus, etc.
*
* @return Command help handler. A new instance will be created
* each time this method is called.
* each time this method is called.
*/
public final @NonNull CommandHelpHandler<C> getCommandHelpHandler() {
return new CommandHelpHandler<>(this);
@ -580,8 +614,10 @@ public abstract class CommandManager<C> {
* @param value Value
*/
@SuppressWarnings("unused")
public void setSetting(final @NonNull ManagerSettings setting,
final boolean value) {
public void setSetting(
final @NonNull ManagerSettings setting,
final boolean value
) {
if (value) {
this.managerSettings.add(setting);
} else {

View file

@ -112,45 +112,58 @@ public final class CommandTree<C> {
* @param args Input
* @return Parsed command, if one could be found
*/
public @NonNull Pair<@Nullable Command<C>, @Nullable Exception> parse(final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> args) {
final Pair<@Nullable Command<C>, @Nullable Exception> pair = this.parseCommand(new ArrayList<>(),
commandContext,
args,
this.internalTree);
public @NonNull Pair<@Nullable Command<C>, @Nullable Exception> parse(
final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> args
) {
final Pair<@Nullable Command<C>, @Nullable Exception> pair = this.parseCommand(
new ArrayList<>(),
commandContext,
args,
this.internalTree
);
if (pair.getFirst() != null) {
final Command<C> command = pair.getFirst();
if (command.getSenderType().isPresent() && !command.getSenderType().get()
.isAssignableFrom(commandContext.getSender().getClass())) {
return Pair.of(null, new InvalidCommandSenderException(commandContext.getSender(),
command.getSenderType().get(),
Collections.emptyList()));
.isAssignableFrom(commandContext
.getSender()
.getClass())) {
return Pair.of(null, new InvalidCommandSenderException(
commandContext.getSender(),
command.getSenderType().get(),
Collections.emptyList()
));
}
}
return pair;
}
private @NonNull Pair<@Nullable Command<C>, @Nullable Exception>
parseCommand(final @NonNull List<@NonNull CommandArgument<C, ?>> parsedArguments,
final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> commandQueue,
final @NonNull Node<@Nullable CommandArgument<C, ?>> root) {
private @NonNull Pair<@Nullable Command<C>, @Nullable Exception> parseCommand(
final @NonNull List<@NonNull CommandArgument<C, ?>> parsedArguments,
final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> commandQueue,
final @NonNull Node<@Nullable CommandArgument<C, ?>> root
) {
CommandPermission permission = this.isPermitted(commandContext.getSender(), root);
if (permission != null) {
return Pair.of(null, new NoPermissionException(permission,
commandContext.getSender(),
this.getChain(root)
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())));
return Pair.of(null, new NoPermissionException(
permission,
commandContext.getSender(),
this.getChain(root)
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())
));
}
final Pair<@Nullable Command<C>, @Nullable Exception> parsedChild = this.attemptParseUnambiguousChild(parsedArguments,
commandContext,
root,
commandQueue);
final Pair<@Nullable Command<C>, @Nullable Exception> parsedChild = this.attemptParseUnambiguousChild(
parsedArguments,
commandContext,
root,
commandQueue
);
if (parsedChild.getFirst() != null || parsedChild.getSecond() != null) {
return parsedChild;
}
@ -165,23 +178,25 @@ public final class CommandTree<C> {
/* Too many arguments. We have a unique path, so we can send the entire context */
return Pair.of(null, new InvalidSyntaxException(
this.commandManager.getCommandSyntaxFormatter()
.apply(parsedArguments, root),
.apply(parsedArguments, root),
commandContext.getSender(), this.getChain(root)
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())));
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())
));
}
} else {
/* Too many arguments. We have a unique path, so we can send the entire context */
return Pair.of(null, new InvalidSyntaxException(
this.commandManager.getCommandSyntaxFormatter()
.apply(parsedArguments, root),
.apply(parsedArguments, root),
commandContext.getSender(), this.getChain(root)
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())));
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())
));
}
} else {
final Iterator<Node<CommandArgument<C, ?>>> childIterator = root.getChildren().iterator();
@ -208,33 +223,38 @@ public final class CommandTree<C> {
return Pair.of(null, new NoSuchCommandException(
commandContext.getSender(),
getChain(root).stream().map(Node::getValue).collect(Collectors.toList()),
stringOrEmpty(commandQueue.peek())));
stringOrEmpty(commandQueue.peek())
));
}
/* If we couldn't match a child, check if there's a command attached and execute it */
if (root.getValue() != null && root.getValue().getOwningCommand() != null && commandQueue.isEmpty()) {
final Command<C> command = root.getValue().getOwningCommand();
if (!this.getCommandManager().hasPermission(commandContext.getSender(),
command.getCommandPermission())) {
if (!this.getCommandManager().hasPermission(
commandContext.getSender(),
command.getCommandPermission()
)) {
return Pair.of(null, new NoPermissionException(
command.getCommandPermission(),
commandContext.getSender(),
this.getChain(root)
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())));
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())
));
}
return Pair.of(root.getValue().getOwningCommand(), null);
}
/* We know that there's no command and we also cannot match any of the children */
return Pair.of(null, new InvalidSyntaxException(
this.commandManager.getCommandSyntaxFormatter()
.apply(parsedArguments, root),
.apply(parsedArguments, root),
commandContext.getSender(), this.getChain(root)
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())));
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())
));
}
}
@ -242,7 +262,8 @@ public final class CommandTree<C> {
final @NonNull List<@NonNull CommandArgument<C, ?>> parsedArguments,
final @NonNull CommandContext<C> commandContext,
final @NonNull Node<@Nullable CommandArgument<C, ?>> root,
final @NonNull Queue<String> commandQueue) {
final @NonNull Queue<String> commandQueue
) {
CommandPermission permission;
final List<Node<CommandArgument<C, ?>>> children = root.getChildren();
if (children.size() == 1 && !(children.get(0).getValue() instanceof StaticArgument)) {
@ -254,11 +275,11 @@ public final class CommandTree<C> {
permission,
commandContext.getSender(),
this.getChain(child)
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(
Collectors.toList())));
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())
));
}
if (child.getValue() != null) {
if (commandQueue.isEmpty()) {
@ -270,58 +291,65 @@ public final class CommandTree<C> {
/* The child is not a leaf, but may have an intermediary executor, attempt to use it */
if (root.getValue() != null && root.getValue().getOwningCommand() != null) {
final Command<C> command = root.getValue().getOwningCommand();
if (!this.getCommandManager().hasPermission(commandContext.getSender(),
command.getCommandPermission())) {
if (!this.getCommandManager().hasPermission(
commandContext.getSender(),
command.getCommandPermission()
)) {
return Pair.of(null, new NoPermissionException(
command.getCommandPermission(),
commandContext.getSender(),
this.getChain(root)
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())));
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())
));
}
return Pair.of(command, null);
}
/* Not enough arguments */
return Pair.of(null, new InvalidSyntaxException(
this.commandManager.getCommandSyntaxFormatter()
.apply(Objects.requireNonNull(
child.getValue()
.getOwningCommand())
.getArguments(), child),
.apply(Objects.requireNonNull(
child.getValue()
.getOwningCommand())
.getArguments(), child),
commandContext.getSender(), this.getChain(root)
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(
Collectors.toList())));
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())
));
} else {
/* The child is not a leaf, but may have an intermediary executor, attempt to use it */
if (root.getValue() != null && root.getValue().getOwningCommand() != null) {
final Command<C> command = root.getValue().getOwningCommand();
if (!this.getCommandManager().hasPermission(commandContext.getSender(),
command.getCommandPermission())) {
if (!this.getCommandManager().hasPermission(
commandContext.getSender(),
command.getCommandPermission()
)) {
return Pair.of(null, new NoPermissionException(
command.getCommandPermission(),
commandContext.getSender(),
this.getChain(root)
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())));
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())
));
}
return Pair.of(command, null);
}
/* Child does not have a command and so we cannot proceed */
return Pair.of(null, new InvalidSyntaxException(
this.commandManager.getCommandSyntaxFormatter()
.apply(parsedArguments, root),
.apply(parsedArguments, root),
commandContext.getSender(), this.getChain(root)
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())));
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())
));
}
}
@ -341,13 +369,13 @@ public final class CommandTree<C> {
/* Too many arguments. We have a unique path, so we can send the entire context */
return Pair.of(null, new InvalidSyntaxException(
this.commandManager.getCommandSyntaxFormatter()
.apply(parsedArguments, child),
.apply(parsedArguments, child),
commandContext.getSender(), this.getChain(root)
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(
Collectors.toList())));
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())
));
}
} else {
parsedArguments.add(child.getValue());
@ -357,10 +385,11 @@ public final class CommandTree<C> {
return Pair.of(null, new ArgumentParseException(
result.getFailure().get(), commandContext.getSender(),
this.getChain(child)
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())));
.stream()
.filter(node -> node.getValue() != null)
.map(Node::getValue)
.collect(Collectors.toList())
));
}
}
}
@ -374,14 +403,18 @@ public final class CommandTree<C> {
* @param commandQueue Input queue
* @return String suggestions. These should be filtered based on {@link String#startsWith(String)}
*/
public @NonNull List<@NonNull String> getSuggestions(final @NonNull CommandContext<C> context,
final @NonNull Queue<@NonNull String> commandQueue) {
public @NonNull List<@NonNull String> getSuggestions(
final @NonNull CommandContext<C> context,
final @NonNull Queue<@NonNull String> commandQueue
) {
return getSuggestions(context, commandQueue, this.internalTree);
}
private @NonNull List<@NonNull String> getSuggestions(final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> commandQueue,
final @NonNull Node<@Nullable CommandArgument<C, ?>> root) {
private @NonNull List<@NonNull String> getSuggestions(
final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> commandQueue,
final @NonNull Node<@Nullable CommandArgument<C, ?>> root
) {
/* If the sender isn't allowed to access the root node, no suggestions are needed */
if (this.isPermitted(commandContext.getSender(), root) != null) {
@ -395,8 +428,8 @@ public final class CommandTree<C> {
// START: Compound arguments
/* When we get in here, we need to treat compound arguments a little differently */
if (child.getValue() instanceof CompoundArgument) {
@SuppressWarnings("unchecked")
final CompoundArgument<?, C, ?> compoundArgument = (CompoundArgument<?, C, ?>) child.getValue();
@SuppressWarnings("unchecked") final CompoundArgument<?, C, ?> compoundArgument = (CompoundArgument<?, C, ?>) child
.getValue();
/* See how many arguments it requires */
final int requiredArguments = compoundArgument.getParserTuple().getSize();
/* Figure out whether we even need to care about this */
@ -453,7 +486,10 @@ public final class CommandTree<C> {
while (childIterator.hasNext()) {
final Node<CommandArgument<C, ?>> child = childIterator.next();
if (child.getValue() != null) {
final ArgumentParseResult<?> result = child.getValue().getParser().parse(commandContext, commandQueue);
final ArgumentParseResult<?> result = child.getValue().getParser().parse(
commandContext,
commandQueue
);
if (result.getParsedValue().isPresent()) {
return this.getSuggestions(commandContext, commandQueue, child);
}
@ -466,7 +502,7 @@ public final class CommandTree<C> {
continue;
}
suggestions.addAll(argument.getValue().getSuggestionsProvider()
.apply(commandContext, stringOrEmpty(commandQueue.peek())));
.apply(commandContext, stringOrEmpty(commandQueue.peek())));
}
return suggestions;
}
@ -517,19 +553,27 @@ public final class CommandTree<C> {
}
}
private @Nullable CommandPermission isPermitted(final @NonNull C sender,
final @NonNull Node<@Nullable CommandArgument<C, ?>> node) {
private @Nullable CommandPermission isPermitted(
final @NonNull C sender,
final @NonNull Node<@Nullable CommandArgument<C, ?>> node
) {
final CommandPermission permission = (CommandPermission) node.nodeMeta.get("permission");
if (permission != null) {
return this.commandManager.hasPermission(sender, permission) ? null : permission;
}
if (node.isLeaf()) {
return this.commandManager.hasPermission(sender,
Objects.requireNonNull(
Objects.requireNonNull(node.value, "node.value").getOwningCommand(),
"owning command").getCommandPermission())
? null : Objects.requireNonNull(node.value.getOwningCommand(), "owning command")
.getCommandPermission();
return this.commandManager.hasPermission(
sender,
Objects.requireNonNull(
Objects.requireNonNull(
node.value,
"node.value"
).getOwningCommand(),
"owning command"
).getCommandPermission()
)
? null : Objects.requireNonNull(node.value.getOwningCommand(), "owning command")
.getCommandPermission();
}
/*
if any of the children would permit the execution, then the sender has a valid
@ -584,7 +628,8 @@ public final class CommandTree<C> {
chain = chain.subList(1, chain.size());
// Go through all nodes from the tail upwards until a collision occurs
for (final Node<CommandArgument<C, ?>> commandArgumentNode : chain) {
final CommandPermission existingPermission = (CommandPermission) commandArgumentNode.nodeMeta.get("permission");
final CommandPermission existingPermission = (CommandPermission) commandArgumentNode.nodeMeta
.get("permission");
CommandPermission permission;
if (existingPermission != null) {
@ -594,9 +639,13 @@ public final class CommandTree<C> {
}
/* Now also check if there's a command handler attached to an upper level node */
if (commandArgumentNode.getValue() != null && commandArgumentNode.getValue().getOwningCommand() != null) {
if (commandArgumentNode.getValue() != null && commandArgumentNode
.getValue()
.getOwningCommand() != null) {
final Command<C> command = commandArgumentNode.getValue().getOwningCommand();
if (this.getCommandManager().getSetting(CommandManager.ManagerSettings.ENFORCE_INTERMEDIARY_PERMISSIONS)) {
if (this
.getCommandManager()
.getSetting(CommandManager.ManagerSettings.ENFORCE_INTERMEDIARY_PERMISSIONS)) {
permission = command.getCommandPermission();
} else {
permission = OrPermission.of(Arrays.asList(permission, command.getCommandPermission()));
@ -608,26 +657,30 @@ public final class CommandTree<C> {
});
}
private void checkAmbiguity(final @NonNull Node<@Nullable CommandArgument<C, ?>> node) throws AmbiguousNodeException {
private void checkAmbiguity(final @NonNull Node<@Nullable CommandArgument<C, ?>> node) throws
AmbiguousNodeException {
if (node.isLeaf()) {
return;
}
final int size = node.children.size();
for (final Node<CommandArgument<C, ?>> child : node.children) {
if (child.getValue() != null && !child.getValue().isRequired() && size > 1) {
throw new AmbiguousNodeException(node.getValue(),
child.getValue(),
node.getChildren()
.stream()
.filter(n -> n.getValue() != null)
.map(Node::getValue).collect(Collectors.toList()));
throw new AmbiguousNodeException(
node.getValue(),
child.getValue(),
node.getChildren()
.stream()
.filter(n -> n.getValue() != null)
.map(Node::getValue).collect(Collectors.toList())
);
}
}
node.children.forEach(this::checkAmbiguity);
}
private @NonNull List<@NonNull Node<@Nullable CommandArgument<C, ?>>>
getLeavesRaw(final @NonNull Node<@Nullable CommandArgument<C, ?>> node) {
private @NonNull List<@NonNull Node<@Nullable CommandArgument<C, ?>>> getLeavesRaw(
final @NonNull Node<@Nullable CommandArgument<C, ?>> node
) {
final List<Node<CommandArgument<C, ?>>> leaves = new LinkedList<>();
if (node.isLeaf()) {
if (node.getValue() != null) {
@ -639,7 +692,9 @@ public final class CommandTree<C> {
return leaves;
}
private @NonNull List<@NonNull CommandArgument<C, ?>> getLeaves(final @NonNull Node<@NonNull CommandArgument<C, ?>> node) {
private @NonNull List<@NonNull CommandArgument<C, ?>> getLeaves(
final @NonNull Node<@NonNull CommandArgument<C, ?>> node
) {
final List<CommandArgument<C, ?>> leaves = new LinkedList<>();
if (node.isLeaf()) {
if (node.getValue() != null) {
@ -651,8 +706,9 @@ public final class CommandTree<C> {
return leaves;
}
private @NonNull List<@NonNull Node<@Nullable CommandArgument<C, ?>>>
getChain(final @Nullable Node<@Nullable CommandArgument<C, ?>> end) {
private @NonNull List<@NonNull Node<@Nullable CommandArgument<C, ?>>> getChain(
final @Nullable Node<@Nullable CommandArgument<C, ?>> end
) {
final List<Node<CommandArgument<C, ?>>> chain = new LinkedList<>();
Node<CommandArgument<C, ?>> tail = end;
while (tail != null) {
@ -812,6 +868,7 @@ public final class CommandTree<C> {
public String toString() {
return "Node{value=" + value + '}';
}
}
}

View file

@ -67,7 +67,7 @@ public final class Description {
* @return Command description
*/
public @NonNull String getDescription() {
return this.description;
return this.description;
}
/**

View file

@ -34,4 +34,5 @@ import java.lang.annotation.Target;
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface Greedy {
}

View file

@ -23,13 +23,13 @@
//
package cloud.commandframework.arguments;
import cloud.commandframework.arguments.parser.ArgumentParser;
import io.leangen.geantyref.TypeToken;
import cloud.commandframework.Command;
import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.parser.ArgumentParseResult;
import cloud.commandframework.arguments.parser.ArgumentParser;
import cloud.commandframework.arguments.parser.ParserParameters;
import cloud.commandframework.context.CommandContext;
import io.leangen.geantyref.TypeToken;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@ -99,12 +99,14 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
* @param valueType Type produced by the parser
* @param suggestionsProvider Suggestions provider
*/
public CommandArgument(final boolean required,
final @NonNull String name,
final @NonNull ArgumentParser<C, T> parser,
final @NonNull String defaultValue,
final @NonNull TypeToken<T> valueType,
final @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider) {
public CommandArgument(
final boolean required,
final @NonNull String name,
final @NonNull ArgumentParser<C, T> parser,
final @NonNull String defaultValue,
final @NonNull TypeToken<T> valueType,
final @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider
) {
this.required = required;
this.name = Objects.requireNonNull(name, "Name may not be null");
if (!NAME_PATTERN.asPredicate().test(name)) {
@ -114,8 +116,8 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
this.defaultValue = defaultValue;
this.valueType = valueType;
this.suggestionsProvider = suggestionsProvider == null
? buildDefaultSuggestionsProvider(this)
: suggestionsProvider;
? buildDefaultSuggestionsProvider(this)
: suggestionsProvider;
}
/**
@ -128,13 +130,15 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
* @param valueType Type produced by the parser
* @param suggestionsProvider Suggestions provider
*/
public CommandArgument(final boolean required,
final @NonNull String name,
final @NonNull ArgumentParser<C, T> parser,
final @NonNull String defaultValue,
final @NonNull Class<T> valueType,
final @Nullable BiFunction<@NonNull CommandContext<C>,
@NonNull String, @NonNull List<@NonNull String>> suggestionsProvider) {
public CommandArgument(
final boolean required,
final @NonNull String name,
final @NonNull ArgumentParser<C, T> parser,
final @NonNull String defaultValue,
final @NonNull Class<T> valueType,
final @Nullable BiFunction<@NonNull CommandContext<C>,
@NonNull String, @NonNull List<@NonNull String>> suggestionsProvider
) {
this(required, name, parser, defaultValue, TypeToken.get(valueType), suggestionsProvider);
}
@ -146,10 +150,12 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
* @param parser The argument parser
* @param valueType Type produced by the parser
*/
public CommandArgument(final boolean required,
final @NonNull String name,
final @NonNull ArgumentParser<C, T> parser,
final @NonNull Class<T> valueType) {
public CommandArgument(
final boolean required,
final @NonNull String name,
final @NonNull ArgumentParser<C, T> parser,
final @NonNull Class<T> valueType
) {
this(required, name, parser, "", valueType, null);
}
@ -167,8 +173,10 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
* @param <T> Argument Type. Used to make the compiler happy.
* @return Argument builder
*/
public static <C, T> CommandArgument.@NonNull Builder<C, T> ofType(final @NonNull TypeToken<T> clazz,
final @NonNull String name) {
public static <C, T> CommandArgument.@NonNull Builder<C, T> ofType(
final @NonNull TypeToken<T> clazz,
final @NonNull String name
) {
return new Builder<>(clazz, name);
}
@ -181,8 +189,10 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
* @param <T> Argument Type. Used to make the compiler happy.
* @return Argument builder
*/
public static <C, T> CommandArgument.@NonNull Builder<@NonNull C, @NonNull T> ofType(final @NonNull Class<T> clazz,
final @NonNull String name) {
public static <C, T> CommandArgument.@NonNull Builder<@NonNull C, @NonNull T> ofType(
final @NonNull Class<T> clazz,
final @NonNull String name
) {
return new Builder<>(TypeToken.get(clazz), name);
}
@ -366,14 +376,18 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
private String defaultValue = "";
private BiFunction<@NonNull CommandContext<C>, @NonNull String, @NonNull List<String>> suggestionsProvider;
protected Builder(final @NonNull TypeToken<T> valueType,
final @NonNull String name) {
protected Builder(
final @NonNull TypeToken<T> valueType,
final @NonNull String name
) {
this.valueType = valueType;
this.name = name;
}
protected Builder(final @NonNull Class<T> valueType,
final @NonNull String name) {
protected Builder(
final @NonNull Class<T> valueType,
final @NonNull String name
) {
this(TypeToken.get(valueType), name);
}
@ -452,7 +466,8 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
*/
public @NonNull Builder<@NonNull C, @NonNull T> withSuggestionsProvider(
final @NonNull BiFunction<@NonNull CommandContext<C>,
@NonNull String, @NonNull List<String>> suggestionsProvider) {
@NonNull String, @NonNull List<String>> suggestionsProvider
) {
this.suggestionsProvider = suggestionsProvider;
return this;
}
@ -465,7 +480,7 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
public @NonNull CommandArgument<@NonNull C, @NonNull T> build() {
if (this.parser == null && this.manager != null) {
this.parser = this.manager.getParserRegistry().createParser(valueType, ParserParameters.empty())
.orElse(null);
.orElse(null);
}
if (this.parser == null) {
this.parser = (c, i) -> ArgumentParseResult
@ -475,7 +490,8 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
this.suggestionsProvider = new DelegatingSuggestionsProvider<>(this.name, this.parser);
}
return new CommandArgument<>(this.required, this.name, this.parser,
this.defaultValue, this.valueType, this.suggestionsProvider);
this.defaultValue, this.valueType, this.suggestionsProvider
);
}
protected final @NonNull String getName() {

View file

@ -44,7 +44,9 @@ public interface CommandSyntaxFormatter<C> {
* @param node Trailing node
* @return Syntax string
*/
@NonNull String apply(@NonNull List<@NonNull CommandArgument<C, ?>> commandArguments,
CommandTree.@Nullable Node<@Nullable CommandArgument<C, ?>> node);
@NonNull String apply(
@NonNull List<@NonNull CommandArgument<C, ?>> commandArguments,
CommandTree.@Nullable Node<@Nullable CommandArgument<C, ?>> node
);
}

View file

@ -49,7 +49,8 @@ final class DelegatingSuggestionsProvider<C> implements BiFunction<@NonNull Comm
@Override
public String toString() {
return String.format("DelegatingSuggestionsProvider{name='%s',parser='%s'}", this.argumentName,
this.parser.getClass().getCanonicalName());
this.parser.getClass().getCanonicalName()
);
}
}

View file

@ -46,8 +46,10 @@ import java.util.List;
public class StandardCommandSyntaxFormatter<C> implements CommandSyntaxFormatter<C> {
@Override
public final @NonNull String apply(final @NonNull List<@NonNull CommandArgument<C, ?>> commandArguments,
final CommandTree.@Nullable Node<@Nullable CommandArgument<C, ?>> node) {
public final @NonNull String apply(
final @NonNull List<@NonNull CommandArgument<C, ?>> commandArguments,
final CommandTree.@Nullable Node<@Nullable CommandArgument<C, ?>> node
) {
final StringBuilder stringBuilder = new StringBuilder();
final Iterator<CommandArgument<C, ?>> iterator = commandArguments.iterator();
while (iterator.hasNext()) {
@ -73,8 +75,9 @@ public class StandardCommandSyntaxFormatter<C> implements CommandSyntaxFormatter
if (commandArgument instanceof FlagArgument) {
final StringBuilder flagBuilder = new StringBuilder();
@SuppressWarnings("unchecked")
final Iterator<CommandFlag<?>> flagIterator = ((FlagArgument<C>) commandArgument).getFlags().iterator();
@SuppressWarnings("unchecked") final Iterator<CommandFlag<?>> flagIterator = ((FlagArgument<C>) commandArgument)
.getFlags()
.iterator();
while (flagIterator.hasNext()) {
final CommandFlag<?> flag = flagIterator.next();
flagBuilder.append("--").append(flag.getName());
@ -140,8 +143,9 @@ public class StandardCommandSyntaxFormatter<C> implements CommandSyntaxFormatter
stringBuilder.append(suffix);
} else if (argument instanceof FlagArgument) {
final StringBuilder flagBuilder = new StringBuilder();
@SuppressWarnings("unchecked")
final Iterator<CommandFlag<?>> flagIterator = ((FlagArgument<C>) argument).getFlags().iterator();
@SuppressWarnings("unchecked") final Iterator<CommandFlag<?>> flagIterator = ((FlagArgument<C>) argument)
.getFlags()
.iterator();
while (flagIterator.hasNext()) {
final CommandFlag<?> flag = flagIterator.next();
flagBuilder.append("--").append(flag.getName());
@ -153,14 +157,14 @@ public class StandardCommandSyntaxFormatter<C> implements CommandSyntaxFormatter
}
}
stringBuilder.append(" ")
.append(prefix)
.append(flagBuilder)
.append(suffix);
.append(prefix)
.append(flagBuilder)
.append(suffix);
} else {
stringBuilder.append(" ")
.append(prefix)
.append(argument.getName())
.append(suffix);
.append(prefix)
.append(argument.getName())
.append(suffix);
}
tail = tail.getChildren().get(0);
}

View file

@ -56,8 +56,10 @@ public final class StaticArgument<C> extends CommandArgument<C, String> {
* @param <C> Command sender type
* @return Constructed argument
*/
public static <C> @NonNull StaticArgument<C> of(final @NonNull String name,
final @NonNull String... aliases) {
public static <C> @NonNull StaticArgument<C> of(
final @NonNull String name,
final @NonNull String... aliases
) {
return new StaticArgument<>(true, name, aliases);
}
@ -104,8 +106,10 @@ public final class StaticArgument<C> extends CommandArgument<C, String> {
}
@Override
public @NonNull ArgumentParseResult<String> parse(final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> inputQueue) {
public @NonNull ArgumentParseResult<String> parse(
final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> inputQueue
) {
final String string = inputQueue.peek();
if (string == null) {
return ArgumentParseResult.failure(new NullPointerException("No input provided"));
@ -118,8 +122,10 @@ public final class StaticArgument<C> extends CommandArgument<C, String> {
}
@Override
public @NonNull List<@NonNull String> suggestions(final @NonNull CommandContext<C> commandContext,
final @NonNull String input) {
public @NonNull List<@NonNull String> suggestions(
final @NonNull CommandContext<C> commandContext,
final @NonNull String input
) {
return Collections.singletonList(this.name);
}

View file

@ -54,13 +54,15 @@ public class ArgumentPair<C, U, V, O> extends CompoundArgument<Pair<U, V>, C, O>
* @param mapper Mapper that maps the sub-arguments to the output type
* @param valueType The output type
*/
protected ArgumentPair(final boolean required,
final @NonNull String name,
final @NonNull Pair<@NonNull String, @NonNull String> names,
final @NonNull Pair<@NonNull Class<U>, @NonNull Class<V>> types,
final @NonNull Pair<@NonNull ArgumentParser<C, U>, @NonNull ArgumentParser<C, V>> parserPair,
final @NonNull BiFunction<@NonNull C, @NonNull Pair<@NonNull U, @NonNull V>, @NonNull O> mapper,
final @NonNull TypeToken<O> valueType) {
protected ArgumentPair(
final boolean required,
final @NonNull String name,
final @NonNull Pair<@NonNull String, @NonNull String> names,
final @NonNull Pair<@NonNull Class<U>, @NonNull Class<V>> types,
final @NonNull Pair<@NonNull ArgumentParser<C, U>, @NonNull ArgumentParser<C, V>> parserPair,
final @NonNull BiFunction<@NonNull C, @NonNull Pair<@NonNull U, @NonNull V>, @NonNull O> mapper,
final @NonNull TypeToken<O> valueType
) {
super(required, name, names, parserPair, types, mapper, o -> Pair.of((U) o[0], (V) o[1]), valueType);
}
@ -78,21 +80,27 @@ public class ArgumentPair<C, U, V, O> extends CompoundArgument<Pair<U, V>, C, O>
* @param <V> Second parsed type
* @return Intermediary builder
*/
public static <C, U, V> @NonNull ArgumentPairIntermediaryBuilder<C, U, V> of(final @NonNull CommandManager<C> manager,
final @NonNull String name,
final @NonNull Pair<@NonNull String,
@NonNull String> names,
final @NonNull Pair<@NonNull Class<U>,
@NonNull Class<V>> types) {
public static <C, U, V> @NonNull ArgumentPairIntermediaryBuilder<C, U, V> of(
final @NonNull CommandManager<C> manager,
final @NonNull String name,
final @NonNull Pair<@NonNull String,
@NonNull String> names,
final @NonNull Pair<@NonNull Class<U>,
@NonNull Class<V>> types
) {
final ParserRegistry<C> parserRegistry = manager.getParserRegistry();
final ArgumentParser<C, U> firstParser = parserRegistry.createParser(TypeToken.get(types.getFirst()),
ParserParameters.empty()).orElseThrow(() ->
new IllegalArgumentException(
"Could not create parser for primary type"));
final ArgumentParser<C, V> secondaryParser = parserRegistry.createParser(TypeToken.get(types.getSecond()),
ParserParameters.empty()).orElseThrow(() ->
new IllegalArgumentException(
"Could not create parser for secondary type"));
final ArgumentParser<C, U> firstParser = parserRegistry.createParser(
TypeToken.get(types.getFirst()),
ParserParameters.empty()
).orElseThrow(() ->
new IllegalArgumentException(
"Could not create parser for primary type"));
final ArgumentParser<C, V> secondaryParser = parserRegistry.createParser(
TypeToken.get(types.getSecond()),
ParserParameters.empty()
).orElseThrow(() ->
new IllegalArgumentException(
"Could not create parser for secondary type"));
return new ArgumentPairIntermediaryBuilder<>(true, name, names, Pair.of(firstParser, secondaryParser), types);
}
@ -105,12 +113,14 @@ public class ArgumentPair<C, U, V, O> extends CompoundArgument<Pair<U, V>, C, O>
private final Pair<String, String> names;
private final Pair<Class<U>, Class<V>> types;
private ArgumentPairIntermediaryBuilder(final boolean required,
final @NonNull String name,
final @NonNull Pair<@NonNull String, @NonNull String> names,
final @NonNull Pair<@NonNull ArgumentParser<@NonNull C, @NonNull U>,
@NonNull ArgumentParser<@NonNull C, @NonNull V>> parserPair,
final @NonNull Pair<@NonNull Class<U>, @NonNull Class<V>> types) {
private ArgumentPairIntermediaryBuilder(
final boolean required,
final @NonNull String name,
final @NonNull Pair<@NonNull String, @NonNull String> names,
final @NonNull Pair<@NonNull ArgumentParser<@NonNull C, @NonNull U>,
@NonNull ArgumentParser<@NonNull C, @NonNull V>> parserPair,
final @NonNull Pair<@NonNull Class<U>, @NonNull Class<V>> types
) {
this.required = required;
this.name = name;
this.names = names;
@ -124,14 +134,16 @@ public class ArgumentPair<C, U, V, O> extends CompoundArgument<Pair<U, V>, C, O>
* @return Argument pair
*/
public @NonNull ArgumentPair<@NonNull C, @NonNull U, @NonNull V, @NonNull Pair<@NonNull U, @NonNull V>> simple() {
return new ArgumentPair<C, U, V, Pair<U, V>>(this.required,
this.name,
this.names,
this.types,
this.parserPair,
(sender, pair) -> pair,
new TypeToken<Pair<U, V>>() {
});
return new ArgumentPair<C, U, V, Pair<U, V>>(
this.required,
this.name,
this.names,
this.types,
this.parserPair,
(sender, pair) -> pair,
new TypeToken<Pair<U, V>>() {
}
);
}
/**
@ -142,9 +154,11 @@ public class ArgumentPair<C, U, V, O> extends CompoundArgument<Pair<U, V>, C, O>
* @param <O> Output type
* @return Created pair
*/
public <O> @NonNull ArgumentPair<C, U, V, O> withMapper(final @NonNull TypeToken<O> clazz,
final @NonNull BiFunction<@NonNull C, @NonNull Pair<@NonNull U,
@NonNull V>, @NonNull O> mapper) {
public <O> @NonNull ArgumentPair<C, U, V, O> withMapper(
final @NonNull TypeToken<O> clazz,
final @NonNull BiFunction<@NonNull C, @NonNull Pair<@NonNull U,
@NonNull V>, @NonNull O> mapper
) {
return new ArgumentPair<C, U, V, O>(this.required, this.name, this.names, this.types, this.parserPair, mapper, clazz);
}
@ -158,7 +172,8 @@ public class ArgumentPair<C, U, V, O> extends CompoundArgument<Pair<U, V>, C, O>
*/
public <O> @NonNull ArgumentPair<@NonNull C, @NonNull U, @NonNull V, @NonNull O> withMapper(
final @NonNull Class<O> clazz,
final @NonNull BiFunction<@NonNull C, @NonNull Pair<@NonNull U, @NonNull V>, @NonNull O> mapper) {
final @NonNull BiFunction<@NonNull C, @NonNull Pair<@NonNull U, @NonNull V>, @NonNull O> mapper
) {
return this.withMapper(TypeToken.get(clazz), mapper);
}

View file

@ -55,15 +55,17 @@ public class ArgumentTriplet<C, U, V, W, O> extends CompoundArgument<Triplet<U,
* @param mapper Mapper that maps the sub-arguments to the output type
* @param valueType The output type
*/
protected ArgumentTriplet(final boolean required,
final @NonNull String name,
final @NonNull Triplet<@NonNull String, @NonNull String, @NonNull String> names,
final @NonNull Triplet<@NonNull Class<U>, @NonNull Class<V>, @NonNull Class<W>> types,
final @NonNull Triplet<@NonNull ArgumentParser<C, U>, @NonNull ArgumentParser<C, V>,
@NonNull ArgumentParser<C, W>> parserTriplet,
final @NonNull BiFunction<@NonNull C,
@NonNull Triplet<U, @NonNull V, @NonNull W>, @NonNull O> mapper,
final @NonNull TypeToken<O> valueType) {
protected ArgumentTriplet(
final boolean required,
final @NonNull String name,
final @NonNull Triplet<@NonNull String, @NonNull String, @NonNull String> names,
final @NonNull Triplet<@NonNull Class<U>, @NonNull Class<V>, @NonNull Class<W>> types,
final @NonNull Triplet<@NonNull ArgumentParser<C, U>, @NonNull ArgumentParser<C, V>,
@NonNull ArgumentParser<C, W>> parserTriplet,
final @NonNull BiFunction<@NonNull C,
@NonNull Triplet<U, @NonNull V, @NonNull W>, @NonNull O> mapper,
final @NonNull TypeToken<O> valueType
) {
super(required, name, names, parserTriplet, types, mapper, o -> Triplet.of((U) o[0], (V) o[1], (W) o[2]), valueType);
}
@ -83,25 +85,34 @@ public class ArgumentTriplet<C, U, V, W, O> extends CompoundArgument<Triplet<U,
* @return Intermediary builder
*/
public static <C, U, V, W> @NonNull ArgumentTripletIntermediaryBuilder<@NonNull C, @NonNull U, @NonNull V, @NonNull W>
of(final @NonNull CommandManager<C> manager,
final @NonNull String name,
final @NonNull Triplet<@NonNull String, @NonNull String, @NonNull String> names,
final @NonNull Triplet<@NonNull Class<U>, @NonNull Class<V>, @NonNull Class<W>> types) {
of(
final @NonNull CommandManager<C> manager,
final @NonNull String name,
final @NonNull Triplet<@NonNull String, @NonNull String, @NonNull String> names,
final @NonNull Triplet<@NonNull Class<U>, @NonNull Class<V>, @NonNull Class<W>> types
) {
final ParserRegistry<C> parserRegistry = manager.getParserRegistry();
final ArgumentParser<C, U> firstParser = parserRegistry.createParser(TypeToken.get(types.getFirst()),
ParserParameters.empty()).orElseThrow(() ->
new IllegalArgumentException(
"Could not create parser for primary type"));
final ArgumentParser<C, V> secondaryParser = parserRegistry.createParser(TypeToken.get(types.getSecond()),
ParserParameters.empty()).orElseThrow(() ->
new IllegalArgumentException(
"Could not create parser for secondary type"));
final ArgumentParser<C, W> tertiaryParser = parserRegistry.createParser(TypeToken.get(types.getThird()),
ParserParameters.empty()).orElseThrow(() ->
new IllegalArgumentException(
"Could not create parser for tertiary type"));
final ArgumentParser<C, U> firstParser = parserRegistry.createParser(
TypeToken.get(types.getFirst()),
ParserParameters.empty()
).orElseThrow(() ->
new IllegalArgumentException(
"Could not create parser for primary type"));
final ArgumentParser<C, V> secondaryParser = parserRegistry.createParser(
TypeToken.get(types.getSecond()),
ParserParameters.empty()
).orElseThrow(() ->
new IllegalArgumentException(
"Could not create parser for secondary type"));
final ArgumentParser<C, W> tertiaryParser = parserRegistry.createParser(
TypeToken.get(types.getThird()),
ParserParameters.empty()
).orElseThrow(() ->
new IllegalArgumentException(
"Could not create parser for tertiary type"));
return new ArgumentTripletIntermediaryBuilder<>(true, name, names,
Triplet.of(firstParser, secondaryParser, tertiaryParser), types);
Triplet.of(firstParser, secondaryParser, tertiaryParser), types
);
}
@SuppressWarnings("ALL")
@ -113,15 +124,17 @@ public class ArgumentTriplet<C, U, V, W, O> extends CompoundArgument<Triplet<U,
private final Triplet<String, String, String> names;
private final Triplet<Class<U>, Class<V>, Class<W>> types;
private ArgumentTripletIntermediaryBuilder(final boolean required,
final @NonNull String name,
final @NonNull Triplet<@NonNull String, @NonNull String,
@NonNull String> names,
final @NonNull Triplet<@NonNull ArgumentParser<C, U>,
@NonNull ArgumentParser<C, V>,
@NonNull ArgumentParser<C, W>> parserTriplet,
final @NonNull Triplet<@NonNull Class<U>,
@NonNull Class<V>, @NonNull Class<W>> types) {
private ArgumentTripletIntermediaryBuilder(
final boolean required,
final @NonNull String name,
final @NonNull Triplet<@NonNull String, @NonNull String,
@NonNull String> names,
final @NonNull Triplet<@NonNull ArgumentParser<C, U>,
@NonNull ArgumentParser<C, V>,
@NonNull ArgumentParser<C, W>> parserTriplet,
final @NonNull Triplet<@NonNull Class<U>,
@NonNull Class<V>, @NonNull Class<W>> types
) {
this.required = required;
this.name = name;
this.names = names;
@ -136,14 +149,16 @@ public class ArgumentTriplet<C, U, V, W, O> extends CompoundArgument<Triplet<U,
*/
public @NonNull ArgumentTriplet<@NonNull C, @NonNull U, @NonNull V,
@NonNull W, Triplet<U, V, W>> simple() {
return new ArgumentTriplet<>(this.required,
this.name,
this.names,
this.types,
this.parserTriplet,
(sender, triplet) -> triplet,
new TypeToken<Triplet<U, V, W>>() {
});
return new ArgumentTriplet<>(
this.required,
this.name,
this.names,
this.types,
this.parserTriplet,
(sender, triplet) -> triplet,
new TypeToken<Triplet<U, V, W>>() {
}
);
}
/**
@ -155,9 +170,11 @@ public class ArgumentTriplet<C, U, V, W, O> extends CompoundArgument<Triplet<U,
* @return Created triplet
*/
public <O> @NonNull ArgumentTriplet<@NonNull C, @NonNull U, @NonNull V,
@NonNull W, @NonNull O> withMapper(final @NonNull TypeToken<O> clazz,
final @NonNull BiFunction<@NonNull C, @NonNull Triplet<@NonNull U,
@NonNull V, @NonNull W>, @NonNull O> mapper) {
@NonNull W, @NonNull O> withMapper(
final @NonNull TypeToken<O> clazz,
final @NonNull BiFunction<@NonNull C, @NonNull Triplet<@NonNull U,
@NonNull V, @NonNull W>, @NonNull O> mapper
) {
return new ArgumentTriplet<>(this.required, this.name, this.names, this.types, this.parserTriplet, mapper, clazz);
}
@ -169,12 +186,15 @@ public class ArgumentTriplet<C, U, V, W, O> extends CompoundArgument<Triplet<U,
* @param <O> Output type
* @return Created triplet
*/
public <O> @NonNull ArgumentTriplet<C, U, V, W, O> withMapper(final @NonNull Class<O> clazz,
final @NonNull BiFunction<@NonNull C, @NonNull Triplet<
@NonNull U, @NonNull V, @NonNull W>,
@NonNull O> mapper) {
public <O> @NonNull ArgumentTriplet<C, U, V, W, O> withMapper(
final @NonNull Class<O> clazz,
final @NonNull BiFunction<@NonNull C, @NonNull Triplet<
@NonNull U, @NonNull V, @NonNull W>,
@NonNull O> mapper
) {
return new ArgumentTriplet<>(this.required, this.name, this.names, this.types,
this.parserTriplet, mapper, TypeToken.get(clazz));
this.parserTriplet, mapper, TypeToken.get(clazz)
);
}
}

View file

@ -61,20 +61,24 @@ public class CompoundArgument<T extends Tuple, C, O> extends CommandArgument<C,
* @param tupleFactory Function to use when creating tuple
* @param valueType The output type
*/
public CompoundArgument(final boolean required,
final @NonNull String name,
final @NonNull Tuple names,
final @NonNull Tuple parserTuple,
final @NonNull Tuple types,
final @NonNull BiFunction<@NonNull C, @NonNull T, @NonNull O> mapper,
final @NonNull Function<@NonNull Object[], @NonNull T> tupleFactory,
final @NonNull TypeToken<O> valueType) {
super(required,
name,
new CompoundParser<>(parserTuple, mapper, tupleFactory),
"",
valueType,
null);
public CompoundArgument(
final boolean required,
final @NonNull String name,
final @NonNull Tuple names,
final @NonNull Tuple parserTuple,
final @NonNull Tuple types,
final @NonNull BiFunction<@NonNull C, @NonNull T, @NonNull O> mapper,
final @NonNull Function<@NonNull Object[], @NonNull T> tupleFactory,
final @NonNull TypeToken<O> valueType
) {
super(
required,
name,
new CompoundParser<>(parserTuple, mapper, tupleFactory),
"",
valueType,
null
);
this.parserTuple = parserTuple;
this.names = names;
this.types = types;
@ -114,17 +118,21 @@ public class CompoundArgument<T extends Tuple, C, O> extends CommandArgument<C,
private final BiFunction<C, T, O> mapper;
private final Function<Object[], T> tupleFactory;
private CompoundParser(final @NonNull Tuple parserTuple,
final @NonNull BiFunction<@NonNull C, @NonNull T, @NonNull O> mapper,
final @NonNull Function<@NonNull Object[], @NonNull T> tupleFactory) {
private CompoundParser(
final @NonNull Tuple parserTuple,
final @NonNull BiFunction<@NonNull C, @NonNull T, @NonNull O> mapper,
final @NonNull Function<@NonNull Object[], @NonNull T> tupleFactory
) {
this.parsers = parserTuple.toArray();
this.mapper = mapper;
this.tupleFactory = tupleFactory;
}
@Override
public @NonNull ArgumentParseResult<O> parse(final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> inputQueue) {
public @NonNull ArgumentParseResult<O> parse(
final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> inputQueue
) {
final Object[] output = new Object[this.parsers.length];
for (int i = 0; i < this.parsers.length; i++) {
@SuppressWarnings("unchecked") final ArgumentParser<C, ?> parser = (ArgumentParser<C, ?>) this.parsers[i];
@ -141,16 +149,20 @@ public class CompoundArgument<T extends Tuple, C, O> extends CommandArgument<C,
* Now check if the mapper threw any exceptions
*/
try {
return ArgumentParseResult.success(this.mapper.apply(commandContext.getSender(),
this.tupleFactory.apply(output)));
return ArgumentParseResult.success(this.mapper.apply(
commandContext.getSender(),
this.tupleFactory.apply(output)
));
} catch (final Exception e) {
return ArgumentParseResult.failure(e);
}
}
@Override
public @NonNull List<@NonNull String> suggestions(final @NonNull CommandContext<C> commandContext,
final @NonNull String input) {
public @NonNull List<@NonNull String> suggestions(
final @NonNull CommandContext<C> commandContext,
final @NonNull String input
) {
/*
This method will be called n times, each time for each of the internal types.
The problem is that we need to then know which of the parsers to forward the
@ -163,6 +175,7 @@ public class CompoundArgument<T extends Tuple, C, O> extends CommandArgument<C,
//noinspection all
return ((ArgumentParser<C, ?>) this.parsers[argument]).suggestions(commandContext, input);
}
}
}

View file

@ -66,10 +66,12 @@ public final class FlagArgument<C> extends CommandArgument<C, Object> {
* @param flags Flags
*/
public FlagArgument(final Collection<CommandFlag<?>> flags) {
super(false,
FLAG_ARGUMENT_NAME,
new FlagArgumentParser<>(flags.toArray(new CommandFlag<?>[0])),
Object.class);
super(
false,
FLAG_ARGUMENT_NAME,
new FlagArgumentParser<>(flags.toArray(new CommandFlag<?>[0])),
Object.class
);
this.flags = flags;
}
@ -92,8 +94,10 @@ public final class FlagArgument<C> extends CommandArgument<C, Object> {
}
@Override
public @NonNull ArgumentParseResult<@NonNull Object> parse(final @NonNull CommandContext<@NonNull C> commandContext,
final @NonNull Queue<@NonNull String> inputQueue) {
public @NonNull ArgumentParseResult<@NonNull Object> parse(
final @NonNull CommandContext<@NonNull C> commandContext,
final @NonNull Queue<@NonNull String> inputQueue
) {
/*
This argument must necessarily be the last so we can just consume all remaining input. This argument type
is similar to a greedy string in that sense. But, we need to keep all flag logic contained to the parser
@ -144,13 +148,15 @@ public final class FlagArgument<C> extends CommandArgument<C, Object> {
if (currentFlag == null) {
return ArgumentParseResult.failure(
new IllegalArgumentException(String.format("No flag started. Don't"
+ " know what to do with '%s'", string)));
+ " know what to do with '%s'", string)));
} else {
final ArgumentParseResult<?> result =
((CommandArgument) currentFlag.getCommandArgument())
.getParser()
.parse(commandContext,
new LinkedList<>(Collections.singletonList(string)));
.parse(
commandContext,
new LinkedList<>(Collections.singletonList(string))
);
if (result.getFailure().isPresent()) {
return ArgumentParseResult.failure(result.getFailure().get());
} else {
@ -167,8 +173,10 @@ public final class FlagArgument<C> extends CommandArgument<C, Object> {
}
@Override
public @NonNull List<@NonNull String> suggestions(final @NonNull CommandContext<C> commandContext,
final @NonNull String input) {
public @NonNull List<@NonNull String> suggestions(
final @NonNull CommandContext<C> commandContext,
final @NonNull String input
) {
/* Check if we have a last flag stored */
final String lastArg = commandContext.getOrDefault(FLAG_META, "");
if (lastArg.isEmpty() || !lastArg.startsWith("-")) {

View file

@ -48,10 +48,12 @@ public final class CommandFlag<T> {
private final @Nullable CommandArgument<?, T> commandArgument;
private CommandFlag(final @NonNull String name,
final @NonNull String @NonNull [] aliases,
final @NonNull Description description,
final @Nullable CommandArgument<?, T> commandArgument) {
private CommandFlag(
final @NonNull String name,
final @NonNull String @NonNull [] aliases,
final @NonNull Description description,
final @Nullable CommandArgument<?, T> commandArgument
) {
this.name = name;
this.aliases = aliases;
this.description = description;
@ -135,10 +137,12 @@ public final class CommandFlag<T> {
private final Description description;
private final CommandArgument<?, T> commandArgument;
private Builder(final @NonNull String name,
final @NonNull String[] aliases,
final @NonNull Description description,
final @Nullable CommandArgument<?, T> commandArgument) {
private Builder(
final @NonNull String name,
final @NonNull String[] aliases,
final @NonNull Description description,
final @Nullable CommandArgument<?, T> commandArgument
) {
this.name = name;
this.aliases = aliases;
this.description = description;

View file

@ -70,8 +70,10 @@ public final class FlagContext {
* @param value Flag value
* @param <T> Value type
*/
public <T> void addValueFlag(final @NonNull CommandFlag<T> flag,
final @NonNull T value) {
public <T> void addValueFlag(
final @NonNull CommandFlag<T> flag,
final @NonNull T value
) {
this.flagValues.put(flag.getName(), value);
}
@ -81,7 +83,7 @@ public final class FlagContext {
*
* @param flag Flag name
* @return {@code true} if the flag is presence and the flag is a presence flag,
* else {@code false}
* else {@code false}
*/
public boolean isPresent(final @NonNull String flag) {
final Object value = this.flagValues.get(flag);
@ -96,8 +98,10 @@ public final class FlagContext {
* @param <T> Value type
* @return Stored value, or the supplied default value
*/
public <T> @Nullable T getValue(final @NonNull String name,
final @Nullable T defaultValue) {
public <T> @Nullable T getValue(
final @NonNull String name,
final @Nullable T defaultValue
) {
final Object value = this.flagValues.get(name);
if (value == null) {
return defaultValue;

View file

@ -118,6 +118,7 @@ public abstract class ArgumentParseResult<T> {
public @NonNull Optional<Throwable> getFailure() {
return Optional.of(this.failure);
}
}
}

View file

@ -46,8 +46,10 @@ public interface ArgumentParser<C, T> {
* @param inputQueue The queue of arguments
* @return Parsed command result
*/
@NonNull ArgumentParseResult<@NonNull T> parse(@NonNull CommandContext<@NonNull C> commandContext,
@NonNull Queue<@NonNull String> inputQueue);
@NonNull ArgumentParseResult<@NonNull T> parse(
@NonNull CommandContext<@NonNull C> commandContext,
@NonNull Queue<@NonNull String> inputQueue
);
/**
* Get a list of suggested arguments that would be correctly parsed by this parser
@ -56,8 +58,10 @@ public interface ArgumentParser<C, T> {
* @param input Input string
* @return List of suggestions
*/
default @NonNull List<@NonNull String> suggestions(final @NonNull CommandContext<C> commandContext,
final @NonNull String input) {
default @NonNull List<@NonNull String> suggestions(
final @NonNull CommandContext<C> commandContext,
final @NonNull String input
) {
return Collections.emptyList();
}

View file

@ -44,8 +44,10 @@ public class ParserParameter<T> {
* @param key Parameter key
* @param expectedType Type that is expected to be mapped to this parameter
*/
public ParserParameter(final @NonNull String key,
final @NonNull TypeToken<T> expectedType) {
public ParserParameter(
final @NonNull String key,
final @NonNull TypeToken<T> expectedType
) {
this.key = key;
this.expectedType = expectedType;
}

View file

@ -53,8 +53,10 @@ public final class ParserParameters {
* @param <T> Value type
* @return Constructed instance
*/
public static <T> @NonNull ParserParameters single(final @NonNull ParserParameter<T> parameter,
final @NonNull T value) {
public static <T> @NonNull ParserParameters single(
final @NonNull ParserParameter<T> parameter,
final @NonNull T value
) {
final ParserParameters parameters = new ParserParameters();
parameters.store(parameter, value);
return parameters;
@ -78,8 +80,10 @@ public final class ParserParameters {
* @param value Object
* @param <T> Parameter type
*/
public <T> void store(final @NonNull ParserParameter<T> parameter,
final @NonNull T value) {
public <T> void store(
final @NonNull ParserParameter<T> parameter,
final @NonNull T value
) {
this.internalMap.put(parameter, value);
}
@ -92,8 +96,10 @@ public final class ParserParameters {
* @return Parameter value
*/
@SuppressWarnings("unchecked")
public <T> @NonNull T get(final @NonNull ParserParameter<T> parameter,
final @NonNull T defaultValue) {
public <T> @NonNull T get(
final @NonNull ParserParameter<T> parameter,
final @NonNull T defaultValue
) {
return (T) this.internalMap.getOrDefault(parameter, defaultValue);
}

View file

@ -49,8 +49,10 @@ public interface ParserRegistry<C> {
* to configure the parser, many of which are documented in {@link StandardParameters}
* @param <T> Generic type specifying what is produced by the parser
*/
<T> void registerParserSupplier(@NonNull TypeToken<T> type,
@NonNull Function<@NonNull ParserParameters, @NonNull ArgumentParser<C, ?>> supplier);
<T> void registerParserSupplier(
@NonNull TypeToken<T> type,
@NonNull Function<@NonNull ParserParameters, @NonNull ArgumentParser<C, ?>> supplier
);
/**
* Register a named parser supplier
@ -59,8 +61,10 @@ public interface ParserRegistry<C> {
* @param supplier The function that generates the parser. The map supplied my contain parameters used
* to configure the parser, many of which are documented in {@link StandardParameters}
*/
void registerNamedParserSupplier(@NonNull String name,
@NonNull Function<@NonNull ParserParameters, @NonNull ArgumentParser<C, ?>> supplier);
void registerNamedParserSupplier(
@NonNull String name,
@NonNull Function<@NonNull ParserParameters, @NonNull ArgumentParser<C, ?>> supplier
);
/**
* Register a mapper that maps annotation instances to a map of parameter-object pairs
@ -71,9 +75,11 @@ public interface ParserRegistry<C> {
* @param <A> Annotation type
* @param <T> Type of the object that the parser is retrieved for
*/
<A extends Annotation, T> void registerAnnotationMapper(@NonNull Class<A> annotation,
@NonNull BiFunction<@NonNull A, @NonNull TypeToken<?>,
@NonNull ParserParameters> mapper);
<A extends Annotation, T> void registerAnnotationMapper(
@NonNull Class<A> annotation,
@NonNull BiFunction<@NonNull A, @NonNull TypeToken<?>,
@NonNull ParserParameters> mapper
);
/**
* Parse annotations into {@link ParserParameters}
@ -82,8 +88,10 @@ public interface ParserRegistry<C> {
* @param annotations The annotations to be parsed
* @return Parsed parameters
*/
@NonNull ParserParameters parseAnnotations(@NonNull TypeToken<?> parsingType,
@NonNull Collection<? extends Annotation> annotations);
@NonNull ParserParameters parseAnnotations(
@NonNull TypeToken<?> parsingType,
@NonNull Collection<? extends Annotation> annotations
);
/**
* Attempt to create a {@link ArgumentParser} for a specified type, using
@ -94,8 +102,10 @@ public interface ParserRegistry<C> {
* @param <T> Generic type
* @return Parser, if one can be created
*/
<T> @NonNull Optional<ArgumentParser<C, T>> createParser(@NonNull TypeToken<T> type,
@NonNull ParserParameters parserParameters);
<T> @NonNull Optional<ArgumentParser<C, T>> createParser(
@NonNull TypeToken<T> type,
@NonNull ParserParameters parserParameters
);
/**
* Attempt to create a {@link ArgumentParser} for a specified type, using
@ -106,7 +116,9 @@ public interface ParserRegistry<C> {
* @param <T> Generic type
* @return Parser, if one can be created
*/
<T> @NonNull Optional<ArgumentParser<C, T>> createParser(@NonNull String name,
@NonNull ParserParameters parserParameters);
<T> @NonNull Optional<ArgumentParser<C, T>> createParser(
@NonNull String name,
@NonNull ParserParameters parserParameters
);
}

View file

@ -63,8 +63,10 @@ public final class StandardParameters {
private StandardParameters() {
}
private static <T> @NonNull ParserParameter<T> create(final @NonNull String key,
final @NonNull TypeToken<T> expectedType) {
private static <T> @NonNull ParserParameter<T> create(
final @NonNull String key,
final @NonNull TypeToken<T> expectedType
) {
return new ParserParameter<>(key, expectedType);
}

View file

@ -23,9 +23,8 @@
//
package cloud.commandframework.arguments.parser;
import cloud.commandframework.annotations.specifier.Greedy;
import cloud.commandframework.arguments.standard.UUIDArgument;
import cloud.commandframework.annotations.specifier.Completions;
import cloud.commandframework.annotations.specifier.Greedy;
import cloud.commandframework.annotations.specifier.Range;
import cloud.commandframework.arguments.standard.BooleanArgument;
import cloud.commandframework.arguments.standard.ByteArgument;
@ -36,6 +35,7 @@ import cloud.commandframework.arguments.standard.FloatArgument;
import cloud.commandframework.arguments.standard.IntegerArgument;
import cloud.commandframework.arguments.standard.ShortArgument;
import cloud.commandframework.arguments.standard.StringArgument;
import cloud.commandframework.arguments.standard.UUIDArgument;
import io.leangen.geantyref.GenericTypeReflector;
import io.leangen.geantyref.TypeToken;
import org.checkerframework.checker.nullness.qual.NonNull;
@ -86,60 +86,83 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
/* Register standard types */
this.registerParserSupplier(TypeToken.get(Byte.class), options ->
new ByteArgument.ByteParser<C>((byte) options.get(StandardParameters.RANGE_MIN, Byte.MIN_VALUE),
(byte) options.get(StandardParameters.RANGE_MAX, Byte.MAX_VALUE)));
new ByteArgument.ByteParser<C>(
(byte) options.get(StandardParameters.RANGE_MIN, Byte.MIN_VALUE),
(byte) options.get(StandardParameters.RANGE_MAX, Byte.MAX_VALUE)
));
this.registerParserSupplier(TypeToken.get(Short.class), options ->
new ShortArgument.ShortParser<C>((short) options.get(StandardParameters.RANGE_MIN, Short.MIN_VALUE),
(short) options.get(StandardParameters.RANGE_MAX, Short.MAX_VALUE)));
new ShortArgument.ShortParser<C>(
(short) options.get(StandardParameters.RANGE_MIN, Short.MIN_VALUE),
(short) options.get(StandardParameters.RANGE_MAX, Short.MAX_VALUE)
));
this.registerParserSupplier(TypeToken.get(Integer.class), options ->
new IntegerArgument.IntegerParser<C>((int) options.get(StandardParameters.RANGE_MIN, Integer.MIN_VALUE),
(int) options.get(StandardParameters.RANGE_MAX, Integer.MAX_VALUE)));
new IntegerArgument.IntegerParser<C>(
(int) options.get(StandardParameters.RANGE_MIN, Integer.MIN_VALUE),
(int) options.get(StandardParameters.RANGE_MAX, Integer.MAX_VALUE)
));
this.registerParserSupplier(TypeToken.get(Float.class), options ->
new FloatArgument.FloatParser<C>((float) options.get(StandardParameters.RANGE_MIN, Float.MIN_VALUE),
(float) options.get(StandardParameters.RANGE_MAX, Float.MAX_VALUE)));
new FloatArgument.FloatParser<C>(
(float) options.get(StandardParameters.RANGE_MIN, Float.MIN_VALUE),
(float) options.get(StandardParameters.RANGE_MAX, Float.MAX_VALUE)
));
this.registerParserSupplier(TypeToken.get(Double.class), options ->
new DoubleArgument.DoubleParser<C>((double) options.get(StandardParameters.RANGE_MIN, Double.MIN_VALUE),
(double) options.get(StandardParameters.RANGE_MAX, Double.MAX_VALUE)));
new DoubleArgument.DoubleParser<C>(
(double) options.get(StandardParameters.RANGE_MIN, Double.MIN_VALUE),
(double) options.get(StandardParameters.RANGE_MAX, Double.MAX_VALUE)
));
this.registerParserSupplier(TypeToken.get(Character.class), options -> new CharArgument.CharacterParser<C>());
/* Make this one less awful */
this.registerParserSupplier(TypeToken.get(String.class), options -> {
final boolean greedy = options.get(StandardParameters.GREEDY, false);
final StringArgument.StringMode stringMode = greedy
? StringArgument.StringMode.GREEDY
: StringArgument.StringMode.SINGLE;
? StringArgument.StringMode.GREEDY
: StringArgument.StringMode.SINGLE;
return new StringArgument.StringParser<C>(
stringMode,
(context, s) -> Arrays.asList(options.get(StandardParameters.COMPLETIONS, new String[0])));
(context, s) -> Arrays.asList(options.get(StandardParameters.COMPLETIONS, new String[0]))
);
});
/* Add options to this */
this.registerParserSupplier(TypeToken.get(Boolean.class), options -> new BooleanArgument.BooleanParser<>(false));
this.registerParserSupplier(TypeToken.get(UUID.class), options -> new UUIDArgument.UUIDParser<>());
}
private static boolean isPrimitive(final @NonNull TypeToken<?> type) {
return GenericTypeReflector.erase(type.getType()).isPrimitive();
}
@Override
public <T> void registerParserSupplier(final @NonNull TypeToken<T> type,
final @NonNull Function<@NonNull ParserParameters,
@NonNull ArgumentParser<C, ?>> supplier) {
public <T> void registerParserSupplier(
final @NonNull TypeToken<T> type,
final @NonNull Function<@NonNull ParserParameters,
@NonNull ArgumentParser<C, ?>> supplier
) {
this.parserSuppliers.put(type, supplier);
}
@Override
public void registerNamedParserSupplier(final @NonNull String name,
final @NonNull Function<@NonNull ParserParameters,
@NonNull ArgumentParser<C, ?>> supplier) {
public void registerNamedParserSupplier(
final @NonNull String name,
final @NonNull Function<@NonNull ParserParameters,
@NonNull ArgumentParser<C, ?>> supplier
) {
this.namedParsers.put(name, supplier);
}
@Override
public <A extends Annotation, T> void registerAnnotationMapper(final @NonNull Class<A> annotation,
final @NonNull BiFunction<@NonNull A, @NonNull TypeToken<?>,
@NonNull ParserParameters> mapper) {
public <A extends Annotation, T> void registerAnnotationMapper(
final @NonNull Class<A> annotation,
final @NonNull BiFunction<@NonNull A, @NonNull TypeToken<?>,
@NonNull ParserParameters> mapper
) {
this.annotationMappers.put(annotation, mapper);
}
@Override
public @NonNull ParserParameters parseAnnotations(final @NonNull TypeToken<?> parsingType,
final @NonNull Collection<@NonNull ? extends Annotation> annotations) {
public @NonNull ParserParameters parseAnnotations(
final @NonNull TypeToken<?> parsingType,
final @NonNull Collection<@NonNull ? extends Annotation> annotations
) {
final ParserParameters parserParameters = new ParserParameters();
annotations.forEach(annotation -> {
// noinspection all
@ -155,8 +178,10 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
}
@Override
public <T> @NonNull Optional<ArgumentParser<C, T>> createParser(final @NonNull TypeToken<T> type,
final @NonNull ParserParameters parserParameters) {
public <T> @NonNull Optional<ArgumentParser<C, T>> createParser(
final @NonNull TypeToken<T> type,
final @NonNull ParserParameters parserParameters
) {
final TypeToken<?> actualType;
if (GenericTypeReflector.erase(type.getType()).isPrimitive()) {
actualType = TypeToken.get(PRIMITIVE_MAPPINGS.get(GenericTypeReflector.erase(type.getType())));
@ -180,8 +205,10 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
}
@Override
public <T> @NonNull Optional<ArgumentParser<C, T>> createParser(final @NonNull String name,
final @NonNull ParserParameters parserParameters) {
public <T> @NonNull Optional<ArgumentParser<C, T>> createParser(
final @NonNull String name,
final @NonNull ParserParameters parserParameters
) {
final Function<ParserParameters, ArgumentParser<C, ?>> producer = this.namedParsers.get(name);
if (producer == null) {
return Optional.empty();
@ -191,12 +218,6 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
return Optional.of(parser);
}
private static boolean isPrimitive(final @NonNull TypeToken<?> type) {
return GenericTypeReflector.erase(type.getType()).isPrimitive();
}
private static final class RangeMapper<T> implements BiFunction<@NonNull Range, @NonNull TypeToken<?>,
@NonNull ParserParameters> {

View file

@ -37,14 +37,17 @@ import java.util.function.BiFunction;
@SuppressWarnings("unused")
public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
private final boolean liberal;
private BooleanArgument(final boolean required,
final @NonNull String name,
final boolean liberal,
final @NonNull String defaultValue,
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
@NonNull List<@NonNull String>> suggestionsProvider) {
private BooleanArgument(
final boolean required,
final @NonNull String name,
final boolean liberal,
final @NonNull String defaultValue,
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
@NonNull List<@NonNull String>> suggestionsProvider
) {
super(required, name, new BooleanParser<>(liberal), defaultValue, Boolean.class, suggestionsProvider);
this.liberal = liberal;
}
@ -90,8 +93,10 @@ public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull CommandArgument<C, Boolean> optional(final @NonNull String name,
final boolean defaultBoolean) {
public static <C> @NonNull CommandArgument<C, Boolean> optional(
final @NonNull String name,
final boolean defaultBoolean
) {
return BooleanArgument.<C>newBuilder(name).asOptionalWithDefault(Boolean.toString(defaultBoolean)).build();
}
@ -131,7 +136,8 @@ public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
@Override
public @NonNull BooleanArgument<C> build() {
return new BooleanArgument<>(this.isRequired(), this.getName(), this.liberal,
this.getDefaultValue(), this.getSuggestionsProvider());
this.getDefaultValue(), this.getSuggestionsProvider()
);
}
}
@ -154,8 +160,10 @@ public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
}
@Override
public @NonNull ArgumentParseResult<Boolean> parse(final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> inputQueue) {
public @NonNull ArgumentParseResult<Boolean> parse(
final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> inputQueue
) {
final String input = inputQueue.peek();
if (input == null) {
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
@ -188,8 +196,10 @@ public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
}
@Override
public @NonNull List<@NonNull String> suggestions(final @NonNull CommandContext<C> commandContext,
final @NonNull String input) {
public @NonNull List<@NonNull String> suggestions(
final @NonNull CommandContext<C> commandContext,
final @NonNull String input
) {
if (!liberal) {
return Arrays.asList("TRUE", "FALSE");
}
@ -201,6 +211,7 @@ public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
public boolean isContextFree() {
return true;
}
}
@ -218,8 +229,10 @@ public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
* @param input String input
* @param liberal Liberal value
*/
public BooleanParseException(final @NonNull String input,
final boolean liberal) {
public BooleanParseException(
final @NonNull String input,
final boolean liberal
) {
this.input = input;
this.liberal = liberal;
}
@ -246,5 +259,7 @@ public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
public String getMessage() {
return String.format("Could not parse boolean from '%s'.", input);
}
}
}

View file

@ -41,13 +41,15 @@ public final class ByteArgument<C> extends CommandArgument<C, Byte> {
private final byte min;
private final byte max;
private ByteArgument(final boolean required,
final @NonNull String name,
final byte min,
final byte max,
final @NonNull String defaultValue,
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
@NonNull List<@NonNull String>> suggestionsProvider) {
private ByteArgument(
final boolean required,
final @NonNull String name,
final byte min,
final byte max,
final @NonNull String defaultValue,
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
@NonNull List<@NonNull String>> suggestionsProvider
) {
super(required, name, new ByteParser<>(min, max), defaultValue, Byte.class, suggestionsProvider);
this.min = min;
this.max = max;
@ -94,8 +96,10 @@ public final class ByteArgument<C> extends CommandArgument<C, Byte> {
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull CommandArgument<C, Byte> optional(final @NonNull String name,
final byte defaultNum) {
public static <C> @NonNull CommandArgument<C, Byte> optional(
final @NonNull String name,
final byte defaultNum
) {
return ByteArgument.<C>newBuilder(name).asOptionalWithDefault(Byte.toString(defaultNum)).build();
}
@ -156,7 +160,8 @@ public final class ByteArgument<C> extends CommandArgument<C, Byte> {
@Override
public @NonNull ByteArgument<C> build() {
return new ByteArgument<>(this.isRequired(), this.getName(), this.min, this.max,
this.getDefaultValue(), this.getSuggestionsProvider());
this.getDefaultValue(), this.getSuggestionsProvider()
);
}
}
@ -180,7 +185,8 @@ public final class ByteArgument<C> extends CommandArgument<C, Byte> {
@Override
public @NonNull ArgumentParseResult<Byte> parse(
final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> inputQueue) {
final @NonNull Queue<@NonNull String> inputQueue
) {
final String input = inputQueue.peek();
if (input == null) {
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
@ -189,16 +195,19 @@ public final class ByteArgument<C> extends CommandArgument<C, Byte> {
final byte value = Byte.parseByte(input);
if (value < this.min || value > this.max) {
return ArgumentParseResult.failure(
new ByteParseException(input,
this.min,
this.max));
new ByteParseException(
input,
this.min,
this.max
));
}
inputQueue.remove();
return ArgumentParseResult.success(value);
} catch (final Exception e) {
return ArgumentParseResult.failure(
new ByteParseException(input, this.min,
this.max));
this.max
));
}
}
@ -208,8 +217,10 @@ public final class ByteArgument<C> extends CommandArgument<C, Byte> {
}
@Override
public @NonNull List<@NonNull String> suggestions(final @NonNull CommandContext<C> commandContext,
final @NonNull String input) {
public @NonNull List<@NonNull String> suggestions(
final @NonNull CommandContext<C> commandContext,
final @NonNull String input
) {
return IntegerArgument.IntegerParser.getSuggestions(this.min, this.max, input);
}

View file

@ -37,11 +37,13 @@ import java.util.function.BiFunction;
@SuppressWarnings("unused")
public final class CharArgument<C> extends CommandArgument<C, Character> {
private CharArgument(final boolean required,
final @NonNull String name,
final @NonNull String defaultValue,
final @Nullable BiFunction<@NonNull CommandContext<C>,
@NonNull String, @NonNull List<@NonNull String>> suggestionsProvider) {
private CharArgument(
final boolean required,
final @NonNull String name,
final @NonNull String defaultValue,
final @Nullable BiFunction<@NonNull CommandContext<C>,
@NonNull String, @NonNull List<@NonNull String>> suggestionsProvider
) {
super(required, name, new CharacterParser<>(), defaultValue, Character.class, suggestionsProvider);
}
@ -86,8 +88,10 @@ public final class CharArgument<C> extends CommandArgument<C, Character> {
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull CommandArgument<C, Character> optional(final @NonNull String name,
final @NonNull String defaultNum) {
public static <C> @NonNull CommandArgument<C, Character> optional(
final @NonNull String name,
final @NonNull String defaultNum
) {
return CharArgument.<C>newBuilder(name).asOptionalWithDefault(defaultNum).build();
}
@ -106,7 +110,8 @@ public final class CharArgument<C> extends CommandArgument<C, Character> {
@Override
public @NonNull CharArgument<C> build() {
return new CharArgument<>(this.isRequired(), this.getName(),
this.getDefaultValue(), this.getSuggestionsProvider());
this.getDefaultValue(), this.getSuggestionsProvider()
);
}
}
@ -115,8 +120,10 @@ public final class CharArgument<C> extends CommandArgument<C, Character> {
public static final class CharacterParser<C> implements ArgumentParser<C, Character> {
@Override
public @NonNull ArgumentParseResult<Character> parse(final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> inputQueue) {
public @NonNull ArgumentParseResult<Character> parse(
final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> inputQueue
) {
final String input = inputQueue.peek();
if (input == null) {
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
@ -166,5 +173,7 @@ public final class CharArgument<C> extends CommandArgument<C, Character> {
public String getMessage() {
return String.format("'%s' is not a valid character.", input);
}
}
}

View file

@ -41,13 +41,15 @@ public final class DoubleArgument<C> extends CommandArgument<C, Double> {
private final double min;
private final double max;
private DoubleArgument(final boolean required,
final @NonNull String name,
final double min,
final double max,
final String defaultValue,
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
@NonNull List<@NonNull String>> suggestionsProvider) {
private DoubleArgument(
final boolean required,
final @NonNull String name,
final double min,
final double max,
final String defaultValue,
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
@NonNull List<@NonNull String>> suggestionsProvider
) {
super(required, name, new DoubleParser<>(min, max), defaultValue, Double.class, suggestionsProvider);
this.min = min;
this.max = max;
@ -94,8 +96,10 @@ public final class DoubleArgument<C> extends CommandArgument<C, Double> {
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull CommandArgument<C, Double> optional(final @NonNull String name,
final double defaultNum) {
public static <C> @NonNull CommandArgument<C, Double> optional(
final @NonNull String name,
final double defaultNum
) {
return DoubleArgument.<C>newBuilder(name).asOptionalWithDefault(Double.toString(defaultNum)).build();
}
@ -156,7 +160,8 @@ public final class DoubleArgument<C> extends CommandArgument<C, Double> {
@Override
public @NonNull DoubleArgument<C> build() {
return new DoubleArgument<>(this.isRequired(), this.getName(), this.min, this.max,
this.getDefaultValue(), this.getSuggestionsProvider());
this.getDefaultValue(), this.getSuggestionsProvider()
);
}
}
@ -180,7 +185,8 @@ public final class DoubleArgument<C> extends CommandArgument<C, Double> {
@Override
public @NonNull ArgumentParseResult<Double> parse(
final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> inputQueue) {
final @NonNull Queue<@NonNull String> inputQueue
) {
final String input = inputQueue.peek();
if (input == null) {
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));

View file

@ -45,12 +45,14 @@ import java.util.stream.Collectors;
@SuppressWarnings("unused")
public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
protected EnumArgument(final @NonNull Class<E> enumClass,
final boolean required,
final @NonNull String name,
final @NonNull String defaultValue,
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
@NonNull List<@NonNull String>> suggestionsProvider) {
protected EnumArgument(
final @NonNull Class<E> enumClass,
final boolean required,
final @NonNull String name,
final @NonNull String defaultValue,
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
@NonNull List<@NonNull String>> suggestionsProvider
) {
super(required, name, new EnumParser<>(enumClass), defaultValue, enumClass, suggestionsProvider);
}
@ -64,8 +66,9 @@ public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
* @return Created builder
*/
public static <C, E extends Enum<E>> EnumArgument.@NonNull Builder<C, E> newBuilder(
@NonNull final Class<E> enumClass,
final @NonNull String name) {
@NonNull final Class<E> enumClass,
final @NonNull String name
) {
return new EnumArgument.Builder<>(name, enumClass);
}
@ -80,7 +83,8 @@ public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
*/
public static <C, E extends Enum<E>> @NonNull CommandArgument<C, E> of(
final @NonNull Class<E> enumClass,
final @NonNull String name) {
final @NonNull String name
) {
return EnumArgument.<C, E>newBuilder(enumClass, name).asRequired().build();
}
@ -95,7 +99,8 @@ public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
*/
public static <C, E extends Enum<E>> @NonNull CommandArgument<C, E> optional(
final @NonNull Class<E> enumClass,
final @NonNull String name) {
final @NonNull String name
) {
return EnumArgument.<C, E>newBuilder(enumClass, name).asOptional().build();
}
@ -112,7 +117,8 @@ public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
public static <C, E extends Enum<E>> @NonNull CommandArgument<C, E> optional(
final @NonNull Class<E> enumClass,
final @NonNull String name,
final @NonNull E defaultValue) {
final @NonNull E defaultValue
) {
return EnumArgument.<C, E>newBuilder(enumClass, name).asOptionalWithDefault(defaultValue.name().toLowerCase()).build();
}
@ -129,8 +135,10 @@ public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
@Override
public @NonNull CommandArgument<C, E> build() {
return new EnumArgument<>(this.enumClass, this.isRequired(), this.getName(),
this.getDefaultValue(), this.getSuggestionsProvider());
this.getDefaultValue(), this.getSuggestionsProvider()
);
}
}
@ -150,8 +158,10 @@ public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
}
@Override
public @NonNull ArgumentParseResult<E> parse(final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> inputQueue) {
public @NonNull ArgumentParseResult<E> parse(
final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> inputQueue
) {
final String input = inputQueue.peek();
if (input == null) {
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
@ -168,8 +178,10 @@ public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
}
@Override
public @NonNull List<@NonNull String> suggestions(final @NonNull CommandContext<C> commandContext,
final @NonNull String input) {
public @NonNull List<@NonNull String> suggestions(
final @NonNull CommandContext<C> commandContext,
final @NonNull String input
) {
return EnumSet.allOf(this.enumClass).stream().map(e -> e.name().toLowerCase()).collect(Collectors.toList());
}
@ -177,6 +189,7 @@ public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
public boolean isContextFree() {
return true;
}
}
@ -191,8 +204,10 @@ public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
* @param input Input
* @param enumClass Enum class
*/
public EnumParseException(final @NonNull String input,
final @NonNull Class<? extends Enum<?>> enumClass) {
public EnumParseException(
final @NonNull String input,
final @NonNull Class<? extends Enum<?>> enumClass
) {
this.input = input;
this.enumClass = enumClass;
}
@ -201,8 +216,8 @@ public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
private static @NonNull String join(final @NonNull Class<? extends Enum> clazz) {
final EnumSet<?> enumSet = EnumSet.allOf(clazz);
return enumSet.stream()
.map(e -> e.toString().toLowerCase())
.collect(Collectors.joining(", "));
.map(e -> e.toString().toLowerCase())
.collect(Collectors.joining(", "));
}
/**

View file

@ -41,13 +41,15 @@ public final class FloatArgument<C> extends CommandArgument<C, Float> {
private final float min;
private final float max;
private FloatArgument(final boolean required,
final @NonNull String name,
final float min,
final float max,
final @NonNull String defaultValue,
final @Nullable BiFunction<@NonNull CommandContext<C>,
@NonNull String, @NonNull List<@NonNull String>> suggestionsProvider) {
private FloatArgument(
final boolean required,
final @NonNull String name,
final float min,
final float max,
final @NonNull String defaultValue,
final @Nullable BiFunction<@NonNull CommandContext<C>,
@NonNull String, @NonNull List<@NonNull String>> suggestionsProvider
) {
super(required, name, new FloatParser<>(min, max), defaultValue, Float.class, suggestionsProvider);
this.min = min;
this.max = max;
@ -94,8 +96,10 @@ public final class FloatArgument<C> extends CommandArgument<C, Float> {
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull CommandArgument<C, Float> optional(final @NonNull String name,
final float defaultNum) {
public static <C> @NonNull CommandArgument<C, Float> optional(
final @NonNull String name,
final float defaultNum
) {
return FloatArgument.<C>newBuilder(name).asOptionalWithDefault(Float.toString(defaultNum)).build();
}
@ -156,7 +160,8 @@ public final class FloatArgument<C> extends CommandArgument<C, Float> {
@Override
public @NonNull FloatArgument<C> build() {
return new FloatArgument<>(this.isRequired(), this.getName(), this.min, this.max,
this.getDefaultValue(), this.getSuggestionsProvider());
this.getDefaultValue(), this.getSuggestionsProvider()
);
}
}
@ -180,7 +185,8 @@ public final class FloatArgument<C> extends CommandArgument<C, Float> {
@Override
public @NonNull ArgumentParseResult<Float> parse(
final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<String> inputQueue) {
final @NonNull Queue<String> inputQueue
) {
final String input = inputQueue.peek();
if (input == null) {
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));

View file

@ -48,13 +48,15 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
private final int min;
private final int max;
private IntegerArgument(final boolean required,
final @NonNull String name,
final int min,
final int max,
final String defaultValue,
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
@NonNull List<@NonNull String>> suggestionsProvider) {
private IntegerArgument(
final boolean required,
final @NonNull String name,
final int min,
final int max,
final String defaultValue,
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
@NonNull List<@NonNull String>> suggestionsProvider
) {
super(required, name, new IntegerParser<>(min, max), defaultValue, Integer.class, suggestionsProvider);
this.min = min;
this.max = max;
@ -101,8 +103,10 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull CommandArgument<C, Integer> optional(final @NonNull String name,
final int defaultNum) {
public static <C> @NonNull CommandArgument<C, Integer> optional(
final @NonNull String name,
final int defaultNum
) {
return IntegerArgument.<C>newBuilder(name).asOptionalWithDefault(Integer.toString(defaultNum)).build();
}
@ -163,7 +167,8 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
@Override
public @NonNull IntegerArgument<C> build() {
return new IntegerArgument<>(this.isRequired(), this.getName(), this.min, this.max,
this.getDefaultValue(), this.getSuggestionsProvider());
this.getDefaultValue(), this.getSuggestionsProvider()
);
}
}
@ -209,7 +214,8 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
@Override
public @NonNull ArgumentParseResult<Integer> parse(
final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> inputQueue) {
final @NonNull Queue<@NonNull String> inputQueue
) {
final String input = inputQueue.peek();
if (input == null) {
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
@ -250,8 +256,10 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
}
@Override
public @NonNull List<@NonNull String> suggestions(final @NonNull CommandContext<C> commandContext,
final @NonNull String input) {
public @NonNull List<@NonNull String> suggestions(
final @NonNull CommandContext<C> commandContext,
final @NonNull String input
) {
return getSuggestions(this.min, this.max, input);
}

View file

@ -41,13 +41,15 @@ public final class LongArgument<C> extends CommandArgument<C, Long> {
private final long min;
private final long max;
private LongArgument(final boolean required,
final @NonNull String name,
final long min,
final long max,
final String defaultValue,
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
@NonNull List<@NonNull String>> suggestionsProvider) {
private LongArgument(
final boolean required,
final @NonNull String name,
final long min,
final long max,
final String defaultValue,
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
@NonNull List<@NonNull String>> suggestionsProvider
) {
super(required, name, new LongParser<>(min, max), defaultValue, Long.class, suggestionsProvider);
this.min = min;
this.max = max;
@ -94,8 +96,10 @@ public final class LongArgument<C> extends CommandArgument<C, Long> {
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull CommandArgument<C, Long> optional(final @NonNull String name,
final long defaultNum) {
public static <C> @NonNull CommandArgument<C, Long> optional(
final @NonNull String name,
final long defaultNum
) {
return LongArgument.<C>newBuilder(name).asOptionalWithDefault(Long.toString(defaultNum)).build();
}
@ -156,7 +160,8 @@ public final class LongArgument<C> extends CommandArgument<C, Long> {
@Override
public @NonNull LongArgument<C> build() {
return new LongArgument<>(this.isRequired(), this.getName(), this.min,
this.max, this.getDefaultValue(), this.getSuggestionsProvider());
this.max, this.getDefaultValue(), this.getSuggestionsProvider()
);
}
}
@ -174,7 +179,8 @@ public final class LongArgument<C> extends CommandArgument<C, Long> {
@Override
public @NonNull ArgumentParseResult<Long> parse(
final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> inputQueue) {
final @NonNull Queue<@NonNull String> inputQueue
) {
final String input = inputQueue.peek();
if (input == null) {
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
@ -197,8 +203,10 @@ public final class LongArgument<C> extends CommandArgument<C, Long> {
}
@Override
public @NonNull List<@NonNull String> suggestions(final @NonNull CommandContext<C> commandContext,
final @NonNull String input) {
public @NonNull List<@NonNull String> suggestions(
final @NonNull CommandContext<C> commandContext,
final @NonNull String input
) {
return IntegerArgument.IntegerParser.getSuggestions(this.min, this.max, input);
}

View file

@ -41,13 +41,15 @@ public final class ShortArgument<C> extends CommandArgument<C, Short> {
private final short min;
private final short max;
private ShortArgument(final boolean required,
final @NonNull String name,
final short min,
final short max,
final String defaultValue,
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
@NonNull List<String>> suggestionsProvider) {
private ShortArgument(
final boolean required,
final @NonNull String name,
final short min,
final short max,
final String defaultValue,
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
@NonNull List<String>> suggestionsProvider
) {
super(required, name, new ShortParser<>(min, max), defaultValue, Short.class, suggestionsProvider);
this.min = min;
this.max = max;
@ -94,8 +96,10 @@ public final class ShortArgument<C> extends CommandArgument<C, Short> {
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull CommandArgument<C, Short> optional(final @NonNull String name,
final short defaultNum) {
public static <C> @NonNull CommandArgument<C, Short> optional(
final @NonNull String name,
final short defaultNum
) {
return ShortArgument.<C>newBuilder(name).asOptionalWithDefault(Short.toString(defaultNum)).build();
}
@ -156,7 +160,8 @@ public final class ShortArgument<C> extends CommandArgument<C, Short> {
@Override
public @NonNull ShortArgument<C> build() {
return new ShortArgument<>(this.isRequired(), this.getName(), this.min, this.max,
this.getDefaultValue(), this.getSuggestionsProvider());
this.getDefaultValue(), this.getSuggestionsProvider()
);
}
}
@ -180,7 +185,8 @@ public final class ShortArgument<C> extends CommandArgument<C, Short> {
@Override
public @NonNull ArgumentParseResult<Short> parse(
final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> inputQueue) {
final @NonNull Queue<@NonNull String> inputQueue
) {
final String input = inputQueue.peek();
if (input == null) {
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
@ -203,8 +209,10 @@ public final class ShortArgument<C> extends CommandArgument<C, Short> {
}
@Override
public @NonNull List<@NonNull String> suggestions(final @NonNull CommandContext<C> commandContext,
final @NonNull String input) {
public @NonNull List<@NonNull String> suggestions(
final @NonNull CommandContext<C> commandContext,
final @NonNull String input
) {
return IntegerArgument.IntegerParser.getSuggestions(this.min, this.max, input);
}

View file

@ -40,14 +40,17 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
private final StringMode stringMode;
private StringArgument(final boolean required,
final @NonNull String name,
final @NonNull StringMode stringMode,
final @NonNull String defaultValue,
final @NonNull BiFunction<@NonNull CommandContext<C>, @NonNull String,
@NonNull List<@NonNull String>> suggestionsProvider) {
private StringArgument(
final boolean required,
final @NonNull String name,
final @NonNull StringMode stringMode,
final @NonNull String defaultValue,
final @NonNull BiFunction<@NonNull CommandContext<C>, @NonNull String,
@NonNull List<@NonNull String>> suggestionsProvider
) {
super(required, name, new StringParser<>(stringMode, suggestionsProvider),
defaultValue, String.class, suggestionsProvider);
defaultValue, String.class, suggestionsProvider
);
this.stringMode = stringMode;
}
@ -81,8 +84,10 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull CommandArgument<C, String> of(final @NonNull String name,
final @NonNull StringMode stringMode) {
public static <C> @NonNull CommandArgument<C, String> of(
final @NonNull String name,
final @NonNull StringMode stringMode
) {
return StringArgument.<C>newBuilder(name).withMode(stringMode).asRequired().build();
}
@ -105,8 +110,10 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull CommandArgument<C, String> optional(final @NonNull String name,
final @NonNull StringMode stringMode) {
public static <C> @NonNull CommandArgument<C, String> optional(
final @NonNull String name,
final @NonNull StringMode stringMode
) {
return StringArgument.<C>newBuilder(name).withMode(stringMode).asOptional().build();
}
@ -118,8 +125,10 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull CommandArgument<C, String> optional(final @NonNull String name,
final @NonNull String defaultString) {
public static <C> @NonNull CommandArgument<C, String> optional(
final @NonNull String name,
final @NonNull String defaultString
) {
return StringArgument.<C>newBuilder(name).asOptionalWithDefault(defaultString).build();
}
@ -190,8 +199,10 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
* @param suggestionsProvider Suggestions provider
* @return Builder instance
*/
public @NonNull Builder<C> withSuggestionsProvider(final @NonNull BiFunction<@NonNull CommandContext<C>,
@NonNull String, @NonNull List<@NonNull String>> suggestionsProvider) {
public @NonNull Builder<C> withSuggestionsProvider(
final @NonNull BiFunction<@NonNull CommandContext<C>,
@NonNull String, @NonNull List<@NonNull String>> suggestionsProvider
) {
this.suggestionsProvider = suggestionsProvider;
return this;
}
@ -204,7 +215,8 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
@Override
public @NonNull StringArgument<C> build() {
return new StringArgument<>(this.isRequired(), this.getName(), this.stringMode,
this.getDefaultValue(), this.suggestionsProvider);
this.getDefaultValue(), this.suggestionsProvider
);
}
}
@ -221,16 +233,20 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
* @param stringMode String parsing mode
* @param suggestionsProvider Suggestions provider
*/
public StringParser(final @NonNull StringMode stringMode,
final @NonNull BiFunction<@NonNull CommandContext<C>, @NonNull String,
@NonNull List<@NonNull String>> suggestionsProvider) {
public StringParser(
final @NonNull StringMode stringMode,
final @NonNull BiFunction<@NonNull CommandContext<C>, @NonNull String,
@NonNull List<@NonNull String>> suggestionsProvider
) {
this.stringMode = stringMode;
this.suggestionsProvider = suggestionsProvider;
}
@Override
public @NonNull ArgumentParseResult<String> parse(final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> inputQueue) {
public @NonNull ArgumentParseResult<String> parse(
final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> inputQueue
) {
final String input = inputQueue.peek();
if (input == null) {
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
@ -294,8 +310,10 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
}
@Override
public @NonNull List<@NonNull String> suggestions(final @NonNull CommandContext<C> commandContext,
final @NonNull String input) {
public @NonNull List<@NonNull String> suggestions(
final @NonNull CommandContext<C> commandContext,
final @NonNull String input
) {
return this.suggestionsProvider.apply(commandContext, input);
}
@ -312,6 +330,7 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
public @NonNull StringMode getStringMode() {
return this.stringMode;
}
}

View file

@ -38,11 +38,13 @@ import java.util.function.BiFunction;
@SuppressWarnings("unused")
public final class UUIDArgument<C> extends CommandArgument<C, UUID> {
private UUIDArgument(final boolean required,
final @NonNull String name,
final @NonNull String defaultValue,
final @Nullable BiFunction<@NonNull CommandContext<C>,
@NonNull String, @NonNull List<@NonNull String>> suggestionsProvider) {
private UUIDArgument(
final boolean required,
final @NonNull String name,
final @NonNull String defaultValue,
final @Nullable BiFunction<@NonNull CommandContext<C>,
@NonNull String, @NonNull List<@NonNull String>> suggestionsProvider
) {
super(required, name, new UUIDParser<>(), defaultValue, UUID.class, suggestionsProvider);
}
@ -87,8 +89,10 @@ public final class UUIDArgument<C> extends CommandArgument<C, UUID> {
* @param <C> Command sender type
* @return Created component
*/
public static <C> @NonNull CommandArgument<C, UUID> optional(final @NonNull String name,
final @NonNull UUID defaultUUID) {
public static <C> @NonNull CommandArgument<C, UUID> optional(
final @NonNull String name,
final @NonNull UUID defaultUUID
) {
return UUIDArgument.<C>newBuilder(name).asOptionalWithDefault(defaultUUID.toString()).build();
}
@ -117,7 +121,8 @@ public final class UUIDArgument<C> extends CommandArgument<C, UUID> {
@Override
public @NonNull ArgumentParseResult<UUID> parse(
final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> inputQueue) {
final @NonNull Queue<@NonNull String> inputQueue
) {
final String input = inputQueue.peek();
if (input == null) {
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
@ -136,6 +141,7 @@ public final class UUIDArgument<C> extends CommandArgument<C, UUID> {
public boolean isContextFree() {
return true;
}
}
@ -156,5 +162,7 @@ public final class UUIDArgument<C> extends CommandArgument<C, UUID> {
public String getMessage() {
return String.format("Could not parse UUID from '%s'.", input);
}
}
}

View file

@ -61,8 +61,10 @@ public final class CommandContext<C> {
* @param suggestions Whether or not the context is created for command suggestions
* @param commandSender Sender of the command
*/
public CommandContext(final boolean suggestions,
final @NonNull C commandSender) {
public CommandContext(
final boolean suggestions,
final @NonNull C commandSender
) {
this.commandSender = commandSender;
this.suggestions = suggestions;
}
@ -181,8 +183,10 @@ public final class CommandContext<C> {
* @param <T> Argument type
* @return Stored value, or supplied default value
*/
public <T> @Nullable T getOrDefault(final @NonNull CommandArgument<C, T> argument,
final @Nullable T defaultValue) {
public <T> @Nullable T getOrDefault(
final @NonNull CommandArgument<C, T> argument,
final @Nullable T defaultValue
) {
return this.<T>getOptional(argument.getName()).orElse(defaultValue);
}
@ -194,8 +198,10 @@ public final class CommandContext<C> {
* @param <T> Argument type
* @return Argument, or supplied default value
*/
public <T> @Nullable T getOrDefault(final @NonNull String key,
final @Nullable T defaultValue) {
public <T> @Nullable T getOrDefault(
final @NonNull String key,
final @Nullable T defaultValue
) {
return this.<T>getOptional(key).orElse(defaultValue);
}

View file

@ -36,7 +36,7 @@ public interface CommandContextFactory<C> {
* Create a new command context
*
* @param suggestions Whether or not the sender is requesting suggestions
* @param sender Command sender
* @param sender Command sender
* @return Command context
*/
@NonNull CommandContext<C> create(boolean suggestions, @NonNull C sender);

View file

@ -51,9 +51,11 @@ public final class AmbiguousNodeException extends IllegalStateException {
* @param ambiguousNode Node that caused exception
* @param children All children of the parent
*/
public AmbiguousNodeException(final @Nullable CommandArgument<?, ?> parentNode,
final @NonNull CommandArgument<?, ?> ambiguousNode,
final @NonNull List<@NonNull CommandArgument<?, ?>> children) {
public AmbiguousNodeException(
final @Nullable CommandArgument<?, ?> parentNode,
final @NonNull CommandArgument<?, ?> ambiguousNode,
final @NonNull List<@NonNull CommandArgument<?, ?>> children
) {
this.parentNode = parentNode;
this.ambiguousNode = ambiguousNode;
this.children = children;
@ -101,7 +103,7 @@ public final class AmbiguousNodeException extends IllegalStateException {
}
}
return stringBuilder.append(")")
.toString();
.toString();
}
}

View file

@ -39,9 +39,11 @@ public class ArgumentParseException extends CommandParseException {
* @param commandSender Command sender
* @param currentChain Chain leading up to the exception
*/
public ArgumentParseException(final @NonNull Throwable throwable,
final @NonNull Object commandSender,
final @NonNull List<@NonNull CommandArgument<?, ?>> currentChain) {
public ArgumentParseException(
final @NonNull Throwable throwable,
final @NonNull Object commandSender,
final @NonNull List<@NonNull CommandArgument<?, ?>> currentChain
) {
super(commandSender, currentChain);
this.cause = throwable;
}

View file

@ -44,8 +44,10 @@ public class CommandParseException extends IllegalArgumentException {
* @param commandSender Sender who executed the command
* @param currentChain Chain leading up to the exception
*/
protected CommandParseException(final @NonNull Object commandSender,
final @NonNull List<CommandArgument<?, ?>> currentChain) {
protected CommandParseException(
final @NonNull Object commandSender,
final @NonNull List<CommandArgument<?, ?>> currentChain
) {
this.commandSender = commandSender;
this.currentChain = currentChain;
}

View file

@ -42,9 +42,11 @@ public final class InvalidCommandSenderException extends CommandParseException {
* @param requiredSender The sender type that is required
* @param currentChain Chain leading up to the exception
*/
public InvalidCommandSenderException(final @NonNull Object commandSender,
final @NonNull Class<?> requiredSender,
final @NonNull List<@NonNull CommandArgument<?, ?>> currentChain) {
public InvalidCommandSenderException(
final @NonNull Object commandSender,
final @NonNull Class<?> requiredSender,
final @NonNull List<@NonNull CommandArgument<?, ?>> currentChain
) {
super(commandSender, currentChain);
this.requiredSender = requiredSender;
}
@ -60,8 +62,11 @@ public final class InvalidCommandSenderException extends CommandParseException {
@Override
public String getMessage() {
return String.format("%s is not allowed to execute that command. Must be of type %s",
getCommandSender().getClass().getSimpleName(),
requiredSender.getSimpleName());
return String.format(
"%s is not allowed to execute that command. Must be of type %s",
getCommandSender().getClass().getSimpleName(),
requiredSender.getSimpleName()
);
}
}

View file

@ -43,9 +43,11 @@ public class InvalidSyntaxException extends CommandParseException {
* @param commandSender Sender that sent the command
* @param currentChain Chain leading up to issue
*/
public InvalidSyntaxException(final @NonNull String correctSyntax,
final @NonNull Object commandSender,
final @NonNull List<@NonNull CommandArgument<?, ?>> currentChain) {
public InvalidSyntaxException(
final @NonNull String correctSyntax,
final @NonNull Object commandSender,
final @NonNull List<@NonNull CommandArgument<?, ?>> currentChain
) {
super(commandSender, currentChain);
this.correctSyntax = correctSyntax;
}

View file

@ -46,9 +46,11 @@ public class NoPermissionException extends CommandParseException {
* @param commandSender Command sender
* @param currentChain Chain leading up to the exception
*/
public NoPermissionException(final @NonNull CommandPermission missingPermission,
final @NonNull Object commandSender,
final @NonNull List<@NonNull CommandArgument<?, ?>> currentChain) {
public NoPermissionException(
final @NonNull CommandPermission missingPermission,
final @NonNull Object commandSender,
final @NonNull List<@NonNull CommandArgument<?, ?>> currentChain
) {
super(commandSender, currentChain);
this.missingPermission = missingPermission;
}

View file

@ -44,9 +44,11 @@ public final class NoSuchCommandException extends CommandParseException {
* @param currentChain Chain leading up to the exception
* @param command Entered command (following the command chain)
*/
public NoSuchCommandException(final @NonNull Object commandSender,
final @NonNull List<CommandArgument<?, ?>> currentChain,
final @NonNull String command) {
public NoSuchCommandException(
final @NonNull Object commandSender,
final @NonNull List<CommandArgument<?, ?>> currentChain,
final @NonNull String command
) {
super(commandSender, currentChain);
this.suppliedCommand = command;
}

View file

@ -38,9 +38,11 @@ public abstract class NumberParseException extends IllegalArgumentException {
* @param min Maximum value
* @param max Minimum value
*/
public NumberParseException(final @NonNull String input,
final @NonNull Number min,
final @NonNull Number max) {
public NumberParseException(
final @NonNull String input,
final @NonNull Number min,
final @NonNull Number max
) {
this.input = input;
this.min = min;
this.max = max;

View file

@ -50,9 +50,11 @@ public final class AsynchronousCommandExecutionCoordinator<C> extends CommandExe
private final Executor executor;
private final boolean synchronizeParsing;
private AsynchronousCommandExecutionCoordinator(final @Nullable Executor executor,
final boolean synchronizeParsing,
final @NonNull CommandTree<C> commandTree) {
private AsynchronousCommandExecutionCoordinator(
final @Nullable Executor executor,
final boolean synchronizeParsing,
final @NonNull CommandTree<C> commandTree
) {
super(commandTree);
this.executor = executor == null ? ForkJoinPool.commonPool() : executor;
this.synchronizeParsing = synchronizeParsing;
@ -70,8 +72,10 @@ public final class AsynchronousCommandExecutionCoordinator<C> extends CommandExe
}
@Override
public @NonNull CompletableFuture<CommandResult<C>> coordinateExecution(final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> input) {
public @NonNull CompletableFuture<CommandResult<C>> coordinateExecution(
final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> input
) {
final Consumer<Command<C>> commandConsumer = command -> {
if (this.commandManager.postprocessContext(commandContext, command) == State.ACCEPTED) {

View file

@ -74,8 +74,10 @@ public abstract class CommandExecutionCoordinator<C> {
* @param input Command input
* @return Future that completes with the result
*/
public abstract @NonNull CompletableFuture<CommandResult<C>> coordinateExecution(@NonNull CommandContext<C> commandContext,
@NonNull Queue<@NonNull String> input);
public abstract @NonNull CompletableFuture<CommandResult<C>> coordinateExecution(
@NonNull CommandContext<C> commandContext,
@NonNull Queue<@NonNull String> input
);
/**
* Get the command tree
@ -100,8 +102,10 @@ public abstract class CommandExecutionCoordinator<C> {
}
@Override
public CompletableFuture<CommandResult<C>> coordinateExecution(final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> input) {
public CompletableFuture<CommandResult<C>> coordinateExecution(
final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> input
) {
final CompletableFuture<CommandResult<C>> completableFuture = new CompletableFuture<>();
try {
final @NonNull Pair<@Nullable Command<C>, @Nullable Exception> pair =

View file

@ -37,8 +37,10 @@ import java.util.List;
public final class FilteringCommandSuggestionProcessor<C> implements CommandSuggestionProcessor<C> {
@Override
public @NonNull List<@NonNull String> apply(final @NonNull CommandPreprocessingContext<C> context,
final @NonNull List<@NonNull String> strings) {
public @NonNull List<@NonNull String> apply(
final @NonNull CommandPreprocessingContext<C> context,
final @NonNull List<@NonNull String> strings
) {
final String input;
if (context.getInputQueue().isEmpty()) {
input = "";

View file

@ -45,8 +45,10 @@ public final class CommandPostprocessingContext<C> {
* @param commandContext Command context
* @param command Command instance
*/
public CommandPostprocessingContext(final @NonNull CommandContext<@NonNull C> commandContext,
final @NonNull Command<@NonNull C> command) {
public CommandPostprocessingContext(
final @NonNull CommandContext<@NonNull C> commandContext,
final @NonNull Command<@NonNull C> command
) {
this.commandContext = commandContext;
this.command = command;
}

View file

@ -31,4 +31,5 @@ import cloud.commandframework.services.types.ConsumerService;
* @param <C> Command sender type
*/
public interface CommandPostprocessor<C> extends ConsumerService<CommandPostprocessingContext<C>> {
}

View file

@ -45,8 +45,10 @@ public final class CommandPreprocessingContext<C> {
* @param commandContext Command context
* @param inputQueue Command input as supplied by sender
*/
public CommandPreprocessingContext(final @NonNull CommandContext<C> commandContext,
final @NonNull LinkedList<@NonNull String> inputQueue) {
public CommandPreprocessingContext(
final @NonNull CommandContext<C> commandContext,
final @NonNull LinkedList<@NonNull String> inputQueue
) {
this.commandContext = commandContext;
this.inputQueue = inputQueue;
}

View file

@ -35,4 +35,5 @@ import cloud.commandframework.services.types.ConsumerService;
* @param <C> Command sender type
*/
public interface CommandPreprocessor<C> extends ConsumerService<CommandPreprocessingContext<C>> {
}

View file

@ -72,10 +72,12 @@ public class CommandConfirmationManager<C> {
* @param notifier Notifier that gets called when a command gets added to the queue
* @param errorNotifier Notifier that gets called when someone tries to confirm a command with nothing in the queue
*/
public CommandConfirmationManager(final long timeout,
final @NonNull TimeUnit timeoutTimeUnit,
final @NonNull Consumer<@NonNull CommandPostprocessingContext<C>> notifier,
final @NonNull Consumer<@NonNull C> errorNotifier) {
public CommandConfirmationManager(
final long timeout,
final @NonNull TimeUnit timeoutTimeUnit,
final @NonNull Consumer<@NonNull CommandPostprocessingContext<C>> notifier,
final @NonNull Consumer<@NonNull C> errorNotifier
) {
this.notifier = notifier;
this.errorNotifier = errorNotifier;
this.pendingCommands = new LinkedHashMap<C, Pair<CommandPostprocessingContext<C>, Long>>() {
@ -141,8 +143,8 @@ public class CommandConfirmationManager<C> {
if (pending.isPresent()) {
final CommandPostprocessingContext<C> postprocessingContext = pending.get();
postprocessingContext.getCommand()
.getCommandExecutionHandler()
.execute(postprocessingContext.getCommandContext());
.getCommandExecutionHandler()
.execute(postprocessingContext.getCommandContext());
} else {
this.errorNotifier.accept(context.getSender());
}
@ -155,9 +157,9 @@ public class CommandConfirmationManager<C> {
@Override
public void accept(final @NonNull CommandPostprocessingContext<C> context) {
if (!context.getCommand()
.getCommandMeta()
.getOrDefault(CONFIRMATION_REQUIRED_META, "false")
.equals("true")) {
.getCommandMeta()
.getOrDefault(CONFIRMATION_REQUIRED_META, "false")
.equals("true")) {
return;
}
/* Add it to the "queue" */

View file

@ -48,7 +48,7 @@ public interface CommandRegistrationHandler {
*
* @param command Command to register
* @return {@code true} if the command was registered successfully,
* else {@code false}
* else {@code false}
*/
boolean registerCommand(@NonNull Command<?> command);

View file

@ -121,8 +121,10 @@ public class SimpleCommandMeta extends CommandMeta {
* @param value Value
* @return Builder instance
*/
public @NonNull Builder with(final @NonNull String key,
final @NonNull String value) {
public @NonNull Builder with(
final @NonNull String key,
final @NonNull String value
) {
this.map.put(key, value);
return this;
}

View file

@ -38,8 +38,10 @@ public class Pair<U, V> implements Tuple {
private final U first;
private final V second;
protected Pair(final U first,
final V second) {
protected Pair(
final U first,
final V second
) {
this.first = first;
this.second = second;
}
@ -53,8 +55,10 @@ public class Pair<U, V> implements Tuple {
* @param <V> Second type
* @return Created pair
*/
public static <U, V> @NonNull Pair<U, V> of(final U first,
final V second) {
public static <U, V> @NonNull Pair<U, V> of(
final U first,
final V second
) {
return new Pair<>(first, second);
}

View file

@ -42,10 +42,12 @@ public class Quartet<U, V, W, X> implements Tuple {
private final W third;
private final X fourth;
protected Quartet(final @NonNull U first,
final @NonNull V second,
final @NonNull W third,
final @NonNull X fourth) {
protected Quartet(
final @NonNull U first,
final @NonNull V second,
final @NonNull W third,
final @NonNull X fourth
) {
this.first = first;
this.second = second;
this.third = third;
@ -65,10 +67,12 @@ public class Quartet<U, V, W, X> implements Tuple {
* @param <X> Fourth type
* @return Created quartet
*/
public static <U, V, W, X> @NonNull Quartet<@NonNull U, @NonNull V, @NonNull W, @NonNull X> of(final @NonNull U first,
final @NonNull V second,
final @NonNull W third,
final @NonNull X fourth) {
public static <U, V, W, X> @NonNull Quartet<@NonNull U, @NonNull V, @NonNull W, @NonNull X> of(
final @NonNull U first,
final @NonNull V second,
final @NonNull W third,
final @NonNull X fourth
) {
return new Quartet<>(first, second, third, fourth);
}

View file

@ -44,11 +44,13 @@ public class Quintet<U, V, W, X, Y> implements Tuple {
private final X fourth;
private final Y fifth;
protected Quintet(final @NonNull U first,
final @NonNull V second,
final @NonNull W third,
final @NonNull X fourth,
final @NonNull Y fifth) {
protected Quintet(
final @NonNull U first,
final @NonNull V second,
final @NonNull W third,
final @NonNull X fourth,
final @NonNull Y fifth
) {
this.first = first;
this.second = second;
this.third = third;
@ -76,7 +78,8 @@ public class Quintet<U, V, W, X, Y> implements Tuple {
final @NonNull V second,
final @NonNull W third,
final @NonNull X fourth,
final @NonNull Y fifth) {
final @NonNull Y fifth
) {
return new Quintet<>(first, second, third, fourth, fifth);
}

View file

@ -46,12 +46,14 @@ public class Sextet<U, V, W, X, Y, Z> implements Tuple {
private final Y fifth;
private final Z sixth;
protected Sextet(final @NonNull U first,
final @NonNull V second,
final @NonNull W third,
final @NonNull X fourth,
final @NonNull Y fifth,
final @NonNull Z sixth) {
protected Sextet(
final @NonNull U first,
final @NonNull V second,
final @NonNull W third,
final @NonNull X fourth,
final @NonNull Y fifth,
final @NonNull Z sixth
) {
this.first = first;
this.second = second;
this.third = third;
@ -78,12 +80,13 @@ public class Sextet<U, V, W, X, Y, Z> implements Tuple {
* @return Created sextet
*/
public static <U, V, W, X, Y, Z> @NonNull Sextet<@NonNull U, @NonNull V, @NonNull W, @NonNull X, @NonNull Y, @NonNull Z> of(
final @NonNull U first,
final @NonNull V second,
final @NonNull W third,
final @NonNull X fourth,
final @NonNull Y fifth,
final @NonNull Z sixth) {
final @NonNull U first,
final @NonNull V second,
final @NonNull W third,
final @NonNull X fourth,
final @NonNull Y fifth,
final @NonNull Z sixth
) {
return new Sextet<>(first, second, third, fourth, fifth, sixth);
}
@ -166,7 +169,8 @@ public class Sextet<U, V, W, X, Y, Z> implements Tuple {
@Override
public final String toString() {
return String.format("(%s, %s, %s, %s, %s, %s)", this.first, this.second, this.third,
this.fourth, this.fifth, this.sixth);
this.fourth, this.fifth, this.sixth
);
}
@Override

View file

@ -40,9 +40,11 @@ public class Triplet<U, V, W> implements Tuple {
private final V second;
private final W third;
protected Triplet(final @NonNull U first,
final @NonNull V second,
final @NonNull W third) {
protected Triplet(
final @NonNull U first,
final @NonNull V second,
final @NonNull W third
) {
this.first = first;
this.second = second;
this.third = third;
@ -59,9 +61,11 @@ public class Triplet<U, V, W> implements Tuple {
* @param <W> Third type
* @return Created triplet
*/
public static <U, V, W> @NonNull Triplet<@NonNull U, @NonNull V, @NonNull W> of(final @NonNull U first,
final @NonNull V second,
final @NonNull W third) {
public static <U, V, W> @NonNull Triplet<@NonNull U, @NonNull V, @NonNull W> of(
final @NonNull U first,
final @NonNull V second,
final @NonNull W third
) {
return new Triplet<>(first, second, third);
}

View file

@ -50,10 +50,11 @@ class CommandHelpHandlerTest {
argument(IntegerArgument.of("int"), Description.of("A number")).build());
manager.command(manager.commandBuilder("vec")
.meta("description", "Takes in a vector")
.argumentPair("vec", Pair.of("x", "y"),
Pair.of(Double.class, Double.class), Description.of("Vector"))
.build());
.meta("description", "Takes in a vector")
.argumentPair("vec", Pair.of("x", "y"),
Pair.of(Double.class, Double.class), Description.of("Vector")
)
.build());
}
@Test
@ -88,8 +89,10 @@ class CommandHelpHandlerTest {
this.printTopic("vec", query4);
}
private void printTopic(final String query,
final CommandHelpHandler.HelpTopic<TestCommandSender> helpTopic) {
private void printTopic(
final String query,
final CommandHelpHandler.HelpTopic<TestCommandSender> helpTopic
) {
System.out.printf("Showing results for query: \"/%s\"\n", query);
if (helpTopic instanceof CommandHelpHandler.IndexHelpTopic) {
this.printIndexHelpTopic((CommandHelpHandler.IndexHelpTopic<TestCommandSender>) helpTopic);
@ -135,7 +138,7 @@ class CommandHelpHandlerTest {
private void printVerboseHelpTopic(final CommandHelpHandler.VerboseHelpTopic<TestCommandSender> helpTopic) {
System.out.printf("└── Command: /%s\n", manager.getCommandSyntaxFormatter()
.apply(helpTopic.getCommand().getArguments(), null));
.apply(helpTopic.getCommand().getArguments(), null));
System.out.printf(" ├── Description: %s\n", helpTopic.getDescription());
System.out.println(" └── Args: ");
final Iterator<CommandArgument<TestCommandSender, ?>> iterator = helpTopic.getCommand().getArguments().iterator();

View file

@ -23,8 +23,8 @@
//
package cloud.commandframework;
import cloud.commandframework.execution.CommandResult;
import cloud.commandframework.context.CommandContext;
import cloud.commandframework.execution.CommandResult;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@ -73,7 +73,8 @@ final class CommandPerformanceTest {
double averageTime = elapsedTime / (double) amount;
System.out.printf("Average literal parse time: %fns (%f ms) | %d samples & %d iterations\n",
averageTime, averageTime / 10e6, 101, 100000);
averageTime, averageTime / 10e6, 101, 100000
);
}
@Test
@ -84,7 +85,7 @@ final class CommandPerformanceTest {
final Options options = new OptionsBuilder()
.include(ExecutionBenchmark.class.getSimpleName())
.build();
final Collection<RunResult> results = new Runner(options).run();
final Collection<RunResult> results = new Runner(options).run();
Assertions.assertFalse(results.isEmpty());
}

View file

@ -57,8 +57,10 @@ class CommandPermissionTest {
}
@Override
public boolean hasPermission(final TestCommandSender sender,
final String permission) {
public boolean hasPermission(
final TestCommandSender sender,
final String permission
) {
return acceptOne && permission.equalsIgnoreCase("test.permission.four");
}
@ -66,6 +68,7 @@ class CommandPermissionTest {
public CommandMeta createDefaultCommandMeta() {
return SimpleCommandMeta.empty();
}
}
}

View file

@ -33,21 +33,21 @@ import org.junit.jupiter.api.Test;
public class CommandPostProcessorTest {
private static final boolean[] state = new boolean[]{false};
private static CommandManager<TestCommandSender> manager;
private static final boolean[] state = new boolean[] {false};
@BeforeAll
static void newTree() {
manager = new TestCommandManager();
manager.command(manager.commandBuilder("test", SimpleCommandMeta.empty())
.handler(c -> state[0] = true)
.build());
.handler(c -> state[0] = true)
.build());
manager.registerCommandPostProcessor(new SamplePostprocessor());
}
@Test
void testPreprocessing() {
manager.executeCommand(new TestCommandSender(),"test").join();
manager.executeCommand(new TestCommandSender(), "test").join();
Assertions.assertEquals(false, state[0]);
}

View file

@ -40,24 +40,26 @@ public class CommandPreProcessorTest {
static void newTree() {
manager = new TestCommandManager();
manager.command(manager.commandBuilder("test", SimpleCommandMeta.empty())
.argument(EnumArgument.of(SampleEnum.class, "enum"))
.handler(
commandContext -> System.out.printf("enum = %s | integer = %d\n",
commandContext.<SampleEnum>getOptional(
"enum").orElse(
SampleEnum.VALUE1),
commandContext.<Integer>getOptional(
"int").orElseThrow(
() -> new NullPointerException(
"int"))))
.build());
.argument(EnumArgument.of(SampleEnum.class, "enum"))
.handler(
commandContext -> System.out.printf(
"enum = %s | integer = %d\n",
commandContext.<SampleEnum>getOptional(
"enum").orElse(
SampleEnum.VALUE1),
commandContext.<Integer>getOptional(
"int").orElseThrow(
() -> new NullPointerException(
"int"))
))
.build());
manager.registerCommandPreProcessor(new SamplePreprocessor());
}
@Test
void testPreprocessing() {
Assertions.assertEquals(10, manager.executeCommand(new TestCommandSender(), "10 test value1")
.join().getCommandContext().<Integer>getOptional("int").orElse(0));
.join().getCommandContext().<Integer>getOptional("int").orElse(0));
manager.executeCommand(new TestCommandSender(), "aa test value1").join();
}

View file

@ -45,38 +45,40 @@ public class CommandSuggestionsTest {
manager.command(manager.commandBuilder("test").literal("one").build());
manager.command(manager.commandBuilder("test").literal("two").build());
manager.command(manager.commandBuilder("test")
.literal("var")
.argument(StringArgument.<TestCommandSender>newBuilder("str")
.withSuggestionsProvider((c, s) -> Arrays.asList("one", "two")))
.argument(EnumArgument.of(TestEnum.class, "enum")));
.literal("var")
.argument(StringArgument.<TestCommandSender>newBuilder("str")
.withSuggestionsProvider((c, s) -> Arrays.asList("one", "two")))
.argument(EnumArgument.of(TestEnum.class, "enum")));
manager.command(manager.commandBuilder("test")
.literal("comb")
.argument(StringArgument.<TestCommandSender>newBuilder("str")
.withSuggestionsProvider((c, s) -> Arrays.asList("one", "two")))
.argument(IntegerArgument.<TestCommandSender>newBuilder("num")
.withMin(1).withMax(95).asOptional()));
.literal("comb")
.argument(StringArgument.<TestCommandSender>newBuilder("str")
.withSuggestionsProvider((c, s) -> Arrays.asList("one", "two")))
.argument(IntegerArgument.<TestCommandSender>newBuilder("num")
.withMin(1).withMax(95).asOptional()));
manager.command(manager.commandBuilder("test")
.literal("alt")
.argument(IntegerArgument.<TestCommandSender>newBuilder("num")
.withSuggestionsProvider((c, s) -> Arrays.asList("3", "33", "333"))));
.literal("alt")
.argument(IntegerArgument.<TestCommandSender>newBuilder("num")
.withSuggestionsProvider((c, s) -> Arrays.asList("3", "33", "333"))));
manager.command(manager.commandBuilder("com")
.argumentPair("com", Pair.of("x", "y"), Pair.of(Integer.class, TestEnum.class),
Description.empty())
.argument(IntegerArgument.of("int")));
.argumentPair("com", Pair.of("x", "y"), Pair.of(Integer.class, TestEnum.class),
Description.empty()
)
.argument(IntegerArgument.of("int")));
manager.command(manager.commandBuilder("com2")
.argumentPair("com", Pair.of("x", "enum"),
Pair.of(Integer.class, TestEnum.class), Description.empty()));
.argumentPair("com", Pair.of("x", "enum"),
Pair.of(Integer.class, TestEnum.class), Description.empty()
));
manager.command(manager.commandBuilder("flags")
.argument(IntegerArgument.of("num"))
.flag(manager.flagBuilder("enum")
.withArgument(EnumArgument.of(TestEnum.class, "enum"))
.build())
.flag(manager.flagBuilder("static")
.build())
.build());
.argument(IntegerArgument.of("num"))
.flag(manager.flagBuilder("enum")
.withArgument(EnumArgument.of(TestEnum.class, "enum"))
.build())
.flag(manager.flagBuilder("static")
.build())
.build());
}
@Test

View file

@ -40,7 +40,7 @@ class CommandTest {
void ensureOrdering() {
Assertions.assertThrows(IllegalArgumentException.class, () ->
Command.newBuilder("test", SimpleCommandMeta.empty()).argument(StringArgument.optional("something"))
.argument(StaticArgument.of("somethingelse")).build());
.argument(StaticArgument.of("somethingelse")).build());
}
}

View file

@ -51,102 +51,113 @@ class CommandTreeTest {
/* Build general test commands */
manager.command(manager.commandBuilder("test", SimpleCommandMeta.empty())
.literal("one").build())
.command(manager.commandBuilder("test", SimpleCommandMeta.empty())
.literal("two").withPermission("no").build())
.command(manager.commandBuilder("test", Collections.singleton("other"),
SimpleCommandMeta.empty())
.literal("opt", "öpt")
.argument(IntegerArgument
.optional("num", EXPECTED_INPUT_NUMBER))
.build())
.command(manager.commandBuilder("req").withSenderType(SpecificCommandSender.class).build());
.literal("one").build())
.command(manager.commandBuilder("test", SimpleCommandMeta.empty())
.literal("two").withPermission("no").build())
.command(manager.commandBuilder("test", Collections.singleton("other"),
SimpleCommandMeta.empty()
)
.literal("opt", "öpt")
.argument(IntegerArgument
.optional("num", EXPECTED_INPUT_NUMBER))
.build())
.command(manager.commandBuilder("req").senderType(SpecificCommandSender.class).build());
/* Build command to test command proxying */
final Command<TestCommandSender> toProxy = manager.commandBuilder("test")
.literal("unproxied")
.argument(StringArgument.of("string"))
.argument(IntegerArgument.of("int"))
.literal("anotherliteral")
.handler(c -> {
})
.build();
.literal("unproxied")
.argument(StringArgument.of("string"))
.argument(IntegerArgument.of("int"))
.literal("anotherliteral")
.handler(c -> {
})
.build();
manager.command(toProxy);
manager.command(manager.commandBuilder("proxy").proxies(toProxy).build());
/* Build command for testing intermediary and final executors */
manager.command(manager.commandBuilder("command")
.withPermission("command.inner")
.literal("inner")
.handler(c -> System.out.println("Using inner command")));
.withPermission("command.inner")
.literal("inner")
.handler(c -> System.out.println("Using inner command")));
manager.command(manager.commandBuilder("command")
.withPermission("command.outer")
.handler(c -> System.out.println("Using outer command")));
.withPermission("command.outer")
.handler(c -> System.out.println("Using outer command")));
/* Build command for testing compound types */
manager.command(manager.commandBuilder("pos")
.argument(ArgumentPair.of(manager, "pos", Pair.of("x", "y"),
Pair.of(Integer.class, Integer.class))
.simple())
.handler(c -> {
final Pair<Integer, Integer> pair = c.get("pos");
System.out.printf("X: %d | Y: %d\n", pair.getFirst(), pair.getSecond());
}));
.argument(ArgumentPair.of(manager, "pos", Pair.of("x", "y"),
Pair.of(Integer.class, Integer.class)
)
.simple())
.handler(c -> {
final Pair<Integer, Integer> pair = c.get("pos");
System.out.printf("X: %d | Y: %d\n", pair.getFirst(), pair.getSecond());
}));
manager.command(manager.commandBuilder("vec")
.argument(ArgumentPair.of(manager, "vec", Pair.of("x", "y"),
Pair.of(Double.class, Double.class))
.withMapper(Vector2.class,
(sender, pair) -> new Vector2(pair.getFirst(), pair.getSecond()))
)
.handler(c -> {
final Vector2 vector2 = c.get("vec");
System.out.printf("X: %f | Y: %f\n", vector2.getX(), vector2.getY());
}));
.argument(ArgumentPair.of(manager, "vec", Pair.of("x", "y"),
Pair.of(Double.class, Double.class)
)
.withMapper(
Vector2.class,
(sender, pair) -> new Vector2(pair.getFirst(), pair.getSecond())
)
)
.handler(c -> {
final Vector2 vector2 = c.get("vec");
System.out.printf("X: %f | Y: %f\n", vector2.getX(), vector2.getY());
}));
/* Build command for testing flags */
manager.command(manager.commandBuilder("flags")
.flag(manager.flagBuilder("test")
.withAliases("t")
.build())
.flag(manager.flagBuilder("test2")
.build())
.flag(manager.flagBuilder("num")
.withArgument(IntegerArgument.of("num")).build())
.handler(c -> {
System.out.println("Flag present? " + c.flags().isPresent("test"));
System.out.println("Numerical flag: " + c.flags().getValue("num", -10));
})
.build());
.flag(manager.flagBuilder("test")
.withAliases("t")
.build())
.flag(manager.flagBuilder("test2")
.build())
.flag(manager.flagBuilder("num")
.withArgument(IntegerArgument.of("num")).build())
.handler(c -> {
System.out.println("Flag present? " + c.flags().isPresent("test"));
System.out.println("Numerical flag: " + c.flags().getValue("num", -10));
})
.build());
}
@Test
void parse() {
final Pair<Command<TestCommandSender>, Exception> command = manager.getCommandTree()
.parse(new CommandContext<>(
new TestCommandSender()),
new LinkedList<>(
Arrays.asList("test",
"one")));
.parse(
new CommandContext<>(
new TestCommandSender()),
new LinkedList<>(
Arrays.asList(
"test",
"one"
))
);
Assertions.assertNotNull(command.getFirst());
Assertions.assertEquals(NoPermissionException.class, manager.getCommandTree()
.parse(new CommandContext<>(
new TestCommandSender()),
new LinkedList<>(
Arrays.asList("test", "two")))
.getSecond().getClass());
.parse(
new CommandContext<>(
new TestCommandSender()),
new LinkedList<>(
Arrays.asList("test", "two"))
)
.getSecond().getClass());
manager.getCommandTree()
.parse(new CommandContext<>(new TestCommandSender()), new LinkedList<>(Arrays.asList("test", "opt")))
.getFirst().getCommandExecutionHandler().execute(new CommandContext<>(new TestCommandSender()));
.parse(new CommandContext<>(new TestCommandSender()), new LinkedList<>(Arrays.asList("test", "opt")))
.getFirst().getCommandExecutionHandler().execute(new CommandContext<>(new TestCommandSender()));
manager.getCommandTree()
.parse(new CommandContext<>(new TestCommandSender()), new LinkedList<>(Arrays.asList("test", "opt", "12")))
.getFirst().getCommandExecutionHandler().execute(new CommandContext<>(new TestCommandSender()));
.parse(new CommandContext<>(new TestCommandSender()), new LinkedList<>(Arrays.asList("test", "opt", "12")))
.getFirst().getCommandExecutionHandler().execute(new CommandContext<>(new TestCommandSender()));
}
@Test
void testAlias() {
manager.getCommandTree()
.parse(new CommandContext<>(new TestCommandSender()), new LinkedList<>(Arrays.asList("other", "öpt", "12")))
.getFirst().getCommandExecutionHandler().execute(new CommandContext<>(new TestCommandSender()));
.parse(new CommandContext<>(new TestCommandSender()), new LinkedList<>(Arrays.asList("other", "öpt", "12")))
.getFirst().getCommandExecutionHandler().execute(new CommandContext<>(new TestCommandSender()));
}
@Test
@ -166,11 +177,11 @@ class CommandTreeTest {
void testDefaultParser() {
manager.command(
manager.commandBuilder("default")
.argument(manager.argumentBuilder(Integer.class, "int"))
.handler(context -> {
final int number = context.get("int");
System.out.printf("Supplied number is: %d\n", number);
})
.argument(manager.argumentBuilder(Integer.class, "int"))
.handler(context -> {
final int number = context.get("int");
System.out.printf("Supplied number is: %d\n", number);
})
);
manager.executeCommand(new TestCommandSender(), "default 5").join();
}
@ -224,6 +235,7 @@ class CommandTreeTest {
public static final class SpecificCommandSender extends TestCommandSender {
}

View file

@ -68,11 +68,13 @@ public class ParserRegistryTest {
final ParserParameters parserParameters = parserRegistry.parseAnnotations(parsedType, Collections.singleton(range));
Assertions.assertTrue(parserParameters.has(StandardParameters.RANGE_MIN));
Assertions.assertTrue(parserParameters.has(StandardParameters.RANGE_MAX));
final ArgumentParser<TestCommandSender, ?> parser = parserRegistry.createParser(parsedType,
parserParameters)
.orElseThrow(
() -> new NullPointerException(
"No parser found"));
final ArgumentParser<TestCommandSender, ?> parser = parserRegistry.createParser(
parsedType,
parserParameters
)
.orElseThrow(
() -> new NullPointerException(
"No parser found"));
Assertions.assertTrue(parser instanceof IntegerArgument.IntegerParser);
@SuppressWarnings("unchecked") final IntegerArgument.IntegerParser<TestCommandSender> integerParser =
(IntegerArgument.IntegerParser<TestCommandSender>) parser;
@ -81,11 +83,11 @@ public class ParserRegistryTest {
/* Test integer */
parserRegistry.createParser(TypeToken.get(int.class), ParserParameters.empty())
.orElseThrow(() -> new IllegalArgumentException("No parser found for int.class"));
.orElseThrow(() -> new IllegalArgumentException("No parser found for int.class"));
/* Test Enum */
parserRegistry.createParser(TypeToken.get(CommandManager.ManagerSettings.class), ParserParameters.empty())
.orElseThrow(() -> new IllegalArgumentException("No parser found for enum"));
.orElseThrow(() -> new IllegalArgumentException("No parser found for enum"));
}
}

View file

@ -39,29 +39,29 @@ class StringArgumentTest {
static void setup() {
manager = new TestCommandManager();
manager.command(manager.commandBuilder("quoted")
.argument(StringArgument.of("message1", StringArgument.StringMode.QUOTED))
.argument(StringArgument.of("message2"))
.handler(c -> {
final String message1 = c.get("message1");
final String message2 = c.get("message2");
storage[0] = message1;
storage[1] = message2;
})
.build());
.argument(StringArgument.of("message1", StringArgument.StringMode.QUOTED))
.argument(StringArgument.of("message2"))
.handler(c -> {
final String message1 = c.get("message1");
final String message2 = c.get("message2");
storage[0] = message1;
storage[1] = message2;
})
.build());
manager.command(manager.commandBuilder("single")
.argument(StringArgument.of("message"))
.handler(c -> {
final String message = c.get("message");
storage[0] = message;
})
.build());
.argument(StringArgument.of("message"))
.handler(c -> {
final String message = c.get("message");
storage[0] = message;
})
.build());
manager.command(manager.commandBuilder("greedy")
.argument(StringArgument.of("message", StringArgument.StringMode.GREEDY))
.handler(c -> {
final String message = c.get("message");
storage[0] = message;
})
.build());
.argument(StringArgument.of("message", StringArgument.StringMode.GREEDY))
.handler(c -> {
final String message = c.get("message");
storage[0] = message;
})
.build());
}
private static void clear() {

View file

@ -48,9 +48,11 @@ public class JavacordCommand<C> implements MessageCreateListener {
private final CommandArgument<C, ?> command;
private final cloud.commandframework.Command<C> cloudCommand;
JavacordCommand(final cloud.commandframework.@NonNull Command<C> cloudCommand,
final @NonNull CommandArgument<C, ?> command,
final @NonNull JavacordCommandManager<C> manager) {
JavacordCommand(
final cloud.commandframework.@NonNull Command<C> cloudCommand,
final @NonNull CommandArgument<C, ?> command,
final @NonNull JavacordCommandManager<C> manager
) {
this.command = command;
this.manager = manager;
this.cloudCommand = cloudCommand;
@ -85,70 +87,78 @@ public class JavacordCommand<C> implements MessageCreateListener {
final String finalContent = messageContent;
//noinspection unchecked
if (((StaticArgument<C>) command).getAliases()
.stream()
.map(String::toLowerCase)
.noneMatch(commandAlias -> finalContent.toLowerCase().startsWith(commandAlias))) {
.stream()
.map(String::toLowerCase)
.noneMatch(commandAlias -> finalContent.toLowerCase().startsWith(commandAlias))) {
return;
}
manager.executeCommand(sender, finalContent)
.whenComplete(((commandResult, throwable) -> {
if (throwable == null) {
return;
}
.whenComplete(((commandResult, throwable) -> {
if (throwable == null) {
return;
}
if (throwable instanceof CompletionException) {
throwable = throwable.getCause();
}
if (throwable instanceof CompletionException) {
throwable = throwable.getCause();
}
if (throwable instanceof NoSuchCommandException) {
//Ignore, should never happen
return;
}
if (throwable instanceof NoSuchCommandException) {
//Ignore, should never happen
return;
}
if (throwable instanceof InvalidSyntaxException) {
manager.handleException(sender,
InvalidSyntaxException.class,
(InvalidSyntaxException) throwable,
(c, e) -> commandSender.sendErrorMessage(
"Invalid Command Syntax. Correct command syntax is: `"
+ e.getCorrectSyntax()
+ "`")
);
if (throwable instanceof InvalidSyntaxException) {
manager.handleException(
sender,
InvalidSyntaxException.class,
(InvalidSyntaxException) throwable,
(c, e) -> commandSender.sendErrorMessage(
"Invalid Command Syntax. Correct command syntax is: `"
+ e.getCorrectSyntax()
+ "`")
);
return;
}
return;
}
if (throwable instanceof InvalidCommandSenderException) {
manager.handleException(sender,
InvalidCommandSenderException.class,
(InvalidCommandSenderException) throwable,
(c, e) -> commandSender.sendErrorMessage(e.getMessage()));
if (throwable instanceof InvalidCommandSenderException) {
manager.handleException(
sender,
InvalidCommandSenderException.class,
(InvalidCommandSenderException) throwable,
(c, e) -> commandSender.sendErrorMessage(e.getMessage())
);
return;
}
return;
}
if (throwable instanceof NoPermissionException) {
manager.handleException(sender,
NoPermissionException.class,
(NoPermissionException) throwable,
(c, e) -> commandSender.sendErrorMessage(MESSAGE_NO_PERMS));
if (throwable instanceof NoPermissionException) {
manager.handleException(
sender,
NoPermissionException.class,
(NoPermissionException) throwable,
(c, e) -> commandSender.sendErrorMessage(MESSAGE_NO_PERMS)
);
return;
}
return;
}
if (throwable instanceof ArgumentParseException) {
manager.handleException(sender,
ArgumentParseException.class,
(ArgumentParseException) throwable,
(c, e) -> commandSender.sendErrorMessage(
"Invalid Command Argument: `" + e.getCause().getMessage() + "`"));
if (throwable instanceof ArgumentParseException) {
manager.handleException(
sender,
ArgumentParseException.class,
(ArgumentParseException) throwable,
(c, e) -> commandSender.sendErrorMessage(
"Invalid Command Argument: `" + e.getCause().getMessage() + "`")
);
return;
}
return;
}
commandSender.sendErrorMessage(throwable.getMessage());
throwable.printStackTrace();
}));
commandSender.sendErrorMessage(throwable.getMessage());
throwable.printStackTrace();
}));
}
}

View file

@ -59,15 +59,17 @@ public class JavacordCommandManager<C> extends CommandManager<C> {
* @param commandPermissionMapper Function used to check if a command sender has the permission to execute a command
* @throws Exception If the construction of the manager fails
*/
public JavacordCommandManager(final @NonNull DiscordApi discordApi,
final @NonNull Function<@NonNull CommandTree<C>,
@NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator,
final @NonNull Function<@NonNull JavacordCommandSender, @NonNull C> commandSenderMapper,
final @NonNull Function<@NonNull C,
@NonNull JavacordCommandSender> backwardsCommandSenderMapper,
final @NonNull Function<@NonNull C, @NonNull String> commandPrefixMapper,
final @Nullable BiFunction<@NonNull C,
@NonNull String, @NonNull Boolean> commandPermissionMapper)
public JavacordCommandManager(
final @NonNull DiscordApi discordApi,
final @NonNull Function<@NonNull CommandTree<C>,
@NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator,
final @NonNull Function<@NonNull JavacordCommandSender, @NonNull C> commandSenderMapper,
final @NonNull Function<@NonNull C,
@NonNull JavacordCommandSender> backwardsCommandSenderMapper,
final @NonNull Function<@NonNull C, @NonNull String> commandPrefixMapper,
final @Nullable BiFunction<@NonNull C,
@NonNull String, @NonNull Boolean> commandPermissionMapper
)
throws Exception {
super(commandExecutionCoordinator, new JavacordRegistrationHandler<>());
((JavacordRegistrationHandler<C>) this.getCommandRegistrationHandler()).initialize(this);
@ -81,7 +83,8 @@ public class JavacordCommandManager<C> extends CommandManager<C> {
@Override
public final boolean hasPermission(
final @NonNull C sender, final @NonNull String permission) {
final @NonNull C sender, final @NonNull String permission
) {
if (permission.isEmpty()) {
return true;
}
@ -131,4 +134,5 @@ public class JavacordCommandManager<C> extends CommandManager<C> {
public @NonNull DiscordApi getDiscordApi() {
return this.discordApi;
}
}

View file

@ -26,38 +26,40 @@ package cloud.commandframework.javacord;
import cloud.commandframework.Command;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.internal.CommandRegistrationHandler;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.HashMap;
import java.util.Map;
import org.checkerframework.checker.nullness.qual.NonNull;
final class JavacordRegistrationHandler<C> implements CommandRegistrationHandler {
private final Map<CommandArgument<?, ?>, JavacordCommand<C>> registeredCommands = new HashMap<>();
private final Map<CommandArgument<?, ?>, JavacordCommand<C>> registeredCommands = new HashMap<>();
private JavacordCommandManager<C> javacordCommandManager;
private JavacordCommandManager<C> javacordCommandManager;
JavacordRegistrationHandler() {
}
void initialize(final @NonNull JavacordCommandManager<C> javacordCommandManager) {
this.javacordCommandManager = javacordCommandManager;
}
@Override
public boolean registerCommand(final @NonNull Command<?> command) {
/* We only care about the root command argument */
final CommandArgument<?, ?> commandArgument = command.getArguments().get(0);
if (this.registeredCommands.containsKey(commandArgument)) {
return false;
JavacordRegistrationHandler() {
}
void initialize(final @NonNull JavacordCommandManager<C> javacordCommandManager) {
this.javacordCommandManager = javacordCommandManager;
}
@Override
public boolean registerCommand(final @NonNull Command<?> command) {
/* We only care about the root command argument */
final CommandArgument<?, ?> commandArgument = command.getArguments().get(0);
if (this.registeredCommands.containsKey(commandArgument)) {
return false;
}
@SuppressWarnings("unchecked") final JavacordCommand<C> javacordCommand = new JavacordCommand<>(
(Command<C>) command,
(CommandArgument<C, ?>) commandArgument,
this.javacordCommandManager
);
this.registeredCommands.put(commandArgument, javacordCommand);
this.javacordCommandManager.getDiscordApi().addMessageCreateListener(javacordCommand);
return true;
}
@SuppressWarnings("unchecked") final JavacordCommand<C> javacordCommand = new JavacordCommand<>(
(Command<C>) command,
(CommandArgument<C, ?>) commandArgument,
this.javacordCommandManager);
this.registeredCommands.put(commandArgument, javacordCommand);
this.javacordCommandManager.getDiscordApi().addMessageCreateListener(javacordCommand);
return true;
}
}

View file

@ -46,7 +46,8 @@ public class JavacordPrivateSender extends JavacordCommandSender {
@NonNull
public PrivateChannel getPrivateChannel() {
return getEvent().getPrivateChannel()
.orElseThrow(() -> new UnsupportedOperationException(
"PrivateTextChannel not present even though message was sent in a private channel"));
.orElseThrow(() -> new UnsupportedOperationException(
"PrivateTextChannel not present even though message was sent in a private channel"));
}
}

View file

@ -47,8 +47,8 @@ public class JavacordServerSender extends JavacordCommandSender {
@NonNull
public ServerChannel getServerChannel() {
return getEvent().getServerTextChannel()
.orElseThrow(() -> new UnsupportedOperationException(
"ServerTextChannel not present even though message was sent in a server channel"));
.orElseThrow(() -> new UnsupportedOperationException(
"ServerTextChannel not present even though message was sent in a server channel"));
}
/**
@ -59,7 +59,8 @@ public class JavacordServerSender extends JavacordCommandSender {
@NonNull
public Server getServer() {
return getEvent().getServer()
.orElseThrow(() -> new UnsupportedOperationException(
"Server not present even though message was sent on a server"));
.orElseThrow(() -> new UnsupportedOperationException(
"Server not present even though message was sent on a server"));
}
}

View file

@ -75,51 +75,58 @@ public class JDACommandListener<C> extends ListenerAdapter {
content = content.substring(prefix.length());
commandManager.executeCommand(sender, content)
.whenComplete((commandResult, throwable) -> {
if (throwable == null) {
return;
}
.whenComplete((commandResult, throwable) -> {
if (throwable == null) {
return;
}
if (throwable instanceof InvalidSyntaxException) {
this.commandManager.handleException(sender,
InvalidSyntaxException.class,
(InvalidSyntaxException) throwable, (c, e) -> {
this.sendMessage(event,
MESSAGE_INVALID_SYNTAX + prefix + ((InvalidSyntaxException) throwable)
.getCorrectSyntax());
});
} else if (throwable instanceof InvalidCommandSenderException) {
this.commandManager.handleException(sender,
InvalidCommandSenderException.class,
(InvalidCommandSenderException) throwable, (c, e) ->
this.sendMessage(event, throwable.getMessage())
);
} else if (throwable instanceof NoPermissionException) {
this.commandManager.handleException(sender,
NoPermissionException.class,
(NoPermissionException) throwable, (c, e) ->
this.sendMessage(event, MESSAGE_NO_PERMS)
);
} else if (throwable instanceof NoSuchCommandException) {
this.commandManager.handleException(sender,
NoSuchCommandException.class,
(NoSuchCommandException) throwable, (c, e) ->
this.sendMessage(event, MESSAGE_UNKNOWN_COMMAND)
);
} else if (throwable instanceof ArgumentParseException) {
this.commandManager.handleException(sender, ArgumentParseException.class,
(ArgumentParseException) throwable, (c, e) -> {
this.sendMessage(event,
"Invalid Command Argument: " + throwable.getCause()
.getMessage());
});
} else {
this.sendMessage(event, throwable.getMessage());
}
});
if (throwable instanceof InvalidSyntaxException) {
this.commandManager.handleException(sender,
InvalidSyntaxException.class,
(InvalidSyntaxException) throwable, (c, e) -> {
this.sendMessage(
event,
MESSAGE_INVALID_SYNTAX + prefix + ((InvalidSyntaxException) throwable)
.getCorrectSyntax()
);
}
);
} else if (throwable instanceof InvalidCommandSenderException) {
this.commandManager.handleException(sender,
InvalidCommandSenderException.class,
(InvalidCommandSenderException) throwable, (c, e) ->
this.sendMessage(event, throwable.getMessage())
);
} else if (throwable instanceof NoPermissionException) {
this.commandManager.handleException(sender,
NoPermissionException.class,
(NoPermissionException) throwable, (c, e) ->
this.sendMessage(event, MESSAGE_NO_PERMS)
);
} else if (throwable instanceof NoSuchCommandException) {
this.commandManager.handleException(sender,
NoSuchCommandException.class,
(NoSuchCommandException) throwable, (c, e) ->
this.sendMessage(event, MESSAGE_UNKNOWN_COMMAND)
);
} else if (throwable instanceof ArgumentParseException) {
this.commandManager.handleException(sender, ArgumentParseException.class,
(ArgumentParseException) throwable, (c, e) -> {
this.sendMessage(
event,
"Invalid Command Argument: " + throwable.getCause()
.getMessage()
);
}
);
} else {
this.sendMessage(event, throwable.getMessage());
}
});
}
private void sendMessage(final @NonNull MessageReceivedEvent event, final @NonNull String message) {
event.getChannel().sendMessage(message).queue();
}
}

View file

@ -45,6 +45,7 @@ import java.util.function.Function;
* @param <C> Command sender type
*/
public class JDACommandManager<C> extends CommandManager<C> {
private final long botId;
private final Function<@NonNull C, @NonNull String> prefixMapper;
@ -63,12 +64,14 @@ public class JDACommandManager<C> extends CommandManager<C> {
* @param backwardsCommandSenderMapper Function that maps the command sender type to {@link MessageReceivedEvent}
* @throws InterruptedException If the jda instance does not ready correctly
*/
public JDACommandManager(final @NonNull JDA jda,
final @NonNull Function<@NonNull C, @NonNull String> prefixMapper,
final @Nullable BiFunction<@NonNull C, @NonNull String, @NonNull Boolean> permissionMapper,
final @NonNull Function<CommandTree<C>, CommandExecutionCoordinator<C>> commandExecutionCoordinator,
final @NonNull Function<@NonNull MessageReceivedEvent, @NonNull C> commandSenderMapper,
final @NonNull Function<@NonNull C, @NonNull MessageReceivedEvent> backwardsCommandSenderMapper)
public JDACommandManager(
final @NonNull JDA jda,
final @NonNull Function<@NonNull C, @NonNull String> prefixMapper,
final @Nullable BiFunction<@NonNull C, @NonNull String, @NonNull Boolean> permissionMapper,
final @NonNull Function<CommandTree<C>, CommandExecutionCoordinator<C>> commandExecutionCoordinator,
final @NonNull Function<@NonNull MessageReceivedEvent, @NonNull C> commandSenderMapper,
final @NonNull Function<@NonNull C, @NonNull MessageReceivedEvent> backwardsCommandSenderMapper
)
throws InterruptedException {
super(commandExecutionCoordinator, CommandRegistrationHandler.nullCommandRegistrationHandler());
this.prefixMapper = prefixMapper;
@ -130,4 +133,5 @@ public class JDACommandManager<C> extends CommandManager<C> {
public final @NonNull CommandMeta createDefaultCommandMeta() {
return SimpleCommandMeta.empty();
}
}

View file

@ -31,6 +31,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
* Wrapper for {@link MessageReceivedEvent}
*/
public class JDACommandSender {
private final MessageReceivedEvent event;
/**
@ -42,15 +43,6 @@ public class JDACommandSender {
this.event = event;
}
/**
* Get the {@link MessageReceivedEvent}
*
* @return Message Received Event
*/
public @NonNull MessageReceivedEvent getEvent() {
return event;
}
/**
* Create a JDA Command Sender from a {@link MessageReceivedEvent}
*
@ -64,4 +56,14 @@ public class JDACommandSender {
return new JDAGuildSender(event);
}
/**
* Get the {@link MessageReceivedEvent}
*
* @return Message Received Event
*/
public @NonNull MessageReceivedEvent getEvent() {
return event;
}
}

View file

@ -34,4 +34,5 @@ public class JDAGuildSender extends JDACommandSender {
JDAGuildSender(final @NonNull MessageReceivedEvent event) {
super(event);
}
}

View file

@ -34,4 +34,5 @@ public class JDAPrivateSender extends JDACommandSender {
JDAPrivateSender(final @NonNull MessageReceivedEvent event) {
super(event);
}
}

View file

@ -43,10 +43,13 @@ import java.util.Queue;
*/
@SuppressWarnings("unused")
public final class UserArgument<C> extends CommandArgument<C, User> {
private final List<ParserMode> modes;
private UserArgument(final boolean required, final @NonNull String name,
final @NonNull JDA jda, final @NonNull List<ParserMode> modes) {
private UserArgument(
final boolean required, final @NonNull String name,
final @NonNull JDA jda, final @NonNull List<ParserMode> modes
) {
super(required, name, new UserParser<>(jda, modes), User.class);
this.modes = modes;
}
@ -105,6 +108,7 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
public static final class Builder<C> extends CommandArgument.Builder<C, User> {
private final JDA jda;
private List<ParserMode> modes = new ArrayList<>();
@ -138,6 +142,7 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
public static final class UserParser<C> implements ArgumentParser<C, User> {
private final JDA jda;
private final List<ParserMode> modes;
@ -149,7 +154,8 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
@Override
public @NonNull ArgumentParseResult<User> parse(
final @NonNull CommandContext<C> commandContext,
final @NonNull Queue<@NonNull String> inputQueue) {
final @NonNull Queue<@NonNull String> inputQueue
) {
final String input = inputQueue.peek();
if (input == null) {
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
@ -218,6 +224,7 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
return ArgumentParseResult.success(user);
}
}
}
@ -242,10 +249,12 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
public final @NonNull String getInput() {
return input;
}
}
public static final class TooManyUsersFoundParseException extends UserParseException {
/**
* Construct a new UUID parse exception
*
@ -259,10 +268,12 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
public @NonNull String getMessage() {
return String.format("Too many users found for '%s'.", getInput());
}
}
public static final class UserNotFoundParseException extends UserParseException {
/**
* Construct a new UUID parse exception
*
@ -276,5 +287,7 @@ public final class UserArgument<C> extends CommandArgument<C, User> {
public @NonNull String getMessage() {
return String.format("User not found for '%s'.", getInput());
}
}
}

View file

@ -54,8 +54,10 @@ public class JLineCommandManager extends CommandManager<JLineCommandSender> impl
*
* @param executionCoordinatorFunction Function producing a new coordinator
*/
public JLineCommandManager(final @NonNull Function<CommandTree<JLineCommandSender>,
CommandExecutionCoordinator<JLineCommandSender>> executionCoordinatorFunction) {
public JLineCommandManager(
final @NonNull Function<CommandTree<JLineCommandSender>,
CommandExecutionCoordinator<JLineCommandSender>> executionCoordinatorFunction
) {
super(executionCoordinatorFunction, CommandRegistrationHandler.nullCommandRegistrationHandler());
}
@ -69,44 +71,44 @@ public class JLineCommandManager extends CommandManager<JLineCommandSender> impl
final JLineCommandManager jLineCommandManager = new JLineCommandManager(CommandExecutionCoordinator.simpleCoordinator());
final Terminal terminal = TerminalBuilder.builder().build();
LineReader lineReader = LineReaderBuilder.builder()
.completer(jLineCommandManager)
.option(LineReader.Option.INSERT_TAB, false)
.terminal(terminal)
.appName("Test")
.build();
.completer(jLineCommandManager)
.option(LineReader.Option.INSERT_TAB, false)
.terminal(terminal)
.appName("Test")
.build();
boolean[] shouldStop = new boolean[]{false};
jLineCommandManager.command(
jLineCommandManager.commandBuilder("stop", SimpleCommandMeta.empty())
.handler(commandContext ->
shouldStop[0] = true)
.build())
.command(jLineCommandManager.commandBuilder("echo", SimpleCommandMeta.empty())
.argument(String.class, "string", builder ->
builder.asRequired()
.withParser(((commandContext, inputQueue) -> {
final StringBuilder stringBuilder =
new StringBuilder();
while (!inputQueue.isEmpty()) {
stringBuilder.append(inputQueue.remove());
if (!inputQueue.isEmpty()) {
stringBuilder.append(" ");
}
}
return ArgumentParseResult.success(
stringBuilder.toString());
})).build())
.handler(commandContext -> commandContext.getOptional("string")
.ifPresent(
System.out::println))
.build())
.command(jLineCommandManager.commandBuilder("test", SimpleCommandMeta.empty())
.argument(StaticArgument.of("one"))
.handler(commandContext -> System.out.println("Test (1)"))
.build())
.command(jLineCommandManager.commandBuilder("test", SimpleCommandMeta.empty())
.argument(StaticArgument.of("two"))
.handler(commandContext -> System.out.println("Test (2)"))
.build());
.handler(commandContext ->
shouldStop[0] = true)
.build())
.command(jLineCommandManager.commandBuilder("echo", SimpleCommandMeta.empty())
.argument(String.class, "string", builder ->
builder.asRequired()
.withParser(((commandContext, inputQueue) -> {
final StringBuilder stringBuilder =
new StringBuilder();
while (!inputQueue.isEmpty()) {
stringBuilder.append(inputQueue.remove());
if (!inputQueue.isEmpty()) {
stringBuilder.append(" ");
}
}
return ArgumentParseResult.success(
stringBuilder.toString());
})).build())
.handler(commandContext -> commandContext.getOptional("string")
.ifPresent(
System.out::println))
.build())
.command(jLineCommandManager.commandBuilder("test", SimpleCommandMeta.empty())
.argument(StaticArgument.of("one"))
.handler(commandContext -> System.out.println("Test (1)"))
.build())
.command(jLineCommandManager.commandBuilder("test", SimpleCommandMeta.empty())
.argument(StaticArgument.of("two"))
.handler(commandContext -> System.out.println("Test (2)"))
.build());
System.out.println("Ready...");
while (!shouldStop[0]) {
final String line = lineReader.readLine();
@ -138,9 +140,11 @@ public class JLineCommandManager extends CommandManager<JLineCommandSender> impl
}
@Override
public final void complete(final @NonNull LineReader lineReader,
final @NonNull ParsedLine parsedLine,
final @NonNull List<@NonNull Candidate> list) {
public final void complete(
final @NonNull LineReader lineReader,
final @NonNull ParsedLine parsedLine,
final @NonNull List<@NonNull Candidate> list
) {
final String line = parsedLine.line();
if (line == null || line.isEmpty() || !line.startsWith("/")) {
System.out.println("Cannot suggest: empty line");
@ -155,8 +159,10 @@ public class JLineCommandManager extends CommandManager<JLineCommandSender> impl
}
@Override
public final boolean hasPermission(final @NonNull JLineCommandSender sender,
final @NonNull String permission) {
public final boolean hasPermission(
final @NonNull JLineCommandSender sender,
final @NonNull String permission
) {
return true;
}

View file

@ -95,9 +95,10 @@ public final class CloudBrigadierManager<C, S> {
* @param commandManager Command manager
* @param dummyContextProvider Provider of dummy context for completions
*/
public CloudBrigadierManager(final @NonNull CommandManager<C> commandManager,
final @NonNull Supplier<@NonNull CommandContext<C>>
dummyContextProvider) {
public CloudBrigadierManager(
final @NonNull CommandManager<C> commandManager,
final @NonNull Supplier<@NonNull CommandContext<C>> dummyContextProvider
) {
this.mappers = new HashMap<>();
this.defaultArgumentTypeSuppliers = new HashMap<>();
this.commandManager = commandManager;
@ -199,10 +200,12 @@ public final class CloudBrigadierManager<C, S> {
* @param <K> cloud argument type
* @param <O> Brigadier argument type value
*/
public <T, K extends ArgumentParser<C, T>, O> void registerMapping(final @NonNull TypeToken<K> argumentType,
final boolean nativeSuggestions,
final @NonNull Function<@NonNull ? extends K,
@NonNull ? extends ArgumentType<O>> mapper) {
public <T, K extends ArgumentParser<C, T>, O> void registerMapping(
final @NonNull TypeToken<K> argumentType,
final boolean nativeSuggestions,
final @NonNull Function<@NonNull ? extends K,
@NonNull ? extends ArgumentType<O>> mapper
) {
this.mappers.put(GenericTypeReflector.erase(argumentType.getType()), Pair.of(mapper, nativeSuggestions));
}
@ -212,8 +215,10 @@ public final class CloudBrigadierManager<C, S> {
* @param clazz Type to map
* @param supplier Supplier that supplies the argument type
*/
public void registerDefaultArgumentTypeSupplier(final @NonNull Class<?> clazz,
final @NonNull Supplier<@Nullable ArgumentType<?>> supplier) {
public void registerDefaultArgumentTypeSupplier(
final @NonNull Class<?> clazz,
final @NonNull Supplier<@Nullable ArgumentType<?>> supplier
) {
this.defaultArgumentTypeSuppliers.put(clazz, supplier);
}
@ -221,19 +226,23 @@ public final class CloudBrigadierManager<C, S> {
private <T, K extends ArgumentParser<?, ?>> @Nullable Pair<@NonNull ArgumentType<?>, @NonNull Boolean> getArgument(
final @NonNull TypeToken<?> valueType,
final @NonNull TypeToken<T> argumentType,
final @NonNull K argument) {
final @NonNull K argument
) {
final ArgumentParser<C, ?> commandArgument = (ArgumentParser<C, ?>) argument;
final Pair pair = this.mappers.get(GenericTypeReflector.erase(argumentType.getType()));
if (pair == null || pair.getFirst() == null) {
return this.createDefaultMapper(valueType, commandArgument);
}
return Pair.of((ArgumentType<?>) ((Function) pair.getFirst()).apply(commandArgument),
(boolean) pair.getSecond());
return Pair.of(
(ArgumentType<?>) ((Function) pair.getFirst()).apply(commandArgument),
(boolean) pair.getSecond()
);
}
private <T, K extends ArgumentParser<C, T>> @NonNull Pair<@NonNull ArgumentType<?>, @NonNull Boolean> createDefaultMapper(
final @NonNull TypeToken<?> clazz,
final @NonNull ArgumentParser<C, T> argument) {
final @NonNull ArgumentParser<C, T> argument
) {
final Supplier<ArgumentType<?>> argumentTypeSupplier = this.defaultArgumentTypeSuppliers
.get(GenericTypeReflector.erase(clazz.getType()));
final @Nullable ArgumentType<?> defaultType;
@ -258,20 +267,24 @@ public final class CloudBrigadierManager<C, S> {
* @param executor Command executor
* @return Literal command node
*/
public @NonNull LiteralCommandNode<S> createLiteralCommandNode(final @NonNull String label,
final @NonNull Command<C> cloudCommand,
final @NonNull BiPredicate<@NonNull S,
@NonNull CommandPermission> permissionChecker,
final boolean forceRegister,
final com.mojang.brigadier.@NonNull Command<S> executor) {
public @NonNull LiteralCommandNode<S> createLiteralCommandNode(
final @NonNull String label,
final @NonNull Command<C> cloudCommand,
final @NonNull BiPredicate<@NonNull S,
@NonNull CommandPermission> permissionChecker,
final boolean forceRegister,
final com.mojang.brigadier.@NonNull Command<S> executor
) {
final CommandTree.Node<CommandArgument<C, ?>> node = this.commandManager
.getCommandTree().getNamedNode(cloudCommand.getArguments().get(0).getName());
final SuggestionProvider<S> provider = (context, builder) -> this.buildSuggestions(node.getValue(), context, builder);
final LiteralArgumentBuilder<S> literalArgumentBuilder = LiteralArgumentBuilder
.<S>literal(label)
.requires(sender -> permissionChecker.test(sender, (CommandPermission) node.getNodeMeta()
.getOrDefault("permission",
Permission.empty())));
.getOrDefault(
"permission",
Permission.empty()
)));
if (forceRegister || (node.getValue() != null && node.getValue().getOwningCommand() != null)) {
literalArgumentBuilder.executes(executor);
}
@ -279,7 +292,8 @@ public final class CloudBrigadierManager<C, S> {
final LiteralCommandNode<S> constructedRoot = literalArgumentBuilder.build();
for (final CommandTree.Node<CommandArgument<C, ?>> child : node.getChildren()) {
constructedRoot.addChild(this.constructCommandNode(forceRegister, child,
permissionChecker, executor, provider).build());
permissionChecker, executor, provider
).build());
}
return constructedRoot;
}
@ -299,19 +313,25 @@ public final class CloudBrigadierManager<C, S> {
final @NonNull LiteralCommandNode<S> root,
final @NonNull SuggestionProvider<S> suggestionProvider,
final com.mojang.brigadier.@NonNull Command<S> executor,
final @NonNull BiPredicate<@NonNull S, @NonNull CommandPermission> permissionChecker) {
final @NonNull BiPredicate<@NonNull S, @NonNull CommandPermission> permissionChecker
) {
final LiteralArgumentBuilder<S> literalArgumentBuilder = LiteralArgumentBuilder.<S>literal(root.getLiteral())
.requires(sender -> permissionChecker.test(sender,
(CommandPermission) cloudCommand.getNodeMeta()
.getOrDefault("permission",
Permission.empty())));
.requires(sender -> permissionChecker.test(
sender,
(CommandPermission) cloudCommand.getNodeMeta()
.getOrDefault(
"permission",
Permission.empty()
)
));
if (cloudCommand.getValue() != null && cloudCommand.getValue().getOwningCommand() != null) {
literalArgumentBuilder.executes(executor);
}
final LiteralCommandNode<S> constructedRoot = literalArgumentBuilder.build();
for (final CommandTree.Node<CommandArgument<C, ?>> child : cloudCommand.getChildren()) {
constructedRoot.addChild(this.constructCommandNode(false, child, permissionChecker,
executor, suggestionProvider).build());
executor, suggestionProvider
).build());
}
return constructedRoot;
}
@ -321,10 +341,10 @@ public final class CloudBrigadierManager<C, S> {
final CommandTree.@NonNull Node<CommandArgument<C, ?>> root,
final @NonNull BiPredicate<@NonNull S, @NonNull CommandPermission> permissionChecker,
final com.mojang.brigadier.@NonNull Command<S> executor,
final SuggestionProvider<S> suggestionProvider) {
final SuggestionProvider<S> suggestionProvider
) {
if (root.getValue() instanceof CompoundArgument) {
@SuppressWarnings("unchecked")
final CompoundArgument<?, C, ?> compoundArgument = (CompoundArgument<?, C, ?>) root.getValue();
@SuppressWarnings("unchecked") final CompoundArgument<?, C, ?> compoundArgument = (CompoundArgument<?, C, ?>) root.getValue();
final Object[] parsers = compoundArgument.getParserTuple().toArray();
final Object[] types = compoundArgument.getTypes().toArray();
final Object[] names = compoundArgument.getNames().toArray();
@ -334,18 +354,24 @@ public final class CloudBrigadierManager<C, S> {
for (int i = parsers.length - 1; i >= 0; i--) {
@SuppressWarnings("unchecked") final ArgumentParser<C, ?> parser = (ArgumentParser<C, ?>) parsers[i];
final Pair<ArgumentType<?>, Boolean> pair = this.getArgument(TypeToken.get((Class<?>) types[i]),
TypeToken.get(parser.getClass()),
parser);
final Pair<ArgumentType<?>, Boolean> pair = this.getArgument(
TypeToken.get((Class<?>) types[i]),
TypeToken.get(parser.getClass()),
parser
);
final SuggestionProvider<S> provider = pair.getSecond() ? null : suggestionProvider;
final ArgumentBuilder<S, ?> fragmentBuilder = RequiredArgumentBuilder
.<S, Object>argument((String) names[i], (ArgumentType<Object>) pair.getFirst())
.suggests(provider)
.requires(sender -> permissionChecker.test(sender,
(CommandPermission) root.getNodeMeta()
.getOrDefault("permission",
Permission.empty())));
.requires(sender -> permissionChecker.test(
sender,
(CommandPermission) root.getNodeMeta()
.getOrDefault(
"permission",
Permission.empty()
)
));
argumentBuilders[i] = fragmentBuilder;
if (forceExecutor || (i == parsers.length - 1) && (root.isLeaf() || !root.getValue().isRequired())) {
@ -369,24 +395,33 @@ public final class CloudBrigadierManager<C, S> {
if (root.getValue() instanceof StaticArgument) {
argumentBuilder = LiteralArgumentBuilder.<S>literal(root.getValue().getName())
.requires(sender -> permissionChecker.test(sender, (CommandPermission) root.getNodeMeta()
.getOrDefault("permission",
Permission.empty())))
.getOrDefault(
"permission",
Permission.empty()
)))
.executes(executor);
} else {
final Pair<ArgumentType<?>, Boolean> pair = this.getArgument(root.getValue().getValueType(),
TypeToken.get(root.getValue().getParser().getClass()),
root.getValue().getParser());
final Pair<ArgumentType<?>, Boolean> pair = this.getArgument(
root.getValue().getValueType(),
TypeToken.get(root.getValue().getParser().getClass()),
root.getValue().getParser()
);
final SuggestionProvider<S> provider = pair.getSecond()
? null
: (context, builder) -> this.buildSuggestions(root.getValue(),
context, builder);
? null
: (context, builder) -> this.buildSuggestions(root.getValue(),
context, builder
);
argumentBuilder = RequiredArgumentBuilder
.<S, Object>argument(root.getValue().getName(), (ArgumentType<Object>) pair.getFirst())
.suggests(provider)
.requires(sender -> permissionChecker.test(sender,
(CommandPermission) root.getNodeMeta()
.getOrDefault("permission",
Permission.empty())));
.requires(sender -> permissionChecker.test(
sender,
(CommandPermission) root.getNodeMeta()
.getOrDefault(
"permission",
Permission.empty()
)
));
}
if (forceExecutor || root.isLeaf() || !root.getValue().isRequired()) {
argumentBuilder.executes(executor);
@ -400,7 +435,8 @@ public final class CloudBrigadierManager<C, S> {
private @NonNull CompletableFuture<Suggestions> buildSuggestions(
final @NonNull CommandArgument<C, ?> argument,
final com.mojang.brigadier.context.@NonNull CommandContext<S> s,
final @NonNull SuggestionsBuilder builder) {
final @NonNull SuggestionsBuilder builder
) {
final CommandContext<C> commandContext = this.dummyContextProvider.get();
final LinkedList<String> inputQueue = new LinkedList<>(Collections.singletonList(builder.getInput()));
final CommandPreprocessingContext<C> commandPreprocessingContext =

Some files were not shown because too many files have changed in this diff Show more